/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
//Redimensiona una imagen
function redimensiona(imagen){
    var maxAncho = 113; //define la anchura máxima de la imagen
    var maxAlto = 72; //define la altura máxima de la imagen
    if(imagen.width > imagen.height){ //horizontal
        if (imagen.width > maxAncho){
            porcientoAnchura = parseInt(maxAncho/imagen.width*100);
            ancho = maxAncho;
            altura = parseInt(porcientoAnchura*imagen.height/100);
            imagen.height = altura;
            imagen.width = ancho;
        }
    }else{ //vertical
        if (imagen.height > maxAlto){
            porcientoAltura = parseInt(maxAlto/imagen.height*100);
            alto = maxAlto;
            anchura = parseInt(porcientoAltura*imagen.width/100);
            imagen.width = anchura;
            imagen.height = alto;
        }
    }
    return true;
}

//Redimensiona una imagen
function redimensionaLista(imagen){
    var maxAncho = 75; //define la anchura máxima de la imagen
    var maxAlto = 75; //define la altura máxima de la imagen
    if(imagen.width > imagen.height){ //horizontal
        if (imagen.width > maxAncho){
            porcientoAnchura = parseInt(maxAncho/imagen.width*100);
            ancho = maxAncho;
            altura = parseInt(porcientoAnchura*imagen.height/100);
            imagen.height = altura;
            imagen.width = ancho;
        }
    }else{ //vertical
        if (imagen.height > maxAlto){
            porcientoAltura = parseInt(maxAlto/imagen.height*100);
            alto = maxAlto;
            anchura = parseInt(porcientoAltura*imagen.width/100);
            imagen.width = anchura;
            imagen.height = alto;
        }
    }
    return true;
}

function desactivarCapa(capa) {
    div = document.getElementById(capa);
    div.style.display="none";
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function showCookies() {
   
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        document.write("COOKIE "+i+":: "+c);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}


function mostrarDocumento(doc_url, titulo) {
    var especificaciones="top=0, left=0, toolbar=no,location=no, status=no,menubar=yes,scrollbars=no, resizable=yes"
    window.open(doc_url,titulo,especificaciones);
}

function resizeFrame ( )
    {            
            var frameCook = readCookie('brmuframecook');
            //bucle de espera para leer la cookie
            //alert(frameCook+'-'+document.getElementById("ventanaFrame").height);
            if(frameCook != null){
                try{
                  document.getElementById("ventanaFrame").height = parseInt(frameCook)+50;
                } catch(e) {
                }
                
                //document.cookie = 'brmuframecook=; path=/; domain=.carm.es';
                //alert(document.getElementById("ventanaFrame").height);
            }
            //clearInterval(inter);
      // (do something here)
    }
    
function getSesionHide (url_val, url_abnet)
    {    
       
      //if(readCookie('brmusesion')== null){
        var sesionCook = readCookie('brmusesionhide');
        //sesionCook = sesionCook.substring(sesionCook.indexOf("abnetopac")+9,sesionCook.indexOf("NT1"));
        //'/cgi-bin3/abnetopac/O7090/IDf963f7fe/NT1?ACC=120'
        //bucle de espera para leer la cookie
        //alert(frameCook+'-'+document.getElementById("ventanaFrame").height);
        if(sesionCook != null){
           document.getElementById("ventanaSesionHide").location = url_abnet + sesionCook;
           //alert(url_abnet + sesionCook);
           var contenido = readCookie('brmusesioncontent');
           
           if(contenido != ''){
              document.getElementById("ventanaSesionHide").location = url_val + sesionCook;
              //alert(url_val  + sesionCook);
              //alert('Nueva Cookie:'+readCookie('brmusesionhide'));
           }else{   
              var date = new Date(); 
              date.setTime(date.getTime()+(0.042*24*60*60*1000)); 
              document.cookie = 'brmusesionhide=; expires='+date.toGMTString()+'; path=/; domain=.carm.es';
              //alert('Cookie borrada:'+readCookie('brmusesionhide'));
              
           }

        }
     // }
      
    }    
