var xmlHttp;
	
var afterFunc = "";
var xmlDoc;
var sSendMethod = "GET";

var iErrors;
var sText;
var aTotallCol;
var aRedCol;

var PDF = '', PDFType = '';
var iBoxH;

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();
	//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] && aTotallCol[iPar].childNodes[0].nodeValue)
		{
//			alert(aTotallCol[iPar].childNodes[0].nodeValue);
			if( document.getElementById("lb"+aTotallCol[iPar].childNodes[0].nodeValue) )
				document.getElementById("lb"+aTotallCol[iPar].childNodes[0].nodeValue).className = "obligatoryField";
		}
	}
	iPar = 0;
	for(;iPar<aRedCol.length;iPar++)
	{
		if(aRedCol[iPar].childNodes[0].nodeValue && document.getElementById("lb"+aRedCol[iPar].childNodes[0].nodeValue) )
			document.getElementById("lb"+aRedCol[iPar].childNodes[0].nodeValue).className = "redField";
	}
}


/*==================== START SEND CONTACT US ========================*/
function SendContactUs()
{
//	document.getElementById("slt").style.color = "#000000";
//	document.getElementById("slt").innerHTML = promo;	
	document.getElementById("google_contact_us_div").style.display = "none";	
	document.getElementById("google_contact_us_img").src="";

	var params = "id=0&name="+document.getElementById("name").value;
	params += "&cname="+document.getElementById("cname").value;
	params += "&phone="+document.getElementById("phone").value;
	params += "&email="+document.getElementById("email").value;
	params += "&comment="+document.getElementById("comment").value;
	params += "&depart="+document.getElementById("depart").value;
	params += "&action=contactus";
	Run(params,"afterSendContactUs");
}

function afterSendContactUs()
{	
	document.getElementById("slt").style.display = "";
	if( 0 == iErrors)	
	{
		var mess = '<h1 style=" font-size:16px; font-weight:700;">Thank you for your message</h1> <br /><br />';
		
//		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('cname').value = "";
		document.getElementById('email').value = "";
		document.getElementById('phone').value = "";
		document.getElementById('comment').value = "";
		document.getElementById("slt").innerHTML = mess;
		google_conversion_id = 1028548333;
		google_conversion_language = "en_GB";
		google_conversion_format = "1";
		google_conversion_color = "ffffff";
		google_conversion_label = "2fhECOHvrQEQ7c256gM";
		google_conversion_value = 0;
		
		document.getElementById("google_contact_us_div").style.display = "inline";	
		document.getElementById("google_contact_us_img").src="http://www.googleadservices.com/pagead/conversion/1028548333/?label="+google_conversion_label+"&guid=ON&script=0";
		setTimeout('prepareContact()',5000);
	}
	else
	{
		document.getElementById("slt").style.color = "#990000";
		document.getElementById( "slt" ).innerHTML = sText+"<br><br>";		
	}
}
var google_conversion_id;
var google_conversion_language;
var google_conversion_format;
var google_conversion_color;
var google_conversion_label;
var google_conversion_value;
function prepareContact()
{		
//	var txt = '<script type="text/javascript">';
//		txt += '<!--';
//		txt += 'var google_conversion_id = 1028548333;';
//		txt += 'var google_conversion_language = "en_GB";';
//		txt += 'var google_conversion_format = "1";';
//		txt += 'var google_conversion_color = "ffffff";';
//		txt += 'var google_conversion_label = "2fhECOHvrQEQ7c256gM";';
//		txt += 'var google_conversion_value = 0;';
//		txt += '//-->';
//		txt += '</script>';
//		txt += '<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">';
//		txt += '</script>';
//		txt += '<noscript>';
//		txt += '<div style="display:inline;">';
//		txt += '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1028548333/?label=2fhECOHvrQEQ7c256gM&guid=ON&script=0"/>';
//		txt += '</div>';
//		txt += '</noscript>';
	
//	document.getElementById( "boxregTh" ).style.display = "none";
//	document.getElementById( "cnt" ).style.display = "block";
	document.getElementById("slt").style.color = "#000000";
	document.getElementById("slt").innerHTML = promo;	
//	document.write(txt);	
//	document.getElementById("contact_box").style.height = iBoxH-48+"px";
	
}
/*==================== END SEND CONTACT US ========================*/

/*==================== START SEND NEWSLETTER SUBSCRIBER ========================*/
function SendSubscriber()
{
//	document.getElementById("slt").style.color = "#000000";
//	document.getElementById("slt").innerHTML = promo;	

	var params = "id=0&name_sb="+document.getElementById("name_sb").value;
	params += "&cname_sb="+document.getElementById("cname_sb").value;
	params += "&country_sb="+document.getElementById("country_sb").value;
	params += "&email_sb="+document.getElementById("email_sb").value;
	params += "&divsion_sb="+document.getElementById("divsion_sb").value;
	params += "&action=subscriber";
	Run(params,"afterSendSubscriber");
}

function afterSendSubscriber()
{	
	document.getElementById("slt_sb").style.display = "";
	if( 0 == iErrors)	
	{
		var mess = '<h4>Thank you for your message</h4><br/>';
		
		document.getElementById('name_sb').value = "";
		document.getElementById('cname_sb').value = "";
		document.getElementById('country_sb').value = "";
		document.getElementById('email_sb').value = "";
		document.getElementById("slt_sb").style.color = "#000000";
		document.getElementById("slt_sb").innerHTML = mess;
		setTimeout('prepareSubscriber()',5000);
	}
	else
	{
		document.getElementById("slt_sb").style.color = "#990000";
		document.getElementById( "slt_sb" ).innerHTML = sText+"<br><br>";		
	}
}

function prepareSubscriber()
{		
	document.getElementById("slt_sb").style.color = "#000000";
	document.getElementById("slt_sb").innerHTML = promo;	
	document.getElementById("overlayNewsletter").style.display = "none";
	
}
/*==================== END SEND NEWSLETTER SUBSCRIBER ========================*/
/*==================== START SEND PDF FILES ========================*/
function SendPdfFile()
{
//	document.getElementById("slt").style.color = "#000000";
//	document.getElementById("slt").innerHTML = promo;	

//	document.getElementById("lbname_sb").style.color = '#000000';
//	document.getElementById("lbemail_sb").style.color = '#000000';
//	document.getElementById("lbcompany_sb").style.color = '#000000';
	var params = "id=0&name="+document.getElementById("name_sb").value;
	params += "&company="+document.getElementById("cname_sb").value;
	params += "&country="+document.getElementById("country_sb").value;
	params += "&email="+document.getElementById("email_sb").value;
	params += "&phone="+document.getElementById("phone_sb").value;
	if( document.getElementById("enquire_company_name") && document.getElementById("enquire_company_name").value == 0 ) params += "&disableCname=1";
	params += "&pdf="+PDF;
	params += "&pdf_type="+PDFType;
	params += "&action=PDFSend";
	
	if( document.getElementById("newsletter_sb") ) params += "&newsletter=" + ( document.getElementById("newsletter_sb").checked ? '1' : '0' );
	
	sSendMethod = 'POST';
	Run(params,"afterSendPdfFile");
}

function afterSendPdfFile()
{	
	document.getElementById("slt_sb").style.display = "";
	if( 0 == iErrors)	
	{
		var mess = '<h4>The PDF has been emailed to you</h4><br/>';
		
		document.getElementById('name_sb').value = "";
		document.getElementById('cname_sb').value = "";
		document.getElementById('country_sb').value = "";
		document.getElementById('email_sb').value = "";
		document.getElementById('phone_sb').value = "";
		document.getElementById("slt_sb").style.color = "#000000";
		document.getElementById("slt_sb").innerHTML = mess;
		setTimeout('preparePDFFile()',2000);
	}
	else
	{
		document.getElementById("slt_sb").style.color = "#990000";
		document.getElementById( "slt_sb" ).innerHTML = sText+"<br><br>";		
	}
}

function preparePDFFile()
{		
	document.getElementById("slt_sb").style.color = "#000000";
	document.getElementById("slt_sb").innerHTML = '';	
	document.getElementById("overlayNewsletter").style.display = "none";
	
}
/*==================== END SEND PDF FILES ========================*/

