﻿<!--
/*
  copyToClipboard(str)
  参数:str 字符串
  功能:复制字符串到剪贴板
*/
function copyToClipboard(str)
{
  window.clipboardData.setData('text', str);
}

//判断当前串是否已制定的串结尾
String.prototype.endWith = function(str)
{
  if("string"!=typeof(str))
  {
    throw new Error(-1,"\""+str+"\" 不是一个字符串。");
  }
  return (this.substring(this.length-str.length, this.length) == str);
}

/*去除字符串头尾空格（包括半角、全角空格、tab键和换行符）
e.g.
var strData = " 　	test string	 ";
strData.trim();
*/
String.prototype.trim = function()
{
    return this.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g, "");
}

/*去除字符串所有空格（包括半角、全角空格、tab键和换行符）
e.g.
var strData = " 　	test string	 ";
strData.clearSpace();
*/
String.prototype.clearSpace = function()
{
    return this.replace(/[\s\u3000]+/g, "");
}

//给String添加一个方法名字为len,计算字符串的字节长度
String.prototype.len = function()
{
  return this.replace(/[^\x00-\xff]/g,"**").length;
}

/*
	setDisplay(area, img, up, down)
	参数:area 需要设置显示状态的区域ID
	     img  显示up、down图片标志的img标签ID
             up   up图片标志
             down down图片标志
	功能:设置某一区域的显示状态（显示或隐藏），同时更改up、down图片标志
*/
function setDisplay(area, img, up, down)
{
	if (document.getElementById(area).style.display == "none")
	{
		document.getElementById(img).src = up;
		document.getElementById(area).style.display = "";
	}
 	else
	{
		document.getElementById(img).src = down;
		document.getElementById(area).style.display = "none";
	}
}

/*
	setDisplay(area)
	参数:area 需要设置显示状态的区域ID
	功能:设置某一区域的显示状态（显示或隐藏）
*/
function setDisplay(area)
{
	if (document.getElementById(area).style.display == "none")
	{
		document.getElementById(area).style.display = "";
	}
 	else
	{
		document.getElementById(area).style.display = "none";
	}
}

/*
	setDisplay(area, status)
	参数:area 需要设置显示状态的区域ID
          status boolean true or false
	功能:设置某一区域的显示状态（显示或隐藏）
*/
//function setDisplay(area, status)
//{
//        $(area).style.display = status;
//}

/*
	setDisabled(objId, status)
	参数:objId 对象ID
            status boolean true or false
	功能:设置某一对象的只读状态
*/
function setDisabled(objId, status)
{
	document.getElementById(objId).disabled = status;
}


/*
	setDisabled(objId)
	参数:objId 对象ID
	功能:设置某一对象的只读状态
*/
function setDisabled(objId)
{
	if (document.getElementById(objId).disabled)
		document.getElementById(objId).disabled = false;
	else
		document.getElementById(objId).disabled = true;
}


/*
	clearCookie(name)
	参数:name 为欲清空cookie的名字
	功能:清除名字为name的cookie
*/
function clearCookie(name) {
	document.cookie=name+"=; " + "domain=zhcw.com; path=/; ";
}

/*
	logout()
	功能:安全退出
*/
function logout()
{
	clearCookie("zhcwLogin");
	clearCookie("zhcwTzz");
	top.location.reload();
}

//-->
/*
  addOption(obj, name, value)
  参数:obj  select对象
      name  选项名称
      value 选项值
  功能:添加下拉框选项
*/
function addOption(obj, name, value)
{
  obj.add(new Option(name, value));
}

/*
  delOptions(obj)
  参数:obj  select对象
  功能:删除下拉框所有选项
*/
function delOptions(obj)
{
  for(i=0; i<obj.length; i++)
  {
     obj.remove(0);
  }
}

/*
  selectedOption(obj, value)
  参数:obj  select对象
      value 选项值
  功能:设置值为value的选项默认选中
*/
function selectedOption(obj, value)
{
  for(i=0; i<obj.length; i++)
  {
    if (obj.options[i].value == value)
    {
      obj.options[i].selected = true;
    }
  }
}

/*
  getRadioGroupValue(objName)
  参数:objName  radioGroupName
  返回值：radioGroup的选中值
  功能:获取radioGroup的选中值
*/
function getRadioGroupValue(objName)
{
  for(i=0; i<document.getElementsByName(objName).length; i++)
  {
    if (document.getElementsByName(objName)[i].checked == true)
    {
      return document.getElementsByName(objName)[i].value;
    }
  }
}

/*
  setCaretAtEnd(field)
  参数:field 文本对象
  返回值：
  功能:将光标移动到文本的末尾
*/
function setCaretAtEnd(field) {  
   if (field.createTextRange) {  
       var  r  =  field.createTextRange();  
       r.moveStart('character',  field.value.length);  
       r.collapse();  
       r.select();  
   }  
}
//-->
