/************************AJAX****************************************/
function nuevoAjax(){ 
	var xmlhttp=false; 
	try 
	{ 
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); for (var i=0; i<x; i++) {
	
};
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 
	return xmlhttp; 
}
window.addEvent('domready', function() {
/*******************ALERTAS*********************************************/		
	/* Declara Variable para alertas */
	var Sexy = new SexyAlertBox({
	  OverlayStyles:{
	    'background-color': '#000',
	    'opacity': 0.7
	  }
	});
	$('english').addEvent('click', function(coming){
		Sexy.alert('<span class=titulo_alerta>¡Coming Soon!</span>¡Quarto Útil English Version!');
	})
/*******************RECOMENDAR*********************************************/	
	$('recomienda').addEvent('click', function(validador){
		var nombre = $('nombre_recomienda').value;
		nombre = nombre.replace(/(^\s*)|(\s*$)/g,"");
		var amigo = $('amigo_recomienda').value;
		amigo = amigo.replace(/(^\s*)|(\s*$)/g,"");
		var email = $('email_recomienda').value;
		email = email.replace(/(^\s*)|(\s*$)/g,"");
		if(nombre == ""){
    		Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>Por favor digita tu nombre para recomendar este sitio');
			return;
		}
		if(amigo == ""){
    		Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>Por favor digita a quien quieres recomendar nuestro sitio');
			return;
		}
		if(email == ""){
    		Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>Por favor digita el correo de la persona a quien le recomendarás nuestro sitio');
			return;
		}else{
			var filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filtro.test($('email_recomienda').value)){
				Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>Por favor rectifica el correo electrónico');
				return;
			}
		}
		var ajax=nuevoAjax();
		ajax.open("POST", "functions/recomendar.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("nombre="+nombre+"&amigo="+amigo+"&email="+email);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>¡Gracias por recomendar nuestro sitio!');
			}
		}		
	})
/*******************SUSCRIBIRSE*********************************************/		
	$('suscribe').addEvent('click', function(validador){
		var nombre = $('nombre_suscribe').value;
		nombre = nombre.replace(/(^\s*)|(\s*$)/g,"");
		var email = $('email_suscribe').value;
		email = email.replace(/(^\s*)|(\s*$)/g,"");
		if(nombre == ""){
    		Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>Por favor digita tu nombre completo para poder suscribirte');
			return;
		}
		if(email == ""){
    		Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>Por favor digita tu correo electrónico para completar tu suscripción');
			return;
		}else{
			var filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filtro.test($('email_suscribe').value)){
				Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>Por favor rectifica tu correo electrónico');
				return;
			}
		}
		var ajax=nuevoAjax();
		ajax.open("POST", "functions/suscribe.php", true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send("nombre="+nombre+"&email="+email);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				Sexy.alert('<span class=titulo_alerta>Quarto Útil</span>¡Gracias por suscribirte a nuestro boletín!');
			}
		}		
	})
});