// JavaScript Document
var xmlHttp
function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
///////////////////////////////////////////////////////////
function stateChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			//document.getElementById('resultado').innerHTML = "Cargando...";
			text_html = xmlHttp.responseText 
			//document.getElementById('fin_ventata_acceso')
			imagen = document.getElementById('fin_ventata_acceso_login');
			padre = imagen.parentNode;
			padre.removeChild(imagen);

			document.getElementById('content_login').innerHTML=text_html
	} 
} 
function abrirLogin(){	
	xmlHttp=GetXmlHttpObject()
	variables = "";
	if (xmlHttp==null)	{
		alert ("Tu navegador no soporta HTTP Request, es necesario para el funcionamiento de esta página")
		return
	} 	
	xmlHttp.onreadystatechange=stateChanged

	xmlHttp.open("POST","/pages/comun/login.php",true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(variables);
}
///////////////////////////////////////////////////////////
function stateChanged2(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			//document.getElementById('resultado').innerHTML = "Cargando...";
			text_html = xmlHttp.responseText 
			//document.getElementById('fin_ventata_acceso')
			imagen = document.getElementById('fin_ventata_acceso_news');
			padre = imagen.parentNode;
			padre.removeChild(imagen);

			document.getElementById('content_news').innerHTML=text_html
	} 
} 
function abrirNews(){	
	xmlHttp=GetXmlHttpObject()
	variables = "";
	if (xmlHttp==null)	{
		alert ("Tu navegador no soporta HTTP Request, es necesario para el funcionamiento de esta página")
		return
	} 	
	xmlHttp.onreadystatechange=stateChanged2

	xmlHttp.open("POST","/pages/comun/news.php",true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(variables);
}
function stateChanged3(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
			//document.getElementById('resultado').innerHTML = "Cargando...";
			text_html = xmlHttp.responseText 
			document.getElementById('emailAmigo_div').innerHTML=text_html
	} 
} 
function enviarAmigo(valor,paso){	
	xmlHttp=GetXmlHttpObject()
	variables = "datos_var="+valor+"&paso="+paso;
	if (xmlHttp==null)	{
		alert ("Tu navegador no soporta HTTP Request, es necesario para el funcionamiento de esta página")
		return
	} 	
	xmlHttp.onreadystatechange=stateChanged3;

	xmlHttp.open("POST","/pages/comun/enviarAmigo.php",true)
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(variables);
}

function enviarLogin(){
	if(document.getElementById('usuario_d').value == "" || document.getElementById('idGrupos_d').value == "" || document.getElementById('password_d').value == ""){
		alert("faltan campos por rellenar");
	} else if(isNaN(document.getElementById('idGrupos_d').value)){
		alert("el grupo es incorrecto");
	} else {
		document.login.idGrupos.value = document.getElementById('idGrupos_d').value;
		document.login.usuario.value = document.getElementById('usuario_d').value;
		document.login.password.value = document.getElementById('password_d').value;

		if(document.login.idGrupos.value < 5000){
			document.login.action = "https://secure.easymailing.es/front/inicio/inicio.php";
		}else{
			document.login.action = "https://s1.emsrv.es/front/inicio/inicio.php";
		}
		document.login.submit();
	}
	
}
function validaMail(mail){										
	var pos1, pos2, bOk = true;
	var sDir = mail;
	
	pos1 = sDir.indexOf('@', 0);
	pos2 = sDir.indexOf('.', pos1);
	bOk = bOk && (pos1 > 0);
	bOk = bOk && (pos2 != -1);
	bOk = bOk && (pos1 < pos2 - 1);
	bOk = bOk && (pos2 < sDir.length - 1);
	if (!bOk){
	 return false;
	}
	else{
		return true;
	}
  }
function validaEmailObj(obj){
	if(validaMail(obj)){
		return true	
	}
	else{
		alert('El email introducido no tiene el formato correcto');	
	}
}
function altaNews(){
	if(validaEmailObj(document.getElementById('email_d').value)){
	document.news_form.nombre.value = document.getElementById('nombre_d').value;
	document.news_form.apellidos.value = document.getElementById('apellidos_d').value;
	document.news_form.email.value = document.getElementById('email_d').value;
	document.news_form.action = "https://secure.easymailing.es/front/srvweb/nsrt_sus.php";
	document.news_form.submit();
	}
}
function favoritos(){
	window.external.addFavorite('http://www.easymailing.es','EasyMailing - Tu herramienta de e-mail marketing')
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

