function popaway(){
window.close();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function searchvalidate() {
    var typesel = 0;
	var provincesel = 0;
	var areasel = 0;
	var suburbsel = 0;
	
	for (i = 0;  i < document.advancedsearch.elements['propertytype[]'].length; i++) {
		if (document.advancedsearch.elements['propertytype[]'].options[i].selected)
			typesel++;
	}
	
	for (i = 0;  i < document.advancedsearch.elements['area[]'].length; i++) {
		if (document.advancedsearch.elements['area[]'].options[i].selected)
			areasel++;
	}
		
	if (typesel < 1) {
		alert("Please make sure that you select at least one Property Type.");
	} else if (areasel < 1) {
		alert("Please make sure that you select at least one Area.");
	} else {
		document.advancedsearch.action = "results.php";
		document.advancedsearch.submit();
	}
}

function propertyalertsvalidate() {
    var typesel = 0;
	var provincesel = 0;
	var areasel = 0;
	var suburbsel = 0;
	
	for (i = 0;  i < document.propertyalerts.elements['propertytype[]'].length; i++) {
		if (document.propertyalerts.elements['propertytype[]'].options[i].selected)
			typesel++;
	}
	
	for (i = 0;  i < document.propertyalerts.elements['area[]'].length; i++) {
		if (document.propertyalerts.elements['area[]'].options[i].selected)
			areasel++;
	}
	
	if (document.propertyalerts.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.propertyalerts.surname.value=='') {
		alert("Please fill in your surname.");
	} else if (document.propertyalerts.number.value=='') {
		alert("Please fill in a Contact Number.");
	} else if (document.propertyalerts.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.propertyalerts.email.value.search("@")==-1) || (document.propertyalerts.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else if (areasel < 1) {
		alert("Please make sure that you select at least one Area/Suburb.");
	} else if (typesel < 1) {
		alert("Please make sure that you select at least one Property Type.");
	} else {
		document.propertyalerts.action = "property_alerts_confirm.php";
		document.propertyalerts.submit();
	}
}

function contactvalidate() {
	if (document.contact.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.contact.number.value=='') {
		alert("Please fill in a Contact Number.");
	} else if (document.contact.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.contact.email.value.search("@")==-1) || (document.contact.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else {
		document.contact.action = "send-contact-me.php";
		document.contact.submit();
	}
}

function contactvalidateholiday() {
	if (document.contact.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.contact.number.value=='') {
		alert("Please fill in a Contact Number.");
	} else if (document.contact.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.contact.email.value.search("@")==-1) || (document.contact.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else {
		document.contact.action = "send-contact-me-holiday.php";
		document.contact.submit();
	}
}

function contact_us_validate() {
	if (document.contact.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.contact.number.value=='') {
		alert("Please fill in a Contact Number.");
	} else if (document.contact.email.value=='') {
		alert("Please fill in your email address.");
	} else if (document.contact.enquiry.value=='') {
		alert("Please fill in the enquiry field with a short description of your enquiry.");
	} else {
		document.contact.action = "contact_confirm.php";
		document.contact.submit();
	}
}

function smsvalidate() {
	if (document.sms.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.sms.number.value=='') {
		alert("Please fill in a Contact Number.");
	} else if (document.sms.email.value=='') {
		alert("Please fill in your email address.");
	} else if (document.sms.enquiry.value=='') {
		alert("Please fill in the enquiry field with a short description of your enquiry.");
	} else {
		document.sms.action = "send-sms.php";
		document.sms.submit();
	}
}

function refsearchvalidate() {
	if (document.refsearch.refnum.value=='') {
		alert("Please fill in the reference number.");
	} else {
		document.refsearch.action = "details.php";
		document.refsearch.submit();
	}
}

function savesearchvalidate() {
	if (document.savesearch.searchname.value=='') {
		alert("Please fill in a name for your search.");
	} else {
		document.savesearch.action = "savesearchdb.php";
		document.savesearch.submit();
	}
}

function registervalidate() {
	if (document.register.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.register.surname.value=='') {
		alert("Please fill in your surname.");
	} else if (document.register.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.register.email.value.search("@")==-1) || (document.register.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else if (document.register.contactnum.value=='') {
		alert("Please fill in your contact number.");
	} else {
		document.register.action = "register.php";
		document.register.submit();
	}
}

function assessmentvalidate() {
	if (document.assessment.address.value=='') {
		alert("Please fill in the address of your property.");
	} else if (document.assessment.description.value=='') {
		alert("Please fill in a short description of your property.");
	} else if (document.assessment.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.assessment.contactnum.value=='') {
		alert("Please fill in a Contact Number.");
	} else if (document.assessment.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.assessment.email.value.search("@")==-1) || (document.assessment.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else {
		document.assessment.action = "assessment_confirm.php";
		document.assessment.submit();
	}
}

function emailresultsvalidate() {
	if (document.email_results.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.email_results.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.email_results.email.value.search("@")==-1) || (document.email_results.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else if (document.email_results.recname.value=='') {
		alert("Please fill in the receipients name.");
	} else if (document.email_results.recemail.value=='') {
		alert("Please fill in the receipients email address.");
	} else if ((document.email_results.recemail.value.search("@")==-1) || (document.email_results.recemail.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else if (document.email_results.comments.value=='') {
		alert("Please fill in your comments.");
	} else {
		document.email_results.action = "send-results.php";
		document.email_results.submit();
	}
}

function emaildetailsvalidate() {
	if (document.emaildetails.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.emaildetails.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.emaildetails.email.value.search("@")==-1) || (document.emaildetails.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else if (document.emaildetails.recname.value=='') {
		alert("Please fill in the receipients name.");
	} else if (document.emaildetails.recemail.value=='') {
		alert("Please fill in the receipients email address.");
	} else if ((document.emaildetails.recemail.value.search("@")==-1) || (document.emaildetails.recemail.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else if (document.emaildetails.comments.value=='') {
		alert("Please fill in your comments.");
	} else {
		document.emaildetails.action = "send-details.php";
		document.emaildetails.submit();
	}
}

function llcontactvalidate(formnum) {
	if (document.forms[formnum].name.value=="") {
		alert("Please fill in your name.");
	} else if (document.forms[formnum].number.value=="") {
		alert("Please fill in your contact number.");
	} else if (document.forms[formnum].email.value=="") {
		alert("Please fill in your email address.");
	} else if ((document.forms[formnum].email.value.search("@")==-1) || (document.forms[formnum].email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");	
	} else if (document.forms[formnum].comments.value=="") {
		alert("Please fill in your comments.");
	} else {
		document.forms[formnum].action = "email-contact-me.php";
		document.forms[formnum].submit();
	}
}

function loginvalidate() {
	if (document.login.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.login.email.value.search("@")==-1) || (document.login.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");
	} else {
		document.login.action = "login.php";
		document.login.submit();
	}
}

function selectAll(box) {
    for(var i=0; i<box.length; i++) {
    	box[i].selected = true;
   	}
}

function dselectAll(box) {
  	for(var i=0; i<box.length; i++) {
    	box[i].selected = false;
  	}
}

function updateSavedSearchEmailAlert(row) {
	var formName = "savedSearchedResulsts" + row;
	document.getElementById(formName).action="update_emailalerts.php";
	document.getElementById(formName).submit();
}

function printWindow() {
  	alert("Please set your printer to A4 portrait. Thank You.");
	window.print();
}
function textCounter(field,counter,maxlimit,linecounter) {
        var fieldWidth =  parseInt(field.style.width);
        var charcnt = field.value.length;        
        if (charcnt > maxlimit) { 
                field.value = field.value.substring(0, maxlimit);
        }
        else { 
        var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
        document.getElementById(counter).style.width =  parseInt((fieldWidth*percentage)/100)+"px";
        setcolor(document.getElementById(counter),percentage,"background-color");
        }
}
function setcolor(obj,percentage,prop){
        obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
function reloadSearch() {
	type = document.advancedsearch.listingtype.value.split("|");
	window.location = "search.php?province=" + document.advancedsearch.province.value + "&listingstatus=" + type[0] + "&listingtype=" + type[1];
}
function reloadSearch2() {
	type = document.advancedsearch.listingtype.value.split("|");
	window.location = "search.php?listingstatus=" + type[0] + "&listingtype=" + type[1];
}

function reloadPropertyAlerts() {
	type	= document.propertyalerts.listingtype.value.split("|");
	name	= document.propertyalerts.name.value;
	sname	= document.propertyalerts.surname.value;
	number	= document.propertyalerts.number.value;
	email	= document.propertyalerts.email.value;
	province= document.propertyalerts.province.value;
	window.location = "property_alerts.php?province="+ province +"&name=" + name + "&surname=" + sname + "&number=" + number + 
						"&email=" + email + "&listingstatus=" + type[0] + "&listingtype=" + type[1];
}

function addtomailinglist() {
	if (document.mailinglist.name.value=='') {
		alert("Please fill in your name.");
	} else if (document.mailinglist.email.value=='') {
		alert("Please fill in your email address.");
	} else if ((document.mailinglist.email.value.search("@")==-1) || (document.mailinglist.email.value.search("[.*]")==-1)) {
        alert("Please make sure that you fill in the email field correctly.");	
	} else {
		document.mailinglist.action = "joinmaillist.php";
		document.mailinglist.submit();
	}
}
function choosePriceRange() {
	
	var store = new Array();
	
	store[0] = new Array(
	'Any',
	'Below R500 000',
	'R500 000 - R1 000 000',
	'R1 000 000 - R1 500 000',
	'R1 500 000 - R2 000 000',
	'R2 000 000 - R2 500 000',
	'R2 500 000 - R3 000 000',
	'R3 000 000 - Above'
	);
	
	store[1] = new Array(
	'',
	'0|500000',
	'500000|1000000',
	'1000000|1500000',
	'1500000|2000000',
	'2000000|2500000',
	'2500000|3000000',
	'3000000|99990000000'
	);
	
	store[2] = new Array(
	'Any',
	'Below R2500',
	'R2 500 - R5 000',
	'R5 000 - R7 500',
	'R7 500 - R10 000',
	'R10 000 - R15 000',
	'R15 000 - R20 000',
	'R20 000 - Above'
	);
	
	store[3] = new Array(
	'',
	'0|2500',
	'2500|5000',
	'5000|7500',
	'7500|10000',
	'10000|15000',
	'15000|20000',
	'20000|99990000000'
	);	
	
	store[4] = new Array(
	'Any',
	'Below R250',
	'R250 - R500',
	'R500 - R750',
	'R750 - R1 000',
	'R1 000 - R1 500',
	'R1 500 - R2 000',
	'R2 000 - Above'
	);
	
	store[5] = new Array(
	'',
	'0|250',
	'250|500',
	'500|750',
	'750|1000',
	'1000|1500',
	'1500|2000',
	'2000|99990000000'
	);	
	
	if(document.quicksearch.listingstatus.value=="For Sale|Residential" || document.quicksearch.listingstatus.value=="For Sale|Commercial") {
		for(i=0; i<8; i++)
			document.quicksearch.pricerange[i] = new Option(store[0][i], store[1][i]);
	
	} else if (document.quicksearch.listingstatus.value=="To Let|Residential" || document.quicksearch.listingstatus.value=="To Let|Commercial") {
		for(i=0; i<8; i++)
			document.quicksearch.pricerange[i] = new Option(store[2][i], store[3][i]);
	} else if (document.quicksearch.listingstatus.value=="To Let|Holiday") {
		for(i=0; i<8; i++)
			document.quicksearch.pricerange[i] = new Option(store[4][i], store[5][i]);
	} else {
		for(i=0; i<8; i++)
			document.quicksearch.pricerange[i] = new Option(store[0][i], store[1][i]);
	}
}


