//FUNCIONES RELATIVAS AL LOCALIZADOR DE OFICINAS
/* 
 * -------------------------------------------------------------
 * Obtiene el valor del combo de comunidad autonoma seleccionado 
 * -------------------------------------------------------------
 */
function recoge_comuni(oficina, portal)
{
  Scomunidad=document.frmcombos.comunidad.options[document.frmcombos.comunidad.selectedIndex].value;

  if (Scomunidad < 10)
    Scomunidad = "0"+Scomunidad;

  document.location.href="/seguros/CargaOficinas.do?comboComuni="+Scomunidad+"&ofi="+oficina+"&portal="+portal;

}


/* 
 * -------------------------------------------------------------
 * Obtiene el valor del combo de provincia seleccionado 
 * -------------------------------------------------------------
 */
function recoge_provin(oficina, portal)
{
	Sprovin=document.frmcombos.provincia.options[document.frmcombos.provincia.selectedIndex].value;
	
	document.location.href="/seguros/CargaOficinas.do?comboProvin="+Sprovin+"&ofi="+oficina+"&portal="+portal;

}


/*
 *-----------------------------------------------------------------
 * Cambia pais. Agencias de viaje
 *-----------------------------------------------------------------
 */
function cambiapais(pais, portal)
{
	if (pais == "espana")
	 {
	   document.location.href="/seguros/CargaOficinas.do?&ofi=viaje&portal="+portal;
	 }
	else
	 {
       document.location.href="/seguros/ConsultaOficinas.do?&ofi=viaje&portal="+portal+"&comboComuni=01&pais="+pais.value;
	 }
}



function mostrarDiv(pais)	
{
	document.getElementById("argentina").style.display="none";
	document.getElementById("chile").style.display="none";
	document.getElementById("brasil").style.display="none";
	document.getElementById("dominicana").style.display="none";
	document.getElementById("venezuela").style.display="none";
	document.getElementById("tit").innerText="";
	
	if (pais == "argentina") document.getElementById("tit").innerText="ARGENTINA";
	if (pais == "chile") document.getElementById("tit").innerText="CHILE";
	if (pais == "brasil") document.getElementById("tit").innerText="BRASIL";
	if (pais == "dominicana") document.getElementById("tit").innerText="REP. DOMINICANA";
	if (pais == "venezuela") document.getElementById("tit").innerText="VENEZUELA";
	
	document.getElementById(pais).style.display="block";
	document.getElementById("combo_aut").style.display="none";
	document.getElementById("combo_prov").style.display="none";
	document.getElementById("bot_form").style.display="none";

}


/**********************   GFT Ini - Buscador Oficinas   *************************/
 
/* 
 * -------------------------------------------------------------
 * Obtiene la lista de Localidades para la provincia seleccionada
 * -------------------------------------------------------------
 */
function cargaLocalidades()
{
	Sprovin=document.buscadorOficinas.selProvincia.options[document.buscadorOficinas.selProvincia.selectedIndex].value;
	// Si se ha elegido la opción --Seleccione una provincia-- no se llama a ningún action y se deshabilita el combo de localidades
	if (Sprovin == "") {
		document.buscadorOficinas.localidad.value = "";
		document.buscadorOficinas.localidad.disabled = true;
		if (document.getElementById("resultadoBusqueda")){
			document.getElementById("resultadoBusqueda").style.display="none";
		}	
	} else {
		document.location.href="/seguros/ListaLocalidades.do?provincia="+Sprovin;
	}
}

/* 
 * --------------------------------------------------------------------------------------------
 * Envia los datos de búsqueda, el tipoBusqueda dependerá del botón que haya pulsado el usuario
 * --------------------------------------------------------------------------------------------
 */
function buscarOficinas(tipoBusqueda)
{	
	if (tipoBusqueda == "guiada"){
		document.buscadorOficinas.action="/seguros/BusquedaGuiada.do";
	} else {
		document.buscadorOficinas.action="/seguros/BusquedaLibre.do";
	}	
}

function ratonON(numFila){
	
	var ofi = "listOfi"+numFila;
	var dir = "listDir"+numFila;
	var cp = "listCP"+numFila;
	var loc = "listLoc"+numFila;
	
	document.getElementById(ofi).className = document.getElementById(ofi).className.replace("normalLink","seleccionado");
	document.getElementById(dir).className = document.getElementById(dir).className.replace("normalLink","seleccionado");
	document.getElementById(cp).className = document.getElementById(cp).className.replace("normalLink","seleccionado");
	document.getElementById(loc).className = document.getElementById(loc).className.replace("normalLink","seleccionado");

}

function ratonOUT(numFila){
	
	var ofi = "listOfi"+numFila;
	var dir = "listDir"+numFila;
	var cp = "listCP"+numFila;
	var loc = "listLoc"+numFila;
	
	document.getElementById(ofi).className = document.getElementById(ofi).className.replace("seleccionado","normalLink");
	document.getElementById(dir).className = document.getElementById(dir).className.replace("seleccionado","normalLink");
	document.getElementById(cp).className = document.getElementById(cp).className.replace("seleccionado","normalLink");
	document.getElementById(loc).className = document.getElementById(loc).className.replace("seleccionado","normalLink");

}

function reseteaFondo(fila, numFila){
	if (numFila%2 != 0){
		fila.style.background = "#F7F7F7" 
	} else {
		fila.style.background="white";
	}

}



//----------------------------------------------------------------------
//     Función : ordenacion
// Descripción : Redireccion a la pagina correspondiente de ordenacion
//  Parámetros : url, y la composicion de parametros para el orden y el criterio
//     Retorno : 
//       Notas : 
//----------------------------------------------------------------------
function ordenacion(url,nameParametro1,valorParametro1,nameParametro2,valorParametro2){	
	url = url + '&' +  nameParametro1 + '=' + valorParametro1 + '&' + nameParametro2 + '=' + valorParametro2;
	document.location.href = url;	 
}



/* 
 * --------------------------------------------------------------------------------------------
 * Valida que el email tenga el formato correcto
 * --------------------------------------------------------------------------------------------
 */
function validaEmail(email) { 
	var re  = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
	if (!re.test(email)) { 
		alert(errormail);
		return false; 
	} 
	return true; 
}
	
	
/* 
 * --------------------------------------------------------------------------------------------
 * Valida que el teléfono tenga el formato correcto
 * --------------------------------------------------------------------------------------------
 */
function validaTelefono(telefono) { 

	var re  = /^\d{9}$/;
	if (!re.test(telefono)) { 
		return false; 
	} 
	return true; 

}
	
	
/* 
 * --------------------------------------------------------------------------------------------
 * Valida que el teléfono tenga el formato correcto
 * --------------------------------------------------------------------------------------------
 */
function validacionDigito( cNumero ) {
// Recorremos los datos introducidos
	for ( nPos = 0; nPos < cNumero.length; nPos++ ) {
        var cCaracter = cNumero.charAt( nPos )
        if ( isNaN( parseInt( cCaracter ) ) ) {
        	return false;
        }
	}
	return true;
}

	
function validarTelefono(tel){		
	if (tel != "") {
		tel = trim(tel);
		if 	(!validacionDigito(tel)){
			alert(msg1);
	    	return false;
	 	}
		if(tel.length!=9){
	    	alert(msg2);
	    	return false;
	   }
	   num = tel.substring(0,1);
	   if(tel.length>0 && num!=6 && num!=9){
	   		alert(msg3);
	   		return false;
	   } 
	}
	return true;
}	

// Trim whitespace from left and right sides of s.
function trim(s) {
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}
		
	
/* 
 * --------------------------------------------------------------------------------------------
 * Comprueba que los campos estén rellenos y los valida antes de enviar el formulario
 * --------------------------------------------------------------------------------------------
 */	
function enviarForm(formulario){

	if(formulario.condicion.checked==false){
		formulario.robinson.value='false';
	}
	
	if (formulario.condicion.checked){
		formulario.cond.value='true';
	}else{
		formulario.cond.value='false';
	}
	formulario.submit();
}
	

function ocultar(elem){
	elem.style.display = "none";
}
function mostrar(elem){
	elem.style.display = "inline";
}

function comboResp(resp){
	if (resp.value=="email"){
		mostrar(document.getElementById('nEmail'));
		ocultar(document.getElementById('nTelf'));
		ocultar(document.getElementById('horarios'));
	}
	if (resp.value=="telefono"){
		ocultar(document.getElementById('nEmail'));
		mostrar(document.getElementById('nTelf'));
		mostrar(document.getElementById('horarios'));
	}
}


/*
function ocultar(elem){
	elem.style.visibility = "hidden";
	
}
function mostrar(elem){
	elem.style.visibility = "visible";
}
*/

/**********************   GFT Fin - Buscador Oficinas   *************************/



 
