var login=0; //deslogueado

/*
if (screen.width + "x" +screen.height == "640x480") location.href="pagina640x480.htm"
if (screen.width + "x" +screen.height == "800x600") location.href="pagina800x600.htm"
if (screen.width + "x" +screen.height == "1024x768") location.href="pagina1024x768.htm"
*/
function cargar_inicial(url_content){
	if (url_content!=''){	
		cargar_get(url_content,'content');
		//url_contents.push(url_content);
	}
}


function cargar_content(url_content){
	if (url_content!=''){	
		cargar_get(url_content,'content');
	}
}

function validar_login()
{
	    var ajax=nuevo_ajax(); 
        //peticionamos los datos, le damos la url enviada desde el link
		usu = document.getElementById("user").value;
		cla = document.getElementById("pass").value;
        ajax.open("POST", "modulos/login/php/valida.php",true);
		var vars="usu="+ usu + "&cla=" + cla;
        ajax.onreadystatechange=function(){
                if(ajax.readyState==1){
					
                }else 
				if(ajax.readyState==4){
                        if(ajax.status==200){
							
							//alert(ajax.responseText);
							if (ajax.responseText=='Error Logueo')
							{
									alert('Usuario o contraseña inválidos.');
							}
							else
							{
								id_header = document.getElementById("header");
								id_header.className='show';
								cargar_post('modulos/login/php/cargar_modulos.php','content','');
								login=1;
							}

						}else if(ajax.status==404){
							alert('Error: La página no existe');
    					}else{
                            alert("Error:".ajax.status); 
                        }
                }
        }
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", vars.length);
      	ajax.setRequestHeader("Connection", "close");
		ajax.send(vars);

	
}

function reload_session(id_sysform01,callback)
{
	    var ajax=nuevo_ajax(); 
        //peticionamos los datos, le damos la url enviada desde el link
        ajax.open("POST", "php/reload_session.php",true);
		var vars="id_sysform01="+ id_sysform01;
        ajax.onreadystatechange=function(){
                if(ajax.readyState==1){
					
                }else 
				if(ajax.readyState==4){
                        if(ajax.status==200){
							callback();

						}else if(ajax.status==404){
							alert('Error: no se pudo recargar la session');
    					}else{
                            alert("Error:"+ajax.status); 
                        }
                }
        }
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.setRequestHeader("Content-length", vars.length);
      	ajax.setRequestHeader("Connection", "close");
		ajax.send(vars);
	
}


function logout()
{
	var answer = confirm ("Esta seguro que quiere cerrar la sesión?");
	if (answer)
	{
		login=0;
		ejecutar_get('php/logout.php');
		cargar_inicial('templates/form_login.html');
		id_menu = document.getElementById("menu_principal");
		id_menu.className='hide';
			
	}
	
}

function acceptNum_valida(evt)
{
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
 if (evt.keyCode == 13)
 {
	validar_login(); 
 }
 
}

function acceso_denegado()
{	
	alert('No tiene acceso para realizar la operación.');
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}


var nav4 = window.Event ? true : false;
function acceptNum(evt)
{
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
	var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
}

function acceptFloat(e)
{
    switch( e.keyCode ) {
        case 48: //0
        case 49: //1
        case 50: //2
        case 51: //3
        case 52: //4
        case 53: //5
        case 54: //6
        case 55: //7
        case 56: //8
        case 57: //9
        case 48: //10
        case 37: //left
        case 39: //right
        case 8:  //tab
        case 13: //return
        case 46: //del
        case 190: //.
            return;
    }
    e.preventDefault();
}


/*
   myInput.keydown(function() {
       var text = this.val
       if(!/^\d/.test(text)) {
          return '';
       } else {
          done = text.match(/^(\d+\.\d\d)/);
          if (done) { return done[0]; }

          last_char = text.substr(text.length-1,1);
          decimal_count = text.replace(/[^\.]/g,'').length;

          if (decimal_count < 1) {
             if (!/[\d\.]/.test(last_char)) {
                return text.substr(0,text.length-1);
             }
          } else if (decimal_count == 1 && last_char == '.') {
             return text;
          } else {
             if (!/[\d]/.test(last_char)) {
                return text.substr(0,text.length-1);
             }
          }
          return text;
       }
    });


*/