//procedemos a que se mueva la capa cuando se mueve el scroll

function MoveLoading() {
	if (document.getElementById("DIVloading")!=null){
		var valorTop=Math.max(document.documentElement.scrollTop,document.body.scrollTop) +"px";
		var valorLeft=Math.max(document.documentElement.scrollLeft,document.body.scrollLeft) +"px";
		document.getElementById("DIVloading").style.top=valorTop; 		
		document.getElementById("DIVloading").style.left=valorLeft; 	
		if (document.getElementById("iframeloading")!=null){	
			document.getElementById("iframeloading").style.left=valorLeft;		
			document.getElementById("iframeloading").style.top=valorTop;	
			}
   }
}

MenuLoad_PrevScroll = (window.onscroll) ? window.onscroll :  new Function;

window.onscroll  = function(){
	setTimeout("MoveLoading()",10);
	MenuLoad_PrevScroll();
};

function ocultarLoading(){
	setTimeout("ocultarLoadingInstant()",1);
}

function ocultarLoadingInstant(){
if (Menu_TipoLoading==0 || Menu_TipoLoading==1)
	if (document.getElementById("loading")!=null)
		document.getElementById("loading").style.visibility='hidden';
if (Menu_TipoLoading==0 || Menu_TipoLoading==2){
	if (document.getElementById("DIVloading")!=null)
		document.getElementById("DIVloading").style.display='none';
	if (document.getElementById("iframeloading")!=null)
		document.getElementById("iframeloading").style.display='none';		
	if (document.getElementById("loading")!=null)
		document.getElementById("loading").style.visibility='hidden';		
}
}

function mostrarLoading(tipo){
    var de = document.documentElement;
    var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

	var valorTop=Math.max(document.documentElement.scrollTop,document.body.scrollTop) +"px";
	var valorWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) ;
	var valorHeight = Math.max(document.body.clientHeight,document.documentElement.clientHeight);
	
	if(Menu_TipoLoading!=1)	
		document.getElementById("Tableloading").style.height=h +'px';	
	if(Menu_TipoLoading==0){	
	if (document.getElementById("loading")!=null)
			document.getElementById("loading").style.visibility='visible';
	

	if (document.getElementById("DIVloading")!=null){
		 if(tipo!=1){
			document.getElementById("DIVloading").style.top=valorTop; 		
			document.getElementById("DIVloading").style.height=h +'px';
		 	document.getElementById("DIVloading").style.display='block';	
		
		 	if (document.getElementById("iframeloading")!=null){
				document.getElementById("iframeloading").style.top=valorTop;	
				document.getElementById("iframeloading").style.display='block';					
				document.getElementById("iframeloading").style.width=valorWidth  + 'px';						
				document.getElementById("iframeloading").style.height=valorHeight+ 'px';					
			}
		}
	}
	
	}else{	
		if ((tipo!=1) && (document.getElementById("DIVloading")!=null)){
			document.getElementById("DIVloading").style.top=valorTop; 		
			document.getElementById("DIVloading").style.height=h+'px';							
			document.getElementById("DIVloading").style.display='block';				
			if (document.getElementById("iframeloading")!=null){		
				document.getElementById("iframeloading").style.top=valorTop;	
				document.getElementById("iframeloading").style.display='block';	
				document.getElementById("iframeloading").style.width=valorWidth  + 'px';						
				document.getElementById("iframeloading").style.height=valorHeight+ 'px';								
				}
			}
		if ((tipo!=2) &&(document.getElementById("loading")!=null))
				document.getElementById("loading").style.visibility='visible';
	}
}

function mostrarLoadingTime(time,tipo){
	mostrarLoading(tipo);
	setTimeout("ocultarLoadingInstant()", time*1000);
}

function MostarLoading(){
	mostrarLoading();
}

//Debido a posibles llamadas al js que provocaria un bucle infinito si se llama a js mas de una vez habilitamos un control

if( isNaN(loading_control)){
	var loading_control=1;
	Menu_Loading_OtherLoad = (window.onload) ? window.onload :  new Function;
	
	window.onload  = function(){
		setTimeout("ocultarLoadingInstant()",10);
		Menu_Loading_OtherLoad();
	};
}


