// JavaScript Document
var xmlHttpAltaMail;
var xmlHttpPassword;
function altaMail(elMail, tipo)
{	
		
		xmlHttpAltaMail=null;
		if (window.XMLHttpRequest){// code for IE7, Firefox, Mozilla, etc.
			xmlHttpAltaMail=new XMLHttpRequest();
		}else if (window.ActiveXObject){// code for IE5, IE6
			xmlHttpAltaMail=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if (xmlHttpAltaMail!=null){
			email=elMail;
			//actividad=document.getElementById("selectorActividad").value;
			
			var params = "email=" + email + "&tipo=" + tipo;

			
			xmlHttpAltaMail.onreadystatechange=onResponseAlta;
			xmlHttpAltaMail.open("POST","grabarMail.asp",true);
			xmlHttpAltaMail.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
			//xmlHttpAltaMail.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
			xmlHttpAltaMail.send(params);
		}else{
			alert("Su navegador no soporta XMLHTTP.");
		}
	
}

function onResponseAlta(){
	
	//alert("ALTA");
	if(xmlHttpAltaMail.readyState!=4) return;
	if(xmlHttpAltaMail.status!=200){
  		alert("Error al dar de Alta. Verifique los datos." + " status:" + xmlHttpAltaMail.status  );
  		return;
 	}
	
	x=xmlHttpAltaMail.responseXML.documentElement.getElementsByTagName("DATOS");
	for (i=0;i<x.length;i++){
			  xx=x[i].getElementsByTagName("sms");
			   {
			   try
				{
				  document.getElementById("ajax").style.display='none';
				   document.getElementById("ajaxF").style.display='none';
				 
				  //document.getElementById("divAltaCliente").style.display='none';
				//  ocultarDIV();
				}
				catch (er){
				  }
				}
			
		
		}

}


function comprobarPassword()
{
		
		xmlHttpPassword=null;
		if (window.XMLHttpRequest){// code for IE7, Firefox, Mozilla, etc.
			xmlHttpPassword=new XMLHttpRequest();
		}else if (window.ActiveXObject){// code for IE5, IE6
			xmlHttpPassword=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if (xmlHttpPassword!=null){
			
			login=document.getElementById("login").value;
			password=document.getElementById("password").value;
			
			var params = "login=" + login + "&password=" + password;

			
			xmlHttpPassword.onreadystatechange=onResponsePassword;
			xmlHttpPassword.open("POST","comprobarPassword.asp",true);
			xmlHttpPassword.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
			//xmlHttpPassword.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
			xmlHttpPassword.send(params);
		}else{
			alert("Su navegador no soporta XMLHTTP.");
		}
	
}

function onResponsePassword(){
	if(xmlHttpPassword.readyState!=4) return;
	if(xmlHttpPassword.status!=200){
  		alert("Error al dar de Alta. Verifique los datos." + " status:" + xmlHttpPassword.status  );
  		return;
 	}
	x=xmlHttpPassword.responseXML.documentElement.getElementsByTagName("DATOS");
	for (i=0;i<x.length;i++){
			  xx=x[i].getElementsByTagName("sms");
			   {
			   try
				{
				  //document.getElementById("ajax").style.display='none';
				   //alert(xx[0].firstChild.nodeValue)
				   if(xx[0].firstChild.nodeValue=="existe"){
					 alert("Ya existe un usuario con la misma contraseña, cámbiela")
				}else{
					validar2();
					}
				  //document.getElementById("divAltaCliente").style.display='none';
				//  ocultarDIV();
				
				}
				catch (er){
				  }
				}
			
		
		}

}




function validarNewsletter(tipo){
	if (tipo=="news"){
		var of = document.getElementById("formNews")
		var mail = document.getElementById("formNews").email
	}else if(tipo=="formacion"){
		var of = document.getElementById("formF")
		var mail = document.getElementById("formF").emailF
	}
	
	var elMail = mail.value;
	
	if(mail.value.length<1){
		alert("Indíquenos su e-mail");
		return(false);
	}
	
	var z= mail.value.indexOf("@")
	var y= mail.value.lastIndexOf(".")
	var x = mail.value.length
	if(mail.value.length>0){
		var z= mail.value.indexOf("@")
		var y= mail.value.lastIndexOf(".")
		if(z<1 || y<5){
			alert ("La direccion de correo electronico no es correcta")
			mail.focus();
		return (false);
		}
	}
	
	if(y==(z+1)){
		alert ("La direccion de correo electronico no es correcta")
		mail.focus();
		return (false);   
	}
	
	if(y<z){
		alert ("La direccion de correo electronico no es correcta")
		mail.focus();
		return (false);   
	}
	
	if(y==(x-1)){
		alert ("La direccion de correo electronico no es correcta")
		mail.focus();
		return (false);   
	}
	
	/*
	if(of.selectorActividad.value=="0"){
		alert("Indíquenos su sector de actividad");
		return(false);
	}
	*/
	if (tipo=="news"){
		document.getElementById("ajax").style.display = "block";
	}else if(tipo=="formacion"){
		document.getElementById("ajaxF").style.display = "block";
	}
	
	altaMail(elMail, tipo)
}


function extranet(){
	window.open("https://extranet.temper.es/")	
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
} 

function cargaCSS(){
	var archivos = document.getElementsByTagName("link");
	if(archivos.length==0){
		//No hay carga de css --> No debemos cargar las imágenes del banner
		document.getElementById("banners").innerHTML = ""
	}
}

function irProductos(){
	var valor = document.getElementById("buscador_producto").value
	switch (valor){
		case "industrial":
			window.location = "familias.asp?q=industrial";
			break;
		case "infraestructuras":
			window.location = "familias.asp?q=infraestructuras";
			break;
		case "energia":
			window.location = "familias.asp?q=energia";
			break;
		case "climatizacion":
			window.location = "familias.asp?q=climatizacion";
			break;
		case "instrumentacion":
			window.location = "familias.asp?q=instrumentacion";
			break;
		case "control":
			window.location = "familias.asp?q=control";
			break;
	}
}
window.onload=function(){
	externalLinks();
	cargaCSS();
	}


