/* ------------------------------------
   SENSORY NETWORKS CORPORATE WEBSITE

   Form validation include
   Date created: 22/03/05
Author: Julian Frumar (jfrumar@sensorynetworks.com)
----------------------------------- */
function validate() {
	// ensure an email address has been entered
	email_regex = /^.+@.+\..+/;
	//phone regex
	phone_regex = /^\+[a-zA-Z0-9\s\-\(\)\[\]]+$/;
	// company regex
	company_regex = /^[a-zA-Z0-9'\.\/]{2,}[a-zA-Z0-9'\.\/\s]{1,}$/;
	// handles
	email_handle 		= document.getElementById('email');
	firstname_handle	= document.getElementById('first_name');
	lastname_handle		= document.getElementById('last_name');
	company_handle		= document.getElementById('company');
	phone_handle		= document.getElementById('phone');
	region_handle		= document.getElementById('00N20000000hvHL');
	industry_handle		= document.getElementById('industry');

	entered_email 		= email_handle.value;
	entered_firstname 	= firstname_handle.value;
	entered_lastname	= lastname_handle.value;
	entered_company		= company_handle.value;
	entered_phone		= phone_handle.value;
	entered_region		= region_handle[region_handle.selectedIndex].text;
	entered_industry	= industry_handle[industry_handle.selectedIndex].text;
	if (entered_firstname=='') {
		alert('Please enter a valid first name');
		firstname_handle.focus();
		firstname_handle.select();
		return false;
	} else if (entered_lastname=='') {
		alert('Please enter a valid last name');
		lastname_handle.focus();
		lastname_handle.select();	
		return false;
	} else if (!email_regex.exec(entered_email)) {
		alert('Please enter a valid email address');
		email_handle.focus();
		email_handle.select();
		return false;
	} else if (!company_regex.exec(entered_company)) {
		alert('Please enter a valid company name');
		company_handle.focus();
		company_handle.select();	
		return false;
	} else if (!phone_regex.exec(entered_phone)) {
		alert("Please enter a valid phone number.  Phone number must start with a '+' and thus include your country code.");
		phone_handle.focus();
		phone_handle.select();	
		return false;
	} else if (entered_region=='') {
		alert('Please enter a valid region');
		region_handle.focus();
		return false;
	} else if (entered_industry=='') {
		alert('Please enter a valid industry');
		industry_handle.focus();
		return false;
	} else {
		return true;
	}
}
