
/* Fichero con las funciones javascript necesarias para la web*/

function AbrirVentanaNueva(ruta,w,h){	

	popupWin = window.open(ruta, '_blank', 'resizable=no,scrollbars=yes,width='+w+',height='+h);
}

function OcultarDesplegarBloque(id){
  var identificador= document.getElementById(id);
  if (identificador){
      if (identificador.style.display == 'none'){
      	$('#'+id).fadeIn();
      }
      else{
      	$('#'+id).fadeOut();
      }
       
  }

}
function MarcarCheckbox(vector, actual){
 if (actual.checked == 1){
   for (i=0;i<vector.elements.length;i++)
      if(vector.elements[i].type == "checkbox")
         vector.elements[i].checked=1;
 }
 else{
   for (i=0;i<vector.elements.length;i++)
      if(vector.elements[i].type == "checkbox")
         vector.elements[i].checked=0;
 }

}

var nav4 = window.Event ? true : false;
function IsNumber(event){
//var key = nav4 ? evt.which : evt.keyCode;
var key; if(window.event){ key = event.keyCode;}else if(event.which){ key = event.which;}
return (key <= 13 || (key >= 48 && key <= 57) || key == 46 || !key);
}

	function esDigito(sChr){
		var sCod = sChr.charCodeAt(0);
		return ((sCod > 47) && (sCod < 58));
	}
	function valSep(oTxt){
		var bOk = false;
		bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
		bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
		return bOk;
	}
	function finMes(oTxt){
		var nMes = parseInt(oTxt.value.substr(3, 2), 10);
		var nRes = 0;
		switch (nMes){
			case 1: nRes = 31; break;
			case 2: nRes = 29; break;
			case 3: nRes = 31; break;
			case 4: nRes = 30; break;
			case 5: nRes = 31; break;
			case 6: nRes = 30; break;
			case 7: nRes = 31; break;
			case 8: nRes = 31; break;
			case 9: nRes = 30; break;
			case 10: nRes = 31; break;
			case 11: nRes = 30; break;
			case 12: nRes = 31; break;
		}
		return nRes;
	}
	function valDia(oTxt){
		var bOk = false;
		var nDia = parseInt(oTxt.value.substr(0, 2), 10);
		bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
		return bOk;
	}
	function valMes(oTxt){
		var bOk = false;
		var nMes = parseInt(oTxt.value.substr(3, 2), 10);
		bOk = bOk || ((nMes >= 1) && (nMes <= 12));
		return bOk;
	}
	function valAno(oTxt){
		var bOk = true;
		var nAno = oTxt.value.substr(6);
		bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
		if (bOk){
			for (var i = 0; i < nAno.length; i++){
			bOk = bOk && esDigito(nAno.charAt(i));
			}
		}
		return bOk;
	}
	function valFecha(oTxt){
		var bOk = true;
		if (oTxt.value != ""){
			bOk = bOk && (valAno(oTxt));
			bOk = bOk && (valMes(oTxt));
			bOk = bOk && (valDia(oTxt));
			bOk = bOk && (valSep(oTxt));
			if (!bOk){
				validacion("Fecha inválida. El formato debe ser dd/mm/aaaa");
				oTxt.value = "";
				oTxt.focus();
			}
		}
	} 
	
function validacion(Mensaje, texto, noCerrarLightbox, camposAMarcar){	

	/* document.getElementById('mensaje').style.display='none';
	document.getElementById('mensaje').innerHTML = 
		"<div class='caja_aviso'><div class='contenedor_aviso'><div class='"+						
		"aviso_alerta' style='text-align:left;'><h3>Aviso</h3>"+Mensaje+
		"<div class='aviso_cerrar'><a "+
		"href='#' onclick='cierraErrorValidacion();' >Cerrar</a></div><div class='clearer'></div></div></div></div>";
	$("#mensaje").fadeIn("slow");		 */
	var textoTitulo = texto || "Aviso";	
	document.getElementById('over').style.display='none';
	document.getElementById('fade').style.display='block';
	document.getElementById('over').innerHTML = 
		"<div class='caja_aviso'><div class='contenedor_aviso'><div class='"+						
		"aviso_alerta' style='text-align:left;'><div class=\"enlace_cerrar\" onclick=\"cierraErrorValidacion("+noCerrarLightbox+");\"><img src=\""+get_base_path()+"sites/default/themes/naviera3.0/imagenes/comun/cerrar-azul-icono.png\" alt=\"Close\" /></div><h3>"+textoTitulo+"</h3>"+Mensaje+
		"<div class='clearer'></div></div></div></div>";
	$("#over").fadeIn("fast");
	if (camposAMarcar)
		pintarCamposResaltados(camposAMarcar);
	$("#fade").click (function () {
		cierraErrorValidacion(noCerrarLightbox);
	});

}

function validacionAccionCerrar(Mensaje, texto, accion){	

	
	var textoTitulo = texto || "Aviso";	
	document.getElementById('over').style.display='none';
	document.getElementById('fade').style.display='block';
	document.getElementById('over').innerHTML = 
		"<div class='caja_aviso'><div class='contenedor_aviso'><div class='"+						
		"aviso_alerta' style='text-align:left;'><div class=\"enlace_cerrar\" onclick=\""+accion+"\"><img src=\""+get_base_path()+"sites/default/themes/naviera3.0/imagenes/comun/cerrar-azul-icono.png\" alt=\"Close\" /></div><h3>"+textoTitulo+"</h3>"+Mensaje+
		"<div class='clearer'></div></div></div></div>";
	$("#over").fadeIn("fast");
	/* if (camposAMarcar)
		pintarCamposResaltados(camposAMarcar); */
	$("#fade").click (function () {
		cierraErrorValidacion(noCerrarLightbox);
	});

}

function pintarCamposResaltados(camposAMarcar){
 for (var i=0;i<camposAMarcar.length;i++){
    
	element = document.getElementById(camposAMarcar[i]);
	if (element){
		if(!element.className) {
			element.className = "campo_a_rellenar";
		} else {
			newClassName = element.className;
			newClassName+= " ";
			newClassName+= "campo_a_rellenar";
			element.className = newClassName;		
		}
	}
 }

}

function cierraErrorValidacion(noCerrarLightbox){
	$("#mensaje").fadeOut("fast");
	$("#fade").fadeOut("fast");
	$("#over").fadeOut("fast");
	if (window.parent && window.parent.Lightbox && !noCerrarLightbox)
		window.parent.Lightbox.end();
}

function muestraContenidoLightbox(idContenido){
	if (document.getElementById(idContenido)){
		document.getElementById('over').style.display='none';
		document.getElementById('fade').style.display='block';		
		document.getElementById('over').innerHTML = "<div class='caja_aviso'><div class='contenedor_aviso'><div class=\"enlace_cerrar\" onclick=\"cierraErrorValidacion();\"><img src=\""+get_base_path()+"sites/default/themes/naviera3.0/imagenes/comun/cerrar-azul-icono.png\" alt=\"Close\" /></div>"+document.getElementById(idContenido).innerHTML+"</div></div>";
		$("#over").fadeIn("slow");
		$("#fade").click (function () {
			cierraErrorValidacion();
		});
	}
}

function avisoFormulario(Mensaje, form, variable){	
    var valor_variable = '';
	if (variable){
		valor_variable = form+".aceptar_compra.value='1';";
	}

	document.getElementById('mensaje').style.display='none';
	document.getElementById('mensaje').innerHTML = 
		"<div class='caja_aviso'><div class='contenedor_aviso'><div class='"+						
		"aviso_alerta' style='text-align:left;'><h3>Aviso</h3>"+Mensaje+
		"<div class='botones_aviso'><input type='button' onclick=\""+valor_variable+""+form+".submit();this.disabled='true';\" class='boton_web' value='Aceptar'/> &nbsp;"+
		"&nbsp;&nbsp;<input type='button' name='botonis_cerrar' value='Cancelar' onclick='cierraErrorValidacion()' class='boton_web'/></div><div class='clearer'></div></div></div></div>";
	$("#mensaje").fadeIn("slow");		

}	


function avisoEnlace(Mensaje, url){	
	document.getElementById('mensaje').style.display='none';
	document.getElementById('mensaje').innerHTML = 
		"<div class='caja_aviso'><div class='contenedor_aviso'><div class='"+						
		"aviso_alerta' style='text-align:left;'><h3>Aviso</h3>"+Mensaje+
		"<div class='botones_aviso'><input type='button' onclick=\"document.location.href='"+url+"'\" class='boton_web' value='Aceptar'/> &nbsp;"+
		"&nbsp;&nbsp;<input type='button' name='botonis_cerrar' onclick='cierraErrorValidacion()' value='Cancelar' class='boton_web'/></div><div class='clearer'></div></div></div></div>";
	$("#mensaje").fadeIn("slow");		

}	
	
function arrayVacio (array){
 if (array){
   for (var i=0;i<array.length;i++){
        if (array[i].checked){           
            return false;
        }
   }
 }
   return true;
}	


/* código para deshabilitar todos los autocomplete en formularios 
window.addEventListener?window.addEventListener("load",formularios,false):window.attachEvent("onload",formularios);
window.addEventListener?window.addEventListener("resize",redimensionar,false):window.attachEvent("onload",redimensionar);

function formularios(){ 
 redimensionar();
 for (var i=0; i<document.forms.length;i++){
	 var frm = document.forms[i];
	 if (frm){ 
	 	frm.autocomplete = 'Off';
	 	frm.setAttribute("autocomplete", "off");
	 }
 }
}
*/

function desplegarOpcion(id){
	var opcion = document.getElementById(id);
	if (opcion)
		if (opcion.style.display == 'none'){
			$("#"+id).fadeIn("slow");
		}	
		else
			$("#"+id).fadeOut("slow");
	return false;
}
function quitarOpcion(id){
	var opcion = document.getElementById(id);
	if (opcion)
		opcion.style.display = 'none';
}

function mostrarMensaje(){
     
/*	document.getElementById('mensaje').innerHTML = 
		 "<div class='caja_aviso'><div class='contenedor_aviso'><div class='"+						
		"aviso_alerta' style='text-align:left;'>Loading...<div class='clearer'></div></div></div></div>";
		
		 "<div id=\"over\" class=\"overbox\"><div id=\"content\">Loading<br /></div></div><div id=\"fade\" class=\"fadebox\">&nbsp;</div> "; 
	$("#mensaje").fadeIn("slow");		
*/
document.getElementById('over').style.display='none';
	document.getElementById('fade').style.display='block';
	document.getElementById('over').innerHTML = 
		"<div class='caja_aviso'><div class='contenedor_aviso'><div class='"+						
		"aviso_loading' style='text-align:center' ><p>Procesando datos</p><div class='clearer'></div></div></div></div>";
	$("#over").fadeIn("slow");	
}

function desplegarOpcion(id){
            var opcion = document.getElementById(id);
            if (opcion)
                if (opcion.style.display == 'none'){
                    $("#"+id).fadeIn("slow");
                }   
                else
                    $("#"+id).fadeOut("slow");
            return false;
        }

function get_base_path(){
	if (Drupal){
		return Drupal.settings.basePath;
	}
	else return "/";
}		

function muestraTexto(div,div2){
    elemento = document.getElementById(div);
	elemento2 = document.getElementById(div2);
	if (elemento && elemento2){
		document.getElementById('b_es').style.display='none';
		document.getElementById('b_fr').style.display='none';
		document.getElementById('b_en').style.display='none';
		document.getElementById('b_pt').style.display='none';
		document.getElementById('texto_es').style.display='none';
		document.getElementById('texto_fr').style.display='none';
		document.getElementById('texto_en').style.display='none';
		document.getElementById('texto_pt').style.display='none';
		elemento.style.display='block';		
		elemento2.style.display='block';		
	}
	   
}

