//declaration : si la page est charg?
$(function() {
//popup information

if(document.getElementById('hdnMess').value=="Information"){
	document.getElementById('hdnMess').value="";//r??initialisation de la valeur de hdnMess pour la prochaine saisie.
	$(function() { 
    	$(document).ready(function(){
    		$.blockUI({ message: $('#popup'), css: { width: 'auto' } }); 
    	}); 

        $('#close').click(function(){ 
            $.unblockUI(); 
            return false; 
        }); 
        
        $('#buttonclose').click(function(){
        	$.unblockUI();
        	return false;
        });
        $('#imgclose').click(function(){
        	$.unblockUI();
        	return false;
        }); 
    }); 
}

//Message d'erreur
if(document.getElementById('hdnMess').value=="Erreur"){
	document.getElementById('hdnMess').value="";//r??initialisation de la valeur de hdnMess pour la prochaine saisie.
	$(function() { 
    	$(document).ready(function(){
    		$.blockUI({ message: $('#popupError'), css: { width: 'auto' } }); 
			setOnClick();
    	}); 
    }); 
}
else{
	showLoading();
}

if(document.getElementById('hdnMess').value=="Confirmation"){
	document.getElementById('hdnMess').value="";//r??initialisation de la valeur de hdnMess pour la prochaine saisie.
	$(function() { 
    	$(document).ready(function(){
    		$.blockUI({ message: $('#popupConfirmation'), css: { width: 'auto' } }); 
    	}); 

        $('#close2').click(function(){ 
            $.unblockUI(); 
            return false; 
        }); 
        
        $('#buttonclose2').click(function(){
        	$.unblockUI();
        	return false;
        });
        $('#imgclose2').click(function(){
        	$.unblockUI();
        	return false;
        }); 
    }); 
}
//Fin declaration 
});

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
};
$.preloadImages("../assets/images/loading.gif");
function showLoading(action) {
	var showLoading = document.getElementById('showLoading');
	if(action || (showLoading && showLoading.value == "true")){
		
		msg = '<div style="color:#fff;font-weight: bold;">'
			+ '   Chargement en cours ...   '
			+ '</div>'
			+ '<br><img src="../assets/images/loading.gif" />';
		
		if(showLoading) showLoading.value="false";
		
		$(function() { 
			$(document).ready(function(){
				$.blockUI(
					{ 
						message:$('#popupLoad'),
						css: { border: 'none', padding: '15px', backgroundColor:'transparent', 
							   '-webkit-border-radius': '10px','-moz-border-radius': '10px', 
							   opacity: '.5', color: '#fff'}
					}
				);
				if(!action){
					action = document.getElementById('params').value+'&showLoading=false';
				}
				else{
					action += '&showLoading=false';
				}
				setTimeout("",400);
				document.location=action;				
			}); 
		}); 
	}
}

function waiting() {
}
function setOnClick() {
	var loading = document.getElementById('showLoading');
	if(loading) loading.value="false";
	var idFromSearch = document.getElementById('idFromSearch');
	var idFrom = document.getElementById('idFrom');
	if(idFromSearch && idFromSearch.value == "true"){
		returnTo(-1);
	}else if(idFrom && idFrom.value == 'toc'){
		returnTo(-1);
	}else{
		returnTo(-2);
	}
}
function returnTo(page){
	document.getElementById("close1").onclick=function () { window.history.go(page); } ;
	document.getElementById("imgclose1").onclick=function () { window.history.go(page); };
	hrefclose = document.getElementById('hrefclose');
	if(hrefclose){
		hrefclose.onclick=function () { window.history.go(page); };	
	}
}
