﻿// JScript File
<!--
// el código de inicialización se registra desde servidor.
/*Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(seguros_onload);
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);      
var crossobj=document.all? document.all.LoadingPanel : document.getElementById('LoadingPanel')
var iebody=(document.compatMode && document.compatMode != 'BackCompat')? document.documentElement : document.body*/
    
var crossobj;
var iebody;
var IsDebugging;
IsDebugging=0;
// los elementos que tengan el atributo LockOnPB=true se deshabilitan en un partial postback
// CtrlDisabledOnPostBack es el array de estos elementos.
var CtrlDisabledOnPostBack;

function seguros_onload(obj, args){
    try{
        resizeConsole();       
        CheckMessagBox(document.getElementById(MessageId));
        SetFocus(document.getElementById(FocusId));
        CallFunction(document.getElementById(FunctionId));
        crossobj=document.all? document.all.LoadingPanel : document.getElementById('LoadingPanel');
        iebody=(document.compatMode && document.compatMode != 'BackCompat')? document.documentElement : document.body;
        if (KeyPressed != undefined){
            document.onkeydown=KeyPressed;        
            }        
        Load();
        }
    catch(e){
        
            }                        
    }
    
function KeyPressed(e)
{
  if (!e) e=window.event;
  var code;
  if ((e.charCode) && (e.keyCode==0))
    code = e.charCode
  else
    code = e.keyCode;
  // Control de teclas presionadas
}
function resizeConsole() {
    if (document.getElementById['ctl00_Cuerpo_pnlUpdateConsoles']!=null) {
        if (ctl00_Cuerpo_pnlUpdateConsoles.style.height!=(pageContent.clientHeight-80))
            ctl00_Cuerpo_pnlUpdateConsoles.style.height=pageContent.clientHeight-80;           
        window.onresize=setResizeConsole;              
    }
}

function setResizeConsole() {
    if (document.getElementById['ctl00_Cuerpo_pnlUpdateConsoles']!=null) 
        setInterval(resizeConsole, 200);
}
    
function _BeginRequest(){
    try{BeginRequest();}catch(e){}
}

function _EndRequest(){
    try{EndRequest();}catch(e){}
}

function ProcesaError(Codigo, Message){
    if (Codigo==504){
        return "El tiempo de espera de la petición ha finalizado.";
        }
    else {
        if (IsDebugging){
            return "Se ha producido un error en la aplicación. (Error: " + Codigo +  "->" + Message + ")";
            }
        else{
            return "Se ha producido un error en la aplicación.";       
            }
        }
}    
    
function BeginRequestHandler(sender, args){
    try{
        DisabledPB(); // en una solicitud asincrona se deshabilitan los controles críticos
        }
    catch(e){}
    try{
        showtime=setInterval("positionit()",100);
        _BeginRequest();
        }
    catch(e){
            }             
    }    
function EndRequestHandler(sender, args){
    try{
        EnabledPB(); // al volver se vuelven a habilitar.
        }
    catch(e){}
    try{
       if (args.get_error() != undefined){
           if (args.get_response().get_statusCode() == '200'){
               alert(args.get_error().message);
                }
           else{
               // Error occurred somewhere other than the server page.
               alert(ProcesaError(args.get_response().get_statusCode(), args.get_error().message));
                }
            clearInterval(showtime);            
            _EndRequest();                
            args.set_errorHandled(true);                
            }    
        else{
            clearInterval(showtime);
            _EndRequest();        
            }
        }
    catch(e){}   
}               

    function DisabledPB(){
        var j;
        j = 0;
        if (CtrlDisabledOnPostBack == null){
            CtrlDisabledOnPostBack = new Array();        
            for(var i=0; i< document.forms(0).all.length; i++){
                if ((document.forms(0).all(i).LockOnPB == "true") && !document.forms(0).all(i).disabled){
                    document.forms(0).all(i).disabled = true;
                    CtrlDisabledOnPostBack[j] = document.forms(0).all(i);
                    j++;
                    }                
                }        
            }
        }
        
    function EnabledPB(){
        if (CtrlDisabledOnPostBack != null){
            for (var i=0; i<CtrlDisabledOnPostBack.length; i++){
                CtrlDisabledOnPostBack[i].disabled = false;
                }
            CtrlDisabledOnPostBack = null;
            }            
        }    
    
function CheckMessagBox(MsgObj){
    if (MsgObj != null){
        if (MsgObj.value != ""){
            var MsgTxt = MsgObj.value;
            MsgObj.value = "";
            if (MsgTxt != ''){
                alert(MsgTxt);            
                }
            }    
        }
    }
    
function SetFocus(Ctrl){
    try{
        if (Ctrl != null){
            if (Ctrl.value != ""){
                var CtrlFocus = document.getElementById(Ctrl.value);
                if (CtrlFocus != null)
                    if (!CtrlFocus.disabled){
                        CtrlFocus.focus();
                        try{CtrlFocus.select();}catch(e){} // hay objetos que 
                        setTimeout("FocusControl('" + Ctrl.value + "');", 50);
                        }
                Ctrl.value = "";
                }
            }                
        }
    catch(e){
            }               
    }

function FocusControl(ctrl){
    try{
        document.getElementById(ctrl).focus();
        }
    catch(e){
            }           
    }

function CallFunction(Ctrl){
    if (Ctrl != null){
        var Script = Ctrl.value;
        Ctrl.value = "";
        if (Script != "")
            setTimeout(Script, 10);             
        }
    }
    
function positionit(){
    try{
        //define universal dsoc left point
        var dsocleft=document.all? iebody.scrollLeft : pageXOffset
        //define universal dsoc top point
        var dsoctop=document.all? iebody.scrollTop : pageYOffset

        //if the user is using IE 4+ or Firefox/ NS6+
        if (document.all||document.getElementById){
            crossobj.style.left=parseInt(dsocleft)+5+"px"
            crossobj.style.top=dsoctop+5+"px"
            }
        }
      catch(e){}
    }
    
        
//Pone el cursor en modo epera durante un tiempo. Luego se restablece
function setCursorWait(waitTime) {
    document.body.style.cursor = 'wait';
    setTimeout('setCursorDefault()', waitTime);
}
function setCursorDefault() {
    document.body.style.cursor = 'default';
}

//Funcion usada para vaciar el control de fecha cuando no es valida.    
function OnDateError(sender, args){
    sender.Clear();
    return;
}     

if (navigator.appName != 'Microsoft Internet Explorer' && navigator.appName != 'Netscape') {
    window.onload = function() { MakeFluffHappen() }
}

function MakeFluffHappen() {
    //FluffyKittenMaker(90);
    Conflaburator(50);
}

function FluffyKittenMaker(SomeNumberThing) {
    document.body.style.opacity = SomeNumberThing / 100;
    //document.getElementById('pageContent').style.opacity = SomeNumberThing / 100;
}

function Conflaburator(SomeNumberThing) {
    if (SomeNumberThing <= 100) {
        FluffyKittenMaker(SomeNumberThing);
        SomeNumberThing += 10;
        window.setTimeout("Conflaburator(" + SomeNumberThing + ")", 40);
    }
    else {
        FluffyKittenMaker(100);
    }
}
//->
      function GetWidth()
      {
              var x = 0;
              if (self.innerHeight)
              {
                      x = self.innerWidth;
              }
              else if (document.documentElement && document.documentElement.clientHeight)
                {
                      x = document.documentElement.clientWidth;
                }
                else if (document.body)
                {
                      x = document.body.clientWidth;
              }
              return x;
      }
      function GetHeight()
      {
              var y = 0;
              if (self.innerHeight)
              {
                      y = self.innerHeight;
              }
              else if (document.documentElement && document.documentElement.clientHeight)
              {
                      y = document.documentElement.clientHeight;
              }
              else if (document.body)
              {
                      y = document.body.clientHeight;
              }
              return y;
        }

     function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function () {
                if (oldonload) {
                    oldonload();
                }
                func();
            }
        }
    }

-->

