function showPhone(theLink,page,phone) {
	
	if (phone && phone!='')
	{
		theLink.innerHTML = phone;
	}
	else {
		theLink.innerHTML = 'coming soon';
	}

	theLink.style.textDecoration = 'none';

	pageTracker._trackPageview('/click'+page);


}

function submitLead() {

	var f = document.form1;


	var checkForEmpty = new Array();

	/*

	if (document.getElementById('customerData[name]').value=='' 
		|| document.getElementById('customerData[email]').value==''
		|| document.getElementById('customerData[squareMeters]').value==''
		|| document.getElementById('customerData[phone]').value==''
		|| document.getElementById('customerData[jobType]').value==''
		|| document.getElementById('customerData[floorType]').value==''
		|| document.getElementById('customerData[job_details]').value==''

	
	) {
		
		alert('Please enter all required fields');
		return false;

	}


	if (document.getElementById('customerData[suburb]').value==''
	   || document.getElementById('customerData[postcode]').value=='' 
	
	) {
		
		alert('Suburb and Postcode not found please select it from the list after you start typing');
		return false;

	}
*/

	//ajaxPostRequest(postURL,theForm,returnDisplayId,hideBlockId,dataValidation,defaultSuccessLocation);

	f.signupUrl.value = window.location;

	f.spamCheck.value = 'notspammer';

	
	f.submit();
}


function loadLeadForm(url)
{

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  xmlhttp.open("GET",url,false);
  xmlhttp.send(null);
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.open("GET",url,false);
  xmlhttp.send();
  }
	
  document.getElementById('leadCaptureContainer').innerHTML=xmlhttp.responseText;

	//for suburbs select
	var options = {
		script:"/action.php?a=autocompletesuburb&json=true&",
		varname:"input",
		json:true,
		minchars:2,
		noresults:"Suburb and Postcode not found please select it from the list after you start typing",
		callback: function (obj) { document.getElementById('customerData[postcode]').value = obj.id;   }
	};
	var as_json = new AutoSuggest('customerData[suburb]', options);
	
	/*
	var options_xml = {
		script:"action.php?",
		varname:"input"
	};
	var as_xml = new AutoSuggest('testinput_xml', options_xml);*/

}


function getXMLObject()  //XML OBJECT
{
   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}
 



/*

ajax submit form



*/

function ajaxPostRequest(postURL,theForm,returnDisplayId,hideBlockId,dataValidation,defaultSuccessLocation) {

	$('#submitButton').attr('disabled', 'disabled');
	
	var xmlhttp = new getXMLObject();	//xmlhttp holds the ajax object



	var getdate = new Date();  //Used to prevent caching during ajax call

	if (xmlhttp) { 

		var elem = document.getElementById(theForm).elements;

		var postStr = "";

        for(var i = 0; i < elem.length; i++)
        {
            postStr += encodeURIComponent(elem[i].name) + "="+ encodeURIComponent(elem[i].value)+"&";
            
        } 

			
  	
    xmlhttp.open("POST",postURL,false); 

	

   // xmlhttp.onreadystatechange = function()
	//{
	//	alert(xmlhttp);
		
	//}

    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send(postStr); 

	if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{

	
			var returnObject = eval("(" + xmlhttp.responseText + ")");
			
			if (returnObject.message=='error' && dataValidation)
			{
				//hide all form fields first
				//alert($(".requiredField").length);

				$.each($(".requiredField"), function(index, value) { 
					
					//alert(this.id + ': ' + value); 
					$(this).css('display','none');

					$(this).parent().removeClass('errorHighlight');

				});

			
				//highlight validation error fields
				for (var key in returnObject.errorFields) 
				{
					if (document.getElementById('required_'+key) && returnObject.errorFields[key]==1)
					{
						//document.getElementById('required_'+key).style.display='block';

						//highlight the field

						key = key.replace("[","\\[");

						key = key.replace("]","\\]");

						$('#required_'+key).css('display','block');

						$('#required_'+key).parent().addClass('errorHighlight');
					

					}



				}
				$('#submitButton').removeAttr('disabled');

				alert('One of the fields you have entered does not look correct');

			}
			else if (returnObject.message=='displayMessage')
			{
				
				document.getElementById(returnDisplayId).innerHTML=returnObject.displayMessage;
				document.getElementById(returnDisplayId).style.display='block';

			}
			else if (returnObject.message=='success')
			{
				
				if (hideBlockId!='')
				{
					$('#'+hideBlockId).css('display','none');
				}

				//change confirm message to green if available
				$('#'+returnDisplayId).css('display','block');
				$('#'+returnDisplayId).toggleClass('greenMessage');

				//success is not always a redirect, sometimes we may just want to display a message so use displayMessage above

				if (returnObject.displayMessage && returnObject.displayMessage!='')
				{
				
					$('#'+returnDisplayId).html(returnObject.displayMessage);
				}
				else {
				
				
				if (returnObject.redirect && returnObject.redirect!='')
				{
						
					window.location=returnObject.redirect;
				}

				else if (defaultSuccessLocation && defaultSuccessLocation!= '')
				{

					window.location=defaultSuccessLocation;

				}

				}
				//sometimes we want to hide a block block to display success message, sometimes we want to redirect to another page, sometimes we just display a message
				
			}
		}

	
  }


}
