//Funciones para red de delegaciones de la web
//	1.- FUNCIÓN JSCargarDocumento: Carga el docuemnto de centro seleccionado
//	2.- FUNCIÓN JSCargarCentros: Carga el listado de centros en el desplegable
//	3.- FUNCIÓN JSRellenarCampos: Rellena los campos desplegables de comunidades y centros
//	4.- FUNCIÓN JSbuscar: Busca el centro correspondiente al CP introducido
//	5.- FUNCIÓN JSstring2Unicode: Convierte una cadena de texto en un formato especial para pasar por URL
//	6.- FUNCIÓN JSEnviaCorreo: Abre la ventana con el formulario de contacto
//	7.- FUNCIÓN JSelem: Permite coger un objeto HTML a partir de su ID
//	8.- FUNCIÓN JSonClickBuscar: Se ejecuta al pulsar el icono de búsqueda
//	9.- FUNCIÓN JSonKeyPressBuscar: Al pulsar <return> sobre el campo de búsqueda por código se evita que se ejecute un "submit"
function JSCargarDocumento(jsComunidad, jsIndiceCentro)
{
	if (jsComunidad.selectedIndex<0 || jsIndiceCentro<0) return false;
	var jsCentro = f.Centro.options[jsIndiceCentro].text;
	if (jsCentro!="") {
		var jsId  = f.Centro.options[jsIndiceCentro].value;
	
		jsDatos = "&ID=" +jsId+ "&Comunidad=" + jsComunidad.options[jsComunidad.selectedIndex].text + "&Centro=" + jsCentro + "&OpSel="+jsOpSel+"&Perfil=" + jsPerfil + "&TipoMenu="+jsTipoMenu+"&Tipo=" + jsTipo + "&Ale=";
		jsUrl="/"+JSPRFLHomease+"/CENWFO01?OpenForm"+jsDatos;
		window.location.replace(jsUrl);
	}
}
function JSCargarCentros(jsNom)
{
	jsS = f.Centro.length;
	for (jsI=0; jsI<jsS; jsI++) {
		f.Centro.options[0]=null;
	}
	f.Centro.options[0]=new Option("", "");
	if (jsNom=="") return false;
	jsK=0;
	jsP = jsComunidades.length;
	for (jsI=0; jsI<jsP; jsI++) {
		if (jsComunidades[jsI]==jsNom) {
			jsK = jsK + 1;
			f.Centro.options[jsK] = new Option(jsCentros[jsI], jsListaIDCentros[jsI]);
		}
	}
}
function JSRellenarCampos()
{
	if (jsCPInicio!="") {
		f.cpos.value = jsCPInicio;
	} else {
		jsS1 = f.Comunidad.length;
		for (jsI1=0; jsI1<jsS1; jsI1++) {
			if (f.Comunidad.options[jsI1].text==jsComunidadInicio) {
				f.Comunidad.selectedIndex = jsI1;
				JSCargarCentros(jsComunidadInicio);
				jsS2 = f.Centro.length;
				for (jsI2=0; jsI2<jsS2; jsI2++) {
					if (f.Centro.options[jsI2].text==jsCentroInicio) {
						f.Centro.selectedIndex = jsI2;
					}
				}
				break;
			}
		}	
	}
}
function JSbuscar(jsTipus)
{
	var jsC = f.cpos.value;
	var jsNoNum;
	var jsS = new String();
	if (f.cpos.value == "") {
		if (jsLanguage == "CT") {
			alert("El codi postal és obligatori.");
		}else{
			alert("El código postal es obligatorio");
		}
		f.cpos.focus();
		return false;
	}
	jsNoNum = 0;
	jsS = f.cpos.value;
	if (jsS.length!=5) {
		if (jsLanguage == "CT") {
			alert("El codi postal ha de ser numèric de 5 posicions.");
		}else{
			alert("El código postal debe ser numérico de 5 posiciones.");
		}
		f.cpos.focus();
		return false;
	} else {
		for (jsI=0; jsI<=4; jsI++) {
			if (isNaN(parseInt(jsS.substr(jsI,1)))) {
				jsNoNum = 1;
			}
		}
		if (jsNoNum != 0) {
			if (jsLanguage == "CT") {
				alert("El codi postal ha de ser numèric de 5 posicions.");
			} else {
				alert("El código postal debe ser numérico de 5 posiciones.");
			}
			f.cpos.focus();
			return false;
		}
	}
	jsUrl  = "/" + JSPRFLHomease + "/CENWFO01?Openform&C=" + jsC + "&LANG=" + jsLanguage + "&OpSel="+jsOpSel+"&Perfil=" + jsPerfil + "&TipoMenu="+jsTipoMenu+"&Tipo=SP&ID=" + jsID + "&T="+jsTipus+"&Ale=" + Math.random();
	window.location.replace(jsUrl);
}
function JSstring2Unicode(jsEntrada)
{
	var jsSalida="";
	for( jsI=0 ; jsI<jsEntrada.length ; jsI++ ) {
		// la función charCodeAt(x) transforma x en caracter.
		jsSalida = jsSalida + "." + jsEntrada.charCodeAt(jsI);
	}
	return jsSalida + ".";
}
function JSEnviaCorreo()
{
	var opsp="";
	if (jsTipo=="SP") {
		opsp="&OP=SP";
	}
	var jsTemp=JSstring2Unicode(jsMail);
	window.open("/"+JSPRFLTextos+"/TEXWFO00?Openform&SendTo="+jsTemp+"&Cod="+jsCentro+"&LANG=" + jsLanguage.toUpperCase() + opsp + "&","top",'toolbar=0, width=650, height=470, scrollbars=1');
}
function JSelem ( jsIDElem )
{
	var jsIe = (document.all ? true : false);
	var jsNs6 = (! jsIe && document.getElementById ? true : false);
	var jsNs = (document.layers ? true : false);
	if (jsIe) return document.all [jsIDElem];
	if (jsNs6) return document.getElementById (jsIDElem);
	if (jsNs) return null;
}
function JSonClickBuscar() {
	var jsCad = window.location.href;
	var jsP=jsCad.lastIndexOf("CENWFO00");
	if (jsP==-1) {
		JSbuscar("2");
	}else{
		JSbuscar("1");
	}
}
function JSonKeyPressBuscar(e) {
	var key = window.event ? e.keyCode : e.which;
	if (key==13) {
		JSonClickBuscar();
		return false;
	}
	return true;
}

