
function CheckVals(form){
//document.AddImage.i
//alert (form.name);

var iLen = form.length - 1;

var retVal = true;

var i = 0;
while (i < iLen) {



	if(InStr(form[i].title, 'CheckExist') >= 0){
		//alert(InStr(form[i].title, 'CheckExist'));
		var retExist;
		retExist = CheckExist(form[i]);
			if (retExist == false){
				retVal = false;
				//return false;
			}
		}
		
	//alert("Loop " + i + ": Is " + form[i].name + "'s title = CheckEmail?");
	//alert(form[i].title == 'CheckEmail');
	


	if(InStr(form[i].title, 'CheckEmail') >= 0){
		if(InStr(form[i].title, 'req') >= 0){
			var retEmail
			retEmail = CheckEmail(form[i], 1);
			if (retEmail == false){
				retVal = false;
				//return false;
			}			
		}else{
			retEmail = CheckEmail(form[i], 0);
			if (retEmail == false){
				retVal = false;
				//return false;
			}			
		}
	}

	if(InStr(form[i].title, 'CheckDate') >= 0){
		if(InStr(form[i].title, 'req') >= 0){
			var retDate;
			retDate = CheckDate(form[i], 1);
			if (retDate == false){
				retVal = false;
				//return false;
			}			
		}else{
			retDate = CheckDate(form[i], 0);
			if (retDate == false){
				retVal = false;
				//return false;
			}			
		}
	}
		
	if(InStr(form[i].title, 'CheckNum') >= 0){
		//alert(InStr(form[i].title, 'CheckNum'));
		//CheckNum(form[i]);
		//}
		if(InStr(form[i].title, 'req') >= 0){
			var retNum;
			retNum = CheckNum(form[i], 1);
			if (retNum == false){
				retVal = false;			}			
		}else{
			retNum = CheckNum(form[i], 0);
			if (retNum == false){
				retVal = false;
			}			
		}
	}

	if(InStr(form[i].title, 'CheckLen') >= 0){
		//alert('CheckLen');
		if(InStr(form[i].title, 'req') >= 0){
			var retNum;
			retNum = CheckLen(form[i], 1);
			if (retNum == false){
				retVal = false;			}			
		}else{
			retNum = CheckLen(form[i], 0);
			if (retNum == false){
				retVal = false;
			}			
		}
	}

	if(InStr(form[i].title, 'CheckGTLen') >= 0){
		//alert('CheckGTLen');
		if(InStr(form[i].title, 'req') >= 0){
			var retNum;
			retNum = CheckGTLen(form[i], 1);
			if (retNum == false){
				retVal = false;			}			
		}else{
			retNum = CheckGTLen(form[i], 0);
			if (retNum == false){
				retVal = false;
			}			
		}
	}
	
//CheckState(element, req)	
	if(InStr(form[i].title, 'CheckState') >= 0){
		if(InStr(form[i].title, 'req') >= 0){
			var retState;
			retState = CheckState(form[i], 1);
			if (retState == false){
				retVal = false;			
			}			
		}else{
			retState = CheckState(form[i], 0);
			if (retState == false){
				retVal = false;
			}			
		}
	}	
	
	i++ ;
	
	}
//alert(retVal);	
return retVal;	
}


//**********************************************************************************************************
//
// Description: valid date.  sDate must be in d/m/yy or d/m/ccyy format.
//              
//**********************************************************************************************************

function isDate(datein) {
    var indate=datein;
    if (indate.indexOf("-")!=-1)   {
        var sdate = indate.split("-")
    }
    else {
        var sdate = indate.split("/")
    }
    var chkDate = new Date(Date.parse(indate))
    var cmpDate = (chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+(chkDate.getYear())
    var indate2 = (Math.abs(sdate[0]))+"/"+(Math.abs(sdate[1]))+"/"+(Math.abs(sdate[2]))
    if (indate2 != cmpDate){
        //alert("You've entered an invalid date or date format. Please use the MM/DD/YY format.");
        return false ;
    }
    else {
        if (cmpDate=="NaN/NaN/NaN"){
            //alert("You've entered an invalid date or date format. Please use the MM/DD/YY format.");
			return false ;
        }
     }
return true;
}


//**********************************************************************************************************
//The following function is probably obsolete since the .req functionality was added to the other functions,
//but I left it in anyways just in case.
//
//CheckExist function checks the validity of an HTML form element.
//To use it, place a 'title' property equal to 'CheckExist' in the form element you wish to check.
//The following HTML tag will use CheckExist to validate the form element.
//
//i.e. - <input type="text" name="name" value="" title="CheckExist">
//
//**********************************************************************************************************
function CheckExist(element){
	//alert(element.value)
	if (element.value == '' || element.value == ' '){
	alert(element.name + ' is a required field!');
	return false;
	}
}


//**********************************************************************************************************
//
//
//**********************************************************************************************************
function CheckDate(element, req){
	//alert(element.value)


	if (req == 1){
		if (element.value == '' || element.value == ' '){
		alert(element.name + ' is a required field!');
		return false;
		}
	}
	
	
	var iRet = isDate(element.value);
	//alert(iRet);
	if (iRet == false && Len(element.value) > 0){
		alert(element.name + ' must be in the following format: mm/dd/ccyy or mm/dd/yy');
		return false;
	}
	return true;
	
	
	
	
}

//**********************************************************************************************************
//
//
//**********************************************************************************************************
function CheckBox(element){
	//alert(element.value)
}

//**********************************************************************************************************
//
//
//**********************************************************************************************************
function CheckState(element, req){
	//alert(element.value)
	var boState;
	
	if (req == 1){
		if (element.value == '' || element.value == ' '){
		alert(element.name + ' is a required field!');
		return false;
		}
	}
	
	arStateCode = new Array('ak', 'al', 'ar', 'as', 'az', 'ca', 'co', 'ct', 'dc', 'de', 'fl', 'ga', 'gu', 'hi', 'ia', 'id', 'il', 'in', 'ks', 'ky', 'la', 'ma', 'md', 'me', 'mi', 'mn', 'mo', 'ms', 'mt', 'nc', 'nd', 'ne', 'nh', 'nj', 'nm', 'nv', 'ny', 'oh', 'ok', 'or', 'pa', 'pr', 'ri', 'sd', 'tn', 'tx', 'ut', 'va', 'vi', 'vt', 'wa', 'wi', 'wv', 'wy') ;	

	arState = new Array('alaska', 'alabama', 'arkansas', 'american samoa', 'arizona', 'california', 'colorado', 'connecticut', 'district of columia', 'delaware', 'florida', 'georgia', 'guam', 'hawaii', 'iowa', 'idaho', 'illinois', 'indiana', 'kansas', 'kentucky', 'louisiana', 'massachusetts', 'maryland', 'maine', 'michigan', 'minnesota', 'missouri', 'mississippi', 'montana', 'north carolina', 'north dakota', 'nebraska', 'new hampshire', 'new jersey', 'new mexico', 'nevada', 'new york', 'ohio', 'oklahoma', 'oregon', 'pennsylvania', 'puerto rico', 'rhode island', 'south carolina', 'south dakota', 'tennessee', 'texas', 'utah', 'virginia', 'virgin islands', 'vermont', 'washington', 'wisconsin', 'west virginia', 'wyoming');

	eleVal = new String(element.value);

	eleVal = eleVal.toLowerCase();

	for(x=0; x<arState.length; x++){
		if(eleVal == arState[x]){
			boState = true;
		}
	
	}

	for(n=0; n<arStateCode.length; n++){
		if(eleVal == arStateCode[n]){
			boState = true;
		}
	
	}
if(boState == true){
	//alert('True');
	return true;
}else{
	alert('The value you entered in ' + element.name + ' is not a valid US state.');
	return false;
}	
									
}

//**********************************************************************************************************
//CheckNum function checks the validity of an HTML form element that is supposed to be numeric.
//To use it, place a 'title' property equal to 'CheckNum' in the form element you wish to check.
//To make this a required field, append '.req' to 'CheckNum'.  The following HTML tag will use 
//CheckNum to validate the form element.  It is a required field.
//
//i.e. - <input type="text" name="num" value="" title="CheckNum.req">
//
//**********************************************************************************************************
function CheckNum(element, req){

	if (req == 1){
		if (element.value == '' || element.value == ' '){
		alert(element.name + ' is a required field!');
		return false;
		}
	}
	
	//alert(element.value)
	if (isNaN(element.value) == true && Len(element.value) > 0){
	alert(element.name + ' must be a numeric value!');
	return false;
	}
}



//**********************************************************************************************************
//Check Length of a given form element.  Length must be provided in parenthsis.  Required Function is
//implemented.  This function is to check TOTAL length, like for a zip code.  It does not work for a
// >= situation, like checking to make sure a name is at least 2 characters long.  Use CheckGTLen function
// for that.  Note:  No CheckLTLen was created because max length can be controlled with HTML.
//
//i.e. - <input type="text" name="num" value="" title="CheckLen(10).req">
//
//**********************************************************************************************************
function CheckLen(element, req){
//alert('checklen');
	if (req == 1){
		if (element.value == '' || element.value == ' '){
		alert(element.name + ' is a required field!');
		return false;
		}
	}
	
	var strElement = new String(element.title);
	var strElVal = new String(element.value);
	
	
	if (strElVal.length > 0){
	
		if (InStr(strElement, ')') == -1 ){
		alert('CheckLen function not implemented correctly [length not provided in parens].  Please check with Webmaster!');
		return false;
		}
	
		if (InStr(strElement, '(') == -1 ){
		alert('CheckLen function not implemented correctly [length not provided in parens].  Please check with Webmaster!');
		return false;
		}
	
	
		var iStart = InStr(element.title, '(') + 1;
		var iEnd = InStrRev(element.title, ')');
	
		iLen = new Number(strElement.substring(iStart, iEnd));
	
		if (isNaN(iLen)){
		alert('CheckLen function not implemented correctly (length not a number).  Please check with Webmaster!');
		return false;
		}
	
	
		if (strElVal.length != iLen){
		alert(element.name + ' must be ' + iLen + ' characters long');
		return false;
		}

	}
}


function CheckGTLen(element, req){
//alert('checklen');
	if (req == 1){
		if (element.value == '' || element.value == ' '){
		alert(element.name + ' is a required field!');
		return false;
		}
	}
	
	var strElement = new String(element.title);
	var strElVal = new String(element.value);
	
	
	if (strElVal.length > 0){
	
		if (InStr(strElement, ')') == -1 ){
		alert('CheckLen function not implemented correctly [length not provided in parens].  Please check with Webmaster!');
		return false;
		}
	
		if (InStr(strElement, '(') == -1 ){
		alert('CheckLen function not implemented correctly [length not provided in parens].  Please check with Webmaster!');
		return false;
		}
	
	
		var iStart = InStr(element.title, '(') + 1;
		var iEnd = InStrRev(element.title, ')');
	
		iLen = new Number(strElement.substring(iStart, iEnd));
	
		if (isNaN(iLen)){
		alert('CheckLen function not implemented correctly (length not a number).  Please check with Webmaster!');
		return false;
		}
	
		if (strElVal.length < iLen){
		alert(element.name + ' must be at least ' + iLen + ' characters long');
		return false;
		}

	}
}

//**********************************************************************************************************
//CheckEmail function checks the validity of an e-mail that has been submitted through a HTML form.
//To use it, place a 'title' property equal to 'CheckEmail' in the form element you wish to check.
//To make this a required field, append '.req' to 'CheckEmail'.  The following HTML tag will use 
//CheckEmail to validate the form element.  It is a required field.
//
//i.e. - <input type="text" name="email" value="" title="CheckEmail.req">
//
//**********************************************************************************************************
function CheckEmail(element, req){
//alert("CheckEmail");
	//alert('this is CheckEmail');
	//alert(InStr(element.value, '@')) ;

	if (req == 1){
		if (element.value == '' || element.value == ' '){
		alert(element.name + ' is a required field!');
		return false;
		}
	}
	
	if (Len(element.value) > 0){

		arReq = new Array('@', '.') ;    

		for (y=0; y<arReq.length; y++){
			//alert(arInv[z]);
			if (InStr(element.value, arReq[y]) == -1) {
				alert(element.name + " does not contain a valid e-mail address.  A '" + arReq[y] + "' is required.");
				return false;
			}
		}

		//if (InStr(element.value, '@') == -1) {
		//	alert(element.name + " does not contain a valid e-mail address.  A '@' is required.");
		//	return false;
		//}

		//if (InStr(element.value, '.') == -1) {
		//	alert(element.name + " does not contain a valid e-mail address.  A '.' is required.");
		//	return false;
		//}

		arInv = new Array('!', '#', '$', '%', '^', '&', '*', '(', ')', '=', '+', '{', '}', '[', ']', '|', ';', ' ', ':', "'", '/', '?', '>', ',', '<', '\\') ;    

		arTLD = new Array('.aero', '.biz', '.coop', '.info', '.museum', '.name', '.pro', '.com', '.edu', '.int', '.mil', '.net', '.org', '.af', '.al', '.dz', '.as', '.ad', '.ao', '.ai', '.aq', '.ag', '.ar', '.am', '.aw', '.ac', '.au', '.at', '.az', '.bs', '.bh', '.bd', '.bb', '.by', '.be', '.bz', '.bj', '.bm', '.bt', '.bo', '.ba', '.bw', '.bv', '.br', '.io', '.bn', '.bg', '.bf', '.bi', '.kh', '.cm', '.ca', '.cv', '.ky', '.cf', '.td', '.cl', '.cn', '.cx', '.cc', '.co', '.km', '.cg', '.cd', '.ck', '.cr', '.ci', '.hr', '.cu', '.cy', '.cz', '.cs', '.dk', '.dj', '.dm', '.do', '.tp', '.ec', '.eg', '.sv', '.gq', '.er', '.ee', '.et', '.fk', '.fo', '.fj', '.fi', '.fr', '.fx', '.gf', '.pf', '.tf', '.ga', '.gm', '.ge', '.de', '.gh', '.gi', '.gb', '.gr', '.gl', '.gd', '.gp', '.gu', '.gt', '.gg', '.gn', '.gw', '.gy', '.ht', '.hm', '.hn', '.hk', '.hu', '.is', '.in', '.id', '.ir', '.iq', '.ie', '.im', '.il', '.it', '.jm', '.jp', '.je', '.jo', '.kz', '.ke', '.ki', '.kp', '.kr', '.kw', '.kg', '.la', '.lv', '.lb', '.ls', '.lr', '.ly', '.li', '.lt', '.lu', '.mo', '.mk', '.mg', '.mw', '.my', '.mv', '.ml', '.mt', '.mh', '.mq', '.mr', '.mu', '.yt', '.mx', '.fm', '.md', '.mc', '.mn', '.ms', '.ma', '.mz', '.mm', '.na', '.nr', '.np', '.nl', '.an', '.nc', '.nz', '.ni', '.ne', '.ng', '.nu', '.nf', '.mp', '.no', '.om', '.pk', '.pw', '.ps', '.pa', '.pg', '.py', '.pe', '.ph', '.pn', '.pl', '.pt', '.pr', '.qa', '.re', '.ro', '.ru', '.rw', '.gs', '.kn', '.lc', '.vc', '.ws', '.sm', '.st', '.sa', '.sn', '.sc', '.sl', '.sg', '.sk', '.si', '.sb', '.so', '.za', '.es', '.lk', '.sh', '.pm', '.sd', '.sr', '.sj', '.sz', '.se', '.ch', '.sy', '.tw', '.tj', '.tz', '.th', '.tg', '.tk', '.to', '.tt', '.tn', '.tr', '.tm', '.tc', '.tv', '.ug', '.ua', '.ae', '.uk', '.us', '.uy', '.um', '.su', '.uz', '.vu', '.va', '.ve', '.vn', '.vg', '.vi', '.wf', '.eh', '.ye', '.yu', '.zm', '.zw');

		//alert (arInv[0]) ;
		//alert (arInv[1]) ;

		for (z=0; z<arInv.length; z++){
			//alert(arInv[z]);
			if (InStr(element.value, arInv[z]) > -1){
				alert("'" + arInv[z] + "'" + " is an invalid character for an e-mail address!");
				return false;
			}
		}

		var n = false;		
		eleVal = new String(element.value);
		eleVal = eleVal.toLowerCase();

		for (z=0; z<arTLD.length; z++){
			//alert(arTLD[z]);
			if (InStr(eleVal, arTLD[z]) > 2){
				n = true;
			}
		}

		if (n==false){
			alert("A valid top level domain is required to have a valid e-mail address (i.e. .com, .edu, etc.)");
			return false;
		}

	}
	
return true;
}





//function validate(frmName){
////frmName is the name of the form
//frmLength = document.frmName.length;
//isEmpty = false;
//
//for (i=0; i&lt;frmLength;i++){
//    if(document.frmName[i].value == "")
//        isEmpty = true;  //one element is empty
//}
//
//if(istEmpty)
//    return false;  //at least one element is empty so return false
//return true; //all fields are non-empty so return true;
//
//}

//**********************************************************************************************************
//
//The Len function is designed to mimic the VB len() function
//
//**********************************************************************************************************

function Len(str)
/***
        IN: str - the string whose length we are interested in

        RETVAL: The number of characters in the string
***/
{  return String(str).length;  }


//**********************************************************************************************************
//
//The mid function is designed to mimic the VB mid() function
//
//**********************************************************************************************************

function Mid(str, start, len)
/***
        IN: str - the string we are LEFTing
            start - our string's starting position (0 based!!)
            len - how many characters from start we want to get

        RETVAL: The substring from start to start+len
***/
{
//	alert(str);
//	alert(start);
//	alert(len);
			
        // Make sure start and len are within proper bounds
        if (start < 0 || len < 0) return "";

        var iEnd, iLen = String(str).length;
        if (start + len > iLen)
                iEnd = iLen;
        else
                iEnd = start + len;

        return String(str).substring(start,iEnd);
}


//**********************************************************************************************************
//
//The InStr function is designed to mimic the VB InStr() function
//
//**********************************************************************************************************

function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is <B>not</B>
                           found, -1 is returned.)
Requires use of:
	<A href="http://www.4guysfromrolla.com/webtech/code/Mid.shtml">Mid function</A>
	<A href="http://www.4guysfromrolla.com/webtech/code/Len.shtml">Len function</A>
*/
{
var iLen = Len(charSearchFor);

	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, iLen))
	    {
			return i;
	    }
	}
	return -1;
}

function InStrRev(charSearch, charSearchFor){

	strSearch = new String(charSearch);
	strSearch = strSearch.toLowerCase();

	strSearchFor = new String(charSearchFor);
	strSearchFor = strSearchFor.toLowerCase();
	
	//alert (strSearch.lastIndexOf(strSearchFor));

	return 	strSearch.lastIndexOf(strSearchFor);

}

//****************************************************************************************************
//lcase function - mimics VBScript lcase function
//
//****************************************************************************************************
function lcase(str){
	var str2 = new String(str);
	alert(str2.toLowerCase());
	return str2.toLowerCase();
}


