// loading_div.class.js
//
// 
// vigotti div loading class
function LOADING_DIV_CLASS() {

    try {

        this.loading_id = 0 ; // to avoid to close other loading progress, unique id is used (0 close all )
        
        this.DIV_STYLE = 1;


        this.show_txt = 0; // 1 = title, 2 = desc

        this.TITLE = 'Loading';
        this.DESC = '';

        this.AutoCLOSE = 4000; // autoclose interval (0 = disabled)
        this.LAST_ACTION_TIME = 0 ;


        this.DIV_STATUS = 0; // 0 = hidden, 1 = showing
        // -- float
        this.maintain_position = 1; // 0 = no, 1 = yes
        this.OBJ_floating = null; // floating div as object
        this.floating_start_Y = 300;
        this.floating_start_x = 0;
        this.floating_center_x = true;
        // - end float
        this.DIV_loading_NAME = 'div_LOADINGDIV';


        this.bool_ONLOAD_BODY_FUNCTION= false;
        this.bool_BODY_LOADED= true;
        this.ONLOAD_BODY_FUNCTION_eval = '' ;

        this.f_do_onloadbody=  function (){ // close div
            G_LOAD.bool_BODY_LOADED = true  ;
            G_LOAD.f_do_onloadbodyEVAL();
        }
        this.f_do_onloadbodyEVAL=  function (){ // close div
            if(this.bool_ONLOAD_BODY_FUNCTION == true ){
                eval( this.ONLOAD_BODY_FUNCTION_eval);
                this.bool_ONLOAD_BODY_FUNCTION = false;
            }
        }
        
        this.f_apply_STYLE =  function (){ // close div
            var HTML_CONTENT = '';

            if(this.DIV_STYLE==1){
                HTML_CONTENT = '<center><font class="text14_white">&nbsp; Loading...</font><br><br><img border="0" src="'+GLOBALS['FOLDER_img']+'load1k.gif" ></center>';
            }else if(this.DIV_STYLE==2){ // last20k
                

                this.TITLE = addslashes(this.TITLE);
                HTML_CONTENT = '<div align="center"><table border="0" width="100%" id="table56" cellpadding="4" height="100%"  cellspacing="0">\
                                  <tr>\
                                    <td align="center"><br>\
                                      <font class="text14_white"><div id="div_LOADINGDIV_frase">&nbsp; '+this.TITLE+'</div></font><br><br>\
                                      <img border="0" src="'+GLOBALS['FOLDER_img']+'load1k.gif"><br><br>\
                                      <table border="1" width="100" id="table57" cellpadding="0" background="'+GLOBALS['FOLDER_img']+'bg_bt_l.jpg" height="20" style="border-collapse: collapse" bordercolor="#CCCCCC" bgcolor="#FFFFFF"><tr><td align="center"><a href="javascript:f_hide_cachingL20k();" class="text11_orange">CANCEL</a></td></tr></table><br>\
                                    </td>\
                                  </tr>\
                                </table></div>';





            }else if(this.DIV_STYLE==3){ // referer
                HTML_CONTENT = '<table border="0" width="100%" cellspacing="0" cellpadding="0" height="80"><tr><td height="40" align="center"><font class="text14_white"><div id="div_loadingSock_txt">'+this.DESC+'</div></font></td></tr><tr><td align="center" height="40"><img border="0" src="'+GLOBALS['FOLDER_img']+'load1k.gif"></td></tr></table>';
            }

            HTML_CONTENT = '<table border="0" class="loadingBox" cellspacing="0" cellpadding="0"><tr><td align="center">'+HTML_CONTENT+'</td></tr></table>';

            //alert(this.DIV_STYLE+'\n'+HTML_CONTENT);
            if(!document.getElementById(this.DIV_loading_NAME)) return ; 
            document.getElementById(this.DIV_loading_NAME).innerHTML = HTML_CONTENT;
        }
        
        this.f_CLOSE =  function (id){ // close div
         
            if(id > 0 ) if(this.loading_id != id ) return;
            document.getElementById(this.DIV_loading_NAME).style.display ="none";
            this.DIV_STATUS = 0;
        }
        
        this.f_set_style =  function (style_id){ // open div
            this.DIV_STYLE = parseInt(style_id);
        }
        this.f_set_desc=  function (desc){ // open div
            this.DESC = desc;
        }
        this.f_set_ALL_OPEN=  function (style_id,desc){ // open div
            if(style_id > 0){
                this.f_set_style(style_id);
            }else{
                style_id = 0;
            }
            //if(style_id==2) F_loadbodyFob();
            if(desc.length > 0) this.f_set_desc(desc);
            this.f_OPEN(style_id);
        }
        this.f_OPEN =  function (id){ // open div
            if(id > 0 ) this.loading_id = id  ;
            
           
            
            this.DIV_STATUS = 1;
            this.f_apply_STYLE();
            this.f_set_last_action();
            this.f_KEEP_POSITION();
            document.getElementById(this.DIV_loading_NAME).style.display ="block";
        }

        this.f_set_last_action =  function (){ // set last action and start timer for timeout
            var b       = new Date();
            this.LAST_ACTION_TIME = b.getTime();
            if(this.AutoCLOSE >0) setTimeout("G_LOAD.f_check_autoclose("+this.LAST_ACTION_TIME+");",this.AutoCLOSE );
        }

        this.f_check_autoclose =  function (last_action){ // timeout check
            if(this.DIV_STATUS!=1) return;
            if(this.LAST_ACTION_TIME == last_action){
                this.f_CLOSE();
            }
        }


        // floating function


        this.__f_floating_center_x =  function (){ // mantain div in position
            if(!this.floating_center_x) return ;
            if(!this.OBJ_floating) return ;
            //  alert(document.body.clientWidth);
            this.floating_start_x =((document.body.clientWidth/2)-150);
          
        }

        this.__f_build_floating_obj =  function (){ // mantain div in position
            var d = document;
            var px = document.layers ? "" : "px";
            

            var id = this.DIV_loading_NAME;
            var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
            if(!el) return ;
            if(d.layers)el.style=el;
            el.sP=function(x,y){
                this.style.top=y+px;
                this.style.left=x+px;
            };
           
           
            el.y = this.floating_start_Y;
            this.OBJ_floating = el;
            this.__f_floating_center_x();
            
            this.OBJ_floating.x = this.floating_start_x;

            
        }

        this.f_KEEP_POSITION =  function (){ // mantain div in position
            var d = document;
           
            var ns = (navigator.appName.indexOf("Netscape") != -1);
            var d = document;
            var px = document.layers ? "" : "px";

            if(this.maintain_position == 0) return;
            if(this.DIV_STATUS!=1) return;
            if(!this.OBJ_floating) this.__f_build_floating_obj ();

            var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
            var dY = (pY > this.floating_start_Y) ? pY : this.floating_start_Y;
            if(!this.OBJ_floating) return ;
            this.OBJ_floating.y += (dY - this.OBJ_floating.y);
            //alert( this.floating_start_x + ', ' + pY + 'float'  + this.OBJ_floating.x +', '+this.OBJ_floating.y);
            this.OBJ_floating.sP(this.OBJ_floating.x, this.OBJ_floating.y);
            setTimeout("G_LOAD.f_KEEP_POSITION()", 200);

        }

    } catch(e){
        alert("err loading javascript ,    try refreshing browser cache \n "  + e.message + "\n ");
    }

} // end
var G_LOAD = new LOADING_DIV_CLASS();



//function F_loadbodyFob(){
    

//}


 





//G_LOAD.f_OPEN(1); // start the loading div
//G_LOAD.f_set_style(3) ;
//G_LOAD.f_set_desc("preparing table ");
///G_LOAD.f_OPEN(3); // start the loading div
//G_LOAD.f_set_ALL_OPEN(3,"preparing table ");
//

//G_LOAD.f_CLOSE(3);


if(!JSCACHE) JSCACHE = [] ;
JSCACHE.push(['loading_div.class.js',1]);
