function CheckSubmit(intForm) {
	if (CheckValidation(intForm)) {
		document.forms[intForm].submit();
	}else {
		return false;
	}
}

function emailTest(src) {
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
  }

function passwordTest() {
	if (document.forms[3].Password.value != document.forms[3].Password2.value) {
		return false;
	}else{
	return true;
	}
}

function CheckValidation(intForm) {
	var rtnVal = true;
	var strOutcome = ""; 
	var frm = document.forms[intForm];
	if (frm.elements) {
		var ele = frm.elements;

		for ( i=0; i < ele.length; i++ ) {
			if ( ele[i].type.length > 0 ) {
				strOutcome = isElementBad( ele, i);
				if (strOutcome.length > 0){
					rtnVal = false;
					break;
				}				
			}
		}
	}
	if (rtnVal != true) {
		var strName = ele[i].name;
		alert("illegal character in " + strName +" field ( \" "+strOutcome+" \"): Please remove and re-submit.");
		ele[i].focus();
		return false;
	}else {
		//need to switch through all "special case forms with their own javascript handlers -- these must be given the chance to fire"
		switch (frm.name) {
			case "regform":
				if (emailTest(frm.MemberEmail.value) != true) {	
					alert("please check your email address for proper form");
					frm.MemberEmail.focus();
					return false;
					break;
				}else if (passwordTest() != true) {
					alert("you mis-typed your password election, please try again.");
					frm.Password.focus();
					return false;
					break;
				}else {
					return true;
					break;
				}
    		case "newLoc":
				if ((numbersOnlyTest(frm.latDeg.value) != true) && (frm.latDeg.value != "")) {
					alert("please use only numbers, the '-' negative indicator, and decimals in the Latitude Degree textbox");
					frm.latDeg.focus();
					return false;
					break;
				}else if ((numbersOnlyTest(frm.latMin.value) != true) && (frm.latMin.value != "")) {
					alert("please use only numbers, the '-' negative indicator, and decimals in the Latitude Minutes textbox");
					frm.latMin.focus();
					return false;
					break;
				}else if ((numbersOnlyTest(frm.latSec.value) != true) && (frm.latSec.value != "")) {
					alert("please use only numbers, the '-' negative indicator, and decimals in the Latitude Seconds textbox");
					frm.latSec.focus();
					return false;
					break;
				}else if ((numbersOnlyTest(frm.lonDeg.value) != true) && (frm.lonDeg.value != "")) {
					alert("please use only numbers, the '-' negative indicator, and decimals in the Longitude Degree textbox");
					frm.lonDeg.focus();
					return false;
					break;
				}else if ((numbersOnlyTest(frm.lonMin.value) != true) && (frm.lonMin.value != "")) {
					alert("please use only numbers, the '-' negative indicator, and decimals in the Longitude Minute textbox");
					frm.lonMin.focus();
					return false;
					break;
				}else if ((numbersOnlyTest(frm.lonSec.value) != true) && (frm.lonSec.value != "")) {
					alert("please use only numbers, the '-' negative indicator, and decimals in the Longitude Seconds textbox");
					frm.lonSec.focus();
					return false;
					break;
				}else if ((numbersOnlyTest(frm.hrsToGMT.value) != true) && (frm.hrsToGMT.value != "")) {
					alert("please use only numbers, the '-' negative indicator, and decimals in the UTC Offset textbox");
					frm.lonSec.focus();
					return false;
					break;
				}else {
					return true;
					break;
				} 
			default:
				return true;
				break;
		}
	}
}

function numbersOnlyTest(src) {
	var numReg = /^[\-]?\d+(\.\d+)?$/;	//a regular expression test for numbers with optional neg(-) sign, & decimals...
	return numReg.test(src);
}

function isElementBad( ele, i ) {
	var strEleBad = "";					//comparison outcome
	var myString = ele[i].value;		//form with possible string content
	var objRegexCR = new RegExp("\n")	//Regular Expression Carriage Return
	var objRegexLF = new RegExp("\r")	//Regular Expression Line Feed
	var aBadStrings = new Array();		//Array of bad characters to compare
										//As new bad strings are identified, add them to the array here...
	aBadStrings[0] = "'";
	aBadStrings[1] = ";";
	aBadStrings[2] = "--";
	aBadStrings[3] = "::";
	aBadStrings[4] = "|";
	aBadStrings[5] = "/*";
	aBadStrings[6] = "*.";
	aBadStrings[7] = "%";
	aBadStrings[8] = ":=";
	aBadStrings[9] = "\\";
	aBadStrings[10] = ")";
	aBadStrings[11] = "&";
	aBadStrings[12] = "[";
	aBadStrings[13] = "]";
	aBadStrings[14] = "{";
	aBadStrings[15] = "}";	
	aBadStrings[16] = "<";
	aBadStrings[17] = ">";
	aBadStrings[18] = "./";
	aBadStrings[19] = "/.";
	aBadStrings[20] = "\"";
	aBadStrings[21] = "(";
	aBadStrings[22] = "~";
	aBadStrings[23] = "//";

	
  for (var x=0; x<aBadStrings.length; x++) {

	switch ( ele[i].type ) { 
		case "text" : 
			if ( myString.indexOf(aBadStrings[x]) >= 0){
				strEleBad = aBadStrings[x];
			}
			if (objRegexCR.test(myString)){
				strEleBad = "Carriage Return";
			}
			if (objRegexLF.test(myString)){
				strEleBad = "Line Feed";
			}
			break;
		case "textarea" : 
			if ( myString.indexOf(aBadStrings[x]) >= 0){
				strEleBad = aBadStrings[x];
			}
			if (objRegexCR.test(myString)){
				strEleBad = "Carriage Return";
			}
			if (objRegexLF.test(myString)){
				strEleBad = "Line Feed";
			}
			break;
		}
	}
	return strEleBad;
}

