var xmlHttp;
	
var afterFunc = "";
var xmlDoc;
var sSendMethod = "GET";

var iErrors;
var sText;
var aTotallCol;
var aRedCol;

var iBoxH;
if(!url)
	var url="lib/functions_send.php";
/*==================== 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();
	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)
		{
//			alert(aTotallCol[iPar].childNodes[0].nodeValue);
			document.getElementById("lb"+aTotallCol[iPar].childNodes[0].nodeValue).style.color = "#000";
		}
	}
	iPar = 0;
	for(;iPar<aRedCol.length;iPar++)
	{
		if(aRedCol[iPar].childNodes[0].nodeValue)
		{
//			alert("lb"+aRedCol[iPar].childNodes[0].nodeValue);
			document.getElementById("lb"+aRedCol[iPar].childNodes[0].nodeValue).style.color = "#b71d1d";
//			alert(document.getElementById("lb"+aRedCol[iPar].childNodes[0].nodeValue).className);
		}
	}
}


/*==================== START SEND CONTACT US ========================*/
function SendContactUs()
{
//	document.getElementById("slt").style.color = "#000000";
//	document.getElementById("slt").innerHTML = promo;	

	var params = "id=0&name="+document.getElementById("name").value;
	params += "&title="+document.getElementById("title").value;
	params += "&company="+document.getElementById("company").value;
	params += "&email="+document.getElementById("email").value;
	params += "&text="+document.getElementById("text").value;
	params += "&action=contactus";
	Run(params,"afterSendContactUs");
}

function afterSendContactUs()
{	
	document.getElementById("slt").style.display = "";
	if( 0 == iErrors)	
	{
		var mess = '<h1 style=" font-size:14px; font-weight:700;">Thank you for your message</h1>';
		
//		document.getElementById("cnt").style.display = "none";
//		document.getElementById("boxregTh").style.display = "block";
//		document.getElementById("contact_box").style.height = iBoxH-48+"px";
		
		document.getElementById('name').value = "";
		document.getElementById('title').value = "";
		document.getElementById('company').value = "";
		document.getElementById('email').value = "";
		document.getElementById('text').value = "";
		document.getElementById("slt").innerHTML = mess;
		setTimeout('prepareContact()',5000);
	}
	else
	{
		document.getElementById("slt").style.color = "#990000";
		document.getElementById( "slt" ).innerHTML = sText+"<br><br>";		
	}
}

function prepareContact()
{		
//	document.getElementById( "boxregTh" ).style.display = "none";
//	document.getElementById( "cnt" ).style.display = "block";
	document.getElementById("slt").style.color = "#000000";
	document.getElementById("slt").innerHTML = promo;	
//	document.getElementById("contact_box").style.height = iBoxH-48+"px";
	
}
/*==================== END SEND CONTACT US ========================*/
/*==================== START CHECK APPLY ========================*/
function SendCheckApply()
{

	var params = "id=0&name="+document.getElementById("name").value;
	params += "&email="+document.getElementById("email").value;
	params += "&f_input="+document.getElementById("f_input").value;
	params += "&action=check_apply";
	Run(params,"afterSendCheckApply");
}

function afterSendCheckApply()
{	
	document.getElementById("slt").style.display = "";

	if( 0 == iErrors)	
	{
		document.send_apply.submit();
		var mess = "Thank you for your query. We'll be in touch shortly.";		
		
		document.getElementById('name').value = "";
		document.getElementById('cnumber').value = "";
		document.getElementById('email').value = "";
		document.getElementById('f_input').value = "";
		document.getElementById('f_file').value = "";
		document.getElementById("slt").style.color = "red";
		document.getElementById("slt").innerHTML = mess;
		document.getElementById("afterLoding").innerHTML = "<img src='/images/loading.gif' style='float:left; padding:10px 0px 10px 170px;' />";
		setTimeout('prepareApply()',5000);
	}
	else
	{
		document.getElementById("slt").style.color = "#990000";
		document.getElementById("slt").innerHTML = sText;		
	}
}

function prepareApply()
{	
	document.getElementById("slt").style.color = "#000000";
	document.getElementById("slt").innerHTML = promo;
	document.getElementById("apply_bg").style.display = "none";		
	document.getElementById("apply_form").style.display = "none";
	document.getElementById("afterLoding").innerHTML = '<input value="SUBMIT"  onclick="SendCheckApply();return false;" type="submit">';
}
/*==================== END CHECK APPLY ========================*/
