//	----- EMAIL -----
function evalName(testElement){
	// Validate Email
	evalField(testElement,re_text,"Invalid email address.",false);
}

//	----- TEXT -----
function evalSentFrom(testElement){
	// Validate Email
	if (document.getElementById("cc_to").checked){
		evalField(testElement,re_email,"Invalid email address.",true);
	} else {
		evalField(testElement,re_email,"Invalid email address.",false);
	}
}

//	----- TEXT -----
function evalSendTo(testElement){
	// Validate Email
	evalField(testElement,re_email,"Invalid email address.",true);
}

function evalCC(e){
	var divElem = document.getElementById("div_sent_from");

	if (e.checked){
		divElem.className="required";
	} else {
		divElem.className="optional";
	}
	
	evalSentFrom(document.getElementById("sent_from"));
}

//	----- TEXT -----
function evalCaptcha(testElement){
	// Validate Text
	evalField(testElement,re_text,"Invalid characters.",true);
}



// --------------------------------------------
//	Test Validation Using Regular Expressions
//	Library (Input fields only)
// --------------------------------------------
function evalField(		testField, 		// element: the input form element to be validated
						regExObj,		// RegEx: name of a valid Regular Expression to use for validation (see regex_library.js for names)
						msgText,		// string: message text, whether an error or okay
						required) 		// boolean: true = required, false = optional
{

	var testValue;
	testValue = trim(testField.value);

	// Test for Required Field or Selection
	if (required){
		if (testValue.length==0){
			msg (testField,"error","Required.");
			setFocus(testField);	// Places the cursor on the field
			return false;
		}
	} 

	// Test the Value
	if (testValue.length > 0){
		if (!regexValidate(testValue,regExObj)){
			msg (testField,"error",msgText);
			setFocus(testField);	// Places the cursor on the field
			return false;
		}
	}

	// Update the form Message area
	msg (testField,"okay","&nbsp");
	return true;
}


// --------------------------------------------
//	Change Form Messages
// --------------------------------------------
function msg(testField,cssClass,message){
	if (cssClass == "error"){
		testField.className = "textbox_attn"
		alert(message);
	} else {
		testField.className = "textbox"
	}
}

// --------------------------------------------
//	Trim: Trims leading and trailing white space
// --------------------------------------------
function trim(str){
	return str.replace(/^\s+|\s+$/g,'');
}


// --------------------------------------------
//	Regular Expression Test
// --------------------------------------------
function regexValidate(strValue,regEx){
	return regEx.test(strValue);
}


// --------------------------------------------
//	Set Focus - Delayed focus routine
// --------------------------------------------
function setFocus(testField){
	// save valfield in global variable so value retained when routine exits
	focusField = testField;
	setTimeout('doFocus()',100);
}

function doFocus(){
	focusField.focus();
}