//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popup").fadeIn("slow", function(){ popupStatus = 1; });
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		jQuery("#backgroundPopup").fadeOut("slow");
		jQuery("#popup").fadeOut("slow", function(){ popupStatus = 0; });
	//	jQuery.validationEngine.closePrompt('.formError', true);
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery("#popup").height();
	var popupWidth = jQuery("#popup").width();
	//centering
	jQuery("#popup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
	/*	"top": "15px",*/
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
	
}











$(function(document) {
  	
      	//LOADING POPUP
      	//Click the button event!
      jQuery(".popopise").click(function(){
  			if(popupStatus == 0) {
  				url_page = $(this).attr('url');

  				jQuery.ajax({
  					  url: url_page,
  					  type: 'GET',
  					  dataType: 'html',
  					  //data: 'id2usrTemp=&select=',
  					  timeout: 2000,
  					  error: function(){
  						  alert('Erreur de chargement');
  					  },
  					  success: function(html){
  						jQuery('#popup .contenu').css("display","none").html(html).fadeIn();
  						
  						//centering with css
  						centerPopup();
  						//load popup
  						loadPopup();
  
  				
    						}
    				});
  			}
        
        return false;			
      	});
      				
      	//CLOSING POPUP
      	//Click out event!
      	jQuery("#backgroundPopup, #popopise_close").click(function(){
      		disablePopup();
      	});


});