
///////////////////       email validaion ///////

function EmailValidation(Element)
	{
		Flag  = 1;
		count = 0;
	
		var alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_@.-";
		
		if(Element.value.length > 0)
		{
			for (var i=0; i<Element.value.length; i++)
			{
				temp = Element.value.substring(i, i+1);
	
				if (alp.indexOf(temp) == -1)
				{
					Flag = 0;
				}
			} // closing the for loop
		}
		else
		{
			Flag = 0;
		}
	
		for(var i=0; i <= Element.value.length; i++)
		{
			if(Element.value.charAt(0)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(Element.value.length-1)=='@')
			{
				Flag = 0;
				break;
			}

			if(Element.value.charAt(i)=='@') 
			{
				count = count + 1;

				if(count>1)
				{
					Flag = 0;
					break;
				}
			  
				if((Element.value.charAt(i-1)=='.') || (Element.value.charAt(i+1)=='.'))
				{
					Flag = 0;
					break;
				}
			}
			if(Element.value.indexOf('@')==-1)
			{
				Flag = 0;		    	
				break;
			}
			if(Element.value.charAt(0)=='.')
			{
				Flag = 0;
				break;
			}
			if(Element.value.indexOf('.')==-1)
			{
				Flag = 0;		    	
				break;
			}
		  } //closing the for loop
		///// added  
		if (Element.value.indexOf('..') > 0){
			Flag=0;
		}
		//////
		if(Element.value.charAt(Element.value.length-1) == '.')
			Flag = 0;
			
		if(Flag != 1)
		{
			alert("Invalid Email Address.\nValid Characters are [a-z][A-Z][0-9][ _ @ . - ].");
			Element.focus();
			return 0;
		}	
		else
			return 1;
	}
	
//        end email validation/////
///////////////////////////////Login validation//////////////////////////
function login()
{
	
	var username = document.formx1.username.value;
	var password = document.formx1.password.value;
		if(username == "")
		{
			alert("Please enter User Name.");
			document.formx1.username.focus();
			return false;
		
		}	
		if(password == "")
		{
			alert("Please enter Password.");
			document.formx1.password.focus();
			return false;
		
		}	
	else
	{
		document.formx1.action='login.php';
		document.formx1.submit();
	}

}



////////////////////////////////End //////////////////////////////////////////////////


//////////////////////////////Logout ////////////////////////////////////////////////
function logout()
{       
		document.formx1.action='logout.php';
		document.formx1.submit();
}
/////////////////////////////////////End ///////////////////////////////////////


///////////////////////////////Properties validation//////////////////////////
function property()
{
	
	/*var username = document.formx1.username.value;
	var password = document.formx1.password.value;
		if(username == "")
		{
			alert("Please enter User Name.");
			document.formx1.username.focus();
			return false;
		
		}	
		if(password == "")
		{
			alert("Please enter Password.");
			document.formx1.password.focus();
			return false;
		
		}	
	else
	{*/
	
	document.formx1.action='add_property.php?ok=add';
	document.formx1.submit();
	/*}*/

}



////////////////////////////////End //////////////////////////////////////////////////


//////////////////////////////Number Validation ////////////////////////////////////////////////
function number(f)
{       
       	numb=f.value;
		document.formx2.action='login.php?numb='+numb;
		document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////

//////////////////////////////property selection ////////////////////////////////////////////////
function properties(f)
{       

p_id=f.value;
document.formx2.action='property_add1.php?p_id='+p_id;
document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////

//////////////////////////////New User property selection ////////////////////////////////////////////////
function properties2(f)
{       

p_id=f.value;
document.formx2.action='newuser_add1.php?p_id='+p_id;
document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////

//////////////////////////////property selection ////////////////////////////////////////////////
function deletepro(f,del_id)
{       
proper=f.property.value;
pid=f.p_id.value;

if(proper == "0")
{
	alert("Please select a Property To Delete");
	f.property.focus();
	return false;
}

document.formx2.action='property_delete.php?ok=delete&P_id='+proper+'&PageNo='+del_id;
document.formx2.submit();

}
/////////////////////////////////////End ///////////////////////////////////////


//////////////////////////////Number Validation ////////////////////////////////////////////////
function letter()
{       
       	
		f=document.form_news;
		e_mail=f.e_mail.value;
		if(!EmailValidation(f.e_mail,'Email','','')) {
		return false;
		}
		
		 window.location='newsletter.php?e_mail='+e_mail;
		//document.form_news.submit();
}
/////////////////////////////////////End ///////////////////////////////////////


//////////////////////////////form_type Validation ////////////////////////////////////////////////
function advertise()
{       
       	
		alert("ok its checked");
		/*f=document.form_type;
		e_mail=f.e_mail.value;
		if(!EmailValidation(f.e_mail,'Email','','')) {
		return false;
		}
		
		 window.location='newsletter.php?e_mail='+e_mail;*/
		 return false;
		//document.form_news.submit();
}
/////////////////////////////////////End ///////////////////////////////////////


function register(f) {
	
		var fname = document.formx2.fname.value;
		if(fname == "")
		{
			alert("Please enter First Name.");
			document.formx2.fname.focus();
			return false;
		
		}
		var lname = document.formx2.lname.value;
		if(lname == "")
		{
			alert("Please enter Last Name.");
			document.formx2.lname.focus();
			return false;
		
		}	
		var country = document.formx2.country.value;
		if(country == "")
		{
			alert("Please enter the country.");
			document.formx2.country.focus();
			return false;
		
		}	
		email=document.formx2.email.value;
		if(!EmailValidation(f.email,'Email','','')) {
		return false;
		}
		email1=document.formx2.email1.value;
		if(!EmailValidation(f.email1,'Email','','')) {
		return false;
		}
		if(email != email1)
		{
		alert("Your Email and Confirmation Email are Not Matching");
		email1=document.formx2.email1.value;
		return false;
		}
		
	
}
///////////////

//////////////////////////////Advance Search ////////////////////////////////////////////////
function advancesearch()
{      
		var country = document.formx2.property_city.value;
		if(country == "")
		{
			alert("Please select the city.");
			document.formx2.property_city.focus();
			return false;
		
		}
		
		document.formx2.action='search_results.php';
		document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////
//////////////////////////////Owner Search ////////////////////////////////////////////////
function ownercheck()
{      
		var country = document.owner.property_city.value;
		if(country == "")
		{
			alert("Please select the location");
			document.owner.property_city.focus();
			return false;
		
		}
		
		//document.formx2.action='search_results.php';
//		document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////

//////////////////////////////Advance Search  for testing ////////////////////////////////////////////////
function advancesearched()
{       
		var country = document.formx2.property_country.value;
		if(country == "")
		{
			alert("Please select the country.");
			document.formx2.property_country.focus();
			return false;
		
		}
		
		document.formx2.action='search_results_30.php';
		document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////

//////////////////////////////Advance Search ////////////////////////////////////////////////
function wantedsearch()
{       
		var country = document.formx2.state.value;
		if(country == "")
		{
			alert("Please select the city.");
			document.formx2.state.focus();
			return false;
		
		}
		document.formx2.action='wanted_results.php';
		document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////

//////////////////////////////Advance Search ////////////////////////////////////////////////
function offer(f,email)
{       
property_id=document.formx2.prop.value;

alert("Suggested Property Successfully");

document.formx2.action='suggest_property.php?p_id='+property_id+'&email='+email;
		document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////


	//////////////////////////////virtual tour photos ////////////////////////////////////////////////
function virtualpic(f,p_id)
{
img=f.value;

window.location.href='virtualtour.php?id='+p_id+'&img_no='+img;

}
/////////////////////////////////////End ///////////////////////////////////////

//////////////////////////////property selection ////////////////////////////////////////////////
function bannerpoints(f)
{       

p_id=f.value;
document.formx2.action='points_prints.php?p_id='+p_id;
document.formx2.submit();
}
/////////////////////////////////////End ///////////////////////////////////////

///////////////////my account Validaiont /////////////
function validateaccount()
{
	urlname=document.formx2.displayname.value;
	if(urlname == "")
		{
			alert("Please Enter the Display/Url Name.");
			document.formx2.displayname.focus();
			return false;
		
		}
		
	
		document.formx2.action='myaccount.php';
		document.formx2.submit();
		

	
}





/////
function agent_email(f) {
	
		
		email=document.formx2.email.value;
		if(!EmailValidation(f.email,'Email','','')) {
		return false;
		}
		
		
		return true;
	
}
///////////////

//////////////////////////////Advance Search ////////////////////////////////////////////////
function addbanner()
{       
		alert("hi");
		
}
/////////////////////////////////////End ///////////////////////////////////////

/////////////////////////add property//////////////////////////////////////////////
/////
function addproperty1() {
	
		
		name=document.formx2.property_name.value;
		country=document.formx2.property_country.value;
		type=document.formx2.property_type.value;
		if(name == '') {
		alert("Please Enter Property Name");
		document.formx2.property_name.focus();
		return false;
		}
		if(country == '') {
		alert("Please select the country");
		document.formx2.property_country.focus();
		return false;
		}
		if(type==''){alert("Please Choose A Property Type");
		document.formx2.property_type.focus();
		return false;}
		
		
		return true;
	
}
////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////Wanted property1//////////////////////////////////////////////
/////
function wanteddetail1(f) {
	
		//alert("hello");
		name=document.formx2.fname.value;
		lname=document.formx2.lname.value;
		//country=document.formx2.country.value;
		email=document.formx2.email.value;
		if(name == '') {
		alert("Please Enter First Name");
		document.formx2.fname.focus();
		return false;
		}
		if(lname == '') {
		alert("Please Enter Last Name");
		document.formx2.lname.focus();
		return false;
		}
		/*if(country == '') {
		alert("Please Select Country");
		document.formx2.country.focus();
		return false;
		}*/
		if(email == '') {
		alert("Please Enter Email");
		document.formx2.email.focus();
		return false;
		}
		if(!EmailValidation(f.email,'Email','','')) {
		return false;
		}
		
		
		return true;
	
}
////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////Wanted property1//////////////////////////////////////////////
/////
function wanteddetail2() {
	
		
		from=document.formx2.from1.value;
		to=document.formx2.to1.value;
		if(from == '') {
		alert("Please Enter From Price");
		document.formx2.from1.focus();
		return false;
		}
		if(to == '') {
		alert("Please Enter To Price");
		document.formx2.to1.focus();
		return false;
		}
		country=document.formx2.country.value;
		if(country == '') {
		alert("Please select the country");
		document.formx2.country.focus();
		return false;
		}
		
		
		return true;
	
}
////////////////////////////////////////////////////////////////////////////////////////



///////////////////////////////////sending property to friend/////////////////////////

function friend(fri) {
	
	name=document.form2.name.value;
	from=document.form2.frommail.value;
	toname=document.form2.toname.value;
	tomail=document.form2.tomail.value;
	
	if(name == '') {
		alert("Please Enter You Name");
		document.form2.name.focus();
		return false;
		}
		if(!EmailValidation(fri.frommail,'Your Email','','')) {
		return false;
		}
		if(toname == '') {
		alert("Please Enter Friend's Name");
		document.form2.toname.focus();
		return false;
		}	
	    if(!EmailValidation(fri.tomail,'Friends Email','','')) {
		return false;
		}
		if(from==tomail) {
		alert("Please enter your friends Mail Id ,your and your friends Mail Id both are same");
		return false;
		
		}
			
	
	return true;
}
////////////////////////////////////////////end///////////////////////////////////
	
