function ft(xUrl,xform,campo1,campo2) {
var xform=xform
var c1=campo1
var c2=campo2
if (document.getElementById(xform).ft.value=="no" && document.getElementById(c2).value!="")  {
					  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();
					  }
				xUrl=xUrl + '?n=1'
				   for (i = 0; i < document.getElementById(xform).elements.length; i++){
						xUrl=xUrl + '&' + document.getElementById(xform).elements[i].name + '=' + document.getElementById(xform).elements[i].value
					}
					  xmlhttp.open("GET", xUrl,true);
					  xmlhttp.send(null)
}
}

function okmasterd(){
if (document.formu.nombre.value=="" || document.formu.apellidos.value=="" || document.formu.email.value=="" || document.formu.pais.value=="" || document.formu.direccion.value=="" || document.formu.poblacion.value=="" || document.formu.provincia.value=="" || document.formu.tel.value=="" || document.formu.cp.value=="" || document.formu.edad.value=="" || document.formu.estudios.value=="") {
	alert('Por favor, rellene todos los campos correctamente');
	return false;
	}
if (isNaN(document.formu.tel.value))  {
		alert ('El teléfono debe tener SOLO números sin espacios ni otros caracteres que no sean números');
		document.formu.tel.focus();
		return false;
		}
var vv=document.formu.tel.value.substr(0,1);
var vvv=document.formu.tel.value;

if (document.formu.provincia.value!="Fuera de España")	{
		if (document.formu.tel.value.length!=9 ) {
			alert ('El teléfono debe tener 9 cifras sin espacios ni otros caracteres que no sean números');
			document.formu.tel.focus();
			return false;
			}
		if (vv!=9 && vv!=6 && vv!=8 ) {
				alert ('El teléfono NO es correcto. No es un teléfono de España');
				document.formu.tel.focus();
				return false;
				}
		if (isNaN(document.formu.cp.value) || document.formu.cp.value.length!=5)  {
				alert ('El Código Postal NO es correcto. No es un c.p. de España');
				document.formu.cp.focus();
				return false;
				}
}
if (vvv==000000000 || vvv==999999999 || vvv==666666666 || vvv==888888888 ) {
	alert ('El teléfono NO es correcto');
	document.formu.tel.focus();
	return false;
	}


if (document.formu.direccion.value=="" ) {
			alert ('El campo dirección no es correcto');
			document.formu.direccion.focus();
			return false;
			}	

texto=document.formu.email.value
   var mailres = true; 
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
    var arroba = texto.indexOf("@",0); 
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
    var punto = texto.lastIndexOf("."); 
 
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
     mailres = true; 
    else 
     mailres = false; 
  
    if (mailres==false) {
			alert('La dirección de email es errónea. Comprueba que está escrita correctamente y sin espacios');
			 return false; 
			 }
document.formu.ft.value="si";
return true;
}
function Left(s, n){
// Devuelve los n primeros caracteres de la cadena
	if(n>s.length)
		n=s.length;					
		return s.substring(0, n);
}					
function UCase(s){
// Devuelve la cadena convertida a mayúsculas
	return s.toUpperCase();
}				
function InStr(n, s1, s2){
	// Devuelve la posición de la primera ocurrencia de s2 en s1
	// Si se especifica n, se empezará a comprobar desde esa posición
	// Sino se especifica, los dos parámetros serán las cadenas
	var numargs=InStr.arguments.length;					
	if(numargs<3)
		return n.indexOf(s1)+1;
	else
		return s1.indexOf(s2, n)+1;
}						
function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) 
			break; 
		}
	return null;
}
function cargadatos(){
		if (GetCookie("nombre")!=null) {
			var re =new RegExp("\\+","g");
			if (GetCookie("nombre")!=null) {
					document.formu.nombre.value=GetCookie("nombre").replace(re," ");
					document.getElementById("nombre").style.backgroundColor = "#FFFFCC";
			}
			if (GetCookie("apellidos")!=null) {
				document.formu.apellidos.value=GetCookie("apellidos").replace(re," ");
				document.getElementById("apellidos").style.backgroundColor = "#FFFFCC";
				if (InStr(UCase(GetCookie("nombre")), UCase(GetCookie("apellidos")))!=0) {
					document.formu.nombre.value=Left(GetCookie("nombre").replace(re," "),InStr(UCase(GetCookie("nombre")), UCase(GetCookie("apellidos")))-1)
				}									
			}
			if (GetCookie("telefono")!=null) {
				document.formu.tel.value=GetCookie("telefono").replace(re," ");
				document.getElementById("tel").style.backgroundColor = "#FFFFCC";
			}
			if (GetCookie("direccion")!=null) {	
				document.formu.direccion.value=GetCookie("direccion").replace(re," ");
				document.getElementById("direccion").style.backgroundColor = "#FFFFCC";
			}
			if (GetCookie("numero")!=null) {
				if (InStr(UCase(GetCookie("direccion")), UCase(GetCookie("numero")))==0) {
					document.formu.direccion.value+=' '+GetCookie("numero").replace(re," ");
				}																												
//no hay num. lo añadimos a direccion
			}	
			if (GetCookie("piso")!=null) {
				if (InStr(UCase(GetCookie("direccion")), UCase(GetCookie("piso")))==0) {
					document.formu.direccion.value+=' '+GetCookie("piso").replace(re," ");
				}																																					
//no hay piso asi que si hay lo añadimos a direccion
			}
			if (GetCookie("puerta")!=null) {
				if (InStr(UCase(GetCookie("direccion")), UCase(GetCookie("puerta")))==0) {
					document.formu.direccion.value+=' '+GetCookie("puerta").replace(re," ");
				}																																					
//no hay puerta asi que si hay lo añadimos a direccion
			}																			
			if (GetCookie("poblacion")!=null) {				
				document.formu.poblacion.value=GetCookie("poblacion").replace(re," ");
				document.getElementById("poblacion").style.backgroundColor = "#FFFFCC";		
			}
			if (GetCookie("provincia")!=null) {
				var newElem = document.createElement("option");
				pro=GetCookie("provincia").replace(re," ")
				newElem.text = pro;
				newElem.value = pro;
				document.formu.provincia.options.add(newElem,0);
				document.formu.provincia.options[0].selected=true;
				document.getElementById("provincia").style.backgroundColor = "#FFFFCC";	
			}			
			if (GetCookie("amail")!=null) {
				document.formu.email.value=GetCookie("amail");
				document.getElementById("email").style.backgroundColor = "#FFFFCC";	
			}
			if (GetCookie("cp")!=null) {
				document.formu.cp.value=GetCookie("cp");
				document.getElementById("cp").style.backgroundColor = "#FFFFCC";	
			}
			if (GetCookie("pais")!=null) {
				document.formu.pais.value=GetCookie("pais");
				document.getElementById("pais").style.backgroundColor = "#FFFFCC";	
			}			
		}
}

