// TEXTOS DEL BUSCADOR
var TXT_DENO = "Insira o nome da empresa, marca ou NIF, e clique em pesquisar. Para pesquisar gestores clique <u style=\"cursor:pointer;font: bold; color: red;\" onclick=\"buscador_cambia_portal_inter(\'bus02\',\'bot_gestores\');\">aqui</u>.";
var TXT_DIRI = "Insira o nome do gestor e clique em pesquisar. Para pesquisar empresas clique <u style=\"cursor:pointer;font: bold; color: red;\" onclick=\"buscador_cambia_portal_inter(\'bus01\',\'bot_empresasEnis\');\">aqui</u>.";
var TXT_SUBV = "Inserte el texto del título de la subvención";
var TXT_INTER = "Inserte nombre o número duns y pulse buscar";

var ACTUAL = 1;

// numero de menus generales
var numeroMenus = 4;

// guarda el timeout
var tiempo;

// pestana bloqueada
var bloqueada = -1;

// colores de los fondos
var colormenu_on = "#96B8CF";
var colormenu_off = "#D1DEE6";
var colorsubmenu_on = "#D1DEE6";
var colorsubmenu_off = "#96B8CF";

// imagenes
imageng0 = new Image();
imageng0.src = "/img/n_web/RelatorioEmpresasOFFN.gif";
imagenr0 = new Image();
imagenr0.src = "/img/n_web/RelatorioEmpresasOFFN.gif";
// imagenr0.src ="/img/n_web/informes_empresas_off.gif";
imgc0 = new Image();
imgc0.src = "/img/n_web/RelatorioEmpresasON.gif";
// imgc0.src ="/img/n_web/informes_empresas3_off.gif";

imgn0 = new Image();
imgn0.src = "/img/n_web/RelatorioEmpresas3.gif";

imageng1 = new Image();
imageng1.src = "/img/n_web/BDMarketingOFFN.gif";
imagenr1 = new Image();
imagenr1.src = "/img/n_web/BDMarketingOFFN.gif";
// imagenr1.src ="/img/n_web/listados_marketing_off.gif";
imgc1 = new Image();
imgc1.src = "/img/n_web/BDMarketingON.gif";

imgn1 = new Image();
imgn1.src = "/img/n_web/BDMarketing3.gif";

imageng2 = new Image();
imageng2.src = "/img/n_web/EstudosePublicacoesOFFN.gif";
imagenr2 = new Image();
// imagenr2.src ="/img/n_web/gestoria_online_off.gif";
imagenr2.src = "/img/n_web/EstudosePublicacoesOFFN.gif";
imgc2 = new Image();
imgc2.src = "/img/n_web/EstudosePublicacoesON.gif";

imgn2 = new Image();
imgn2.src = "/img/n_web/EstudosePublicacoes3.gif";

imageng3 = new Image();
imageng3.src = "/img/n_web/RelatorioInternacionalOFFN.gif";
imagenr3 = new Image();
// imagenr3.src ="/img/n_web/subvenciones_concursos_off.gif";
imagenr3.src = "/img/n_web/subvenciones_concursos_offN.gif";
imgc3 = new Image();
imgc3.src = "/img/n_web/RelatorioInternacionalON.gif";

imgn3 = new Image();
imgn3.src = "/img/n_web/subvenciones_concursos3_off.gif";

imagen01 = new Image();
imagen01.src = "/img/n_web/bot_empresas_nacionales_on.gif";
imagen02 = new Image();
imagen02.src = "/img/n_web/bot_empresas_internacion_on.gif";
imagen03 = new Image();
imagen03.src = "/img/n_web/bot_directivos_on.gif";
imagen04 = new Image();
imagen04.src = "/img/n_web/bot_analisis_grupos_on.gif";
imagen05 = new Image();
imagen05.src = "/img/n_web/bot_informes_riesgo_on.gif";
imagen11 = new Image();
imagen11.src = "/img/n_web/bot_prospecta_on.gif";
imagen12 = new Image();
imagen12.src = "/img/n_web/bot_pack_on.gif";
imagen13 = new Image();
imagen13.src = "/img/n_web/bot_empresas_creacion_on.gif";
imagen14 = new Image();
imagen14.src = "/img/n_web/bot_informes_sectores_on.gif";
imagen15 = new Image();
imagen15.src = "/img/n_web/bot_publicaciones_on.gif";
imagen21 = new Image();
imagen21.src = "/img/n_web/bot_registro_mercantil_on.gif";
imagen22 = new Image();
imagen22.src = "/img/n_web/bot_registro_propiedad_on.gif";
imagen23 = new Image();
imagen23.src = "/img/n_web/bot_direccion_general_on.gif";
imagen31 = new Image();
imagen31.src = "/img/n_web/bot_subvenciones_sub_on.gif";
imagen32 = new Image();
imagen32.src = "/img/n_web/bot_concursos_sub_on.gif";
imagen41 = new Image();
imagen41.src = "/img/n_web/bot_prospecta_sub_on.gif";

img01 = new Image();
img01.src = "/img/n_web/bot_empresas_nacionales.gif";
img02 = new Image();
img02.src = "/img/n_web/bot_empresas_internacionale.gif";
img03 = new Image();
img03.src = "/img/n_web/bot_directivos.gif";
img04 = new Image();
img04.src = "/img/n_web/bot_analisis_grupos.gif";
img05 = new Image();
img05.src = "/img/n_web/bot_informes_riesgo.gif";
img11 = new Image();
img11.src = "/img/n_web/bot_prospecta.gif";
img12 = new Image();
img12.src = "/img/n_web/bot_pack.gif";
img13 = new Image();
img13.src = "/img/n_web/bot_empresas_creacion.gif";
img14 = new Image();
img14.src = "/img/n_web/bot_informes_sectores.gif";
img15 = new Image();
img15.src = "/img/n_web/bot_publicaciones.gif";
img21 = new Image();
img21.src = "/img/n_web/bot_registro_mercantil.gif";
img22 = new Image();
img22.src = "/img/n_web/bot_registro_propiedad.gif";
img23 = new Image();
img23.src = "/img/n_web/bot_direccion_general.gif";
img31 = new Image();
img31.src = "/img/n_web/bot_subvenciones_sub.gif";
img32 = new Image();
img32.src = "/img/n_web/bot_concursos_sub.gif";
img33 = new Image();

// indica si esta activado el onmouseover para las pestañas
var activado = false;


function loadURL(url){	
	window.location.href=url;
}

/**
 * muestra (int idMenu)
 * 
 * despliega el 'DIV' con id = 'menu'+idMenu y oculta el resto lo pone en la posicion que ocupe su 'ref' correspondiente
 */
function muestra(idMenu) {
	var i;

	for (i = 0; i < numeroMenus; i++) {
		var menu = document.getElementById('trozo' + i);
		var ref = document.getElementById('ref' + i);
		var sig = document.getElementById('ref' + (i + 1));

		if (!menu) {
			// alert(idMenu);
			continue;
		}

		if (i == idMenu) {
			// alert(idMenu);
			// alert(ref. + "--" + sig.value);
			if ((ref) && (sig)) {
				menu.style.top = findPosY(ref);
				menu.style.left = findPosX(ref);
				menu.style.width = findPosX(sig) - findPosX(ref);
			} else if (ref != '') {// la ultima
				menu.style.top = findPosY(ref);
				menu.style.left = findPosX(ref);
				menu.style.width = document.body.clientWidth - findPosX(ref);
			}
			menu.style.visibility = 'visible';
			menu.style.backgroundColor = colormenu_off;
			activado = true;
			activaColor(idMenu);
		} else if ((idMenu == -1) && (bloqueada == -1)) {
			menu.style.visibility = 'hidden';
			desactivaColorRojo(i);
		} else {
			menu.style.visibility = 'hidden';
			desactivaColor(i);
		}

	}
	if (idMenu < 0)
		activado = false;
}

/**
 * ocultara la capa en 1/2 segundo si no se llama con b == false
 */
function oculta(b, m) {

	if (b) {
		tiempo = setTimeout("muestra(-1)", 500);
	} else {
		if (tiempo) {
			clearTimeout(tiempo);
			muestra(m);
		}
	}
}

/**
 * ocultara la capa en 1 segundo si no se llama con b == false
 */
function ocultaM(b, m) {
	// alert(activado);
	if (b && activado) {
		tiempo = setTimeout("muestra(-1)", 500);
	} else if (b && !activado) {
		muestra(-1);
	} else if (activado) {
		if (tiempo) {
			clearTimeout(tiempo);
			muestra(m);
		}
	}
}

/**
 * devuelve la variable activado
 */
function getActivado() {
	// alert(activado);
	return activado;
}

/**
 * cambia una imagen a activada
 */
function activaColor(numero) {
	var nombre_cabecera = "imgc" + numero + ".src";

	if (document.getElementById("imageng" + numero))
		document.getElementById("imageng" + numero).src = eval(nombre_cabecera);
	if (document.getElementById('trozoa' + numero))
		document.getElementById('trozoa' + numero).style.backgroundColor = colormenu_on;

	/*
	 * if (document.getElementById("frase"+numero)){ //document.getElementById("frase"+numero).style.fontWeight= "bold"; document.getElementById("frase"+numero).style.textDecoration= "underline"; }
	 */

	return true;
}

/**
 * cambia una imagen a activada y se mantiene asi
 */
function bloqueaColor(numero) {
	var nombre_cabecera = "imageng" + numero + ".src";
	document.getElementById("imageng" + numero).src = eval(nombre_cabecera);
	document.getElementById('trozoa' + numero).style.backgroundColor = colormenu_off;
	bloqueada = numero;
	for (var i = 0; i < numeroMenus; i++) {
		if (i != numero) {
			desactivaColor(i);
		}
	}
	return true;
}

/**
 * cambia una imagen a desactivada
 */
function desactivaColor(numero) {
	if (bloqueada == numero) {
		var nombre_cabecera = "imageng" + numero + ".src";
		var completo = eval(nombre_cabecera);
		if (document.getElementById("imageng" + numero))
			document.getElementById("imageng" + numero).src = completo;
		if (document.getElementById('trozoa' + numero)) {
			document.getElementById('trozoa' + numero).style.backgroundColor = colormenu_off;
		}

		return;
	}
	var nombre_cabecera = "imageng" + numero + ".src";
	if (bloqueada != -1) {
		nombre_cabecera = "imgn" + numero + ".src";
	}
	var completo = eval(nombre_cabecera);
	if (document.getElementById("imageng" + numero))
		document.getElementById("imageng" + numero).src = completo;
	if (document.getElementById('trozoa' + numero)) {
		if (bloqueada != -1) {
			document.getElementById('trozoa' + numero).style.backgroundColor = colormenu_on;
		} else {
			document.getElementById('trozoa' + numero).style.backgroundColor = colormenu_off;
		}
	}
	return true;
}

/**
 * cambia una imagen a desactivada dejando la bola roja (para el portal)
 */
function desactivaColorRojo(numero) {
	if (bloqueada == numero)
		return;
	var nombre_cabecera = "imagenr" + numero + ".src";
	var completo = eval(nombre_cabecera);
	if (document.getElementById("imageng" + numero))
		document.getElementById("imageng" + numero).src = completo;
	if (document.getElementById('trozoa' + numero))
		document.getElementById('trozoa' + numero).style.backgroundColor = colormenu_off;
	/*
	 * if (document.getElementById("frase"+numero)){ //document.getElementById("frase"+numero).style.fontWeight= "normal"; document.getElementById("frase"+numero).style.textDecoration= "none"; }
	 */
	return true;
}

/**
 * activa el color de una opcion de un menu
 */
function selecciona(numMenu, numOpcion) {
	var nombre = "img" + numMenu + numOpcion + ".src";
	document.getElementById("imagen" + numMenu + numOpcion).src = eval(nombre);
	document.getElementById('panel' + numMenu + numOpcion).style.backgroundColor = colorsubmenu_on;
}

/**
 * desactiva el color de una opcion de un menu
 */
function deselecciona(numMenu, numOpcion) {
	var nombre = "imagen" + numMenu + numOpcion + ".src";
	var completo = eval(nombre);
	document.getElementById("imagen" + numMenu + numOpcion).src = completo;
	document.getElementById('panel' + numMenu + numOpcion).style.backgroundColor = colorsubmenu_off;
}

/*******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
 * 
 * FUNCIONES PARA LOS SUBMENUS
 * 
 ******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
function cambia_submenu_su(nombresub, menusubmenu) {
	document.getElementById(nombresub).src = '/img/n_web/' + menusubmenu + '.gif';
}

/*******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
 * 
 * FUNCIONES PARA EL BUSCADOR
 * 
 ******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/
function userPassRelleno(formulario, accion) {
	if (formulario.username.value == null || formulario.username.value == "" || formulario.password.value == null || formulario.password.value == "")
		alert("Por favor, introduza o seu utilizador e password.");
	else {
		formulario.action = accion;
		formulario.submit();
	}
}

function userPassRelleno2(LOGIN, accion) {
	if (LOGIN.username.value == null || LOGIN.username.value == "" || LOGIN.password.value == null || LOGIN.password.value == "")
		alert("Por favor, introduza o seu utilizador e password.");
	else {
		LOGIN.action = accion;
		LOGIN.submit();
	}
}

function buscador_cambia(quien, imagen, texto, tamano) {
	if (tamano == "") {
		if (document.getElementById("bus01"))
			document.getElementById("bus01").src = "/img/n_web/bot_empresas_off.gif";
		if (document.getElementById("bus02"))
			document.getElementById("bus02").src = "/img/n_web/bot_dirigente_off.gif";
		if (document.getElementById("bus03"))
			document.getElementById("bus03").src = "/img/n_web/bot_listados_off.gif";
		if (document.getElementById("bus04"))
			document.getElementById("bus04").src = "/img/n_web/bot_subvenciones_off.gif";
	} else if (tamano == "2") {
		if (document.getElementById("bus01"))
			document.getElementById("bus01").src = "/img/n_web/bot_empresasEnis_off.gif";
		if (document.getElementById("bus02"))
			document.getElementById("bus02").src = "/img/n_web/bot3_dirigente_off.gif";
		if (document.getElementById("bus03"))
			document.getElementById("bus03").src = "/img/n_web/bot3_listados_off.gif";
		if (document.getElementById("bus04"))
			document.getElementById("bus04").src = "/img/n_web/bot3_subvenciones_off.gif";
	}
	document.getElementById(quien).src = "/img/n_web/" + imagen + ".gif";
	document.buscador.accion.value = quien;
	document.getElementById("busqueda").value = '';
	if (document.getElementById("frase_buscador")) {
		switch (quien) {
			case 'bus01' :
				document.forms['buscador'].busqueda.value = TXT_DENO;
				// document.getElementById("ponefrase").innerHTML=TXT_DENO;
				break;
			case 'bus02' :
				document.forms['buscador'].busqueda.value = TXT_DIRI;
				// document.getElementById("ponefrase").innerHTML=TXT_DIRI;
				break;
			case 'bus03' :
				document.forms['buscador'].busqueda.value = TXT_DENO;
				// document.getElementById("ponefrase").innerHTML=TXT_DENO;
				break;
			case 'bus04' :
				document.forms['buscador'].busqueda.value = TXT_SUBV;
				// document.getElementById("ponefrase").innerHTML=TXT_SUBV;
				break;
		}
	}
}

function buscador_cambia_portal(quien, imagen) {

	if (document.getElementById("bus01"))
		document.getElementById("bus01").src = "/img/n_web/bot_empresasEnis_off.gif";
	if (document.getElementById("bus02"))
		document.getElementById("bus02").src = "/img/n_web/bot_gestores_off.gif";
	if (document.getElementById("bus03"))
		document.getElementById("bus03").src = "/img/n_web/bot2_listados_off.gif";
	if (document.getElementById("bus04"))
		document.getElementById("bus04").src = "/img/n_web/bot2_subvenciones_off.gif";
	document.getElementById(quien).src = "/img/n_web/" + imagen + ".gif";
	document.buscador.accion.value = quien;
	document.getElementById("busqueda").value = '';
	switch (quien) {
		case 'bus01' :
			ACTUAL = 1;
			document.getElementById("ponefrase").innerHTML = TXT_DENO;			
			break;
		case 'bus02' :
			ACTUAL = 2;
			document.getElementById("ponefrase").innerHTML = TXT_DIRI;			
			// document.getElementById("bton").style.left="-50px";
			document.getElementById('eeuu').style.visibility = "hidden";
			document.getElementById('eeuu').style.display = "none";
			document.getElementById('canada').style.visibility = "hidden";
			document.getElementById('canada').style.display = "none";
			break;
		case 'bus03' :
			document.getElementById("ponefrase").innerHTML = TXT_DENO;
			break;
		case 'bus04' :
			ACTUAL = 4;
			document.getElementById("ponefrase").innerHTML = TXT_SUBV;
			break;
	}
}

function buscador_cambia_portal_inter(quien, imagen) {
	ns = (document.layers) ? true : false;
	ie = (document.all) ? true : false;
	if (document.getElementById("bus01"))
		document.getElementById("bus01").src = "/img/n_web/bot_empresasEnis_off.gif";
	if (document.getElementById("bus02"))
		document.getElementById("bus02").src = "/img/n_web/bot_gestores_off.gif";
	if (document.getElementById("bus03"))
		document.getElementById("bus03").src = "/img/n_web/bot2_listados_off.gif";
	if (document.getElementById("bus04"))
		document.getElementById("bus04").src = "/img/n_web/bot2_subvenciones_off.gif";
	document.getElementById(quien).src = "/img/n_web/" + imagen + ".gif";
	document.buscador.accion.value = quien;
	document.getElementById("busqueda").value = '';
	switch (quien) {
		case 'bus01' :
			ACTUAL = 1;
			if (imagen == 'bot_empresasEnis') {
				document.getElementById("ponefrase").innerHTML = TXT_DENO;
			} else
				document.getElementById("ponefrase").innerHTML = TXT_DENO;
			document.getElementById("pais").style.display = "block";
			// document.getElementById("bton").style.left="0px";
			break;
		case 'bus02' :
			ACTUAL = 2;
			document.getElementById("ponefrase").innerHTML = TXT_DIRI;
			document.getElementById("pais").style.display = "none";
			// document.getElementById("bton").style.left="-50px";
			document.getElementById('eeuu').style.visibility = "hidden";
			document.getElementById('eeuu').style.display = "none";
			document.getElementById('canada').style.visibility = "hidden";
			document.getElementById('canada').style.display = "none";
			break;
		case 'bus03' :
			document.getElementById("ponefrase").innerHTML = TXT_DENO;
			break;
		case 'bus04' :
			ACTUAL = 4;
			document.getElementById("ponefrase").innerHTML = TXT_SUBV;
			document.getElementById("pais").style.display = "none";
			// document.getElementById("bton").style.left="-50px";
			document.getElementById('eeuu').style.visibility = "hidden";
			document.getElementById('eeuu').style.display = "none";
			document.getElementById('canada').style.visibility = "hidden";
			document.getElementById('canada').style.display = "none";
			break;
	}
}

function comprueba_pais_inter() {
	var pais = document.getElementById('pais').value;
	var paises = document.getElementById('pais');

	if (pais == 'US') {
		document.getElementById('eeuu').style.visibility = "visible";
		document.getElementById('eeuu').style.display = "block";
		document.getElementById('canada').style.visibility = "hidden";
		document.getElementById('canada').style.display = "none";
		//buscador_cambia_portal_inter('bus01', 'bot_empresasEnis');
	} else if (pais == 'CA') {
		document.getElementById('canada').style.visibility = "visible";
		document.getElementById('canada').style.display = "block";
		document.getElementById('eeuu').style.visibility = "hidden";
		document.getElementById('eeuu').style.display = "none";
		//buscador_cambia_portal_inter('bus01', 'bot_empresasEnis');
	} else if (pais != '') {
		document.getElementById('eeuu').style.visibility = "hidden";
		document.getElementById('eeuu').style.display = "none";
		document.getElementById('canada').style.visibility = "hidden";
		document.getElementById('canada').style.display = "none";
		document.getElementById('provincia').value = "00";
		//buscador_cambia_portal_inter('bus01', 'bot_empresasEnis');
	} else if (pais == '') {
		buscador_cambia_portal('bus01', 'bot_empresasEnis');
		document.getElementById('eeuu').style.visibility = "hidden";
		document.getElementById('eeuu').style.display = "none";
		document.getElementById('canada').style.visibility = "hidden";
		document.getElementById('canada').style.display = "none";
		document.getElementById('provincia').value = "00";
	}
}

function foco() {
	if (document.buscador) {
		if (!document.forms['frmOffline'])
			document.forms['buscador'].busqueda.focus();
	}
}

function limpiar_buscador(numerobusca) {
	if (document.getElementById('control_buscador')) {
		var nodos = document.getElementById('control_buscador');
		var txt = nodos.childNodes[numerobusca].getAttribute('value');
		if (txt == TXT_DENO || txt == TXT_DIRI || txt == TXT_SUBV)
			nodos.childNodes[numerobusca].setAttribute('value', '');
	}
}

function reset_buscador(numerobusca) {
	if (ACTUAL == 1) {
		Texto = TXT_DENO;
	} else if (ACTUAL == 2) {
		Texto = TXT_DIRI;
	} else if (ACTUAL == 4) {
		Texto = TXT_SUBV;
	} else
		return;

	if (document.getElementById('control_buscador')) {
		var nodos = document.getElementById('control_buscador');
		var txt = nodos.childNodes[numerobusca].getAttribute('value');
		if (txt == '') {
			nodos.childNodes[numerobusca].setAttribute('value', Texto);
		}
	}
}

// Para eInforma Portugal no se buscará por paises, y la comprobacion del DUNS o NIF se hará en el servidor 
// en la misma clase java en la que se busca por nombre de empresa
function comprueba_formulario_paisNOVO_SEM_PAISES(url) {
	var quebusca = document.getElementById("accion").value;
	if ((document.getElementById("busqueda").value == "")) {
		alert("Por favor, introduza a informação a pesquisar");
		document.getElementById("busqueda").focus();
	} else {
		actionFormBusqueda(url);		
	}
}

//Original de eInforma España - a usar agora para o internacional
function comprueba_formulario_pais(url) {
	var quebusca = document.getElementById("accion").value;
	if ((document.getElementById("busqueda").value == "")) {
		alert("Por favor, introduza a informação a pesquisar");
		document.getElementById("busqueda").focus();
	} else if (esDUNS(limpiarCIFNIF(document.getElementById("busqueda").value))) {
		actionFormBusqueda(url);
	} else if (document.getElementById("pais").value == "" && quebusca == "bus01") {
		alert("Debe seleccionar un pa" + decodeURI("%C3%AD") + "s");
		document.getElementById("pais").focus();
	} else {
		if ((document.getElementById("estados1")) && (document.getElementById("pais").value == "CA") && (document.getElementById("estados1").value == "")) {
			alert("Deve seleccionar uma provincia");
			document.getElementById("estados1").focus();
		} else if ((document.getElementById("estados2")) && (document.getElementById("pais").value == "US") && (document.getElementById("estados2").value == "")) {
			alert("Deve seleccionar um estado");
			document.getElementById("estados2").focus();
		} else {
			actionFormBusqueda(url);
		}
	}
}

// Intentamos que busqueda por nif vaya igual que busqueda por nombre, a
// la misma clase java
function actionFormBusqueda(url) {	
	if (document.getElementById('busqueda').value == '')
		return;		

	tipoBusqueda = document.buscador.accion.value;
	//tipoBusqueda = document.getElementById('accion').value;
	debugger;
	switch (tipoBusqueda) {
		case 'bus01' :
			document.location.href = urlBusqueda_Deno_o_Cif(url);
			break;
		case 'bus02' :
			valorProv = document.forms['buscador'].provincia.value;				
			document.location.href = url + '/provincia/' +  valorProv + '/nombre/' + document.forms['buscador'].busqueda.value + '/prod/LISTA_ADMINISTRADORES';
			//document.location.href = url + '/nombre/' + formatea(document.forms['buscador'].busqueda.value) + '/prod/LISTA_ADMINISTRADORES'; // +'/apellidos/'+document.forms['buscador'].busqueda1.value+'/prod/LISTA_ADMINISTRADORES';
			break;
		case 'bus03' :
			document.location.href = url + '';
			break;
		case 'bus04' :
			document.location.href = url + '/prod/LISTADO_SUBV/nombre/' + document.forms['buscador'].busqueda.value;
			break;
	}
}

//Original: de EInforma España, cuando se busca por nif se utilizaba otra clase java
function actionFormBusquedaBACKUP(url) {

	if (document.getElementById('busqueda').value == '')
		return;

	tipoBusqueda = document.buscador.accion.value;
	switch (tipoBusqueda) {
		case 'bus01' :
			document.location.href = urlBusqueda_Deno_o_Cif(url);
			break;
		case 'bus02' :
			document.location.href = url + '/nombre/' + formatea(document.forms['buscador'].busqueda.value) + '/prod/LISTA_ADMINISTRADORES'; // +'/apellidos/'+document.forms['buscador'].busqueda1.value+'/prod/LISTA_ADMINISTRADORES';
			break;
		case 'bus03' :
			document.location.href = url + '';
			break;
		case 'bus04' :
			document.location.href = url + '/prod/LISTADO_SUBV/nombre/' + document.forms['buscador'].busqueda.value;
			break;
	}
}

//Modificacion para que funciona con eInforma Portugal solamente, 
//cuando se busque por nif, se utiliza la misma clase java que por nombre
function urlBusqueda_Deno_o_CifNOVO(url) {
	var frm = document.buscador;
	var cif_o_razonsocial;
	var IndexProv;
	var valorProv;
	var textoIntroducido = frm.busqueda.value;
	// Casos: Espacio inicio texto
	// Espacio final texto.
	// Varios espacios concatenados.
	// Se elimina caracteres espacio del inicio y final. En JS no hay
	// funciones rtrim, trim y ltrim, por lo que usamos expresiones regulares
	inicioEspacio = /^ / // El ^ indica principio cadena
	finEspacio = / $/ // El $ indica final cadena
	variosEspacios = /[ ]+/g // El global (g) es xa obtener todas combinaciones posibles
	// Importante el orden de estas 3 sentencias, multiples espacios primero lo deja en uno
	// que luego puede ser, segun caso, que sea el de inicio de cadena o fin
	textoIntroducido = textoIntroducido.replace(variosEspacios, " ");
	textoIntroducido = textoIntroducido.replace(inicioEspacio, "");
	textoIntroducido = textoIntroducido.replace(finEspacio, "");
	debugger;
	var aux = limpiarCIFNIF(textoIntroducido);

	
	if (textoIntroducido != '') {		
		url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + textoIntroducido;
		valorProv = frm.provincia.value;
		url = url + '/provincia/' + valorProv;
	} 
	
	return url;
}

//Original de eInforma España // usado novamente para Portugal para incluir a busca internacional
function urlBusqueda_Deno_o_CifOLD(url) {
	var frm = document.buscador;
	var cif_o_razonsocial;
	var IndexProv;
	var valorProv;
	var textoIntroducido = frm.busqueda.value;
	// Casos: Espacio inicio texto
	// Espacio final texto.
	// Varios espacios concatenados.
	// Se elimina caracteres espacio del inicio y final. En JS no hay
	// funciones rtrim, trim y ltrim, por lo que usamos expresiones regulares
	inicioEspacio = /^ / // El ^ indica principio cadena
	finEspacio = / $/ // El $ indica final cadena
	variosEspacios = /[ ]+/g // El global (g) es xa obtener todas combinaciones posibles
	// Importante el orden de estas 3 sentencias, multiples espacios primero lo deja en uno
	// que luego puede ser, segun caso, que sea el de inicio de cadena o fin
	textoIntroducido = textoIntroducido.replace(variosEspacios, " ");
	textoIntroducido = textoIntroducido.replace(inicioEspacio, "");
	textoIntroducido = textoIntroducido.replace(finEspacio, "");

	var aux = limpiarCIFNIF(textoIntroducido);
	debugger;
	if (esNIFValido(aux)) {
		if (aux != '') {
			url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + aux;
		}
	} else if (esDUNS(limpiarCIFNIF(textoIntroducido))) {
		if(frm.pais.value == 'PT'){
			url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + aux;
		}
		else{
		url = url + '/screen/SProducto/prod/ETIQUETA_EMPRESA_INTER/nif/' + aux;
		}
	} else {
			if (textoIntroducido != '') {
				if ((frm.pais != null) && (frm.pais.value != 'PT')) {
				url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS_INTERNACIONAIS/razonsocial/' + formatea(textoIntroducido);
				} else
				url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + formatea(textoIntroducido);
			valorProv = frm.provincia.value;
			url = url + '/provincia/' + valorProv;
		} else {
			var IndexProv = frm.provincia.selectedIndex;
			var valorProv = frm.provincia.options[IndexProv].value;
			url = url + '/prod/PESQUISA_EMPRESAS/prod_mostrar/ETIQUETA_EMPRESA/provincia/' + valorProv;
		}
		if (frm.pais != null) {
			// alert("va con pais "+frm.pais.value);
			url = url + '/pais/' + frm.pais.value;
		}
	}
	return url;
}
//novo algoritmo - em teste
function urlBusqueda_Deno_o_Cif(url) {
	var frm = document.buscador;
	var cif_o_razonsocial;
	var IndexProv;
	var valorProv;
	var textoIntroducido = frm.busqueda.value;
	// Casos: Espacio inicio texto
	// Espacio final texto.
	// Varios espacios concatenados.
	// Se elimina caracteres espacio del inicio y final. En JS no hay
	// funciones rtrim, trim y ltrim, por lo que usamos expresiones regulares
	inicioEspacio = /^ / // El ^ indica principio cadena
	finEspacio = / $/ // El $ indica final cadena
	variosEspacios = /[ ]+/g // El global (g) es xa obtener todas combinaciones posibles
	// Importante el orden de estas 3 sentencias, multiples espacios primero lo deja en uno
	// que luego puede ser, segun caso, que sea el de inicio de cadena o fin
	textoIntroducido = textoIntroducido.replace(variosEspacios, " ");
	textoIntroducido = textoIntroducido.replace(inicioEspacio, "");
	textoIntroducido = textoIntroducido.replace(finEspacio, "");

	var aux = limpiarCIFNIF(textoIntroducido);

	if(frm.pais.value == 'PT'){ // se é PT, vai para a PESQUISA_EMPRESAS que trata nif/duns/nome em PT
		if (aux != '') {
			url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + aux;
		}
	}
	else{ //se é internacional
		if (esDUNS(limpiarCIFNIF(textoIntroducido))) { //é duns
			url = url + '/screen/SProducto/prod/ETIQUETA_EMPRESA_INTER/nif/' + aux;
		}
		else{ // é nome de empresa
			url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS_INTERNACIONAIS/razonsocial/' + formatea(textoIntroducido);
			valorProv = frm.provincia.value;
			url = url + '/provincia/' + valorProv;
		}
	}
	
	if (esNIFValido(aux)) {
		if (aux != '') {
			url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + aux;
		}
	} else if (esDUNS(limpiarCIFNIF(textoIntroducido))) {
		if(frm.pais.value == 'PT'){
			url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + aux;
		}
		else{
		url = url + '/screen/SProducto/prod/ETIQUETA_EMPRESA_INTER/nif/' + aux;
		}
	} else {
			if (textoIntroducido != '') {
				if ((frm.pais != null) && (frm.pais.value != 'PT')) {
				url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS_INTERNACIONAIS/razonsocial/' + formatea(textoIntroducido);
				} else
				url = url + '/screen/SProducto/prod/PESQUISA_EMPRESAS/razonsocial/' + formatea(textoIntroducido);
			valorProv = frm.provincia.value;
			url = url + '/provincia/' + valorProv;
		} else {
			var IndexProv = frm.provincia.selectedIndex;
			var valorProv = frm.provincia.options[IndexProv].value;
			url = url + '/prod/PESQUISA_EMPRESAS/prod_mostrar/ETIQUETA_EMPRESA/provincia/' + valorProv;
		}
		if (frm.pais != null) {
			// alert("va con pais "+frm.pais.value);
			url = url + '/pais/' + frm.pais.value;
		}
	}
	return url;
}

function esDUNS(texto) {
	if ((texto.length == 9) && (IsInteger(texto))) {
		return true;
	}

	return false;

}

function esNIFValido(nif){
	var c;
    var checkDigit = 0;
 
	if(nif=='500520658'){
		return false;
	}
	if(nif=='000000000'){
		return false;
	}
	if(nif.length<9){
		return false;
	}

        //Obtem o primeiro número do NIF
        c = nif.charAt(0);
 
        //Verifica se o primeiro número é (1, 2, 5, 6, 8 ou 9)
        if(c == '1' || c == '2' || c == '5' || c == '6' || c == '8' || c == '9')
        {
            //Calculo do Digito de Controle
            checkDigit = c * 9;
            var i = 0;
            for(i = 2; i <= 8; i++)
            {
                checkDigit += nif.charAt(i-1) * (10-i);
            }
            checkDigit = 11 - (checkDigit % 11);
 
            //Se o digito de controle é maior que dez, coloca-o a zero
            if(checkDigit >= 10)
                checkDigit = 0;
 
            //Compara o digito de controle com o último numero do NIF
            //Se igual, o NIF é válido.
            if(checkDigit == nif.charAt(8))
                return true;
        }

    return false;
}

// la funcion IsInteger(Chain) chequea si "Chain" es un numero entero sin signo valido
// La variable "Chain" es una cadena de caracteres
function IsInteger(Chain) {
	var Template = /^\d+$/ // Formato de numero entero sin signo
	return Template.test(Chain) // Compara "Chain" con el formato "Template"
}

