// JavaScript Document
function objectAjax()
	{
	var xmlhttp=false;
	try 
		{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
	catch (e) 
		{
		try 
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
		catch (E) 
			{
			xmlhttp = false;
			}
		}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
		{
  		xmlhttp = new XMLHttpRequest();
  		}
  	return xmlhttp;
  	}
function isMail(texto)
	{ 
	var mailres = true;             
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
	 
	var arroba = texto.indexOf("@",0); 
	if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
	 
	var punto = texto.lastIndexOf("."); 
				 
	for (var contador = 0 ; contador < texto.length ; contador++)
		{ 
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1)
			{ 
			mailres = false; 
			break; 
		 	} 
		} 	
	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 2 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
		 mailres = true; 
	else 
		 mailres = false; 
	return mailres; 
	} 
function restoreNew(a)
{
 if (document.getElementById(a).className=='req')
 {
	 $("#div"+a).hide();
	 $("#"+a+'2').hide();
	 document.getElementById(a).className='inputB';
 }
}
function validateForm()
{
	sw0=true;
	sw1=true;
	sw2=true;
	//is_validate (e, valType, nameClass, nameClassError, isRequired, msgRequired, msgErrorType)
	sw0 = is_validate('ct_name', 'text', 'input', 'inputError', true, 'Campo requerido', 'Solo texto');
	if (sw0==false)
	{
	document.getElementById('ct_name').className='req';
	$('#ct_name2').show();
	}
	sw1 = is_validate('ct_mail', 'email', 'input', 'inputError', true, 'Campo requerido', 'Solo E-mail');
	if (sw1==false)
	{
	document.getElementById('ct_mail').className='req';
	$('#ct_mail2').show();
	}
	if ((sw0==true) && (sw1==true) && (sw2==true))
	{
		var sendmail = document.getElementById("sendMail");
		var ct_name = document.getElementById('ct_name');
		var ct_mail = document.getElementById('ct_mail');
		var ct_query = document.getElementById('ct_query');
		var ct_country = document.getElementById('ct_country');
		var ct_city = document.getElementById('ct_city');
		var domain = document.getElementById('domain');
		ct_names=ct_name.value;
		ct_mails=ct_mail.value;
		ct_city=ct_city.value;
		ct_country=ct_country.value;
		ct_querys=ct_query.value;
		
		//document.getElementById('hOk').value='ok';
		sendmail.innerHTML= '<br /><span class="subtitle2">Enviando su consulta/Sending your message....</span>';
		//instanciamos el objetoAjax
		ajax=objectAjax();
		//uso del medotod POST
		//alert (domain.value + "/skin/contactSend.php");
		ajax.open("POST",domain.value + "/skin/contactSend.php",true);
		
		ajax.onreadystatechange=function() {
										  if (ajax.readyState==4) 
											{
											//mostrar resultados en esta capa
											//document.location.href=domain.value + '/contactenos/';
											sendmail.innerHTML = ajax.responseText;
											//
											}
										}  
		ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//enviando los valores
		ajax.send("ct_name="+ct_names+"&ct_mail="+ct_mails+"&ct_query="+ct_querys+"&ct_city="+ct_city+"&ct_country="+ct_country)
	}else
	{
		document.getElementById('hOk').value='';
	}
 
}
