var nbsp=160;var node_text=3;var emptyString=/^\s*$/;var glb_vfld;var minYear=1900;var maxYear=2100;function trim(str){return str.replace(/^\s+|\s+$/g,'');}
function isInteger(s){var i;for(i=0;i<s.length;i++){var c=s.charAt(i);if(((c<"0")||(c>"9")))return false;}
return true;}
function stripCharsInBag(s,bag){var i;var returnString="";for(i=0;i<s.length;i++){var c=s.charAt(i);if(bag.indexOf(c)==-1)returnString+=c;}
return returnString;}
function daysInFebruary(year){return(((year%4==0)&&((!(year%100==0))||(year%400==0)))?29:28);}
function DaysArray(n){for(var i=1;i<=n;i++){this[i]=31
if(i==4||i==6||i==9||i==11){this[i]=30;}
if(i==2){this[i]=29;}}
return this;}
function setFocusDelayed(){glb_vfld.focus();}
function setfocus(vfld){glb_vfld=vfld;setTimeout('setFocusDelayed()',100);}
function msg(fld,msgtype,message)
{var elem=document.getElementById(fld);if((fld==null)||(elem==null))return;var dispmessage;if(emptyString.test(message))
dispmessage=String.fromCharCode(nbsp);else
dispmessage=message;var elem=document.getElementById(fld);if(elem!=null){elem.firstChild.nodeValue=dispmessage;}};var proceed=2;function commonCheck(vfld,ifld,reqd)
{if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
return proceed;}
function setValidationError(vfld,ifld){msg(ifld,"error","*");setfocus(vfld);}
function clearValidationError(ifld){msg(ifld,"warn","");}
function validatePresent(vfld,ifld)
{var stat=commonCheck(vfld,ifld,true);if(stat!=proceed)return stat;msg(ifld,"warn","");return true;};function validateSet(vfld,ifld)
{if((vfld.value==0)||(vfld.value==-1)){msg(ifld,"error","*");return false;}
else{msg(ifld,"warn","");return true;}};function checkEmail(vfld,ifld,reqd){var emailFilter=/^.+@.+\..{2,3}$/;var illegalChars=/[\(\)\<\>\,\;\:\\\"\[\]]/;if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
if(!(emailFilter.test(vfld.value))){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","*");return false;}}
if(vfld.value.match(illegalChars)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
msg(ifld,"warn","");return true;}
function checkCurrency(vfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
num=vfld.value.toString().replace(/\$|\,/g,'');if(isNaN(num)){num="0";}
sign=(num==(num=Math.abs(num)));num=Math.floor(num*100+0.50000000001);cents=num%100;num=Math.floor(num/100).toString();if(cents<10){cents="0"+cents;}
value=parseFloat(num+'.'+cents);if(value<=0){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
msg(ifld,"warn","");return true;}
function checkPhone(vfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
var strng=vfld.value;var stripped=strng.replace(/[\(\)\.\-\ ]/g,'');if(isNaN(parseInt(stripped))){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","*");return false;}}
if(stripped.length!=10){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
msg(ifld,"warn","");return true;}
function checkPassword(vfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}}else{if(vfld.value.length<4){msg(ifld,"error","not long enough");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}}
function checkPassword2(vfld,cfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}}else{if(vfld.value!=cfld.value){msg(ifld,"error","does not match");setfocus(vfld);return false;}else{msg(ifld,"warn","");return true;}}}
function checkDropdown(vfld,ifld,reqd,checkvalue){if(!document.getElementById)
return true;if(vfld.value==checkvalue){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
msg(ifld,"warn","");return true;}
function checkCheckBox(vfld,ifld,reqd){if(!document.getElementById)
return true;if(vfld.checked==false){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
msg(ifld,"warn","");return true;}
function checkNumber(vfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}}else{if(parseInt(vfld.value)<1){msg(ifld,"error","*");setfocus(vfld);return false;}else{msg(ifld,"warn","");return true;}}}
function checkFloat(vfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
num=vfld.value.toString().replace(/\,/g,'');if(isNaN(num)){num="0";}
sign=(num==(num=Math.abs(num)));num=Math.floor(num*100+0.50000000001);decimals=num%100;num=Math.floor(num/100).toString();if(decimals<10){decimals="0"+decimals;}
value=parseFloat(num+'.'+decimals);if(value<=0){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
msg(ifld,"warn","");return true;}
function checkPhone(vfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
var strng=vfld.value;var stripped=strng.replace(/[\(\)\.\-\ ]/g,'');if(isNaN(parseInt(stripped))){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","*");return false;}}
if(stripped.length!=10){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}
else{msg(ifld,"warn","");return true;}}
msg(ifld,"warn","");return true;}
function checkEmail2(vfld,cfld,ifld,reqd){if(!document.getElementById)
return true;if(emptyString.test(vfld.value)){if(reqd){msg(ifld,"error","*");setfocus(vfld);return false;}}else{if(vfld.value!=cfld.value){msg(ifld,"error","does not match");setfocus(vfld);return false;}else{msg(ifld,"warn","");return true;}}}
function checkDate(vfld,ifld,reqd){if(!document.getElementById)
return true;if(!reqd&&(vfld.value.length==0)){return true;}
var dtStr=vfld.value;var daysInMonth=DaysArray(12);var dtCh="";if(dtStr.indexOf("/")!=-1){dtCh="/";}else{dtCh="-";}
var pos1=dtStr.indexOf(dtCh);var pos2=dtStr.indexOf(dtCh,pos1+1);var strMonth=dtStr.substring(0,pos1);var strDay=dtStr.substring(pos1+1,pos2);var strYear=dtStr.substring(pos2+1);strYr=strYear;if((strDay.charAt(0)=="0")&&(strDay.length>1))strDay=strDay.substring(1);if((strMonth.charAt(0)=="0")&&(strMonth.length>1))strMonth=strMonth.substring(1);for(var i=1;i<=3;i++){if(strYr.charAt(0)=="0"&&strYr.length>1)strYr=strYr.substring(1);}
month=parseInt(strMonth);day=parseInt(strDay);year=parseInt(strYr);if((pos1==-1)||(pos2==-1)){msg(ifld,"error","*");setfocus(vfld);return false;}
if((strMonth.length<1)||(month<1)||(month>12)){msg(ifld,"error","*");setfocus(vfld);return false;}
if((strDay.length<1)||(day<1)||(day>31)||((month==2)&&(day>daysInFebruary(year)))||(day>daysInMonth[month])){msg(ifld,"error","*");setfocus(vfld);return false;}
if((strYear.length!=4)||(year==0)||(year<minYear)||(year>maxYear)){msg(ifld,"error","*");setfocus(vfld);return false;}
if((dtStr.indexOf(dtCh,pos2+1)!=-1)||(isInteger(stripCharsInBag(dtStr,dtCh))==false)){msg(ifld,"error","*");setfocus(vfld);return false;}
return true;}
function parseDate(dtStr){var daysInMonth=DaysArray(12);var dtCh="";if(dtStr.indexOf("/")!=-1){dtCh="/";}else{dtCh="-";}
var pos1=dtStr.indexOf(dtCh);var pos2=dtStr.indexOf(dtCh,pos1+1);var strMonth=dtStr.substring(0,pos1);var strDay=dtStr.substring(pos1+1,pos2);var strYear=dtStr.substring(pos2+1);strYr=strYear;if((strDay.charAt(0)=="0")&&(strDay.length>1))strDay=strDay.substring(1);if((strMonth.charAt(0)=="0")&&(strMonth.length>1))strMonth=strMonth.substring(1);for(var i=1;i<=3;i++){if(strYr.charAt(0)=="0"&&strYr.length>1)strYr=strYr.substring(1);}
return new Date(parseInt(strYr),parseInt(strMonth),parseInt(strDay));}
function compareDates(vfld1,ifld1,reqd1,vfld2,ifld2,reqd2){var ret=checkDate(vfld1,ifld1,reqd1);if(ret&&(!emptyString.test(vfld2.value))){ret=checkDate(vfld2,ifld2,reqd2);if(ret){ret=parseDate(vfld1.value)<=parseDate(vfld2.value);if(!ret){msg(ifld2,"error","*");setfocus(vfld2);}}}
return ret;}
