/**
	@Description- Takes a parent and child dom object IDs. Parent should be static DOM location to which the returned AJAX data should be appended to.The all DOM data in the content will be swapped the data returned by an AJAX response.
	@param      - method (GET, POST, HEAD)
	@param      - structure (DOM ID of which the returned ajax content will be appened to) this stucture should be static it just defines a location in DOM where to returned data to appendChild to. This is the parent element  
	@param	- content. This is the child element of structure. The returned data from an AJAX request is the "content" This "content" needs to be appended to a location in DOM. The structure variable(DOM element id) is that location.
	@param	- url. this the path to which the ajax action is located. all the action should do is include a content. The default action might be used as well. by setting the c1 parameter.
	@param	- width (if the AJAX returned data that is put into a DIV needs to be sized. )
	@param	- height (if the AJAX returned data that is put into a DIV needs to be sized. )
	@author	- chad Walling chad@razordata.com
//example: javascript: AJAXUpdateByElementID('GET', 'AJAXStructure', 'AJAXContent', 'members/ajax?c1=members/industry');
*/
function getContentByAJAX(method, structure, content, url, width, height)
{
	width  = (width === null) ? "" : width;
	height = (height === null) ? "" : height;
	// handles replacing the ticker on page.
	setTickerInForm(url);
	//todo handle time out variable
	var callback    = { success:updateContentByAJAXCallBack, width:width, height:height, structure:structure, content:content, failure:responseFailure, timeout: 15000 };
	YAHOO.util.Connect.asyncRequest(method, url, callback);
}

var responseFailure = function(o)
{
	//Don't need to do anything at this point in time!
};

function setTickerInForm(url)
{
	var urlpos;
	var equalpos;
	var amppos;
	var ntick;
	urlpos = url.indexOf("ticker");
	if(urlpos > 0)
	{
		equalpos = url.indexOf("=",urlpos);
		amppos   = url.indexOf("&",urlpos);
		ntick    = url.substring(equalpos+1);
		document.stockSearch.ticker.value=ntick;
	}
}

/**
	@Description- if a successful response is returned from an AJAX request made by getContentByAJAX this function will swap the returned data 
	with the DOM data contained by the "content" variable passed in to getContentByAJAX.
*/
function updateContentByAJAXCallBack(o)
{
	var responseText      = o.responseText; //assumes responseText is html
	AJAXStructure         = document.getElementById(this.structure);
	var deleteReplaceNode = document.getElementById(this.content);
	delElement(deleteReplaceNode);
	
	newAJAXContentDiv    = document.createElement("div"); //assumes the content node to be replaced was a DIV element
	newAJAXContentDiv.id = this.content;

	if (this.width !== "" && (this.width.indexOf("px") !== -1 || this.width.indexOf("%") !== -1))
	{
		replacementDiv.style.width  = this.width;
	}
	
	if (this.height !== "" && (this.height.indexOf("px") !== -1 || this.height.indexOf("%") !== -1))
	{
		replacementDiv.style.height = this.height;
	}

	newAJAXContentDiv.innerHTML = responseText;
	AJAXStructure.appendChild(newAJAXContentDiv);
}

function CenterWindow(window_name, width, height, url)
{
	var str = "alwaysLowered=no,alwaysRaised=no,dependent=yes,directories=no,hotkeys=yes,location=no,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no";
	str += ",height=" + height;
	str += ",innerHeight=" + height;
	str += ",width=" + width;
	str += ",innerWidth=" + width;
	
	if (window.screen)
	{
		ypos = ((screen.availHeight/2) - (height/2));
		xpos = ((screen.availWidth/2) - (width/2));
		str += ",left=" + xpos;
		str += ",screenX=" + xpos;
		str += ",top=" + ypos;
		str += ",screenY=" + ypos;
	}
	
	win = window.open(url, window_name, str);
	if (win)
	{
		win.focus();
	}
}

function CenterWindowNoScroll(window_name, width, height, url)
{
	var str = "alwaysLowered=no,alwaysRaised=no,dependent=yes,directories=no,hotkeys=yes,location=no,menubar=no,personalbar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no";
	str += ",height=" + height;
	str += ",innerHeight=" + height;
	str += ",width=" + width;
	str += ",innerWidth=" + width;
	
	if (window.screen)
	{
		ypos = ((screen.availHeight/2) - (height/2));
		xpos = ((screen.availWidth/2) - (width/2));
		str += ",left=" + xpos;
		str += ",screenX=" + xpos;
		str += ",top=" + ypos;
		str += ",screenY=" + ypos;
	}
	
	win = window.open(url, window_name, str);
	if (win)
	{
		win.focus();
	}
}


/**
	@Description - Create a cookie object
	@param       - name (name of the new cookie)
	@param       - value (value associated with the cookie)
	@param       - days (days before cookie expiration)
*/
function setCookie(name, value, days)
{
	var expires = '';
	if (days)
	{
		date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}

	document.cookie = name+"="+value+expires+"; path=/";
}


/**
	@Description - Get a cookie object
	@param       - name (name of cookie to get)
	@return      - cookie object if exists, otherwise null
*/
function getCookie(name)
{
	var cName        = name + "=";
	var cookiesArray = document.cookie.split(';');
	for(var i = 0; i < cookiesArray.length; i++)
	{
		c = cookiesArray[i];
		while (c.charAt(0) === ' ')
		{
			c = c.substring(1, c.length);
		}
		
		if (c.indexOf(cName) === 0)
		{
			return c.substring(cName.length, c.length);
		}
	}
	
	return null;
}

/**
	@Description - Causes browser to delete cookie by setting it's expiration
	               date before now.
	@param       - name (name of cookie to delete)
*/
function unsetCookie(name)
{
	setCookie(name, "", -1);
}


/**
	@Description - Creates a button using the parameters passed in
	@param       - btnType (the name of the button style to use)
	@param       - btnText (text to be placed in the button)
	@param       - btnAction (action to perform in string form)
	@param       - parentElement (optional value; if provided will add button element to this "parentElement")
*/
function createButton(btnType, btnText, btnAction, parentElement)
{
	var tmpWrapperTable   = document.createElement('TABLE');
	tmpWrapperTable.align = 'left';
	tmpWrapperTable.setAttribute('cellPadding', "0");
	tmpWrapperTable.setAttribute('cellSpacing', "0");
	
	var tmpWrapperTBody = document.createElement('TBODY');
	tmpWrapperTable.appendChild(tmpWrapperTBody);
	
	var tmpWrapperRow = document.createElement('TR');
	tmpWrapperTBody.appendChild(tmpWrapperRow);
	
	var btnContainerCell       = document.createElement('TD');
	btnContainerCell.className = 'btnCntr_' + btnType;
	tmpWrapperRow.appendChild(btnContainerCell);
	
	var btnHref  = document.createElement('a');
	btnHref.href = '#';
	btnContainerCell.appendChild(btnHref);
	
	var btnTable         = document.createElement('TABLE');
	btnTable.className   = 'btn_' + btnType;
	btnTable.onmousedown = function() {this.className='btnPush_'+ btnType;};
	btnTable.onmouseout  = function() {this.className='btn_'+ btnType;};
	btnTable.onclick     = new Function(this.className='btn_'+ btnType, btnAction);
	btnTable.setAttribute('cellPadding', "0");
	btnTable.setAttribute('cellSpacing', "0");
	
//	btnTable.onclick                    = function() {this.className='btn_'+ btnType};
	var btnTBody = document.createElement('TBODY');
	btnTable.appendChild(btnTBody);
	btnHref.appendChild(btnTable);
	
	var btnRow = document.createElement('TR');
	btnTBody.appendChild(btnRow);
	
	var btnLeftCell       = document.createElement('TD');
	btnLeftCell.className = 'btnLeft';
	btnLeftCell.innerHTML = ' ';
	
	var btnMiddleCell = document.createElement('TD');
	var btnDiv        = document.createElement('DIV');
	btnDiv.className  = 'btnMiddle';
	btnMiddleCell.appendChild(btnDiv);
	
	var btnTextNode = document.createTextNode(btnText);
	btnDiv.appendChild(btnTextNode);
	
	var btnRightCell       = document.createElement('TD');
	btnRightCell.className = 'btnRight';
	btnRightCell.innerHTML = ' ';
	btnRow.appendChild(btnLeftCell);
	btnRow.appendChild(btnMiddleCell);
	btnRow.appendChild(btnRightCell);
	
	if (parentElement !== null)
	{
		parentElement.appendChild(tmpWrapperTable);
	}
	else
	{
		document.write(tmpWrapperTable);
	}
}


function formatNumber(number)
{
	number += '';
	x = number.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1))
	{
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


/**
	@Description - This function will return a String that represents a color coded string
	@param textValue[String] - The Text to encompass in a font tag
	@param positive[boolean] - Used to determine if the positive or negative font color should be used
	@return String - Represents an HTML font node w/ the text as a child TextNode
*/
function colorCurrency(textValue, positive)
{
	var color = positive ? 'darkgreen' : 'red';
	return '<font color="' + color + '">' + textValue + '<\/font>';
}


/**
	@Description - This function will set the focus to an element by it's id
	@param elementID [String] The element of the id to set the focus to.
**/
function SetFocus(elementID)
{
	self.focus();
	el = document.getElementById(elementID);
	if (el.focus)
	{
		el.focus();
	}
}


/**
	@description This function will allow CSS to be loaded into the head from any content page.
	@param contentPath [string] The path to load the CSS from.
**/
function LoadCSSModule(contentPath)
{
	var head         = document.getElementsByTagName('head');
	var linkNode     = document.createElement('link');
	var allLinkNodes = document.getElementsByTagName('link');
	var found        = false;
	if (head && linkNode && allLinkNodes)
	{
		contentPath = location.protocol + '//' + location.host + (contentPath.indexOf('/') === 0 ? '' : '/') + contentPath;
		
		for (i = 0; i < allLinkNodes.length && ! found; i++)
		{
			if (allLinkNodes[i].href === contentPath)
			{
				found = true;
			}
		}
		
		if (! found)
		{
			linkNode.type  = 'text/css';
			linkNode.rel   = 'stylesheet';
			linkNode.href  = contentPath;
			linkNode.media = 'screen';
			
			head[0].appendChild(linkNode);
		}
	}
}


/**
	@description This function will allow JavaScript to be loaded into the head from any content page.
	@param contentPath [string] The path to load the JavaScript from.
**/
function LoadJSModule(
	contentPath)
{
	var head           = document.getElementsByTagName('head')[0];
	var scriptNode     = document.createElement('script');
	var allScriptNodes = head.getElementsByTagName('script');
	var found          = false;
	if (head && scriptNode && allScriptNodes)
	{
		//contentPath = location.protocol + '//' + location.host + (contentPath.indexOf('/') === 0 ? '' : '/') + contentPath;

		for (i = 0; i < allScriptNodes.length && ! found; i++)
		{
			if (allScriptNodes[i].src === contentPath)
			{
				found = true;
			}
		}

		if (! found)
		{
			scriptNode.type = 'text/javascript';
			scriptNode.src  = contentPath;
			
			head.appendChild(scriptNode);
		}
	}
}

function loadJSModule(
	contentPath)
{
	LoadJSModule(contentPath);
}


/**
	@description Appends an Event Handler
	@note This function is loosely based on the YUI Event.addListener().
	@param el [String|HTMLElement] An id or an element reference to assign the listener to.
	@param sType [String] The type of event to append
	@param fn [Function] The method the event invokes
	@return [Boolean] True if the action was successful or defered, false if one or more of the elements could not have the listener attached, or if the operation throws an exception.
**/
function AddEventListener(el, sType, fn)
{
	var returnValue = false;
	
	//Check to see if the element is a string or an HTMLElement
	if (typeof el === 'string')
	{
		oEl = document.getElementById(el);
		if (oEl)
		{
			el = oEl;
		}
	}
	
	if (el)
	{
		try
		{
			if (window.addEventListener)
			{
				el.addEventListener(sType, fn, false);
				returnValue = true;
			}
			else if (window.attachEvent)
			{
				el.attachEvent("on" + sType, fn);
				returnValue = true;
			}
		}
		catch(e)
		{
			RemoveEventListener(el, sType, fn);
		}
	}
	
	return returnValue;
}


/**
	@description Removes an Event Handler
	@note This function is loosely based on the YUI Event.removeListener().
	@param el [String|HTMLElement] An id or an element reference to assign the listener to.
	@param sType [String] The type of event to append
	@param fn [Function] The method the event invokes
	@return [Boolean] True if the action was successful or defered, false if one or more of the elements could not have the listener attached, or if the operation throws an exception.
**/
function RemoveEventListener(el, sType, fn)
{
	var returnValue = false;
	
	//Check to see if the element is a string or an HTMLElement
	if (typeof el === 'string')
	{
		oEl = document.getElementById(el);
		if (oEl)
		{
			el = oEl;
		}
	}
	
	if (el)
	{
		try
		{
			if (window.removeEventListener)
			{
				el.removeEventListener(sType, fn, false);
				returnValue = true;
			}
			else if (window.detachEvent)
			{
				el.detachEvent("on" + sType, fn);
				returnValue = true;
			}
		}
		catch(e) {}
	}
	
	return returnValue;
}


//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.
function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try
	{
		// version will be set for 7.X or greater players
		axo     = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	}
	catch (e) {}
	
	if (! version)
	{
		try
		{
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
		
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		}
		catch (e) {}
	}
	
	if (! version)
	{
		try
		{
			// version will be set for 4.X or 5.X player
			axo     = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		}
		catch (e) {}
	}
	
	if (! version)
	{
		try
		{
			// version will be set for 3.X player
			axo     = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		}
		catch (e) {}
	}
	
	if (! version)
	{
		try
		{
			// version will be set for 2.X player
			axo     = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		}
		catch (e)
		{
			version = -1;
		}
	}
	
	return version;
}


// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer()
{
	var isIE    = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin   = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0)
	{
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"])
		{
			var swVer2           = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray        = flashDescription.split(" ");
			var tempArrayMajor   = descArray[2].split(".");
			var versionMajor     = tempArrayMajor[0];
			var versionMinor     = tempArrayMajor[1];
			var versionRevision  = descArray[3];
			if (versionRevision == "")
			{
				versionRevision = descArray[4];
			}
			
			if (versionRevision[0] == "d")
			{
				versionRevision = versionRevision.substring(1);
			}
			else if (versionRevision[0] == "r")
			{
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0)
				{
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1)
	{
		flashVer = 4;
	}
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1)
	{
		flashVer = 3;
	}
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1)
	{
		flashVer = 2;
	}
	else if ( isIE && isWin && ! isOpera )
	{
		flashVer = ControlVersion();
	}
	
	return flashVer;
}


// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	var isIE    = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin   = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

	versionStr = GetSwfVer();
	if (versionStr == -1 )
	{
		return false;
	}
	else if (versionStr != 0)
	{
		if(isIE && isWin && ! isOpera)
		{
			// Given "WIN 2,0,0,11"
			tempArray    = versionStr.split(" "); // ["WIN", "2,0,0,11"]
			tempString   = tempArray[1];          // "2,0,0,11"
			versionArray = tempString.split(","); // ['2', '0', '0', '11']
		}
		else
		{
			versionArray = versionStr.split(".");
		}
		var versionMajor    = versionArray[0];
		var versionMinor    = versionArray[1];
		var versionRevision = versionArray[2];
		
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer))
		{
			return true;
		}
		else if (versionMajor == parseFloat(reqMajorVer))
		{
			if (versionMinor > parseFloat(reqMinorVer))
			{
				return true;
			}
			else if (versionMinor == parseFloat(reqMinorVer))
			{
				if (versionRevision >= parseFloat(reqRevision))
				{
					return true;
				}
			}
		}
		
		return false;
	}
}


function AC_AddExtension(src, ext)
{
	if (src.indexOf('?') != -1)
	{
		return src.replace(/\?/, ext+'?');
	}
	else
	{
		return src + ext;
	}
}


function AC_Generateobj(objAttrs, params, embedAttrs) 
{
	var isIE    = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin   = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
	var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
	
	var str = '';
	if (isIE && isWin && !isOpera)
	{
		str += '<object ';
		for (var i in objAttrs)
		{
			str += i + '="' + objAttrs[i] + '" ';
		}
		str += '>';
		
		for (var i in params)
		{
			str += '<param name="' + i + '" value="' + params[i] + '" /> ';
		}
		
		str += '<\/object>';
	}
	else
	{
		str += '<embed ';
		for (var i in embedAttrs)
		{
			str += i + '="' + embedAttrs[i] + '" ';
		}
		str += '> <\/embed>';
	}
	
	document.write(str);
}


function AC_FL_RunContent()
{
	var ret = AC_GetArgs(arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");
	AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}


function AC_SW_RunContent()
{
	var ret = AC_GetArgs(arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000", null);
	AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}


function AC_GetArgs(args, ext, srcParamName, classid, mimeType)
{
	var ret        = new Object();
	ret.embedAttrs = new Object();
	ret.params     = new Object();
	ret.objAttrs   = new Object();
	
	for (var i = 0; i < args.length; i = i + 2)
	{
		var currArg = args[i].toLowerCase();
		switch (currArg)
		{
			case "classid":
				break;
			case "pluginspage":
				ret.embedAttrs[args[i]] = args[i+1];
				break;
			case "src":
			case "movie":	
				args[i+1]                = AC_AddExtension(args[i+1], ext);
				ret.embedAttrs["src"]    = args[i+1];
				ret.params[srcParamName] = args[i+1];
				break;
			case "onafterupdate":
			case "onbeforeupdate":
			case "onblur":
			case "oncellchange":
			case "onclick":
			case "ondblclick":
			case "ondrag":
			case "ondragend":
			case "ondragenter":
			case "ondragleave":
			case "ondragover":
			case "ondrop":
			case "onfinish":
			case "onfocus":
			case "onhelp":
			case "onmousedown":
			case "onmouseup":
			case "onmouseover":
			case "onmousemove":
			case "onmouseout":
			case "onkeypress":
			case "onkeydown":
			case "onkeyup":
			case "onload":
			case "onlosecapture":
			case "onpropertychange":
			case "onreadystatechange":
			case "onrowsdelete":
			case "onrowenter":
			case "onrowexit":
			case "onrowsinserted":
			case "onstart":
			case "onscroll":
			case "onbeforeeditfocus":
			case "onactivate":
			case "onbeforedeactivate":
			case "ondeactivate":
			case "type":
			case "codebase":
			case "id":
				ret.objAttrs[args[i]] = args[i+1];
				break;
			case "width":
			case "height":
			case "align":
			case "vspace": 
			case "hspace":
			case "class":
			case "title":
			case "accesskey":
			case "name":
			case "tabindex":
				ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
				break;
			default:
				ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
		}
	}
	
	ret.objAttrs["classid"] = classid;
	if (mimeType)
	{
		ret.embedAttrs["type"] = mimeType;
	}
	
	return ret;
}


function ChangeOpacity(
	elementParam,
	opactityParam)
{
	var element = typeof elementParam == 'object' ? elementParam : document.getElementById(elementParam);
	var opacity = parseFloat(opactityParam) > 1 ? opactityParam / 100 : opactityParam;
	
	element.style.opacity      = opacity;
	element.style.MozOpacity   = opacity;
	element.style.KhtmlOpacity = opacity;
	element.style.filter       = 'alpha(opacity=' + (opacity * 100) + ')';
}

// The constructor should be called with
// the parent object (optional, defaults to window).
function Timer()
{
	this.obj = (arguments.length) ? arguments[0] : window;
	
	// Methods
	
	// The set functions should be called with:
	// - The name of the object method (as a string) (required)
	// - The millisecond delay (required)
	// - Any number of extra arguments, which will all be
	//   passed to the method when it is evaluated.
	this.setInterval = function(
		func,
		msec)
	{
		var i = Timer.getNew();
		var t = Timer.buildCall(this.obj, i, arguments);
		
		Timer.set[i].timer = window.setInterval(t, msec);
		
		return i;
	}
	
	this.setTimeout = function(
		func,
		msec)
	{
		var i = Timer.getNew();
		Timer.buildCall(this.obj, i, arguments);
		
		Timer.set[i].timer = window.setTimeout("Timer.callOnce(" + i + ");", msec);
		
		return i;
	}
	
	// The clear functions should be called with
	// the return value from the equivalent set function.
	this.clearInterval = function(
		i)
	{
		if (Timer.set[i])
		{
			window.clearInterval(Timer.set[i].timer);
			Timer.set[i] = null;
		}
	}
	
	this.clearTimeout = function(
		i)
	{
		if (Timer.set[i])
		{
			window.clearTimeout(Timer.set[i].timer);
			Timer.set[i] = null;
		}
	}
}

Timer.set = new Array();

Timer.buildCall = function(
	obj,
	i,
	args)
{
	var t = "";
	Timer.set[i] = new Array();
	
	if (obj != window)
	{
		Timer.set[i].obj = obj;
		t = "Timer.set["+i+"].obj.";
	}
	
	t += args[0] + "(";
	
	if (args.length > 2)
	{
		Timer.set[i][0] = args[2];
		t += "Timer.set[" + i + "][0]";
		
		for (var j = 1; (j + 2) < args.length; j++)
		{
			Timer.set[i][j] = args[j + 2];
			t += ", Timer.set[" + i + "][" + j + "]";
		}
	}
	
	t += ");";
	Timer.set[i].call = t;
	
	return t;
}

Timer.callOnce = function(
	i)
{
	if (Timer.set[i])
	{
		eval(Timer.set[i].call);
		Timer.set[i] = null;
	}
}

Timer.getNew = function()
{
	var i = 0;
	
	while (Timer.set[i])
	{
		i++;
	}
	
	return i;
}


if (! self.getXmlHttpObject)
{
	function getXmlHttpObject()
	{
		var xmlHttp = null;
	
		try
		{
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
		}
		catch (e)
		{
			// Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	
		return xmlHttp;
	}
}


if (! self.ConvertToString)
{
	function ConvertToString(
		objectParam)
	{
		var tmpString = '';
		
		switch (typeof(objectParam))
		{
			case 'string':
				tmpString += "'" + objectParam + "'";
				break;
			case 'object':
				tmpString += "[";
				
				if (objectParam.length > 0)
				{
					tmpString += ConvertToString(objectParam[0]);
					
					for (var i = 1; i < objectParam.length; i++)
					{
						tmpString += ", " + ConvertToString(objectParam[i]);
					}
				}
				
				tmpString += "]";
				break;
			default:
				tmpString += objectParam;
		}
		
		return tmpString;
	}
}


if (! self.executeFunction)
{
	function executeFunction(
		functionObject)
	{
		var functionString = functionObject.functionName + "(";
		
		if (!(functionObject.parameters == 'undefined' || functionObject.parameters == null) && functionObject.parameters.length)
		{
			functionString += ConvertToString(functionObject.parameters[0]);
			
			for (var i = 1; i < functionObject.parameters.length; i++)
			{
				functionString += ", " + ConvertToString(functionObject.parameters[i]);
			}
		}
		
		functionString += ");";
		
		eval(functionString);
	}
}


function LoadTargetViaAjax(
	targetID,
	sourceURL,
	followUpFunction)
{
	var xmlHttp = getXmlHttpObject();

	if (xmlHttp != null)
	{
		xmlHttp.onreadystatechange = function()
		{
			// The request is complete
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var targetElement = document.getElementById(targetID);
				targetElement.innerHTML = xmlHttp.responseText;
				
				var scripts = targetElement.getElementsByTagName('script');
				
				for (var i = 0; i < scripts.length; i++)
				{
					if (scripts[i].type == 'text/javascript')
					{
						if (scripts[i].src)
						{
							LoadJSModule(scripts[i].src);
						}
						else
						{
							eval(scripts[i].innerHTML);
						}
					}
				}
				
				// If a follow up function was passed then execute it when request returns
				if (followUpFunction != null)
				{
					executeFunction(followUpFunction);
				}
			}
		}

		xmlHttp.open("GET", sourceURL, true);
		xmlHttp.send(null);
	}
	else
	{
		alert ("Your browser does not support AJAX!");
	}
}


function SubmitAjaxForm(
	formElement,
	actionURL,
	followUpFunctionName)
{
	var addElement;
	var elementType;
	var postStr = '';
	var tmpElement;
	var xmlHttp = getXmlHttpObject();

	if (xmlHttp != null)
	{
		for (var i = 0; i < formElement.length; i++)
		{
			addElement  = true;
			tmpElement  = formElement.elements[i];
			elementType = tmpElement.type;
			
			if ((elementType == 'checkbox' || elementType == 'radio') && ! tmpElement.checked)
			{
				addElement = false;
			}
			
			if (addElement)
			{
				postStr += tmpElement.name + '=' + tmpElement.value + '&';
			}
		}
		
		postStr = postStr.substring(0, postStr.length - 1);
		
		xmlHttp.onreadystatechange = function()
		{
			// The request is complete
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
			{
				var responseXML = xmlHttp.responseText;
				var functionObj = {
					"functionName" : followUpFunctionName,
					"parameters"   : [responseXML]};
				
				executeFunction(functionObj);
			}
		}
		
		xmlHttp.open('POST', actionURL, true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", postStr.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(postStr);
	}
	else
	{
		alert ("Your browser does not support AJAX!");
	}
}