/*************************************
Language:Javascript
**************************************/

/********************************************************************
 added by hetao
*********************************************************************/
function ChkFrmLogin()
	{
		if(document.frmLogin.userID.value=="")
		{
			alert("请输入用户名！");
			document.frmLogin.userID.focus();
			return false;
		}
		if(document.frmLogin.password.value == "")
		{
			alert("请输入密码！");
			document.frmLogin.password.focus();
			return false;
		}
	}

//是否为有效ID。长度 4-12。
function checkUserId(theField){
	if (theField.value.length < 4||theField.value.length>12)
		{
			alert("登录名长度必须为4到12位，请重试！");
			theField.focus();	
			return false;
		}
	else return true;		
}

//是否为密码。如果密码小于4位，则返回错误。
function checkPassWord(theField){
	if (theField.value.length < 4||theField.value.length>12)
		{
			alert("密码长度必须为4到12位，请重试！");
			theField.focus();	
			return false;
		}
	else return true;		
}

//两次密码是否一致。
function checkSamePassword(theField1, theField2){
	if (theField1.value != theField2.value)
		{
			alert("两次输入的密码不一致,请重新输入");
			theField2.focus();	
			return false;
		}
	else return true;		
}

//是否为空（空则返回false）
function checkEmpty(theField, errMsg) {
	if (theField.value == "")
		{
			alert(errMsg);
			theField.focus();	
			return false;
		}
	else return true;		
}

//值长度是否为空,或者大于指定长度。
function checkLength(theField,maxLen,errMsg){
		if (theField.value.length>maxLen)
		{
			alert(errMsg + "不能多于" + maxLen + "字符，请重试！");
			theField.focus();	
			return false;
		}
	return true;		
}


/*************************************************************************
 end by hetao
*************************************************************************/



//是否为空（字符串为空或长度为0，返回true）
function isEmpty(s) {
 return ((s == null) || (s.length == 0));
}

//是否为whitespace。（如果为"\t\n\r",则返回true）
function isWhitespace (s) {
  var whitespace = " \t\n\r";
  // Is s empty?
  if (isEmpty(s)) return true;
  // Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.
  var i;		
  for (i = 0; i < s.length; i++)
  {   
   // Check that current character isn't whitespace.
   var c = s.charAt(i);
   if (whitespace.indexOf(c) != -1) 
      continue;
   else
      return false;
    }
 // All characters are whitespace.
 return true;
}

//检查是否为Email。由checkEmail进行调用。	
function isEmail(s){
	var ex=/^[A-Za-z0-9_.-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,4}$/
 	return ex.test(s);
}

//检查是否为QQ。由checkQQ进行调用。	
function isQQ(s){
	var ex=/[0-9]{4,10}$/
 	return ex.test(s);
}

//显示提示。
function warnEmpty (theField, s){
	alert(s);
    theField.focus();
   	return false;
}

//显示无效并选中。theFiled为被查找的字符串的对象；如果错误，则返回错误提示s。
function warnInvalid (theField, s){
	alert(s);
    	theField.focus();
    	theField.select();
    	return false;
}
//检查是否为空。theFiled为被查找的字符串的对象；如果错误，则返回错误提示s。
function checkString (theField,s){
  // Make sure the field exists before completing the test
  if (theField == null) return true;
  if (isWhitespace(theField.value)) return  warnEmpty (theField, s);	
  else return true;
}

//检查是否超过最大值。theFiled为被查找的字符串的对象；max为最大值；如果错误，则返回错误提示s。
function checkMax(theField,max,s){
	if (theField==null) return true;
	str=theField.value;
	if(!isEmpty(str)){
		if (str.length>max)
			return warnEmpty(theField,s);
		else return true;
	}else return true;
}

//得到字符串str的左边n个字符。
function getLeft(str,n){
	tmp=str.substring(0,n);
	return tmp;
}

//得到字符串str的右边n个字符。
function getRight(str,n){
	l=str.length;
	tmp=str.substring(l-n,l);
	return tmp;
}

//判断是否为有效图片类型，search为查找的文件扩展名；e为错误提示
function isImage(search,e){
	str=".gif;.GIF;.jpg;.JPG;.jpeg;.JPEG;.ico;.ICO;.png;.PNG";
	if(str.indexOf(search)==-1)
		{alert(e);
		return false;}
	else return true;
}

//判断是否以指定字符开头。theField为被查字符串的对象，n为开始字符数，search为查找的字符串，e为出错提示
function isStart(theField,n,search,e){
	//if (theField==null) return true;
	str=theField.value;
	if(1){
		if(getLeft(str,n).toLowerCase()!=search.toLowerCase()){
			return warnEmpty(theField,e);	
		}else return true;
	}else return true;
}

//判断是否以指定字符结尾。theField为被查字符串的对象，n为结尾字符数，search为查找的字符串，e为出错提示
function isEnd(theField,n,search,e){
	if (theField==null) return true;
	str=theField.value;
	if(!isEmpty(str)){
		if(getRight(str,n).toLowerCase()!=search.toLowerCase()){
			return warnEmpty(theField,e);	
		}else return true;
	}else return true;
}

//调用isvalueChar()，判断，输入项theField中的字符是否为有效字符。
function checkValueChar (theField,s){  
	if (!isValueChar(theField.value))
	   return warnEmpty(theField, s);
	else return true;
}

//是否为有效字符，如果是，返回true,如果含有以下非法字符，返回false。由checkValueChar()调用。
function isValueChar (s) {
	var badWords ="\t\n\r><,[]{}?/=^+|\\'\":;~!@#$%^&()`";
		var i;		
		for (i = 0; i < s.length; i++)
		{   
			var c = s.charAt(i);
			if (badWords.indexOf(c) > -1)
				return false;				
			else
				continue;
		}
	// All characters are value.
		   return true;
}

//检验Email是否合法。返回错误提示s.
function checkEmail (theField,s){
	str=theField.value;
	if(!isEmpty(str)){
 		if (!isEmail(str))
   			return warnInvalid (theField, s);
 		else return true;
	}else return true;
}

//检验QQ是否合法。返回错误提示s.
function checkQQ(theField,s){
 str=theField.value;
 if (!isEmpty(str)){
   if (!isQQ(theField.value))
     return warnInvalid (theField, s);
   else return true;
 }else return true;
}
//是否为数字。由checkNumber()进行调用。
function isNumber(s){
 var digits = "0123456789";
 var i = 0;
 var sLength = s.length;
 while ((i < sLength))
 { 
   var c = s.charAt(i);
   if (digits.indexOf(c) == -1) return false; 
      i++;
 }
 return true;
}

//列表是否为空。返回错误提示s.
function checkSelect(theSelect,s){
  if (theSelect.options[theSelect.selectedIndex].value != "")	return true;
  else
  {
    theSelect.focus();
    warnEmpty(theSelect,s);
    return false;
  }
} 


// 调用isNumber()，判断输入项theField中的值是否为数字。返回错误提示s.
function checkNumber (theField,s){
  if (!isNumber(theField.value))
   {    return warnEmpty (theField, s);
   }
  if (isWhitespace(theField.value))
    return warnEmpty (theField, s);
  else return true;	
}

// 调用isNumber()，判断输入项theField中的值是否为数字。返回错误提示s.
function checkChar (theField,s){
  if (isNumber(theField.value))
   {    return warnEmpty (theField, s);
   }
  if (isWhitespace(theField.value))
    return warnEmpty (theField, s);
  else return true;	
}
// 比较日期大小.
function compareDate(theField1,theField2,s){    
   dateA = theField1.value.split("-");
   dateB = theField2.value.split("-");      
   if (dateB[0]<dateA[0]){
    return warnEmpty(theField2,s);    
   }
   if (dateB[1]<dateA[1]){
    return warnEmpty(theField2,s);    
   }
   if (dateB[2]<dateA[2]){
    return warnEmpty(theField2,s);    
   }
   else return true;
}   

//检查月份格式是否有效
function checkMonth (theField,s){
if(theField.value!="")
{
  if (!isNumber(theField.value))
   {    return warnEmpty (theField, s);
   }
  if(parseInt(theField.value)<1 || parseInt(theField.value)>12)
{
	return warnEmpty (theField, s);
}
  if (isWhitespace(theField.value))
    return warnEmpty (theField, s);
  else return true;
}
else return true; 
}

function checkDay (theField,s){
if(theField.value!="")
{
  if (!isNumber(theField.value))
   {    return warnEmpty (theField, s);
   }
  if(parseInt(theField.value)<1 || parseInt(theField.value)>31)
{
	return warnEmpty (theField, s);
}
  if (isWhitespace(theField.value))
    return warnEmpty (theField, s);
  else return true;
}
else return true; 
}

function checkYear (theField,s){
if(theField.value!="")
{
  if (!isNumber(theField.value))
   {    return warnEmpty (theField, s);
   }
  if(parseInt(theField.value)<1900 || parseInt(theField.value)>2900)
{
	return warnEmpty (theField, s);
}
  if (isWhitespace(theField.value))
    return warnEmpty (theField, s);
  else return true;	
}
else return true;
}

function checkHour (theField,s){
if (isWhitespace(theField.value))
return warnEmpty (theField, s);
if(theField.value!="")
{
  if (!isNumber(theField.value))
   {    return warnEmpty (theField, s);
   }
  if(parseInt(theField.value)<1 || parseInt(theField.value)>24)
{
	return warnEmpty (theField, s);
}
 
  else return true;	
}
else return true;
}

function checkMinute (theField,s){
if (isWhitespace(theField.value))
    return warnEmpty (theField, s);
if(theField.value!="")
{
  if (!isNumber(theField.value))
   {    return warnEmpty (theField, s);
   }
  if(parseInt(theField.value)<0 || parseInt(theField.value)>60)
{
	return warnEmpty (theField, s);
}
  
  else return true;	
}
else return true;
}

function checkYearMonth(theYear,theMonth,s){
 stryear=theYear.value;
 strmonth=theMonth.value;
if(stryear!="")
{
   return checkString(theMonth,s);
 }else return true;
}

//是否为邮编号码。必须为六位数字。否则返回false.
function checkZip (theField,s){
  var ss=theField.value;
  var digits = "0123456789";
  var i = 0;
  var sLength = ss.length;
	if(sLength==0)
	return true;
		if(sLength!=6)
		    return warnInvalid (theField, s);
		    
		while ((i < sLength))
		{ 
			var c = ss.charAt(i);
			if (digits.indexOf(c) == -1) 
					return warnInvalid (theField, s);

			i++;		
		}
		
		return true;
	}

//是否为电话号码。只能包括数字和"-"号组成。'--'号返回错误。
function checkPhone(theField,s){
	var ss=theField.value;
	var digits = "0123456789-";
	var i = 0;
	var sLength = ss.length;
	while ((i < sLength))
		{ 
			var c = ss.charAt(i);
			if (digits.indexOf(c) == -1) 
				return warnInvalid (theField, s);

			i++;
		}
	c = "--";
	if (ss.indexOf(c) != -1) 
		return warnInvalid (theField, s);
	return true;
}


//验证密码是否与密码相等
function checkPWDConfirm(sField,oField,s){
	if (sField.value!=oField.value){
		alert(s);
		oField.focus();
		return false;
	}
	else return true;

}
	
//检验是否为有效浮点数。否则返回错误提示s。
function checkFigure (theField,s){
	var vv,ww,xx;
	vv=theField.value;
	var iPos=vv.indexOf(".");
	if(iPos==0) vv="0"+vv;
	if(iPos==(vv.length - 1))  vv=vv+"0";
	xx=parseFloat(vv);
	ww=xx.toString(10);
	var i=vv.length - ww.length;
	var j=0;
	if(i>0)	{
		iPos=ww.indexOf(".");
		if(iPos==-1){
		      ww=ww+".";  		 
	              i=i-1;}
		for(j=0;j<i;j++)
			ww=ww+"0";
 		}
 	if(ww!=vv) 
  	    return warnInvalid (theField, s);
  	return true;  		
}

//去日期的单位数前面的零。此函数由parseYMD()调用。
function parseNum(theNum){
  if (theNum.substring(0,1)==0)
    theNum=theNum.substring(1)
  return theNum
}

//转化日期格式。（如果返回值大于0，则为日期不合法）
function parseYMD(theYear,theMonth,theDay) {
  theYear=parseNum(theYear)
  theMonth=parseNum(theMonth)
  theDay=parseNum(theDay)
  if ((theYear < 1900) || (theYear > 3000)){
    return 1
  }
  if (theMonth < 1 || theMonth > 12){
    return 2
  }
  if ((theMonth==1 || theMonth==3 || theMonth==5 || theMonth==7 || theMonth==8 || theMonth==10 || theMonth==12) &&
      (theDay <1 || theDay > 31)
     ){
    return 3
  }
  if ((theMonth==4 || theMonth==6 || theMonth==9 || theMonth==11) &&
      (theDay <1 || theDay > 30)
     ){
    return 3
  }
  if (theYear%400==0 || (theYear%4==0 && theYear%100!=0)){  //闰年
    if (theMonth==2 && (theDay <1 || theDay > 29) )
      return 3
  }
  else  //平年
    if (theMonth==2 && (theDay <1 || theDay > 28) )
      return 3
     
  return 0
}

//判断日期是否无效。如果日期无效，则返回true.如果日期有效，则返回false.
function isInvalidDate(theDate,separator){   
  default_style=1
  if (theDate.length>10 || theDate.length<8)
    return true
  idx1=theDate.indexOf(separator)
  if (idx1==-1)
    return true
  idx2=theDate.indexOf(separator,idx1+1)
  if (idx2==-1)
    return true
  if (isInvalidDate.arguments.length>2)
  	default_style=isInvalidDate.arguments[2]
  if (default_style<1 || default_style>9){
  	alert("传入参数有误！请检查。")
	return true
  }
  if (default_style==1){
  theYear=theDate.substring(0,idx1)
  theMonth=theDate.substring(idx1+1,idx2)
  theDay=theDate.substring(idx2+1)
  }
  if (default_style==2){
  theMonth=theDate.substring(0,idx1)
  theDay=theDate.substring(idx1+1,idx2)
  theYear=theDate.substring(idx2+1)
  } 
  if (theDay.length>2)
    return true
  if (parseYMD(theYear,theMonth,theDay)>0)
    return true
  else
    return false
}

//若日期无效返回false
function checkDate(theDate,s){   
  if (!isEmpty(theDate.value)){ 
    if ((isInvalidDate(theDate.value,"-"))==true){
		return warnEmpty(theDate,s);
	}
	else{
		return true;
	}
  }else{
  	  return true;
  }
 }
//


//下拉框跳转函数。参数s就是select 的"this"
function jumpTo(s){
	if (s.selectedIndex != -1){
		top.location.href = s.value;
		return true;
	}
}

//改变按钮或文本框的样式，参数backgroundcolor为背景色，forecolor为前景色。
function changeStyle(obj,backgroundcolor,forecolor){
	obj.style.backgroundColor=backgroundcolor;
	obj.style.color=forecolor;
}

function changeTextStyle(obj,backcolor,forecolor){
	obj.style.backgroundColor=backcolor;
	obj.style.color=forecolor;
}


//动态改变月份。formname为表单名，theyear为年的列表框对象；themonth为月的对象；theday为日的对象。
 function FillSelectmonth(formname,theyear,themonth,theday){
	var i;
		eval("formname.elements['"+themonth+"'].value=''");
		eval("formname.elements['"+theday+"'].value=''");
	
		str = "出生年份有误!";

		if  (!checkString(eval("formname.elements['"+theyear+"']"),str)){
			eval("formname.elements['"+themonth+"'].length = 1");
			eval("formname.elements['"+theday+"'].length = 1");

			}
		else{
			for(i=1;i<=12;i++)
		   	 		eval("formname.elements['"+themonth+"'].options["+i+"] = new Option("+i+","+i+")");
		   	//for(i=1;i<=30;i++)
		   	 	//	eval("formname.elements['"+theday+"'].options[0] = new Option('','')");
		   	 	//	eval("formname.elements['"+theday+"'].length = 1");
	}

}

//动态改变日期。formname为表单名，theyear为年的列表框对象；themonth为月的对象；theday为日的对象。
function FillSelectday(formname,theyear,themonth,theday){
	var str;
	var varmonth,varyear;
	var formname;
	var dayselect
	var i;
	
	monthstr="103578"
	
	eval("varmonth=formname.elements['"+themonth+"'].value");
	eval("varyear=formname.elements['"+theyear+"'].value");
	eval("dayselect=formname.elements['"+theday+"']");
	//document.form1.elements["month"].value="";
	eval("formname.elements['"+theday+"'].value=''");
	
	if(varmonth-0==0) 
		dayselect.length=1;
	else{
		dayselect.length=1;
	if (monthstr.search(varmonth)!=-1 ||"12".search(varmonth)!=-1)
        if ("02".search(varmonth)==-1) 
		for(i = 1; i <=31 ; i++)
		{
		dayselect.options[i] = new Option(i, i);
		}
	     else{
		if(((varyear-0) % 4 == 0 && (varyear-0) % 100 != 0)||(varyear-0) % 400 ==0) 
		  for(i = 1; i <=29 ; i++)
		  	{
   	 		dayselect.options[i] = new Option(i, i);
			  }
		else
		  for(i = 1; i <=28 ; i++)
		  	{
   	 		dayselect.options[i] = new Option(i, i);
			  }
		}
	else
	 for(i = 1; i <=30 ; i++)
		dayselect.options[i] = new Option(i, i);
	}
}

//菜单弹出式函数。whick为要弹出的id号，函数内部会自动加１；myLayer为id的标识字符，如“MFX”；count为层的总数，用于关闭其他层；
function MFXrunMenu(which,myLayer,count){
	pos=".style.position";
	vis=".style.visibility";
	which=which+1;
	old_vis=eval(myLayer+which+vis);
	if(old_vis!="visible"){
	MFXCloseAll(count,myLayer);
	eval(myLayer+which+pos+"=\"relative\";");
	eval(myLayer+which+vis+"=\"visible\";");
	}else{
	eval(myLayer+which+pos+"=\"absolute\";");
	eval(myLayer+which+vis+"=\"hidden\";");
	}
}

//关闭弹出式菜单。num为要关闭的层数；myLayer1为层标识符，如"MFX"。
function MFXCloseAll(num,myLayer1){
	pos=".style.position";
	vis=".style.visibility";
	if(num==""){num=-1;}
	for(i=1;i<=num;i=i+3){
	j=i+1;
	eval(myLayer1+j+pos+"=\"absolute\";");
	eval(myLayer1+j+vis+"=\"hidden\";")
		
	}
}
//显示/隐藏有关层。image为图片域，show_image为显示时的图片地址，hide_image为隐藏时图片地址,id_name为层的id号
function show_hide(image,show_image,hide_image,id_name){
	if (eval(id_name+".style.visibility!='hidden'")){
	image.src=show_image;
	eval(id_name+".style.position='absolute'");
	eval(id_name+".style.visibility='hidden'");
	}else{
	image.src=hide_image;
	eval(id_name+".style.position='relative'");
	eval(id_name+".style.visibility='visible'");	
	}	
}

//选择所有复选框，image为图片对象，formname为表单名，show_image为选中时的图片，hide_image为不选中的图片，id_name为checkbox的id前缀，n为复选框范围
function check_all(image,formname,show_image,hide_image,id_name,n){
	r=getRight(image.src,(image.src.length-image.src.lastIndexOf("/")-1));
	h=getRight(hide_image,(hide_image.length-hide_image.lastIndexOf("/")-1));
	if (r==h){
	image.src=show_image;
	for (i=1;i<=n;i++){
	eval(formname+"."+id_name+"_"+i+".checked=true");
	i=i+2;}
	}else{
	image.src=hide_image;
	for (i=1;i<=n;i++){
	eval(formname+"."+id_name+"_"+i+".checked=false");
	i=i+2;}
	}	
}

//域后面的提示显示函数，此为隐藏指定的层
function hide_span(id_name){
	eval(id_name+".style.position='absolute'");
	eval(id_name+".style.visibility='hidden'");
}
//域后面的提示显示函数，此为显示指定的层
function show_span(id_name){
	eval(id_name+".style.position='relative'");
	eval(id_name+".style.visibility='visible'");
}

//动态改变下拉框，x为选择项的id，field为要影响的下拉域的对象
function redirect(x,field){
		field+".options.length=0";
		for(i=0;i<arrImage[x].length;i++){
			field.options[i]=new Option(arrImage[x][i].text,arrImage[x][i].value);
		}	
	}

function checkAttachFile(theField,s){
	if (theField==null) return true;
	var fileStr = theField.value;
	if(fileStr == null || fileStr ==""){
		return true;
	}else{
		if (isAttachFile(fileStr) == true)
			return true;
		else
			return warnEmpty(theField, s);
	}
}

function isAttachFile(fileNameStr){
	var pos = fileNameStr.lastIndexOf(".");
	if(pos == -1) {
		return false;
	};
	var fileExt = fileNameStr.substring(pos).toLowerCase();
	var sExtTbl = new Array(15);
	var bExist = new Boolean(false);

	sExtTbl[0] = ".dll";
	sExtTbl[1] = ".sys";
	sExtTbl[2] = ".ini";
	sExtTbl[3] = ".inf";
	sExtTbl[4] = ".com";
	sExtTbl[5] = ".bat";
	sExtTbl[6] = ".bin";
	sExtTbl[7] = ".tmp";
	sExtTbl[8] = ".dir";
	sExtTbl[9] = ".ocx";
	sExtTbl[10] = ".oca";
	sExtTbl[11] = ".bak";
	sExtTbl[12] = ".cnt";
	sExtTbl[13] = ".cpl";
	sExtTbl[14] = ".exe";
	sExtTbl[15] = ".scr";

	for(var i = 0; i < 16; i++) {
		if(fileExt == sExtTbl[i]) {
			bExist = true;
			break;
		};
	};

	if(bExist == false) {
		return true;
	} else {
		return false;
	};
}

function checkBoxClick(type)
{
	if(type==1){
		if(!document.Form1.testProduct.checked){
			document.Form1.testNum.disabled=true;
			document.Form1.testPrice.disabled=true;
		}else{
			document.Form1.testNum.disabled=false;
			document.Form1.testPrice.disabled=false;
		}
	}else{
		if(!document.Form1.formalProduct.checked){
			document.Form1.formalNum.disabled=true;
			document.Form1.formalPrice.disabled=true;
		}else{
			document.Form1.formalNum.disabled=false;
			document.Form1.formalPrice.disabled=false;
		}
	}
}

function popupPicWindow(tpicturePath){
	window.open(tpicturePath ,"_blank","resizable=yes,width=400,height=300,top=0,scrollbars=no;help=no");
//	window.open("/sl/p.asp?pic="+tpicturePath ,"_blank");
}

function checkIntNumber(argValue) {
	var flag1=false;
	var compStr="1234567890";
	var length2=argValue.length;
	for (var iIndex=0;iIndex<length2;iIndex++)
		{
			var temp1=compStr.indexOf(argValue.charAt(iIndex));
			if(temp1==-1) 
				{
					flag1=false;
					break;							
				}
			else
				{
					flag1=true;
				}
		}
	return flag1;
}

//去掉空格
function checkNull(string) 
{ 
var i=string.length;
var j = 0; 
var k = 0; 
var flag = true;
while (k<i)
{ 
if (string.charAt(k)!= " ") 
j = j+1; 
k = k+1; 
} 
if (j==0) 
{ 
flag = false;
} 
return flag; 
}

function checkIntNumber(form){
	if(!checkNull(form.page.value) || !checkIntNumber(form.page.value)){
		form.page.focus();
		alert("请输入自然整数。");
		return false;	
	}
	return true;
}
