var gOnLoadArray = new Array();

window.onload = Document_OnLoadHandler;

function Document_OnLoadHandler()
{
	try 
	{
		for (var i in gOnLoadArray) 
		{
			try 
			{
				gOnLoadArray[i]();
			} 
			catch (e) 
			{
			}
		}
	} 
	catch (e) 
	{
	}
	
	SetFocus();
}

function SetFocus()
{
	if (document.forms.length > 0) 
	{
		var found = false;
		for (var y=0; y<document.forms.length; y++)
		{
			var field = document.forms[y];
			for (i = 0; i < field.length; i++) 
			{
				if ((field.elements[i].type != "image") &&
				(field.elements[i].type != "hidden") &&
				(field.elements[i].type != "reset") &&
				(field.elements[i].type != "submit")) 
				{
				
					try 
					{
						document.forms[y].elements[i].focus();
						found = true;
					} 
					catch (e) 
					{
						continue;
					}
					break;
				}
			}
			if (found) break;
		}
	}
}

function Offset(x, y)
{
	this.x = x;
	this.y = y;
}

function isIE()
{
	return navigator.appName.indexOf('Microsoft') >= 0;
}

function getLeft(obj)
{
	return (obj.offsetParent == null ? obj.offsetLeft : obj.offsetLeft + getLeft(obj.offsetParent));
}

function getTop(obj)
{
	return (obj.offsetParent == null ? obj.offsetTop : obj.offsetTop + getTop(obj.offsetParent));
}

function getScrTop()
{
	var scrTop = 0;
	if (document.body && document.body.scrollTop) 
		scrTop = document.body.scrollTop;
	else 
		if (window.pageYOffset) 
			scrTop = window.pageYOffset;
	return scrTop;
}

function Set_Cookie(name, value, expires, path, domain, secure)
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());
	
	/*
	 if the expires variable is set, make the correct
	 expires time, the current script below will set
	 it for x number of days, to make it for hours,
	 delete * 24, for minutes, delete * 60 * 24
	 */
	if (expires) 
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));
	
	document.cookie = name + "=" + escape(value) +
	((expires) ? ";expires=" + expires_date.toGMTString() : "") +
	((path) ? ";path=" + path : "") +
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : "");
}

// this function gets the cookie, if it exists
function Get_Cookie(name)
{
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) &&
	(name != document.cookie.substring(0, name.length))) 
	{
		return null;
	}
	if (start == -1) 
		return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) 
		end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}

// this deletes the cookie when called
function Delete_Cookie(name, path, domain)
{
	if (Get_Cookie(name)) 
		document.cookie = name + "=" +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function URLEncode(t)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" + // Numeric
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
	"abcdefghijklmnopqrstuvwxyz" +
	"-_.!~*'()"; // RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	
	var plaintext = t;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++) 
	{
		var ch = plaintext.charAt(i);
		if (ch == " ") 
		{
			encoded += "+"; // x-www-urlencoded, rather than %20
		}
		else 
			if (SAFECHARS.indexOf(ch) != -1) 
			{
				encoded += ch;
			}
			else 
			{
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) 
				{
					encoded += "+";
				}
				else 
				{
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
	} // for
	return encoded;
}

function php_serialize(obj)
{
	var string = '';
	
	if (typeof(obj) == 'object') 
	{
		if (obj instanceof Array) 
		{
			string = 'a:';
			tmpstring = '';
			var count = 0;
			for (var key in obj) 
			{
				tmpstring += php_serialize(parseInt(key));
				tmpstring += php_serialize(obj[key]);
				count++;
			}
			string += count + ':{';
			string += tmpstring;
			string += '}';
		}
		else 
			if (obj instanceof Object) 
			{
				classname = obj.toString();
				
				if (classname == '[object Object]') 
				{
					classname = 'StdClass';
				}
				
				string = 'O:' + classname.length + ':"' + classname + '":';
				tmpstring = '';
				var count = 0;
				for (var key in obj) 
				{
					tmpstring += php_serialize(key);
					if (obj[key]) 
					{
						tmpstring += php_serialize(obj[key]);
					}
					else 
					{
						tmpstring += php_serialize('');
					}
					count++;
				}
				string += count + ':{' + tmpstring + '}';
			}
			else 
				if (obj == undefined) 
				{
					string += 'N;';
				}
	}
	else 
	{
		switch (typeof(obj))
		{
			case 'number':
				if (obj - Math.floor(obj) != 0) 
				{
					string += 'd:' + obj + ';';
				}
				else 
				{
					string += 'i:' + obj + ';';
				}
				break;
			case 'string':
				string += 's:' + obj.length + ':"' + obj + '";';
				break;
			case 'boolean':
				if (obj) 
				{
					string += 'b:1;';
				}
				else 
				{
					string += 'b:0;';
				}
				break;
		}
	}
	
	return string;
}

/**
 * X-browser event handler attachment and detachment
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn)
{
	if (obj.addEventListener) 
	{
		obj.addEventListener(evType, fn, false);
		return true;
	}
	else 
		if (obj.attachEvent) 
		{
			var r = obj.attachEvent("on" + evType, fn);
			return r;
		}
		else 
		{
			return false;
		}
}

function removeEvent(obj, evType, fn, useCapture)
{
	if (obj.removeEventListener) 
	{
		obj.removeEventListener(evType, fn, useCapture);
		return true;
	}
	else 
		if (obj.detachEvent) 
		{
			var r = obj.detachEvent("on" + evType, fn);
			return r;
		}
		else 
		{
			alert("Handler could not be removed");
		}
}

/**
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight()
{
	if (window.innerHeight != window.undefined) 
		return window.innerHeight;
	if (document.compatMode == 'CSS1Compat') 
		return document.documentElement.clientHeight;
	if (document.body) 
		return document.body.clientHeight;
	return window.undefined;
}

function getViewportWidth()
{
	if (window.innerWidth != window.undefined) 
		return window.innerWidth;
	if (document.compatMode == 'CSS1Compat') 
		return document.documentElement.clientWidth;
	if (document.body) 
		return document.body.clientWidth;
	return window.undefined;
}

function in_array(needle, haystack)
{
	for (var i in haystack) 
	{
		if (haystack[i] == needle) 
			return true;
	}
	return false;
}

// Array.lastIndexOf( array, value, begin, strict ) - Return index of the last element that matches value
function array_indexof(a, v, b, s)
{
	for (var i = b || 0; i < a.length; i++) 
	{
		if (a[i] === v || s && a[i] == v) 
		{
			return i;
		}
	}
	return -1;
}

// Array.unique( array, strict ) - Remove duplicate values
function array_unique(ar, b)
{
	var a = [], i, l = ar.length;
	for (i = 0; i < l; i++) 
	{
		if (array_indexof(a, ar[i], 0, b) < 0) 
		{
			a.push(ar[i]);
		}
	}
	return a;
}
