/*
	Classe de gestion des messages affichés par javascript
*/

var Response = Class.create();


Response.prototype = {

	initialize: function( message ) {
		this.message = message;

		/*

			<div id="overlay_26584">
				<div id="zone_175896"></div>
			</div>

		*/

		var _overlay = $("overlay_26584");

		if( ! _overlay ) {
			var objBody = document.getElementsByTagName("body").item(0);

			var objOverlay = document.createElement("div");
			with ( objOverlay) {
				setAttribute('id','overlay_26584');
				style.display = 'none';
				style.position = 'absolute';
				style.top = '0';
				style.left = '0';
				style.zIndex = '90';
			 	style.width = '100%';
			}

			Event.observe(objOverlay , "click", function() { myResponse.hideOverlay(); });

			objBody.insertBefore(objOverlay, objBody.firstChild);

			var _zone = document.createElement("div");
			_zone.setAttribute("id", "zone_175896");
			
			

			objOverlay.appendChild(_zone);
		}

	},

	display : function() {

		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }

		if( $("message_45687") ) {
			Element.remove("message_45687");
		}

		var _p = document.createElement("p");
		_p.setAttribute("id", "message_45687"); //__ id complexe pour éviter un telescopage avec la structure de le page
		_p.className = this.className;
		//_p.appendChild( document.createTextNode( this.message ) );
		_p.innerHTML = this.message ;

		$('zone_175896').appendChild( _p );

		var arrayPageSize = this.getPageSize();
		var arrayPageScroll = this.getPageScroll();

		//__ centrage de la zone
			var _size = Element.getDimensions( $("zone_175896") );

			var _top = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - _size.height ) / 2);
			var _left = ((arrayPageSize[0] - 20 - 300 ) / 2);

		with ( $("zone_175896") ) {
			style.top = (_top < 0) ? "0px" : Math.ceil(_top) + "px";
			style.left = (_left < 0) ? "0px" : Math.ceil(_left) + "px";
		}

		with( $("overlay_26584") ) {
			style.height = (arrayPageSize[1] + "px");
			style.display = "block";
		}

		//__ appel automatique pour cacher le message
		if( this.time > 0 ) {
			this.autoHide();
		}
		
		new Effect.Appear('overlay_26584', { duration: 0.2, from: 0.5, to: 1 });		
	},

	hideOverlay : function() {
		var _overlay = $('overlay_26584');

		selects = document.getElementsByTagName("select");
	    for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}

		if( _overlay ) {
			new Effect.Fade('overlay_26584', { duration: 0.3 });
		}

		if( this.timer ) {
			clearTimeout(this.timer);
		}
		
		if( typeof this.onhide == "function" ) {
			this.onhide();
		}
	},

	autoHide : function() {
		var _overlay = $('overlay_26584');

		if( _overlay ) {
			this.timer = window.setTimeout( function() {
			
				myResponse.hideOverlay();
				
			}, this.time*1000 );
		}
	},

	getPageSize : function() {

		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {
			xScroll = document.body.scrollWidth;
			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
			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 = windowWidth;
		} else {
			pageWidth = xScroll;
		}

		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
		return arrayPageSize;
	},

	getPageScroll: function() {

		var yScroll;

		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}

		arrayPageScroll = new Array('',yScroll)
		return arrayPageScroll;
	},

	setMessage : function( msg ) {
		this.message = msg;
	}

};



Event.observe(window, 'load', function() {
	myResponse = new Response();
}, false);