function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function paginadoListado(mipagina) {
	var ff = window.document.bava;
	ff.pagina.value = mipagina;
	ff.submit();
}

function VPrint(parametros) {
	window.open("/vprint.php?" + parametros,"","RESIZABLE=1,SCROLLBARS=YES,HEIGHT=600,WIDTH=788");
}

function vaciar(dato){
	dato.value = "";
}

function imprimir(){
	window.print();
	window.close();
}

function getRadio(ctrl){
	for(i=0;i<ctrl.length;i++)
		if(ctrl[i].checked) return ctrl[i].value;
}

function mostrarSubmenu(id){

	ocultarSubmenus(id);
	
	var pos = 0;
	if(id > 1){
		for(i=1; i<id; i++){
			flecha = 13;
			if($("#menu" + (id - i)).attr("class") == "flechamenu"){
				flecha = 31;
			}
			pos += $("#menu" + (id - i)).width() + 14 + flecha;
		}
	}
	var ancho = $("#menu" + id).width() + 14 + 31;
	$("#menu" + id).addClass("subilu");
	$("#submenu" + id).css("width", ancho + "px");
	$("#submenu" + id).css("margin-left", pos + "px");
	$("#submenu" + id).show();
}

function ocultarSubmenus(id){
	for(i = 1; i<10; i++){
		if(id != i){
			$("#menu" + i).removeClass("subilu");
			$("#submenu" + i).hide();		
		}
	}
}

function ocultarIlu(){
	for(i = 1; i<10; i++){
		$("#menu" + i).removeClass("subilu");
	}
}

function init_dw_Scroll() {
	var wndo = new dw_scrollObj("wn", "lyr1", "t1");
	wndo.setUpScrollbar("dragBar", "track", "h", 0, 0);
	wndo.setUpScrollControls("scrollbar");
}

function validarLogin(){
	ff = document.f_login;
	fallo = "";

	if(ff.Login.value==""){ fallo += "\n· Usuario."; }
	if(ff.Pass.value==""){ fallo += "\n· Contraseña."; }

	if(fallo==""){
		ff.submit();
	} else{
		alert("Los campos del formulario no pueden estar vacios.\nRevise atentamente el/los campo/s siguiente/s:\n" + fallo);
	}
}

function comprobarTel(tel){

	var telres = true;
	var cadena = "0123456789 +";
	var total = tel.length;

	if(total < 9){

		telres = false;

	} else {

		for (var contador = 0 ; contador < total ; contador++){
			if (cadena.indexOf(tel.substr(contador, 1),0) == -1){
				telres = false;
				break;
			}
		}

	}

	return telres;
}


function comprobarEmail(texto){

	var mailres = true;
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
	var arroba = texto.indexOf("@",0);

	if ((texto.lastIndexOf("@")) != arroba) arroba = -1;

	var punto = texto.lastIndexOf(".");
	for (var contador = 0 ; contador < texto.length ; contador++){
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
			mailres = false;
			 break;
		}
	}

	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
		mailres = true;
	else
		mailres = false;

	return mailres;
}

function comprobarFecha(Cadena){

	var Fecha = new String(Cadena);
	var RealFecha= new Date();

	var Ano = new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length));
	var Mes = new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")));
	var Dia = new String(Fecha.substring(0,Fecha.indexOf("/")));

	var ok = 1;

	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
		ok = 0;
	}
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		ok = 0;
	}
	if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){
		ok = 0;
	}
	if(Fecha.indexOf("/") != 2 || Fecha.lastIndexOf("/") != 5){
		ok = 0;
	}
	
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes!=2 && Dia>30) {
			ok = 0;
		}

		if (Mes==2) {
			if(Dia > 29){
				ok = 0;
			}
			else {
				if((parseInt(Ano)%4==0) && ((parseInt(Ano)%100!=0) || (parseInt(Ano)%400==0))){
					//Bisiesto
				}
				else {
					if(Dia > 28){
						ok = 0;
					}
				}
			}
		}

	}

	if(ok == 1){
		return true;
	}
	else{
		return false;
	}

}
