// JScript File
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}


function fncIsValidEmail(strElementValue)
{
	var blnIsValid;
	strElementValue = strElementValue.trim();
	var expBad = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(^\!)|(^\#)|(^\$)|(^\%)|(^\^)|(^\&)|(^\*)|(^\()|(^\))|(^\+)|(^\{)|(^\})/; 
	// not valid
	var expGood = /^[^\[\]].+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
	// valid
	blnIsValid =(!expBad.test(strElementValue) && expGood.test(strElementValue));
	return blnIsValid;
}

function fncIsValidPhone(strElementValue)
{
	strElementValue = strElementValue.trim();
	var blnIsValid;
	//Change the following expression if format of 10 digit number truly matters for presentation! See below!
	//The following is a catch all for almost any phone entry
	var expGood = /^\d{3}\-\d{3}\-\d{4}$/; 
	blnIsValid =(expGood.test(strElementValue));
	return blnIsValid;
}

function fncGetFormErrors(strElementName)
{
	var strHighlightColor = "#c00";
	var strErr;
	var astrErr = new Array();
	astrErr["ContactPerson"] = " \t - Please enter a Contact Person. \n";
	astrErr["PhoneNumber"] = " \t - Please enter a valid Phone. For example: 999-999-9999. \n";
	astrErr["EmailAddress"] = " \t - Please provide a valid E-mail address. \n";
	astrErr["City"] = " \t - Please enter your City. \n";
	astrErr["txtCode"] = " \t - Please enter the text you see in the picture. \n";
	strErr = (astrErr[strElementName]) ? astrErr[strElementName] : ""; 
	return strErr;
}

function fncIsEmpty(strFormElementValue)
{
	var blnIsEmpty;
	blnIsEmpty = (strFormElementValue.trim().length < 1);
	return blnIsEmpty;
}

function fncValidateForm(strFormName)
	{
		var i = 0;
		var strErrors = "";
		strInstructions = "There were errors processing your request \n";
		strInstructions += "Please correct the following before continuing: \n \n";
		while(i < document.forms[strFormName].length)
		{
			var objFormElement = document.forms[strFormName].elements[i];

			switch(objFormElement.name)
			{
				case "PhoneNumber":
					if(!(fncIsValidPhone(objFormElement.value))) strErrors+=fncGetFormErrors(objFormElement.name);
					break;
				case "EmailAddress":
					if(!(fncIsValidEmail(objFormElement.value))) strErrors+=fncGetFormErrors(objFormElement.name);
					break;
				case "ContactPerson":
				case "txtCode":
				case "City":
					if(fncIsEmpty(objFormElement.value))
					    strErrors+=fncGetFormErrors(objFormElement.name);
					break;
				default:
					break;
			}
			i++;
		}
		
		document.getElementById('submitmode').value = "submit";
		submitmode = "submit";
		
		(strErrors)?alert(strErrors = strInstructions + strErrors):document.forms[strFormName].submit();
}


function fncGetNewCaptchaImage(strFormName)
{
    document.getElementById('submitmode').value = "newcaptcha";
    document.forms[strFormName].submit();
}