﻿var divisionDestino = '';
var swTam = 0;
var cerrar = 1;
var visited = "";
          
function test()
{
    reLoad('frmLogout','logout.aspx');
    delay(3000);     
}

function cerrarSesion()
{		
   	var sw = window.parent.cerrar || cerrar;
   
    if (sw == 1)
    {
        reLoad('frmLogout','logout.aspx');
        delay(3000);     
    }
	   
    if (window.parent.cerrar)
        window.parent.cerrar = 1;
	else
		cerrar = 1;
}

function inicializarIndex()
{
    //setTrd('tdTituloSuperior','.');
    //changeBG('tdTituloSuperior','White');   
    cambiarTop(null, 1);
    cargarPaginaEnDiv('login.aspx','menu');  
    var contenido = 'contenido.aspx?opcion=' + document.getElementById('hdnContenido').value;
    cargarPaginaEnDiv( contenido ,'contenidos');
    //cargarPaginaEnDiv('contenido.aspx?opcion=1','contenidos');
}

function achicarMenu()
{
    if (swTam == 0)  //achicar
    {
        document.getElementById('tdContenidos').style.width = '99%';  
        document.getElementById('tdMenu').style.width = '1%';         		
        document.getElementById('btnAjustar').style.left='5px'; 
        document.getElementById('btnAjustar').innerHTML = document.getElementById('btnAjustar').innerHTML.replace('left.png','right.png');
        swTam = 1;       
    } 
    else 
    {
        document.getElementById('tdContenidos').style.width = '79%';  	
        document.getElementById('tdMenu').style.width = '21%';    	
        document.getElementById('btnAjustar').style.left='203px'; 
        document.getElementById('btnAjustar').innerHTML = document.getElementById('btnAjustar').innerHTML.replace('right.png','left.png'); 
        swTam = 0;
    }
}

function loginIntranet(userName) //funcion que se accesa desde el boton ir en login.aspx
{
    //llamarasincrono('bodyIntranet.aspx', 'contenidos'); 
    cargarPaginaEnDiv('menuArbol/menuArbol.aspx','menu');
    cargarPaginaEnDiv('bodyIntranet.aspx', 'contenidos');
    cambiarTop(null,1);
    Hide('Loading');
}

function cambiarClave(userName) //funcion que se accesa desde el boton ir en login.aspx
{
    //setTrd('nombreUsuario',userName);
    //llamarasincrono('bodyIntranet.aspx', 'contenidos'); 
    cargarPaginaEnDiv('cambiarClaveInicial.aspx','menu');
    cargarPaginaEnDiv('bodyIntranet.aspx', 'contenidos');
    Hide('Loading');
}


var idBold = null;
var sw = 0;
//funcion para cambiar el TOP (que es una table) de la default.aspx (se accede desde en el menu superior)
function cambiarTop(obj,opcion)
{
    sw = 1;
    divisionDestino = 'contenidos';
    var imgLogo = 'logoxb.jpg';
    var color = '#00aeef';
    var tdDestino = 'tdTituloSuperior';
    var titulo = 'Portal Extranet';
    
    if (obj)
    {
        if (idBold)
            document.getElementById(idBold).style.fontWeight = "";
            
        obj.style.fontWeight = "bold";
        idBold = obj.id;
    }
    
    switch (opcion)
    {
        case 2:
            titulo = 'Portal Privado Prestadores';
            color = '#a97bb6';  ///'#7b6093'
            break;
        case 3:
            titulo = 'Portal Privado Proveedores';
            color = '#acd25a'; ////'#8db834'
            break;
        case 4:
            imgLogo = 'logoEmpresas.jpg';
            titulo = 'Portal Privado Empresas';
            color = '#003568'; /////'#008dd9'
            break;
        case 5:
            color = '#ec008c';
            break;            
        case 6:
            titulo = 'Portal Privado SIS';
            color = '#fdb415'; /////'#8db834'
            break;

    }
    setTrd(tdDestino, titulo);
    changeBG(tdDestino, color);
    setLogo('imgLogo', 'images/' + imgLogo);
    /////cargarPaginaEnDiv('contenido.aspx?opcion=1', divisionDestino);
    sw = 0;
    Hide('Loading');
}

function cargarHref(opcion) {

    var url = 'http://cruzblanca.altavoz.net/prontus_cruzblanca/site/edic/base/port/';
    switch (opcion) {
        case 2: url += 'prestadores.html';
            break;
        case 3:
            break;
        case 4: url += 'empresas.html';
            break;
        case 5:
            break;
        case 6: url += 'sis.html';
            break;

    }
    window.open(url,'a','height=760,width=1024,scrollbars=yes,resizable=yes,directories=yes,location=yes,menubar=yes,status=yes,titlebar=yes,toolbar=yes');
}

function cargarPaginaEnDiv(pagina,div,externa)
{      
    try
    {  
        if (sw == 0)
        {
            if (idBold)
                document.getElementById(idBold).style.fontWeight = ""; 
        }     
        document.getElementById('Loading').style.display = 'block';  
        divisionDestino = div;
        test(pagina);
       
        //ret = PageLoader.LoadPage(pagina, OnComplete, OnTimeOut, OnError); 
        if (externa)
            Hide('Loading');

        //return(true);        
    }
    catch(e)
    {}
    finally
    {    
        //Hide('Loading');
    }
}

function test(pagina)
{
    if (divisionDestino== 'menu')
    {
        var a = "<iframe frameborder='0' marginheight='0' marginwidth='0' height='100%' width='100%'  id='frameLeft' src='" + pagina + "' runat='server' style='overflow: auto'></iframe>";
        document.getElementById(divisionDestino).innerHTML = a;
    }
    else      
    {
        var oFrme = document.getElementById("frame");  
        oFrme.src = pagina;
////////        var sAltoPage  = screen.height - 260;

////////        if (oFrme.contentWindow.document.body.offsetHeight <= sAltoPage)
////////        {
////////                    oFrme.contentWindow.document.body.style.scrollbarBaseColor = "";
////////            oFrme.contentWindow.document.body.style.scrollbarFaceColor = "";
////////            oFrme.contentWindow.document.body.style.scrollbar3dLightColor = "";
////////            oFrme.contentWindow.document.body.style.scrollbarShadowColor = "";
////////            oFrme.contentWindow.document.body.style.scrollbarHighlightColor = "";
////////            oFrme.contentWindow.document.body.style.scrollbarDarkShadowColor = "";
////////            oFrme.contentWindow.document.body.style.scrollbarArrowColor = "";
////////            oFrme.contentWindow.document.body.style.scrollbarTrackColor = "";
////////        }
////////        else
////////        {         
////////            oFrme.scrolling = "no";
////////            oFrme.style.scrollbarBaseColor = "White";
////////            oFrme.style.scrollbarFaceColor = "White";
////////            oFrme.style.scrollbar3dLightColor = "White";
////////            oFrme.style.scrollbarShadowColor = "White";
////////            oFrme.style.scrollbarHighlightColor = "White";
////////            oFrme.style.scrollbarDarkShadowColor = "White";
////////            oFrme.style.scrollbarArrowColor = "White";   
////////            oFrme.style.scrollbarTrackColor = "White";        
////////        }
     }
}

function OnComplete(args)
{    
    document.getElementById(divisionDestino).innerHTML = args;
    //var tdContenido = document.getElementById('tdContenidos');    
    var divContenido = document.getElementById('contenidos');    
    var iframe = divContenido.document.getElementById('frmMain');
  
    //Hide('divLoading');
}

function OnTimeOut(args)
{
    alert("Service call timed out.");
}

function OnError(args)
{
    alert("Error calling service method.");
}

function cambiarTituloMain(titulo) {

    try
    {
        window.parent.document.title = "Extranet CruzBlanca | " + titulo;
    }catch(ex) { }
}

function llamarasincrono(url, id_contenedor)
{
    var pagina_requerida = false;
    if (window.XMLHttpRequest) // Si es Mozilla, Safari etc
    {
        pagina_requerida = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject)
    { // pero si es IE
        try 
        {
            pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e)
        { // en caso que sea una versión antigua
            try
            {
                pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){}
        }
    }
    else
        return false
    
    pagina_requerida.onreadystatechange=function()
    { // función de respuesta
        cargarpagina(pagina_requerida, id_contenedor);
    }
    
    pagina_requerida.open('GET', url, true); // asignamos los métodos open y send
    pagina_requerida.send(null);
}


// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor)
{
    try 
    {
        if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1))
            document.getElementById(id_contenedor).innerHTML=pagina_requerida.responseText;
    }
    catch (e)
    {
        var x = e;
        //alert('error');
    }
}

function validafecha(input)
{
    if (input._container != null)
        input = document.getElementById(tbFechaCreacion);
    if (!validarFecha(input))
    {
        try
        {
            Show(lblError);
            setTrd(lblError,'Fecha incorrecta');
            return false;
        }
        catch(e)
        {
            alert("Fecha incorrecta.");
            input.select();
            input.focus();
            return false;
        }
    }
    else
        return true;    
}

function formatearFecha(obj)
{
    var fec = obj.value;
    obj.value = obj.value.replace('/','-');
    obj.value = obj.value.replace('/','-');
}


function pintarAction(url)
{  
    document.location.href = url;
}


function doBeforeUnload() 
{
 index.cerrarSesion(cerrarSesion_CallBack);
 return;
    //return document.location.href="logout.aspx";

//   if(window.event)
//   {
//      //window.event.returnValue = UNLOAD_MSG; // IE
//        if(event.clientY < 0 || event.altKey || event.ctrlKey)
//            return document.location.href="logout.aspx";
//    }
//   else
//      return UNLOAD_MSG; // FX
      

}


function error(msg)
{
    try
    {
        if (msg != '')
        {
            document.getElementById('tdError').style.backgroundColor = 'red';
            document.getElementById('tdError').style.color = 'white';
            setTrd('tdError',msg);
        }
        else
        {
            document.getElementById('tdError').style.backgroundColor = 'white';
            setTrd('tdError',msg);
        }
    }
    catch(e)
    {
        if (msg != '')
        {
            window.parent.document.getElementById('tdError').style.backgroundColor = 'red';
            window.parent.document.getElementById('tdError').style.color = 'white';
            setTrd('tdError',msg,1);
        }
        else
        {
            window.parent.document.getElementById('tdError').style.backgroundColor = 'white';
            setTrd('tdError',msg);
        }
    }
}


function msg(m)
{
    try
    {
        if (m != '')
        {
            document.getElementById('tdError').style.backgroundColor = 'blue';
            document.getElementById('tdError').style.color = 'white';
            setTrd('tdError',m);
        }
        else
        {
            document.getElementById('tdError').style.backgroundColor = 'white';
            setTrd('tdError',m);
        }
    } 
    catch(e)
    {
        if (m != '')
        {
            window.parent.document.getElementById('tdError').style.backgroundColor = 'blue';
            window.parent.document.getElementById('tdError').style.color = 'blue';
            setTrd('tdError',m,1);
        }
        else
        {
            window.parent.document.getElementById('tdError').style.backgroundColor = 'white';
            setTrd('tdError',m);
        }
    }
}



function verDatosUsuario()
{
    window.open('../administracion/infoUsuario.aspx','a','height=265,width=700,scrollbars=no,resizable=no,directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no');
}


function achicarSpan()
{
    if(document.getElementById('lblTexto'))
    {
       document.getElementById('lblTexto').style.width = "100px";
    }
}

