// JavaScript Document
function validate_buying(thisform)
{
	with (thisform)
	{ 
	
	
		if(Bedrooms.value=="Choose One")Bedrooms.value="";	
	if (emptyvalidation(Bedrooms,"Please enter Min.Bedrooms")==false) 
		{
		Bedrooms.focus();
		return false;	
		}
		if(Bathrooms.value=="Choose One")Bathrooms.value="";	
		if (emptyvalidation(Bathrooms,"Please enter Min.Bathrooms")==false) 
		{
		Bathrooms.focus();
		return false;	
		}
		if(Price_Range.value=="Choose One")Price_Range.value="";	
		if (emptyvalidation(Price_Range,"Please enter Price Range")==false) 
		{
		Price_Range.focus();
		return false;	
		}
	
	if (emptyvalidation(Rent_Or_Own,"Please enter Rent/Own")==false) 
		{
		Rent_Or_Own.focus();
		return false;	
		}
		if (emptyvalidation(Square_Footage,"Please enter Min.Square Footage")==false) 
		{
		Square_Footage.focus();
		return false;	
		}
		if (emptyvalidation(Location,"Please enter Location")==false) 
		{
		Location.focus();
		return false;	
		}
		if (emptyvalidation(Type_of_Condo,"Please enter Type of Home")==false) 
		{
		Type_of_Condo.focus();
		return false;	
		}
		if (emptyvalidation(name,"Please enter Name")==false) 
		{
		name.focus();
		return false;	
		}
		
	if (emptyvalidation(email,"Please enter E-mail Address")==false) 
		{
		email.focus();
		return false;	
		}		
		
		if(echeck(email.value)==false)
		{
			
			email.select();
			email.focus();
			return false;
		}
		
	
	
	if (emptyvalidation(phone,"Please enter Phone Number")==false) 
		{
		phone.focus();
		return false;	
		}
		if (emptyvalidation(comments,"Please enter Comments")==false) 
		{
		comments.focus();
		return false;	
		}
	
		
		
	}
	thisform.submit();
}	



function emptyvalidation(entered, alertbox)
{
	with (entered)
	{
		while (value.charAt(0) == ' ')
			value = value.substring(1);
		while (value.charAt(value.length - 1) == ' ')
			value = value.substring(0, value.length - 1);
		if (value==null || value=="")
		{
			if (alertbox!="") alert(alertbox);
			return false;
		}
		else return true;
	}
}

function echeck(str) 
	{
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)		 
		if (str.indexOf(at)==-1){			
		   alert("Invalid E-mail Address")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail Address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail Address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail Address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail Address")
		    return false
		 }
		
	 return true					
	}
