//替换字符串,与java自身提供的replace方法不同的是:ReplaceAll函数替换所有的s1为s2.
//而java自身提供的方法只替换第一个碰到的s1.
function ReplaceAll(s,s1,s2){
	//把s种的s1全部替换成s2
	var i,j,k;
	i=s.indexOf(s1);
	if(i!=-1)
		return s.substr(0,i)+s2+ReplaceAll(s.substr(i+s1.length,s.length-i-s1.length),s1,s2);
	else
		return s;
}
function toString(v){
	return ""+v;
}

function ltrim(s){
	var len;
	s=s+"";
	len=s.length;
	for(i=0;i<len;i++)
		if(s.charAt(i)>" ")
			break;
	return s.substring(i,len);
}

function rtrim(s){
	var len;
	s=s+"";
	len=s.length;
	for(i=len-1;i>-1;i--)
		if(s.charAt(i)>" ")
			break;
	return s.substring(0,i+1);
	
}

function trim(s){
	return ltrim(rtrim(s));
}

function isNoise(s){
	if(s!=""){
		var i;
		var sNoise;
		sNoise="about after all also an and another any are as at be because been before" 
			+ " being between both but by came can come could did do each for from get got"
			+ " has had he have her here him himself his how if in into is it like make many" 
			+ " me might more most much must my never now of on only or other our out over said" 
			+ " same see should since some still such take than that the their them then there" 
			+ " these they this those through to too under up very was way we well were what" 
			+ " where which while who with would you your  1 2 3 4 5 6 7 8 9 0 $ ? _" 
			+ " a b c d e f g h i j k l m n o p q r s t u v w x y z " 
			+ " 的 一 不 在 人 有 是 为 以 于 上 他 而 后 之 来 及 了 因 下 可 到 由 这 与 也 此" 
			+ " 但 并 个 其 已 无 小 我 们 起 最 再 今 去 好 只 又 或 很 亦 某 把 那 你 乃 它 ";
		i=s.indexOf(",");
		if(i<0){
			if(sNoise.indexOf(s+" ")>0)
				return true;
			else
				return false;
		}else{		
			return (isNoise(s.substr(0,i))&&isNoise(s.substr(i+1,s.length-1)));
		}
	}else
		return true;
}
function checkDate(checkForm,VarDate)
{  
	var sYear,sMonth,sDate,index,Nindex,DateTime,str,len
	sYear=""
	sMonth=""
	sDate=""
	DateTime=document.forms[checkForm].elements[VarDate].value
	Nindex=0;
	len=DateTime.length
	for(index=1;index<=len;index++)
	  {
	   str=DateTime.substr(0,1)
	   DateTime=DateTime.substr(1,DateTime.length)
	   if (isNaN(str))
	        break;
	    else
	     {
	        if (!(0<parseInt(str)<9))
	           break;
	      }
	    sYear=sYear+str;	        
       }
	len=DateTime.length
	for(index=1;index<=len;index++)
	  {
	   str=DateTime.substr(0,1)
	   DateTime=DateTime.substr(1,DateTime.length)
	   if (isNaN(str))
	        break;
	    else
	     {     if (!(0<parseInt(str)<9))
	           break;
	      }
	    sMonth=sMonth+str;
	    }	
	len=DateTime.length
	for(index=1;index<=len;index++)
	  {
	   str=DateTime.substr(0,1)
	   if (isNaN(str))
	        break;
	    else
	     {
	        if (!(0<parseInt(str)<9))
	           break;
	      }
	    sDate=sDate+str;
	    DateTime=DateTime.substr(1,DateTime.length)
       }
    if (DateTime!="")
    {
       alert("日期输入错误！");   
       document.forms[checkForm].elements[VarDate].focus();
       return false
    }   
	if (isNaN(sYear) || isNaN(sMonth) || isNaN(sDate)) 
	{
		alert("时间输入错误!"); 
		document.forms[checkForm].elements[VarDate].focus();
		return false;
	}	
	if (!((sYear>1900) && (sYear<2900)))
	{	alert("年份输入错误!"); 
		document.forms[checkForm].elements[VarDate].focus();
		return false;
	}	
	if (!((sMonth>0) && (sMonth<13)))
	{
		alert("月份输入错误!"); 
		document.forms[checkForm].elements[VarDate].focus();
		return false;
	}
	sMonth=parseInt(sMonth)
	switch (sMonth)
	{
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
	if (!((sDate>0) && (sDate<32)))
		{
			alert("日期输入错误!"); 
			document.forms[checkForm].elements[VarDate].focus();
			return false;
		}
		break;
	case 2:
		if (sYear%4==0)
		{
			if((sYear%100==0) && (!(sYear%400==0)))
			{
				if (!((sDate>0) && (sDate<29)))
				{
					alert("日期输入错误!"); 
					document.forms[checkForm].elements[VarDate].focus();
					return false;
				}
			}
			else
			{
				if (!((sDate>0) && (sDate<30)))
				{
					alert("日期输入错误!"); VarDate
					document.forms[checkForm].elements[VarDate].focus();
					return false;
				}
			}
		}
		else
		{
			if (!((sDate>0) && (sDate<29)))
			{
				alert("日期输入错误!"); 
				document.forms[checkForm].elements[VarDate].focus();
				return false;
			}
		}
		break;
	case 4:
	case 6:
	case 9:
	case 11:
	if (!((sDate>0) && (sDate<31)))
		{
			alert("日期输入错误!"); 
			document.forms[checkForm].elements[VarDate].focus();
			return false;
		}
		break;
	}
	return true;
}
function checkEmail(checkForm,checkField){
	var tempStr=trim(document.forms[checkForm].elements[checkField].value);	
	var cCheck, etCount=0, nIndex, etIndex=-1;
	for(nIndex=0; nIndex<tempStr.length; nIndex++)
	{
		cCheck=tempStr.charAt(nIndex);
		if (!(((cCheck>='0') && (cCheck<='9')) || ((cCheck>='a') && (cCheck<='z')) || ((cCheck>='A') && (cCheck<='Z')) || (cCheck=='-') || (cCheck=='_') || (cCheck=='.') || (cCheck=='@')))
		{
			alert("You Can Only Use Digit, Alphabet, '-', '_', and '.'");
			document.forms[checkForm].elements[checkField].focus();
			return false;
		}
		if (cCheck=='@')
		{
			if ((etIndex>0) || (nIndex==0) || (tempStr.charAt(nIndex+1)=='.')) 
			{
				alert("Please Input a Valid Email Address!");
				document.forms[checkForm].elements[checkField].focus();
				return false;
			}
			etIndex=nIndex;
		}
		if(cCheck=='.')
		{
			if ((nIndex>etIndex) && (tempStr.charAt(nIndex+1)=='.') && (etIndex>0))
			{
				alert("Please Input a Valid Email Address!");
				document.forms[checkForm].elements[checkField].focus();
				return false;
			}
		}
		if ((cCheck=='.') && (nIndex==(tempStr.length-1)))
		{
				alert("请输入正确的邮件地址!");
				document.forms[checkForm].elements[checkField].focus();
				return false;
		}
	}
	return true;
}


