function ValidateAndSubmit()
{
  
	/* FIRST NAME 	*/ if (!ValidateString(document.getElementById('FirstName'), 'First Name')) return false;
	/* LAST NAME 	*/ if (!ValidateString(document.getElementById('LastName'), 'Last Name')) return false;
	/* STREET 	 	*/ if (!ValidateString(document.getElementById('StreetAddress'), 'Street')) return false;
	/* CITY 	 	*/ if (!ValidateString(document.getElementById('City'), 'City')) return false;
	/* PROVINCE 	*/ if (!ValidateString(document.getElementById('Province'), 'Province')) return false;
	/* COUNTRY 	*/ if (!ValidateString(document.getElementById('Country'), 'Country')) return false;
	/* POSTAL CODE 	*/ if (!ValidateString(document.getElementById('PostalCode'), 'Postal Code')) return false;
	/* PHONE NUMBER */ if (!ValidatePhoneNumber(document.getElementById('Phone'), 'Phone Number')) return false;
	/* EMAIL		*/ if (!ValidateEmail(document.getElementById('Email'), 'Email Address')) return false;
	
	if (document.getElementById('SquareFootage').value == '') { 
			document.getElementById('SquareFootage').focus(); 
			alert('Must select preferred square footage.'); 
			return false; 
	}
	
	if (document.getElementById('SquareFootage').value == '') { 
			document.getElementById('SquareFootage').focus(); 
			alert('Must select preferred square footage.'); 
			return false; 
	}
	
	if (document.getElementById('PriceRange').value == '') { 
			document.getElementById('PriceRange').focus(); 
			alert('Must select preferred Price Range.'); 
			return false; 
	}
	
	if (document.getElementById('BedRooms').value == '') { 
			document.getElementById('BedRooms').focus(); 
			alert('Must select preferred number of bed rooms.'); 
			return false; 
	}
	
	if (document.getElementById('BathRooms').value == '') { 
			document.getElementById('BathRooms').focus(); 
			alert('Must select preferred number of bath rooms.'); 
			return false; 
	}
	
	if (document.getElementById('HomeType').value == '') { 
			document.getElementById('HomeType').focus(); 
			alert('Must select preferred Home Type.'); 
			return false; 
	}
	
	if (document.getElementById('Status').value == '') { 
			document.getElementById('Status').focus(); 
			alert('Must select your residence type.'); 
			return false; 
	}
	if (document.getElementById('Age').value == '') { 
			document.getElementById('Age').focus(); 
			alert('Must select age group.'); 
			return false; 
	}
	
	if (document.getElementById('MoveType').value == '') { 
			document.getElementById('MoveType').focus(); 
			alert('Must select your move type.'); 
			return false; 
	}
	
	if (document.getElementById('TrafficSource').value == '') { 
			document.getElementById('TrafficSource').focus(); 
			alert('Must select marketting source.'); 
			return false; 
	}
	
	if (document.getElementById('chkYes').checked) { 
		
		document.getElementById('NotifyMe').value = 'Yes';
		
	} else {
		
		document.getElementById('NotifyMe').value = 'No';
		
	}
	
	document.getElementById('formone').submit();
	  
}


/*  ********************************************
	VALIDATE EMAIL
 * ********************************************/
 
function ValidateEmail(e){
	
	if (e.disabled == true) return true;
	
	e.style.backgroundColor  = 'white';
	
	var email=String(e.value);
	
	while (email.substring(0,1) == ' ') {
		email = email.substring(1, email.length);
	}
	while (email.substring(email.length-1,email.length) == ' ') {
		email = email.substring(0,email.length-1);
	}

	if (email=="") {
		
		
		e.style.backgroundColor  = 'yellow';	
		e.focus();
		e.select();
		alert("Please enter a valid email address.");
		return false;
	}
	
	if (email){
		if(!email.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,6}$/i)) {
			
			e.style.backgroundColor  = 'yellow';	
			e.focus();
			e.select();
			alert("The email address you have entered is invalid.");
			return false;
			
		}
	}
	
	return true;
	
}


/*  ********************************************
	VALIDATE PHONE NUMBER
 * ********************************************/
 
function ValidatePhoneNumber (e){
	
	if (e.disabled == true) return true;
	
	var goodphone="";
	var phone=String(e.value);
	phone=phone.replace(/[^0-9]/g,'');
	var vlen=phone.length;
	
	if (phone=="") {
		
		e.style.backgroundColor  = 'yellow';	
		e.focus();
		e.select();
		alert("Please enter a valid phone number.");
		return false;
	}
	
	if (phone){
		if (vlen=='10' && !isNaN(phone)){
			goodphone="("+phone.slice(0,3)+") "+phone.slice(3,6)+"-"+phone.slice(6);
			e.value=goodphone;
		} else {
			alert("The phone number you have entered is in an unrecognized format. Please enter only 10 numbers including the area code.");
			e.focus();
			e.select();
			return false;
		}
	} else {
		e.value=phone;
	}
	
	return true;
	
}

/*  ********************************************
VALIDATE STRING
* ********************************************/

function ValidateString(cell, name) {

	if (cell.disabled == true) return true;
	
	var value = cell.value;
	
	cell.style.backgroundColor  = 'white';
	
	while (value.substring(0,1) == ' ') {
		value = value.substring(1, value.length);
	}
	while (value.substring(value.length-1,value.length) == ' ') {
		value = value.substring(0,value.length-1);
	}

	if (value=="") {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " must not be blank!");
		return false;
	
	}				
	
	if (value.indexOf("&")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain & characters!");
		return false;
	
	}
	
	if (value.indexOf("%")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain % characters!");
		return false;
	
	}
	
	if (value.indexOf("(")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain ( characters!");
		return false;
	
	}
	
	if (value.indexOf(")")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain ) characters!");
		return false;
	
	}
	
	if (value.indexOf("^")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain ^ characters!");
		return false;
	
	}
	
	if (value.indexOf("*")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain * characters!");
		return false;
	
	}
	
	if (value.indexOf("+")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain + characters!");
		return false;
	
	}
	
	if (value.indexOf("=")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain = characters!");
		return false;
	
	}
	
	if (value.indexOf("@")>=0 || value.indexOf("$")>=0 || value.indexOf("!")>=0 || value.indexOf(";")>=0 || value.indexOf(":")>=0 || value.indexOf("\"")>=0 || value.indexOf("?")>=0 || value.indexOf("<")>=0 || value.indexOf(">")>=0 || value.indexOf("/")>=0 || value.indexOf("\\")>=0) {
		
		cell.focus();
		cell.select();
		cell.style.backgroundColor  = 'yellow';
		alert(name + " cannot contain special characters!");
		return false;
	
	}
	
	return true;
	
}

