<!--
// HTML Form checking code

//PUT this in Form Input field to restrict entry to 
//allow only numbers and decimal
//onKeypress='if ( event.keyCode == 47 || event.keyCode < 46 || event.keyCode > 57 ) event.returnValue = false;'

//allow only numbers
//onKeypress='if ( event.keyCode < 48 || event.keyCode > 57 ) event.returnValue = false;'

//field.value = field.value.toString().replace(/^0*/g,'') ; //replace leading zeros
//removing trailing zeros

//alert if Netscape is Browser
//	if(document.all) {}	//IE	
//	else alert("Netscape was detected as your Browser. Some features will not work with Netscape. Internet Explorer is required.")

//code to prevent enter key from submitting form
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);

function keyDown(DnEvents) { // handles keypress
	// determines whether Netscape or Internet Explorer
	k = (netscape) ? DnEvents.which : window.event.keyCode;
	if (k == 13) { // enter key pressed
		return false;
   }
}

function setfocusfirsttextelement() {
//set focus to first text element on HTML form
	if(document.forms[0].length>0 && document.forms[0].elements.length>0)
		
		for(var i=0;i< document.forms[0].elements.length;i++){
  		if(document.forms[0].elements[i].type == 'text'){
    		document.forms[0].elements[i].focus();
	    	break;
  	 	}		
		}
//	 	document.forms[0].elements[0].focus(); // delete for loop and use this for first element
}

function isEmpty(passedValue) {
	if(passedValue.length == 0) {return true;}
	if (passedValue == "") {return true;}
	return false
}

function isBlank(passedVal) {
	for (i=0; i<passedVal.length; i++) {
		if (passedVal.charAt(i) != " ") {	return false; }
	}
	return true
}

function isNum(passedVal) {
	if (passedVal.length == 0) { return false; }
	for (i=0; i<passedVal.length; i++) {
		if (passedVal.charAt(i) < "0") {return false;	}
		if (passedVal.charAt(i) > "9") {return false; }
	}
	return true;
}

function validZip(passedValue) {
	if(passedValue.length > 5){	return false;	}
	if (isNum(passedValue)) {	return true; }
	return false
}

function validEmail(passedValue) {
	invalidChars = " /:,;"
	if (passedValue.length == 0) { return false; }
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (passedValue.indexOf(badChar,0) > -1) { return false; }
	}
	atPos = passedValue.indexOf("@",1)
	if (atPos == -1) {	return false;	}
	if (passedValue.indexOf("@",atPos+1) > -1) { return false; }
	periodPos = passedValue.indexOf(".",atPos)
	if (periodPos == -1) { return false;	}
	if (periodPos+3 > passedValue.length)	{	return false;}
	return true;
}

function validWebsite(passedValue) {
//only checking for .xxx could check for valid extensions com, org, gov, ect.
// not all sites start with www
	periodPos = passedValue.indexOf(".",atPos)
	if (periodPos == -1) { return false;	}
	if (periodPos+3 > passedValue.length)	{	return false;}
	return true;
}

function validDollars(fieldname) {
	//fieldname from html form: prevents empty field or non numberic characters
	fieldObject = eval(fieldname);			
	if (fieldObject.value == "" || !isNum(fieldObject.value)){
		alert("You must enter a dollar amount. Enter 0 if no dollars. Commas and decimal point not permitted.")
		return false;
	}
		return true;
}
	
function validCents(fieldname) {
	//fieldname from html form: prevents empty field or non numberic characters
	fieldObject = eval(fieldname)
	if (fieldObject.value == "" || !isNum(fieldObject.value)){
		alert("You must enter a cents amount. Enter 0 if no cents. Decimal point not permitted.")
		return false;
	}
		return true;
}

function validChar(thefield) {
// returns false if finds invalid character in string
	invalidValues = "\"\'()";     // invalid characters
	var strPass = thefield.value;
	var strLength = strPass.length;
	var i;
	for (i = 0; i < strLength; i++) {  
		var c = strPass.charAt(i);
		if (invalidValues.indexOf(c) != -1) {	return false;	}		
	}
	return true;
}

function removeSpaces(thestring) {
//removes spaces (leading, internal, trailing) from thestring
	var temp = "";
	thestring = '' + thestring;
	splitstring = thestring.split(" ");
	for(i = 0; i < splitstring.length; i++)	temp += splitstring[i];
	return temp;
}

// -->
