// JavaScript Document

//-------------- This Function will show/hide Login/Subscriber Layers --------------
function budget_layer()
{
	if($('search_ad_type').value=="Rent")
	{
		$('budget_div').hide();
		$('rent_budget_div').show();
		$('isbudget').value="rent";
	}
			else if($('search_ad_type').value=="Buy")
			{
				$('budget_div').show();
				$('rent_budget_div').hide();
				$('isbudget').value="buy";
			}
					
						else if($('search_ad_type').value=="")
						{
							$('budget_div').hide();
							$('rent_budget_div').hide();
							$('isbudget').value="";
						}
							
}

function login()
{
	//$('subscribers_show').hide();
	$('logiHorizLayer1').hide();
	$('logiHorizLayer2').show();
	$('logininfo').show();
	$('loginOpen').hide();
	$('loginClose').show();
	$('menu-bar').hide();
}

// make fields empty
function makeEmpty(id, sid, defaultvalue)
{
	if($(id).value == defaultvalue)
	{
		$(id).value = "";
	}
}
function fillValue(id, sid, defaultvalue)
{
	if( $(id).value == "")
	{
		$(id).value = defaultvalue;
	}
}





function selOpt(OptLstNam, LstVal)
{
	for (i=0; i < OptLstNam.length; i++)
	{
		if (OptLstNam.options[i].value == LstVal)
		{
			OptLstNam.selectedIndex = i;
			break;
		}
	}
}

function show_Login_Layer( layer )
{
	//alert( layer );	
	if( layer == "login" )
	{
		$('subscribers_show').hide();
		$('logininfo').show();
	}
	
	if( layer == "error_login_message" )
	{
		alert( layer );
		$('campaign_login').hide();
		$('error_login_message').show();
	}
	
	if( layer == "campaign_login" )
	{
		$('error_login_message').hide();
		$('campaign_login').show();
	}
	
	if( layer == "campaign_login_off" )
	{
		//$('campaign_login_error').hide();
		$('campaign_login').hide();
	}
	
	if( layer == "subscribers" )
	{
		$('logininfo').hide();
		$('subscribers_show').show();
	}
	
	if( layer == "subscriber_error" )
	{
		//alert("1");
		
		$('subscribers_success').hide();
		$('subscribers_already').hide();
		$('subscribers_error').hide();
		$('subscribers_show').show();
		//alert("3");
	}
	
	if( layer == "subscriber_show_error" )
	{
		//alert("here");
		$('subscribers_show').hide();
		//alert("here1");
		$('subscribers_error').show();
		//alert("here2");
	}
	
	if( layer == "forum_login" )
	{
		$('forum_subscribers_show').hide();
		$('logininfo').show();
	}
	
	if( layer == "forum_subscribers" )
	{
		$('logininfo').hide();
		$('forum_subscribers_show').show();
	}
	
	if( layer == "forum_subscribers_error" )
	{
		//alert("here");
		$('forum_subscribers_error').hide();
		$('forum_subscribers_success').hide();
		//alert("here1");
		$('forum_subscribers_show').show();
		//alert("here2");
	}
	
	if( layer == "forum_subscribers_success" )
	{
		//alert("here");
		$('forum_subscribers_error').hide();
		$('forum_subscribers_success').hide();
		//alert("here1");
		$('forum_subscribers_show').show();
		//alert("here2");
	}
	
	if(layer == "emailit")
	{
	
		$('noemail').hide();	
		$('emailit').show();
	}
	
	if(layer == "noemail")
	{
		$('emailit').hide();	
		$('noemail').show();
	}
	
	if( layer == "change_image" )
	{
		$('change_photo').show();
	}
	
	if( layer == "change_image_firm" )
	{
		$('change_photo_firm').show();
	}
	
	if( layer == "change_image_firm_logo" )
	{
		$('change_photo_firm_logo').show();
	}
	
	if( layer == "change_image_profile" )
	{
		$('change_photo_profile').show();
	}
	
	if( layer == "contact_div" )
	{
		$('contact_div').show();
	}
	
	if( layer == "add_additional" )
	{
		
		$('add_additional_home').hide();
		$('home_additional_fields_hide').show();
		$('remove_additional_home').show();
		$('additionalDiv').value = 'show';
	}
	
	if( layer == "remove_additional" )
	{
		$('remove_additional_home').hide();
		$('home_additional_fields_hide').hide();
		$('add_additional_home').show();
		$('additionalDiv').value = '';
		
	}
	
	if( layer == "add_additional_shop" )
	{
		$('add_additional_shop').hide();
		$('shop_additional_fields_hide').show();
		$('remove_additional_shop').show();
		$('additionalDiv').value = 'show';
	}
	
	if( layer == "remove_additional_shop" )
	{
		$('remove_additional_shop').hide();
		$('shop_additional_fields_hide').hide();
		$('add_additional_shop').show();
		$('additionalDiv').value = '';
		
	}
	
	if( layer == "add_additional_office" )
	{
		//alert("1");
		$('add_additional_office').hide();
		$('office_additional_fields_hide').show();
		$('remove_additional_office').show();
		$('additionalDiv').value = 'show';
	}
	
	if( layer == "remove_additional_office" )
	{
		$('remove_additional_office').hide();
		$('office_additional_fields_hide').hide();
		$('add_additional_office').show();
		$('additionalDiv').value = '';
	}
	
	if( layer == "add_additional_land" )
	{
		//alert("1");
		$('add_additional_land').hide();
		$('land_additional_fields_hide').show();
		$('remove_additional_land').show();
		$('additionalDiv').value = 'show';
	}
	
	if( layer == "remove_additional_land" )
	{
		$('remove_additional_land').hide();
		$('land_additional_fields_hide').hide();
		$('add_additional_land').show();
		$('additionalDiv').value = '';
	}
	
	if( layer == "hometype" )
	{
		var h_type;
		h_type = $('hometype').value;
		
		if(h_type == "Independent Portion" || h_type == "Flat/Apartment")
		{
			$('noofstories').hide();
			$('flat').show();
		}
		else
		{
			$('flat').hide();
			$('noofstories').show();
		}
	}
	
	if( layer == "additionalform" )
	{
		$('mainform').hide();
		$('additionalform').show();
		$('additionalDiv').value = 'show';
	}
	else if ( layer == "mainform" )
	{
		$('additionalform').hide();
		$('mainform').show();
		$('additionalDiv').value = '';
	}
	
	/*if( layer == "property_want_emailit")
	{
		$('property_want_emailit').show();
	}*/
	/*else if(layer == "property_want_cancelit")
	{
		$('property_want_emailit').hide();
	}
	*/
	if( layer == "property_want_emailit")
	{
			$('property_want_noemail').hide();
		$('property_want_emailit').show();
	}
	else if(layer == "property_want_cancelit")
	{
		$('property_want_emailit').hide();
		$('property_want_noemail').show();
	}
	
	
	if(layer == "profile_alert")
	{
		//alert( layer );
		$('profile_alert').hide();
		//alert( layer );
	}
	
	if(layer == "gmail_div")
	{
		//alert( layer );
		$('yahoo_div').hide();
		$('gmail_div').show();
		$('servername').value = "@gmail.com";
		//alert( layer );
	}
	
	if(layer == "yahoo_div")
	{
		//alert( layer );
		$('gmail_div').hide();
		$('yahoo_div').show();
		$('servername').value = "@yahoo.com";
		//alert( layer );
	}
	
	if(layer == "showReportLayer")
	{
		//alert(layer);
		$('hideReportLayer').hide();
		$('showReportLayer').show();
	}
	
	if(layer == "hideReportLayer")
	{
		//alert(layer);
		$('showReportLayer').hide();
		$('hideReportLayer').show();
	}
	
	if(layer == "showReportThisAgent")
	{
		//alert(layer);
		$('hideReportThisAgent').hide();
		$('showReportThisAgent').show();
	}
	
	if(layer == "hideReportThisAgent")
	{
		//alert(layer);
		$('showReportThisAgent').hide();
		$('hideReportThisAgent').show();
	}
	
	if(layer == "mobileWithCode")
	{
		//alert(layer);
		$('mobileWithCode').hide();
		//alert("a");
		$('buttonWithCode').hide();
		//alert("b");
		$('buttonWithOutCode').show();
		//alert("c");
		$('mobileWithoutCode').show();
		//alert("d");
		$('new').value = 'new';
	}
	
	if( layer == "visitingdayto_hide" )
	{
		//alert(layer);
		$('visitingdayto_show').hide();
		$('visitingdayto_hide').show();
		
		if($('valueExchange').value == 'Yes')
		{
			$('visitdayfrom_id').value = $('visitdayfromid').value;
			$('valueExchange').value = '';
		}
	}
	
	if( layer == "visitingdayto_show" )
	{
		//alert(layer);
		$('visitingdayto_hide').hide();
		$('visitingdayto_show').show();
		
		if($('valueExchange').value == 'Yes')
		{
			$('visitdayfromid').value = $('visitdayfrom_id').value;
			$('valueExchange').value = '';
		}
		
	}
	
	if( layer == "MobileWithCode_fromRegister" )
	{
		//alert("a");
		$('mobileWithCode').hide();
		//alert("c");
		$('mobileWithoutCode').show();
		//alert("d");
		$('new').value = 'new';
	}
	
	if( layer == "MobileWithCode_fromRegister1" )
	{
		//alert("a");
		$('mobileWithCode2').hide();
		//alert("c");
		$('mobileWithoutCode2').show();
		//alert("d");
		$('new1').value = 'new';
	}
	
	if( layer == "countries" )
	{
		$('cities').hide();
		$('city').value="";
		$('area-tr').hide();
		$('area').value="";
		$('otherArea').value="";
		$('phnumber1').hide();
		$('phnumber2').hide();
		$('number1').hide();
		$('number2').hide();
		$('mobcode1').value="";
		$('mobcode2').value="";
		$('mobnum1').value="";
		$('mobnum2').value="";
		$('phcode1').value="";
		$('phcode2').value="";
		$('phnum1').value="";
		$('phnum2').value="";
		$('other-tr1').show();
		$('otherph-tr1').show();
		$('countries').show();
		$('iscountry').value="yes";
		
		
	//$('city').value = "";
	}
	else if( layer == "cities" )
	{
		$('countries').hide();
		$('country').value="";
		$('other-tr1').hide();
		$('other-tr2').hide();
		$('otherph-tr1').hide();
		$('otherph-tr2').hide();
		$('othernumber1').value="";
		$('othernumber2').value="";
		$('otherphnumber1').value="";
		$('otherphnumber2').value="";
		$('phnumber1').show();
		$('number1').show();
		$('cities').show();
		$('iscountry').value="";
	}
	
	if( layer == "add_outside_country" )
	{	
		$('add_outside_country_link').hide();
		$('add_outside_country').show();
	}
	if( layer == "remove_add_outside_country" )
	{	
		$('outside_country_number1').value = "";
		$('add_outside_country').hide();
		$('add_outside_country_link').show();
	}
	if( layer == "add_outside_mobile" )
	{	
		$('add_outside_mobile_link').hide();
		$('add_outside_mobile').show();
	}
	if( layer == "remove_add_outside_mobile" )
	{	
		$('outside_mobile_number1').value = "";
		$('add_outside_mobile').hide();
		$('add_outside_mobile_link').show();
	}
	if(layer == "add_anothermobile")
	{
		
		$('add_outside_mobile_link').hide();
		$('add_outside_mobile').show();	
	}
	if(layer == "add_anotherphone")
	{
		$('add_outside_country_link').hide();
		$('add_outside_country').show();	
	}
	
	
	if(layer == "show_budget_layer")
	{
		
		if($('search_ad_type').value == "Rent")
		{
			$('budget_div').hide();
			$('rent_budget_div').show();
			$('isbudget').value = "rent";
		}
		else if($('search_ad_type').value == "Buy")
		{
			$('rent_budget_div').hide();
			$('budget_div').show();
			$('isbudget').value = "buy";
		}
		else if($('search_ad_type').value == "")
		{
			$('rent_budget_div').hide();
			$('budget_div').hide();
			$('isbudget').value = "";
		}
	}// end if(layer == "budget_type") 
}
//-------------- End of function show_Login_Layer( layer ) --------------

//-------------- This Function will check empty subscriber field and it will perform email validation--------------

function validate_Subscriber_Form(  )
{
	if (document.come_subscribers.property_alert_email.value == "")
	{
		alert("Please write your email to subscribe!");	
		document.come_subscribers.property_alert_email.focus();
		return false;
	}
	else if (document.come_subscribers.property_alert_email.value.indexOf('@',0) < 0 || document.come_subscribers.property_alert_email.value.indexOf('.',0) < 0 || !checkchar(document.come_subscribers.property_alert_email.value," ?/:,;=+'\"<>|\\`~{}#$%!^&*()"))
	{
		alert("You have given invalid email address");
		document.come_subscribers.property_alert_email.focus();
		return false;
	}
}
//-------------- function validate_Subscriber_Form( Value ) --------------

function checkchar(mystr,invalidChars1)
{
			
	for (i=0; i<invalidChars1.length; i++) // does it contain any invalid characters?
		{
			badChar1 = invalidChars1.charAt(i)
			if (mystr.indexOf(badChar1,0) > -1) 
				{
					return false;
				}
		}
return true;
}

//-------------- This Function will check empty subscriber field and it will perform email validation--------------

function characters_left( fieldid, limit, return_field )
{
	var total_left;
	fieldname = $(fieldid).value;
	//alert (fieldname);
	//alert(fieldname.length + "<" + limit);
	if(fieldname.length < limit)
	{
		total_left = limit - fieldname.length;	
		$(return_field).value = total_left;
	}
	else
	{
		alert('Your characters limit has exceeded and characters above this limit will not been saved!');
		$(fieldid).value = $(fieldid).value.substring(1, limit);
		$(return_field).value = 0;
	}
}
//-------------- function validate_Subscriber_Form( Value ) --------------

//-------------- function will be used to open large image in a  new window --------------
function image_popup(image_path)
{
	//alert(image_path);
	window.open(image_path,"mywindow","resizable=1" );	
}
//-------------- function image_popup(image_path) --------------

//-------------- function will be used to open large image in a  new window --------------
function popup_image(image_path)
{
	//alert(image_path);
	window.open(image_path,"mywindow","resizable=1" );	
}
//-------------- function popup_image(image_path) --------------

//-------------- function will be used to popup pages in new window --------------
function page_popup(page_path, height, width)
{
	//alert(page_path+" "+height+" "+width);
	window.open(page_path,"mywindow","height="+height+",width="+width+", resizable=1");
}
//-------------- function image_popup(image_path) --------------

//-------------- function will validate the login form --------------
function validate_loginform( usernameid, passwordid )
{
	//alert(formname);
	if($(usernameid).value == "")
	{
		alert("Please enter your username to get login!");
		$(usernameid).focus();
		return false;
	}
	else if($(passwordid).value == "")
	{
		alert("Please enter your password to get login!");
		$(passwordid).focus();
		return false;
	}
}
//-------------- function validate_loginform() --------------

//-------------- function will be used to Redirect from one page to other. --------------
function goAtPage( url )
{
	//alert(url);
	window.location = url;
}
//-------------- function goAtPage( url ) --------------

//-------------- function will validate change password form --------------
function validate_change_password_form(  )
{
	if(document.property_ads_manage_myaccount.currentpassword.value == "")
	{
		alert("Please enter your current password!");
		document.property_ads_manage_myaccount.currentpassword.focus();
		return false;
	}
	else if(document.property_ads_manage_myaccount.newpassword.value == "")
	{
		alert("Please enter your new password!");
		document.property_ads_manage_myaccount.newpassword.focus();
		return false;
	}
	else if(document.property_ads_manage_myaccount.confirmnewpassword.value == "")
	{
		alert("Please confirm your new password!");
		document.property_ads_manage_myaccount.confirmnewpassword.focus();
		return false;
	}
	else if(document.property_ads_manage_myaccount.confirmnewpassword.value != document.property_ads_manage_myaccount.newpassword.value)
	{
		alert("Your new password didn't match!");
		document.property_ads_manage_myaccount.confirmnewpassword.focus();
		return false;
	}
}

function validate_reset_password_form(  )
{
	if(document.property_reset_password.your_password.value != document.property_reset_password.your_confrim_pw.value)
	{
		alert("Your new password didn't match!");
		document.property_reset_password.your_confrim_pw.focus();
		return false;
	}
}




//-------------- function validate_change_password_form(  ) --------------

//-------------- function will cancel change password process --------------
function cancel_change_password_form(  )
{
	document.property_ads_manage_myaccount.currentpassword.value = "";
	document.property_ads_manage_myaccount.newpassword.value = "";
	document.property_ads_manage_myaccount.confirmnewpassword.value = "";
}
//-------------- function cancel_change_password_form(  ) --------------

//-------------- function will return you total characters of particular field --------------
function total_characters( fieldid, limit, return_field )
{

	var total_left;
	//alert(return_field);


	fieldname = $(fieldid).value;
	
	total_left = limit - fieldname.length;

	//alert(total_left);
	
	$(return_field).value = total_left;
		
	//alert(fieldname.length + " < " + limit +" = "+ total_left);
}
//-------------- function total_characters(  ) --------------

function news_layers_management(id, total)
{	
	for(i = 1 ; i<= total; i++)
	{
		$(i).hide();
	}
		$(id).show();
}

//-------------- function will take you in contact box --------------
function contact_box( fieldid )
{
	$(fieldid).focus();
}
//-------------- function total_characters(  ) --------------

//--------------function will manage layers to send news as email on basteenaaama page --------------
function email_news_layer(id,action,total)
{
	if(action == 'show')
	{
		for(i=0 ; i<total; i++)
		{
			$(i).hide();
		}
		$(id).show();
	}
	else if(action =='hide')
	{
		$(id).hide();	
	}
}
//-------------- function email_news_layer(id, action) --------------

//-------------- This function will help to delete record from your favorites --------------
function delete_from_myfavorites( formname )
{
	
	if(formname == "favorite_agents")
	{
		var flag;
		flag = confirm("Do you want to delete your agent(s) from your favorites?");
		
		if( flag == true )
		{
			document.favorite_agents.submit();
		}
	}
	
	if(formname == "favorite_news")
	{
		var flag;
		flag = confirm("Do you want to delete your news from your favorites?");
		
		if( flag == true )
		{
			document.favorite_news.submit();
		}
	}
	
	if(formname == "favorite_property")
	{
		var flag;
		flag = confirm("Do you want to delete your property from your favorites?");
		
		if( flag == true )
		{
			document.favorite_property.submit();
		}
	}
	
	if(formname == "property_ads_manage")
	{
		var flag;
		flag = confirm("Do you want to delete your ad from bastee?");
		
		if( flag == true )
		{
			document.property_ads_manage.submit();
		}
	}
}
//-------------- function delete_from_myfavorites( formname ) --------------

//// vaslidate user search form on admin side
function validate_usersearch()
{
	if(document.search_users.uname.value == "")
	{
		alert("Provide username to search");
		document.search_users.uname.focus();
	}
	else
	{
		document.search_users.submit();
	}
}


/// validate ads search form on admin side
function validate_adsearch()
{
	if(document.search_ads.adid.value == "")
	{
		alert("Provide id to search");
		document.search_ads.adid.focus();
	}
	else
	{
		document.search_ads.submit();
	}
}

function del_profile_image( url )
{
 	flag = 	confirm("Do you want to delete this image");
	
	if(flag)
	{
		window.location = url;
	}
}

//// function to open a new popup window
function pop_up(url)
 {
 	window.open (url,"mywindow","resizable=yes, scrollbars=yes");
 }
 
// prompt admin to make sure that wants to delete a report 
function confirm_report_deletion( url )
{
	flag = confirm("Do you want to delete reported item from bastee");	
	
	if(flag)
	{
		window.location = url;
	}
}

function validateAdAction(action)
{
	if( action == 'accept')
	{
		flag = confirm("Do you want to accept selected ad(s)");
		if(flag)
		{
			document.ads_status.option.value = 'accept';
			document.ads_status.submit();
		}
	}
	else if( action == 'unaccept')
	{
		flag = confirm("Do you want to inactive selected ad(s)");
		if(flag)
		{
			document.ads_status.option.value = 'unaccept';
			document.ads_status.submit();
		}
	}
	else if( action == 'reject')
	{
		flag = confirm("Do you want to reject selected ad(s)");
		if(flag)
		{
			document.ads_status.option.value = 'reject';
			document.ads_status.submit();
		}
	}
	else if( action == 'delete')
	{
		flag = confirm("Do you want to delete selected ad(s)");
		if(flag)
		{
			document.ads_status.option.value = 'delete';
			document.ads_status.submit();
		}
	}
	else if( action == 'featured')
	{
		flag = confirm("Do you want to make selected ad(s) featured?");
		if(flag)
		{
			document.ads_status.option.value = 'featured';
			document.ads_status.submit();
		}
	}
	else if( action == 'unfeatured')
	{
		flag = confirm("Do you want to make selected ad(s) Unfeatured?");
		if(flag)
		{
			document.ads_status.option.value = 'Unfeatured';
			document.ads_status.submit();
		}
	}
	else if( action == 'sold')
	{
		flag = confirm("Do you want to make selected ad(s) sold?");
		if(flag)
		{
			document.ads_status.option.value = 'sold';
			document.ads_status.submit();
		}
	}
	else if( action == 'rented')
	{
		flag = confirm("Do you want to make selected ad(s) rented out?");
		if(flag)
		{
			document.ads_status.option.value = 'rented';
			document.ads_status.submit();
		}
	}
}//function validateAdAction(action)

function getCityAds()
{
	document.get_City_Ads.submit();	
}

///// function makes the field empty
function fillValue(id, sid, defaultvalue)
{
	if( document.getElementById(id).value == "")
	{
		document.getElementById(id).value = defaultvalue;
	}
	//else if(document.getElementById(id).value == "" )
	//{
		//document.getElementById(id).value = document.getElementById(sid).value;
	//}
}


function getCityAds( city_from )
{
	if( city_from == "homepage_city" )
	{
		document.get_homepage_City_Ads.submit();	
	}
	
	if( city_from == 'get_adall_City_Ads')
	{
		document.get_adall_City_Ads.submit();	
	}
	
	if( city_from == 'get_adbuy_City_Ads')
	{
		document.get_adbuy_City_Ads.submit();	
	}
	if(city_from == "get_homepage_hostel_Ads")
	{
		document.get_homepage_hostel_Ads.submit();	
	}
}

function getCityAdds(action,categ,ptype)
{
	
city=$('homepage_city').value;
type=$('addtype').value;

if(type == "")
type="All";

var url="property-listing/1/"+ptype+"-";

		if (city != "")
		{
			window.location = url+type+"/"+city+"/";
		}
		else
		window.location = url+type+"/";	
		
/*			else if (type == "rent" || type == "buy" || type == "All")
			{
				window.location = url+type+"/";	
			}*/
}



function validate_Keyword_Field()
{
	if( document.propertysearch.keywords.value == "" )
	{
		alert("Please write some keywords to search (e.g. Home, 5 Marla, Lahore)");	
		document.propertysearch.keywords.focus();
		return false;
	}
}

function invite_friends_checkbox(  )
{
	var checks = document.getElementsByName('invite[]');

	if ( $('checkboxvalue').value == 'false' )
	{
		for ( i = 0; i < checks.length; i++ )
		{
			checks[i].checked = true;
		}
		$('selectall').checked = true;
		$('selectall2').checked = true;
					$('checkboxvalue').value = 'true';
	}
	else if ( $('checkboxvalue').value == 'true' )
	{
		for ( i = 0; i < checks.length; i++ )
		{
			checks[i].checked = false;
		}
		$('selectall').checked = false;
		$('selectall2').checked = false;
					$('checkboxvalue').value = 'false'
	}	
}

function MakeOffer( fieldid )
{
	if($(fieldid).value == "")
	{
		alert( "Please write your offer?" );
		$(fieldid).focus();
		return false;
	}
}

////// fucnction to validate data on form for creating special account on admin sie
function validateAccountForm()
{
	if(	document.accountForm.user.value == "")
	{
		alert("Provide user name");
		document.accountForm.user.focus();
		
	}
	else if(	document.accountForm.pass.value == "")
	{
		alert("Provide password");
		document.accountForm.pass.focus();
	}
	else
	{
		document.accountForm.submit();
	}

}//// end function accountForm()



//////////////////////////////////numeric + character validations////////////////////

//// validate for numeric data



/// validate character data////////////////  

function IsNumeric(str)
   {
	   var strValidChars = "0123456789";
	   var strChar;
	   var strString = str;
	   var blnResult = true;
	   var field;

	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
		  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
			 	//alert('This value should be Numeric!');
				//field.value = "";
				blnResult = false;
			 }
		  }
	   return blnResult;
   }	//	End	of function IsNumeric

function IsNumericFlo(str)
   {
	   var strValidChars = "0123456789.";
	   var strChar;
	   var strString = str;
	   var blnResult = true;
	   var field;

	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
		  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
			 	//alert('This value should be Numeric!');
				//field.value = "";
				blnResult = false;
			 }
		  }
	   return blnResult;
   }
   
  function IsNumericFlo1(str)
   {
	   var strValidChars = "0123456789./- abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	   var strChar;
	   var strString = str;
	   var blnResult = true;
	   var field;

	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
		  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
			 	//alert('This value should be Numeric!');
				//field.value = "";
				blnResult = false;
			 }
		  }
	   return blnResult;
   }
function isNumber (id,val)
{
	
	if($(id).value != "")
	{
		if( IsNumeric ($(id).value) == false )
		{
			alert("Only numeric values are allowed");
			$(id).value = val;
			
		}
	}
}
function isNumberFlo (id,val)
{
	
	if($(id).value != "")
	{
		if( IsNumericFlo ($(id).value) == false )
		{
			alert("Only numeric values are allowed");
			$(id).value = val;
			
		}
	}
}

function isNumbersPFlo (id,val)
{
	
	if($(id).value != "")
	{
		if( IsNumericFlo1 ($(id).value) == false )
		{
			alert("Only numeric values, White spaces and oblique(/) are allowed");
			$(id).value = val;
			
		}
	}
}

function checkchar(mystr,invalidChars1)
{
	
	for (i=0; i<invalidChars1.length; i++) // does it contain any invalid characters?
		{
			badChar1 = invalidChars1.charAt(i)
			if (mystr.indexOf(badChar1,0) > -1) 
				{
					return false;
				}
		}

return true;
} 

function isChar(id,val)
{
	if($(id).value != "")
	{
		if(id == 'user')
		{
			if(!checkchar($(id).value," ?./:,;=+'\"<>|\\`~{}#$%@!^&*()[]"))
			{
				alert("Special characters and spaces are not allowed");
				$(id).value = val;			
			}
		}
		else if(!checkchar($(id).value,"?/:,;=+'\"<>|\\`~{}#$%@!^&*[]()_.-0123456789"))
		{
			alert("Only alphabets are allowed");
			$(id).value = val;
		
		}
		
	}// if($(id).value != "")
}

//////////////////// End of character data validation

function validate_Ad_Report( Fieldid )
{
	//alert("it comes here?");
	if( $(Fieldid).value == "" )
	{
		alert("Please select the report issue");	
		return false;
	}
}

//// valdiate admin password change form///////////
/*
function validateAdminChange()
{
	if(document.adminForm.opassword.value == "")
	{
		alert("Give your current password");
		document.adminForm.opassword.focus();
	}
	else if(document.adminForm.npassword.value == "")
	{
		alert("Give new password");
		document.adminForm.npassword.focus();
	}
	elseif(document.adminForm.cpassword.value == "")
	{
		alert("Confirm new password");
		document.adminForm.cpassword.focus();
	}
	else if(document.adminForm.cpassword.value != document.adminForm.npassword.value)
	{
		alert("Password mismatch in confirm field");
		document.adminForm.cpassword.focus();
	}
	else
	{
		document.adminForm.submit();
	}
}// end function validateAdminChange()*/

////////////////////////
function addCode(url)
{
	flag = confirm("Do you want to add this mobile code to Bastee's database?");
	
	if(flag)
	
	{
		window.location = url;
	}
	
}// end function addCode(url)


function upload_another_image( divid, dividvalue, linkdivname )
{
	var dividno;
	var divname;
	//alert( dividvalue );
	dividno = $( dividvalue ).value; 
	divname = divid + dividno;
	//alert( divname );
	$( divname ).show();
	if( dividno == 5 )
	{
		$( linkdivname ).hide();
	}
	else
	{
		$( dividvalue ).value = parseInt(dividno) + 1; 
	}
	//alert( "fine" );
}

function validateOffer(id)
{
	
	if($(id).value == "")
	{
		alert("Give valid amount for your offer");
		$(id).focus();
		return false;
	}
	
}
/*
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');

num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
//  End -->
*/
function remove_image(divid, imageid)
{
	//alert(imageid);
	//alert($(imageid).value);
	$(imageid).value = "Pakistan";
	//alert(imageid);
	//alert($(imageid).value);
	
	$(divid).hide();
	//alert(	$('imageuploadvalue').value);
	$('imageuploadvalue').value = $('imageuploadvalue').value - 1;
	

	if($('imageuploadvalue').value != 5)
	{
		$('uploadanotherimage').show();
	}
	
}// end function remove_image(divid, imageid) 


function drawImageDiv(divid, image)
{
	imagediv = '<div id=\''+divid+'\' style="display:block"><table width="100%" height="23" cellpadding="0" cellspacing="0" border="0"><tr><td><input name="pic[]" type="file" id="'+image+'" class="property_form" /><span class="property_ad_detail">jpeg,bmp,gif <a href="javascript:remove_image(\''+divid+'\', \''+image+'\')" ><img src="images/icon_cancel.gif" alt="Remove Image" width="10" border="0" height="10" /></a>&nbsp;</span></td></tr></table></div>';
		return imagediv;
	
}// end function drawImageDiv($divid)

function validateInvitation()
{
	if($('youremail_contact_yahoo').value == "")
	{
		alert("Provide email address");
		$('youremail_contact_yahoo').focus();
		return false;
	}
	else if($('yourpassword_contact').value == "")
	{
		alert("Provide password");
		$('yourpassword_contact').focus();
		return false;
	}
}

function addAnotherMobilePhone( id, action, fieldid, hidinglayer )
{
	if( action == "show" )
	{
		//alert( id );
		$(id).show();
		$(id+"layer").value = "show";
		//alert($(hidinglayer).value);
		$(hidinglayer).hide();
	}
	else if( action == "remove" )
	{
		$(id).hide();
		$(id+"layer").value = "";
		
		if( fieldid != "" )
		{
			$(fieldid).value = "";
		}
		$(hidinglayer).show();
	}

	if( fieldid == "mobile_number2" || fieldid == "mobile_number4" )
	{
		//alert(fieldid);
		$('mobile_code2').value = "0300";
		$('mobile_code4').value = "";
		//$('new1').value = "";
	}

}

function change_profile_image1(type)
{
		
	if(type == 'user')
	{
		flag = confirm("Your current image will be removed, Do you want to continue?");
		if(flag)
		{
			$('change_photo_profile').show();
			window.location = "adsman-prof.php?option=del_image";
		}	
	}// end if(type == 'user')
	
	else if(type == 'logo')
	{
		flag = confirm("Current logo will be removed, Do you want to continue?");
		if(flag)
		{
			$('change_image_profile').show();
			window.location ="adsman-firm.php?option=del_image";
		}	
	}// end if(type == 'logo')
	else if(type == 'logo1')
	{
		flag = confirm("Current logo will be removed, Do you want to continue?");
		if(flag)
		{
			$('change_image_profile').show();
			window.location ="firm-agent.php?option=del_image";
		}	
	}// end if(type == 'logo')
}

function confirm_objection(id)
{
	flag = confirm("Do you want to send objection email for the ad image(s)?");
	if(flag)
	{
		window.location ="ads_moderation.php?action=obj_mail&id="+id;
	}
	
}// end function confirm_objection(id)

function validate_contactMessage()
{
	//alert("yes");
	if($('login').value == "" )
	{
		if($('yourname').value == "" || $('yourname').value == "Enter Your Name")
		{
			alert("Please provide your name");
			$('yourname').focus();
			return false;
		}
		else if ($('youremail').value.indexOf('@',0) < 0 || $('youremail').value.indexOf('.',0) < 0 || !checkchar($('youremail').value," ?/:,;=+'\"<>|\\`~{}#$%!^&*()"))
		{
			alert("Provide your valid email address");
			$('youremail').focus();
			return false;
		}
	}// end if($('login').value != "")
	
	if($('contact_url_page').value == "" || $('contact_url_page').value == "Enter your message")
	{
		alert("Please write your message");
		$('contact_url_page').focus();
		return false;
	}
}// end function validate_contactMessage()


function validate_post_ad()
{
	
	var resCom=$('ad_type').value;
	var saleRent=$('ad_typeNew').value;
	var pro=$('property_type').value;
	
	if ($('actionEdit') != null)
	{
		var edit=$('actionEdit').value;
	}
	var url="";
	
	if(resCom == "")
	{
		alert("Please select ad type");
		$('ad_type').focus();
		return false;
	}
	else if(pro == "")
	{
		alert("Please select a property type");
		$('property_type').focus();
		return false;
	}
	if (document.postAd != null)
	{
		if (edit != "yes")
		{
			$('hideRent').value=saleRent;
			$('hideProperty').value=pro;
			$('hideresCom').value=resCom;
			document.postAd.submit();
		}
		else
		{
			validate_post_ad_sess(pro);	
		}
	}
	else
	{
		validate_post_ad_sess(pro);
	}
}

function getCityUrl(url,http,categ,cityOrig)
{	
urlNew1=url.split("property-listing/");
city=$('homepage_city').value;
type=$('addtype').value;
urlNew=urlNew1[1].split("/");
var makeUrl;
		
		makeUrl=categ+"-"+type;
		
		if (urlNew[4] != null)
		{
			if (cityOrig == city)
			{
				Url=makeUrl+"/"+city+"/"+urlNew[3]+"/"+urlNew[4];
			}
			else
			Url=makeUrl+"/"+city+"/";
		
		}
		else if (urlNew[3] != null)
		{
			if (cityOrig == city)
			{
				Url=makeUrl+"/"+city+"/"+urlNew[3];
			}
			else
			Url=makeUrl+"/"+city+"/";
		}
		else if (urlNew[2] != null)
		{
			Url=makeUrl+"/"+city;
		}
		else if (urlNew[1] != null)
		{
			if(city != "")
			{
				Url=makeUrl+"/"+city;
			}
			else
				Url=makeUrl;
		}
gotext="property-listing/1/";
httpRequest=http+gotext+Url;
window.location = http+"property-listing/1/"+Url;
}

function aArea()
{
	var sarea=$('area').value;
	if ($('area1') != null)
	{
		$('area1').value=$('area').value;	
	}
	if (sarea == 'other')	
	{
		$('spArea').hide();
		$('spOarea').show();
		$('area').value="";
		if ($('area1') != null)
		{
			$('area1').value="";
		}
		if ($('existLoc') != null)
		{
			$('existLoc').show();
		}
	}
	else
	{
		getPhase();
		$('spOarea').hide();
		$('spArea').show();	
	}
}

function aPhase()
{
	var sphase=$('phase').value;
	if (sphase == 'other')	
	{
		$('spPhase').hide();
		$('spOPhase').show();
		$('phase').value="";
	}
}

function adaction(param)
{
if ($('ptipe') != null)
{
type=$('ptipe').value;

blur_message('area');

	if (param == null)
	{
		if (type == "Apartment" || type == "Building" || type == "Floor" || type == "Office Unit" || type == "Shop")
		{
			if (type == "Building")
			{
				$('otherBuild').value="Enter Building Name";
				$('apartments').value="";
				$('spBuild').hide();
				$('spObuild').show();
				$('build').show();
				$('build-Sptr').show();	
			}
			else
			{
				getBuilding('city');	
			}
			
		}
			
			$('phase-tr').show();
			$('phase-tr1').show();
			$('street-tr').show();
			$('street-tr1').show();
	}
	else if (param == "marla")
	{
		if ($('totalarea_unit').value == "Kanal" || $('totalarea_unit').value == "Acre")
		{
			kanalText=($('totalarea_unit').value == "Kanal" ? "Marla" : "Kanal");
			$('kanal').show();
			$('kanal1').update(kanalText);
		}
		else
		{
			$('kanal').hide();
			$('kanal1').update("");
		}
	}
 	else if (param == "kanal")
	{
		if ($('coveredarea_unit').value == "Kanal" || $('coveredarea_unit').value == "Acre")
		{
			kanalText=($('coveredarea_unit').value == "Kanal" ? "Marla" : "Kanal");
			$('acre').show();
			$('acre1').update(kanalText);
		}
		else
		{
			$('acre').hide();
			$('acre1').update("");
		}
	}
}
}
function adminadaction(param)
{
if ($('ptipe') != null)
{	
type=$('ptipe').value;
blur_message('area');

	if (param == null)
	{
		if (type == "Apartment" || type == "Building" || type == "Floor" || type == "Office Unit" || type == "Shop")
		{
			getBuilding('city','admin');
		}
			$('phase-tr').show();
			$('phase-tr1').show();
			$('street-tr').show();
			$('street-tr1').show();
	}

	else if (param == "marla")
	{
		if ($('totalarea_unit').value == "Kanal" || $('totalarea_unit').value == "Acre")
		{
			kanalText=($('totalarea_unit').value == "Kanal" ? "Marla" : "Kanal");
			$('kanal').show();
			$('kanal1').update(kanalText);
		}
		else
		{
			$('kanal').hide();
			$('kanal1').update("");			
		}
	}
	else if (param == "kanal")
	{
		if ($('coveredarea_unit').value == "Kanal" || $('coveredarea_unit').value == "Acre")
		{
			kanalText=($('coveredarea_unit').value == "Kanal" ? "Marla" : "Kanal");
			$('acre').show();
			$('acre1').update(kanalText);
		}
		else
		{
			$('acre').hide();
			$('acre1').update("");
		}
	}
}
}
function adactionbuild()
{
	//blur_message('apartments');
}

function aBuild()
{
	var sarea=$('apartments').value;	
	if ($('apartments1') != null)
	{
		$('apartments1').value=$('apartments').value;	
	}
	if (sarea == 'other')	
	{
		$('spBuild').hide();
		$('spObuild').show();
		$('apartments').value="";
		$('apartments1').value="";
		if ($('existBui') != null)
		{
			$('existBui').show();
		}
	}
	else
	{
		$('spObuild').hide();
		$('spBuild').show();	
	}
}

function blur_message(opt)
{
	if (opt == 'area')
	{
		if ($('area').value == "" &&( $('otherArea').value == "" || $('otherArea').value == "Enter Area"))
		{
			$(opt+'_img').innerHTML=" Required";
		}
		else
		{
			$(opt+'_img').innerHTML="<img src='i/click.gif' align='absmiddle' />";
		}	
	}
	else if (opt == 'apartments')
	{
		if ($('apartments').value == "" &&( $('otherBuild').value == "" || $('otherBuild').value == "Enter Building Name"))
		{
			$(opt+'_img').innerHTML=" Required";
		}
		else
		{
			$(opt+'_img').innerHTML="<img src='i/click.gif' align='absmiddle' />";
		}	
	}
	else if (opt == 'bathrooms')
	{
		if ($('bathrooms').value == "" && $('halfbath').value == "")
		{
			$(opt+'_img').innerHTML=" Required";
		}
		else
		{
			$(opt+'_img').innerHTML="<img src='i/click.gif' align='absmiddle' />";
		}	
	}
	else
	{
		if ($(opt).value == "")
		{
			$(opt+'_img').innerHTML=" Required";
		}
		else
		{
			$(opt+'_img').innerHTML="<img src='i/click.gif' align='absmiddle' />";
		}
	}

}


function costInWords(event)
{
	isNumberFlo('demand','');
	$('amountShow').show();
	var getIn=document.getElementsByTagName("input");
	var rent;

	for(i=0;i<getIn.length;i++)
	{
		if(getIn[i].getAttribute("name")=="demand")
		rent=getIn[i];
	}

	if (isNaN(rent.value))
	{
		getRent = "<font color=\"red\">Price must contain numbers only</font>";
	}
	else 

	{
		getRent = getCost(rent.value);
	}
	document.getElementById("amountShow").innerHTML = getRent;
}

function getCost(cost)
{	
	retText="";
	price_array = cost.split(",");
	price_length = price_array.length;
	cost = "";

	for(i = 0;i < price_length; i++)
	{
		cost += price_array[i];
	}
	lprice = cost.length;
	
	if(cost == 0)
	{
		retText += "Price should be greater than '0'";
	}
	else
	{
		if(lprice>=12)
		{
				retText+="Price is too big. Please contact us";
		}
		else if(lprice==11)
		{
		retText+=cost.substr(0,2)+" Billion ";

		if(cost.substr(2,2)!="00")
				retText+=cost.substr(2,2)+" Crore ";
			if(cost.substr(4,2)!="00")
				retText+=cost.substr(4,2)+" Lakh";
			if(cost.substr(6,2)!="00" && cost.substr(6,1)!="0")
				retText+=" and "+cost.substr(6,2)+" Thousand";
			if(cost.substr(6,2)!="00" && cost.substr(6,1)=="0")
				retText+=" and "+cost.substr(7,1)+" Thousand";
		}
		else if(lprice==10)
		{
			retText+=cost.substr(0,1)+" Billion ";
			if(cost.substr(1,2)!="00")
				retText+=cost.substr(1,2)+" Crore ";
			if(cost.substr(3,2)!="00")
				retText+=cost.substr(3,2)+" Lakh";
				
			if(cost.substr(5,2)!="00" && cost.substr(5,1)!="0")
				retText+=" and "+cost.substr(5,2)+" Thousand";
			if(cost.substr(5,2)!="00" && cost.substr(5,1)=="0")
				retText+=" and "+cost.substr(6,1)+" Thousand";
		}
		else if(lprice==9)
		{
			retText+=cost.substr(0,2)+" Crore ";
			if(cost.substr(2,2)!="00")
				retText+=cost.substr(2,2)+" Lakh";
			if(cost.substr(4,2)!="00" && cost.substr(4,1)!="0")
				retText+=" and "+cost.substr(4,2)+" Thousand";
			if(cost.substr(4,2)!="00" && cost.substr(4,1)=="0")
				retText+=" and "+cost.substr(5,1)+" Thousand";
		}
		
		else if(lprice==8)
		{
			retText+=cost.substr(0,1)+" Crore ";
			if(cost.substr(1,2)!="00")
				retText+=cost.substr(1,2)+" Lakh";
			if(cost.substr(3,2)!="00" && cost.substr(3,1)!="0")
				retText+=" and "+cost.substr(3,2)+" Thousand";
			if(cost.substr(3,2)!="00" && cost.substr(3,1)=="0")
				retText+=" and "+cost.substr(4,1)+" Thousand";
		}
	
		else if(lprice==7)
		{
			retText+=cost.substr(0,2)+" Lakh";
	
			if(cost.substr(2,2)!="00" && cost.substr(2,1)!="0")
				retText+=" and "+cost.substr(2,2)+" Thousand";
			if(cost.substr(2,2)!="00" && cost.substr(2,1)=="0")
				retText+=" and "+cost.substr(3,1)+" Thousand";
	
		}	
		else if(lprice==6)
		{
			
				retText+=cost.substr(0,1)+" Lakh";
			
			if(cost.substr(1,2)!="00" && cost.substr(1,1)!="0")
				retText+=" and "+cost.substr(1,2)+" Thousand";
			if(cost.substr(1,2)!="00" && cost.substr(1,1)=="0")
				retText+=" and "+cost.substr(2,1)+" Thousand";
		}
		else if(lprice==5)
		{

			if(cost.substr(0,2)!="00" && cost.substr(0,1)!="0")
				retText+=cost.substr(0,2)+" Thousand(s)";
			if(cost.substr(0,1)=="0" && cost.substr(1,1)!="0") 
			retText+=cost.substr(1,1)+" Thousand(s)";
				
				
		}
		else if(lprice==4)
		{
		
			if(cost.substr(0,1)!="0" && cost.substr(0,2)!="00")
				retText+=cost.substr(0,1)+" Thousand(s)";
				
			
		}
		else if(lprice<=3)
		{
			retText+="Price Should be in thousands";
		}
		
		if(lprice<12)
				retText+=" PKR";
	}
	return retText;
	
}//End of Function

function chanUnit(total)
{
	selPro=$('pselect').value;
	for (var i=0; i<total; i++)
	{
		if (document.getElementById('tArea_'+i) != null)
		{
				var r=$('tArea_'+i).innerHTML.split(" ");
				unitValue=r[0];
				unitType=r[1];
				
				
				if (unitType == "Marla")
				{
						
					yards=Math.round(unitValue*25);
					feet=Math.round(unitValue*225);
					marla=unitValue;
					kanal=(unitValue*0.05);
				
				}
				else if (unitType == "Kanal")
				{
					yards=Math.round(unitValue*500);
					feet=Math.round(unitValue*4500);
					marla=unitValue*20;
					kanal=unitValue;
				}
				else if (unitType == "Sq/Yards")
				{
					yards=unitValue;
					feet=Math.round(unitValue*9);
					marla=unitValue*0.04;
					kanal=(unitValue*(1/500));
					
				}
				else if (unitType == "Sq/Feet")
				{
					yards=Math.round(unitValue*0.111111);
					feet=unitValue;
					marla=Math.round(unitValue*0.004444);
					kanal=(unitValue*(1/4500));
				}
				
				else if (unitType == "Acre")
				{
					yards=Math.round(unitValue*4000);
					feet=Math.round(unitValue*36000);
					marla=Math.round(unitValue*160);
					kanal=(unitValue*8);
				}
		
						
						if (marla >=20)
						{
							aMarla=Math.round(marla%20);
							Kanal=Math.round(marla/20);
							
							if (aMarla>0)
							{
								spMarla=Kanal+" Kanal "+aMarla+" Marla ";
							}
							else
							{
								spMarla=Kanal+" Kanal ";	
							}
						}
						else
						{
							spMarla=marla+" Marla";
						}
						
						spYards=yards+" Sq/Yards";
						spFeet=feet+" Sq/Feet";
						
						
						
						
				if (selPro == "Sq/Feet")
				{
					$('tArea_'+i).hide();
					$('tArea_e_'+i).update(spFeet);	
				}
				else if (selPro == "Sq/Yards")
				{
					$('tArea_'+i).hide();
					$('tArea_e_'+i).update(spYards);
				}
				else if (selPro == "Marla/Kanal")
				{
					$('tArea_'+i).hide();
					$('tArea_e_'+i).update(spMarla);
				}
		
	}
	}
	
	
	for (var j=0; j<2; j++)
	{
		if (document.getElementById('tArea_f_'+j) != null)
		{
				var r=$('tArea_f_'+j).innerHTML.split(" ");
				unitValue=r[0];
				unitType=r[1];
				
				
				if (unitType == "Marla")
				{
						
					yards=Math.round(unitValue*25);
					feet=Math.round(unitValue*225);
					marla=unitValue;
					kanal=(unitValue*0.05);
				
				}
				else if (unitType == "Kanal")
				{
					yards=Math.round(unitValue*500);
					feet=Math.round(unitValue*4500);
					marla=unitValue*20;
					kanal=unitValue;
				}
				else if (unitType == "Sq/Yards")
				{
					yards=unitValue;
					feet=Math.round(unitValue*9);
					marla=unitValue*0.04;
					kanal=(unitValue*(1/500));
					
				}
				else if (unitType == "Sq/Feet")
				{
					yards=Math.round(unitValue*0.111111);
					feet=unitValue;
					marla=Math.round(unitValue*0.004444);
					kanal=(unitValue*(1/4500));
				}
				
				else if (unitType == "Acre")
				{
					yards=Math.round(unitValue*4000);
					feet=Math.round(unitValue*36000);
					marla=Math.round(unitValue*160);
					kanal=(unitValue*8);
				}
		
						
						if (marla >=20)
						{
							aMarla=Math.round(marla%20);
							Kanal=Math.round(marla/20);
							
							if (aMarla>0)
							{
								spMarla=Kanal+" Kanal "+aMarla+" Marla ";
							}
							else
							{
								spMarla=Kanal+" Kanal ";	
							}
						}
						else
						{
							spMarla=marla+" Marla";
						}
						
						spYards=yards+" Sq/Yards";
						spFeet=feet+" Sq/Feet";
						
				if (selPro == "Sq/Feet")
				{
					$('tArea_f_'+j).hide();
					$('tArea_fe_'+j).update(spFeet);	
				}
				else if (selPro == "Sq/Yards")
				{
					$('tArea_f_'+j).hide();
					$('tArea_fe_'+j).update(spYards);
				}
				else if (selPro == "Marla/Kanal")
				{
					$('tArea_f_'+j).hide();
					$('tArea_fe_'+j).update(spMarla);
				}
	}
	}
	
}

function removeImages(count)
{
	
	$('photo-'+count).update('');	
	
}

function getNewImage(count)
{
	countNew=count+1;
	var spanTag=$('href-'+countNew);
	if (count == 19)
	{
		spanTag.innerHTML='&nbsp;&nbsp;<a href="javascript: removeImages('+count+');" class="frmLnk">Remove';	
	}
		else
		{
			spanTag.innerHTML='&nbsp;&nbsp;<a href="javascript: getNewImage('+countNew+')" class="frmLnk">Upload another image</a><br />';
		}
			$('href-'+count).innerHTML='&nbsp;&nbsp;<a href="javascript: removeImages('+count+');" class="frmLnk">Remove<br />';
			$('photo-'+countNew).show();
}

function getTotal(type)
{
	var demand=parseInt($('demand').value);	
	
	if (isNaN(demand))
	{demand=0;}
	else {demand=demand;}
	
	if (type == 'Plot' || type == 'Agricultural Land')
	{
		var othercharges=parseInt($('othercharge').value);
	
		if (isNaN(othercharges))
		{othercharges=0;}
		else
		{othercharges=othercharges;}
		var total=addCommas(demand+othercharges);
		$('totalup-span').update(total);	
	}
	else 
	{
		var secu=0;
		var secu1=parseInt($('security1').value);
		var secu2=parseInt($('security2').value);		
		var advance=parseInt($('advRent').value);		
		
		if (isNaN(secu1))
		{secu1=0;}
		else {secu1=secu1;}
		
		if (isNaN(secu2))
		{secu2=0;}
		else
		{secu2=secu2;}
		
		if (isNaN(advance))
		{advance=0;}
		else
		{advance=advance;}
		
		if (secu1 != 0)
		{
			secu=secu1*demand;
		}
		else if (secu2 != 0)
		{
			secu=secu2;
		}
		if (advance != 0)
		{
			secu=secu+advance*demand;
		}
			secu=secu+demand;
			if (secu != 0 && secu !=- "")
			{
				var total=addCommas(secu);
				$('tUpfront').update(total);
			}
	}
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function rengeText()
{
	linktext=$('range-text').innerHTML;
	if (linktext == "Specify your own monthly rent range" || linktext == "Specify your own price range")
	{
		$('rent-div').hide();
		$('range-from').show();
		$('budgetRent').value="";
		$('budget').value="";
		if (linktext == "Specify your own monthly rent range")
		{
			$('range-text').innerHTML = "Fixed monthly rent range"
		}
		else
		{
			$('range-text').innerHTML = "Fixed price range"
		}
	}
	else if (linktext == "Fixed monthly rent range" || linktext == "Fixed price range")
	{
		$('range-from').hide();
		$('budgetFrom').value="";
		$('budgetTo').value="";
		$('rent-div').show();
		if (linktext == "Fixed monthly rent range")
		{
			$('range-text').innerHTML = "Specify your own monthly rent range"
		}
		else
		{
			$('range-text').innerHTML = "Specify your own price range"
		}
	}
}

function chngClass(opt,action,adType)
{
	if (action == 'ad')
	{
		if (opt== "sale")
		{
			$('rentTab1').className = "";
			$('saleTab1').className = "active";
			$('ad_typeNew').value="forsale";
			$('ad_type').value="";
			$('property_type').value="";
			
		}
		else if (opt == "rent")
		{
			$('saleTab1').className = "";
			$('rentTab1').className = "active";
			$('ad_typeNew').value="forrent";
			$('ad_type').value="";
			$('property_type').value="";
			
		}
		
		
	}
	else
	{
		if (opt== "sale")
		{
			$('rentTab').className = ""
			$('saleTab').className = "active";
			$('adTypeHide').value="For Sale";
			if (adType== "Residential")
			{
				$('rent-budget').hide();
				$('range-from').hide();
				$('rent-div').show();
				$('sale-budget').show();
				$('budgetRent').value="";
				$('budget').value="";
				$('range-text').innerHTML = "Specify your own price range"
				FromToValue(opt);
			}
			
		}
		else if (opt == "rent")
		{
			$('saleTab').className = ""
			$('rentTab').className = "active";
			$('adTypeHide').value="For Rent";
				if (adType== "Residential")
				{
					$('range-from').hide();
					$('sale-budget').hide();
					$('rent-budget').show();
					$('rent-div').show();
					$('budgetRent').value="";
					$('budget').value="";
					$('range-text').innerHTML = "Specify your own monthly rent range"
					FromToValue(opt);
				}
		}
	}
}

function show_build()
{
	$('apartments').value="";
	$('apartments1').value="";
	$('spBuild').hide(); 
	$('spObuild').show();
	if ($('existBui') != null)
	{
		$('existBui').show();
	}
}

function aditional(opt)
{
	if (opt == 'show')
	{
		$('adit2').show();
		new Effect.SlideDown('adit3');
		$('adnalInfo').hide();
	}
	else if (opt == 'hide')
	{
		$('adit2').hide();
		new Effect.SlideUp('adit3');
		$('adnalInfo').show();
	}
}

function onKitchen()
{
if ($('roomkitchen').value == 'Common') 
{ 
	$('kitchfee').show(); 
} 
	else 
	{	 
		$('kitchfee').hide();
	}

if ($('meal').value == 'Included') 
{
	$('numM').show(); 
	$('mCharge').hide();
	$('mealcharges').value="";
} 
	else if ($('meal').value == 'Extra') 
	{	 
		$('mCharge').show(); 
		$('numM').show();
	}	 
	else 
	{ 
		$('numM').hide(); 
		$('mCharge').hide(); 
		$('nummeals').value="";
		$('mealcharges').value="";
	}
}
function getImageSpan(param)
{
	$('image'+param).show();
	$('href'+param).hide();
}

function cityCheck()
{
	city = $('search-area').value;
	
	if (city == "")
	{
		alert("Please select city before entering in the locations.");
		$('is').value="Enter housing scheme, road etc.";
		$('search-area').focus();
	}
}

function resComText()
{
	var headText=$('resComHead').innerHTML;
	var linkText=$('resComTxt').innerHTML;

	if (linkText == "Looking for Commercial Property?")
	{
		$('resComHead').update('Find Commercial Property');
		$('resComTxt').update('Looking for Residential Property?');
		$('rent-div').hide();
		$('range-from').hide();
		$('rngText-div').hide();
		$('appList-div').show();
		$('adCatHide').value="Commercial";
	}
	else if (linkText == "Looking for Residential Property?")
	{
		$('resComHead').update('Find Residential Property');
		$('resComTxt').update('Looking for Commercial Property?');
		$('appList-div').hide();
		$('rent-div').show();
		
		if ($('adTypeHide').value == "For Rent")
		{
			$('rent-budget').show();
			$('sale-budget').hide();
		}
		else if ($('adTypeHide').value == "For Sale")
		{
			$('sale-budget').show();
			$('rent-budget').hide();
		}
		$('rngText-div').show();	
		$('adCatHide').value="Residential";		
	}
}

function validate_searchForm(categ)
{
	
	if($('search-area').value == "")
	{
		alert("Please select city");
		$('search-area').focus();
		return false;
	}
	if (categ == "Commercial")
	{
			if($('appList').value == "")
			{
				alert("Please select appropriate commercial property type");
				$('appList').focus();
				return false;
			}
	}
	else if (categ == "Residential")
	{
		var from=$('budgetFrom').value;
		var to=$('budgetTo').value;
		if((from != "" && to == "" ) || (from == "" && to != "" ))
		{
			alert("Please select amounts from both, starting and ending amount ranges");	
			return false;
		}
		else if (from !="" && to != "") 
		{
			if (parseInt(from) > parseInt(to))
			{
				alert("Starting amount should be lesser than or equal to ending amount");	
				return false;
			}
		}
	}
	var acfb =jQuery("div.first").autoCompletefb({urlLookup:areas});
	$('ids').value=acfb.getData();
}

function hideFacets(opt)
{

if (opt == "city_exact")
{
	if (document.getElementById('area_exact_tr') != null)
	{
		$('area_exact_tr').hide();
		$('area_exact_space1').hide();
		$('area_exact_space2').hide();
	}
	if (document.getElementById('block_exact_tr') != null)
	{
		$('block_exact_tr').hide();
		$('block_exact_space1').hide();
		$('block_exact_space2').hide();
		$('block_exact_title').hide();
	}
	if (document.getElementById('phase_exact_tr') != null)
	{
		$('phase_exact_tr').hide();
		$('phase_exact_space1').hide();
		$('phase_exact_space2').hide();
		$('phase_exact_title').hide();
	}
}
else if (opt == "ptype_exact")
{
var subProTitles= new Array("appFor","building_exact","flFloor_exact","plotType_exact","noOfStories_exact","portion_exact","entrance_exact","garage_exact","parking_exact","floor_exact","apartment_exact","comPermit_exact","offKitchen_exact","comRooms_exact","comBaths_exact","roomType_exact","roomBath_exact","roomKit_exact","meals_exact","roomAc_exact","buildAc_exact","elevator_exact");

var cntSub=subProTitles.length;
for (i=0;i<cntSub;i++)
{
	
	if (document.getElementById(subProTitles[i]+'_tr') != null)
	{
		$(subProTitles[i]+'_tr').hide();
		$(subProTitles[i]+'_space1').hide();
		$(subProTitles[i]+'_space2').hide();
		$(subProTitles[i]+'_title').hide();
	}
	
}
		$('ptype_exact_space1').hide();
		$('ptype_exact_space2').hide();
}

	if(opt == "parkingMain")
	{
	var subParTitles= new Array("publicParking_exact","privateParking_exact","underGroundParking_exact");
	var cntSubr=subParTitles.length;
	for (j=0;j<cntSubr;j++)
	{
		if (document.getElementById(subParTitles[j]+'_tr') != null)
		{
			$(subParTitles[j]+'_tr').hide();
			$(subParTitles[j]+'_space1').hide();
			$(subParTitles[j]+'_space2').hide();
			$(subParTitles[j]+'_title').hide();
		}
		$('parkingMain_sHide').hide();
		$('parkingMain_THide').hide();
		$('parkingMain_sShow').show();
		$('parkingMain_TShow').show();	
	}	
	}
	else
	{
		$(opt+'_tr').hide();
		if (opt != "ptype_exact" && opt != "city_exact")
		{
			$(opt+'_space1').hide();
			$(opt+'_space2').hide();
		}
		$(opt+'_sHide').hide();
		$(opt+'_THide').hide();
		$(opt+'_sShow').show();
		$(opt+'_TShow').show();
	}
}
function showFacets(opt)
{
if (opt == "city_exact")
{
	if (document.getElementById('area_exact_tr') != null)
	{
		$('area_exact_tr').show();
		$('area_exact_space1').show();
		$('area_exact_space2').show();
	}
	if (document.getElementById('block_exact_tr') != null)
	{
		$('block_exact_tr').show();
		$('block_exact_space1').show();
		$('block_exact_space2').show();
		$('block_exact_title').show();
	}
	if (document.getElementById('phase_exact_tr') != null)
	{
		$('phase_exact_tr').show();
		$('phase_exact_space1').show();
		$('phase_exact_space2').show();
		$('phase_exact_title').show();
	}
}
else if (opt == "ptype_exact")
{
var subProTitles= new Array("appFor","building_exact","flFloor_exact","plotType_exact","noOfStories_exact","portion_exact","entrance_exact","garage_exact","parking_exact","floor_exact","apartment_exact","comPermit_exact","offKitchen_exact","comRooms_exact","comBaths_exact","roomType_exact","roomBath_exact","roomKit_exact","meals_exact","roomAc_exact","buildAc_exact","elevator_exact");

var cntSub=subProTitles.length;
for (i=0;i<cntSub;i++)
{
	
	if (document.getElementById(subProTitles[i]+'_tr') != null)
	{
		$(subProTitles[i]+'_tr').show();
		$(subProTitles[i]+'_space1').show();
		$(subProTitles[i]+'_space2').show();
		$(subProTitles[i]+'_title').show();
	}
	
}
		$('ptype_exact_space1').show();
		$('ptype_exact_space2').show();

}
	if(opt == "parkingMain")
	{
	var subParTitles= new Array("publicParking_exact","privateParking_exact","underGroundParking_exact");
	var cntSubr=subParTitles.length;
	for (j=0;j<cntSubr;j++)
	{
		if (document.getElementById(subParTitles[j]+'_tr') != null)
		{
			$(subParTitles[j]+'_tr').show();
			$(subParTitles[j]+'_space1').show();
			$(subParTitles[j]+'_space2').show();
			$(subParTitles[j]+'_title').show();
		}
		$('parkingMain_sHide').show();
		$('parkingMain_THide').show();
		$('parkingMain_sShow').hide();
		$('parkingMain_TShow').hide();	
	}	
	}
	else
	{
		$(opt+'_tr').show();
		if (opt != "ptype_exact" && opt != "city_exact")
		{
			$(opt+'_space1').show();
			$(opt+'_space2').show();
		}
		$(opt+'_sHide').show();
		$(opt+'_THide').show();
		$(opt+'_sShow').hide();
		$(opt+'_TShow').hide();
	}

}

function filedsShowHide(param)
{
	
	if (param == "security")
	{
		var option=$('monChange').value;
		if (option == "fix")
		{
			$('secDep1').hide();$('security1').value='';$('secDep2').show();return false;
		}
		else if(option == "month")
		{
			$('secDep1').show();$('security2').value='';$('secDep2').hide();return false;
		}
	}
	else if(param == "nobuild")
	{
		var checkme=($('checkBuilding').checked ? "true" : "false");	

		if (checkme == "true")
		{
			$('shed').value="";
			$('shed').disabled="disabled";	
			$('hall').value="";
			$('hall').disabled="disabled";	
			$('commercialrooms').value="";
			$('commercialrooms').disabled="disabled";	
		}
		else
		{
			$('shed').disabled=false;	
			$('hall').disabled=false;	
			$('commercialrooms').disabled=false;	
		}
	}
	else if(param == "Location")
	{
		$('spOarea').hide();
		$('spArea').show();	
		$('otherArea').value="";
		$('area1').value="";
		$('area').value="";
		$('existLoc').hide();
	}
	else if(param == "Building")
	{
		$('spObuild').hide();
		$('spBuild').show();	
		$('otherBuild').value="";
		$('apartments1').value="";
		$('apartments').value="";
		$('existBui').hide();
	}
}

function validate_post_ad_sess(pro)
{
	
	var resCom=$('ad_type').value;
	var saleRent=$('ad_typeNew').value;
	//alert(resCom);
	//alert(pro);
	//alert(saleRent);
	var url="";
	
	if(pro == "Office")
	{
		pro="Office+Unit";	
	}
	else if(pro == "Industrial Facility")
	{
		pro="Industrial+Facility";	
	}
	else if(pro == "Agricultural Land")
	{
		pro="Agricultural+Land";	
	}
	
	if(resCom == "Residential")
	{
		url="res-ads.php?type="+saleRent+"&pro="+pro;	
	}	
	else if(resCom == "Commercial")
	{
		url="com-ads.php?type="+saleRent+"&pro="+pro;	
	}
	else
	{
		return false;	
	}
	url = javaFileUrl+url;
	window.location=unescape(url);
}

function clearFillTxt(thisField,action)
{

	if (action == "clear")
	{
		if (thisField.defaultValue == thisField.value)
		{
			thisField.value="";
		}
	}

	if (action == "fill")
	{
		if (thisField.value == "")
		{
			thisField.value=thisField.defaultValue;
		}
	}

}

function clearFilTxt(thisField,action,textValue)
{

	if (action == "clear")
	{
		if (thisField.value == textValue)
		{
			thisField.value="";
		}
	}

	if (action == "fill")
	{
		if (thisField.value == "")
		{
			thisField.value=textValue;
		}
	}

}

function showmobileLand(action)
{
	if (action == 'other')
	{
		$('clickother').hide();
		$('clickcancel').show();
		$('number2').show();
		$('other-tr2').show();
	}
	else if (action == 'clickother')
	{
		$('clickcancel').hide();
		$('clickother').show();
		$('number1').show();
		$('number2').hide();
		$('other-tr2').hide();
		$('mobcode2').value="";
		$('mobnum2').value="";
	}
	else if (action == "mobother")
	{
		$('mobcode1').value="";
		$('mobnum1').value="";
		$('mobcode2').value="";
		$('mobnum2').value="";
		$('othermob1').show();
		$('clickmobother').hide();
		$('other-tr2').show();
		$('othermob2').show();
		$('clickmobcancel').show();			
	}
	
	else if (action == "clickmobother")
	{
		$('othernumber2').value="";
		$('clickmobother').show();
		$('other-tr2').hide();
		$('othermob2').hide();
		$('clickmobcancel').hide();	
		
	}
	else if (action == "int")
	{
		$('mobcode1').value="";
		$('mobnum1').value="";
		$('mobcode2').value="";
		$('mobnum2').value="";
		$('other-tr2').hide();
		$('number1').hide();
		$('number2').hide();
		$('othermob1').show();
		$('clickmobother').show();
		$('clickmobcancel').hide();		
	}
	else if (action == "local")
	{
		$('othernumber1').value="";
		$('othernumber2').value="";
		$('other-tr2').hide();
		$('number1').show();
		$('othermob1').hide();
		$('othermob2').hide();		
		$('clickother').show();
		$('clickcancel').hide();		
	}

}
function showphLand(action)
{
	if (action == 'other')
	{
		$('clickphother').hide();
		$('clickcancelph').show();
		$('ph2').show();
		$('otherph-tr2').show();
	}
	else if (action == 'clickother')
	{
		$('clickcancelph').hide();
		$('clickotherph').show();
		$('ph1').show();
		$('ph2').hide();
		$('otherph-tr2').hide();
		$('phcode2').value="";
		$('phnum2').value="";
	}
	else if (action == "phother")
	{
		$('phcode1').value="";
		$('phnum1').value="";
		$('phcode2').value="";
		$('phnum2').value="";
		$('otherph1').show();
		$('clickphotherph').hide();
		$('otherph-tr2').show();
		$('otherph2').show();
		$('clickphcancelph').show();			
	}
	
	else if (action == "clickphother")
	{
		$('otherphnumber2').value="";
		$('clickphotherph').show();
		$('otherph-tr2').hide();
		$('otherph2').hide();
		$('clickphcancelph').hide();	
		
	}
	else if (action == "int")
	{
		$('phcode1').value="";
		$('phnum1').value="";
		$('phcode2').value="";
		$('phnum2').value="";
		$('ph1').hide();
		$('ph2').hide();
		$('otherph-tr2').hide();
		$('otherph1').show();
		$('clickphotherph').show();
		$('clickphcancelph').hide();		
	}
	else if (action == "local")
	{
		$('otherphnumber1').value="";
		$('otherphnumber2').value="";
		$('otherph-tr2').hide();
		$('ph1').show();
		$('otherph1').hide();
		$('otherph2').hide();		
		$('clickotherph').show();
		$('clickcancelph').hide();		

	}

}
function errorCncl()
{
	$('err1').hide();
	$('err2').hide();
	$('err3').hide();	
}

function closeLogin()
{
	$('logiHorizLayer1').show();
	$('logiHorizLayer2').hide();
	$('logininfo').hide();
	$('loginOpen').show();
	$('loginClose').hide();
	$('menu-bar').show();
}
function aCity()
{
	if ($('city1') != null )
	{
		$('city1').value=$('city').value;	
		
		if($('city').value == "Not Applicable" )
		{
			$('spCity').hide();
			$('spOtherCity').show();
		}
	}

}

function getValidateValue(str,opt,specialChars)
{
	 var alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	 var numeric="0123456789";
	 var strValidChars = ""; 
	 
	 if (opt == "alpha")
	 {
	 	strValidChars=alpha;
	 }
	 else if (opt == "numeric")
	 {
	 	strValidChars=numeric;		 
	 }
	 else if (opt == "alphanumeric")
	 {
 	 	strValidChars=alpha+numeric;
	 }

	 strValidChars=strValidChars+specialChars;
	  
	 var strChar;
	 var strString = str;
	 var blnResult = true;
	 var field;

	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
		  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
				blnResult = false;
			 }
		  }
	   return blnResult;
}
function validateValue(id,opt,spChars)
{
	val=$(id).value;
	if (opt == "alpha")
	{
		msg ="alphabets";	
	}
	else if (opt == "numeric")
	{
		msg ="numbers";	
	}
	else if (opt == "alphanumeric")
	{
		msg ="alphabets, numbers";	
	}
	
	if (spChars != "")
	{
		msg=msg+" and "+spChars;
	}
	
	if(val != "")
	{
		if( getValidateValue (val,opt,spChars) == false )
		{
			alert("Only "+msg+" are allowed");
			$(id).value ="";
		}
	}
}
function cofirmAction(url,msg)
{
		var flag;
		flag = confirm(msg);
		
		if( flag == true )
		{
			start="window.location.href='"+url+"'";
			setTimeout(start,0);
		}
}
function confirmAdDelete()
{
		var flag;
		flag = confirm('Do you really want to delete selected ads?');
		
		if(flag == true)
		{ 
			document.property_ads_manage.submit();
		}
}
function actvDeactvAds(status,url,statusUser)
{
		if (statusUser == "active")
		{
			var flag;
			flag = confirm("By marking your ad as "+status+ ", your ad will also be deactivated.");
		
			if( flag == true )
			{
				start="window.location.href='"+url+"'";
				setTimeout(start,0);
			}		
		}
		else
		{
				start="window.location.href='"+url+"'";
				setTimeout(start,0);	
		}
}