/* *********************************************************************************************************************************************** */
/* Functions for the Occlusion DIV */

// Get the height of the page 
function getWindowHeight() {
	var windowHeight = 0;
	if (document.body && document.body.scrollHeight) {
		windowHeight = document.body.scrollHeight - 20;
	}
	return windowHeight;
}

// Get the width of the page 
function getWindowWidth() {
	var windowWidth = 0;
	var minWidth = 980;
	var maxWidth = 1024;
	if (document.body && document.body.clientWidth) {
		windowWidth = (document.body.clientWidth - 20);
		if (windowWidth < minWidth) windowWidth = minWidth;
		if (windowWidth > maxWidth) windowWidth = maxWidth;
	}
	return windowWidth;
}

// Set the occlusion panel size
function setOcclusionPanelSize(useMegaBanner){
  document.getElementById('occlusionPanel').style.width=(getWindowWidth())+'px';
  document.getElementById('occlusionPanel').style.height=(getWindowHeight())+'px';
  positionModalPanel(useMegaBanner);
}

// Display the occlusion panel
function displayOcclusionPanel(useMegaBanner){
  setOcclusionPanelSize(useMegaBanner);
  document.getElementById('occlusionPanel').style.display='block';
}

// Close the occlusion panel
function closeOcclusionPanel(){
  document.getElementById('occlusionPanel').style.display='none';
}

/* *********************************************************************************************************************************************** */
/* Functions for the Modal Panel*/

function sizeModalPanel(withIFrame){
	document.getElementById('firstTimeRiaPanel').style.width=modalPanelWidth;
	document.getElementById('firstTimeRiaPanel').style.height=modalPanelHeight;
	if (withIFrame) {
		document.getElementById('firstTimeRiaPaneliFrame').style.width=modalPanelWidth-44;
		document.getElementById('firstTimeRiaPaneliFrame').style.height=modalPanelHeight-123;
	}
}

// Set the position of the Modal Panel
function positionModalPanel(useMegaBanner){
	if (((document.body.clientWidth-modalPanelWidth)/2) < 0){
		document.getElementById('firstTimeRiaPanel').style.left = 0;
	}else{
		document.getElementById('firstTimeRiaPanel').style.left=(document.body.clientWidth-modalPanelWidth)/2;
	}
	if (useMegaBanner){
		document.getElementById('firstTimeRiaPanel').style.top=topPositionWithMb;
	}else{
		document.getElementById('firstTimeRiaPanel').style.top=topPositionWithoutMb;
	}
}

// Display the Modal Panel
function displayModalPanel(){
  document.getElementById('modalPanel').style.display='block';
}

// Set the source of the Modal Panel
function setModalPanelSrc(srcToSet){
	document.getElementById('firstTimeRiaPaneliFrame').src='..'+srcToSet;
}

// Close the Modal Panel
function closePanel()
{
  document.getElementById('modalPanel').style.display='none';
  document.getElementById('modalPanel').style.display='none';
  closeOcclusionPanel();
  // Check to save the skip preference if this one exists
  if (document.skipform) {
    if (document.skipform.skip && document.skipform.skip.value == 'OK'){
      document.skipform.target="submitSkipPref";
      document.skipform.action="welcome_panel_skip_submit.html";
      document.skipform.submit();
    }
  }
}

// Close the Modal Panel and open a webmail page
function closePanelAndOpen(src)
{
  closePanel();
  self.location='../'+src;
}

/* *********************************************************************************************************************************************** */
//Specific functions for the XML Welcome Panel

function requestWelcomePanel() {		
	var url = "XML_welcomePanel.xml";
	XMLRequestCaller(XMLRequestWelcomePanel, url, "", "POST", function() {processWelcomePanelResponse(XMLRequestWelcomePanel)});
}

function processWelcomePanelResponse(thisXMLObject) {	  
	try {
		if(thisXMLObject.readyState == 4) {
			if (thisXMLObject.status == 200) {
				if (thisXMLObject.responseXML) {
					XMLDisplay = thisXMLObject.responseXML.documentElement.getElementsByTagName("display");
					if (XMLDisplay.item(0).firstChild.data == "1") {
						displayOcclusionPanel(useMegaBanner);
						setModalPanelSrc(modalPanelUrl);
						displayModalPanel(); 
					} 
				}
			}
		} else
			return;
	} catch (e) {
		//en cas d'erreur on recharge la page
		window.self.location = window.self.location;
	}		
}
