/* Javascript for popup message */
/*-----------------------------------------------------------
|															|
|	Creation date: 09-03-2007				 				|
|	Created by: Pieter Portauw 				 				|
|   Description: Creating the graybackground to gray-out 	|
|				 the webpage and the creation of the popup	|
|				 message.									|
|				 											|
|	Constructor: message = new popupMessage(upperDiv)		|		
|	Methods: displayMessage(url)							|
|			 displayResponse(div, response)					|
|			 closePopup()									|
|			 setCssClassMessageBox(cssClass)				|	
|			 resizePopup()									|
|											 				|
-------------------------------------------------------------
*/
popupMessage = function(globalDivId)
{
	_init(globalDivId);
	

}

popupMessage.prototype = {
	// displayAlert can be used to display the gray background, the messageBox and the insertion of the data
	displayAlert : function (text) {
		_createTransparentDiv();
			_createMessageDiv ();
		document.getElementById("messageDiv").innerHTML = text;
		
		
	},
	
	// displayMessage can be used to display the gray background, the messageBox and the insertion of the data
	displayMessage : function (url) {
	
		_createTransparentDiv();
		_insertData("messageDiv", url);
		_createMessageDiv();
		
	},
	
	// displayResponse is used to display the response in the selected div (in most cases that would be messageDiv)
	displayResponse : function(div, response){
		document.getElementById(div).innerHTML = "";
		document.getElementById(div).innerHTML = response;
		_createMessageDiv();
		
			
		
	},
	
	
	// closePopup can be used to hide the gray background and messagebox
	closePopup : function(){
		document.getElementById("messageDiv").parentNode.removeChild(document.getElementById("messageDiv"));
		document.getElementById("transDiv").parentNode.removeChild(document.getElementById("transDiv"));
		_unHideSelects();
		_unHideObjects();
		
		
	},
	
	// setCssClassMessageBox can be used to change the css class for the messageBox
	setCssClassMessageBox : function(cssClass){
		
		messageBoxClass = cssClass;
		_createMessageDiv();
	},
	
	//When the browser size is changed, this method is called to rechange the size and postion of the popup message and the transparentDiv
	resizePopup : function (){
		_createTransparentDiv();
		_createMessageDiv();
		
	}
}


	// Initialising the messageBox and the transparentBox	
	function _init(globalDivId){	
		messageHeight = 220;													// Default value for messageHeight
		messageWidth = 425;														// Default value for messageWidth
		messageBoxClass = "messageBox";											// Default css class for messageBox
		transDiv = document.createElement('div');							
		messageDiv = document.createElement('div');
		messageDiv.setAttribute('id', "messageDiv");
		transDiv.setAttribute('id',"transDiv");
		document.getElementById(globalDivId).appendChild(transDiv);
		document.getElementById(globalDivId).appendChild(messageDiv);
		
	}
	
	 
	// SET ALL ATTRIBUTES / PARAMETERS FOR TRANSPARENT DIV
	 function _createTransparentDiv() {
		var heightWidth = _getDocSize();
		var docWidth = heightWidth[0];
		var docHeight = heightWidth[1];	
		var transdiv = document.getElementById("transDiv");
		transdiv.style.display='block';
		transdiv.style.width = docWidth+'px';
		transdiv.style.height = docHeight+'px';
		transdiv.style.left = 0;
		transdiv.style.top = 0;
		transdiv.style.position = "absolute";
		transdiv.style.filter="alpha(opacity=60)";
		transdiv.style.opacity="0.6";
		transdiv.style.backgroundColor="#AAA";
		transdiv.style.border="0px";
		transdiv.style.zIndex="1000";
		
		var nav = BrowserDetect.browser;
	  	var navNr = BrowserDetect.version; 
	  	var navig = nav; 
	  	if (navig == 'Explorer' && (navNr == '6' || navNr == '5.5')){
			_hideSelects();
	  	}
		_hideObjects();
		
		
	}
	
	// SET ALL ATTRIBUTES / PARAMETERS FOR MESSAGE DIV
	function _createMessageDiv () {
		var messageDiv = document.getElementById("messageDiv");
		messageDiv.className = messageBoxClass;
		if (document.getElementById("mailLayout") != null){
			messageHeight = document.getElementById("mailLayout").offsetHeight;	
		}
		
		
		messageDiv.style.display='block'; 
		messageDiv.style.float='none'; 
		messageDiv.style.width = messageWidth+100+'px';
		messageDiv.style.height = messageHeight+18+'px';
		messageDiv.style.position = "absolute";
//		var test		document.getElementsByTagName("select")
			var scrollHeight = _f_scrollTop();
			var heightWidth = _getNavSize();
			var navWidth = heightWidth[0];
			var navHeight = heightWidth[1];	
		messageDiv.style.left = (navWidth/2 - (messageWidth+100)/2)+'px';
		if (navHeight <= messageHeight){
			messageDiv.style.top =  (scrollHeight + 10)+'px';
		}
		else{
			messageDiv.style.top =  (scrollHeight + 30)+'px';
		}		
	}
	
	// RETURNS THE HEIGHT AND WIDTH OF THE PAGE IN AN ARRAY
	function _getNavSize() {
	  var myWidth = 0, myHeight = 0;
	  
	  var nav = BrowserDetect.browser;
	  var navNr = BrowserDetect.version; 
	  var navig = nav; 
	  
	  if (navig == 'Opera'){
		  myHeight = window.innerHeight;
	  }else
	  
	  {
		  myHeight = document.documentElement.clientHeight;
	  }
	  myWidth = document.body.clientWidth;	 
	  return [myWidth, myHeight];  
	}
	
	function _hideSelects() {
		
		var selectList =document.getElementsByTagName("select");
		var max = selectList.length
		for(var i = 0;i < max;i++)
   		{
  		 	var nodeObj = selectList.item(i)
   			nodeObj.style.visibility = 'hidden';
   			
   		}
		
		
	}
	
	function _hideObjects(){
		var objectList =document.getElementsByTagName("Object");
		var max = objectList.length
		for(var i = 0;i < max;i++)
   		{
  		 	var nodeObj = objectList.item(i)
   			nodeObj.style.visibility = 'hidden';
   			
   		}
		
	}
	
	function _unHideObjects(){
		var objectList =document.getElementsByTagName("Object");
		var max = objectList.length
		for(var i = 0;i < max;i++)
   		{
  		 	var nodeObj = objectList.item(i)
   			nodeObj.style.visibility = 'visible';
   			
   		}
	}
	
	function _unHideSelects() {
		
		var selectList =document.getElementsByTagName("select");
		var max = selectList.length
		for(var i = 0;i < max;i++)
   		{
  		 	var nodeObj = selectList.item(i)
   			nodeObj.style.visibility = 'visible';
   			
   		}
		
	} 
	
	function _getDocSize() {
	  var pageWidth = 0, pageHeight = 0;
	  if( window.innerHeight && window.scrollMaxY ) // Firefox 
	  	{
		//pageWidth = window.innerWidth + window.scrollMaxX;
		pageHeight = window.innerHeight + window.scrollMaxY;
		}
		else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
		{
		//pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
		}
		else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		{ 
		//pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
		pageHeight = document.body.offsetHeight + 		document.body.offsetTop; 
		}
	  pageWidth = document.body.clientWidth;
	  return [pageWidth, pageHeight];  
	}
	
	// INSERTS THE DATA FROM A FILE INTO THE MESSAGEBOX
	function _insertData(divId, url){	
	
		var ajaxIndex = dynamicContent_ajaxObjects.length;
		document.getElementById(divId).innerHTML = 'Loading content - please wait';
		dynamicContent_ajaxObjects[ajaxIndex] = new sack();
		dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
		dynamicContent_ajaxObjects[ajaxIndex].onCompletion = 
		function(){ 
			ajax_showContent(divId,ajaxIndex,url);
			_createMessageDiv ();
		};	// Specify function that will be executed after file has been found
		dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
		
	}
	

	
	
	
	// _f_scrollTop() is used to get the amount that has been scrolled to position the message
	// _f_filterResults() is used to remove any crossbrowser problems
	function _f_scrollTop() {
 		return _f_filterResults (window.pageYOffset ? window.pageYOffset : 0, document.documentElement ? document.documentElement.scrollTop : 0, document.body ? document.body.scrollTop : 0);
	}
	
	function _f_filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
 		if (n_docel && (!n_result || (n_result > n_docel)))
 			n_result = n_docel;
 		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}
