
function isNumeric(strText,allowNeg)
{if(allowNeg)
return/^[+-]?\d+(\.\d+)?$/.test(strText);else
return/^\d+(\.\d+)?$/.test(strText);}
function isRightStr(strText,strValidate)
{var i;for(var i=0;i<strText.length;i++)
if(strValidate.indexOf(strText.substring(i,i+1))<0)
return false;return true;}
function packAllSpace(str)
{var strTemp,ch
var i,lenOfString
strTemp="";lenOfString=str.length;for(i=0;i<lenOfString;i++)
if(str.charAt(i)!=" ")
strTemp=strTemp+str.charAt(i);return strTemp;}
var g_iYear,g_iMonth,g_iDay,g_strDate;function getDate(strDateIn,strFormatIn)
{var strTemp,ch1,ch2
var i,j,k,lenOfFormat,lenOfDate
var bYear,bMonth,bDay
strDate=packAllSpace(strDateIn);strFormat=packAllSpace(strFormatIn);bYear=bMonth=bDay=false;g_strDate="";lenOfDate=strDate.length;lenOfFormat=strFormat.length;j=0;for(i=0;i<lenOfFormat;i++){ch1=strFormat.charAt(i);if(ch1=="Y"||ch1=="y"){strTemp="";for(k=0;k<4;k++){ch2=strDate.charAt(j);if(ch2<"0"||ch2>"9")
break;j++;if(!(strTemp==""&&ch2=="0"))
strTemp=strTemp+ch2;}
if(!k)
return false;g_iYear=parseInt(strTemp);if(ch1=="Y")
if(g_iYear<30)
g_iYear=g_iYear+2000;else if(g_iYear<100)
g_iYear=g_iYear+1900;bYear=true;g_strDate=g_strDate+g_iYear;}
else if(ch1=="M"||ch1=="m"){strTemp="";for(k=0;k<2;k++){ch2=strDate.charAt(j);if(ch2<"0"||ch2>"9")
break;j++;if(!(strTemp==""&&ch2=="0"))
strTemp=strTemp+ch2;}
if(!k)
return false;g_iMonth=parseInt(strTemp);if(g_iMonth>12||g_iMonth<1)
return false;bMonth=true;g_strDate=g_strDate+g_iMonth;}
else if(ch1=="D"||ch1=="d"){strTemp="";for(k=0;k<2;k++){ch2=strDate.charAt(j);if(ch2<"0"||ch2>"9")
break;j++;if(!(strTemp==""&&ch2=="0"))
strTemp=strTemp+ch2;}
if(!k)
return false;g_iDay=parseInt(strTemp);if(g_iDay>31||g_iDay<1)
return false;bDay=true;g_strDate=g_strDate+g_iDay;}
else{ch2=strDate.charAt(j);j++;if(ch2!=ch1)
return false;g_strDate=g_strDate+ch1;}}
if(bYear&&bMonth&&bDay){switch(g_iMonth){case 2:if(0==g_iYear%4){if(g_iDay>29)
return false;if((0==g_iYear%100)&&(0!=g_iYear%8))
if(g_iDay>28)
return false;}
else
if(g_iDay>28)
return false;break;case 4:case 6:case 9:case 11:if(g_iDay>30)
return false;}}
return true;}
function isEmpty(str)
{if(str.length==0)
return true;return false;}
function chkboxSelectedCount(objForm,strName)
{var i;var count
count=0;for(i=objForm.length-1;i>=0;i--)
if(objForm.elements[i].type=="checkbox"&&objForm.elements[i].name==strName)
if(objForm.elements[i].checked)
count++;return count;}
function setChkboxMulti(objForm,strName,isChecked)
{var i;for(i=objForm.length-1;i>=0;i--)
if(objForm.elements[i].type=="checkbox"&&objForm.elements[i].name==strName)
objForm.elements[i].checked=isChecked;}
var g_bValid;var g_objError;var g_strErrMsg;function validateCond(cond,obj,strMsg)
{if(!g_bValid)
return;if(!cond){g_bValid=false;g_objError=obj;g_strErrMsg=strMsg;}}
function validateEmpty(objText,strMsg)
{if(!g_bValid)
return;if(isEmpty(objText.value)){g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}}
function validateEmptyWithoutSpace(objText,strMsg)
{if(!g_bValid)
return;if(/^\s*$/.test(objText.value)){g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}}
function validateLength(objText,len,strMsg)
{if(!g_bValid)
return;if(objText.value.length<len){g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}}
function validateNum(objText,bAllowNull,strMsg,allowNeg)
{if(!g_bValid)
return;if(isEmpty(objText.value))
if(bAllowNull)
return;else{g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}
if(!isNumeric(objText.value,allowNeg)){g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}}
function validateDate(objText,bAllowNull,strFormat,strMsg)
{if(!g_bValid)
return;if(isEmpty(objText.value))
if(bAllowNull)
return;else{g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}
if(!getDate(objText.value,strFormat)){g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}
else
objText.value=g_strDate;}
function validateEmail(objText,bAllowNull,strMsg)
{if(!g_bValid)
return;if(isEmpty(objText.value))
if(bAllowNull)
return;if(!/^\w+([-+.]\w+)*@{1}\w+([-.]\w+)*\.[a-zA-Z]{2,3}$/.test(objText.value)){g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}}
function validateString(objText,strValidat,strMsg)
{var i;if(!g_bValid)
return;if(isEmpty(objText.value))
return;if(!isRightStr(objText.value,strValidat)){g_bValid=false;g_objError=objText;g_strErrMsg=strMsg;}}
function validateBegin()
{g_bValid=true;}
function validateEnd()
{if(!g_bValid){alert(g_strErrMsg);if(g_objError.type=="text")
g_objError.select();g_objError.focus();}
return g_bValid;}