// Home page

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
	  // Internet Explorer
	  try
	  {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e)
	  {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	return xmlHttp;
}

function postcodeCheck_Return()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.responseText=='OK') {
			document.getElementById('search').disabled=false;
			document.getElementById('search').style.display="block";
			$("#find_consultant").backgroundCanvasPaint(MyBackgroundPaint40); 
		} else {
			document.getElementById('search').disabled=true;
			document.getElementById('search').style.display="none";
			$("#find_consultant").backgroundCanvasPaint(MyBackgroundPaint40); 
		}

	}
}

function postcodeCheck()
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		return;
	}

	var url = "checkpostcode.php";
	url = url + "?pcode=" + document.getElementById('pcode').value;
	url = url + "&tno=" + document.getElementById('tno').value;
	url = url + "&cname=" + document.getElementById('cname').value;

	xmlHttp.onreadystatechange=postcodeCheck_Return;
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
}

function postcodeSearch_Return()
{
	if(xmlHttp.readyState==4)
	{
			alert(xmlHttp.responseText);
	}
}

function postcodeSearch()
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("I'm sorry i'm unable to send your request at this time.\n\nTo find your nearest MortgageForce consultant, please call us on 0800 083 1006.");
		return;
	}

	var url = "postcodesearch.php";
	url = url + "?pcode=" + document.getElementById('pcode').value;
	url = url + "&tno=" + document.getElementById('tno').value;
	url = url + "&cname=" + document.getElementById('cname').value;

	xmlHttp.onreadystatechange=postcodeSearch_Return;
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
}

function ask_katie_a_question()
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("I'm sorry i'm unable to send your question to Katie at this time.\n\nTo find your nearest MortgageForce consultant, please call us on 0800 083 1006.");
		return;
	} 
		
	var url="/ask_katie/post_katie_a_question.php";
	url=url+"?name="+document.getElementById("cName").value;
	url=url+"&email="+document.getElementById("cEmail").value;
	url=url+"&question="+document.getElementById("cQuestion").value;
	xmlHttp.onreadystatechange=questionPosted;
	xmlHttp.open("GET",url,true);	
	xmlHttp.send(null);
}

function questionPosted()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.responseText=='OK')
		{
			document.getElementById("cName").value = "";
			document.getElementById("cEmail").value = "";
			document.getElementById("cQuestion").value = "";
			alert("Thank You.\n\nYour question has been sent to Katie who will post an answer as soon as she can.\n\nKatie will endeavour to answer every question but sometimes this may not be possible.");			
		} else {			
			alert ("I'm sorry i'm unable to send your question to Katie at this time.\n\nTo find your nearest MortgageForce consultant, please call us on 0800 083 1006.");
		}
	}
}
