﻿// JScript File

//Quita los caracteres del lado izquierdo
function lTrim(value){
var ix=0;
var s=value;
    
    while(s.charAt(0) == ' '){
        s = s.substring(1, s.length);
        ix++;
    }
    return s;
}

//valida que tenga un formato de tipo fecha válido para el cliente: dd/mm/yyyy
function validaFc_Client(value){
var bOk=true;
var s=value;    
var dia = new Number(0);
var mes = new Number(0);
var año = new Number(0);
    
    arr=s.split("/");
    if(arr[0] != value){ //controlo si hay un "/" en la fecha
        if(arr.length == 3){ //controlo si me genero un array de 3 elementos (dia, mes y año)
            //controlo que el día este entre 1 y 31
            dia = parseInt(arr[0]);
            if(dia < 1 || dia > 31)
            {
                bOk=false;
            }else{
                //controlo que el mes este entre 1 y 12
                if (arr[1].charAt(0) == 0)
                    mes = parseInt(arr[1].substring(1));   
                else
                    mes = parseInt(arr[1]);
                    
                if(mes < 1 || mes > 12){
                    bOk=false;
                }else{    
                    //controlo que el año este entre 1990 y 2050
                    año=parseInt(arr[2]);
                    if(año < 1990 || año > 2050){
                        bOk=false;
                    }else{
                       //controlo fin de mes      
                        if( (mes == 2 && dia > 28) || (mes == 4 && dia > 30) || (mes == 6 && dia > 30) || 
                        (mes == 9 && dia > 30) || (mes == 11 && dia > 30) ){
                            bOk=false;
                        }
                    }    
                }    
            }       
        }else{
            bOk=false;
        }
    }else{
        bOk=false;
    }  
    return bOk;
}


//amplia la ventana al máximo de la resolución de pantalla
function amplia_ventana(){
    resizeTo(screen.width, screen.height)
    moveTo(0, 0);
}

//centra en el medio de la pantalla una ventana
function centra_ventana(){
    var left = screen.width / 2;
    var top = screen.height / 2;
    
    moveTo(left, top);
    
}

//cambia el puntero del mouse
//tipos: pointer, default, wait, ect
function change_pointer(type){
    window.document.body.style.cursor=type;
}

//te redirecciona a la url especificada
function redireccionar(url){
    document.location.href = url;
} 


//Controla que la página de un iframe no pueda ser
//llamada fuera de este.
//url: página que contiene el iframe a donde se debe redireccionar.
function controla_iframe(url)
{
    if(top.location==self.location)
    {
        document.location.href = url;
    }
}


//Controla que la página no pueda ser llamada desde un iframe
function not_in_iframe()
{
    if(top.location != self.location)
        top.location = self.location;
}

//Cambia el valor del contenido de el control especificado
function change_value(id, value){ 
    
    var win = window.parent;
    var ctrl = win.document.getElementById(id);
    
    if('textContent' in ctrl) {
        ctrl.textContent = value;
    } else if('innerText' in ctrl) {
        ctrl.innerText = value;
    } else {
        // algo... tirar un error o algo...
    }
}

function OpenPopPup(url, width, height){
    var left = (screen.width / 2) - 270; 
    var top = (screen.height / 2) - 90;
    
    var parametros="width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",status=yes,toolbar=no,menubar=no,location=no";
    
    window.open(url,null,parametros);
}

function resize_iframe(ctrlId)
{
    //find the height of the internal page
    var the_height = document.getElementById(ctrlId).contentWindow.document.body.scrollHeight;
    
    //if the height is higher than 500px
    //change the height of the iframe
    if(the_height >= 500)  
        document.getElementById(ctrlId).height = the_height + 20;
}