
/* Fichero con las funciones javascript necesarias para la web*/

function AbrirVentanaNueva(ruta,w,h){	

	popupWin = window.open(ruta, '_blank', 'resizable=no,scrollbars=no,width='+w+',height='+h);
}
var nav4 = window.Event ? true : false;
function IsNumber(evt){
//var key = nav4 ? evt.which : evt.keyCode;
var key; if(window.event){ key = event.keyCode;}else if(evt.which){ key = evt.which;}
return (key <= 13 || (key >= 48 && key <= 57) || key == 46);
}

	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){	
	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");		

}
function cierraErrorValidacion(){
	$("#mensaje").fadeOut("slow");
}
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();\" 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 avisoFormularioEliminar(Mensaje, form){	
	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=\""+form+".operacion.value='Eliminar';"+form+".submit();\" 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");		

}	

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 redimensionar(){
var estiloPubli = document.getElementById('publicidad_dcha'); 
if (estiloPubli){
	if((dimension("width") <= 900) ){	
		estiloPubli.style.position = 'absolute';	  
//		estiloPubli.style.display = 'none';
	} else { 
		var alineacion = parseInt((dimension("width")-990)/2);
		estiloPubli.style.position = 'fixed';
		estiloPubli.style.top = '55px';
		estiloPubli.style.left = (860+alineacion)+'px';
		estiloPubli.style.height= '500px';	
		estiloPubli.style.display = 'block';
	}
}
}

function dimension(tipo) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if (tipo=='width') return myWidth;
  if (tipo=='height') return myHeight;
}

window.onresize = function()
{
  if(document.all)
  {
  window.resizeEnd = (window.resizeEnd ==null)?(new Object()):window.resizeEnd;
  clearTimeout(window.resizeEnd);
  window.resizeEnd = setTimeout(onResizeEnd,1);
  }
  else
  { onResizeEnd();}
 
}

function onResizeEnd()
{
 redimensionar();
}