
/* Entire page (C) Copyright 2000-2004 Quick Technologies Inc.		*/
/* Copying or distribution of this proprietary source code is 		*/
/* STRICTLY prohibited.  											*/

function MinLen(fld,name,m)
{
	if (fld==null) return(true);
	s=Trim(fld.value);
	if (s.length>=m) return(true);
	if (s=="") 
		alert("Please fill in the \""+name+"\" field.");
	else 
		alert("Please enter at least "+m+" characters in the \""+name+"\" field.");
    fld.focus();
	return(false);
}

function Trim(fld)
{
	return(LeftTrim(RightTrim(fld,"")," "));
}

function LeftTrim(String,TrimChar)
{
 	String += "";		// Force argument to string.
 	TrimChar += "";		// Force argument to string.
	if ((TrimChar == "") || (!(TrimChar.length == 1))) {
		TrimChar = " ";
 	}
 	if (String.length==0) {
  		return(String);
	}
 	var Count;
 	for (Count = 0 ; Count<String.length ; Count++) {
  		if(!(String.charAt(Count) == TrimChar)) {
   			return(String.substring(Count,String.length));
		}
	}
	return("");
}
function RightTrim(String,TrimChar)
{
	String += ""        // Force argument to string.
 	TrimChar += ""      // Force argument to string.
 	if ((TrimChar == "") || (!(TrimChar.length == 1)))
  		TrimChar = " ";
 	if (String.length==0) {
  		return(String);
	}
 	var Count;
 	for (Count = String.length-1 ; Count>=0 ; Count--) {
		if (!(String.charAt(Count) == TrimChar)) {
			return(String.substring(0,Count+1));
		}
	}
	return("");
}

function MinNum(fld,name,m)
{
	if (fld==null) return(true);
	if (parseInt(fld.value)>=m) return(true);
	alert("The \""+name+"\" must be at least "+m+".");
    fld.focus();
	return(false);
}

function MaxNum(fld,name,m)
{
	if (fld==null) return(true);
	if (fld.value<=m) return(true);
	alert("The \""+name+"\" must be less than or equal to "+m+".");
    fld.focus();
	return(false);
}

function AllDigits(fld,name,allowdecimal)
{
	return(AllDigitsBase(fld,name,allowdecimal));
}

function IsNum(fld,name,allowdecimal)
{
	return(AllDigitsBase(fld,name,allowdecimal,true));
}

function AllDigitsBase(fld,name,allowdecimal,allowcomma)
{
	var chk = "0123456789";
	if (allowdecimal==true) chk=chk+".";
	if (allowcomma==true) chk=chk+",";
  	var valid = true;
	var decimals = 0;
  	if (fld==null) return(true);
  	for (i = 0 ; i < fld.value.length ; i++) {
    	ch = fld.value.charAt(i);
    	for (j = 0;  j < chk.length;  j++) {
      		if (ch == chk.charAt(j)) break;
		}
    	if (j == chk.length) {
      		valid = false;
      		break;
    	}
		if (ch=='.') decimals++;
		if (decimals>1) {
			valid=false;
			break;
		}
  	}
  	if (!valid) {
    	alert("Please enter only numbers in the \""+name+"\" field.");
    	fld.focus();
    	return (false);
  	}
  	else return(true);
}

function RequiredIfFilled(fld1,fld1name,fld2,fld2name)
{
	if (fld1==null || fld2==null) return(true);
	s=Trim(fld1.value);
	if (s.length==0) return(true);
	s=Trim(fld2.value);
	if (s.length>0) return(true);
	alert("Please fill in "+fld2name+" because you filled in "+fld1name+".");	
	fld2.focus();
	return(false);
}

function ValidateEmailAddr(fld,name,allowmultiple)
{
	var chk = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._@-&";
  	var valid = true;
  	if (fld==null || fld.value=="") return(true);
	var i=0;
	while (i<fld.value.length) {
		var atsign=0, period=0;
	  	for (i = i ; i < fld.value.length ; i++) {
	    	ch = fld.value.charAt(i);
			if (ch=='@') atsign++;
			else if (ch=='.') period++;
	    	for (j = 0;  j < chk.length;  j++) {
	      		if (ch == chk.charAt(j)) break;
			}
			if (allowmultiple && ch==',') {
				i++;
				while (i<fld.value.length && fld.value.charAt(i)==' ') {
					i++;
				}
				break;
			}
	    	else if (j == chk.length) {
	      		valid = false;
	      		break;
	    	}
	  	}
		if (atsign!=1 || period==0) valid=false;
	  	if (!valid) {
	    	alert("The email address you entered in the \""+name+"\" field is not valid.  You can only use letters, numbers, and periods.  In addition, there must be one '@' sign and no spaces in an email address.");
	    	fld.focus();
	    	return (false);
	  	}
	}
  	return(true);
}

function NoAngleBrackets(fld,name)
{
	var chk = "<>";
  	var valid = true;
  	if (fld==null) return(true);
  	for (i = 0 ; i < fld.value.length ; i++) {
    	ch = fld.value.charAt(i);
    	for (j = 0;  j < chk.length;  j++) {
      		if (ch == chk.charAt(j)) {
				valid = false;
				break;
			}
		}
  	}
  	if (!valid) {
    	alert("You cannot use '<' or '>' signs in the \""+name+"\" field.");
    	fld.focus();
    	return (false);
  	}
  	else return(true);
}

function CheckPass(p1,p2)
{
	if (p1==null) return(true);
	if (p2==null) return(true);
	if (p1.value==p2.value) return(true);
	alert("The new passwords you entered do not match.  Please re-type them.");
	p1.value="";
	p2.value="";
	p1.focus();
	return(false);
}

function CheckDate(mo,day,yr)
{
	var ok=true, leap, oddmo;
	
	leap=(yr%4==0);
	oddmo=(mo%2==1);
	if (mo<1 || mo>12) {
		ok=false;
	}
	else if ((day<1) ||
			 (mo<8 && oddmo && day>31) ||
			 (mo<8 && !oddmo && day>30) ||
			 (mo>7 && !oddmo && day>31) ||
			 (mo>7 && oddmo && day>30) ||
			 (mo==2 && !leap && day>28) ||
			 (mo==2 && leap && day>29)) {
		ok=false;
	}
	else if (yr.length!=2 && yr.length!=4) {
		ok=false;
	}
	else if (!(yr>=0 && yr<30) && !(yr>=2000 && yr<2030)) {
		ok=false;
	}
	return(ok);
}

function DateOk(fld,name)
{
	var chk="0123456789/";
  	var ok=true;
	var mo="", day="", yr="";
  	if (fld==null || fld.value=="") return(true);
  	for (i=0 ; i<fld.value.length ; i++) {
    	ch = fld.value.charAt(i);
    	for (j=0 ; j<chk.length ; j++) {
      		if (ch==chk.charAt(j)) break;
		}
    	if (j == chk.length) {
      		ok=false;
      		break;
    	}
	}
	if (ok) {
	  	for (i=0 ; i<fld.value.length ; i++) {
	    	ch=fld.value.charAt(i);
			if (ch=='/') break;
			mo=mo+ch;
		}
	  	for (i=i+1 ; i<fld.value.length ; i++) {
	    	ch=fld.value.charAt(i);
			if (ch=='/') break;
			day=day+ch;
		}
	  	for (i=i+1 ; i<fld.value.length ; i++) {
	    	ch=fld.value.charAt(i);
			yr=yr+ch;
		}
		ok=CheckDate(mo,day,yr);
	}
  	if (!ok) {
    	alert("The date you entered in the \""+name+"\" field is invalid.  Please be sure you are entering the date in the format MM/DD/YYYY.");
    	fld.focus();
    	return (false);
  	}
  	else return(true);
}

