/*-------------------------------------------------------------------------------------
SPB Form Field Validation
	by: ian laurin
	modified: 8/9/04
Description:
	Netscape does not allow for try/catch or window.onerror=blockError; function blockError() {return true;}
------------------------------------------------------------------------------------
Validation Calls (input Objects) 
-------------------------------------------------------------------------------------*/	 
	//null
	function isNull(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(trim(o.value)!='') {e.innerHTML=''; return true;}   
		else {e.innerHTML="*Required Field!"; o.focus(); return false;}}
	//number
	function isNum(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(numChk(o.value)) {e.innerHTML=''; return true;}   
		else {e.innerHTML="*Required with Numbers!"; o.focus(); return false;}}
	//number or null	
	function isNumNull(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(numChk(o.value) || !nullChk(o.value)) {e.innerHTML=''; return true;}   
		else {e.innerHTML="*Required with Numbers or Blank!"; o.focus(); return false;}}
	//money 	
	function isMoney(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(moneyChk(o.value)) {e.innerHTML=''; return true;}  
		else {e.innerHTML="*Requires a Currency Format!"; o.focus(); return false;}}
	//money or null	
	function isMoneyNull(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(moneyChk(o.value) || !nullChk(o.value)) {e.innerHTML=''; return true;}  
		else {e.innerHTML="*Requires a Currency Format or Blank!"; o.focus(); return false;}}
	//zip or null (bad for cf all numbers check will not let this format pass)
	//function isZipNull(o, e) {
	//	o=eval("document.myForm."+o); e=document.getElementById(e);
	//	if(zipChk(o.value) || !nullChk(o.value)) {e.innerHTML=''; return true;}  
	//	else {e.innerHTML="*Requires a Zip Format or Blank!"; o.focus(); return false;}}
	//email 
	function isEmail(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(emailChk(o.value)) {e.innerHTML=''; return true;}   
		else {e.innerHTML="*Requires an Email Format!"; o.focus(); return false;}}
	//email or null	
	function isEmailNull(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(emailChk(o.value) || !nullChk(o.value)) {e.innerHTML=''; return true;}  
		else {e.innerHTML="*Requires an Email Format or Blank!"; o.focus(); return false;}}
	//date
	function isDate(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(dateChk(o.value)) {e.innerHTML=''; return true;}  
		else {e.innerHTML="*Requires a valid date (mm/dd/yyyy)!"; o.focus(); return false;}}
	//date or null
	function isDateNull(o, e) {
		o=eval("document.myForm."+o); e=document.getElementById(e);
		if(dateChk(o.value)  || !nullChk(o.value)) {e.innerHTML=''; return true;}  
		else {e.innerHTML="*Requires a valid date (mm/dd/yyyy)!"; o.focus(); return false;}}
/*-------------------------------------------------------------------------------------
Special Cases (input Objects)
-------------------------------------------------------------------------------------*/	 
	//ssn
	function isSsnNull(o1,o2,o3, e) {
	o1=eval("document.myForm."+o1); o2=eval("document.myForm."+o2);
	o3=eval("document.myForm."+o3); e=document.getElementById(e);
	o1=o1.value; o2=o2.value; o3=o3.value;
	if(((trim(o1).length==3) && numChk(o1) && (trim(o2).length==2) && numChk(o2) && (trim(o3).length==4) && numChk(o3)) ||  
		(!nullChk(o1) && !nullChk(o2) && !nullChk(o3))) {e.innerHTML=''; return true;}   
		else {o1.focus; e.innerHTML="*SSN must be 9 digits or blank!"; return false;}}
	//textarea counter
	function tarCount(o, oCounter, oMax) {
		o=eval("document.myForm."+o); oCounter=eval("document.myForm."+oCounter);
		var oUsed=o.value.length, oOver=0;
		if(oUsed>oMax) {o.value=o.value.substring(0,(oMax-oOver)); //See if pasting is too long and trim it
			oCounter.value=0; o.focus();
			alert("Your text has been truncated at the end to fit the the "+oMax+" character limit!");	
		} else oCounter.value=oMax-oUsed;} //if not over update counter
/*-------------------------------------------------------------------------------------
Special Text Modifying Functions (input Value)
-------------------------------------------------------------------------------------*/	 
	function trim(v) {
		while(v.substring(0,1)==' ') {v=v.substring(1,v.length);}
		while(v.substring(v.length-1,v.length)==' ') {v=v.substring(0,v.length-1);} return v;}
	function removeChar(v,bad) {	//v=string, bad=remove 
		var str='', c=''; for(var i=0; i<v.length; i++) {c=v.charAt(i); if(bad.indexOf(c)==-1) str+=c;}	return str;}
/*-------------------------------------------------------------------------------------
Datatype Boolean Functions (input Value)
-------------------------------------------------------------------------------------*/	 
	//Null 	
	function nullChk(v) {if(trim(v)!='') return true; else return false;}
	//Number
	function numChk(v) {while(v.indexOf(",")!=-1) v=v.replace(",", "");
	if(!isNaN(v) && v.indexOf("e")==-1 && nullChk(v)) return true; else return false;}
	//Money
	function moneyChk(v) {if(v.indexOf("$")!=-1) v=v.replace("$", ""); 
		while(v.indexOf(",")!=-1) v=v.replace(",", ""); if(numChk(v)) return true; else return false;}
	//Zip
	function zipChk(v) {var vFormat=/^(\d{5}(-\d{4})?)$/;
		if(vFormat.test(v)) return true; else return false;}		
	//Email 
	function emailChk(v) {var vFormat=/^\w(\.?\w)*@\w(\.?[-\w])*\.([a-z]{3}(\.[a-z]{2})?|[a-z]{2}(\.[a-z]{2})?)$/i
		if((vFormat.test(v)==true) && (v.indexOf("www.")==-1)) return true; else return false;}		
	//Date
	function dateChk(v) { //M=month, D=day, Y=year, p1/p2=digit spacers, t=temp numChk
		var p1, p2, e='', t='';
		if(v.indexOf("/")!=-1) {p1=v.indexOf("/"); p2=v.indexOf("/",p1+1); t=removeChar(v,"/");} 
		else {p1=v.indexOf("-"); p2=v.indexOf("-",p1+1); t=removeChar(v,"-");}
		if(p1==-1 || p2==-1 || !numChk(t)) return false; 
		M=parseInt(v.substring(0,p1)); D=parseInt(v.substring(p1+1,p2)); Y=parseInt(v.substring(p2+1));
		if(M==0) M=parseInt(v.substring(1,p1)); 
		if((M<1 || M>12) || (M==2 && D>(Y%4==0?29:28))) return false; 
		if((D<1 || D>31) || (D>30 && (M==4 || M==6 || M==9 || M==11))) return false;
		if((Y<100?Y=2000+Y:Y) && Y<2000 || Y>2100) return false;
		return true;}
	
