var authServer = 'www.fullcompass.com.golden-web.fullcompass.com';
var webServer = 'www.fullcompass.com';
function loadExtendedInfo ()
{
	var head = document.getElementsByTagName('head')[0];
	if (head != null)
	{
		var script = document.createElement('script');
		script.setAttribute('type', 'text/javascript');
		script.setAttribute('src', 'http://www.fullcompass.com.golden-web.fullcompass.com/extendedInfo/js/extendedInfo.js');
		head.appendChild(script);
		var link = document.createElement('link');
		link.setAttribute('type', 'text/css');
		link.setAttribute('rel', 'stylesheet');
		link.setAttribute('href', 'http://www.fullcompass.com.golden-web.fullcompass.com/extendedInfo/css/extendedInfo.css');
		head.appendChild(link);
	}
};

onContent('loadExtendedInfo()');

function AJAX (requestPage, parameters, type, reply)
{
	var oReply = reply;
	var oRequest;
	var oThis = this;
	
	this.processReply = processReply;
	
	if (window.XMLHttpRequest)
		oRequest = new XMLHttpRequest();
	else if (window.ActiveXObject)
		oRequest = new ActiveXObject('Microsoft.XMLHTTP');

	var list = '';
	for (key in parameters)
	{
		list += key+'='+parameters[key]+'&';
	}
	list += 'r='+ new Date().getTime();
	if (oRequest)
	{
		oRequest.onreadystatechange = processReply;
		try
		{
			if (type == 'get')
			{
				list = '?'+list;
				oRequest.open('GET', 'http://'+window.location.hostname+'/'+requestPage+list, true);
				oRequest.send(null);
			}
			else
			{
				oRequest.open('POST', 'http://'+window.location.hostname+'/'+requestPage, true);
				oRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				oRequest.send(list);
			}
		}
		catch (e)
		{
			var response = escape("var error='The URL " + requestPage + " could not be accessed. The server may be down or busy.  Please try again in a few minutes.'");
			if (oReply != '' && oReply != null)
			{
				eval(oReply + '(\'' + response + '\')');
			}
		}
	}
	else
	{
		var response = escape("var error='An AJAX session could not be instantiated.'");
		if ( oReply != '' && oReply != null )
		{
			eval(oReply + '(\'' + response + '\')');
		}
	}

	function processReply ()
	{
		if (oRequest.readyState == 4)
		{
			var response;
			if (oRequest.status == 200)
			{
				response = escape(oRequest.responseText);
			}
			else if (oRequest.status == 404)
			{
				response =  escape("var error='The requested page does not exist.'");
			}
			else if (oRequest.status == 403)
			{
				response =  escape("var error='Access has been denied.'");
			}
			else
			{
				response =  escape("var error='There was an error during processing your AJAX request. Response status : "+oRequest.status+"'");
			}
			if (oReply != '' && oReply != null)
			{
				eval(oReply + '(\'' + response + '\')');
			}
			delete oThis;
		}
	};
};

function notifier ()
{
	var myWindows = new Array();
	  
	this.display = display;
	this.kill = kill;
	  
	function display (id,text)
	{
		wind = new notifyWindow();
		var thisWind = new Array();
		thisWind['id'] = id;
		thisWind['ptr'] = wind;
		wind.open(text);
		if (myWindows.length > 0)
		{
			wind.setPrev(myWindows[myWindows.length-1]['ptr']);
		}
		else
		{
			wind.setTop();
		}
		myWindows.push(thisWind);
	}
	  
	function kill (id)
	{
		for (var x=0; x<myWindows.length; x++)
		{
			if (myWindows[x]['id'] == id)
			{
				myWindows[x]['ptr'].close();
				delete myWindows[x]['ptr'];
				myWindows.splice(x,1);
			}
		}
	}
};

function notifyWindow ()
{
	var myTarget = 0;
	var myNotify = null;
	var myPrev = null;
	var myNext = null;

	this.open = open;
	this.setPrev = setPrev;
	this.setNext = setNext;
	this.setTop = setTop;
	this.slideTop = slideTop;
	this.doSlide = doSlide;
	this.close = close;
  
	function open (text)
	{
		this.myNotify = document.createElement('div');
		this.myNotify.className = 'notifyContainer';
		this.myNotify.innerHTML = '<div class="notifyBody"><p>'+text+'</p></div>';
		document.getElementsByTagName('body')[0].appendChild(this.myNotify);
		this.myNotify.style.left = getWinWidth()/2 + getScrollLeft() - this.myNotify.offsetWidth/2 + 'px';
	};

	function setPrev (prev)
	{
		this.myPrev = prev;
		if (this.myPrev != null)
			prev.setNext(this);
	};

	function setNext (next)
	{
		if (this.myNext == null && next != null)
			next.setTop(this.myNotify.offsetTop + this.myNotify.offsetHeight);
		else if (next != null)
			next.slideTop(this.myNotify.offsetTop + this.myNotify.offsetHeight);
		this.myNext = next;
	};

	function setTop (top)
	{
		if (top == null || top == '' || top == 'undefined')
		{
			top = getWinHeight()/2 - this.myNotify.offsetHeight/2;
		}
		this.myNotify.style.top = top + 'px';
		this.myNotify.style.visibility = 'visible';
		if (this.myNext != null)
		{
			this.myNext.setTop(top + this.myNotify.offsetHeight);
		}
	};

	function slideTop (top)
	{
		this.myTarget = top;
		doSlide();
	};

	function doSlide ()
	{
		if (this.myNotify.offsetTop > this.myTarget)
		{
			this.myNotify.style.top = this.myNotify.offsetTop - 2 + 'px';
			setTimeout(doSlide,25);
		}
		else
		{
			this.myNotify.style.top = this.myTarget + 'px';
		}
		if (this.myNext != null)
			this.myNext.setTop(this.myNotify.offsetTop + this.myNotify.offsetHeight);
	};

	function close ()
	{
		if (this.myPrev != null && this.myNext != null)
		{
			this.myNext.setPrev(this.myPrev);
		}
		else if (this.myPrev != null)
		{
			this.myPrev.setNext(null);
		}
		else if (this.myNext != null)
		{
			this.myNext.slideTop(this.myNotify.offsetTop);
			this.myNext.setPrev(null);
		}
		this.myNotify.parentNode.removeChild(this.myNotify);
	};
};

function getOffsetTop (element)
{
	var value = element.offsetTop;
	while ( element = element.offsetParent )
    value += element.offsetTop;
	return value;
};

function getOffsetLeft (element)
{
	var value = element.offsetLeft;
	while ( element = element.offsetParent )
		value += element.offsetLeft;
	return value;
};

function getWinHeight ()
{
	var y;
	if (self.innerHeight)
	{	// all except Explorer
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{	// Explorer 6 Strict Mode
		y = document.documentElement.clientHeight;
	}
	else if (document.body)
	{	// other Explorers
		y = document.body.clientHeight;
	}
	return y;
};

function getWinWidth ()
{
	var x;
	if (self.innerWidth)
	{ // all except Explorer
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{	// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
	}
	else if (document.body)
	{	// other Explorers
		x = document.body.clientWidth;
	}
	return x;
};

function getScrollTop ()
{
	var y;
	if (self.pageYOffset)
	{	// all except Explorer
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{	// Explorer 6 Strict
		y = document.documentElement.scrollTop;
	}
	else if (document.body)
	{	// all other Explorers
		y = document.body.scrollTop;
	}
	return y;
};

function getScrollLeft ()
{
	var x;
	if (self.pageYOffset)
	{	// all except Explorer
		x = self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
	{	// Explorer 6 Strict
		x = document.documentElement.scrollLeft;
	}
	else if (document.body)
	{	// all other Explorers
		x = document.body.scrollLeft;
	}
	return x;
};

function getMouseX (e)
{
	if (!e) e = window.event;
	var thisX = (typeof(e.pageX) != 'undefined') ? e.pageX : e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	return thisX;
};

function getMouseY (e)
{
	if (!e) e = window.event;
	var thisY = (typeof(e.pageY) != 'undefined') ? e.pageY : e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	return thisY;
};

var oNotify = new notifier();

function URLDecode (encodedString)
{
	var output = "", x = 0, binVal, match;
	var regex = /(^[^%]*)/i;
	
	while (x < encodedString.length)
	{
		match = regex.exec(encodedString.substr(x));
		if (match != null && match.length > 1 && match[1] != "")
		{
			output += match[1];
			x += match[1].length;
		}
		else
		{
			if(encodedString[x] == '+')
			{
				output += ' ';
				x++;
			}
			else
			{
				binVal = parseInt(encodedString.substr(x+1,2),16);
				output += String.fromCharCode(binVal);
				x += 3;
			}
		}
	}
	return output;
};

function URLEncode (clearString) 
{
	var output = "", x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while (x < clearString.length)
	{
		var match = regex.exec(clearString.substr(x));
		if (match !== null && match.length > 1 && match[1] != "")
		{
			output += match[1];
			x += match[1].length;
		}
		else
		{
			if(clearString[x] == ' ')
				output += '%20';
			else
			{
				var charCode = clearString.charCodeAt(x);
				var hexVal = charCode.toString(16);
				output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
			}
			x++;
		}
	}
	return output;
};

function getElementsByClass(searchClass,node,tag)
{
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(?:^|\\s)'+ searchClass +'(?:\\s|$)');
	for (i = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className)) 
			classElements.push(els[i]);
	}
	return classElements;
};

var addEvent = function(elem, type, eventHandle)
{
    if (elem == null || elem == undefined) return;
    if (elem.addEventListener)
    {
        elem.addEventListener(type, eventHandle, false);
    }
    else if (elem.attachEvent)
    {
        elem.attachEvent( "on" + type, eventHandle );
    }
};

