// Global variables that lists all the characters that should 
// be filtered due to security reasons
var sRestrictChars = "<,>,SCRIPT,HREF,MAILTO,%%,<%,%>,<?,?>,<!--,-->,C$,ADMIN$,WINNT$,CMD,JAVASCRIPT,%3C,%3E,%3C%21%2D%2D,%2D%2D%3E,HTTP";
var nonStandardChars = "/,\\,\?,:,\;,=,+,(,),*,!,#,$,%,^,*,`,~,[,],{,},|";

// Configuration globals
var minEmailLength = 9;
var minNameLength = 0;
var minBusinessLength = 0;
var minCommentsLength = 5;
var disableNoScriptHTML = false;


// noScriptHTML is a security script that restricts characters 
// that a user could put into the fields of a form that could
// compromise the website
function noScriptHTML(sStr,moreChars){
	var tempError = "";
	if(!disableNoScriptHTML){
		sStr = sStr.toUpperCase();
		if(moreChars.length > 0){
			sRestrictChars += "," + moreChars;
		}
		var aRestrictChars = sRestrictChars.split(",");
		for (var i=0; i<aRestrictChars.length; i++ ){
			if(sStr.indexOf(aRestrictChars[i]) >= 0){
				tempError = "Illegal characters were found\n\t\t";
				tempError += aRestrictChars[i] + " is not allowed";
			}
		}
	}
	return tempError;
}

// validateFieldAndSubmit checks to see that a value is included 
// in each of the required fields and also runs noScriptHTML on 
// every field
function validateFieldsAndSubmit(oObj){
	var errorMessage = "";
	//var oObj = document.form1;
	// Name is required and noScriptHTML/nonStandardChars & _ & @
	
	
	/*start here to checnk only e-mail
	if(oObj.name.value.length <= minNameLength) {
		errorMessage += "\n\t Name";
	} else if(noScriptHTML(oObj.name.value,nonStandardChars).length > 0) {
		errorMessage += "\n\t Name: " + noScriptHTML(oObj.name.value,nonStandardChars);
	}
	// Address1 & Address2 is not required but noScriptHTML 
	if(oObj.address1.value.length > 0 || oObj.address2.value.length > 0){
		if((noScriptHTML(oObj.address1.value,nonStandardChars).length + noScriptHTML(oObj.address2.value,nonStandardChars).length) > 0) {
			errorMessage += "\n\t Address: " + noScriptHTML((oObj.address1.value + " " + oObj.address2.value),nonStandardChars);
		}
		if((noScriptHTML(oObj.city.value,nonStandardChars).length + noScriptHTML(oObj.state.value,nonStandardChars).length + noScriptHTML(oObj.zip.value,nonStandardChars).length) > 0) {
			errorMessage += "\n\t City/State/Zip: " + noScriptHTML((oObj.city.value + " " + oObj.state.value + " " + oObj.zip.value),nonStandardChars);
		}
		if(oObj.city.value.length == 0 || oObj.state.value.length == 0 || oObj.zip.value.length == 0) {
		errorMessage += "\n\tPlease provide a complete address and city, state and zip";
		}
	} else if ((oObj.city.value.length + oObj.state.value.length + oObj.zip.value.length) > 0){
		errorMessage += "\n\tPlease provide a complete address and city, state and zip";
	}*/
	// Email is required and so is "@" and "." and noScriptHTML/nonStandardChars
	if(oObj.email.value.length <= minEmailLength){
		errorMessage += "\n\t Email";
	} else if(oObj.email.value.length > minEmailLength && (oObj.email.value.indexOf("@") <= 0 || oObj.email.value.indexOf(".") <= 0 || oObj.email.value.length <= minEmailLength)){
		errorMessage += "\n\t Email is not a valid address";
	} else if(noScriptHTML(oObj.email.value,nonStandardChars).length > 0) {
		errorMessage += "\n\t Email: " + noScriptHTML(oObj.email.value,nonStandardChars);
	}
	// Comments is required and noScriptHTML
	
	/*if(oObj.comments.value.length <= minCommentsLength){
		errorMessage += "\n\t Message\n\t(min: " + (minCommentsLength + 1) + " chars)";
	} else if(noScriptHTML(oObj.comments.value,"").length > 0) {
		errorMessage += "\n\t Message: " + noScriptHTML(oObj.comments.value,"");
	}*/
	// Submit form if validation passes else display problems
	if(errorMessage.length == 0){
		//oObj.submit();
		postForm(oObj);
	} else {
		errorMessage = "Please correct the following areas before submitting:\n" + errorMessage;
		alert(errorMessage);
	}
}