/** @namespace */
var Franson = Franson || {};
/** @namespace */
Franson.UI = Franson.UI || {};


/** @singleton */
Franson.UI.LightBox =
{
	//
	// getPageScroll()
	// Returns array with x,y page scroll values.
	//
	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;
		}

		return ['', yScroll];
	},

	//
	// getPageSize()
	// Returns array with page width, height and window width, height
	// Core code from - quirksmode.org
	// Edit for Firefox by pHaez
	//
	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
		var pageHeight;
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		var pageWidth;
		if(xScroll < windowWidth){
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}

		return [ pageWidth, pageHeight, windowWidth, windowHeight ];
	},

	centerContent: function(domId)
	{
		var objtrackExport = typeof(domId) == 'string' ? document.getElementById(domId) : domId;
		var height = 500; //objtrackExport.height;
		var width = 400; //objtrackExport.width;

		var arrayPageSize = this.getPageSize();
		var contentTop = (arrayPageSize[3] - width) / 2;
		var contentLeft = (arrayPageSize[0] - height) / 2;

		objtrackExport.style.top = (contentTop < 0) ? "0px" : contentTop + "px";
		objtrackExport.style.left = (contentLeft < 0) ? "0px" : contentLeft + "px";
	},

	show: function(domId)
	{
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','overlay');
		//objOverlay.onclick = function () {hideLightbox(); return false;}
		objOverlay.style.display = 'none';
		objOverlay.style.position = 'absolute';
		objOverlay.style.top = '0';
		objOverlay.style.left = '0';
		objOverlay.style.zIndex = '90';
		objOverlay.style.width = '100%';
		objOverlay.style.backgroundColor = '#000000';
		objOverlay.style.filter = 'alpha(Opacity=75)';
		objOverlay.style.opacity = '.75';
		objBody.insertBefore(objOverlay, objBody.firstChild);

		this.createOverlay();
		this.centerContent(domId);

		domId = typeof(domId) == 'string' ? document.getElementById(domId) : domId;
		domId.style.display = 'block';
	},

	createOverlay: function()
	{
		var objOverlay = document.getElementById('overlay');
		var arrayPageSize = this.getPageSize();
		var arrayPageScroll = this.getPageScroll();

		objOverlay.style.height = (arrayPageSize[1] + 'px');
		objOverlay.style.display = 'block';
	},

	hide: function(domId)
	{
		// get objects
		var objOverlay = document.getElementById('overlay');
		var objContent = typeof(domId) == 'string' ? document.getElementById(domId) : domId;
		// hide overlay and content
		objOverlay.style.display = 'none';
		objContent.style.display = 'none';
	}
};

   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('GET', url, true);      
      http_request.send(null);
   }

   function alertContents() 
   {
      if (http_request.readyState == 4) 
      {
         if (http_request.status == 200) 
		 {         
			result = http_request.responseText;			
			addr = document.getElementById("hAddr").value;
			Franson.UI.LightBox.hide('waitBox');
			//window.location=addr;
		}
		else
		{
			Franson.UI.LightBox.hide('waitBox');
		}
     }
   }


function ajaxget(urlname,errorReturnValue)
{
	var xmlhttp=false;
	if (!xmlhttp) 
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		} catch (e) {xmlhttp=false;}
	}

	try
	{
		if (!xmlhttp && window.createRequest) 
		{
			try 
			{
				xmlhttp = window.createRequest();
			} catch (e) {xmlhttp=false;}
		}
	} catch(e) { xmlhttp=false;}

	try
	{
		if(xmlhttp)
		{
			xmlhttp.open("GET",urlname,false);						
			xmlhttp.send(null);				

			return xmlhttp.responseText;
		}
		else return errorReturnValue;
	} catch(e) { return errorReturnValue;}
}	


	function loadUrl(url)
	{
		try
		{
			Franson.UI.LightBox.show('waitBox');
			var loadurl = document.getElementById("hURL").value;
			document.getElementById("hAddr").value = url;
			ajaxget(loadurl,"");				
			Franson.UI.LightBox.hide('waitBox');
		}catch(e)
			{
				Franson.UI.LightBox.hide('waitBox');
			}
	}

	function load(url)
	{
		try
		{
			if(url.indexOf("Download")==-1)
			{
				Franson.UI.LightBox.show('waitBox');
			}
			else
			{
				loadUrl(null);
			}

			if(url.indexOf("//")==-1) 
				window.location="http://www.luckyredcasino.com/" + url;
			else
				window.location=url;
			
		}catch(e)
			{
				Franson.UI.LightBox.hide('waitBox');
			}
	}
