
var root = '';
if (document.location.toString().indexOf("localhost") > 0)
  root = '/geg';

Function.prototype.bind = function() {

  var __method = this
  var argArray = arguments;
  var theobject = argArray[0];

  for (var i = 0; i < argArray.length - 1; i++)
    argArray[i] = argArray[i+1];

  argArray.length--;

  return function() {
    return __method.apply(theobject, argArray);
  }
}


function $(elm) {
	return document.getElementById(elm);
}
function OpenImageWindow(url, args){
	var b = window.open(url, 'PopupWindow', args);
	b.document.write('<html><body style=\"padding-right:0px;padding-left:0px;padding-bottom:0px;padding-top:0px;margin:0px;\"><img src=\"' + url + '\"></body></html>');
}

function DrawSWF(id, file, width, height, AddParms, Embed)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '" id="' + id + '" align="middle" VIEWASTEXT>\n<param name="allowScriptAccess" value="always" />\n<param name="movie" value="' + file + '" />' + AddParms + '<param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="' + file + '" ' + Embed + ' quality="high" bgcolor="#EEEBEB" width="' + width + '" height="' + height + '" name="' + id + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\n</object>');
}


function Communication()
{
	try {this.Transport = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){}
	
	if (!this.Transport)
		try {this.Transport = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
	if (!this.Transport)
		try { this.Transport = new XMLHttpRequest(); }catch(e){}
	
	this.Open = function(Method, URL, Content)
	{
		this.Method = Method;
		this.Content = Content;
		this.URL = URL;
		
		if (URL.indexOf('?') > -1)
			URL += "&sid=" + Math.round(Math.random()*100000000);
		else
			URL += "?sid=" + Math.round(Math.random()*100000000);
			
		this.Transport.open(Method, URL, true);

		this.Transport.onreadystatechange = this.onStateChange.bind(this);

		//send headers
		var requestHeaders = ['X-Requested-With', 'XMLHttpRequest', 'X-Prototype-Version', '1.4.0'];
		
		
		for (var i = 0; i < requestHeaders.length; i += 2)
		{
			this.Transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
		}

		this.Transport.send(null);
	}
	
	
	this.DisplayResponse = function()
	{
		var text = this.Transport.responseText;

		while (text.indexOf('%%ContentID%%') > -1)
			text = text.replace('%%ContentID%%', this.Content.id);
			
		if (this.Transport.getResponseHeader('Content-type').match(/^text\/javascript/i))
			eval(text);
		else if (this.Transport.getResponseHeader('Content-type').match(/^text\/html/i))
			this.Content.innerHTML = text;

		if (this.Transport.getResponseHeader('Ajax-Cache') == "true")
			this.CacheResults = true;

	}
	
	
	this.onStateChange = function()
	{
		var trans = this.Transport;
		if (trans.readyState == 4)
		{
			if (trans.status == 200)
			{
				if (trans.responseText.indexOf("<HTML>") > -1 || trans.responseText.indexOf("<html>") > -1)
				{	
					//alert(trans.responseText);
					alert("ERROR\n\ncontent contains <html> tags");
					return;
				}
				this.DisplayResponse();
			}
			else
			{
				//alert("There was an error on the server");
			}
		}
	}

}



var Ajax = new Object();
Ajax.Communications = new Array();

Ajax.get = function(method, URL, Content, OverrideCache)
{
	this.getData(method, URL, $(Content), OverrideCache);
}

Ajax.getData = function(Method, URL, Content, OverrideCache)
{
	
	if (!OverrideCache)	
	{
		for (var i = 0; i < this.Communications.length; i++)
		{	var aComm = this.Communications[i];
			if (aComm.Method == Method && aComm.URL == URL && aComm.Content.id == Content.id && aComm.CacheResults == true)
			{
				aComm.DisplayResponse();
				return;
			}
		}
	}

	var comm = new Communication();
	this.Communications[this.Communications.length] = comm;
	
	comm.Open(Method, URL, Content);
	
}
Ajax.getToolTip = function(obj, method, URL, AutoHide, xOffset, yOffset, OverrideCache)
{

	
	if (!Ajax.HighestZ)
		Ajax.HighestZ = 100;
		
	Ajax.HighestZ++;
		
	x_Offset = 0;
	y_Offset = 0;
	
	if (xOffset)
		x_Offset = xOffset;
	if (yOffset)
		y_Offset = yOffset;
	
	//var tt = obj.AjaxToolTip;
	
	if (!obj.AjaxToolTip)
	{
		obj.AjaxToolTip = document.createElement('div');
		obj.AjaxToolTip.setAttribute('id', 'AjaxToolTip' + Math.round(Math.random()*100000000));
		obj.AjaxToolTip.className = 'tt';
		document.body.appendChild(obj.AjaxToolTip);
	}

	obj.AjaxToolTip.innerHTML = "Loading...";
	obj.AjaxToolTip.style.display = 'block';


	var yScrollOffset = 0;
	if (ie5)
		yScrollOffset = document.body.scrollTop;
		


	obj.AjaxToolTip.style.left = mouser_mx + 10 + x_Offset;
	obj.AjaxToolTip.style.top = mouser_my + 10 + y_Offset + yScrollOffset;
	obj.AjaxToolTip.style.zIndex = Ajax.HighestZ;
	
	
	
	
	this.getData(method, URL, obj.AjaxToolTip, OverrideCache);
	

	if (AutoHide)
	{
		obj.onmouseout = function() {
			this.AjaxToolTip.style.display = 'none';
		}
	}
	
}

Ajax.CloseContent = function(id)
{
	$(id).style.display = 'none';
}

function proc(message)
{
	var proc = ge('prc');

	var yScrollOffset = 0;
	if (ie5)
		yScrollOffset = document.body.scrollTop;
		
		
	proc.style.left = mouser_mx;
	proc.style.top = mouser_my + yScrollOffset;
	
	if (message)
		proc.innerHTML = message;
	else
		proc.innerHTML = 'Processing... please wait a moment.';
		

	
}

function de() {
	var args = de.arguments;
	for (i=1; i<args.length; i++){
		aLayer = $(args[i]);
		if (aLayer)
			aLayer.style.display = args[0];
	}
}