
/*------------------------------------
|
|  Add load event - loads functions in
|  and unbtrusive manner.
|
*************************************/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}


/*------------------------------------
|
|  Add events object.
|
*************************************/


var xb =
{
	evtHash: [],

	ieGetUniqueID: function(_elem)
	{
		if (_elem === window)
		{
			return 'theWindow';
		}
		else if (_elem === document)
		{
			return 'theDocument';
		}
		else
		{
			return _elem.uniqueID;
		}
	},

	addEvent: function(_elem, _evtName, _fn, _useCapture)
	{
		if (typeof _elem.addEventListener != 'undefined')
		{
			_elem.addEventListener(_evtName, _fn, _useCapture);
		}
		else if (typeof _elem.attachEvent != 'undefined')
		{
			var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) + '::evt_' + _evtName + '::fn_' + _fn + '}';
			var f = xb.evtHash[key];
			
			if (typeof f != 'undefined')
			{
				return;
			}

			f = function()
			{
				_fn.call(_elem);
			};

			xb.evtHash[key] = f;
			_elem.attachEvent('on' + _evtName, f);

			// attach unload event to the window to clean up possibly IE memory leaks
			window.attachEvent('onunload', function()
			{
				_elem.detachEvent('on' + _evtName, f);
			});

			key = null;
			//f = null;   /* DON'T null this out, or we won't be able to detach it */
		}
		else
		{
			_elem['on' + _evtName] = _fn;
		}
	},

	removeEvent: function(_elem, _evtName, _fn, _useCapture)
	{
		if (typeof _elem.removeEventListener != 'undefined')
		{
			_elem.removeEventListener(_evtName, _fn, _useCapture);
		}
		else if (typeof _elem.detachEvent != 'undefined')
		{
			var key = '{FNKEY::obj_' + xb.ieGetUniqueID(_elem) + '::evt' + _evtName + '::fn_' + _fn + '}';
			var f = xb.evtHash[key];
			if (typeof f != 'undefined')
			{
				_elem.detachEvent('on' + _evtName, f);
				delete xb.evtHash[key];
			}

			key = null;
			//f = null;   /* DON'T null this out, or we won't be able to detach it */
		}
	}
};


/*--------------------

String replace all

----------------------*/

function replaceAll(Source,stringToFind,stringToReplace)
{
	var temp = Source;
	var index = temp.indexOf(stringToFind);
	while(index != -1)
	{
		temp = temp.replace(stringToFind,stringToReplace);
		index = temp.indexOf(stringToFind);
	}
	
	return temp;
}


/*---------------------------------------

Get page dimensions, returns an object

----------------------------------------*/

function getPageDimensions()
{
	var dims = new Object();
	var width,height;
	if (window.innerHeight) // all except Explorer
	{
		width = window.innerWidth;
		height = window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
	
	dims.width = width;
	dims.height = height;
	
	return dims;
}

function getScrollDimensions()
{
	var pageDims = getPageDimensions()
	var dims = new Object();
	var width,height;
	
	if (window.innerHeight && window.scrollMaxY)
	{// Firefox
		height = window.innerHeight + window.scrollMaxY;
		width = window.innerWidth + window.scrollMaxX;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		height = document.body.scrollHeight;
		width = document.body.scrollWidth;
	}
	else
	{ // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		height = document.body.offsetHeight;
		width = document.body.offsetWidth;
  	}

	
	//dims.width = pageDims.width + width;
	//dims.height = pageDims.height + height;
	dims.width = width;
	dims.height = height;
	
	if(width < pageDims.width)
	{
		dims.width = pageDims.width;
	}
	
	if(height < pageDims.height)
	{
		dims.height = pageDims.height;
	}
	
	return dims;
}


function MM_findObj(n,d)
{
	var p,i,x;
	
	if(!d) {
		d=document;
	}
	
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);
	}
	
	if(!(x=d[n])&&d.all)
	{
		x=d.all[n];
	}
	
	for(i=0;!x&&i<d.forms.length;i++)
	{
		x=d.forms[i][n];
	}
	
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
	{
		x=MM_findObj(n,d.layers[i].document);
	}
	
	if(!x&&d.getElementById)
	{
		x=d.getElementById(n);
	}
	
	return x;
}

function MM_swapImage() 
{
	var i,j=0,x,a=MM_swapImage.arguments;
	
	document.MM_sr=new Array;
	
	for(i=0;i<(a.length-2);i+=3)
	{
		if((x=MM_findObj(a[i]))!=null)
		{
			document.MM_sr[j++]=x;
			
			if(!x.oSrc)
			{
				x.oSrc=x.src;
			}
			x.src=a[i+2];
		}
	}
}

function MM_swapImgRestore()
{
	var i,x,a=document.MM_sr;
	
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
	{
		x.src=x.oSrc;
	}
}

function MM_preloadImages()
{
	var d=document;
	
	if(d.images)
	{
		if(!d.MM_p)
		{
			d.MM_p=new Array();
		}
		
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		
		for(i=0;i<a.length;i++)
		{
			if(a[i].indexOf("#")!=0)
			{
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

function toggle(obj)
{
	var el=document.getElementById(obj);
	el.style.display=(el.style.display!='block'?'block':'none');
}
function toggleShow(obj)
{
	var el=document.getElementById(obj);
	el.style.display=(el.style.visibility!='hidden'?'hidden':'visible');
}
function clearme(obj)
{
	if(obj.value==obj.getAttribute("default"))
	{
		obj.value="";
	}
}

function restore(obj)
{
	if(obj.value=="")
	{
		obj.value=obj.getAttribute("default");
	}
}

function window_display(strurl)
{
	confirmWin = window.open(strurl,'theconfirmWin','toolbar=no,location=no,directories=no,status=yes,scrollbars=no,menubar=no,width=400,height=400,left=20,top=20');
	
	if(confirmWin.opener==null)
	{
		confirmWin.opener=window;
	}
}

