var ajaxRequest;

function sendValorCombo(idComboDest,idSeleccion,tipoBusqueda,combosDis,idioma) {
	
	deshabilitaElem(combosDis,idioma);
	
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='BuscGuiadoFP.comboViaPres'){
		document.getElementById('BuscGuiadoFP.formaEst').value=idSeleccion;
	}
	
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='buscador.comboViaPres'){
		document.getElementById('buscador.formaEst').value=idSeleccion;	
	}
	
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='CasoDeUso.comboViaPres'){
		document.getElementById('CasoDeUso.formaEst').value=idSeleccion;
	}
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='ExcepcionVia_1.comboViaPres'){
		document.getElementById('ExcepcionVia_1.formaEst').value=idSeleccion;
	}
		
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='CasoDeUsoBase.comboViaPres'){
		document.getElementById('CasoDeUsoBase.formaEst').value=idSeleccion;
	}
	
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='Admintramite.comboViaPres'){
		document.getElementById('Admintramite.formaEst').value=idSeleccion;
	}
	
	if( idSeleccion != "" && ( (tipoBusqueda!="pais" && idSeleccion != "0") || (tipoBusqueda=="pais" && idSeleccion !="-1") ) )
	{
		
		/*  Con streaming */
		/*
		ajaxRequest = new sack();
		ajaxRequest.method = "GET";
		ajaxRequest.encodeURIString = false;
		ajaxRequest.requestFile = '../../generaComboRecServlet';
		ajaxRequest.URLString = tipoBusqueda + '=' + idSeleccion;
		ajaxRequest.onCompletion = function(){ writeListaComboDestino(idComboDest,idioma); };	// Specify function that will be executed after file has been found
		//mostrarTemporizador();
		ajaxRequest.runAJAX();		// Execute AJAX function		
		*/
		/* Con .portal*/
		//alert('dentro');
		ajaxRequest = new sack();
		ajaxRequest.method = "GET";
		var url = '/POVUDS_web/generaComboRecServlet?' + tipoBusqueda + '=' + idSeleccion + '&timestamp=' + new Date().getTime();
		ajaxRequest.requestFile = url;	/* Specifying which file to get*/
		ajaxRequest.charset ="UTF-8";
		ajaxRequest.onCompletion = function(){ writeListaComboDestino(idComboDest,idioma); };	/* Specify function that will be executed after file has been found */
		/*mostrarTemporizador();*/
		ajaxRequest.runAJAX();		/* Execute AJAX function*/
	}
	else
	{
		
		eliminarOptions(idComboDest);
		insertarOptionBlanco(idComboDest,idioma);
		document.getElementById(idComboDest).disabled = true;
	}
}

function sendValorGrupoAccion(idComboDest,idSeleccion,idioma) {
		ajaxRequest = new sack();
		ajaxRequest.method = "GET";
		var url = '/POVUDS_web/generaComboRecServlet?' + tipoBusqueda + '=' + idSeleccion + '&timestamp=' + new Date().getTime();
		ajaxRequest.requestFile = url;	/* Specifying which file to get*/
		ajaxRequest.charset ="UTF-8";
		ajaxRequest.onCompletion = function(){ writeListaComboDestino(idComboDest,idioma); };	/* Specify function that will be executed after file has been found */
		/*mostrarTemporizador();*/
		ajaxRequest.runAJAX();		/* Execute AJAX function*/	
	}

function validaCaptcha(elemento, portlet, boton, idform){
	//si intoducen texto
	var capt= document.getElementById(portlet+".captcha").value;
	
	if(capt != ''){
	
		ajaxRequest = new sack();
		var url = '/POVUDS_web/ValidarCaptchaServlet?' + 'strChaptka=' + capt + '&timestamp=' + new Date().getTime();
		ajaxRequest.requestFile = url;	/* Specifying which file to get*/
		ajaxRequest.onCompletion = function(){ habilitarBoton(portlet, boton, idform); };	/* Specify function that will be executed after file has been found */
		/*mostrarTemporizador();*/
		ajaxRequest.runAJAX();	
		
		
	}else{
		//desahabilitar el boton
		//document.getElementById(portlet+"."+boton).disabled =true;
		document.getElementById(portlet+".captCorrect").value ="falso";
		
	}

}

function habilitarBoton(portlet, boton, idform){
	//si el captcha es correcto habilito el boton de enviar en el apartado de contacto.
	var resp = ajaxRequest.response;
	
	if(resp =='false' || !resp){

	//tengo q refescar la pagina 
	//alert("Entra a falso");
	//hago submit de la forma para q cambie la imagen
	//	document.getElementById(portlet+"."+idform).submit();
		document.getElementById(portlet+".captCorrect").value ="falso";
	//	document.getElementById(portlet+".captcha").value ="";
		
	
	}else{
	 //habilitar el boton
	// document.getElementById(portlet+"."+boton).disabled =false;
	//alert("Entra a verdad");
	 document.getElementById(portlet+".captCorrect").value ="verdadero";
	
	// document.getElementById(portlet+"."+boton).action.submit();
	// document.getElementById("contactaPage.sendContactar").disabled =false;
	}
	
	document.getElementById(portlet+"."+idform).submit();
	
}


function sendValorManualCU(elemento,boton,docName,IdAgrup,desAgrup) {
//alert("El boton es --->>>" + boton);
	var texto = document.getElementById('AdminManualCU_2.descModify').value;
	document.getElementById(elemento).href += '&boton='+boton + "&dDocName" + '=' + docName + '&timestamp=' + new Date().getTime() + '&IdAgrup='+IdAgrup + '&DesAgrup='+desAgrup + '&DesModify='+texto;
	document.getElementById("AdminManualCU_2.formCU").submit();

}

function sendValorManualGA(elemento,boton,IdAgrup,desAgrup,ids,idioma){
	var texto = document.getElementById('AdminGuiasAsist.descModify').value;
	document.getElementById(elemento).href += '&boton='+boton + '&ids='+ids + '&idioma='+idioma + '&timestamp=' + new Date().getTime() + '&IdAgrup='+IdAgrup +'&DesAgrup='+desAgrup + '&DesModify='+texto;
	document.getElementById("AdminGuiasAsist.formGA").submit();

}

function sendImagenCU(docName) {
	var texto = document.getElementById('AdminManualCU_2.id_DocName').value;
	//alert("text1 ---> vacio" + texto);
	document.getElementById('AdminManualCU_2.id_DocName').value=docName;
	//alert("texto --->>>"+ docName);
	document.getElementById("AdminManualCU_2.formImgCU").submit();

}

function doSubmmitImgCU(){
	document.getElementById("formImgCU").submit();
}

function validarTextoCU(portlet){

	var texto = document.getElementById(portlet+'.descModify').value;
	if(texto == '' || texto ==null){
		document.getElementById('errorCU').style.display ='block';
		document.getElementById(portlet+'.guiaCU').disabled = true;
	}else{
		document.getElementById('errorCU').style.display ='none';
		document.getElementById(portlet+'.guiaCU').disabled = false;
	}
}	

//está función trae las actividades que se encuentran en un mapa de trámite dado el el id del trámite y el id de la agrupación
function sendValorComboAdm(idComboDest,idAgrupacion,idTramite,tipoBusqueda,combosDis,idioma) {
	
	deshabilitaElem(combosDis,idioma);
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='BuscGuiadoFP.comboViaPres'){
		document.getElementById('BuscGuiadoFP.formaEst').value=idSeleccion;
	}
	
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='buscador.comboViaPres'){
		document.getElementById('buscador.formaEst').value=idSeleccion;	
	}
	
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='CasoDeUso.comboViaPres'){
		document.getElementById('CasoDeUso.formaEst').value=idSeleccion;
	}
	
	if (tipoBusqueda=='tpEstablecimiento' && idComboDest=='Admintramite.comboViaPres'){
		document.getElementById('Admintramite.formaEst').value=idSeleccion;
	}

	if(idAgrupacion != "" && ((tipoBusqueda!="pais" && idAgrupacion != "0") || (tipoBusqueda=="pais") && idAgrupacion !="-1"))
	{
	
		ajaxRequest = new sack();
		var url = '/POVUDS_web/generaComboRecServlet?' + tipoBusqueda + '=' + idAgrupacion + '&idTramite='+idTramite + '&timestamp=' + new Date().getTime();
		ajaxRequest.requestFile = url;	/* Specifying which file to get*/
		ajaxRequest.onCompletion = function(){ writeListaComboDestino(idComboDest,idioma); };	/* Specify function that will be executed after file has been found */
		/*mostrarTemporizador();*/
		ajaxRequest.runAJAX();		/* Execute AJAX function*/
				
	}
	else
	{
		
		eliminarOptions(idComboDest);
		insertarOptionBlanco(idComboDest,idioma);
		document.getElementById(idComboDest).disabled = true;
	}
}

function writeListaComboDestino(idComboDest,idioma) {
	
	var lista = ajaxRequest.response;
	var select = document.getElementById(idComboDest);
	//alert('vuelta');
	eliminarOptions(idComboDest);
/*	insertarOptionBlanco(idComboDest);*/
	
	/* Insertamos el resto */

	
    if(lista != ""){
   //alert('vuelta2');
    	lista = lista.replace(/&#225;/mg,"\xe1")
    							.replace(/&#224;/mg,"\xe0")
    							.replace(/&#233;/mg,"\xe9")
    							.replace(/&#232;/mg,"\xe8")
								.replace(/&#237;/mg,"\xed")
								.replace(/&#236;/mg,"\xec")
								.replace(/&#243;/mg,"\xf3")
								.replace(/&#242;/mg,"\xf2")
								.replace(/&#250;/mg,"\xda")
								.replace(/&#249;/mg,"\xd9")
								.replace(/&#193;/mg,"\xc1")
								.replace(/&#192;/mg,"\xc0")
								.replace(/&#201;/mg,"\xc9")
								.replace(/&#200;/mg,"\xc8")
								.replace(/&#205;/mg,"\xcd")
								.replace(/&#204;/mg,"\xcc")
								.replace(/&#211;/mg,"\xd3")
								.replace(/&#210;/mg,"\xd2")
								.replace(/&#218;/mg,"\xda")
								.replace(/&#217;/mg,"\xd9")
								.replace(/&#183;/mg,"\xb7");					

    	insertarOptionBlanco(idComboDest,idioma);
	    var splitLista = lista.split("<span notrad=\"true\">##</span>");
	    var auxIndice;
	    var nuevaOpcion;
	    
	    
		
	    for (auxIndice = 0; auxIndice < splitLista.length; auxIndice++) {
	    	var elemLista = splitLista[auxIndice].split("<span notrad=\"true\">$$</span>");
	    	nuevaOpcion = document.createElement('option');
	    	/* En el texto meto la descripcion */
	    	nuevaOpcion.text = elemLista[0];//.replace("<span notrad=\"true\">","").replace("</span>","");
	    	/* En el value meto el codigo */
	    	nuevaOpcion.value = elemLista[1];//.replace("<span notrad=\"true\">","").replace("</span>","");
	    	if(elemLista[0] != ''){
		    	try {
		    		select.add(nuevaOpcion, null); /* standards compliant; doesn't work in IE */
		    	} catch(ex) {
		    		select.add(nuevaOpcion); /* IE only */
		    	}
		    }
	    }	

	    
	    if(idComboDest == 'OrganizacionAsistencia.comboAct'){
	    	insertarOptionTodasActividades(idComboDest,idioma);
	    }
	    	
	    select.disabled = false;
	}else{
		//alert('vuelta3');
		if(idComboDest == 'buscador.fJuri' || idComboDest == 'BuscGuiadoFP.fJuri'){
			insertarOptionSinFJ(idComboDest,idioma);
		}else{
			insertarOptionBlanco(idComboDest,idioma);
		}	
		select.disabled = true;
	}
	
	/*
	//clearTimeout(id);
	//document.getElementById("temporizador").removeChild(document.getElementById("imagenTemp"));
	//document.getElementById("temporizador").removeChild(document.getElementById("cortinaTemp"));
	//document.getElementById("temporizador").style.display = "none";
	//mostrarSelects();	
	//contador = 0;
	*/
	
}

function eliminarOptions(idComboDest) {
	/* Eliminamos las opciones actuales */
	
	var select = document.getElementById(idComboDest);
	while (select!= null && select.length > 0) {
		select.remove(select.length - 1);
	}
}

function insertarOptionBlanco(idComboDest,idioma) {
	
	var select = document.getElementById(idComboDest);
    var nuevaOpcion;
	nuevaOpcion = document.createElement('option');	
	
	if(idioma == 'en_US'){
		nuevaOpcion.text = "Select";
	}else if(idioma == 'ca_ES'){
		nuevaOpcion.text = "Seleccioneu";
	}else if(idioma == 'eu_ES'){
		nuevaOpcion.text = "Aukeratu";
	}else if(idioma == 'gl_ES'){
		nuevaOpcion.text = "Seleccione";
	}else{
		nuevaOpcion.text = "Seleccione";
	}
	if(idComboDest == 'buscador.fJuri' || idComboDest == 'BuscGuiadoFP.fJuri'){
		nuevaOpcion.value = "";
	}else if(idComboDest == 'CasoDeUso.fJuri'){
		nuevaOpcion.value = "-1";
	}else if(idComboDest == 'Admintramite.fJuri'){
		nuevaOpcion.value = "-1";
	}else{
		nuevaOpcion.value = "0";
	}
	try {
		select.add(nuevaOpcion, null); /* standards compliant; doesn't work in IE */
	} catch(ex) {
		select.add(nuevaOpcion); /* IE only */
	}
}

function insertarOptionSinFJ(idComboDest,idioma) {
	
	var select = document.getElementById(idComboDest);
    var nuevaOpcion;
	nuevaOpcion = document.createElement('option');
	
	if(idioma == 'en_US'){
		nuevaOpcion.text = "No Type of Company";
	}else if(idioma == 'eu_ES'){
		 nuevaOpcion.text = "Izaera Juridikorik Gabe"; 
	}else if(idioma == 'ca_ES'){
		 nuevaOpcion.text = "Sense Forma Jur\xEDdica"; 
	}else if(idioma == 'gl_ES'){
		nuevaOpcion.text = "Sen Forma Xur\xEDdica"; 
	}else{
		nuevaOpcion.text = "Sin Forma Jur\xEDdica";
	}
	nuevaOpcion.value = "";	
	try {
		select.add(nuevaOpcion, null); /* standards compliant; doesn't work in IE */
	} catch(ex) {
		select.add(nuevaOpcion); /* IE only */
	}
}


function insertarOptionTodasActividades(idComboDest,idioma) {
	
	var select = document.getElementById(idComboDest);
    var nuevaOpcion;
	nuevaOpcion = document.createElement('option');
		
	if(idioma == 'en_US'){
		nuevaOpcion.text = "All";
	}else if(idioma == 'ca_ES'){
		nuevaOpcion.text = "Totes";
	}else if(idioma == 'eu_ES'){
		nuevaOpcion.text = "Guztiak";
	}else if(idioma == 'gl_ES'){
		nuevaOpcion.text = "Todos";
	}else{
		nuevaOpcion.text = "Todas";
	}
	nuevaOpcion.value = "";	
	try {
		select.add(nuevaOpcion, null); /* standards compliant; doesn't work in IE */
	} catch(ex) {
		select.add(nuevaOpcion); /* IE only */
	}
}

function sendTipoRadio(idComboDest,valueRadio,idRadio,combosDis,idioma) {
	
	deshabilitaElem(combosDis,idioma);
	
	if(valueRadio != "")
	{
		if(idRadio == "tpBusqActiv" && valueRadio == "CNAE"){
			document.getElementById('buscGuiadoActiv.cajaCNAE').disabled = false;
		}else{
			if(document.getElementById('buscGuiadoActiv.cajaCNAE') != null){
				document.getElementById('buscGuiadoActiv.cajaCNAE').disabled = true;
			}
		}
		ajaxRequest = new sack();
		var url = 'generaComboRecServlet?' + idRadio + '=' + valueRadio + '&timestamp=' + new Date().getTime();
		ajaxRequest.requestFile = url;	/* Specifying which file to get */
		ajaxRequest.onCompletion = function(){ writeListaComboDestino(idComboDest,idioma); };	/* Specify function that will be executed after file has been found */ 
		ajaxRequest.runAJAX();		/* Execute AJAX function */		
		
	}else{
		if(idComboDest == 'buscador.fJuri' || idComboDest == 'BuscGuiadoFP.fJuri'){
			insertarOptionSinFJ(idComboDest,idioma);
		}else{
			insertarOptionBlanco(idComboDest,idioma);
		}	
		document.getElementById(idComboDest).disabled = true;
	}
}

function deshabilitaElem(combosDis,idioma){
	if(combosDis != "" && combosDis != null){
		var listaC = combosDis.split("<span notrad=\"true\">##</span>");
		for (var i = 0; i < listaC.length; i++) {
			eliminarOptions(listaC[i]);
			insertarOptionBlanco(listaC[i],idioma);		
			document.getElementById(listaC[i]).disabled = true;
		}
	}

}

function cargando(capa){
	if(document.getElementById(capa) != null){
		document.getElementById(capa).style.display = 'block';
	}else{
	   	for(var i=0;i<document.forms.length;i++){
	   		for(var j=0;i<document.forms[i].elements.length;j++){
				if (document.forms[i].elements[j].id == capa){
	   				document.forms[i].elements[j].style.display = 'block';
	   			}
	   		}
	   	}				
	}
}

function getTextFromFlash(str) {   

	if(document.getElementById('buscGuiadoLocal.ccaa_mapa') != null || document.getElementById('buscadorLocCVEmp_1.ccaa_mapa') != null){
		if(document.getElementById('buscGuiadoLocal.ccaa_mapa') != null){
			document.getElementById('buscGuiadoLocal.ccaa_mapa').value = str;
			document.getElementById('buscGuiadoLocal.btnBuscar').click();
		}else{
			document.getElementById('buscadorLocCVEmp_1.ccaa_mapa').value = str;
			document.getElementById('buscadorLocCVEmp_1.btnBuscar').click();
		}
	}else{
	   	for(var i=0;i<document.forms.length;i++){
	   		for(var j=0;i<document.forms[i].elements.length;j++){
				if (document.forms[i].elements[j].id == 'buscGuiadoLocal.ccaa_mapa'){
	   				document.forms[i].elements[j].value = str;
	   			}
				if (document.forms[i].elements[j].id == 'buscadorLocCVEmp_1.ccaa_mapa'){
	   				document.forms[i].elements[j].value = str;
	   			}
	   		}
	   	}
	   	for(var i=0;i<document.forms.length;i++){
	   		for(var j=0;i<document.forms[i].elements.length;j++){
				if (document.forms[i].elements[j].id == 'buscGuiadoLocal.btnBuscar'){
	   				document.forms[i].elements[j].click();
	   			}
				if (document.forms[i].elements[j].id == 'buscadorLocCVEmp_1.btnBuscar'){
	   				document.forms[i].elements[j].click();
	   			}
	   		}
	   	}				
	}	
}

function habilitaCapaSi(valCondicion, capa, condicion){
	var valor = '';
	if(valCondicion == condicion){
		valor = 'block';		
	}else{
		valor = 'none';
	}
	
	if(document.getElementById(capa) != null){
		document.getElementById(capa).style.display = valor;
	}else{
	   	for(var i=0;i<document.forms.length;i++){
	   		for(var j=0;i<document.forms[i].elements.length;j++){
				if (document.forms[i].elements[j].id == capa){
	   				document.forms[i].elements[j].style.display = valor;
	   			}
	   		}
	   	}
	}
}

function deshabilitarCapaSi(valCondicion, capa, condicion){
	var valor = '';
	if(valCondicion == condicion){
		valor = 'none';		
	}else{
		valor = 'block';
	}
	
	if(document.getElementById(capa) != null){
		document.getElementById(capa).style.display = valor;
	}else{
	   	for(var i=0;i<document.forms.length;i++){
	   		for(var j=0;i<document.forms[i].elements.length;j++){
				if (document.forms[i].elements[j].id == capa){
	   				document.forms[i].elements[j].style.display = valor;
	   			}
	   		}
	   	}
	}
}

function deshabilitarCapaSi_(valCondicion, capa,capa2, condicion, condicion2){
	var valor = '';
	var nameCapa = '';
	if(valCondicion == condicion || valCondicion == condicion2){
		valor = 'none';		
	}else{
		valor = 'block';
	}
	
	if(valCondicion == condicion2){
		if(document.getElementById(capa2) != null){
			document.getElementById(capa2).style.display = valor;
		}else{
	   		for(var i=0;i<document.forms.length;i++){
	   			for(var j=0;i<document.forms[i].elements.length;j++){
					if (document.forms[i].elements[j].id == capa2){
	   					document.forms[i].elements[j].style.display = valor;
	   				}
	   			}
	   		}
		}
	}else {
		
		if(document.getElementById(capa) != null){
			document.getElementById(capa).style.display = valor;
		}else{
	   		for(var i=0;i<document.forms.length;i++){
	   			for(var j=0;i<document.forms[i].elements.length;j++){
					if (document.forms[i].elements[j].id == capa){
	   					document.forms[i].elements[j].style.display = valor;
	   				}
	   			}
	   		}
		}
		
		//cambiar la capa 2.
		if(document.getElementById(capa2) != null){
			document.getElementById(capa2).style.display = valor;
		}else{
	   		for(var i=0;i<document.forms.length;i++){
	   			for(var j=0;i<document.forms[i].elements.length;j++){
					if (document.forms[i].elements[j].id == capa2){
	   					document.forms[i].elements[j].style.display = valor;
	   				}
	   			}
	   		}
		}
		
	}

}


function ponValorSi(capa, valor, valCondicion, condicion){
	if(valCondicion != condicion){
		valor = '';		
	}
	
	if(document.getElementById(capa) != null){
		document.getElementById(capa).value = valor;
	}else{
	   	for(var i=0;i<document.forms.length;i++){
	   		for(var j=0;i<document.forms[i].elements.length;j++){
				if (document.forms[i].elements[j].id == capa){
	   				document.forms[i].elements[j].value = valor;
	   			}
	   		}
	   	}
	}

}

function ponValorSi_(capa,valor,valor2, valCondicion, condicion, condicion2){
	var nameValor =  '';
	if(valCondicion != condicion && valCondicion != condicion2){
		nameValor = '';		
	}
	
	if(capa == 'Loc'){
		nameValor = valor;
	}else if(capa=='AACC'){
		nameValor = valor2;
	}else{
		nameValor = '';
	}
	
	if(document.getElementById(capa) != null){
		document.getElementById(capa).value = nameValor;
	}else{
	   	for(var i=0;i<document.forms.length;i++){
	   		for(var j=0;i<document.forms[i].elements.length;j++){
				if (document.forms[i].elements[j].id == capa){
	   				document.forms[i].elements[j].value = nameValor;
	   			}
	   		}
	   	}
	}
}

function deshabilitarCapaAACC(valCondicion,nombre_portlet){
//de acuerdo al valor q me venga en el this.value q es valCondicion escogo q valor tendra la condicion
//y q capa debe o nop deshablitar
//para 1 y 5 colegio prefesional y adm gral del estado
document.getElementById(nombre_portlet).value = "";

if(valCondicion==1 || valCondicion==5){
  if(valCondicion==1){
 // alert("entra desabilitar Loc ***");
	deshabilitarCapaSi(valCondicion, 'capaLoc', '1');
	ponValorSi(nombre_portlet, 'Loc', valCondicion, '1');
  }else if(valCondicion==5){
//  alert("entra desabilitar Loc");
  	deshabilitarCapaSi(valCondicion, 'capaLoc', '5');
	ponValorSi(nombre_portlet, 'Loc', valCondicion, '5');
  }	
  	
}else if(valCondicion==2){
 //alert("entra desabilitar Loc1");
	deshabilitarCapaSi(valCondicion, 'capaLoc1', '2');
	ponValorSi('autoridadCompetente.tpBuscCcaa', 'Loc1', valCondicion, '2');
	
	deshabilitarCapaSi(valCondicion, 'capaLoc', 'x');
	ponValorSi(nombre_portlet, 'Loc', valCondicion, 'null');
	
}else if(valCondicion==7){
 //alert("entra desabilitar Loc2");
	deshabilitarCapaSi(valCondicion, 'capaLoc2', '7');
	ponValorSi('autoridadCompetente.tpBuscDisp', 'Loc2', valCondicion, '7');
	
	deshabilitarCapaSi(valCondicion, 'capaLoc', 'x');
	ponValorSi(nombre_portlet, 'Loc', valCondicion, 'null');
	
	deshabilitarCapaSi(valCondicion, 'capaLoc1', 'x');
	ponValorSi('autoridadCompetente.tpBuscCcaa', 'Loc1', valCondicion, 'null');
}else{
//alert("habilitar capaas");
	deshabilitarCapaSi(valCondicion, 'capaLoc', 'x');
	deshabilitarCapaSi(valCondicion, 'capaLoc1', 'x');
	deshabilitarCapaSi(valCondicion, 'capaLoc2', 'x');
	ponValorSi(nombre_portlet, 'Loc', valCondicion, 'null');
	ponValorSi('autoridadCompetente.tpBuscCcaa', 'Loc1', valCondicion, 'null');
	ponValorSi('autoridadCompetente.tpBuscDisp', 'Loc2', valCondicion, 'null');
}
/*else if(valCondicion==7){
alert("entra desabilitar Loc2");
	deshabilitarCapaSi(valCondicion, 'capaLoc2', '7');
	ponValorSi(nombre_portlet, 'Loc2', valCondicion, '7');
}else{
alert("habilita cualkiera");
	deshabilitarCapaSi(valCondicion, 'capaLoc', 'x');
	ponValorSi(nombre_portlet,'Locx',valCondicion,valCondicion);

}*/

//deshabilitarCapaSi(this.value,'capaLoc','1');ponValorSi('${pageFlow.portlet}'+'.tpBusc','Loc',this.value,'1')

  
if(valCondicion!=7 && valCondicion!=2){
	if(document.getElementById('autoridadCompetente.permisoAACC')!= null){
		document.getElementById('autoridadCompetente.permisoAACC').disabled = true;
	}

}else{
	if(document.getElementById('autoridadCompetente.permisoAACC')!= null){
		document.getElementById('autoridadCompetente.permisoAACC').disabled = false;
	}
}

}

function filtrado(boton){
   /* document.getElementById(boton).click(); */
   if(document.getElementById(boton) != null){
   	document.getElementById(boton).click();
   }else{
   	for(var i=0;i<document.forms.length;i++){
   		for(var j=0;i<document.forms[i].elements.length;j++){
   			if(document.forms[i].elements[j].id == boton)
   				document.forms[i].elements[j].click();
   		}
   	}
   }
}      

function habilitaEComercio(idActividad,idioma){
	if (document.getElementById('buscador.fJuri').disabled == false){
		document.getElementById('buscador.1').checked=false;
		document.getElementById('buscador.2').checked=false;
		deshabilitaElem('buscador.comboViaPres',idioma);
		deshabilitaElem('buscador.fJuri',idioma);
	}
	
	/*
	if(idActividad != "")
	{*/
		document.getElementById('buscador.activity').value=idActividad;
		/*
		ajaxRequest = new sack();
		var url = 'consultaServEComerce?idActividad=' + idActividad + '&timestamp=' + new Date().getTime();
		ajaxRequest.requestFile = url;	// Specifying which file to get
		ajaxRequest.onCompletion = function(){ writeServEComerce(); };	// Specify function that will be executed after file has been found
		ajaxRequest.runAJAX();		// Execute AJAX function	
		
	}
	else
	{
		document.getElementById('capaEComerce').style.display = 'none';
	}
	*/
}

function writeServEComerce() {
	var respuesta = ajaxRequest.response;
	if (respuesta!="" && respuesta=="N"){
		document.getElementById('capaEComerce').style.display = 'none';
	}else{
		document.getElementById('capaEComerce').style.display = 'block';
	}
	
}      

function isValidarFechaOK(idFecha, idCapaError, botonDesabled, botonDesabledNoScript){
	var cadena = document.getElementById(idFecha).value;
	if(cadena != null && cadena != ""){
		if(!ValidateDateOK(cadena)){
			document.getElementById(idCapaError).style.display='block';
			var elem1 = document.getElementById(botonDesabled);
			if(elem1 != null){
				document.getElementById(botonDesabled).disabled=true;
				document.getElementById(botonDesabled).style.backgroundColor='#f0f0f0';
			}
			var elem2 = document.getElementById(botonDesabledNoScript);
			if(elem2 != null){
				document.getElementById(botonDesabledNoScript).disabled=true;
			}
		}else{
			document.getElementById(idCapaError).style.display='none';
			var elem1 = document.getElementById(botonDesabled);
			if(elem1 != null){
				document.getElementById(botonDesabled).disabled=false;
				document.getElementById(botonDesabled).style.backgroundColor='#45719C';
			}
			var elem2 = document.getElementById(botonDesabledNoScript);
			if(elem2 != null){
				document.getElementById(botonDesabledNoScript).disabled=false;
			}
		}
	}else{
		document.getElementById(idCapaError).style.display='none';
		var elem1 = document.getElementById(botonDesabled);
		if(elem1 != null){
				document.getElementById(botonDesabled).disabled=false;
				document.getElementById(botonDesabled).style.backgroundColor='#45719C';
		}
		if(botonDesabled == 'usuarios.boton'){
			document.getElementById('usuarios.boton').disabled=false;
			document.getElementById('usuarios.boton').style.backgroundColor='#45719C';
		}
		if(botonDesabled == 'misDatosPS_1.botonModif'){
			document.getElementById('misDatosPS_1.botonModif').disabled=false;
			document.getElementById('misDatosPS_1.botonModif').style.backgroundColor='#45719C';
		}
		var elem2 = document.getElementById(botonDesabledNoScript);
			if(elem2 != null){
				document.getElementById(botonDesabledNoScript).disabled=false;
			}
	}
	
}

function isValidarFecha(idFecha, idCapaError){
	var cadena = document.getElementById(idFecha).value;
	if(cadena != null && cadena != ""){
		if(!ValidateDateOK(cadena)){
			document.getElementById(idCapaError).style.display='block';
			var elem1 = document.getElementById('usuarios.boton');
			if(elem1 != null){
				document.getElementById('usuarios.boton').disabled=true;
				document.getElementById('usuarios.boton').style.backgroundColor='#f0f0f0';
			}
		}else{
			document.getElementById(idCapaError).style.display='none';
			var elem1 = document.getElementById('usuarios.boton');
			if(elem1 != null){
				document.getElementById('usuarios.boton').disabled=false;
				document.getElementById('usuarios.boton').style.backgroundColor='#45719C';
			}
		}
	}else{
		document.getElementById(idCapaError).style.display='none';
		document.getElementById('usuarios.boton').disabled=false;
		document.getElementById('usuarios.boton').style.backgroundColor='#45719C';
	}
	
}

function isValidarFecha_BotonMayor(idFecha, idCapaError,botonDesabled){
	var cadena = document.getElementById(idFecha).value;
	var cad_fecha1 = document.getElementById('adminNormativa.fecha').value;
	
	if(cadena != null && cadena != ""){
	
		if(!ValidateDateOK(cadena)){
			document.getElementById(idCapaError).style.display='block';
			var elem1 = document.getElementById(botonDesabled);
			if(elem1 != null){
				document.getElementById(botonDesabled).disabled=true;
				document.getElementById(botonDesabled).style.backgroundColor='#f0f0f0';
			}
				
		}else{
			//Validacion con la fecha 1
			
			if(cad_fecha1 != null && cad_fecha1 != ""){
			
				if(ValidateDateOK(cad_fecha1)){
					var fechaAUX = cad_fecha1.split("/"); 
					var Mi_Fecha1 = new Date(fechaAUX[2], fechaAUX[1], fechaAUX[0]); 
				}		
				var fechaAUX2 = cadena.split("/"); 
				var Mi_Fecha2 = new Date(fechaAUX2[2], fechaAUX2[1], fechaAUX2[0]);
				
				//Comparo las fechas				
				if(Mi_Fecha1.getTime() > Mi_Fecha2.getTime()){ 
					//('Fechas no validas'); 
					document.getElementById('errDoc3').style.display='block';
					var elem1 = document.getElementById(botonDesabled);
					if(elem1 != null){
						document.getElementById(botonDesabled).disabled=true;
						document.getElementById(botonDesabled).style.backgroundColor='#f0f0f0';
					}
				}else{	
					document.getElementById(idCapaError).style.display='none';
					document.getElementById('errDoc3').style.display='none';
					var elem1 = document.getElementById(botonDesabled);
					if(elem1 != null){
						document.getElementById(botonDesabled).disabled=false;
						document.getElementById(botonDesabled).style.backgroundColor='#45719C';
					}
				}
			}else{
			//debe indicar una fecha inicial
			document.getElementById('errDoc4').style.display='block';
			var elem1 = document.getElementById(botonDesabled);
					if(elem1 != null){
						document.getElementById(botonDesabled).disabled=true;
						document.getElementById(botonDesabled).style.backgroundColor='#f0f0f0';
					}

			}
			//Fin validacion
			
		}
	}else{
		document.getElementById(idCapaError).style.display='none';
		document.getElementById('errDoc3').style.display='none';
		document.getElementById('errDoc4').style.display='none';
		document.getElementById(botonDesabled).disabled=false;
		document.getElementById(botonDesabled).style.backgroundColor='#45719C';
	}
	
	
}

function isValidarFecha_Boton(idFecha, idCapaError,botonDesabled){
	var cadena = document.getElementById(idFecha).value;
	if(cadena != null && cadena != ""){
		if(!ValidateDateOK(cadena)){
			document.getElementById(idCapaError).style.display='block';
			var elem1 = document.getElementById(botonDesabled);
			if(elem1 != null){
				document.getElementById(botonDesabled).disabled=true;
				document.getElementById(botonDesabled).style.backgroundColor='#f0f0f0';
			}
		}else{
			document.getElementById(idCapaError).style.display='none';
			var elem1 = document.getElementById(botonDesabled);
			if(elem1 != null){
				document.getElementById(botonDesabled).disabled=false;
				document.getElementById(botonDesabled).style.backgroundColor='#45719C';
			}
		}
	}else{
		document.getElementById(idCapaError).style.display='none';
		document.getElementById(botonDesabled).disabled=false;
		document.getElementById(botonDesabled).style.backgroundColor='#45719C';
	}
	
}

function isValidarFecha2(idFecha, idCapaError){
	var cadena = document.getElementById(idFecha).value;
	if(cadena != null && cadena != ""){
		if(!validarFecha(cadena)){
			document.getElementById(idCapaError).style.display='block';
		}else{
			document.getElementById(idCapaError).style.display='none';
		}
	}else{
		document.getElementById(idCapaError).style.display='none';
	}
	
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
   } 
   return this;
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	
	
	if (pos1==-1 || pos2==-1){		
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false;
	}
	return true;
}

function ValidateDateOK(strValue){
	if (isDate(strValue)==false){
		return false;
	}
    return true;
 }


function validarFecha(cadena){
	var Fecha= new String(cadena);   /* Crea un string */   
    var RealFecha= new Date();   /* Para sacar la fecha de hoy  Cadena Año */   
    if (Fecha.indexOf("/")=='-1' || Fecha.indexOf("/")=='0'){	
    	return false ; 
    }

    var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));  
     Ano = parseInt(Ano);
    /* Cadena Mes */ 
    var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
     Mes =  parseInt(Mes);
   	 /* Cadena Día */   
    var Dia= new String(Fecha.substring(0,Fecha.indexOf("/"))); 

   	Dia = parseInt(Dia); 
  
    /* Valido el año */   
    if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){    
        return false ;  
    }   
    /* Valido el Mes */   
    if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){     
        return false;  
    }   
    /* Valido el Dia */   
    if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){    
        return false;   
    }   
    if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {   
        if (Mes==2 && Dia > 28 || Dia>30) {    
            return false;  
        }   
    }   
	 return true;     
}

function validarNumerico(idTelefono, idCapaError){
	var cadena = document.getElementById(idTelefono).value;
	if (isNaN(cadena)){
		document.getElementById(idCapaError).style.display='block';
	}else{
		document.getElementById(idCapaError).style.display='none';
	}
	
}

function validaCorreo(idCorreo, idCapaCorreo){
	var correoElec=document.getElementById(idCorreo).value;
		var mail = /[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*((\.[A-Za-z]{2,4}){1}$)/;
		if(!mail.test(correoElec)){
			document.getElementById(idCapaCorreo).style.display='block';
		}else{
			document.getElementById(idCapaCorreo).style.display='none';
		}
}

function ponerAncla1Click(elemento, ancla, portlet){
	/*var comboCCAA = document.getElementById("tramita1Click.tramita1Click.comboCCAA").value;
	var comboProv = document.getElementById("tramita1Click.tramita1Click.comboProv").value;
	var comboPobl = document.getElementById("tramita1Click.tramita1Click.comboPobl").value;*/
	document.getElementById(elemento).href  += '&timestamp=' + new Date().getTime() + "#" + ancla;  
	/*alert("ccaa" +  comboCCAA);
	alert("prov" +  comboProv);
	alert("pobl" +  comboPobl);*/
	
}

function ponerAncla(elemento, ancla){
	document.getElementById(elemento).href += '&timestamp=' + new Date().getTime() + "#" + ancla;  
}

function ponerAnclaDocumento(elemento, ancla){
	//debugger;
	if(document.getElementById(elemento).tagName == 'INPUT' &&  
		document.getElementById(elemento).type == 'submit'){
			document.getElementById(elemento).form.action += '&timestamp=' + new Date().getTime() + "#" + ancla;
	}else if(document.getElementById(elemento).tagName == 'A'){
		document.getElementById(elemento).href += '&timestamp=' + new Date().getTime() + "#" + ancla;
	}  
}

var id;
var idTemp = 0;
var contador = 0

function mostrarTemporizador(tipo,idioma){	
	/*Ocultamos todos los elementos que por defecto se quedan por encima */
	ocultarSelects();
	
	/*Pintamos el temporizador, elemnto de espera */
    pintaTemporizador(tipo,idioma);

    /* Lo mantenemos mientras no vuelva de AJAX */ 
    espera ('barras');
    
}

function ocultarSelects(){
	var elementos = document.getElementsByTagName("SELECT");
	
	for (i=0;i<elementos.length;i++){
		elementos[i].style.visibility = "hidden";
	}
	
	elementos = document.getElementsByTagName("IFRAME");
	
	for (i=0;i<elementos.length;i++){
		elementos[i].style.visibility = "hidden";
	}
	
	
	elementos = document.getElementsByTagName("OBJECT");
	
	for (i=0;i<elementos.length;i++){
		elementos[i].style.visibility = "hidden";
	}
	
}

function mostrarSelects(){
	var elementos = document.getElementsByTagName("SELECT");
	
	for (i=0;i<elementos.length;i++){
		elementos[i].style.visibility = "visible";
	}
	
	elementos = document.getElementsByTagName("IFRAME");
	
	for (i=0;i<elementos.length;i++){
		elementos[i].style.visibility = "visible";
	}
	
	elementos = document.getElementsByTagName("OBJECT");
	
	for (i=0;i<elementos.length;i++){
		elementos[i].style.visibility = "visible";
	}
}

function pintaTemporizador(tipo,idioma) {
    var cortina = "<div class='cortina' id='cortinaTemp'></div>";
    pintaElemento(cortina);
    
   	var imagenTemp = "<div id='imagenTemp' class='tras_InitTram' style='margin-left:210px;margin-top:30px;'>"+
							"&nbsp;" +
                 		"</div>";
                 		
	if(tipo == 'iniciarTramitacion'){
		if(idioma == 'es_ES'){
			imagenTemp = "<div id='imagenTemp' class='tras_InitTram' style='margin-left:210px;margin-top:30px;'>"+
							"&nbsp;" +
                 		"</div>"; 
		}else{
			imagenTemp = "<div id='imagenTemp' class='tras_InitTram' style='margin-left:210px;margin-top:30px;'>"+
							"&nbsp;" +			
                 		"</div>"; 
		}
	}else if(tipo == 'espereTramitando'){
		if(idioma == 'es_ES'){
			imagenTemp = "<div id='imagenTemp' style='position:absolute;z-index:5001;margin-left:210px;margin-top:80px;'>"+
                 			"<img src='/framework/skins/POVUDS/images/tramitando.png' width='518' height='400'/>" +
                 		"</div>"; 
		}else{
			imagenTemp = "<div id='imagenTemp' style='position:absolute;z-index:5001;margin-left:210px;margin-top:80px;'>"+
                 			"<img src='/framework/skins/POVUDS/images/tramitando.png' width='518' height='400'/>" +
                 		"</div>"; 
		}	
	}
    pintaElemento(imagenTemp);
    
    document.getElementById("temporizador").style.display = "block";
}

function pintaElemento(elemento) {
    var raiz = document.getElementById('temporizador');
    
    if ( raiz == null) {
        raiz = document.createElement('DIV');
        raiz.id = 'temporizador';
        document.body.appendChild(raiz);        
    } 
    
    raiz.innerHTML += elemento;
    
}

function bucle (objeto) {
	contador = eval(contador) + 15;
	
	id=setTimeout("espera ('"+objeto+"')","900");
	idTemp = id;
}

function espera (objeto){
	
		if(contador==3000000){
			clearTimeout(id);
			document.getElementById("temporizador").removeChild(document.getElementById("imagenTemp"));
			document.getElementById("temporizador").removeChild(document.getElementById("cortinaTemp"));
			document.getElementById("temporizador").style.display = "none";
			mostrarSelects();	
			contador = 0;
			/* popUps(salto); */
		
		}else{
			setTimeout("bucle ('"+objeto+"')","900");
		}
}

/* function para agregar opcion a un combo */
function appendOptionLast(combo,dato)
{
 if(document.getElementById(dato).value != ""){
  var elOptNew = document.createElement('option');
  elOptNew.text = document.getElementById(dato).value;
  elOptNew.value = document.getElementById(dato).value;
  var elSel = document.getElementById(combo);

  try {
    elSel.add(elOptNew, null); /* standards compliant; doesn't work in IE */
  }
  catch(ex) {
    elSel.add(elOptNew); /* IE only */
  }
  document.getElementById(dato).value = "";
  }
}


function addOptionComboAOtroCombo(combo1,combo2){
var elSel = document.getElementById(combo1);
var dato = elSel[elSel.selectedIndex].value;
var elOptNew = document.createElement('option');
elOptNew.text = dato;
elOptNew.value = dato;
var elSel = document.getElementById(combo2);

try {
    elSel.add(elOptNew, null); /* standards compliant; doesn't work in IE */
}
catch(ex) {
    elSel.add(elOptNew); /* IE only */
  }
  
 removeOptionSelected(combo1) 
}


function insertOptionBefore(combo,dato)
{
  var elSel = document.getElementById(combo);
  if (elSel.selectedIndex >= 0) {
    var elOptNew = document.createElement('option');
    elOptNew.text = document.getElementById(dato).value;
    elOptNew.value = document.getElementById(dato).value;
    var elOptOld = elSel.options[elSel.selectedIndex];  
    try {
      elSel.add(elOptNew, elOptOld); /* standards compliant; doesn't work in IE */
    }
    catch(ex) {
      elSel.add(elOptNew, elSel.selectedIndex); /* IE only */
    }
  }
}

function removeOptionSelected(combo)
{
  var elSel = document.getElementById(combo);
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
    if (elSel.options[i].selected) {
      elSel.remove(i);
    }
  }
}

/*function recogerDatos(comboDoc, comoboResult, comboReq, comboAnt){
	var elSel = document.getElementById(comboDoc);
	var elSelR = document.getElementById(comoboResult);
	var elSelRq = document.getElementById(comboReq);
	var elSelAnt = document.getElementById(comboAnt);
	var cadenaDoc= "";
	var cadenaResult= "";
	var cadenaReq = "";
	var cadenaAnt = "";

	if(elSel != null){
		for(var i=1; i< elSel.length; i++){
			cadenaDoc += elSel.options[i].value + "###";
		}
	}

	if(elSelR != null){
		for(var i=1; i< elSelR.length; i++){
			cadenaResult += elSelR.options[i].value + "###";
		}
	}

	if(elSelR != null){
		for(var i=1; i< elSelRq.length; i++){
			cadenaReq += elSelRq.options[i].value + "###";
		}
	}

	if(elSelAnt != null){
		for(var i=1; i< elSelAnt.length; i++){
			cadenaAnt += elSelAnt.options[i].value + "###";
		}
	}

	document.getElementById('CasoDeUso.auxDoc').value = cadenaDoc;
	document.getElementById('CasoDeUso.auxResult').value = cadenaResult;
	document.getElementById('CasoDeUso.auxReq').value = cadenaReq;
	document.getElementById('CasoDeUso.auxAntecesor').value = cadenaAnt;
	
}*/

function filtrarTramiteByPadre(padre, idTramite){

	var idsForms;
	var checks = new Array();
	var habilitarCheck=false;
	var contCheck=0;
	var index= 0;
	
	for(var i=0;i<document.forms.length;i++){
	   	for(var j=0;j<document.forms[i].elements.length;j++){
	   		idsForms = document.forms[i].elements[j].id;
	   		if(idsForms!= null && idsForms!= undefined ){
	   				
	   			var id = (idsForms.split("__"))[2];
	   			var idTra = (idsForms.split("__"))[1];
	   			var caja = (idsForms.split("__"))[1];

	   			if(id != 'undefined' && id != undefined ){

					if(idTra == idTramite && !document.forms[i].elements[j].checked){
				  		habilitarCheck=true;
				  	}else{
	   			  	 	if(id == padre){	   			  	 
	   			  	 		if(caja == 'tx_exclusividad'){
	   			  	 			document.forms[i].elements[j].disabled= true;
	   			  	 		
	   			  	 		}
	   			  	 	}else{
	   			  	 		document.forms[i].elements[j].disabled = true;
	   			  	 		checks[index]=document.forms[i].elements[j]+"<span notrad=\"true\">##</span>"+i+"<span notrad=\"true\">##</span>"+j;
							index++;
	   			  	 	}
	   			  	
	   			  	} 
	   			  
	   			  	if(document.forms[i].elements[j].checked){
	   			  		contCheck++;
	   			  	}
					
				}
	   		}

	   	}
	}
	   	
	   	/* recorro la lista de checks para habilitarlos */
	if(contCheck ==0 && habilitarCheck){
	   	for(var t=0; t<checks.length; t++){
	   		var obj1=(checks[t].split("<span notrad=\"true\">##</span>"))[1]; 
	   		var obj2 =(checks[t].split("<span notrad=\"true\">##</span>"))[2]; 
	   		document.forms[obj1].elements[obj2].disabled = false;
	   	}	
	}
}	


function habilitarMensaje(idTramite){
	
	var text = document.getElementById('CasoDeUso.tx_exclusividad__'+idTramite);
	var check = document.getElementById('CasoDeUso.ck_exclusividad__'+idTramite);
	
	if(check.checked){
		text.disabled= false;
 	}
 	else{
 		text.disabled= true;
 	}
}

function activarAacc(){
	
	var checkDirect = document.getElementById('AdminUsuarios.aaccDirect');
	var checkAdmin = document.getElementById('AdminUsuarios.aaccAdmin');
	var chechAacc = document.getElementById('AdminUsuarios.aacc');
	if(!chechAacc.checked){
		checkDirect.disabled = true;
		checkAdmin.disabled = true;	
	}else{
		checkDirect.disabled = false;
		checkAdmin.disabled = false;	
	}
	
}
	
function habilitarAacc(elemento1, capa1, elemento2, capa2, deshabilitar){
	
	var check1 = document.getElementById(elemento1);
	var check2 = document.getElementById(elemento2);

	if(check1.checked){
		check1.checked= true;
		document.getElementById(capa1).style.display='block';
		document.getElementById(capa2).style.display='none';
		check2.checked= false;
		check2.disabled = true;

		document.getElementById('AdminUsuarios.id_aaccId').value= '';
		document.getElementById('AdminUsuarios.aaccIdForm').value= '';
		document.getElementById('AdminUsuarios.id_aaccWsId').value= '';
		document.getElementById('AdminUsuarios.aaccWsIdForm').value= '';
		
	}else{
		check1.checked= false;
		check2.disabled = false;

		document.getElementById(capa1).style.display='none';
		document.getElementById('AdminUsuarios.id_aaccId').value= '';
		document.getElementById('AdminUsuarios.aaccIdForm').value= '';
		document.getElementById('AdminUsuarios.id_aaccWsId').value= '';
		document.getElementById('AdminUsuarios.aaccWsIdForm').value= '';

	}
	
	var checkDirect = document.getElementById('AdminUsuarios.aaccDirect');
	var checkAdmin = document.getElementById('AdminUsuarios.aaccAdmin');
	
	if(deshabilitar){
		//deshabilito los checks
		checkDirect.disabled = true;
		checkAdmin.disabled = true;		
	}else{
		checkDirect.disabled = false;
		checkAdmin.disabled = false;	
	}
	var chechAacc = document.getElementById('AdminUsuarios.aacc');
	if(!chechAacc.checked){
		checkDirect.disabled = true;
		checkAdmin.disabled = true;	
	}

	
}
function habilitarCheckPSIndiv(valor, checked){
	if (valor != "PSIndiv"){
		if (checked == true){
			document.getElementById("PSIndiv").style.disabled='true';
		}
	}
	//alert(valor);
}
function habilitarAaccAltaUserAdmin(elemento1, capa1, elemento2, capa2, deshabilitar){
	
	var check1 = document.getElementById(elemento1);
	var check2 = document.getElementById(elemento2);
	//alert(check1);
	//alert(check2);
	if(check1.checked){
		check1.checked= true;
		document.getElementById(capa1).style.display='block';
		document.getElementById(capa2).style.display='none';
		check2.checked= false;
		check2.disabled = true;

		document.getElementById('AdminUsuarios.id_aaccId').value= '';
		document.getElementById('AdminUsuarios.aaccIdForm').value= '';
		document.getElementById('AdminUsuarios.id_aaccWsId').value= '';
		document.getElementById('AdminUsuarios.aaccWsIdForm').value= '';
		
	}else{
		check1.checked= false;
		check2.disabled = false;

		document.getElementById(capa1).style.display='none';
		document.getElementById('AdminUsuarios.id_aaccId').value= '';
		document.getElementById('AdminUsuarios.aaccIdForm').value= '';
		document.getElementById('AdminUsuarios.id_aaccWsId').value= '';
		document.getElementById('AdminUsuarios.aaccWsIdForm').value= '';

	}
	
	var checkDirect = document.getElementById('AdminUsuarios.aaccDirect');
	var checkAdmin = document.getElementById('AdminUsuarios.aaccAdmin');
	
	if(deshabilitar){
		//deshabilito los checks
		checkDirect.disabled = true;
		checkAdmin.disabled = true;		
	}else{
		checkDirect.disabled = false;
		checkAdmin.disabled = false;	
	}
	var chechAacc = document.getElementById('AdminUsuarios.aacc');
	if(!chechAacc.checked){
		checkDirect.disabled = true;
		checkAdmin.disabled = true;	
	}
	
}

function habilitarChecks(idTramite){
	
	var checkGen = document.getElementById('CasoDeUso.ch_generico');
	var checkSin = document.getElementById('CasoDeUso.ch_sinPredecesor');
	var btnAnadir = document.getElementById('CasoDeUso.bt_anadir');
	var btnQuitar = document.getElementById('CasoDeUso.bt_quitar');
	
	if(checkGen.checked){
		checkSin.value=false;
		btnAnadir.disabled=true;
		btnQuitar.disabled=true;
		checkSin.disabled=false;
		checkGen.disabled=false;
	}
 	if(checkSin.checked){
 		checkGen.value=false;
		btnAnadir.disabled=true;
		btnQuitar.disabled=true;
		checkSin.disabled=false;
		checkGen.disabled=false;
 	}
 	if(!checkSin.checked && !checkGen.checked){
 		checkGen.disabled=false;
 		checkSin.disabled=false;
		btnAnadir.disabled=false;
		btnQuitar.disabled=false;
 	}
 	
}	

function habilitarChecksBase(idTramite){
	
	var checkGen = document.getElementById('CasoDeUsoBase.ch_generico');
	var btnAnadir = document.getElementById('CasoDeUsoBase.bt_anadir');
	var btnQuitar = document.getElementById('CasoDeUsoBase.bt_quitar');
	
	if(checkGen.checked){
		btnAnadir.disabled=true;
		btnQuitar.disabled=true;
		checkGen.disabled=false;
	}
 	
 	if(!checkGen.checked){
 		checkGen.disabled=false;
		btnAnadir.disabled=false;
		btnQuitar.disabled=false;
 	}
 	
}	


function cambiarHttps(elemento){

	var url = document.getElementById(elemento).form.action;
	url = url.replace("http://", "https://");
	url = url.replace(":7001/", ":7002/");
	document.getElementById(elemento).form.action = url;	 	
}

function cambiarHttp(elemento){

	var url = document.getElementById(elemento).form.action;
	url = url.replace("https://", "http://");
	url = url.replace(":7002/", ":7001/");
	document.getElementById(elemento).form.action = url;	 	
}

function check_url(cadena,capa)
{
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
    // var tomatch2= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
     
     var valor = document.getElementById(cadena).value;
	if(valor != null && valor != "" && valor.length > 0){
  // 		  if (tomatch.test(valor) || tomatch2.test(valor)){
   		if (tomatch.test(valor)){
         	document.getElementById(capa).style.display = "none";
    	 }
    	 else {	
     		 document.getElementById(capa).style.display = "block";
    		
    	 }
     }
}

function check_url_desactiva_boton(cadena,capa,botonDesabled)
{
     var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
    // var tomatch2= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
      var elem1 = document.getElementById(botonDesabled);
     var valor = document.getElementById(cadena).value;
	if(valor != null && valor != "" && valor.length > 0 && valor != " "){
  // 		  if (tomatch.test(valor) || tomatch2.test(valor)){
   		if (tomatch.test(valor)){
         	document.getElementById(capa).style.display = "none";
         	if(elem1 != null){
				document.getElementById(botonDesabled).disabled=false;
			}
    	 }
    	 else {	
     		 document.getElementById(capa).style.display = "block";    		
			 if(elem1 != null){
				document.getElementById(botonDesabled).disabled=true;
				document.getElementById(botonDesabled).style.backgroundColor='#45719C';
			}
    		
    	 }
     }else{
     	if(elem1 != null){
			document.getElementById(botonDesabled).disabled=false;
		}
     }
     
}

function validaIdUsuarioDisponible(idUsuario,portlet) {
	var namePortlet = portlet;
	if (idUsuario != ''){
		if(idUsuario.length < 6 || idUsuario.length > 20){
			mostrarValidacion('longitud','id_userId',namePortlet,'errorLongUser','errorValidUser');
		}else{
			/*
			mostrarTemporizador();
			*/
			ajaxRequest = new sack();
			var url = '/POVUDS_web/validaIdUsuarioServlet?idUsuario=' + idUsuario + '&timestamp=' + new Date().getTime();
			ajaxRequest.requestFile = url;	/* Specifying which file to get*/
			ajaxRequest.onCompletion = function(){ mostrarValidacion('validacion','id_userId',namePortlet,'errorLongUser','errorValidUser'); };	/* Specify function that will be executed after file has been found */
			ajaxRequest.runAJAX();		/* Execute AJAX function*/
		}
				
	}else{
		document.getElementById(portlet+'.id_userId').style.background = 'white';
		document.getElementById('errorLongUser').style.display = 'none';
		document.getElementById('errorValidUser').style.display = 'none';
	}
}

function validaNIEDisponible(idNie,id,portlet) {
	var namePortlet = portlet;
	document.getElementById('errorLongNie').style.display = 'none';
	document.getElementById('errorNieInvalido').style.display = 'none';
	if (idNie != ''){
		if(idNie.length < 9 || idNie.length > 9){
			mostrarValidacion('longitud',id,namePortlet,'errorLongNie','errorNieInvalido');
		}else{
			/*
			mostrarTemporizador();
			*/
			ajaxRequest = new sack();
			var url = '/POVUDS_web/validaNieUsuarioServlet?idNie=' + idNie + '&timestamp=' + new Date().getTime();
			ajaxRequest.requestFile = url;	/* Specifying which file to get*/
			ajaxRequest.onCompletion = function(){ mostrarValidacion('validacion',id,namePortlet,'errorLongNie','errorNieInvalido'); };	/* Specify function that will be executed after file has been found */
			ajaxRequest.runAJAX();		/* Execute AJAX function*/
		}
				
	}else{
		document.getElementById(portlet+'.'+id).style.background = 'white';
		document.getElementById('errorNieInvalido').style.display = 'none';
	}
}

function validaUserAdmin(idTypeUser){
	if(idTypeUser == 'AACC' || idTypeUser == 'AACC_WS'){
		document.getElementById('id_capaTextAacc').style.display = 'block';
		document.getElementById('id_capaVerAacc').style.display = 'block';
	}else{
		document.getElementById('id_capaTextAacc').style.display = 'none';
		document.getElementById('id_capaVerAacc').style.display = 'none';
	}
	
}

function mostrarValidacion(tipo,id,portlet,errorLong,errorValid) {

	if(tipo == 'longitud'){
		document.getElementById(portlet+'.'+id).style.background = 'red';
		document.getElementById(errorLong).style.display = 'block';
		document.getElementById(errorValid).style.display = 'none';
	}else if(tipo == 'validacion'){ 
		var resultado = ajaxRequest.response;	
		if(resultado == 'OK'){
			document.getElementById(portlet+'.'+id).style.background = 'white';
			document.getElementById(errorValid).style.display = 'none';
			document.getElementById(errorLong).style.display = 'none';
		}else{
			document.getElementById(portlet+'.'+id).style.background = 'red';
			document.getElementById(errorLong).style.display = 'none';
			document.getElementById(errorValid).style.display = 'block';		
		}		
		
		/*
		clearTimeout(id);
		document.getElementById("temporizador").removeChild(document.getElementById("imagenTemp"));
		document.getElementById("temporizador").removeChild(document.getElementById("cortinaTemp"));
		document.getElementById("temporizador").style.display = "none";
		mostrarSelects();	
		contador = 0;
		*/
	}
	
}

function cambiarIdiomaOk(){
}

function cambiarIdioma(idIdioma){
	ajaxRequest = new sack();
	var url = '/POVUDS_web/cambiarIdiomaSIServlet?idIdioma=' + idIdioma + '&timestamp=' + new Date().getTime();
	ajaxRequest.requestFile = url;	/* Specifying which file to get*/
	ajaxRequest.onCompletion = function(){ cambiarIdiomaOk(); };	/* Specify function that will be executed after file has been found */
	ajaxRequest.runAJAX();		/* Execute AJAX function*/	
}


function mostrarMapaAcceso(lista,grafico){
	var vars = {urlServicio:'/POVUDS_web/GraficoMapaTramite?tipoMapa=acceso&nocache='+new Date().getTime(),pathImages:'framework/skins/POVUDS/images/iconosflash/'};
	var params = {menu:'false', bgcolor: '#ffffff', allowScriptAccess: 'always'};
       var attributes = {id: "visorTramitesAcceso"};
	swfobject.embedSWF("/POVUDS_web/VisorTramites.swf", "visorTramitesAcceso", "650", "500", "9.0.0", "expressInstall.swf",vars, params, attributes);
	document.getElementById(lista).style.display="none";
	document.getElementById(grafico).style.display="block";
}


function mostrarMapaAccesoCasoUso(lista,grafico){
	var vars = {urlServicio:'/POVUDS_web/GraficoMapaTramite?tipoMapa=acceso&nocache='+new Date().getTime(),pathImages:'framework/skins/POVUDS/images/iconosflash/'};
	var params = {menu:'false', bgcolor: '#ffffff', allowScriptAccess: 'always'};
       var attributes = {id: "visorTramitesAcceso"};
	swfobject.embedSWF("/POVUDS_web/VisorTramites.swf", "visorTramitesAcceso", "716", "573", "9.0.0", "expressInstall.swf",vars, params, attributes);
	document.getElementById(grafico).style.display="block";
}

function mostrarListadoAccesoCasoUso(lista,grafico){
	document.getElementById(lista).style.display="block";
	document.getElementById(grafico).style.display="none";
}

function mostrarMapaEjercicio(lista,grafico){
	var vars = {urlServicio:'/POVUDS_web/GraficoMapaTramite?tipoMapa=ejercicio&nocache='+new Date().getTime(),pathImages:'framework/skins/POVUDS/images/iconosflash/'};
	var params = {menu:'true', bgcolor: '#ffffff', allowScriptAccess: 'always'};
       var attributes = {id: "visorTramitesEjercicio"};
	swfobject.embedSWF("/POVUDS_web/VisorTramites.swf", "visorTramitesEjercicio", "650", "500", "9.0.0", "expressInstall.swf",vars, params, attributes);
	document.getElementById(lista).style.display="none";
	document.getElementById(grafico).style.display="block";
}

function mostrarMapaEjercicioCasoUso(lista,grafico){
	var vars = {urlServicio:'/POVUDS_web/GraficoMapaTramite?tipoMapa=ejercicio&nocache='+new Date().getTime(),pathImages:'framework/skins/POVUDS/images/iconosflash/'};
	var params = {menu:'true', bgcolor: '#ffffff', allowScriptAccess: 'always'};
       var attributes = {id: "visorTramitesEjercicio"};
	swfobject.embedSWF("/POVUDS_web/VisorTramites.swf", "visorTramitesEjercicio", "716", "573", "9.0.0", "expressInstall.swf",vars, params, attributes);
	document.getElementById(grafico).style.display="block";
}

function mostrarListadoEjercicioCasoUso(lista,grafico){
	document.getElementById(lista).style.display="block";
	document.getElementById(grafico).style.display="none";
}

function mostrarListado(lista,grafico){
	document.getElementById(lista).style.display="block";
	document.getElementById(grafico).style.display="none";
}

function verPresentacionPortal(){
var opciones="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=670,height=480,top=85,left=140";
window.open("/POVUDS_web/PresentacionFlashPortal.jsp","",opciones);	
}

function mostrarMapaAcceso_(){
var opciones="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=670,height=480,top=85,left=140";
window.open("/POVUDS_web/GraficoDetails.jsp","",opciones);
}

function setCookie (name, value) 
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = new Date (2100,12,31);
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function submitFormOrgAsist(elemento, valor){
	document.getElementById("idModoActividad_OrgAct").value = valor;
	document.getElementById("OrganizacionAsistencia.form_OrgAsitencia").submit();	

}

function getCookie(name) 
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function cambiaValorCookie(nombre, valor)
{
	setCookie(nombre, valor);
}

function OnDivScroll(){
var lstCollegeNames = document.getElementById("lstCollegeNames");

//The following archives two things while scrolling
//a) On horizontal scrolling: To avoid vertical scroll bar in select box when the size of 
//	 the selectbox is 8 and the count of items in selectbox is greater than 8.
//b) On vertical scrolling:	To view all the items in selectbox
				
//Check if items in selectbox is greater than 8, if so then making the size of the selectbox to count of
//items in selectbox,so that vertival scrollbar won't appear in selectbox
if (lstCollegeNames.options.length > 10)
{
	lstCollegeNames.size=lstCollegeNames.options.length;
}
else
{
	lstCollegeNames.size=10;
}
}
			
//On focus of Selectbox
function OnSelectFocus(){
//On focus of Selectbox, making scroll position of DIV to very left i.e 0 if it is not. The reason behind
//is, in this scenario we are fixing the size of Selectbox to 8 and if the size of items in Selecbox is greater than 8 
//and to implement downarrow key and uparrow key functionality, the vertical scrollbar in selectbox will
//be visible if the horizontal scrollbar of DIV is exremely right.
if (document.getElementById("divCollegeNames").scrollLeft != 0)
{
	document.getElementById("divCollegeNames").scrollLeft = 0;
}
				
var lstCollegeNames = document.getElementById('lstCollegeNames');
//Checks if count of items in Selectbox is greater than 8, if yes then making the size of the selectbox to 8.
//So that on pressing of downarrow key or uparrowkey, the selected item should also scroll up or down as expected.
if( lstCollegeNames.options.length > 10)
{
	lstCollegeNames.focus();
	lstCollegeNames.size=10;
}
}			

//*****************************************************************************
// SCRIPT:    calendar.js
// PURPOSE:   Usado por calendar.htm para seleccion de fecha.
//*****************************************************************************

//*****************************************************************************
// Function:    showCalendar
//
// Despliega el calendario y setea el campo en que será escrita
//
// Argumentos:   p_strObj     - id del campo donde se escribirá la fecha.
//*****************************************************************************
function habilitarCalendar(p_strObj){

	var yearSelect = document.getElementsByName("year")[0].value;
	if(yearSelect != null && yearSelect != ""){	
		showCalendar(p_strObj,yearSelect);
	}else{
		alert("Seleccione el año del calendario");
	}
}

function showCalendar(p_strObj) {
  if (window.showModalDialog) {
      var obj = document.all[p_strObj];
      if (obj.disabled) {
    	  return;
      }
      var topPos = window.screenTop +  obj.getBoundingClientRect().bottom + 10;
      var leftPos = window.screenLeft + obj.getBoundingClientRect().left;
	  var fecha = window.showModalDialog('/POVUDS_web/Calendar.jsp?field=' + p_strObj,obj.value,'dialogWidth:360px;dialogHeight:200px;dialogLeft:' + leftPos + ';dialogTop:' + topPos + ';scroll:no;edge:sunken;help:no;status:no');
	
	  if ( String(fecha) != "undefined" ) {
	    obj.value = fecha;
	  }
  } else {
      var obj = document.getElementById(p_strObj);
      if (obj.disabled) {
    	  return;
      }
      
  	  var win = window.open('/POVUDS_web/Calendar.jsp?field=' + p_strObj +"&value=" + obj.value, "calendar", "width=360, height=180, status=no, scrollbars=no, resizable=no, modal=yes");
      win.focus();
        
  }
  
  document.getElementById(p_strObj).focus();
}

function visible(){
	document.getElementById("irBuscarFP").style.visibility ='visible';
}

function mostrarExplicacionGestor(valor){
	if (valor) {
		document.getElementById("explicacionUsuarioGestor").style.display = 'block';
	}else{
		document.getElementById("explicacionUsuarioGestor").style.display = 'none';
	}
}

