
function valida_alta() {
	error = "";
	if (document.foDatos.p_sex.value =="") error += "Introduzca el tratamiento.\n";
	if (document.foDatos.p_nom.value =="") error += "Introduzca su nombre.\n";
	if (document.foDatos.p_ape1.value =="") error += "Introduzca su apellido.\n";
	if (document.foDatos.p_docide.value =="") error += "Introduzca el nº de identificación.\n";
	if (document.foDatos.p_tipdocide.value =="") error += "Introduzca el tipo de documento identificativo.\n";
	if (document.foDatos.p_codpaidocide.value =="") error += "Seleccione el país de expedición.\n";
    //if (document.foDatos.p_codidi.value =="") error += "Seleccione el idioma preferido.\n";
	if (document.foDatos.p_ema.value =="") error += "Introduzca su E-mail.\n";
	
	else {
		pos_arroba  = document.foDatos.p_ema.value.indexOf('@');
		if (pos_arroba ==-1) error += "Introduzca su E-mail correctamente.\n";
		}
	if (document.foDatos.p_pwdcta.value =="") error += "Introduzca una contraseña.\n";
	else {
		if (document.foDatos.p_pwdcta.value.length<6) error += "La contraseña como mínimo debe teber 8 caracteres.\n";
		if (document.foDatos.p_pwdcta.value != document.foDatos.p_pwdcon.value) error += "La contraseña no coincide.\n";
		}
	if (!document.foDatos.p_swipub.checked) error += "Debe leer las condiciones y acéptelas.\n";
	if (error!="") {alert(error);return (false);}
	if ((document.foDatos.p_fecnac.value!="")&&(document.foDatos.p_fecnac.value!="dd/mm/aaaa"))
	{
	  /*if(IsNumeric(document.foDatos.p_tlf.value)){ alert('Número de telefono, no puede tener caracteres.'); }
	  if(IsNumeric(document.foDatos.p_tlfmov.value)){ alert('Número de telefono movil, no puede tener caracteres.'); }	*/
	  if(document.foDatos.p_tlf.value.length > 15){ alert('Número de telefono invalido.'); }
	  if(document.foDatos.p_tlfmov.value.length > 15){ alert('Número de telefono movil invalido.'); }	
 	  if (!checkDate(document.foDatos.p_fecnac.value)) { alert('Fecha de nacimiento incorrecta (dd/mm/aaaa)'); return (false);}
	}
	else {document.foDatos.p_fecnac.value="";}
	
	if(document.foDatos.p_tlf.value.length > 15)
	{
		alert('Número de telefono invalido');
		return(false);
	}

	if(document.foDatos.p_tlfmov.value.length > 15)
	{
		alert('Número de telefono movil invalido');
		return(false);
	}
	return true;
	}


function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) { 
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1) IsNumber = false;
      }
   return IsNumber;
   }

meses = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
function checkDate(lafecha) {
	var fecha = new String(lafecha);
	cad2=fecha.split('/');
	if (cad2.length!=3)  return false;
	if (!IsNumeric(cad2[0])||!IsNumeric(cad2[1])||!IsNumeric(cad2[2])) return false;
	if (cad2[1]<1 || cad2[1]>12) return false;
	var myDateStr = cad2[0] + ' ' + meses[cad2[1]-1] + ' ' + cad2[2] +" 12:00:00";
	var myDate = new Date( myDateStr );
	var myDate_string = myDate.toGMTString();
	var myDate_array = myDate_string.split( ' ' );
	if ( myDate_array[2] != meses[cad2[1]-1] ) return false;
	else return true;
	}

function updatepais() {
	alert('paises');
	totalpais = paisos.length;
 	Refer1=eval("document.foDatos.p_codpaidocide");
 	Refer2=eval("document.foDatos.p_dircodpai");
	for (i2=0;i2<totalpais;i2++) {
   		Refer1.options[i2] = new Option(paisos[i2][0],paisos[i2][1]);
		if (i2) Refer2.options[i2] = new Option(paisos[i2][0],paisos[i2][1]);
	    }	
	}

//function updateprov() {
//	totalprovs = provincies.length;
// 	Refer1=eval("document.foDatos.p_dirprv");
//	for (i2=0;i2<totalprovs;i2++) {
//   		Refer1.options[i2+1] = new Option(provincies[i2][0],provincies[i2][1]);
//	    }	
//	}

function inicia() {
	alert('iniciamos');
	updatepais()
//	updateprov();
	}