/*
 * ###########################################################################
 * #   Copyright (C) 2007 FoxCroft Trading Inc                               #
 * #                                                                         #
 * #   This program is commercial software; you can not redistribute it      #
 * #   and/or modify it under the terms of the license.txt                   #
 * #   License as published by FoxCroft Trading Inc, available in the        #
 * #   apollo/readme directory of this software distribution.                #
 * #                                                                         #
 * #   This program is distributed WITHOUT ANY WARRANTY                      #
 * #   or FITNESS FOR A PARTICULAR PURPOSE.  See the                         #
 * #   license.txt License for more details.                                 #
 * #                                                                         #
 * #   RXSERVER VERSION: 1.6.7                                               #
 * #                                                                         #
 * ###########################################################################
 *
 * This JS contains all the required methods to the date selection window.
 */

function darkBackground() {
	var objDarkBg = document.getElementById('DarkBarkground');
	
	arrayPageSize = getPageSize();
	objDarkBg.style.height 	= (arrayPageSize[1] + 'px');
	objDarkBg.style.width	= (arrayPageSize[0] + 'px');
	objDarkBg.style.display = 'block';
}

function centerInfoBox() {
	var infoBox = document.getElementById("InformationBox");
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScrollZone();
	
	var infoBoxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 350) / 2);
	var infoBoxLeft = ((arrayPageSize[0] - 20 - 500) / 2);
		
	infoBox.style.top = (infoBoxTop < 0) ? "0px" : infoBoxTop + "px";
	infoBox.style.left = (infoBoxLeft < 0) ? "0px" : infoBoxLeft + "px";
}

function undarkBackground() {
	document.getElementById('DarkBarkground').style.display = 'none';
	document.getElementById('InformationBox').style.display = 'none';
}

function getPageSize(){
	
	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;
}

function getPageScrollZone(){

	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;
}


function getHTTPObject()
{
  var xmlhttp = false;

  /* For IE */
  /*@cc_on
  @if (@_jscript_version >= 5)
     try
     {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
     }
     catch (e)
     {
        try
        {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E)
        {
           xmlhttp = false;
        }
     }
  @else
     xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  {
     try
     {
        xmlhttp = new XMLHttpRequest();
     }
     catch (e)
     {
        xmlhttp = false;
     }
  }

  if (xmlhttp)
  {
     /* When we got the answer ! */
     xmlhttp.onreadystatechange=function()
     {
        if (xmlhttp.readyState == 4) /* 4 : état "complete" */
        {
           if (xmlhttp.status == 200) /* 200 : code HTTP pour OK */
           {
              document.getElementById("dataForm").innerHTML = xmlhttp.responseText;
           }
        }
     }
  }
  return xmlhttp;
}
