var page_sign_pop = 1;
var typ_sign_pop;
var init_sign_pop = 0;
			
/**
* Méthode qui sera appelée sur le click du bouton
*/
function getSigns(type,pag){
	//afficheCentre('loading_signs');
	if(init_sign_pop==0 || (pag!=0 && pag!=page_sign_pop)||typ_sign_pop!=type){
		if(pag!=0) page_sign_pop=pag;
		init_sign_pop = 1;
		typ_sign_pop = type;
		
		var ajax = new Ajax.Request("sign_standalone/getSigns.php",
		{method:'get',parameters:$H({'action':'get_sign','signtype':type,'page':page_sign_pop}),
			onSuccess: function (requete){
				$('liste_signs').update(requete.responseText);
				//afficheCentre('gestion_signs');
				//$('gestion_signs').show();
				overlay.display('gestion_signs');
				if($('pag_sign1')) $('pag_sign1').focus();
			}
		});
	}
	else{
		overlay.display('gestion_signs');
		if($('pag_sign1')) $('pag_sign1').focus();
	}
}

/**
*
*/
function getPagerSigns(id,type){
	if($F(id)!="" && $F(id)!=0){
		var page_sign = $F(id);
		getSigns(type,page_sign);
	}
}

/**
*
*/
function setSign(chemin){			
	var ajax = new Ajax.Request("sign_standalone/getSigns.php",
		{method:'get',parameters:$H({'action':'set_sign','chemin':chemin}),
			onSuccess: function (requete){
				$('mess_sign').update(requete.responseText);
				setTimeout(function(){$('mess_sign').update('');},1000);
			}
		}
	);
}

/**
* Class for overlay
*/
var Overlay = Class.create({
    initialize: function(){
		this.has_loaded = 0;
	
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.style.display = 'none';
		objBody.appendChild( objOverlay);                
									
		objOverlay.setAttribute('id','overlay');
					            
		var arrayPageSize = getPageSize();			
		$('overlay').setStyle({'zIndex':'15000','position':'absolute','top':'0px','left':'0px','width':arrayPageSize[0]+'px','height':arrayPageSize[1]+'px'});
    },

    /**
	    * Display the message
	    */
    display: function(id){
		objRef = this;
		
		$(id).setStyle({'zIndex':'16000'});
		if(!$('overlay').visible()){
			if(objRef.has_loaded == 0){
				//afficheCentre(id);
				new Effect.Appear('overlay',{duration: 0.1, from: 0.0, to: 0.7, afterFinish:function(){afficheCentre(id);}});
				objRef.has_loaded = 1;
			}
			else{
				$('overlay').show();
			}
		}			
		afficheCentre(id);
			
		$('overlay').observe('click', function(event){
			$('overlay').hide();
			$(id).hide();
		});
    },
	
	/**
	    * Display the message
	    */
    hide: function(id){				
		$('overlay').hide();
		//DEVANT
		$(id).hide();
    }
});

var overlay;
Event.observe(window, 'load', function() {
	overlay = new Overlay();
	new Draggable('gestion_signs');
});


 /**** LIB ****/
function returnSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var result = new Array(myWidth,myHeight);
  return result;
}

function getScrollXY() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) 		) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
		}
  return [ scrOfX, scrOfY ];
}

function windowCenter(myId) {
	var result=returnSize();
	var myWidth=result[0];
	var myHeight=result[1];
	var elementWidth=$(myId).offsetWidth;
	var elementHeight=$(myId).offsetHeight;
	var scrolls = getScrollXY();	
	//var myScrollLeft=document.documentElement.scrollLeft;
	var myScrollLeft=scrolls[0];
	//var myScrollTop=document.documentElement.scrollTop;
	var myScrollTop=scrolls[1];
	var posX=myScrollLeft+myWidth-myWidth/2-elementWidth/2;
	var posY=myScrollTop+myHeight-myHeight/2-elementHeight/2;
	//$(myId).setStyle({ 'left': posX+'px',  'top': posY+'px'});
	Element.setStyle(myId,{ 'left': posX+'px',  'top': posY+'px'});
}

function afficheCentre(id){
	windowCenter(id);
	$(id).show();
	windowCenter(id);
}
function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
