function DelDash(str){	var splitString;splitString = str.split("-");return splitString.join(""); }
function DelSpace(str){	var splitString;splitString = str.split(" ");return splitString.join(""); }
function IsNR(str){return(DelSpace(str)!="")&&(!(isNaN(str)))}
function IsNP(str){return(DelSpace(str)!="")&&(!(isNaN(str)))&&(DelSpace(str).charAt(0)!="-")&&(DelSpace(str).charAt(0)!="0")}
function IsNI(str){return(DelSpace(str)!="")&&(!(isNaN(str)))&&(str.indexOf(".")==-1)}
function IsNN(str){return(DelSpace(str)!="")&&(!(isNaN(str)))&&(str.indexOf(".")==-1)&&(DelSpace(str).charAt(0)!="-")&&(DelSpace(str).charAt(0)!="0")}
function DateIsNotNum(str){return(DelSpace(str)!="")&&(isNaN(str))||(str.indexOf(".")!=-1)||(DelSpace(str).charAt(0)=="-")}
function CheckDate(strYear,strMonth,strDay)
{	var year = strYear;var month = strMonth;var day = strDay;
	if(parseInt(year)<=1900||parseInt(year)>2100||year.length<4||DateIsNotNum(year)){return(1)}
	if(parseInt(month)+100<=100|| month.length<1||parseInt(month)+100>112||DateIsNotNum(month)) { return (2) }
	if (parseInt(day)<=0||day.length<1||parseInt(day)>31||DateIsNotNum(day)){return(3)}
	if(parseInt(month)==2&&parseInt(day)>29){return(3)}
	if((year/4)!=Math.round(year/4)&&month==2&&day>28){return(3)}
	if((year/400)!=Math.round(year/400)&&(year/100)==Math.round(year/100)&&month==2&&day>28){return(3)}
	if((month==4&&day==31)||(month==6&&day==31)||(month==9&&day==31)||(month==11&&day==31)){return(3)}
	return 0;}
function CheckTime(strH,strM,strS)
{if(parseInt(strH)<0||parseInt(strH)>23||DateIsNotNum(strH)){return(1)}
if(parseInt(strM)<0||parseInt(strM)>59||DateIsNotNum(strM)){return(2)}
if(parseInt(strS)<0||parseInt(strS)>59||DateIsNotNum(strS)){return(3)}
return 0;}
function IsString(str){if(DelSpace(str)!=""){return true}return false;}
function IsEmail(str){if(str.match("^[^@]+@([a-zA-Z0-9\-]+[\.])+([a-zA-Z0-9\-])")){return true}return false;}
function IsNSpace(str){if((DelSpace(str)!="")&&(str.indexOf(" ")==-1)){return true}return false;}
function CheckCh(formName,elementName){var j;if((document.forms(formName)(elementName).length>0)==false){if(document.forms(formName)(elementName).checked==true){return true}return false}else{for (j=0;j<document.forms(formName)(elementName).length;j++){ if(document.forms(formName)(elementName)[j].checked==true){return true}}return false;}}
function CheckRd(formName,elementName){var j;if((document.forms(formName)(elementName).length>0)==false){if(document.forms(formName)(elementName).checked==true){return true}return false}else{for(j=0;j<document.forms(formName)(elementName).length;j++){if(document.forms(formName)(elementName)[j].checked==true){return true}}return false}}
function CheckSl(formName,elementName){	if (document.forms(formName)(elementName).selectedIndex==0){return false}return true}
function CheckTx(str){if(DelSpace(str)!=""){return true}return false}
function ErrorFind(formName,elementsIndex,errorMsg){window.alert(errorMsg);document.forms(formName).elements[elementsIndex].focus();return false;}
function DateErrorFind(formName,yearName,monthName,dayName,errorNum,errStr){switch (errorNum){case 1:{window.alert("Please input correct "+errStr+"year!");document.forms(formName)(yearName).focus();return false;break;}case 2:{window.alert("Please input correct "+errStr+"month!");document.forms(formName)(monthName).focus();return false;break;}case 3:{window.alert("Please input correct "+errStr+"day of the month!");document.forms(formName)(dayName).focus();return false;break;}}}
function TimeErrorFind(formName,yearName,monthName,dayName,errorNum){switch (errorNum){case 0:{return true;break;}case 1:{window.alert("Please input correct hour!");document.forms(formName)(yearName).focus();return false;break;}case 2:{window.alert("Please input correct minute");document.forms(formName)(monthName).focus();return false;break;}case 3:{window.alert("Please input correct second!");document.forms(formName)(dayName).focus();return false;break;}}}
function CheckInput(formName)
{	var tempFormName;var tempArr;var i;var tempCheckString;tempFormName=formName;i=0;   
	vlu='document.forms(tempFormName).elements[i].value'
	ele='document.forms(tempFormName).elements[i].';
	fms='document.forms(tempFormName)'
	for (i=0;i<eval(fms+'.length');i++)
	{	tempArr = eval(ele+'id.split(\"_\")');
		switch (eval(ele+'type'))
		{	case "text":
			{	
				tempCheckString="";
				if (("ac-se-ph-sn-ss-d1-d2-d3-nr-np-ni-nn-t1").indexOf(tempArr[1])!=-1){tempCheckString = tempArr[1]}else{tempNeedCheck=""}
				if ((("AC-SE-SN-SS-D1-D2-D3-NR-NP-NI-NN-T1").indexOf(tempArr[1])!=-1)&&(DelSpace(eval(vlu))!="")){tempCheckString = tempArr[1].toLowerCase()}else{tempNeedCheck=""}
				switch(tempCheckString)
				{				
				
					case "ac"://Zip Code - US format
					 {
						var str = document.forms(tempFormName).elements[i].value;						
						//int lengthOfElement = document.forms(tempFormName).elements[i].value.length;
						//alert (lengthOfElement);
						var splitString;
						splitString = str.split("-");						
						if (splitString[0].length != 5)
						{
							return ErrorFind(tempFormName,i,"Please enter a valid Zip Code \n\nFormat ''33701-4313'' or ''33701''")						
						}
						//if ((splitString[1].length != 4))
						//{			
						//		return ErrorFind(tempFormName,i," 2 What you enter in Zip Code field is not a Zip Code!")
						//}						
						if  (str.substring(0,5).length != 5)
						{
							return ErrorFind(tempFormName,i,"Please enter a valid Zip Code \n\nFormat ''33701-4313'' or ''33701''")
						}						
						if (str.substring(5,6) == "-")
						{
							if  (str.substring(6,10).length != 4)
							{
								return ErrorFind(tempFormName,i,"Please enter a valid Zip Code \n\nFormat ''33701-4313'' or ''33701''")
							}							
						}						
						if((DelSpace(DelDash(eval(vlu)))=="")||!(IsNN(DelDash(eval(vlu)))))
						{
							return ErrorFind(tempFormName,i,"Please enter a valid Zip Code \n\nFormat ''33701-4313'' or ''33701''")
						}
						break;
					}				
					
						
						
					case "se":
					{
						if(eval(vlu)=="")
						{
								return ErrorFind(tempFormName,i,"Please input "+tempArr[0]+"!")
								break;
						}
						
						if(!(IsEmail(eval(vlu))))
						{
								return ErrorFind(tempFormName,i,"The "+tempArr[0]+" is not correct!")
								break;
						}
						break;	
					}
					
					
					case "ph":{					
						if ((tempArr[2]=="Phone1") && (eval(fms+'(tempArr[2]).value').length < 3)) {
							return ErrorFind(tempFormName,i,"Please enter a valid "+tempArr[0]+" !")
							break;
						}
						if ((tempArr[2]=="Phone2") && (eval(fms+'(tempArr[2]).value').length < 3)) {
							return ErrorFind(tempFormName,i,"Please enter a valid "+tempArr[0]+" !")
							break;
						}
						if ((tempArr[2]=="Phone3") && (eval(fms+'(tempArr[2]).value').length < 4)) {
							return ErrorFind(tempFormName,i,"Please enter a valid "+tempArr[0]+" !")
							break;
						}
							
					}

					
									
					case "sn":{if(!(IsString(eval(vlu)))){return ErrorFind(tempFormName,i,"Please input "+tempArr[0]+"!")}break;}
					case "ss":{if(!(IsNSpace(eval(vlu)))){return ErrorFind(tempFormName,i,tempArr[0]+" space is not allowed!")}break;}
					case "d1":{var tempValue;tempValue=CheckDate(eval(fms+'(tempArr[2]).value'),eval(fms+'(tempArr[3]).value'),eval(fms+'(tempArr[4]).value'));if(tempValue > 0){return DateErrorFind(tempFormName,tempArr[2],tempArr[3],tempArr[4],tempValue,tempArr[0])}break;}
					case "d2":{var tempValue;tempValue=CheckDate(eval(fms+'(tempArr[2]).value'),eval(fms+'(tempArr[3]).value'),"1");if(tempValue > 0){return DateErrorFind(tempFormName,tempArr[2],tempArr[3],tempArr[4],tempValue,tempArr[0])}break;}
					case "d3":{var tempValue;tempValue=CheckDate(eval(fms+'(tempArr[2]).value'),"1","2");if(tempValue > 0){return DateErrorFind(tempFormName,tempArr[2],tempArr[3],tempArr[4],tempValue,tempArr[0])}break;}
					case "nr":{if((DelSpace(eval(vlu))=="")||!(IsNR(eval(vlu))) || (eval(vlu)==0)){return ErrorFind(tempFormName,i,"Please enter a numeric value between 1 - 99 for "+tempArr[0]+" !") }break;}
					case "np":{if((DelSpace(eval(vlu))=="")||!(IsNP(eval(vlu)))){return ErrorFind(tempFormName,i,"What you enter in "+tempArr[0]+" field is not a positive number!")}break;}
					case "ni":{if((DelSpace(eval(vlu))=="")||!(IsNI(eval(vlu)))){return ErrorFind(tempFormName,i,"Please enter a valid "+tempArr[0]+" !")}break;}
					case "nn":{if((DelSpace(eval(vlu))=="")||!(IsNN(eval(vlu)))){return ErrorFind(tempFormName,i,"What you enter in "+tempArr[0]+" field is not a positive integer!")}break;}
					case "t1":{return TimeErrorFind(tempFormName,tempArr[2],tempArr[3],tempArr[4],CheckTime(eval(fms+'(tempArr[2]).value'),eval(fms+'(tempArr[3]).value'),eval(fms+'(tempArr[4]).value')));break;}
					
					
				}
				break;
			}
			case "checkbox":{if(tempArr[1]=="ch"){if(!(CheckCh(tempFormName,eval(ele+'name')))){return ErrorFind(tempFormName,i,"Please select "+tempArr[0]+"!")}}break;}
			case "radio":{if(tempArr[1]=="rd"){if(!(CheckRd(tempFormName,eval(ele+'name')))){return ErrorFind(tempFormName,i,"Please select"+tempArr[0]+"!")}}break;}
			case "select-one":{if(tempArr[1]=="sl"){if(!(CheckSl(tempFormName,eval(ele+'name')))){return ErrorFind(tempFormName,i,"Please select "+tempArr[0]+"!")}}break;}
			case "textarea":{if(tempArr[1]=="tx"){if(!(CheckTx(eval(vlu)))){return ErrorFind(tempFormName,i,"Please select "+tempArr[0]+"!")}}break;}
			case "password":
			{	timpCheckString="";
				if (("pw-pwd").indexOf(tempArr[1])!=-1){tempCheckString = tempArr[1]}else{tempNeedCheck=""}
				switch(tempCheckString)
				{       
					case "pw":
				        {
				        	if(!(IsString(eval(vlu)))){return ErrorFind(tempFormName,i,"Please input "+tempArr[0]+"!")}
				        	if(tempArr[1]=="pw")
				        	{
				        		if(eval(fms+'.'+tempArr[2]+'.value')!=eval(fms+'.'+tempArr[3]+'.value'))
				        		{return ErrorFind(tempFormName,i,"The Password and Confirm Password fields do not match!")}
				        	}
				        	break
				        }
					
					case "pwd":{if(!(IsString(eval(vlu)))){return ErrorFind(tempFormName,i,"Please input "+tempArr[0]+" !")}break;}
				}
			}
			break;
		}
	}
	return true;
}