String.prototype.trim = function()
{
	return this.replace(/(^[\s]*)|([\s]*$)/g, "");
}

String.prototype.len=function()
{
    return this.replace(/[^\x00-\xff]/g,"**").length;
}

function doOK(){
	if(window.opener != null){
		var strURL = window.opener.location.href;
		window.opener.navigate(strURL);
		window.close();
	}
	else
		window.close();
}

function doClose(){
	window.close();
}

function doRefreshOpener(){
	if(window.opener != null){
		window.opener.location.replace(window.opener.location);
	}
}

function doRefresh(){
	window.navigate(window.location.href);
}

function doBack(){
	history.back(-1);
}

function newWindow(winWidth, winHeight, winScroll, winUrl, winName){
	var iLeft = (screen.width  - winWidth)/2;
	var iTop  = (screen.height - winHeight)/2;
	var strFeatures = "resizable=yes,scrollbars=" + winScroll + ",left=" + iLeft + ",top=" + iTop + ",width=" + winWidth.toString() + ",height=" + winHeight.toString();
	window.open(winUrl, winName, strFeatures);
}

function newDialog(winWidth, winHeight, winUrl){
	var strFeatures = "dialogHeight: " + winHeight + "px; dialogWidth: " + winWidth + "px;center: yes; help: no;resizable: no; status: no; scroll: no;";
	return window.showModalDialog(winUrl,this,strFeatures);
}

function newModelessWindow(winWidth, winHeight, winScroll, winUrl, winName){
	/*
	var strFeatures = "dialogHeight: " + winHeight + "px; dialogWidth: " + winWidth + "px;center: yes; help: no;resizable: yes; status: no; scroll: " + winScroll;
	window.showModelessDialog(winUrl,this,strFeatures);
	*/
	window.open(winUrl);
}

function isLong(str,l){ //判断字符串str字节数是否超出长度l
  var valueLen = 0;
  if (str != "")
  {
    for (i = 0; i < str.length; i ++)
    {
      var code = escape(str.charAt(i));
      if ((code.length >= 4) && (code < '%uFF60' || code > '%uFF9F'))
      {
        valueLen += 2;
      }
      else
      {
        valueLen ++;
      }
    }
  }
  return (valueLen>l?true:false)
}

function readCookie(doc, name)
{
	if(doc == null) doc = window.document;
	var cookieValue = "";
	var search = name + "=";
	if(doc.cookie.length > 0)
	{ 
		offset = doc.cookie.indexOf(search);
		if (offset != -1)
		{ 
			offset += search.length;
			end = doc.cookie.indexOf(";", offset);
			if (end == -1) end = doc.cookie.length;
				cookieValue = unescape(doc.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function writeCookie(doc, name, value, expiresSeconds)
{
	if(doc == null) doc = window.document;
	var expire = "";
	if(expiresSeconds != null)
	{
		expire = new Date((new Date()).getTime() + expiresSeconds * 1000);
		expire = "; expires=" + expire.toGMTString();
	}
	doc.cookie = name + "=" + escape(value) + expire;
}


function doCheckAll(checkboxName, checked)
{
	var checkboxList = document.getElementsByTagName("input");
	for (var i=0; i<checkboxList.length; i++)
	{
		if (checkboxList[i].name == checkboxName)
			checkboxList[i].checked = checked;
	}
}

function doCheckboxNavigate(alertMessage, checkboxName, strUrl){
	var IDs = "";
	var UrlIndex = "http";
	var UrlNum = strUrl.indexOf(UrlIndex);
	var UrlSub = strUrl.substring(UrlNum);//截取删除时返回的URL	
	var url = strUrl.substring(0,UrlNum) + escape(UrlSub);//部分加密
	
	var checkboxList = document.getElementsByName(checkboxName);

	var hasSelection = false; // 是否勾选	
	for(var i=0 ; i < checkboxList.length; i++)
	{
		if(checkboxList[i].checked)
		{
			hasSelection = true;
			break
		}
	}
	if(!hasSelection){
		window.alert("请从列表中勾选项目，再点击操作按钮！");
		return;
	}
	
	if(window.confirm(alertMessage)){
		for(var i=0 ; i < checkboxList.length; i++)
		{
			if(checkboxList[i].checked)
			{
				IDs += checkboxList[i].value + ',';
			}
		}
		var urlToGo = "";
		if(url.indexOf("&") >= 0){
			urlToGo = url + "&IDs=" + IDs
		}
		else{
			if(url.indexOf("?") >= 0){
				urlToGo = url + "IDs" + IDs
			}
			else{
				urlToGo = url + "?IDs" + IDs
			}
		}
		window.navigate(urlToGo);
	}
}
