function leftString(InString,num)
{OutString=InString.substring(0,num);return(OutString);}
function rightString(InString,num)
{OutString=InString.substring(InString.length-num,InString.length);return(OutString);}
function isblank(s)
{for(var i=0;i<s.length;i++)
{var c=s.charAt(i);if((c!=' '))return false;}
return true;}
function allowNotInString(InString,RefString)
{for(Count=0;Count<InString.length;Count++)
{TempChar=InString.substring(Count,Count+1);if(RefString.indexOf(TempChar,0)!=-1)
return(false);}
return(true);}
function isNumberString(InString)
{if(InString.length==0)
return(false);RefString="1234567890";for(Count=0;Count<InString.length;Count++)
{TempChar=InString.substring(Count,Count+1);if(RefString.indexOf(TempChar,0)==-1)
return(false);}
return(true);}
function isFloatingPoint(InString)
{if(InString.length==0)
return(false);TempChar=InString.substring(InString.length-3,InString.length-2);if(TempChar!=".")
return(false);RefString="1234567890.";for(Count=0;Count<InString.length;Count++)
{TempChar=InString.substring(Count,Count+1);if(RefString.indexOf(TempChar,0)==-1)
return(false);}
return(true);}
function isWithinRange(InString,RangeMin,RangeMax)
{if((InString==null)||(InString==""))
return(false)
if((InString>=RangeMin)&&(InString<=RangeMax))
return(true);else
return(false);}
function isUSZip(InString)
{if(InString.length==0)
return(false);if((InString.length!=5)&&(InString.length!=10))
return(false);RefString="1234567890-";for(Count=0;Count<InString.length;Count++){TempChar=InString.substring(Count,Count+1);if(RefString.indexOf(TempChar,0)==-1)
return(false);}
return(true);}
function isValidEmail(InString)
{if(InString.length==0)
return(false);if((InString.indexOf('@')==-1)||(InString.indexOf('@')!=InString.lastIndexOf('@')))
return(false);if(InString.indexOf('.')==-1)
return(false);if((InString.lastIndexOf('.'))<(InString.indexOf('@')))
return(false);return(true);}
function verify_isDate(value)
{return(!isNaN(new Date(value.replace('/-/g',"/")).getYear()));}
function verify_isTime(value,mask){if(verify_isHour(value,mask)&&verify_isMinute(value)&&value.indexOf(":")){return true;}else{return false;}}
function verify_isHour(value,mask){var h=value.split(':')[0];var hourMask=mask.split(':')[0];if(hourMask.indexOf('H')>=0){if(h<=24&&h>=0){return true;}else{return false;}}else if(h<13&&h>0){return true;}else{return false;}}
function verify_isMinute(value){var m=value.split(':')[1];m=m.split(' ')[0];if(m<60&&m.length==2){return true;}else{return false;}}
var listOfTypes=new Array();function fieldType(Name,DataType,Mandatory,PrettyName,CharsNot,Mask)
{this.name=Name;this.type=DataType;this.mandatory=Mandatory;this.prettyname=PrettyName;this.charsnot=CharsNot;this.mask=Mask
listOfTypes[count]=this;count++;}
function removeField(Name){for(var i=0;i<listOfTypes.length;i++){if(listOfTypes[i].name==Name){listOfTypes.splice(i,1);count--;return true;}}}
var invalid=new Array();function invalidField(Name,PrettyName,message)
{this.name=Name;this.message=message;this.prettyname=PrettyName;return this;}
function verify(f,formAction){var msg="";var typeFields="";var mandatoryFields="";var TempString="";var dateField="";var timeField="";var nameField="";var radioCheck="";var radioError="";var fieldType="";var passWordStore="";var invalid=[];if(formAction!="submit"){f.elements.formAction.value=formAction;}
for(i=0;i<f.elements.length;i++){var formElement=f.elements[i];for(c=0;c<count;c++){var typeElement=listOfTypes[c];TempString=formElement.name;TempString2=typeElement.name;nameField=TempString.substring(0,TempString2.length);if(nameField==typeElement.name){if((typeElement.type==1)&&(formElement.value!="")&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(!isNumberString(formElement.value)){typeFields+="<li>Atleast one of the \""+typeElement.prettyname+"\" field is empty or is not a whole number</li>";typeFields+=".<br />";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"At least one of the \""+typeElement.prettyname+"\" fields is empty or is not a whole number");count2++;}}
if((typeElement.type==1)&&(typeElement.mandatory=="T")&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value!=""){if(!isNumberString(formElement.value)){typeFields+="<li>Atleast one of the \""+typeElement.prettyname+"\" field is empty or is not a whole number</li>";typeFields+=".<br />";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"At least one of the \""+typeElement.prettyname+"\" fields is empty or is not a whole number");count2++;}}else{mandatoryFields+="     "+typeElement.prettyname;mandatoryFields+=".<br />";}}
if((typeElement.type==2)&&(formElement.value!="")&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(!isUSZip(formElement.value)){typeFields+="<li><h2>- The \""+typeElement.prettyname+"\" field ";typeFields+="must contain a valid Postal Code (5 numbers)</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The \""+typeElement.prettyname+"\" field must contain a valid Postal Code (5 numbers)");count2++;}}
if((typeElement.type==2)&&(typeElement.mandatory=="T")&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value!=""){if(!isUSZip(formElement.value)){typeFields+="<li><h2>- The \""+typeElement.prettyname+"\" field";typeFields+="must contain a valid Postal Code (5 numbers)</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The \""+typeElement.prettyname+"\" field must contain a valid Postal Code (5 numbers)");count2++;}}else{mandatoryFields+="     "+typeElement.prettyname;mandatoryFields+=".<br />";}}
if((typeElement.type==3)&&(formElement.value!="")&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(!allowNotInString(formElement.value,typeElement.charsnot)){typeFields+="<li><h2>- The \""+typeElement.prettyname+"\" field";typeFields+=" cannot contain the following characters:</h2><ul>";typeFields+="<li>   "+typeElement.charsnot+"</li>";typeFields+="</ul></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The \""+typeElement.prettyname+"\" field cannot contain the following characters:<ul><li>   "+typeElement.charsnot+"</li></ul></li>");count2++;}}
if((typeElement.type==3)&&(typeElement.mandatory=="T")&&(typeFields.indexOf(typeElement.prettyname)==-1)&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value!=""){if(allowNotInString(formElement.value,typeElement.charsnot)==false){typeFields+="<li><h2>- The \""+typeElement.prettyname+"\" field";typeFields+=" cannot contain the following characters:</h2><ul>";typeFields+="<li>   "+typeElement.charsnot+"</li>";typeFields+="</ul></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The \""+typeElement.prettyname+"\" field cannot contain the following characters:<ul><li>   "+typeElement.charsnot+"</li></ul></li>");count2++;}}else{mandatoryFields+="     <li>"+typeElement.prettyname;mandatoryFields+="</li>";}}
if((typeElement.type==4)&&(formElement.value!="")&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){dateField=verify_isDate(formElement.value);if(!dateField){typeFields+="<li><h2>- Please specify a valid date for ";typeFields+=typeElement.prettyname+".</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"Please specify a valid date for");count2++;}}
if((typeElement.type==4)&&(typeElement.mandatory=="T")&&(typeFields.indexOf(typeElement.prettyname)==-1)&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value!=""){dateField=verify_isDate(formElement.value);if(dateField=="wrongFormat"){typeFields+="<li><h2>- The \""+typeElement.prettyname+"\" field";typeFields+="must be of the form mm-dd-yyyy.</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The \""+typeElement.prettyname+"\ field must be of the form mm-dd-yyyy.");count2++;}
if(dateField=="wrongMonth"){typeFields+="<li><h2>- Please specify a valid month for ";typeFields+=typeElement.prettyname+".</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"Please specify a valid month for "+typeElement.prettyname);count2++;}
if(dateField=="invalidDate"){typeFields+="<li><h2>- Please specify a valid date for ";typeFields+=typeElement.prettyname+".</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"Please specify a valid date for "+typeElement.prettyname);count2++;}
if(dateField=="notNumber"){typeFields+="<li><h2>- The \""+typeElement.prettyname+"\" field";typeFields+=" must contain only numbers and separators.</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The "+typeElement.prettyname+" field must contain only numbers and separators.");count2++;}
if((dateField!="wrongFormat")&&(dateField!="notNumber")&&(dateField!="wrongMonth")&&(dateField!="invalidDate")){}}else{mandatoryFields+="<li class='child'>"+typeElement.prettyname;mandatoryFields+="</li>";}}
if((typeElement.type==12)&&(formElement.value!="")&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){timeField=verify_isTime(formElement.value,typeElement.mask);if(!timeField){typeFields+="<li><h2>- Please specify a valid time for ";typeFields+=typeElement.prettyname+".</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"Please specify a valid time for");count2++;}}
if((typeElement.type==12)&&(typeElement.mandatory=="T")&&(typeFields.indexOf(typeElement.prettyname)==-1)&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value!=""){timeField=verify_isTime(formElement.value,typeElement.mask);if(!timeField){typeFields+="<li><h2>- The \""+typeElement.prettyname+"\" field";typeFields+="must be of the form "+typeElement.mask+".</h2></li>";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The "+typeElement.prettyname+" field must be in hh:mm am/pm format.");count2++;}}else{mandatoryFields+="<li class='child'>"+typeElement.prettyname;mandatoryFields+="</li>";}}
if((typeElement.type==5)&&(typeElement.mandatory=="T")){if((formElement.selectedIndex==0)||(formElement.selectedIndex==null)){mandatoryFields+="<li class='child'>"+typeElement.prettyname;mandatoryFields+="</li>";}}
if((typeElement.type==6)&&((formElement.value=="")||(formElement.value==null))&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)){mandatoryFields+="<li class='child'>"+typeElement.prettyname;mandatoryFields+="</li>";}
if((typeElement.type==7)&&(typeElement.charsnot!="")){for(Count=0;Count<f.elements.length;Count++){if(formElement.checked){radioCheck="true";break;}}
radioError="- A "+typeElement.prettyname+" must be selected.<br />";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"A "+typeElement.prettyname+" must be selected.");count2++;}
if((typeElement.type==8)&&(typeElement.mandatory=="T")&&(typeFields.indexOf(typeElement.prettyname)==-1)&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value==""){mandatoryFields+="<li class='child'>"+typeElement.prettyname;mandatoryFields+="</li>";}
if((formElement.value!="")&&(formElement.value.length<6)){typeFields+="- The \""+typeElement.prettyname+"\" field";typeFields+=" must be longer than 5 characters.<br />";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The "+typeElement.prettyname+" must be longer than 5 characters.");count2++;}
if((formElement.value.length>=6)&&(passWordStore=="")){passWordStore=formElement.value;}
if((formElement.value.length>=6)&&(passWordStore!="")){if(formElement.value!=passWordStore){typeFields+="- The \""+typeElement.prettyname+"\" fields";typeFields+=" do not match. Please try again.<br />";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The "+typeElement.prettyname+" do not match. Please try again.");count2++;}}}
if((typeElement.type==8)&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){if((formElement.value!="")&&(formElement.value.length<6)){typeFields+="- The \""+typeElement.prettyname+"\" field";typeFields+=" must be longer than 5 characters.<br />";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The "+typeElement.prettyname+" must be longer than 5 characters.");count2++;}
if((formElement.value.length>=6)&&(passWordStore=="")){passWordStore=formElement.value;}
if((formElement.value.length>=6)&&(passWordStore!="")){if(formElement.value!=passWordStore){typeFields+="- The \""+typeElement.prettyname+"\" fields";typeFields+=" do not match. Please try again.<br />";invalid[count2]=invalidField(typeElement.name,typeElement.prettyname,"The "+typeElement.prettyname+" do not match. Please try again.");count2++;}}}
if((typeElement.type==9)&&(formElement.value!="")&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(!isValidEmail(formElement.value)){typeFields+="- A valid \""+typeElement.prettyname+"\" field ";typeFields+=" must have '@' and '.'";typeFields+=".<br />";}}
if((typeElement.type==9)&&(typeElement.mandatory=="T")&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value!=""){if(!isValidEmail(formElement.value)){typeFields+="- A Valid \""+typeElement.prettyname+"\" field";typeFields+=" must have '@' and '.'";typeFields+=".<br />";}}else{mandatoryFields+="     "+typeElement.prettyname;mandatoryFields+=".<br />";}}
if((typeElement.type==10)&&(formElement.value!="")&&(typeElement.mandatory=="F")&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(!isFloatingPoint(formElement.value)){typeFields+="Atleast one of the \""+typeElement.prettyname+"\" field is empty or is not a floating point number";typeFields+=".<br />";}}
if((typeElement.type==10)&&(typeElement.mandatory=="T")&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)&&(typeFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value!=""){if(!isFloatingPoint(formElement.value)){typeFields+="Atleast one of the \""+typeElement.prettyname+"\" field is empty or is not a floating point number";typeFields+=".<br />";}}else{mandatoryFields+="     "+typeElement.prettyname;mandatoryFields+=".<br />";}}
if((typeElement.type==11)&&(typeElement.mandatory=="T")&&(typeFields.indexOf(typeElement.prettyname)==-1)&&(mandatoryFields.indexOf(typeElement.prettyname)==-1)){if(formElement.value==""){mandatoryFields+="     "+typeElement.prettyname;mandatoryFields+=".<br />";}
if((formElement.value!="")&&(formElement.value.length<6)){typeFields+="<li>- The \""+typeElement.prettyname+"\" field";typeFields+=" must be longer than 5 characters.</li>";}}}}}
if(!mandatoryFields&&!typeFields&&(!radioError||radioCheck)&&!invalid.length)return true;msg+="<h1>Please correct the following error(s) and re-submit.</h1>";msg+="<hr />";if(mandatoryFields)
{msg+="<li><h2>- These required field(s) are empty:</h2></li>"
+mandatoryFields+"<br />";}
if(typeFields)
{msg+=typeFields+"<br />";}
if(!radioCheck&&radioError)
{msg+=radioError+"<br />";}
if(mandatoryFields||typeFields||(radioError&&!radioCheck)||invalid.length)
{var test=new Object();test.msg=msg;test.invalid=invalid;count2=0;return test;}else{var test=new Object();test.msg='';test.invalid='';return test;}}
var numeric="1";var zip="2";var chars="3";var date="4";var select="5";var mandatoryOnly="6";var radio="7";var passwd="8";var email="9";var floatingPoint="10";var username="11";var time="12";var array=new Object();var count=0;var count2=0;
