<!-- 
//function to validate Building Comment Form
function validate_comment_building()
{ 
	 var comment = trim_text(document.comment_form.comment);
	 var captchacode = trim(document.comment_form.captchacode);
	 var comment_name = trim(document.comment_form.comment_name);
	 var email = trim(document.comment_form.email);
	 
   if (comment_name == "")
	 {
	    alert("Please enter your name.");
			document.comment_form.comment_name.focus();	
	 }
	 else if (email == "")
	 {
	    alert("Please enter your email address.");
			document.comment_form.email.focus();	
	 }
	 else if (email != "" && isEmail(email) == false)
	 {
	    alert("Your email address is not in correct format. Please enter again.");
			document.comment_form.email.focus();	
	 }
	 else if (comment == "")
	 {
	    alert("Please enter your comment for this apartment.");
			document.comment_form.comment.focus();	
	 }
	 else if (captchacode == "")
	 {
	    alert("Please enter the numbers shown in the image.");
			document.comment_form.captchacode.focus();	
	 }
	 else
	 {
			document.comment_form.submit();	
	 }
}

//function to validate Building Rating Form
function validate_rate_building()
{ 
   var security = document.rating_form.security.value;
	 var parking = document.rating_form.parking.value;
	 var appearance = document.rating_form.appearance.value;
	 var noise = document.rating_form.noise.value;
	 var maintenance = document.rating_form.maintenance.value;
	 var location = document.rating_form.location.value;
	 var quality = document.rating_form.quality.value;
	 var email = trim(document.rating_form.email);
	 
	 if (security == "")
	 {
	    alert("Please choose your rating for building [security].");
			document.rating_form.security.focus();	
	 }
	 else if (parking == "")
	 {
	    alert("Please choose your rating for [parking].");
			document.rating_form.parking.focus();	
	 }
   else if (appearance == "")
	 {
	    alert("Please choose your rating for building [appearance].");
			document.rating_form.appearance.focus();	
	 }
	 else if (noise == "")
	 {
	    alert("Please choose your rating for the [Peaceful / Quiet] condition of this building.");
			document.rating_form.noise.focus();	
	 }
	 else if (maintenance == "")
	 {
	    alert("Please choose your rating for building [maintenance].");
			document.rating_form.maintenance.focus();	
	 }
	 else if (location == "")
	 {
	    alert("Please choose your rating for the [location] of this building.");
			document.rating_form.location.focus();	
	 }
	 else if (quality == "")
	 {
	    alert("Please choose your rating for the [build quality] of home units in this building.");
			document.rating_form.quality.focus();	
	 }
	 else if (email == "")
	 {
	    alert("Please enter your email address.");
			document.rating_form.email.focus();	
	 }
	 else if (email != "" && isEmail(email) == false)
	 {
	    alert("Your email address is not valid. Please enter again.");
			document.rating_form.email.focus();	
	 }
	 else
	 {
			document.rating_form.submit();	
	 }
}


//function to validate Tell Your Friend Form in pub_top.inc
function validate_email_friend1()
{
   var sender_name = trim(document.email_friend_form.sender_name);
	 var receiver_email = trim(document.email_friend_form.receiver_email);
	 
	 if (sender_name == "" || sender_name == "your name")
	 {
	    alert("Please enter your name.");
			document.email_friend_form.sender_name.focus();
			
	 }
	 
	 else if (receiver_email == "")
	 {
	    alert("Please enter recipient email address.");
			document.email_friend_form.receiver_email.focus();
			
	 }
	 
	 else if (isEmail(receiver_email) == false)
	 {
	    alert("Please check the email address and make sure it is in correct format.");
			document.email_friend_form.receiver_email.focus();
			
	 }
	 
	 else
	 {
			document.email_friend_form.submit();	
	 }
}

//function to validate Email To Your Friend Form
function validate_email_friend()
{
   var sender_name = trim(document.pub_email_friend_form.sender_name);
	 var receiver_email = trim(document.pub_email_friend_form.receiver_email);
	 
	 if (sender_name == "")
	 {
	    alert("Please enter your name.");
			document.pub_email_friend_form.sender_name.focus();
			
	 }
	 
	 else if (receiver_email == "")
	 {
	    alert("Please enter recipient email address.");
			document.pub_email_friend_form.receiver_email.focus();
			
	 }
	 
	 else if (isEmail(receiver_email) == false)
	 {
	    alert("Please check the email address and make sure it is in correct format.");
			document.pub_email_friend_form.receiver_email.focus();
			
	 }
	 
	 else
	 {
			//document.location.href="pub_email_friend.asp";
			//window.open('pub_email_friend.asp,'_blank','width=200,height=200');
			//return false;
			document.pub_email_friend_form.submit();	
	 }
}

//function to validate cactus comment form
//file : pub_building_profile.asp
function validate_comment()
{
	 var sender_email = trim(document.comment_form.sender_email);
	 var comment = trim_simple(document.comment_form.mail_body.value);

	 if (sender_email == "")
	 { 
	    alert("Please enter your email address.");
			document.comment_form.sender_email.focus();
	 }
	 else if (isEmail(sender_email) == false)
	 {
	    alert("Please check your email address and make sure it is in correct format.");
			document.comment_form.sender_email.focus();
	 }
	 
	 else if (comment == "")
	 {
	    alert("Please enter your comment.");
			document.comment_form.mail_body.focus();
	 }
	 else
	 {
	 document.comment_form.submit();
	 }
}

//function to validate newsletter sign up form
//file : index.asp
function validate_newsletter()
{
   var email = trim(document.newsletter_form.email);
	 
	 if (email == "")
	 { 
	    alert("Please enter your email address.");
			document.newsletter_form.email.focus();
	 }
	 else if (isEmail(email) == false)
	 {
	    alert("Please check your email address and make sure it is in correct format.");
			document.newsletter_form.email.focus();
	 }
	 else
	 {
	 document.newsletter_form.submit();
	 }
}

//function to add cities options into list
function add_city_options(option_list, state_id, arr_cities)
{
   var i, other_id;
	 
	 for (i=0; i<arr_cities.length-1; i++)
	 {
	    if (arr_cities[i][1] == state_id)
			{
			   if (arr_cities[i][2] != "Others")
			      option_list[option_list.length] = new Option(arr_cities[i][2],arr_cities[i][0]);
				 else
				    other_id = i;		
			}
	 }
	 
	 //remove everything and change first row display if no state is selected
	 if (state_id != "")
	 {
			option_list[0].text = "- - Select City / Town - -";
			option_list[option_list.length] = new Option(arr_cities[other_id][2],arr_cities[other_id][0]);
	 }		
	 else
	 {
	    option_list.options.remove(0);
			option_list[0] = new Option("- - Select State First - -","");
	 }
}

//function to reset the loan calculator form
function reset_loan_calculator()
{
   var form_obj = document.loan_calculator_form;
	 var text;
	 
	 form_obj.loan_amount.value = "";
	 form_obj.loan_period.value = "";
	 form_obj.loan_interest.value = "";
	 form_obj.monthly_repayment.value = "";
	 form_obj.monthly_salary.value = "";
	 
	 document.getElementById('loan_info').innerHTML=" ";
}


//function to validate simple loan calculator in every listing page
function validate_simple_loan_calculator()
{
   var loan_amount = trim(document.loan_calculator_form.loan_amount);
	 var loan_period = trim(document.loan_calculator_form.loan_period);
	 var loan_interest = trim(document.loan_calculator_form.loan_interest);
	 var loan_margin = trim(document.loan_calculator_form.loan_margin);
	 var rate
	 var months
	 var monthly_repayment
	 var monthly_salary
	 
	 if (loan_amount == "")
	 {
	    alert("Please enter your loan amount.");
			document.loan_calculator_form.loan_amount.focus();
			return false;
	 }
	 
	 if (loan_amount != "" && !isCurrency(loan_amount))
	 {
	    alert("Please enter your loan amount in correct format.");
			document.loan_calculator_form.loan_amount.focus();
	    return false;
	 }
	 
	 if (loan_margin == "")
	 {
	    alert("Please enter your margin of finance.");
			document.loan_calculator_form.loan_margin.focus();
			return false;
	 }
	 
	 if (loan_margin != "" && !isCurrency(loan_margin))
	 {
	    alert("Please enter your loan margin of finance in correct format.");
			document.loan_calculator_form.loan_margin.focus();
	    return false;
	 }
	 
	 if (loan_period == "")
	 {
	    alert("Please enter your loan repayment period.");
			document.loan_calculator_form.loan_period.focus();
	    return false;
	 }
	 
	 if (loan_period != "" && !isCurrency(loan_period))
	 {
	    alert("Please enter your loan repayment period in correct format.");
			document.loan_calculator_form.loan_period.focus();
	    return false;
	 }
	 
	 if (loan_period > 100)
	 {
	    alert("Please enter your loan repayment period between 1 to 100 years.");
			document.loan_calculator_form.loan_period.focus();
	    return false;
	 }
	 
	 if (loan_interest == "")
	 {
	    alert("Please enter your loan interest rate.");
			document.loan_calculator_form.loan_interest.focus();
			return false
	 }
	 
	 if (loan_interest != "" && !isCurrency(loan_interest))
	 {
	    alert("Please enter your loan interest rate in correct format.");
			document.loan_calculator_form.loan_interest.focus();
			return false;
	 }
	 
	 
	 loan_amount = loan_amount * (loan_margin/100)
	 rate = loan_interest / 1200
	 months = loan_period * 12
	 monthly_repayment = Math.round((rate + (rate / (Math.pow(1+rate, months) - 1))) * loan_amount)
	 document.loan_calculator_form.monthly_repayment.value = "RM " + monthly_repayment;  
}


//function to validate loan calculator
function validate_loan_calculator()
{
   var loan_amount = trim(document.loan_calculator_form.loan_amount);
	 var loan_period = trim(document.loan_calculator_form.loan_period);
	 var loan_interest = trim(document.loan_calculator_form.loan_interest);
	 var loan_margin = trim(document.loan_calculator_form.loan_margin);
	 var rate
	 var months
	 var monthly_repayment
	 var monthly_salary
	 
	 if (loan_amount == "")
	 {
	    alert("Please enter your loan amount.");
			document.loan_calculator_form.loan_amount.focus();
			return false;
	 }
	 
	 if (loan_amount != "" && !isCurrency(loan_amount))
	 {
	    alert("Please enter your loan amount in correct format.");
			document.loan_calculator_form.loan_amount.focus();
			return false;
	 }
	 
	 if (loan_margin == "")
	 {
	    alert("Please enter your margin of finance.");
			document.loan_calculator_form.loan_margin.focus();
			return false;
	 }
	 
	 if (loan_margin != "" && !isCurrency(loan_margin))
	 {
	    alert("Please enter your loan margin of finance in correct format.");
			document.loan_calculator_form.loan_margin.focus();
	    return false;
	 }
	 
	 if (loan_period == "")
	 {
	    alert("Please enter your loan repayment period.");
			document.loan_calculator_form.loan_period.focus();
			return false;
	 }
	 
	 if (loan_period != "" && !isCurrency(loan_period))
	 {
	    alert("Please enter your loan repayment period in correct format.");
			document.loan_calculator_form.loan_period.focus();
			return false;
	 }
	 
	 if (loan_period > 100)
	 {
	    alert("Please enter your loan repayment period between 1 to 100 years.");
			document.loan_calculator_form.loan_period.focus();
	    return false;
	 }
	 
	 if (loan_interest == "")
	 {
	    alert("Please enter your loan interest rate.");
			document.loan_calculator_form.loan_interest.focus();
			return false;
	 }
	 
	 if (loan_interest != "" && !isCurrency(loan_interest))
	 {
	    alert("Please enter your loan interest rate in correct format.");
			document.loan_calculator_form.loan_interest.focus();
			return false;
	 }
	 
	 
	 loan_amount = loan_amount * (loan_margin/100)
	 rate = loan_interest / 1200
	 months = loan_period * 12
	 monthly_repayment = Math.round((rate + (rate / (Math.pow(1+rate, months) - 1))) * loan_amount)
	 //monthly_salary = monthly_repayment * 3
	 document.loan_calculator_form.monthly_repayment.value = monthly_repayment;
	 //document.loan_calculator_form.monthly_salary.value = monthly_salary;
	 //loan_info(loan_amount, loan_period, monthly_repayment, monthly_salary);
}

//function to display the loan info text at the end of the page
function loan_info(loan_amount, loan_period, monthly_repayment, monthly_salary)
{
   var text = 'For a loan amount of <b>RM' + loan_amount + '</b> with a tenure of <b>' + loan_period + ' years</b>, your monthly repayment is <b>RM' + monthly_repayment + '</b>. Your monthly income should be <b>RM' + monthly_salary + '</b> or more, to qualify for the loan.';
	 document.getElementById('loan_info').innerHTML=text;
}

//function to validate "Add Image" in post ad form
function validate_add_img()
{
   var form_obj = document.post_ad_form2;
	 
	 var file_name = trim_simple(form_obj.img_file.value);
	 var re1 = /.jpg/i;
	 var re2 = /.jpeg/i;
	 
	 form_obj.target="";
	 form_obj.action="pub_post_ad2.asp#post_img";
	 
	 if (form_obj.img_file.value == "") 
	 { 
      alert("Please browse or enter the location of the image file."); 
			form_obj.img_file.focus(); 
	 } 
	 else if (file_name.search(re1) == -1 && file_name.search(re2) == -1) 
	 {
		  alert("JPEG file only."); 
			form_obj.img_file.focus(); 
	 }
	 else 
	 { 
			form_obj.upload_img_now.value = "yes";
			form_obj.submit(); 
	 }

}


//function to validate "Add Image" in post condo ad, linked from cactus page
function validate_add_condo_img()
{
   var form_obj = document.post_ad_form2;
	 
	 var file_name = trim_simple(form_obj.img_file.value);
	 var re1 = /.jpg/i;
	 var re2 = /.jpeg/i;
	 
	 form_obj.target="";
	 form_obj.action="pub_post_condo_ad.asp#post_img";
	 
	 if (form_obj.img_file.value == "") 
	 { 
      alert("Please browse or enter the location of the image file."); 
			form_obj.img_file.focus(); 
	 } 
	 else if (file_name.search(re1) == -1 && file_name.search(re2) == -1) 
	 {
		  alert("JPEG file only."); 
			form_obj.img_file.focus(); 
	 }
	 else 
	 { 
			form_obj.upload_img_now.value = "yes";
			form_obj.submit(); 
	 }

}


//function to validate post advertisement form
//param mode : 1 for form submition - term and conditions must be checked
//             0 for preview mode - term and conditions need not be checked
function validate_post_ad(mode)
{ 
   var address = trim(document.post_ad_form2.address);
   //var pro_cat = trim(document.post_ad_form2.pro_cat);
   var postcode = trim(document.post_ad_form2.postcode);
   var city = trim(document.post_ad_form2.city);
	 var state = trim(document.post_ad_form2.state);
	 var pro_type = trim(document.post_ad_form2.pro_type);
	 //var price = trim(document.post_ad_form2.price);
	 var contact_name = trim(document.post_ad_form2.contact_name);
	 var tel = trim(document.post_ad_form2.tel);
	 var email = trim(document.post_ad_form2.email);
	 //var poster_type = trim(document.post_ad_form2.poster_type);
	 //var email_1 = trim(document.post_ad_form2.email_1);
	 //var email_2 = trim(document.post_ad_form2.email_2);
	 var terms = document.post_ad_form2.terms;
   var valid = true;
	 var img1 = trim(document.post_ad_form2.img1);
	 var img2 = trim(document.post_ad_form2.img2);
	 var img3 = trim(document.post_ad_form2.img3);
	 
	 var ad_type = document.post_ad_form2.ad_type.value;   
	 var ps = document.post_ad_form2.price.value;
	 var pr = document.post_ad_form2.price_rent.value;
	 var compic;
	 	 
	 //validate general ad data
	 if (pro_type == "")
	 {
	    alert("Please select property type.");
			document.post_ad_form2.pro_type.focus();
			valid = false;
	 }
   else if (state == "")
	 {
	    alert("Please select state.");
			document.post_ad_form2.state.focus();
			valid = false;
	 }
	 else if (city == "")
	 {
	    alert("Please select city.");
			document.post_ad_form2.city.focus();
			valid = false;
	 }
	 else if (address == "")
	 {
	    alert("Please enter address.");
			document.post_ad_form2.address.focus();
			valid = false;
	 }
	 else if (postcode != "" && (postcode.length !=5 || !isInteger(postcode)) )
	 {
	    alert("Please enter postcode in correct format.");
			document.post_ad_form2.postcode.focus();
			valid = false;
	 }
	 
	 else if (ad_type == "")
	 {
	    alert("Please select Ad. Type");
			document.post_ad_form2.ad_type.focus();
      valid = false;
	 }
	 
	 //validate data according to property category	 
	 /*else if (pro_cat != "")
	 {
	    if (pro_cat == "r")
			   valid = validate_post_r_pro();
			if (pro_cat == "c")
			   valid = validate_post_c_pro();
			if (pro_cat == "i")
			   valid = validate_post_i_pro();
			if (pro_cat == "l")
			   valid = validate_post_l_pro();
	 }*/
	 

/*	   
	 if (poster_type == "" && valid == true)
	 {
	    alert("Please select a choice for poster type.");
			document.post_ad_form2.poster_type.focus();
			valid = false;
	 }
	 
	  
	 if (email_1 != "" && !isEmail(email_1))
	 {
	    alert("Please provide a valid email address.");
			document.post_ad_form2.email_1.focus();
			valid = false;
	 }
	 
	 if (email_1 != "" && email_1 == email)
	 {
	    alert("Your Friend1 email address is the same as your email address!");
			document.post_ad_form2.email_1.focus();
			valid = false;
	 }
	 
	 if (email_2 != "" && !isEmail(email_2))
	 {
	    alert("Please provide a valid email address.");
			document.post_ad_form2.email_2.focus();
			valid = false;
	 }
	 
	 if (email_2 != "" && email_2 == email)
	 {
	    alert("Your Friend2 email address is the same as your email address!");
			document.post_ad_form2.email_2.focus();
			valid = false;
	 }
	 
	 if (email_2 != "" && email_2 == email_1)
	 {
	    alert("Your Friend2 email address is the same as your Friend1 email address!");
			document.post_ad_form2.email_2.focus();
			valid = false;
	 }
	 */
	 else if ((ad_type == "s" && ps == "") || (ad_type == "b" && ps == ""))
	 {
	    alert("Please enter selling price.");
			document.post_ad_form2.price.focus();
	    valid = false;
	 }
	 else if ((ad_type == "s" && ps != "" && isCurrency(ps) == false) || (ad_type == "b" && ps != "" && isCurrency(ps) == false))
     {
	    alert("Please enter selling price in correct currency format. (eg. 500, 455.50, 300.00, 990)");
			document.post_ad_form2.price.focus();
	    valid = false;
	   }
	 else if ((ad_type == "r" && pr == "") || (ad_type == "b" && pr == ""))
	 {	  
	    alert("Please enter rental price.");
			document.post_ad_form2.price_rent.focus();
	    valid = false;	
	 }
	 else if ((ad_type == "r" && pr != "" && isCurrency(pr) == false) || (ad_type == "b" && pr != "" && isCurrency(pr) == false))
   {
	    alert("Please enter rental price in correct currency format. (eg. 500, 455.50, 300.00, 990)");
			document.post_ad_form2.price_rent.focus();
	    valid = false;
	 }
	 
	 	 if (contact_name == "" && valid == true)
	 {
	    alert("Please provide contact person name.");
			document.post_ad_form2.contact_name.focus();
			valid = false;
	 }
	 
	 if (tel == "" && valid == true)
	 {
	    alert("Please provide contact phone number.");
			document.post_ad_form2.tel.focus();
			valid = false;
	 }
	 if (email == "" && valid == true)
	 {
	    alert("Please provide a email address.");
			document.post_ad_form2.email.focus();
			valid = false;
	 }
	 if (email != "" && !isEmail(email))
	 {
	    alert("Please provide a valid email address.");
			document.post_ad_form2.email.focus();
			valid = false;
	 }
	 if(valid == true && terms.checked == false && mode  == 1)
	 {
	    alert("Before posting your advertisement, please read and agree with the terms and conditions.");
			terms.focus();
			valid = false;
	 }
	 
	 if (img1 == "" && img2 == "" && img3 == "" && valid == true)
	 {
	   if (mode  == 1)
		 {
	      //compic=confirm('You forgot about pictures! \nMake sure your listing rank higher on our \nproperty search results by adding more pictures.\n\n Click OK Proceed without adding pictures,\n CANCEL to  go back.');
				compic=confirm('You forgot about pictures! \nMake your listing rank higher in search property result \nby adding more property pictures.');
			  if (compic)
			  {
			     valid = true;
			  }
			  else
			  {
				   valid = false;			     
			  }
		 }
		 else
		 {
		   valid = true;
		 }				
	 }
	 

	 return valid;
}

//validate residentail property data
function validate_post_r_pro()
{
	 var builtup = trim(document.post_ad_form2.builtup);
	 var land_area = trim(document.post_ad_form2.land_area);
	 
	 if (builtup != "" && isInteger(builtup) == false)
	 {
	    alert("Please enter built up area in integer format (eg. 1400, 2100, 1028).");
			document.post_ad_form2.builtup.focus();
	    return false;
	 }
	 else if (land_area != "" && isInteger(land_area) == false)
	 {
	    alert("Please enter land area in integer format (eg. 1400, 2100, 1028).");
			document.post_ad_form2.land_area.focus();
	    return false;
	 }
	 
	 return true;
}


//validate commercial property data
function validate_post_c_pro()
{
	 var psf = trim(document.post_ad_form2.psf);
	 var builtup = trim(document.post_ad_form2.builtup);

	 if (psf != "" && isCurrency(psf) == false)
	 {
	    alert("Please enter price per square feet in correct currency format. (eg. 500, 455.50, 300.00, 990)");
			document.post_ad_form2.psf.focus();
	    return false;
	 }
	 else if (builtup != "" && isInteger(builtup) == false)
	 {
	    alert("Please enter built up area in integer format (eg. 1400, 2100, 1028).");
			document.post_ad_form2.builtup.focus();
	    return false;
	 }
	 
	 return true;
}


//validate industrial property data
function validate_post_i_pro()
{
   var psf = trim(document.post_ad_form2.psf);
	 var builtup = trim(document.post_ad_form2.builtup);
	 var land_area = trim(document.post_ad_form2.land_area);
	 
	 if (builtup != "" && isInteger(builtup) == false)
	 {
	    alert("Please enter built up area in integer format (eg. 1400, 2100, 1028).");
			document.post_ad_form2.builtup.focus();
	    return false;
	 }
	 else if (psf != "" && isCurrency(psf) == false)
	 {
	    alert("Please enter price per square feet in correct currency format. (eg. 500, 455.50, 300.00, 990)");
			document.post_ad_form2.psf.focus();
	    return false;
	 }
	 else if (land_area != "" && isInteger(land_area) == false)
	 {
	    alert("Please enter land area in integer format (eg. 1400, 2100, 1028).");
			document.post_ad_form2.land_area.focus();
	    return false;
	 }
	 
	 return true;
}


//validate land property data
function validate_post_l_pro()
{
	 var land_area = trim(document.post_ad_form2.land_area);
	 
	 if (land_area != "" && isInteger(land_area) == false)
	 {
	    alert("Please enter land area in integer format (eg. 1400, 2100, 1028).");
			document.post_ad_form2.land_area.focus();
	    return false;
	 }
	 return true;
}



function validate_request_contact()
{
	 var name = trim(document.pub_request_contact_form.name);
	 var email = trim(document.pub_request_contact_form.email);
	 var phone = trim(document.pub_request_contact_form.phone);
	 //var comment = trim(document.pub_request_contact_form.comment);
	 var state = trim(document.pub_request_contact_form.state);
	 var age = trim(document.pub_request_contact_form.age);
	 var education = trim(document.pub_request_contact_form.education);
	 var occupation = trim(document.pub_request_contact_form.occupation);
	 
	 
	 if (name == "")
	 {
	    alert("Please enter your name.");
			document.pub_request_contact_form.name.focus();
	 }
	 else if (state == "")
	 {
	    alert("Please select state.");
			document.pub_request_contact_form.state.focus();
	 }
	 else if (age == "")
	 {
	    alert("Please select age.");
			document.pub_request_contact_form.age.focus();
	 }
	 else if (education == "")
	 {
	    alert("Please select education level.");
			document.pub_request_contact_form.education.focus();
	 }
	 else if (occupation == "")
	 {
	    alert("Please select occupation.");
			document.pub_request_contact_form.occupation.focus();
	 }
	 else if (email == "")
	 {
	    alert("Please enter your email address.");
			document.pub_request_contact_form.email.focus();
	 }
	 else if (email != "" && isEmail(email) == false)
	 {
	    alert("Your email address is not in correct format. Please enter again.");
			document.pub_request_contact_form.email.focus();
	 }
	 else if (phone == "")
	 {
	    alert("Please enter your phone number.");
			document.pub_request_contact_form.phone.focus();
	 }	 
	 else
	 {
	    document.pub_request_contact_form.submit();
	 }
}

function validate_listing_lead()
{
	 var name = trim(document.pub_listing_lead_form.name);
	 var email = trim(document.pub_listing_lead_form.email);
	 var phone = trim(document.pub_listing_lead_form.phone);
	 	 
	 if (name == "")
	 {
	    alert("Please enter your name.");
			document.pub_listing_lead_form.name.focus();
	 }	 
	 else if (email == "")
	 {
	    alert("Please enter your email address.");
			document.pub_listing_lead_form.email.focus();
	 }
	 else if (email != "" && isEmail(email) == false)
	 {
	    alert("Your email address is not in correct format. Please enter again.");
			document.pub_listing_lead_form.email.focus();
	 }
	 else if (phone == "")
	 {
	    alert("Please enter your phone number.");
			document.pub_listing_lead_form.phone.focus();
	 }	 
	 else
	 {
	    document.pub_listing_lead_form.submit();
	 }
}

//function to validate enquiry form
function validate_enquiry()
{
   var sender_name = trim(document.enquiry_form.sender_name);
	 var sender_email = trim(document.enquiry_form.sender_email);
	 var sender_phone = trim(document.enquiry_form.sender_phone);
	 var enquiry_type = document.enquiry_form.enquiry_type.value;
   var comment = trim_simple(document.enquiry_form.comment.value);
	 
	 if (sender_name == "")
	 {
	    alert("Please enter your name.");
			document.enquiry_form.sender_name.focus();
			return false;
	 }
	 else if (sender_email == "")
	 {
	    alert("Please enter your email address.");
			document.enquiry_form.sender_email.focus();
			return false;
	 }
	 else if (isEmail(sender_email) == false)
	 {
	    alert("Please check your email address and make sure it is in correct format.");
			document.enquiry_form.sender_email.focus();
			return false;
	 }
	 else if (enquiry_type == "")
	 {
	    alert("Please select the subject of enquiry.");
			document.enquiry_form.enquiry_type.focus();
			return false;
	 }
	 else if (comment == "")
	 {
	    alert("Please enter your comment.");
			document.enquiry_form.comment.focus();
			return false;
	 }
	 
	 return true;
}

//function to validate public feedback form
function validate_feedback()
{
   var user_email = trim_simple(document.feedback_form.sender_email.value);
   var comment = trim_simple(document.feedback_form.mail_body.value);

	 /*if (comment == "")
	 {
	    alert("Please enter your feedback.");
			document.feedback_form.mail_body.focus();
			return false;
	 }*/
	 
	 return true;
}


//function to remove all options from select object
function remove_options(option_list)
{
   var i;
	 
	 //remove all options except the first one
	 if (option_list.length > 1)
	    while (option_list.length > 1)
			   option_list.remove(1);
}

//function to add property type options into list
function add_pro_type_options(option_list, pro_cat, arr_pro_type)
{
   var i;
	 
	 for (i=0; i<arr_pro_type.length-1; i++)
	    if (arr_pro_type[i][0] == pro_cat)
			   option_list[option_list.length] = new Option(arr_pro_type[i][1].substr(2), arr_pro_type[i][1].substr(0,2));
}

//function to load pef images - printable, email friend, and favourite
function load_pef_imgs()
{
   if (document.images)
   {
      img_p1 = new Image(80,25);
	    img_p1.src = "../themes/pub_printable.gif";
	    img_p2 = new Image(80,25);
	    img_p2.src = "../themes/pub_printable2.gif";
	
	    img_e1 = new Image(80,25);
	    img_e1.src = "../themes/pub_email_friend.gif";
	    img_e2 = new Image(80,25);
	    img_e2.src = "../themes/pub_email_friend2.gif";
	
	    img_f1 = new Image(80,25);
	    img_f1.src = "../themes/pub_favourite.gif";
	    img_f2 = new Image(80,25);
	    img_f2.src = "../themes/pub_favourite2.gif";
   }
}

//function to change pef images for rollover effects
function change_pef_img(img_name, img_obj)
{ 
   var img;
   if (document.images)
   {
      img=eval(img_name + ".src");
      img_obj.src= img;
   }
}

//function to validate quick search form
function validate_quick_search()
{
   var ref_code = trim(document.quick_search_form.ref_code);
	 
	 if (ref_code == "")
	 {
	    alert("Please enter property reference code. [integer numbers only]");
	    return false;
	 }
	 else if (ref_code != "" && isInteger(ref_code) == false)
	 {
	    alert("Please enter property reference code. [integer numbers only]");
	    return false;
	 }
	 else
	 {
	    while (ref_code.length < 7)
			   ref_code = "0" + ref_code;
			
			document.quick_search_form.ref_code.value = ref_code;
	 }
	 
	 return true;
}

function select_city(city_str)
{
   var i, city_name;
   var cities = document.main_search_form.city;
	 
	 if (city_str.length<1)
	 {
	    cities[0].selected= true;
			return;
	 }
	 	 
	 for (i=1; i<cities.length; i++)
	 {
	    city_name = cities[i].text.substring(0, city_str.length).toLowerCase();
	    if (city_str.toLowerCase() == city_name)
			{
			   cities[i].selected = true;
				 return;
			}
	 }	 
}

//function to validate proad ids when user hit add to my favourite button
function validate_add_my_fav()
{
   var i, proad_str;
   var proad_ids = document.search_pro_result_form.proad_id;
	 proad_str = "";
	 
	 //in case only one checkbox available
	 if (proad_ids.value)
	 {
	    if (proad_ids.checked == true)
			{
			   window.open("pub_add_my_fav.asp?proad_str=" + proad_ids.value, "my_new_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, left=400, top=200, width=300, height=100");
         return false;
			}	 
	 }
	 
	 for (i=0; i<proad_ids.length; i++)
	 {
	    if (proad_ids[i].checked == true)
			   proad_str = proad_str + proad_ids[i].value + "a"; 
	 }
	 
	 if (proad_str == "")
	 {
	    alert("Please select properties to be added to your favourite list.");
			return false;
   }
	 else
	 {
	    window.open("pub_add_my_fav.asp?proad_str=" + proad_str, "my_new_window","toolbar=no, location=yes, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, left=400, top=200, width=300, height=100");
      return false;
   }
}


//function to remove proad ids when user hit remove from my favourite button
function validate_remove_my_fav()
{
   var i;
   var proad_ids = document.my_fav_form.proad_id;
	 var projad_ids = document.my_fav_form.projad_id;
	 var selected = false;
	 
	 //in case only one checkbox available
	 if (proad_ids)
	 {
	   if (proad_ids.value)
	   {
	      if (proad_ids.checked == true)
			     selected = true;
	   }
	 
	   for (i=0; i<proad_ids.length; i++)
	      if (proad_ids[i].checked == true)
			     selected = true;
	 }		
	 
	 if (projad_ids)
	 {	 
	   if (projad_ids.value)
	   {
	      if (projad_ids.checked == true)
			     selected = true;
	   }
	 
	   for (i=0; i<projad_ids.length; i++)
	      if (projad_ids[i].checked == true)
			     selected = true;			 
	 }
	 //check for at least one check box selected
	 if (selected == false)
	    alert("Please select properties to be removed from your favourite list.");
	 else
	 {
	    if (confirm("Are you sure you want to remove these properties?") == true)
	       document.my_fav_form.submit();
			else
			   return false;	 
   }
}

//function to check all my favourite advertisements
function select_all_fav()
{
   var i;
   var proad_ids = document.my_fav_form.proad_id;
	 var projad_ids = document.my_fav_form.projad_id;
	 
	 if (proad_ids.value != "")
	    proad_ids.checked = true;
	 
	 for (i=0; i<proad_ids.length; i++)
	    proad_ids[i].checked = true;
			
	 if (projad_ids.value != "")
	    projad_ids.checked = true;
	 
	 for (i=0; i<projad_ids.length; i++)
	    projad_ids[i].checked = true;		
}

function ltrim(s)
{
   return s.replace( /^\s*/, "" );
}

function rtrim(s)
{
   return s.replace( /\s*$/, "" );
}

//function to fully trim a string of obj value
function trim(obj)
{
   var s = obj.value;
	 s = rtrim(ltrim(s));
	 
	 //s = s.replace(/\n+/g,"<BR>");
	 s = s.replace(/\n+/g,"&#10;");
	 
   //strip spaces within a string
   s = s.replace(/\s+/g," ");
	 obj.value = s;	 	 
   return s;
}

//function to trim text description of obj value
function trim_text(obj)
{
   var s = obj.value;
	 s = rtrim(ltrim(s));
	 
	 //s = s.replace(/\n+/g,"<BR>");
	 //s = s.replace(/\n+/g,vbNewLine);
	 
   //strip spaces within a string
   //s = s.replace(/\s+/g," ");
	 obj.value = s;	 	 
   return s;
}

//function to do simple trim
function trim_simple(s)
{
   return rtrim(ltrim(s));
}

function isPhone(val) 
{
   var digits="1234567890+-()";
	 for (var i=0; i < val.length; i++) {
	 if (digits.indexOf(val.charAt(i))==-1) { return false; }
   }
	 return true;
}

function isInteger(val) 
{
   var digits="1234567890";
	 for (var i=0; i < val.length; i++) {
	 if (digits.indexOf(val.charAt(i))==-1) { return false; }
   }
	 return true;
}

function isAlpha(val) 
{
   var digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	 for (var i=0; i < val.length; i++) {
	    if (digits.indexOf(val.charAt(i))==-1) 
			   return false;
   }
	 return true;
}

function isAlphaNumeric(val) 
{
   var digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	 for (var i=0; i < val.length; i++) {
	    if (digits.indexOf(val.charAt(i))==-1) 
			   return false;
   }
	 return true;
}

//function to validate email format
function isEmail(email)
{
  var result = false
  var theStr = new String(rtrim(ltrim(email)))
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	     result = true;
  }
	if (theStr.indexOf(" ") != -1) result = false;
	if (theStr.indexOf("..") != -1) result = false;
	if (theStr.indexOf("@@") != -1) resilt = false;
	if (theStr.indexOf(".@") != -1) resilt = false;
	if (theStr.indexOf("@.") != -1) resilt = false;
	if (isAlphaNumeric(theStr.charAt(theStr.length-1)) == false) result = false;
	if (isAlphaNumeric(theStr.charAt(0)) == false) result = false;
  return result;
}

function isCurrency(val) 
{
   var digits="1234567890.";
	 for (var i=0; i < val.length; i++) {
	    if (digits.indexOf(val.charAt(i))==-1) 
			   return false;
   }
	 
	 //cant end with decimal
	 if (val.charAt(val.length-1) == '.') return false;
	 
	 if (val.indexOf(".") != -1 && val.indexOf(".") != (val.length-3))
	 {
	    if (val.indexOf(".") == (val.length-3)) 
			   return true; 
			else if (val.indexOf(".") == (val.length-2)) 
			   return true;
			else
			   return false;	  
   }
	 
	 return true;
}

//function to return the checked radio button value
function getRadioValue(obj)
{
   var radio_value;
	 radio_value = "";
	 
	 for (var i=0; i < obj.length; i++)
      if (obj[i].checked)
         radio_value = obj[i].value;
	
	 return radio_value;
}
// -->