// JavaScript Document
function objetoAjax(){
	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 valida_correo(valor) {
	if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(valor)) {
		return (true)
	}
	else {
		return (false);
	}
}

function validarcorreo(){
	if (document.frmcontacto.nombres.value.replace(/(^\s*)|(\s*$)/g,"").length == 0) 	
	{
	document.frmcontacto.nombres.focus();
	document.getElementById("mensaje_correo").innerHTML='Ingrese sus Nombres';
	return false;
	}
	else
	{
		if (!valida_correo(document.frmcontacto.correo.value)) 
	 	{
		document.frmcontacto.correo.focus();
		document.getElementById("mensaje_correo").innerHTML='Correo Invalido';
	 	return false;
		}
		else
		{
			if (document.frmcontacto.mensaje.value.replace(/(^\s*)|(\s*$)/g,"").length == 0) 	
			{
			document.frmcontacto.mensaje.focus();
			document.getElementById("mensaje_correo").innerHTML='Ingrese su Mensaje';
			return false;
			}	
			else
			{
				/*alert ('ok');*/
				/*return false;*/
				enviarcorreo();
				
			}
		}
		
	}
}

function validarcorreor(){
	if (document.frmreservas.nombresr.value.replace(/(^\s*)|(\s*$)/g,"").length == 0) 	
	{
	document.frmreservas.nombresr.focus();
	document.getElementById("mensaje_correor").innerHTML='Ingrese sus Nombres';
	return false;
	}
	else
	{
		if (!valida_correo(document.frmreservas.correor.value)) 
	 	{
		document.frmreservas.correor.focus();
		document.getElementById("mensaje_correor").innerHTML='Correo Invalido';
	 	return false;
		}
		else
		{
			if (document.frmreservas.datepicker.value.replace(/(^\s*)|(\s*$)/g,"").length == 0) 
			{
			document.frmreservas.datepicker.focus();
			document.getElementById("mensaje_correor").innerHTML='Seleccione una fecha de reserva';
			return false;
			}
			else
			{
				if (document.frmreservas.mensajer.value.replace(/(^\s*)|(\s*$)/g,"").length == 0) 	
				{
				document.frmreservas.mensajer.focus();
				document.getElementById("mensaje_correor").innerHTML='Ingrese su Mensaje';
				return false;
				}	
				else
				{
					/*alert ('ok');*/
					/*return false;*/
					enviarcorreor();
					
				}
			}
		}
		
	}
}


function enviarcorreo() {
	divResultado = document.getElementById('mensaje_correo');
	divResultado.innerHTML = '<div><img src="images/loading2.gif"></img></div>';
	nombres=document.getElementById('nombres').value;
	correo=document.getElementById('correo').value;
	mensaje=document.getElementById('mensaje').value;
	//divResultado.value = '';
	//f_i = document.getElementById('finicio').value;
	//f_v = document.getElementById('ffin').value;
	ajax=objetoAjax();
	ajax.open("POST", "enviarcorreo.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			divResultado.innerHTML = ajax.responseText
			//ActualizarCuerpoBoletin(idboletin);
			//divResultado.value = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("nombres="+nombres+"&correo="+correo+"&mensaje="+mensaje);
	return false;
}

function enviarcorreor() {
	divResultado = document.getElementById('mensaje_correor');
	divResultado.innerHTML = '<div><img src="images/loading2.gif"></img></div>';
	nombres=document.getElementById('nombresr').value;
	correo=document.getElementById('correor').value;
	mensaje=document.getElementById('mensajer').value;
	fecha=document.getElementById('datepicker').value;
	//divResultado.value = '';
	//f_i = document.getElementById('finicio').value;
	//f_v = document.getElementById('ffin').value;
	ajax=objetoAjax();
	ajax.open("POST", "enviarcorreor.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			//mostrar resultados en esta capa
			divResultado.innerHTML = ajax.responseText
			//ActualizarCuerpoBoletin(idboletin);
			//divResultado.value = ajax.responseText
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//enviando los valores
	ajax.send("nombres="+nombres+"&correo="+correo+"&mensaje="+mensaje+"&fecha="+fecha);
	return false;
}
