//Crea un objeto Ajax
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;
}

//Consulta
function consulta(datos,destino){
	divResultado1 = document.getElementById(destino);
	ajax=objetoAjax();
	ajax.open("GET", datos);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divResultado1.innerHTML = ajax.responseText
		}
	}
	ajax.send(null)
}

function unsuscribe() {  
	var errores = "";
	if (!((document.getElementById('suscripcion').value.indexOf(".") > 2) && (document.getElementById('suscripcion').value.indexOf("@") > 0))){
		errores += "Direccion de email no valida.";
	
	}
	if (errores!=""){
		alert(errores);
	} else {
		var email = document.getElementById('suscripcion').value;
		document.getElementById('suscripcion_form').innerHTML='<img src="img/interface/load_news.gif" width="220" height="19">';

		consulta('newsletter/unsuscribe_ajax.php?mail='+email,'suscripcion_form');
		document.getElementById('suscripcion').value='';
	}
}

function suscribe() {
	var errores = "";
	if (!((document.getElementById('suscripcion').value.indexOf(".") > 2) && (document.getElementById('suscripcion').value.indexOf("@") > 0))){
		errores += "Direccion de email no valida.";
	
	}
	if (errores!=""){
		alert(errores);
	} else {
		var email = document.getElementById('suscripcion').value;
		document.getElementById('suscripcion_form').innerHTML='<img src="img/interface/load_news.gif" width="220" height="19">';

		consulta('newsletter/suscribe_ajax.php?mail='+email,'suscripcion_form');
		document.getElementById('suscripcion').value='';
	}
}
