var xmlHttp;
	
var afterFunc = "";
var xmlDoc;
var sSendMethod = "GET";

var iErrors;
var sText;
var aTotallCol;
var aRedCol;

var iBoxH;
/*==================== STRT AXAS MODEL ========================*/
function GetXmlHttpObject()
{
	if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();        
    } else if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");        
    }
    return xmlHttp;
}

function Run(send_url,func)
{ 
	afterFunc = func;
	var params = "";
	if("" != send_url && "GET" == sSendMethod)
		params = url += "?"+send_url;
	else
		params = send_url;
	xmlHttp=GetXmlHttpObject();
	//alert(url);
	if (xmlHttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}	
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open(sSendMethod,url,true);	
	if("POST" == sSendMethod)
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");	
	try
	{
		xmlHttp.send(params);		
	}
	catch(err){}
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{
		var newses = "";
		var news = "";
		//alert(afterFunc);
		xmlDoc=xmlHttp.responseXML.documentElement;
		if(!xmlDoc)
		{
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.load(url);
		}
		var iErrorsCol = xmlDoc.getElementsByTagName("errors");
		var sTextCol = xmlDoc.getElementsByTagName("message");
		aTotallCol = xmlDoc.getElementsByTagName("totall");
		aRedCol = xmlDoc.getElementsByTagName("red");
		
		iErrors = iErrorsCol[0].childNodes[0].nodeValue;
		sText = sTextCol[0].childNodes[0].nodeValue;
		
		ColorLabel();
		//alert(xmlDoc);
		eval(afterFunc+"()");
	}	
}

/*==================== END AXAS MODEL ========================*/

function ColorLabel()
{
	var iPar = 0;
	for(;iPar<aTotallCol.length;iPar++)
	{
		if(aTotallCol[iPar].childNodes[0].nodeValue 
			&& document.getElementById(aTotallCol[iPar].childNodes[0].nodeValue))
		{
			document.getElementById(aTotallCol[iPar].childNodes[0].nodeValue).className = aTotallCol[iPar].childNodes[0].nodeValue;
			document.getElementById("lb"+aTotallCol[iPar].childNodes[0].nodeValue).style.display = "none";
		}
	}
	iPar = 0;
	for(;iPar<aRedCol.length;iPar++)
	{
		if(aRedCol[iPar].childNodes[0].nodeValue 
			&& document.getElementById(aRedCol[iPar].childNodes[0].nodeValue))	
		{	
			document.getElementById(aRedCol[iPar].childNodes[0].nodeValue).className = aRedCol[iPar].childNodes[0].nodeValue+"err";
			document.getElementById("lb"+aRedCol[iPar].childNodes[0].nodeValue).style.display = "";
		}
	}
}


/*==================== START SEND CONTACT US ========================*/
function SendContactUs()
{

	var params = "id=0&name="+document.getElementById("name").value;
	params += "&cname="+document.getElementById("cname").value;
	params += "&tel="+document.getElementById("tel").value;
	params += "&email="+document.getElementById("email").value;
	params += "&message="+document.getElementById("message").value;
	params += "&action=contactus";
	Run(params,"afterSendContactUs");
}

function afterSendContactUs()
{	
	document.getElementById("slt").style.display = "";
	if( 0 == iErrors)	
	{
		document.location = 'thankyou.html';
//		var mess = "Many thanks for your inquiry. Your message has been received and someone from PowerPax will be in touch shortly. If you require anything in the meantime please do not hesitate to contact us on t: 0118 959 0111";		
		
//		document.getElementById('name').value = "";
//		document.getElementById('cname').value = "";
//		document.getElementById('email').value = "";
//		document.getElementById('message').value = "";
//		document.getElementById('tel').value = "";
//		document.getElementById("slt").style.color = "#000000";
//		document.getElementById("slt").innerHTML = mess;
//		setTimeout('prepareContact()',5000);
	}
	else
	{
		document.getElementById("slt").style.color = "#990000";
		document.getElementById( "slt" ).innerHTML = sText;		
	}
}

function prepareContact()
{	
	document.getElementById("slt").style.color = "#000000";
	document.getElementById("slt").innerHTML = sSLTText;		
}
/*==================== END SEND CONTACT US ========================*/