var http_requestLLP = false;
function llenar_poblaciones(provincia) {
	http_requestLLP = false;
	document.getElementById("cargando").style.display = "block";
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_requestLLP = new XMLHttpRequest();
		if (http_requestLLP.overrideMimeType) {
			http_requestLLP.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_requestLLP = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_requestLLP = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}


	if (!http_requestLLP) {
		alert('Su navegador no es compatible con algunas funciones de este formulario');
		return false;
	}
	
	
	//http_requestLLP.open('GET', '/backoffice/includes/provincia_poblacion_cp.php?provincia=' + provincia, false);
	http_requestLLP.open('GET', '/backoffice/includes/provincia_poblacion_cp.php?provincia=' + provincia, true);
	http_requestLLP.onreadystatechange = rellenar_poblaciones;
	http_requestLLP.send(null);
	
/*if(http_request.readyState==4){
	rellenar_poblaciones();
}*/

	function rellenar_poblaciones(){
		if(http_requestLLP.readyState==4){
			if(http_requestLLP.status==200){
				var respuesta = eval(http_requestLLP.responseText);
				//vuelco las poblaciones de la provincia seleccionada
				var poblaciones = eval("poblacion");
				//var poblaciones_valor = eval("poblaciones_value");
				lista_poblaciones=document.forms['nueva-oferta']['poblacion'];
				lista_poblaciones.options.length = 1; //vuido els municipis
				//lista_poblaciones.options[0] = new Option ("Indiferente","Indiferente");
				//excepto la primera opcion --selecciona...
				for(i=1; i-1 < poblaciones.length; i++){
					lista_poblaciones.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
				}
				//lista_poblaciones.disabled=false;
				document.getElementById("cargando").style.display = "none";
			} else {
				alert('Hubo problemas con la petición.');
			}
		}
	}
}

function llenar_poblaciones_buscador_candidatos(provincia) {
	http_requestLLPBC = false;
	document.getElementById("cargando").style.display = "block";
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_requestLLPBC = new XMLHttpRequest();
		if (http_requestLLPBC.overrideMimeType) {
			http_requestLLPBC.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_requestLLPBC = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_requestLLPBC = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}


	if (!http_requestLLPBC) {
		alert('Su navegador no es compatible con algunas funciones de este formulario');
		return false;
	}
	
	
	//http_requestLLPBC.open('GET', '/backoffice/includes/provincia_poblacion_cp.php?provincia=' + provincia, false);
	http_requestLLPBC.open('GET', '/backoffice/includes/provincia_poblacion_cp.php?provincia=' + provincia, true);
	http_requestLLPBC.onreadystatechange = rellenar_poblaciones;
	http_requestLLPBC.send(null);
	
/*if(http_requestLLPBC.readyState==4){
	rellenar_poblaciones();
}*/

	function rellenar_poblaciones(){
		if(http_requestLLPBC.readyState==4){
			if(http_requestLLPBC.status==200){
				var respuesta = eval(http_requestLLPBC.responseText);
				//vuelco las poblaciones de la provincia seleccionada
				var poblaciones = eval("poblacion");
				//var poblaciones_valor = eval("poblaciones_value");
				lista_poblaciones=document.forms['nueva-oferta']['poblacion'];
				lista_poblaciones.options.length = 1; //vuido els municipis
				lista_poblaciones2=document.forms['nueva-oferta']['poblacion2'];
				lista_poblaciones3=document.forms['nueva-oferta']['poblacion3'];
				lista_poblaciones4=document.forms['nueva-oferta']['poblacion4'];
				lista_poblaciones5=document.forms['nueva-oferta']['poblacion5'];
				lista_poblaciones6=document.forms['nueva-oferta']['poblacion6'];
				lista_poblaciones7=document.forms['nueva-oferta']['poblacion7'];
				lista_poblaciones8=document.forms['nueva-oferta']['poblacion8'];
				lista_poblaciones9=document.forms['nueva-oferta']['poblacion9'];
				lista_poblaciones10=document.forms['nueva-oferta']['poblacion10'];
				lista_poblaciones11=document.forms['nueva-oferta']['poblacion11'];
				lista_poblaciones12=document.forms['nueva-oferta']['poblacion12'];
				//lista_poblaciones.options[0] = new Option ("Indiferente","Indiferente");
				//excepto la primera opcion --selecciona...
				for(i=1; i-1 < poblaciones.length; i++){
					lista_poblaciones.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones2.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones3.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones4.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones5.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones6.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones7.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones8.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones9.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones10.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones11.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
					lista_poblaciones12.options[i] = new Option (poblaciones[i-1][0],poblaciones[i-1][0]);
				}
				//lista_poblaciones.disabled=false;
				document.getElementById("cargando").style.display = "none";
			} else {
				alert('Hubo problemas con la petición.');
			}
		}
	}
}

function llenar_codigos_postales(provincia,poblacion) {
	http_requestLLCP = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_requestLLCP = new XMLHttpRequest();
		if (http_requestLLCP.overrideMimeType) {
			http_requestLLCP.overrideMimeType('text/xml');
			// Ver nota sobre esta linea al final
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_requestLLCP = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_requestLLCP = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_requestLLCP) {
		alert('Su navegador no es compatible con algunas funciones de este formulario');
		return false;
	}
	
	http_requestLLCP.onreadystatechange = rellenar_cp;
	http_requestLLCP.open('GET', '/backoffice/includes/provincia_poblacion_cp.php?provincia=' + provincia + '&poblacion=' + poblacion, true);
	http_requestLLCP.send(null);

	function rellenar_cp(){
		if (http_requestLLCP.readyState == 4) {
			if (http_requestLLCP.status == 200) {
				var respuesta = eval(http_requestLLCP.responseText);
				//vuelco las poblaciones de la provincia seleccionada
				var cp = eval("cp");
				//var poblaciones_valor = eval("poblaciones_value");
				lista_cp=document.forms['nueva-oferta'].cp;
				lista_cp.options.length = 1; //vuido els municipis
				//excepto la primera opcion --selecciona...
				for(i=1; i-1 < cp.length; i++){
					lista_cp.options[i] = new Option (cp[i-1][0],cp[i-1][0]);
				}
				cp.disabled=false;
				
			} else {
				alert('Hubo problemas con la petición.');
			}
		}
	}
}

function llenar_codigos_postales_gen(provincia,poblacion,campo_destino) {
	http_requestLLCPG = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_requestLLCPG = new XMLHttpRequest();
		if (http_requestLLCPG.overrideMimeType) {
			http_requestLLCPG.overrideMimeType('text/xml');
			// Ver nota sobre esta linea al final
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_requestLLCPG = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_requestLLCPG = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_requestLLCPG) {
		alert('Su navegador no es compatible con algunas funciones de este formulario');
		return false;
	}
	
	http_requestLLCPG.onreadystatechange = rellenar_cp;
	http_requestLLCPG.open('GET', '/backoffice/includes/provincia_poblacion_cp.php?provincia=' + provincia + '&poblacion=' + poblacion, true);
	http_requestLLCPG.send(null);

	function rellenar_cp(){
		if (http_requestLLCPG.readyState == 4) {
			if (http_requestLLCPG.status == 200) {
				var respuesta = eval(http_requestLLCPG.responseText);
				//vuelco las poblaciones de la provincia seleccionada
				var cp = eval("cp");
				//var poblaciones_valor = eval("poblaciones_value");
				lista_cp=document.forms['nueva-oferta'][campo_destino];
				lista_cp.options.length = 1; //vuido els municipis
				//excepto la primera opcion --selecciona...
				for(i=1; i-1 < cp.length; i++){
					lista_cp.options[i] = new Option (cp[i-1][0],cp[i-1][0]);
				}
				cp.disabled=false;
				
			} else {
				alert('Hubo problemas con la petición.');
			}
		}
	}
}

function llenar_codigos_postales_exp_prof(provincia,poblacion) {
	http_requestLLCPEP = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_requestLLCPEP = new XMLHttpRequest();
		if (http_requestLLCPEP.overrideMimeType) {
			http_requestLLCPEP.overrideMimeType('text/xml');
			// Ver nota sobre esta linea al final
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_requestLLCPEP = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_requestLLCPEP = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_requestLLCPEP) {
		alert('Su navegador no es compatible con algunas funciones de este formulario');
		return false;
	}
	
	http_requestLLCPEP.onreadystatechange = rellenar_cp;
	http_requestLLCPEP.open('GET', '/backoffice/includes/provincia_poblacion_cp.php?provincia=' + provincia + '&poblacion=' + poblacion, true);
	http_requestLLCPEP.send(null);

	function rellenar_cp(){
		if (http_requestLLCPEP.readyState == 4) {
			if (http_requestLLCPEP.status == 200) {
				var respuesta = eval(http_requestLLCPEP.responseText);
				//vuelco las poblaciones de la provincia seleccionada
				var cp = eval("cp");
				//var poblaciones_valor = eval("poblaciones_value");
				lista_cp=document.forms['curriculum-datos_personales'].cp;
				lista_cp.options.length = 1; //vuido els municipis
				//excepto la primera opcion --selecciona...
				for(i=1; i-1 < cp.length; i++){
					lista_cp.options[i] = new Option (cp[i-1][0],cp[i-1][0]);
				}
				cp.disabled=false;
				selecciona_cp();
			} else {
				alert('Hubo problemas con la petición.');
			}
		}
	}
}