// Form validation scripts

function deSelecciona() {
for (i=0; i<document.form1.elements.length; i++) {
if (document.form1.elements[i].type=="checkbox")
document.form1.elements[i].checked=false;
}
}

function PreEnvioOferta(theForm) {
  if (theForm.FriendEmail.value == "") {
    alert("Por favor, introduce el email de tu amigo.");
    theForm.FriendEmail.focus();
    return (false);
  }
  if (theForm.SenderName.value == "") {
    alert("Por favor, introduce tu nombre.");
    theForm.SenderName.focus();
    return (false);
  }
  if (theForm.SenderEmail.value == "") {
    alert("Por favor, introduce tu email.");
    theForm.SenderEmail.focus();
    return (false);
  }
  theForm.enviar.value="si";
  return (true);
}


function ForgotForm_Validator(theForm)
{  
  if (theForm.UserName.value == "") {
    alert("Por favor, introduce tu email.");
    theForm.UserName.focus();
    return (false);
  }
  return (true);
}


//Login form validation
function LoginForm_Validator(theForm)
{  
  if (theForm.UserName.value == "")
  {
    alert("Por favor, introduzca su nombre de usuario.");
    theForm.UserName.focus();
    return (false);
  }
  
  if (theForm.Password.value == "")
  {
    alert("Por favor, introduzca su contrase\xf1a.");
    theForm.Password.focus();
    return (false);
  }
  
  return (true);
}


//Function(s) to validate add new job ad Form
function addJobad_Validator(theForm)
	{
		  
	  if (theForm.PositionTitle.value == "")
	  {
		alert("Por favor, introduzca el t\xedtulo del puesto.");
		theForm.PositionTitle.focus();
		return (false);
	  }
	  
	  return (true);
	}


//Function(s) to validate add new job ad Form
function addJobad_Validator2(theForm)
	{
	  if (theForm.PositionTitle.value == "") {
			alert("Por favor, introduzca el t\xedtulo del puesto.");
			theForm.PositionTitle.focus();
			return (false);
	  }
	  
	  if (theForm.pais[theForm.pais.selectedIndex].value == "") {
	   	alert("Es necesario rellenar el campo 'Pa\xeds'.");
	    theForm.pais.focus();
	    return (false);
	  }
	  
	  if (theForm.provincia[theForm.provincia.selectedIndex].value == "") {
	   	alert("Es necesario rellenar el campo 'Provincia'.");
	    theForm.provincia.focus();
	    return (false);
	  }

	  if (theForm.alerta_area[theForm.alerta_area.selectedIndex].value == "") {
	   	alert("Es necesario rellenar el campo '\xe1rea'.");
	    theForm.alerta_area.focus();
	    return (false);
	  }
	  
	  if (theForm.alerta_puesto[theForm.alerta_puesto.selectedIndex].value == "") {
	  	if (theForm.alerta_puesto.options.length > 1) {
		   	alert("Es necesario rellenar el campo 'Puesto'.");
		    theForm.alerta_puesto.focus();
		    return (false);
	  	}
	  }

	  if (theForm.formacion[theForm.formacion.selectedIndex].value == "") {
	   	alert("Es necesario rellenar el campo 'Formaci\xf3n'.");
	    theForm.formacion.focus();
	    return (false);
	  }

	  return (true);
	}

function addJobad_ChkNumeric(field, event, content, name){
	var checkOK = "0123456789";
	var checkStr = content;
	var allValid = true;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
	ch = checkStr.charAt(i);
	for (j = 0;  j < checkOK.length;  j++)
	if (ch == checkOK.charAt(j))
	break;
	if (j == checkOK.length)
	{
	allValid = false;
	break;
	}
	if (ch != ",")
	allNum += ch;
	}
	if (!allValid)
	{
		if (name == "MinExp"){
			alert("El campo \"Min. Yrs. Exp.\" s\xf3lo admite n\xfameros.");
			document.form1.MinExp.value="";
			document.form1.MinExp.focus();
		}
		if (name == "MaxExp"){
			alert("El campo \"Max. Yrs. Exp.\" s\xf3lo admite n\xfameros.");
			document.form1.MaxExp.value="";
			document.form1.MaxExp.focus();
		}
		if (name == "CPostalCode"){
			alert("El campo 'C\xf3digo Postal' ha de ser num\xe9rico.");
			document.form1.CPostalCode.value="";
			document.form1.CPostalCode.focus();
		}			
		if (name == "CPhonePre"){
			alert("El campo 'Prefijo del Tel\xe9fono' ha de ser num\xe9rico.");
			document.form1.CPhonePre.value="";
			document.form1.CPhonePre.focus();
		}
		if (name == "CPhone"){
			alert("El campo 'N\xe9mero de Tel\xe9fono' ha de ser num\xe9rico.");
			document.form1.CPhone.value="";
			document.form1.CPhone.focus();
		}
		if (name == "CMobilePre"){
			alert("El campo 'Prefijo del M\xf3vil' ha de ser num\xe9rico.");
			document.form1.CMobilePre.value="";
			document.form1.CMobilePre.focus();
		}
		if (name == "CMobile"){
			alert("El campo 'N\xe9mero de M\xf3vil' ha de ser num\xe9rico.");
			document.form1.CMobile.value="";
			document.form1.CMobile.focus();
		}
	return (false);
	}
}


function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
	
	
	function inicializar_forma_Espec() {
		var ctl = document.getElementById("pest_forma_espec");
		if(ctl!=null) {
			ctl.href = "/ajax_forma_especializacion.asp?id=0&areaID=0&espID=0";
			var especializacion = new ddajaxtabs("forma_espec_tabs", "forma_espec_divcontainer")
			especializacion.setpersist(true)
			especializacion.setselectedClassTarget("link") //"link" or "linkparent"
			especializacion.init()
		}
	}


	function cambiar_forma_Areas(caja, sel) {
		var valor = caja[caja.selectedIndex].value;
		var ctl = document.getElementById("pest_forma_areas");
		ctl.href = "/ajax_forma_areas.asp?id=" + valor + "&sel=" +  sel;
		var areas = new ddajaxtabs("forma_areas_tabs", "forma_areas_divcontainer")
		areas.setpersist(true)
		areas.setselectedClassTarget("link") //"link" or "linkparent"
		areas.init()
	}
	
	
	function cambiar_forma_Espec(caja, sel1, sel2) {
		var valor = caja[caja.selectedIndex].value;
		var ctl = document.getElementById("pest_forma_espec");
		if(ctl!=null) {
			ctl.href = "/ajax_forma_especializacion.asp?id=" + sel1 + "&areaID=" +  valor + "&espID=" +  sel2;
			var especializacion = new ddajaxtabs("forma_espec_tabs", "forma_espec_divcontainer")
			especializacion.setpersist(true)
			especializacion.setselectedClassTarget("link") //"link" or "linkparent"
			especializacion.init()
		}
	}
	
	
	function cambiar_Categ_Puestos(caja, sel) {
		var valor = caja[caja.selectedIndex].value;
		var ctl = document.getElementById("pest_categ_puestos");
		ctl.href = "/ajax_categ_puestos.asp?id=" + valor + "&sel=" +  sel;
		var puestos = new ddajaxtabs("categ_puestos_tabs", "categ_puestos_divcontainer")
		puestos.setpersist(true)
		puestos.setselectedClassTarget("link") //"link" or "linkparent"
		puestos.init()
	}


	function cambiar_Provincias(caja, sel) {
		var valor = caja[caja.selectedIndex].value;
		if(valor=="0") valor="";
		if(valor!="59" && valor!="") valor="0";
		var ctl = document.getElementById("pest_provincia");
		ctl.href = "/ajax_provincias.asp?id=" + valor + "&sel=" +  sel;
		var provincia = new ddajaxtabs("provincia_tabs", "provincia_divcontainer")
		provincia.setpersist(true)
		provincia.setselectedClassTarget("link") //"link" or "linkparent"
		provincia.init()
		cambiar_Localidades(document.getElementById("localidad"), "");
		var ctl2 = document.getElementById("CPostalCode");
		var ctl3 = document.getElementById("antiguoCP");
		if(ctl2!=null) ctl2.value = "";
		if(ctl3!=null) ctl3.value = "";
	}

	
	function cambiar_Localidades(caja, sel, cambioCP) {
		var valor = caja[caja.selectedIndex].value;
		var ctl = document.getElementById("pest_localidad");
		ctl.href = "/ajax_localidades.asp?id=" + valor + "&sel=" +  sel;
		var localidad = new ddajaxtabs("localidad_tabs", "localidad_divcontainer")
		localidad.setpersist(true)
		localidad.setselectedClassTarget("link") //"link" or "linkparent"
		localidad.init();
		if(cambioCP==true) {
		}
	}


	function cambiar_AlertaProvincias(caja, sel) {
		var valor = caja[caja.selectedIndex].value;
		if(valor=="0") valor="";
		if(valor!="59" && valor!="") valor="0";
		var ctl = document.getElementById("pest_alerta_provincia");
		ctl.href = "/ajax_alerta_provincias.asp?id=" + valor + "&sel=" +  sel;
		var alerta_provincia = new ddajaxtabs("alerta_provincia_tabs", "alerta_provincia_divcontainer")
		alerta_provincia.setpersist(true)
		alerta_provincia.setselectedClassTarget("link") //"link" or "linkparent"
		alerta_provincia.init()
		cambiar_AlertaLocalidades(document.getElementById("alerta_localidad"), "");
		var ctl2 = document.getElementById("CPostalCode");
		if(ctl2!=null) ctl2.value = "";
	}
	
	
	function cambiar_AlertaLocalidades(caja, sel) {
		var valor = caja[caja.selectedIndex].value;
		var ctl = document.getElementById("pest_alerta_localidad");
		ctl.href = "/ajax_alerta_localidades.asp?id=" + valor + "&sel=" +  sel;
		var alerta_localidad = new ddajaxtabs("alerta_localidad_tabs", "alerta_localidad_divcontainer")
		alerta_localidad.setpersist(true)
		alerta_localidad.setselectedClassTarget("link") //"link" or "linkparent"
		alerta_localidad.init()
	}


	function cambiar_LocalidadesPorCP(caja, nbCtl, nbCodigosCP) {
		var antiguoCP = document.getElementById("antiguoCP");
		var ctlCodigosCP = new Array();
		ctlCodigosCP = (document.getElementById(nbCodigosCP).value).split(',');
  	var codCP = (caja.value).substr(0,2);
		var provID = ctlCodigosCP[parseInt(codCP)]
		var ctlProv = document.getElementById(nbCtl);
		var ctlProvValue = ctlProv.options[ctlProv.selectedIndex].value;

		if(ctlProvValue!=provID) {
			if(antiguoCP.value!=codCP) {
			  if(!isNaN(caja.value) && caja.value.length==5) {
					var ctlPais = document.getElementById("pais");
					if(ctlPais.options[ctlPais.selectedIndex].value!="59") {
						for(var i=0; i<ctlPais.options.length; i++) {
							ctlPais.options[i].selected = false; 
							if(ctlPais.options[i].value=="59") {
								ctlPais.options[i].selected = true; 
							}
						}
					}
					var valor = ctlPais[ctlPais.selectedIndex].value;
					if(valor=="0") valor="";
					if(valor!="59" && valor!="") valor="0";
					var ctl = document.getElementById("pest_provincia");
					ctl.href = "/ajax_provincias.asp?id=" + valor + "&sel=" +  provID + "&locnb=" + nbCtl + "&loc=" + ctlProvValue;
					var provincia = new ddajaxtabs("provincia_tabs", "provincia_divcontainer")
					provincia.setpersist(true)
					provincia.setselectedClassTarget("link") //"link" or "linkparent"
					provincia.init()
					cambiar_Localidades(document.getElementById("localidad"), provID);
					cambiar_back_AlertaPais(provID);
				}
				antiguoCP.value = codCP;
		  }
	  }
	}
	
	
	function limpiarCP(ctl, nbCP) {
		var ctlCodigosCP = new Array();
		var ctlAux = document.getElementById("CodigosCP");
		if(ctlAux!=null) {
			ctlCodigosCP = (ctlAux.value).split(',');
			var caja = document.getElementById(nbCP)
			if(caja!=null) {
		  	var codCP = (caja.value).substr(0,2);
				var provID = ctlCodigosCP[parseInt(codCP)]
				if(provID != ctl.options[ctl.selectedIndex].value) {
					caja.value="";
				}
			}
		}
	}


	function cambiar_back_AlertaPais(provXX) {
		var prov = "";
		if(provXX!=null && prov!=undefined) prov = provXX;
		var ctlAlertaPais = document.getElementById("alerta_pais");
		if(ctlAlertaPais!=null) {
			// Cambiamos el pais
			var ctlPais = document.getElementById("pais");
			var paisSel = ctlPais.options[ctlPais.selectedIndex].value;
			if(paisSel=="0") paisSel="";
			if(paisSel!="59" && paisSel!="") paisSel="0";
			if(ctlAlertaPais.options[ctlAlertaPais.selectedIndex].value != paisSel) {
				for(var i=0; i<ctlAlertaPais.options.length; i++) {
					ctlAlertaPais.options[i].selected = false; 
					if(ctlAlertaPais.options[i].value==paisSel) {
						ctlAlertaPais.options[i].selected = true; 
					}
				}
			}
			// Cargamos las provincias
			var ctl = document.getElementById("pest_alerta_provincia");
			ctl.href = "/ajax_alerta_provincias.asp?id=" + paisSel + "&sel=" + prov;
			var alerta_provincia = new ddajaxtabs("alerta_provincia_tabs", "alerta_provincia_divcontainer")
			alerta_provincia.setpersist(true)
			alerta_provincia.setselectedClassTarget("link") //"link" or "linkparent"
			alerta_provincia.init()

			// Cambiamos las localidades
			var ctl = document.getElementById("pest_alerta_localidad");
			ctl.href = "/ajax_alerta_localidades.asp?id=" + prov + "&sel=";
			var alerta_localidad = new ddajaxtabs("alerta_localidad_tabs", "alerta_localidad_divcontainer")
			alerta_localidad.setpersist(true)
			alerta_localidad.setselectedClassTarget("link") //"link" or "linkparent"
			alerta_localidad.init()
		}
	}


	function cambiar_back_AlertaProvincia() {
		var ctlAlertaProv = document.getElementById("alerta_provincia");
		if(ctlAlertaProv != null) {
			var ctlProv = document.getElementById("provincia");
			var provSel = ctlProv.options[ctlProv.selectedIndex].value;
			if(ctlAlertaProv.options[ctlAlertaProv.selectedIndex].value != provSel) {
				for(var i=0; i<ctlAlertaProv.options.length; i++) {
					ctlAlertaProv.options[i].selected = false; 
					if(ctlAlertaProv.options[i].value==provSel) {
						ctlAlertaProv.options[i].selected = true; 
					}
				}
			}
			cambiar_AlertaLocalidades(ctlAlertaProv, "")
		}
	}


	function cambiar_back_AlertaLocalidad() {
		var ctlAlertaLoc = document.getElementById("alerta_localidad");
		if(ctlAlertaLoc != null) {
			var ctlLoc = document.getElementById("localidad");
			var locSel = ctlLoc.options[ctlLoc.selectedIndex].value;
			if(ctlAlertaLoc.options[ctlAlertaLoc.selectedIndex].value != locSel) {
				for(var i=0; i<ctlAlertaLoc.options.length; i++) {
					ctlAlertaLoc.options[i].selected = false; 
					if(ctlAlertaLoc.options[i].value==locSel) {
						ctlAlertaLoc.options[i].selected = true; 
					}
				}
			}
		}
	}


	function tratarTexto(ctl) {
		if( ctl.value.length>0 && (ctl.value).substr(0,1)=="[" ) {
			ctl.value = "";
		}
	}


	function comprobarMaysMins(porcentajeMax, cadena) {
		var numMays = 0;
		var numMin = 0;
		for(var i=0; i<cadena.length; i++) {
			var letra = cadena.charAt(i);
			var letraCode = parseInt(letra.charCodeAt(0));
			if ( (letraCode>=65 && letraCode<=90) || letraCode==209 ) { // de la A a la Z, y la Ñ
				numMays = numMays + 1;
				//alert("=M=>" + letra + "(" + letra.charCodeAt(0) + ")<==")
			}
			else {
				numMin = numMin + 1;
				//alert("=m=>" + letra + "(" + letra.charCodeAt(0) + ")<==")
			}
		}
		var res = Math.round( (numMays * 100) / (numMays + numMin) );
		var ok = true;
		if(res > porcentajeMax) {
			ok = false;
		}
		return ok;
	}

// End Of Function(s) to validate add new job ad Form
