// NARZ validation | 25/07/2005
// In-use as data is posted via SalesForce.
// AP.
<!--
	// check required fields are not empty
	function isNotEmpty(elem, fieldname) {
	var error = "";
	var str = elem.value;
	var re = /.+/;
	if(!str.match(re)) {
		error = "* " + fieldname + " is required.\n";
		}
	else {
		error = "";
	}
	return error;
    }

    // check dropdown to see if item has been selected
	function dropdownItmSelected(elem, fieldname) {
	    var error = "";
	    var str = elem.value;
	    if(str == "Please Select") {
		    error = "* " + fieldname + " is required.\n";
		    }
	    else {
		    error = "";
	    }
	    return error;
    }

	// validate email address
	function isEmailAddr(elem, fieldname) {
		var error = "";
		var str = elem.value;
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
		if (str == "") {
			error = "* Email address is required.\n";
			return error;
			}
		if (!str.match(re)) {
			error = "* Email address is not valid.\n";
			}
		else
			{
			error = "";
		}
		return error;
	}
	function isNumeric(elem, strMsg)
	//  check for valid numeric strings	
	{
	var strString = elem.value;
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	if (strString.length == 0)
	{
	    blnResult = false;
	}
	else
	{
	    //  test strString consists of valid characters listed above
	    for (i = 0; i < strString.length && blnResult == true; i++)
		    {
			    strChar = strString.charAt(i);
			    if (strValidChars.indexOf(strChar) == -1)
			    {
				    blnResult = false;
			    }
		    }
	}
	if(blnResult == false)
	{
	    return strMsg;
	}		    
	return "";
	}
	function validateForm(form) {
		var strReason = "";
		strReason += isNotEmpty(form.first_name, "First name");
		strReason += isNotEmpty(form.last_name, "Last name");
		strReason += isNotEmpty(form.company, "Company name");
		strReason += isEmailAddr(form.email, "Email address");
		strReason += isNotEmpty(form.phone, "Telephone number");
		if(form.yourMessage!=null)
		{
		strReason += isValidLength(form.yourMessage,"Your message");
		}
		if (strReason != "") {
			alert("We were unable to process your details\nbecause of the following:\n\n" + strReason);
		return false;
		}
	return true;
	}
	function validateContactForm(form, CheckPhone) {
		var strReason = "";
		if(form.salutation!=null)
		{
		    strReason += dropdownItmSelected(form.salutation, "Salutation");
		}	
		strReason += isNotEmpty(form.first_name, "First name");
		strReason += isNotEmpty(form.last_name, "Last name");
		if(CheckPhone==true)
		{
		    strReason += isNumeric(form.phone, "* Telephone is required.\n");
		}
		strReason += isNotEmpty(form.company, "Company name");
		if(form.industry!=null)
		{
		    strReason += dropdownItmSelected(form.industry, "Industry");
		}				
		strReason += isEmailAddr(form.email, "Email address");
		
		if(form.yourMessage!=null)
		{
		strReason += isValidLength(form.yourMessage,"Your Message");
		}
		
		if (strReason != "") {
			alert("We were unable to process your details\nbecause of the following:\n\n" + strReason);
		return false;
		}
	return true;
	}
	function isUndefined(a) {
		return typeof a == 'undefined';
	}
	//get the referrer and populate the hidden referrer field on the form
	function getReferrer(){
		var strReferrer = '';
		var strQS = String(window.location);
		var s = strQS.split("referrer=");
		strReferrer = s[1];
		if(isUndefined(strReferrer)==false){
			document.frmMain.lead_source.value = strReferrer;
		}
	}
	
	//to validate the length og yourmessage textbox
	function isValidLength(elem, fieldname)
	{
		var error = "";
		var maxL=200;
		var str = elem.value;
		if(str.length<=maxL){
		error="";
		}
		else{
			error = "* " + fieldname + " cannot be greater than 200 characters.\n";
			}
		
		return error;
	}
	
//->
