
var XmlHttpObj = null;
var OKCODE = "%OK_CODE%";

function CreateAjaxXmlHttpObjContactUS()
{
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
		if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}

function resetFormContactUS()
{
		document.getElementById("name").className="account_text_field";
		document.getElementById("mail").className="account_text_field";
		document.getElementById("phone").className="account_text_field";
		document.getElementById("time").className="account_text_field";
		document.getElementById("code").className="account_text_field";
 	document.getElementById("type").className="account_text_field";
		document.getElementById("order").className="account_text_field";		
		document.getElementById("enquiry").className="textarea_general";
}

function validateFormContacUS()
{
  resetFormContactUS();
		var name = document.getElementById('name');
	 var mail = document.getElementById('mail');
		var phone = document.getElementById("phone");
		var time = document.getElementById("time");
		var code = document.getElementById("code");
		var type = document.getElementById("type");
		var order = document.getElementById("order");
		var enquiry = document.getElementById("enquiry");
		
  var timeValue = time.options[time.selectedIndex].value;
		var typeValue = type.options[type.selectedIndex].value;
		
		var message="<img src='./images/skins/Pink_v_2_0/validator/loading.gif' alt='Enviando'><br><span class='text'><b>Validando Datos. Por favor espere.</b></span><br><br>";

		showMessageTransSmall(message);
		
		CreateAjaxXmlHttpObjContactUS();
		
		var url = '&name='+encodeURIComponent(name.value)+'&mail='+encodeURIComponent(mail.value)+'&phone='+encodeURIComponent(phone.value)+'&time='+encodeURIComponent(timeValue)+'&enquiry='+encodeURIComponent(enquiry.value)+'&code='+encodeURIComponent(code.value)+'&type='+encodeURIComponent(typeValue)+'&order='+encodeURIComponent(order.value);
		
		var request = lang + '/contact_us.php?action=send'+ url;
		
		
		XmlHttpObj.open("GET", request, true);
		XmlHttpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		XmlHttpObj.send(null);
		XmlHttpObj.onreadystatechange=function()
		{
			if (XmlHttpObj.readyState==4)
			{
				var response=XmlHttpObj.responseText;
											
				if( response!= "" && response.indexOf(OKCODE) != -1)
				{
						location.href= lang+"/contact_us.php?action=success";
						return;
				}
				else
				{
					refreshCodeGeneral();
					checkResponse(response);
	 	  text = 'Error al procesar la peticion:';
 		  if (language == 'portugal') text = 'Erro ao processar:';			     
					var message="<table id='table_message' border='0' cellspacing='5' cellpadding='0'><tr><td align='center'><table border='0' cellspacing='5' cellpadding='0'><tr><td align='right'><img src='./images/skins/Pink_v_2_0/validator/error.jpg' alt='Error' /></td><td align='left' class='text'><b>"+text+"</b></td></tr></table></td></tr><tr><td align='center' class='text'>"+response+"</td></tr><tr><td align='center' style='padding-top:10px;'><a href='javascript:hideMessage();'><img src='./images/skins/Pink_v_2_0/buttons/button_continue_OFF.jpg' border='0' alt='Continuar' /></a></td></tr></table>";

					showMessageTransSmall(message);
					
				}
			}
		}
}

function checkResponse(response)
{
		if (response.indexOf('name="name_hidden_field"') != -1) document.getElementById("name").className="fieldError";
		if (response.indexOf('name="phone_hidden_field"') != -1) document.getElementById("phone").className="fieldError";
		if (response.indexOf('name="mail_hidden_field"') != -1) document.getElementById("mail").className="fieldError";
		if (response.indexOf('name="enquiry_hidden_field"') != -1) document.getElementById("enquiry").className="fieldError";
		if (response.indexOf('name="code_hidden_field"') != -1) document.getElementById("code").className="fieldError";
 	if (response.indexOf('name="type_hidden_field"') != -1) document.getElementById("type").className="fieldError";
		if (response.indexOf('name="order_hidden_field"') != -1) document.getElementById("order").className="fieldError";
}

function refreshCodeGeneral()
{
	document.getElementById('img_captcha').src = "./captcha.php?"+Math.random()+"="+Math.random();
	document.getElementById("code").value = "";
}

function checkType(combo)
{
	 if (combo.options[combo.selectedIndex].value == 2)
		{
			 document.getElementById("order_div").style.visibility = "visible";
				document.getElementById("order_input_div").style.visibility = "visible";
		}
		else
		{
			 document.getElementById("order_div").style.visibility = "hidden";
				document.getElementById("order_input_div").style.visibility = "hidden";
		}
}