function trimAll(sString)
{
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function isValidEmail(str) {
	return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}

function isFormComplete(FormName,formFields) {
	var x = 0, i = 0;
	var formArray = formFields.split(",");
	for(i=0; i < FormName.elements.length; i++) {
		for (x=0; x < formArray.length; x++) {
			if (FormName.elements[i].name == formArray[x] && trimAll(FormName.elements[i].value) == "") {
				alert('Please enter the '+FormName.elements[i].name +' and try again.');
				FormName.elements[i].focus();
				return false;
			}
		}
	}
	return true;
}

function submitForm(form) {

	if (!isFormComplete(form, form.required.value)) {
		return false;
	}
	if(form.email.value!=''){
		if (!isValidEmail(form.email.value)) {
			alert("Please enter a valid Email.");
			form.email.focus();
			return false;
		}
	}
	return true;

}

function checkValue(field,testValue,newfield,text){
//alert(field.value);
	if(field.value==testValue){
		newfield.style.visibility = "visible";
		newfield.focus();
		newfield.value=text;
		newfield.select();
		//alert('true')
		
	}else{
		//alert('false')
		newfield.value='';
		newfield.style.visibility = "hidden";
	}
}



