// JavaScript Document//For user REgistration
////////
function emailCheck (emailStr) 
		{

			var checkTLD=1;
			var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/	;
			var emailPat=/^(.+)@(.+)$/;
			var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
			var validChars="\[^\\s" + specialChars + "\]";
			var quotedUser="(\"[^\"]*\")";
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
			var atom=validChars + '+';
			var word="(" + atom + "|" + quotedUser + ")";
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
			var matchArray=emailStr.match(emailPat);
			
			if (matchArray==null) 
			{
				alert("Email address seems incorrect (check @ and .'s)");
				return false;
			}
			var user=matchArray[1];
			var domain=matchArray[2];
		
			for (i=0; i<user.length; i++)
			{
				if (user.charCodeAt(i)>127) 
				{
					alert("Ths username contains invalid characters.");
					return false;
	  		 	}
			}
			for (i=0; i<domain.length; i++) 
				{
					if (domain.charCodeAt(i)>127) 
					{
						alert("Ths domain name contains invalid characters.");
						return false;
	  		 		}
				}
	
				if (user.match(userPat)==null)
	 			{
					alert("The username doesn't seem to be valid.");
					return false;
				}
	
			var IPArray=domain.match(ipDomainPat);
	
			if (IPArray!=null) 
			{
			for (var i=1;i<=4;i++)
	 		{
				if (IPArray[i]>255)
		 		{
					alert("Destination IP address is invalid!");
					return false;
	   			}
			}
			return true;
		}
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) 
		{
			if (domArr[i].search(atomPat)==-1)
			{
				alert("The domain name does not seem to be valid.");
				return false;
	   		}
		}
	
		if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(	knownDomsPat)==-1) 
		{
			alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
		}
		if (len<2) 
		{
			alert("This address is missing a hostname!");
			return false;
		}
	
		return true;
	}	

///////////////////////////////////////////
//////////////////////////////////////

	function validateregistration() 
	{
		
		if (document.registration.fname.value=="") 
		{
			alert("Please enter your first name.");
			document.registration.fname.focus();
			return false;
		}
		if (document.registration.lname.value=="")
 		{
			alert("Please enter your last name.");
			document.registration.lname.focus();
			return false;
		}
		if (document.registration.address.value=="") 
		{
			alert("Please enter your address.");
			document.registration.address.focus();
			return false;
		}
		if (document.registration.city.value=="") {

			alert("Please enter your city.");
			document.registration.city.focus();
			return false;

		}
		
		if (document.registration.country_id.value=="") 
		{
			alert("Please select your country.");
			document.registration.country_id.focus();
			return false;

		}
		if (document.registration.email.value=="") 
		{
			alert("Please enter your email address.");
			document.registration.email.focus();
			return false;
		}
	
		if(!emailCheck(document.registration.email.value))
		{
				//alert("Please enter a valid e-mail address");
			document.registration.email.focus();
			return false;
			
		}
			
		if(document.registration.username.value=="")
		{
			alert('Please enter user name');
			document.registration.username.focus();
			return false;
			
		}
		if (document.registration.password.value=="")
		 {
			alert("Please enter password.");
			document.registration.password.focus();
			return false;
		}
		if (document.registration.retypepassword.value=="") 
		{
			alert("Please enter retype password.");
			document.registration.retypepassword.focus();
			return false;

		}
		
		if(document.registration.password.value!=document.registration.retypepassword.value)
		{
			alert("Retype password is not correct.");
			return false;
		}
		

}

function validateaddplot() 
	{
		
		if (document.add_plots.city_id.value=="select") 
		{
			alert("Please select city.");
			document.add_plots.city_id.focus();
			return false;
		}
		if (document.add_plots.plot_owner.value=="")
 		{
			alert("Please enter plot owner name.");
			document.add_plots.plot_owner.focus();
			return false;
		}
		if (document.add_plots.road_width.value=="") 
		{
			alert("Please enter road width.");
			document.add_plots.road_width.focus();
			return false;
		}
		if (document.add_plots.plot_marla.value=="") {

			alert("Please enter marlay of plot.");
			document.add_plots.plot_marla.focus();
			return false;

		}
		
		if (document.add_plots.plot_sf.value=="") 
		{
			alert("Please enter square ft of plot.");
			document.add_plots.plot_sf.focus();
			return false;

		}
		
		if(document.add_plots.plot_price.value=="")
		{
			alert('Please enter plot price');
			document.add_plots.plot_price.focus();
			return false;
			
		}
		if (document.add_plots.owner_phone.value=="")
		 {
			alert("Please enter owner phone no.");
			document.add_plots.owner_phone.focus();
			return false;
		}
		if (document.add_plots.owner_address.value=="") 
		{
			alert("Please enter plot address.");
			document.add_plots.owner_address.focus();
			return false;
		}
		
		if (document.add_plots.plot_desc.value=="") 
		{
			alert("Please enter plot description.");
			document.add_plots.plot_desc.focus();
			return false;

		}
		
		
		
}
/////validatio of add property
function validateaddproperty() 
	{
		
		if (document.add_plots.city_id.value=="select") 
		{
			alert("Please select city.");
			document.add_property.city_id.focus();
			return false;
		}
		if (document.add_property.prop_owner.value=="")
 		{
			alert("Please enter property owner name.");
			document.add_property.prop_owner.focus();
			return false;
		}
		if (document.add_property.beds.value=="")
 		{
			alert("Please enter number of beds.");
			document.add_property.beds.focus();
			return false;
		}
		if (document.add_property.bathrooms.value=="")
 		{
			alert("Please enter number of bathrooms.");
			document.add_property.bathrooms.focus();
			return false;
		}
		if (document.add_property.road_width.value=="") 
		{
			alert("Please enter road width.");
			document.add_property.road_width.focus();
			return false;
		}
		if (document.add_property.prop_marla.value=="") {

			alert("Please enter marlay of property.");
			document.add_property.prop_marla.focus();
			return false;

		}
		
		if (document.add_property.prop_sf.value=="") 
		{
			alert("Please enter square feet of property.");
			document.add_property.prop_sf.focus();
			return false;

		}
		
		if(document.add_property.prop_price.value=="")
		{
			alert('Please enter property price');
			document.add_property.prop_price.focus();
			return false;
			
		}
		if (document.add_property.owner_phone.value=="")
		 {
			alert("Please enter owner phone no.");
			document.add_property.owner_phone.focus();
			return false;
		}
		if (document.add_property.owner_address.value=="") 
		{
			alert("Please enter plot address.");
			document.add_property.owner_address.focus();
			return false;
		}
		
		if (document.add_property.prop_desc.value=="") 
		{
			alert("Please enter property description.");
			document.add_property.prop_desc.focus();
			return false;

		}
		
		
		
}

///////////////////////////////////Login area here/////////////////////////

function loginvalidation()
{
  if(document.login.adminName.value=="")
  {
	  	alert("Please enter admin name.");
		document.login.adminName.focus();
			return false;
	  }
 if(document.login.password.value=="")
  {
	  	alert("Please enter password.");
		document.login.password.focus();
			return false;
	  }
}
function loginvalidations()
{
  if(document.login.username.value=="")
  {
	  	alert("Please enter user name.");
		document.login.username.focus();
			return false;
	  }
 if(document.login.password.value=="")
  {
	  	alert("Please enter password.");
		document.login.password.focus();
			return false;
	  }
}
////contact us validation

function validationcontactus()
{
	
		if (document.contactus.your_name.value=="")
 		{
			alert("Please enter your name");
			document.contactus.your_name.focus();
			return false;
		}
		if(!emailCheck(document.contactus.email_address.value))
		{
				//alert("Please enter a valid e-mail address");
			document.contactus.email_address.focus();
			return false;
		}
			
}
////////////////////////////////////
function show_error(str,div_id){ 
	document.getElementById(div_id).style.display = "block";
	document.getElementById(div_id).innerHTML = str;
}
function hide_error(div_id){ 
	 document.getElementById(div_id).style.display = "none";
}
/////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////
function CheckPlotFields()
{    //alert('yes in checkplotfield');

		if(document.add_plot.sity_id.value=='select')
		{ 
			show_error("<font color='#CB3400'>Please select city name</font>",'div_sity');
		}else{hide_error('div_sity')
		}
		//for society
		if(document.add_plot.sok_id.value=='select')
		{ 
			show_error("<font color='#CB3400'>Please select society name</font>",'div_sok');
		}else{hide_error('div_sok')
		}
		//for plot owner
		if(document.add_plot.plot_owner.value=='')
		{ 
			show_error("<font color='#CB3400'>Please enter plot owner name</font>",'div_owner');
		}else{hide_error('div_owner')
		}
		//for plot marlay
		if(document.add_plot.plot_marla.value=='')
		{ 
			show_error("<font color='#CB3400'>Please enter plot marlay</font>",'div_marlay');
		}else{hide_error('div_marlay')
		}
		if(isNaN(document.add_plot.plot_marla.value))
		{ 
			show_error("<font color='#CB3400'>Please enter only digits</font>",'div_digit');
		}else{hide_error('div_digit')
		}
				
		// for owner phone
		if(document.add_plot.owner_phone.value=='')
		{ 
			show_error("<font color='#CB3400'>Please enter owner phone number</font>",'div_phone');
		}else{hide_error('div_phone')
		}
		
					
//agree
if((document.add_plot.sity_id.value!='select') && (document.add_plot.sok_id.value!='select') && (document.add_plot.plot_owner.value!='') && (document.add_plot.plot_marla.value!='') && (!isNaN(document.add_plot.plot_marla.value)) && (document.add_plot.owner_phone.value!='')){

document.add_plot.submit();
}

}//end 
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
function CheckPropertyFields()
{    //alert('yes in checkplotfield');

		if(document.add_property.sity_id.value=='select')
		{ 
			show_error("<font color='#CB3400'>Please select city name</font>",'div_sity');
		}else{hide_error('div_sity')
		}
		//for society
		if(document.add_property.sok_id.value=='select')
		{ 
			show_error("<font color='#CB3400'>Please select society name</font>",'div_sok');
		}else{hide_error('div_sok')
		}
		//for plot owner
		if(document.add_property.prop_owner.value=='')
		{ 
			show_error("<font color='#CB3400'>Please enter property owner name</font>",'div_owner');
		}else{hide_error('div_owner')
		}
		//for plot marlay
		if(document.add_property.prop_marla.value=='')
		{ 
			show_error("<font color='#CB3400'>Please enter property marlay</font>",'div_marlay');
		}else{hide_error('div_marlay')
		}
		if(isNaN(document.add_property.prop_marla.value))
		{ 
			show_error("<font color='#CB3400'>Please enter only digits</font>",'div_digit');
		}else{hide_error('div_digit')
		}
				
		// for owner phone
		if(document.add_property.owner_phone.value=='')
		{ 
			show_error("<font color='#CB3400'>Please enter owner phone number</font>",'div_phone');
		}else{hide_error('div_phone')
		}
		//agree

if((document.add_property.sity_id.value!='select') && (document.add_property.sok_id.value!='select') && (document.add_property.prop_owner.value!='') && (document.add_property.prop_marla.value!='') && (!isNaN(document.add_property.prop_marla.value)) && (document.add_property.owner_phone.value!='')){

document.add_property.submit();
}

}//end 
/////////////////////////////////////////////////////////////////////////////////////////////////
function CheckPeopleReq(){    
//alert('yes in checkplotfield');

        //for city
		if(document.people_requirement.city_id.value=='')
		{ 
			show_error("<samp class='on_error'>Please select city name</samp>",'div_city');
		}else{hide_error('div_city')}
		
		// for marlas
		if(document.people_requirement.marlas.value=='')
		{ 
			show_error("<samp class='on_error'>Please enter property marlas</samp>",'div_marlas');
		}else{hide_error('div_marlas')
		}
		
		if(document.people_requirement.estimated_pricee.value=='')
		{ 
			show_error("<samp class='on_error'>Please enter your estimated price</samp>",'div_estimated_pricee');
		}else{hide_error('div_estimated_pricee')}
				
			
					
//agree
if((document.people_requirement.city_id.value!='') && (document.people_requirement.marlas.value!='') && (document.people_requirement.estimated_pricee.value!='')){

document.people_requirement.submit();
}

}
//////////////////////////////////////end/////////////////////////////////////////////////
function CheckSocietyFields()
{    
		if(document.society_form.city_id.value=='')
		{ 
			show_error("<samp class='on_error'>Please select city name</samp>",'div_city');
		}else{hide_error('div_city')
		}
		//for society
		if(document.society_form.soc_name.value=='')
		{ 
			show_error("<samp class='on_error'>Please select society name</samp>",'div_society');
		}else{hide_error('div_society')
		}
		
//agree
if((document.society_form.city_id.value!='') && (document.society_form.soc_name.value!='')){
document.society_form.submit();
}

}