/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

if (document.getElementById){ //DynamicDrive.com change
	document.write('<style type="text/css">\n');
	document.write('.submenu{display: none;}\n');
	document.write('</style>\n');
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}


function abreVentana(ruta,nombre,ancho,alto,herramientas,conScroll,dimensionable){
    var t,l,w,h,prop;

	if (ancho == "undefined") {
		ancho = 450;
		alto = 350;
	}

	if (herramientas == "undefined") { herramientas = 0; }
	if (conScroll == "undefined") { conScroll = 0; }
	if (dimensionable == "undefined") { dimensionable = 0; }		

	t=(screen.height-alto)/2;
	l=(screen.width-ancho)/2;
	if(l<0){ //mas de 800*600
		w=800+l*2;
		h=w/16*9;
		l=0;
	}else{
		w=930;
		h=550;
	}
	prop="scrollbars=no,resizable=no,status=no,width="+ancho+",height="+alto+",top="+t+",left="+l+",toolbar="+herramientas+",scrollbars="+conScroll+",resizable="+dimensionable;
	ventana = window.open(ruta,nombre, prop);   
}

function trim(value) {
	var temp = value;
	var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
	if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
	var obj = / +/g;
	temp = temp.replace(obj, " ");
	if (temp == " ") { temp = ""; }
	return temp;
}

	function compruebaDato(tipo,objeto,entero){
		if (tipo == "N"){
			if (entero)
				refnovalida = /[^0-9.]/ ; // expresión regular.    
			else 
				refnovalida = /[^0-9]/ ; // expresión regular.   
						
			if (refnovalida.test(objeto.value))      
				return false;
		}

		if (tipo == "A"){
			refnovalida = /[^A-Za-z]/ ; // expresión regular.    
						
			if (refnovalida.test(objeto.value))     
				return false;
		}
		
		if (tipo == "AN"){
			refnovalida = /[^A-Za-z0-9]/ ; // expresión regular.    
						
			if (refnovalida.test(objeto.value))      
				return false;
		}
		
		if (tipo == "ANE"){
			refnovalida = /[^A-Za-z0-9@|#$%&\{\}\_\-¡!¿?]/ ; // expresión regular.    

			if (refnovalida.test(objeto.value))     
				return false;
		}	
		return true;		
	}


//--------- Funciones para comprobar fechas --------------------
	var a, mes, dia, anyo, febrero;
	function anyoBisiesto(anyo){
		if (anyo < 100)
			var fin = anyo + 1900;
		else
			var fin = anyo ;

		if (fin % 4 != 0)
			return false;
		else{
			if (fin % 100 == 0){
				if (fin % 400 == 0){
					return true;
				}else{
					return false;
				}
			}else{
				return true;
			}
		}
	}

    function validarFecha(obj){
		cadenaError = "";
		a=obj;
		dia=a.split("/")[0];
		mes=a.split("/")[1];
		anyo=a.split("/")[2];
       
		if(anyoBisiesto(anyo))
			febrero=29;
		else
			febrero=28;

		if ((mes<1) || (mes>12))
			cadenaError = "- El mes introducido no es valido. Por favor, introduzca un mes correcto\n";

		if ((mes==2) && ((dia<1) || (dia>febrero)))
			cadenaError = "- El dia introducido no es valido. Por favor, introduzca un dia correcto\n";

		if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31)))
			cadenaError = "- El dia introducido no es valido. Por favor, introduzca un dia correcto\n";

		if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30)))
			cadenaError = "- El dia introducido no es valido. Por favor, introduzca un dia correcto\n";

		if ((anyo<1900) || (anyo>2020))
			cadenaError = "- El año introducido no es valido. Por favor, introduzca un año entre 1900 y 2020\n";
		  
		return cadenaError;
    }  

	function redondeaNumero(value, precision){
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = 0;
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        return result;
	}	


//--------------------------- FUNCIONES PARA VALIDAR CUANTA BANCARIA -------------	
	function obtenerDigito(valor){
		valores = new Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
		control = 0;

		for (i=0; i<=9; i++)
			control += parseInt(valor.charAt(i)) * valores[i];

		control = 11 - (control % 11);

		if (control == 11) control = 0;
		else if (control == 10) control = 1;

		return control;
	}


	function validaCuentaCorriente(entidad,sucursal,dc,cuenta) {
		if (entidad.length != 4 || sucursal.length != 4 || dc.length != 2 || cuenta.length != 10)
			return false;
		else {
			if (!(obtenerDigito("00" + entidad + sucursal) == parseInt(dc.charAt(0))) || !(obtenerDigito(cuenta) == parseInt(dc.charAt(1))))
				return false;
			else
				return true;
		}
	}	
//--------------------------------------------------------------------