/*==============================================================================================
function repSpace(inString)				-----替换字符两边的空格-----
function SetSubmit(objform , getVal)			-----改变 Form 表单中的某个对象的值-----
function VerifyForm(inputName,title)			-----检验输入框里的值是否为空-----
function clearText(objText , isFlag)			-----清空输入框-----
function openWin(strUrl , forName , widthVal , heightVal , isResize)	-----POP 窗口-----
function alertWin(strUrl , forName , widthVal , heightVal , isResize)	-----POP 窗口-----
function forHideObj(obj , status)			-----隐藏/显示---
function IsInteger( forString , sign) 			----判断是否为整数---
function CharToInt (String) 				 -----改变 Form 表单中文本框中的值为数值型
function textCounter (field, maxlimit,remlen,form) 		-----检测 Form 表单中文本框中还有多少字可写
function substringCN(strString , intStart , intStrLen)		-----截取带中文的字串
function CheckSelected(objEnum , chkname)		-----检测 checkbox 或 radio ，是否有选择
function setSingle(FormObj , canLack)			-----设置 checkbox 或 raido 只可有一个为选中
function multipleSelect(objEnum)			-----判断多选列表是否有选中
function runCode(getstr) 				-----定义一个运行代码的函数----
==============================================================================================*/

//=============检测文本框中可写字数==================
function textCounter(objfield,maxlimit,remlen,remlenattribute) { 
	var funcargumentslength=textCounter.arguments.length;
	var fieldcontent = objfield.value;
	var contentlength = objfield.value.length;
	var CNWordCount = 0;
	for(i=0;i<maxlimit;i++){
		if(escape(fieldcontent.charAt(i)).length>=4){
      			CNWordCount++;
       		}
	}
	contentlength += CNWordCount;
	
	if (contentlength > maxlimit) {
		objfield.value = substringCN(fieldcontent  , 0 , maxlimit); 
	}
	else {
		if (funcargumentslength == 4){
			if (remlen.name == null)
				remlen.name = remlen.id;
			var sparelength = maxlimit - contentlength;
			var returnstr= remlen.name + '.' + remlenattribute  + ' = ' + sparelength.toString() + ';' ;
			eval(returnstr);
		}
	}
}

//=============屏蔽鼠标右键==================
if (window.Event) 
	document.captureEvents(Event.MOUSEUP); 
 
function nocontextmenu() {
	event.cancelBubble = true
	event.returnValue = false;
 
	return false;
}
 
function norightclick(e) {
	if (window.Event){
		if (e.which == 2 || e.which == 3)
		return false;
	}
	else
	if (event.button == 2 || event.button == 3){
		event.cancelBubble = true
		event.returnValue = false;
		return false;
	}
}

function look(){ 
	if(event.ctrlKey) 
		return false;
	//alert("禁止按Shift键!"); //可以换成ALT　CTRL
}

//document.oncontextmenu = nocontextmenu;		// for IE5+
//document.onmousedown = norightclick;			// for all others	
//document.onkeydown=look;

//=============屏蔽鼠标右键,CTRL 功能键==================
//===========================================



//-----替换字符两边的空格-----
function repSpace(inString){
	if (inString != null){
		return 	inString.replace(/(^\s*)|(\s*$)/g, "");
	}
	
	return inString;
}


//-----改变 Form 表单中的某个对象的值---
function SetSubmit(objform , getVal){
	objform.value = getVal ;
}


//-----检验输入框里的值是否为空-----
function VerifyForm(inputName,title){
	bError = false;

	if(repSpace(inputName.value)!="")
		lenInputName = inputName.value.length;
	else
		lenInputName=0;

	if(!lenInputName && inputName!="")
	{
		alert(title);
		inputName.focus();
		bError=true;
	}
	return !bError;
}

//-----鼠标移入，换色-----
function mOvr(src,clrOver) 
{ 
	if (!src.contains(event.fromElement)) 
	{   
  		src.bgColor = clrOver;
   	}
}

//-----鼠标移出，换色-----
function mOut(src,clrIn) 
{ 
	if (!src.contains(event.toElement)) 
  	{
   		src.bgColor = clrIn;
   	}
}

//-----清空输入框-----
function clearText(objText , isFlag){
	if (!isFlag){
		objText.value='';
		isFlag = true ;
	}
}

//-----检查是否 E-mail -----
function isEmail(s){
 	var i = 1;
 	var len = s.length;

	if (len > 60)
	{
		alert("email地址长度不能超过60位!");
		return false;
	}
	
	pos1 = s.indexOf("@");
	pos2 = s.indexOf(".");
	pos3 = s.lastIndexOf("@");
	pos4 = s.lastIndexOf(".");
	//check '@' and '.' is not first or last character
	if ((pos1 <= 0)||(pos1 == len)||(pos2 <= 0)||(pos2 == len)||pos4 >= len-1)  
	{
		alert("请输入有效的E-mail地址！");
		return false;
	}
	else
	{
		//check @. or .@
		if( (pos1 == pos2 - 1) || (pos1 == pos2 + 1) 
		  || ( pos1 != pos3 )  //find two @
		  || ( pos4 < pos3 ) ) //. should behind the '@'  		
		{
			alert("请输入有效的E-mail地址！");
			return false;
		}
	}
	
	return true;
}

//---POP 窗口---
function openWin(strUrl , forName , widthVal , heightVal , isResize){
	var strResize , getWidth ,  getHeight ;
	getWidth	= (screen.width-widthVal)/2 ;
	getHeight	= (screen.height-heightVal - 100)/2 ;
	
	strResize = ',top=' + getHeight + ',left=' + getWidth + ' , toolbar=no,menubar=no,location=no,status=no';
	
	if (isResize){
		strResize += ',scrollbars=yes,resizable=yes';
	}
	else{
		strResize += ',scrollbars=no,resizable=no';
	}
	
	self.open(strUrl , forName , 'width=' + widthVal + ' , height =' + heightVal + strResize);
}

//---Alert 窗口---
function alertWin(strUrl , forName , widthVal , heightVal , isResize){
	var strResize , getWidth ,  getHeight ;
	getWidth	= (screen.width-widthVal)/2 ;
	getHeight	= (screen.height-heightVal - 100)/2 ;
	
	strResize = ',top=' + getHeight + ',left=' + getWidth + ' , toolbar=no,menubar=no,location=no,status=no';
	
	if (isResize){
		strResize += ',scrollbars=yes,resizable=yes';
	}
	else{
		strResize += ',scrollbars=no,resizable=no';
	}
	
	returnvalue = showModalDialog(strUrl , forName , 'dialogWidth:' + widthVal + 'em; dialogHeight:' + heightVal + 'em;');
	return returnvalue;
}

//---隐藏/显示---
function forHideObj(obj , status){
	var tmpStatus;
	if (status == 'Auto'){
		tmpStatus = obj.style.display;
		
		if (tmpStatus == ''){
			status = 1;
		}
		else{
			status = 0;
		}
	}
	
	if (status){
		obj.style.display = 'none';
	}
	else{
		obj.style.display = '';
	}
	
	return !status
}

//----判断是否为整数---
function IsInteger( forString , sign) 
{
	var integer; 
	if ((sign!=null) && (sign!='-') && (sign!='+')) 
	{ 
		alert('IsInter(forString,sign)的参数出错： sign为null或"-"或"+"'); 
		return false; 
	}
	
	integer = parseInt(forString); 
	if (isNaN(integer)) 
	{ 
		return false; 
	} 
	else if (integer.toString().length==forString.length) 
	{  
		if ((sign==null) || (sign=='-' && integer<0) || (sign=='+' && integer>0)) 
		{ 
			return true; 
		} 
		else{
			return false;  
		} 
	}	
	else {
		return false; 
	}
} 


function CharToInt (e)    {
	var i;
	i = e - 0; 
	return i;

}

function substringCN(strString , intStart , maxlimit){
	var intStrLen = strString.length;
	var outString = '';
	var t = 0;
	var tmpstr = '';
	
	for(i=0;i<intStrLen;i++){
		if (i < intStart)
			continue;
		tmpstr = strString.charAt(i);
		t++;
		/*----------中文6字节，回车3字节------*/
		if(escape(tmpstr).length>=3)
      			t ++;
       		if (t > maxlimit)
       			break;
       		outString += tmpstr;
	}
	return outString;
}


//====检测 checkbox 或 radio ，是否有选择=====
function CheckSelected(objEnum , chkname)
{
	var intObjLength;
	var intArgumentsLength = CheckSelected.arguments.length;
	var checkNum	= 0;
	var tmpobj	= '';
	var j		= '';
	if(intArgumentsLength == 2){
		//for (j in objEnum){
		//	if (j == chkname){
		//		objEnum = objEnum[j][chkname];
		//		break;
		//	}
		//}
		
		j = objEnum[chkname][chkname];
		if (j == null)
			objEnum = objEnum[chkname];
		else
			objEnum = objEnum[chkname][chkname];
	}
	
	intObjLength= objEnum.length;
	if (intObjLength==null)
		intObjLength = 1;
	for (var i=0;i<intObjLength;i++){
		if (intObjLength==1){
			tmpobj = objEnum;
		}
		else{
			tmpobj = objEnum[i];
		}
		if (tmpobj.checked)
			checkNum++;
	}
	return checkNum;
}

//---------设置 checkbox 或 raido 只可有一个为选中---
function setSingle(FormObj , canLack){
	//canLack		---设置选项框是否可为没选中状态---
	var x = true;
	var j = '';
	var tmpObj = '';
	var intObjLenght;
	if (canLack)
		x = FormObj.checked;
	tmpObj = FormObj.form;
	j = tmpObj[FormObj.name][FormObj.name];
	if (j == null)
		tmpObj = tmpObj[FormObj.name]
	else
		tmpObj = tmpObj[FormObj.name][FormObj.name];
	intObjLenght = tmpObj.length;
	if(intObjLenght == null)
		intObjLenght = 1;
	for(i=0;i<intObjLenght;i++){
		if (intObjLenght == 1)
			tmpObj.checked = false;
		else
			tmpObj[i].checked = false;
	}
	FormObj.checked = x;
}

//------判断多选列表是否有选中-----
function multipleSelect(objEnum){
	selectCount = 0;
	for(i=0;i<objEnum.length;i++){
		if(objEnum[i].selected){
			selectCount++;
		}
	}
	return selectCount;
}

 //-----定义一个运行代码的函数----
function runCode(getstr) 
{
	try{event = arguments[0];}catch(e){}

	var code=getstr;		//即要运行的代码。
	var newwin=window.open('','',''); 		//打开一个窗口并赋给变量newwin。
	newwin.opener = null			// 防止代码对论谈页面修改
	newwin.document.write(code);		//向这个打开的窗口中写入代码code，这样就实现了运行代码功能。
	newwin.document.close();
}

//检测输入的是数字还是字母
function ischecknumstr( checkobj)
   {
     var checkOK = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
//     var checkOK = "0123456789";//只能输入数字
     //var checkOK = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";//只能输入英文字母
     var checkStr = checkobj;
     var allValid = true;
     var decPoints = 0;
     
     for (i = 0;  i < checkStr.length;  i++)
     {
      ch = checkStr.charAt(i);
      for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      break;
       if (j == checkOK.length)
       {
        allValid = false;
        break;
       } 
      }
     return (allValid)
    }

 //只能输入中文开始----------------------------------------------------------------------------------------------
//检查函数:
function ischinese(s)
{
var errorChar;
var badChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789><,[]{}?/+=\\'\":;~!#$%()`";
     errorChar = isCharsInBag( s, badChar)
        if (errorChar != "" )
    {
        report=report+"请重新输入中文\n";
        return false;
    }     
    
    return true;
}  
  
 function isCharsInBag (s, bag)
{  
  var i,c;
  for (i = 0; i < s.length; i++)
  {   
        c = s.charAt(i);//字符串s中的字符
    if (bag.indexOf(c) > -1) 
        return c;
  }
  return "";
}
  
 //只能输入中文结束-----------------------------------------------------------------------------------------
 
//只能输入中文开始2----------------------------------------------------------------------------------------------
function isChinese(name) //只能为中文值检测
{
	j=0;
	for(i = 0; i < name.length; i++) {
		 if(name.charCodeAt(i) <= 128)
			 j++;
	 }
	if(j > 0)
		return false;
	else
		return true;
}
 //只能输入中文结束2-----------------------------------------------------------------------------------------

