function sendMessage() {
	document.getElementById("resultBox").style.display = "none";
	if (document.c.name.value == "" || document.c.name.value == "YOUR NAME") {
		errorMessage("Please enter your name", "resultBox");
		return false;
	}
	if (document.c.email.value == "" || document.c.email.value == "EMAIL ADDRESS") {
		errorMessage("Please enter your email address", "resultBox");
		return false;
	}
	if (document.c.captcha_text.value.length < 2 || document.c.captcha_text.value == "IMAGE TEXT") {
		errorMessage("Please enter the text as shown in the image box", "resultBox");
		return false;
	}
	var name = escape(document.c.name.value);
	var email = escape(document.c.email.value);
	var phone = escape(document.c.phone.value);
	var other = escape(document.c.other.value);
	var captcha = escape(document.c.captcha_text.value);
	var id = document.c.id.value;
	var url = "/ajax/email_agent.php5?id="+id+"&name="+name+"&email="+email+"&phone="+phone+"&other="+other+"&captcha="+captcha;
	if (document.c.arrange_viewing && document.c.arrange_viewing.checked) url += "&viewing=1";
	document.c.but.disabled=true;
	errorMessage("Sending your message...", "resultBox");
	ajaxCall("resultBox", url);
}

function registerInvestor() {
	var f = document.f;
	var url = "/ajax/investment_register.php?name=" + escape(f.name.value) + "&area=" + escape(f.area.value) +
		"&phone=" + escape(f.phone.value) + "&email=" + escape(f.email.value) + "&other=" + escape(f.other.value);
	if (f.individual.checked) url += "&individual=1";
	if (f.portfolios.checked) url += "&portfolios=1";
	if (f.tenanted.checked) url += "&tenanted=1";
	if (f.offplan.checked) url += "&offplan=1";
	if (f.redevelopment.checked) url += "&redevelopment=1";
	if (f.overseas.checked) url += "&overseas=1";
	url += "&merseyside=";
	if (f.merseyside[0].checked) url += escape(f.merseyside[0].value);
	else url += escape(f.merseyside[1].value);
	document.f.s.disabled=true;
	errorMessage("Registering...", "resultBox");
	ajaxCall("resultBox", url);
}

function errorMessage(m, box) {
	var d = document.getElementById(box);
	d.style.display="";
	d.innerHTML = m;
}

function initXmlHttp() {
  	try {
    	// Firefox, Opera 8.0+, Safari
    	xmlHttp=new XMLHttpRequest();
        xmlHttp.overrideMimeType("text/html");
       } catch (e) {
    	// Internet Explorer
    	try {
      		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
     	} catch (e) {
      		try {
       			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      		} catch (e) {
      			alert("Unsupported browser type. This page will not work!");
       			return;
      		}
    	}
  	}
  	return xmlHttp;
}

/**
 * Make an AJAX call, populating the given div with
 * the result from the given URL.
 */
function ajaxCall(divId, url) {
	var div = document.getElementById(divId);
	if (div == null) {
		alert("Div '" + divId + "' does not exist");
		return;
	}

	var xmlHttp = initXmlHttp();
	prepareXmlHttp(xmlHttp, div);
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

/**
 * Common function to prepare the xmlHttpRequest object
 * based on the browser type, ready for making AJAX calls.
 */
function prepareXmlHttp(xmlHttp, div) {
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			div.innerHTML = xmlHttp.responseText;
			if (document.c && document.c.but) document.c.but.disabled=false;
			if (document.f && document.f.s) document.f.s.disabled=false;
		}
	}
}