/*
	Copyright DTDigital         :: www.dtdigital.com.au ::
	Unauthorised modification / use is a criminal offence, and
	will be prosecuted to the fullest extent permitted by law.
	All Rights Reserved
*/

// jQuery functions that run on "dom ready"

var _jQueryLoaded = (typeof(jQuery) == "function");

if (_jQueryLoaded)
{
	$(document).ready(function()
	{
		InitAllSwaps();
		InitFuncs();
		
		// Makes links open in new window when they have rel=external
		$("a[@rel='external'], a.external-link, a.new-window, a[@target='_blank']")
			.not(".thickbox")
			.click(function(){
				window.open(this.href);
				return false;
			});
		
		// Stops IE 6 flicker on hover of link with background image
		if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6) {
			try {
				document.execCommand("BackgroundImageCache", false, true);
			} catch(err) {}
		}
		
		// Improved MSIE sniffing - see http://www.ericmmartin.com/jquery-browser-issues-revisited/
		if ($.browser.msie)
		{
			jQuery.browser.version = jQuery.browser.msie &&
				parseInt(jQuery.browser.version) >= 6 &&
				typeof window['XMLHttpRequest'] == "object" ?
					"7.0" :
					jQuery.browser.version;
			jQuery.browser.msie6 = jQuery.browser.msie &&
				parseInt(jQuery.browser.version) == 6 &&
				typeof window['XMLHttpRequest'] != "object";
		}
		
		$(".search1_autocomplete").autocomplete(
			"WebServices/Keywords.aspx",
			{
				delay:0,
				minChars:0,
				maxItemsToShow:10
			}
		);
		
	});
}

NAVarr = new Array("navhome", "navaboutus", "navourpensionproducts", "navmembers", "navinvestments", "navtoolsforms", "navnewseducation", "navforfinancialplanners");
if (document.images)
{
	for (var NAVitem in NAVarr)
	{ 
		 for (var NAVicount=0; NAVicount < 2; NAVicount++)
		 { 
				eval("b" + NAVarr[NAVitem] + NAVicount + " = new Image()");
				eval("b" + NAVarr[NAVitem] + NAVicount + ".src = 'assets/swap_" + NAVarr[NAVitem] + "_" + NAVicount + ".gif'");
		 } 
	} 
}

function BturnOn(imageName)
{
	if (document.images)
	{
		var imageNumber = "";
		if (arguments.length > 1) imageNumber = arguments[1];
		document [imageName + imageNumber].src = eval("b" + imageName + "1.src");
	}
}

function BturnOff(imageName)
{
	if (document.images)
	{
		var imageNumber = "";
		if (arguments.length > 1) imageNumber = arguments[1];
		document [imageName + imageNumber].src = eval("b" + imageName + "0.src");
	}
}

function InitAllSwaps()
{
	if (_jQueryLoaded)
	{
		$("img[@src*='swap_'], input[@src*='swap_']")
		.not("img[@src*='_2.'], input[@src*='_2.']")
		.not(".no_swap")
		.not("img[@src*='swap_expand_']")
		.not("img[@src*='swap_tabtools_']")
		.not("img[@src*='swap_tabformslinks_']")
		.each(function()
		{
			var imageSrc = $(this).attr("src");
			var imageName = imageSrc.substring(imageSrc.lastIndexOf("swap_") + 5, imageSrc.lastIndexOf("_"));
			
			for (var preloadLoop=0; preloadLoop < 2; preloadLoop++)
			{
				if (eval("typeof(b" + imageName + preloadLoop + ")") != "object")
				{
					eval("b" + imageName + preloadLoop + " = new Image()");
					if (imageSrc.indexOf(".gif") > -1) {
						eval("b" + imageName + preloadLoop + ".src = 'assets/swap_" + imageName + "_" + preloadLoop + ".gif'");
					} else if (imageSrc.indexOf(".jpg") > -1) {
						eval("b" + imageName + preloadLoop + ".src = 'assets/swap_" + imageName + "_" + preloadLoop + ".jpg'");
					}
				}
			}
			$(this).mouseover(function(){
				$(this).attr("src", eval("b" + imageName + "1.src"));
			});
			$(this).mouseout(function()
			{
				$(this).attr("src", eval("b" + imageName + "0.src"));
			});
			
		});
	}
}

function InitFuncs()
{
	if (_jQueryLoaded)
	{
		$("#funcs #func_explain")
			.show();
			
		$("#funcs #func_icons a")
			.mouseover(function(){
				explain_text = $(this).children("img").attr("alt");
				$("#funcs #func_explain").text(explain_text);
			})
			.mouseout(function(){
				$("#funcs #func_explain").html("&nbsp;");
			});
		
		$("#funcs #func_icons #func_icon_email")
			.click(function(){
				path = $(this).attr("href");
				if (path) {
					window.open(path, "popup", "width=450, height=400, toolbar=no, status=no, scrollbars=yes, resizable=yes");
					return false;
				}
			});
		
		$("#funcs #func_icons #func_icon_print")
			.show()
			.click(function(){
				if(window.print) {
					window.print();
				} else {
					if(agt.indexOf("mac") != -1) {
						alert("To print this page press Command-P.");
					} else {
						alert("To print this page press Control-P.");
					}
				}
				return false;
			});
		
	}
}

// Funtions for Global Tabs hover states
function TabHoverOn(id) {
	document.getElementById(id).className="global-tab-active";
}
function TabHoverOff(id) {
	document.getElementById(id).className="";
}


/* Client-side access to querystring name=value pairs
Version 1.3
28 May 2008
	
License (Simplified BSD):
http://adamv.com/dev/javascript/qslicense.txt
	
http://adamv.com/dev/javascript/querystring
*/
function Querystring(qs) { // optionally pass a querystring to parse
    this.params = {};

    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &

    // split out each name=value pair
    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);

        var value = (pair.length == 2)
			? decodeURIComponent(pair[1])
			: name;

        this.params[name] = value;
    }
}

Querystring.prototype.get = function(key, default_) {
    var value = this.params[key];
    return (value != null) ? value : default_;
}

Querystring.prototype.contains = function(key) {
    var value = this.params[key];
    return (value != null);
}

/* Investment Choice - Investment Options Tab switcher */

function show_1invest() {
    document.getElementById("invch_tabs_1invest").style.display = "block";
    document.getElementById("invch_1invest").style.display = "block";
    document.getElementById("invch_tabs_2fytd").style.display = "none";
    document.getElementById("invch_2fytd").style.display = "none";
    document.getElementById("invch_tabs_3month").style.display = "none";
    document.getElementById("invch_3month").style.display = "none";
}

function show_2fytd() {
    document.getElementById("invch_tabs_1invest").style.display = "none";
    document.getElementById("invch_1invest").style.display = "none";
    document.getElementById("invch_tabs_2fytd").style.display = "block";
    document.getElementById("invch_2fytd").style.display = "block";
    document.getElementById("invch_tabs_3month").style.display = "none";
    document.getElementById("invch_3month").style.display = "none";
}

function show_3month() {
    document.getElementById("invch_tabs_1invest").style.display = "none";
    document.getElementById("invch_1invest").style.display = "none";
    document.getElementById("invch_tabs_2fytd").style.display = "none";
    document.getElementById("invch_2fytd").style.display = "none";
    document.getElementById("invch_tabs_3month").style.display = "block";
    document.getElementById("invch_3month").style.display = "block";
}

function LoadInvChTabs() {
    document.getElementById("invch_tabs").style.display = "block";

    document.getElementById("invch_content").className = "invch_content_applied";

    var qs_i = new Querystring()
    var load_invch_tab = qs_i.get("load_invch_tab", "1")
    if (load_invch_tab == "2") {
        show_2fytd();
    }
    else if (load_invch_tab == "3") {
        show_3month();
    }
    else {
        show_1invest();
    }

    var areaContainer = document.getElementById("invch_content");
    var areaHeadings = areaContainer.getElementsByTagName("h4");
    for (var areaHeadingsIndex = 0; areaHeadingsIndex < areaHeadings.length; areaHeadingsIndex++) {
        areaHeadings[areaHeadingsIndex].style.display = "none";
    }

}



function hideAllFields()
{
    for (i = 1; i < 12; i++)
    {
        document.getElementById('language' + i).style.display = 'none';
        document.getElementById('hide' + i).style.display = 'none';
    }
}

function displayThis(id)
{
    document.getElementById('language' + id).style.display = 'block';
    document.getElementById('show' + id).style.display = 'none';
    document.getElementById('hide' + id).style.display = 'inline';
}

function hideThis(id)
{
    document.getElementById('language' + id).style.display = 'none';
    document.getElementById('show' + id).style.display = 'inline';
    document.getElementById('hide' + id).style.display = 'none';
}




/* Simplifies getting elements by id and tag name */
function el(index) 
{
  return document.getElementById(index);
}
function tag(index) 
{
  return document.getElementsByTagName(index);
}



/* Browser detection */
var userAgent = navigator.userAgent;


/* Check All */
function CheckAll(id) 
{
	var Section = el(id);
	
	var CheckboxArray = Section.getElementsByTagName("input");
	
	for(var i=0; i<CheckboxArray.length;i++)
	{
		if(CheckboxArray[i].type == "checkbox")
		{
			CheckboxArray[i].checked = "checked";
		}
		else
		{
			CheckboxArray[i].checked = "";
		}
	}
}


function hideAllFields()
{
	 for(i=1; i<12; i++)
	 {
		el('language' + i).style.display = 'none';
		el('hide' + i).style.display = 'none';

	 }
}


function displayThis(id)
{

		el('language' + id).style.display = 'block';
		el('show' + id).style.display = 'none';
		el('hide' + id).style.display = 'inline';


}


function hideThis(id)
{
	el('language' + id).style.display = 'none';
	el('show' + id).style.display = 'inline';
	el('hide' + id).style.display = 'none';
}


function hideAllFields2(name, count)
{
	for (i = 0; i < count; i++)
	{
		el(name + i).style.display = 'none';
		el('icon-hide' + i).style.display = 'none';
		el('text-hide' + i).style.display = 'none';
	}
}



function displayThis2(name, id)
{
	el(name + id).style.display = 'block';

	el('icon-show' + id).style.display = 'none';
	el('icon-hide' + id).style.display = 'inline';

	el('text-show' + id).style.display = 'none';
	el('text-hide' + id).style.display = 'inline';
	
	el('faq-cell' + id).className = 'faq-cell-background';
}


function hideThis2(name, id)
{
	el(name + id).style.display = 'none';

	el('icon-show' + id).style.display = 'inline';
	el('icon-hide' + id).style.display = 'none';

	el('text-show' + id).style.display = 'inline';
	el('text-hide' + id).style.display = 'none';
	
	el('faq-cell' + id).className = '';
}



/* Glossary tooltip html addition */
var IE = document.all?true:false

function glossaryTooltip()
{
	if(el("centrecontent"))
	{
		for (i=0; i<document.links.length; i++)
		{
			if(String(document.links[i].href).indexOf("tools-forms_glossary.aspx?g") != -1)
			{
			    if(IE)
				{
					document.links[i].onmouseover = function() { getMouseXY(event); }
					document.links[i].onmouseout = function() { removeTooltip(); }
				} else {
					document.links[i].onmouseover = getMouseXY;
					document.links[i].onmouseout = removeTooltip;
				}
				
				// split href.search param on constant delimeter
				var str = unescape(document.links[i].search).split("?g=");

				//load the glossary title into the glossary array
				gLinks.push(str[1]);

				//set expando/custom property "gid" which is the title of the glossary item
				//so we can access the right glossary item for each link.
				document.links[i].gid = str[1];

				glossaryCount ++;
			} else {
				
			}
		}
		buildQuery();
	}
}


function getMouseXY(e) 
{
	var characterLength;
	var contentHeight;
	var topposition;
	
	if(gLoadingComplete)
	{
		var target = el("tooltip");
		
		characterLength = el("text").innerHTML.length;
		contentHeight = Math.ceil(characterLength/44)*14;
		topposition = contentHeight + 35;
		target.style.display = "block";
		
		if(IE)
		{
			var tempX = e.clientX + document.body.scrollLeft;
			var tempY = e.clientY + document.body.scrollTop;
			
			target.style.top = ((tempY - topposition) - 15) + "px";
			target.style.left = tempX + "px";
		} else {
			var tempX = e.clientX + window.pageXOffset;
			var tempY = e.clientY + window.pageYOffset;
			
			target.style.top = (tempY - topposition) + "px";
			target.style.left = tempX + "px";
		}

		if(glossaryText[obj.gid] == "undefined" || glossaryText[obj.gid] == null)
		{
			target.style.display = "none";
			return;
		}

		el("text").innerHTML = glossaryText[obj.gid];
	}
}



//*** Start Glossary Parsing
function chk(obj,val,showhtmltext)
{

	var resultArray = new Array();

	for(var property in obj)
	{
		if(val)
		{
			if(val == property)
			{
				checkIfFunction(resultArray, property, obj);
			}
		}
		else
		{
			if(showhtmltext)
			{
				checkIfFunction(resultArray, property, obj);
			}
			else
			{
				if(property != 'innerHTML' && property != 'innerText' && property != 'outerHTML' && property != 'outerText')
					checkIfFunction(resultArray, property, obj);
			}
		}

	 }
	resultArray.sort();
	var message = new String(resultArray);
	alert(message.replace(/,/g,', '));
}

function checkIfFunction(array, property, object)
{
	if(object[property])
	{
		var theValue = new String(object[property]);

		//alert(theValue);

		if(theValue.indexOf("function") < 0)
		//if(theValue.substring(1,9) != 'function')
			array.push(property + ' = ' + theValue);
	}
}


var gLinks = new Array();
var helpLinks = new Array();
var glossaryText = new Array();
var glossaryCount = 0;

var gLoadingComplete = false;

var bVersion = 0;
var bBrowser = null;
var bPlatform = null;


function checkBrowser()
{

	//bVersion = parseInt(navigator.appVersion);
	
	//bBrowser = (navigator.userAgent.indexOf("MSIE") > -1) ? "IE" : "Other";
	if (navigator.appVersion.indexOf("MSIE")!=-1)
	{
		bBrowser = "IE";
		temp = navigator.appVersion.split("MSIE")
		bVersion = parseFloat(temp[1]);
		
	}
	else
	{
		bBrowser = "Other";
	}
		
	if(bBrowser != "IE")
	{
		bBrowser = (navigator.userAgent.indexOf("Netscape") > -1) ? "Netscape" : "FireFox";
	}

	if(navigator.userAgent.indexOf("Opera") > -1)
		bBrowser = "Opera";

	if(navigator.userAgent.indexOf("Safari") > -1)
		bBrowser = "Safari";

	bPlatform = (navigator.userAgent.indexOf("Mac") > -1) ? "Mac" : "PC";

	
}





function removeTooltip()
{
		if(el("tooltip"))
		{
			var target = el("tooltip");
			target.style.display = "none";
		}
}

var obj = null;


function doGOver(e)
{

	if(gLoadingComplete)
	{
		var ev;

		//if(document.all)
		if (bBrowser == "IE")
		{
			ev = window.event;
			obj  = ev.srcElement;
		}
		else
		{
			ev = e;
			obj  = e.currentTarget;
		}
		
		var target = el("tooltip");
		
		if(el("popup"))
		{
		    el("tooltip").className = "reverse-tooltip";
		}
		
		target.style.display = "block";

		if(glossaryText[obj.gid] == "undefined" || glossaryText[obj.gid] == null)
		{
			target.style.display = "none";
			return;
		}

		el("text").innerHTML = glossaryText[obj.gid];

		var characterLength = el("text").innerHTML.length;
		var contentHeight = Math.ceil(characterLength/44)*14;
		var topposition = contentHeight + 47;
		target.style.display = "block";
		
		//if(document.all)
		if (bBrowser == "IE")
		{
			var tempX = ev.clientX + document.body.scrollLeft;
			var tempY = ev.clientY + document.body.scrollTop;

			target.style.top = (tempY - topposition) + "px";
			target.style.left = tempX + "px";
			
			if(el("popup"))
		    {
		        target.style.left = (tempX - 220) + "px";
		    }
		}
		else
		{
			var tempX = ev.clientX + window.pageXOffset;
			var tempY = ev.clientY + window.pageYOffset;
			
			target.style.top = (tempY - topposition) + "px";
			target.style.left = tempX + "px";
			
			if(el("popup"))
		    {
		        target.style.left = (tempX - 220) + "px";
		    }
		}

		ev.preventDefault();

	}
}

function doHOver(e)
{
    var ev;

	//if(document.all)
	if (bBrowser == "IE")
	{
		ev = window.event;
		obj = ev.srcElement;
	}
	else
	{
		ev = e;
		obj  = e.currentTarget;
	}
	
	var target = el("tooltip");
	var IE6Iframe = el("hideSelect");
	
	if(el("popup"))
	{
	    el("tooltip").className = "reverse-tooltip";
	}
	
	target.style.display = "block";
    
    var characterLength = el("text").innerHTML.length;
	var contentHeight = Math.ceil(characterLength/44)*14;
	var topposition = contentHeight + 60;
	target.style.display = "block";

	
    var commentIndex = this.href.split("?help=")[1];
	el("text").innerHTML = getHelpComment(commentIndex);

	
	if (bBrowser == "IE")
	{
		var tempX = ev.clientX + document.body.scrollLeft;
		var tempY = ev.clientY + document.documentElement.scrollTop;
		
		target.style.top = (tempY - topposition) + "px";
		target.style.left = tempX + "px";
		
		if(el("popup"))
	    {
	        target.style.left = (tempX - 220) + "px";
	        if(tempX < 220)
	        {
	            target.style.left = (tempX) + "px";
	            target.className = "";
	        }
	    }
	}
	else
	{
		var tempX = ev.clientX + window.pageXOffset;
		var tempY = ev.clientY + window.pageYOffset;
		
		target.style.top = (tempY - topposition) + "px";
		target.style.left = tempX + "px";
		
		if(el("popup"))
	    {
	        target.style.left = (tempX - 220) + "px";
	        if(tempX < 220)
	        {
	            target.style.left = (tempX) + "px";
	            target.className = "";
	        }
	    }
	    

	}

	ev.preventDefault();
}

function StopClickThrough(e) {
    var ev;

    if (bBrowser == "IE") {
        ev = window.event;
        obj = ev.srcElement;
    }
    else {
        ev = e;
        obj = e.currentTarget;
    }

    ev.preventDefault();
    
    return false;
}

// Array of help comments for calculators
var commentArray = [];

function getHelpComment(index)
{
    //array of comments
    commentArray[0] = "The total amount payable for the full financial year in Year 1. This amount assumes a pension start date of 1 July.";
    commentArray[1] = "The total amount payable in Year 1, from the date you started your pension (assumed to be today) through to 30 June.  If your pension starts on a date other than 1 July, the amount shown will be pro-rated.";
    commentArray[2] = "Whole numbers between 1% and 5% only.";
    commentArray[3] = "Indexing your pension payments each year will help you to keep up with inflation. Indexation is not available if you have selected the 'Minimum' pension payment amount.";
    commentArray[4] = "See Assumptions for further information about the investment strategy and crediting rates applicable to each option.";
    commentArray[5] = "Under Government legislation, there is a minimum amount you must withdraw from your pension account each financial year. This amount is based on your age and is calculated on your account balance as at 1 July each year (see table below): <br><br><table><tr><th>Age</th><th>% p.a.</th></tr><tr><td>0</td><td>0%</td></tr><tr><td>55</td><td>4%</td></tr><tr><td>65</td><td>5%</td></tr><tr><td>75</td><td>6%</td></tr><tr><td>80</td><td>7%</td></tr><tr><td>85</td><td>9%</td></tr><tr><td>90</td><td>11%</td></tr><tr><td>95+</td><td>14%</td></tr></table>";
	commentArray[6] = "This is the amount that Centrelink would deem as income if your money was invested in a pension rather than held in a bank account.";
	commentArray[7] = "This is the amount that Centrelink would deem as income if your money was invested in a bank account rather than a pension account.";
	
	// For Transition to retirement calculator array is in order of items appearance in calculator
	commentArray[8] = "A Transition to Retirement Pension is only applicable to members aged between 55 and 65 who have not met a condition of release (eg. permanently retired from the work force) which allows them to access their preserved benefits.  If you are aged 65 or over, you can access your superannuation as either a lump sum or a pension without the need to take up the transition to retirement option, even if you are still working.";
	commentArray[9] = "Change your annual voluntary contribution amount to see the effect on your retirement savings. This is a dollar amount and is payable from your after-tax salary or other savings or assets.";
	commentArray[10] = "The part of your superannuation balance that may be subject to tax on withdrawal, depending on your age. Contact your Fund for this information.";
	commentArray[11] = "Shows the combined value of your retirement savings and take home pay if you do not implement a transition to retirement strategy and simply continue accumulating superannuation using the current employer contributions, salary sacrifice and voluntary contributions you have input.";
	commentArray[12] = "Shows the combined value of your retirement savings and take home pay if you do implement a transition to retirement strategy, based on the revised input values you have provided.";
	commentArray[13] = "Shows the combined value of your retirement savings and take home pay if you do implement a transition to retirement strategy. The optimum result indicates the optimum input values for pension payments and extra salary sacrifice contributions needed to provide the highest overall superannuation and pension account balances while maintaining current take-home pay each year.";
	commentArray[14] = "Change your annual pension payment amount to see the effect on your retirement savings. The minimum and maximum amounts you must withdraw from your pension account each financial year are shown.  The optimum payment is the amount that is expected to provide the highest overall superannuation and pension account balances while maintaining current take-home pay each year.";
	commentArray[15] = "Indexing your pension payments each year will help you to keep up with inflation.  You can choose to index your payments in line with inflation (CPI) or can choose a whole number between 1-5%. Indexation is not available if you have nominated the minimum pension payment amount.";
	commentArray[16] = "Change your annual salary sacrifice amount to see the effect on your take home pay and your retirement savings.  The optimum amount indicates the additional salary sacrifice and optimum pension payment required to provide the highest overall superannuation and pension account balances while maintaining current take-home pay each year.";
	commentArray[17] = "The amount used as the basis to calculate your Superannuation Guarantee (SG) contributions.";
	commentArray[18] = "The amount you contribute to superannuation each year from your after-tax salary or other savings or assets, expressed in dollars.";
    commentArray[19] = "The amount you contribute to superannuation each year before tax is deducted from your salary. This can be a dollar amount, a percentage of your salary, or both.";
    commentArray[20] = "Change the age you permanently retire from the workforce to see the effect on your retirement savings.  A Transition to Retirement Pension is only applicable to members aged between 55 and 65 who are still working.  If you are aged 65 or over, or you are aged 55-64 and have permanently retired from the workforce, you can access your superannuation by taking up a pension without the transition option or by receiving a lump sum payment.";
    commentArray[21] = "Change your annual salary sacrifice amount to see the effect on your take home pay and retirement savings.  This can be a dollar amount, a percentage, or both and is deducted from your salary before tax.";
    
	/*  Table for tooltip
        <br><br><div class='wysiwyg_table'><table cellpadding='0' cellspacing='0' border='0'><tr><th><strong>Age on 1 July</strong></th><th><strong>Percentage of account balance</strong></th></tr><tr><td>Under 65</td><td>4%</td></tr><tr><td>65 to 74</td><td>5%</td></tr><tr><td>75 to 79</td><td>6%</td></tr><tr><td>80 to 84</td><td>7%</td></tr><tr><td>85 to 89</td><td>9%</td></tr><tr><td>90 to 94</td><td>11%</td></tr><tr><td>95 or older</td><td>14%</td></tr></table></div>
    */
    return commentArray[index];
}


function initGlossary()
{
	
	checkBrowser();

	if(bBrowser == "IE" && bPlatform == "Mac" || (document.layers))
	{
		return;
	}

		for(i=0;i<document.links.length;i++)
		{
			// if this is a glossary link
			if(String(document.links[i].href).indexOf("tools-forms_glossary.aspx?g") > -1)
			{
				//set mouseover
				document.links[i].onmouseover = doGOver;
				document.links[i].onmouseout = removeTooltip;
				//document.links[i].onmouseout = function(){doGOff()};

				// split href.search param on constant delimeter
				var str = unescape(document.links[i].search).split("?g=");

				//load the glossary title into the glossary array
				gLinks.push(str[1]);

				//set expando/custom property "gid" which is the title of the glossary item
				//so we can access the right glossary item for each link.
				document.links[i].gid = str[1];

				glossaryCount ++;
			}
			else if(String(document.links[i].href).indexOf("?help") > -1 && !(document.links[i].hash))
			{
				//set mouseover
				document.links[i].onmouseover = doHOver;
				document.links[i].onmouseout = removeTooltip;
				document.links[i].onclick = StopClickThrough;
				
				// split href.search param on constant delimeter
	            var str = unescape(document.links[i].search).split("?help=");
	            helpLinks.push(str[1]);
			}
		}
		buildQuery()
}


function buildQuery()
{
	var str = new String();

	// loop through glossary array and delimit with ####
	for(i=0;i<gLinks.length;i++)
	{
		str += gLinks[i];
		if(i < gLinks.length-1)
		str += "####";
	}

	// this will be a Form item called "q" in the ajax request
	str = "q=" + str;

	//call server with supplied callback function and params
	http( "POST", "glossary.ashx" , parseResponse,str);
}


function parseResponse(result)
{
	/*
		The text from the server contains the glossary title and glossary content
		Glossary items are delimited by $$$$
		Each glossary items is then delimited by ####
	*/



	var returnedText = result.split("$$$$");
	var gText;

	for(i=0;i<returnedText.length;i++)
	{
		gText = returnedText[i].split("####");
		//set associative array key to be title of glossary
		//set associative array value to be content of glossary
		glossaryText[gText[0]] = gText[1];
	}
	gLoadingComplete = true;

}

//*** end glossary items parsing



//**** Start engine.js code
/* --------------------------------------------------------------------------------------------------------------
*	API:			JSMX (JavaScript MX) - Universal Ajax API for ColdFusion, PHP, .NET, or anything other language.
*	AUTHOR: 		Todd Kingham [todd@lalabird.com] with contributions by Jan Jannek [jan.jannek@Cetecom.de]
*	CREATED:		8.21.2005
*	VERSION:		2.6.1
*	DESCRIPTION:	This API uses XMLHttpRequest to post/get data from a ColdFusion interface.
*					The CFC's/CFM's will return a string representation of a JS variable: response_param.
*					The "onreadystatechange event handler" will eval() the string into a JS variable
*					and pass the value back to the "return function". To Download a full copy of the sample
*					application visit: http://www.lalabird.com/JSMX/?fa=JSMX.downloads
*
*	HISTORY:		2.0.0:	Todd: Scripted Out Original Version
*					2.1.0:	Todd: Modified for Download
*					2.2.0:	Todd: Modified the firstWord() function to be backward compatable with
*								  CF5 and to be more stable all-around.
*					2.3.0:	Todd: Added "wait div" functionality
*					2.4.0:	Todd: XML!!!! Now JSMX will allow you to pass XML Documents to the API in
*								  addition to the original JavaScript method.
*					2.4.1:	Jan:  2006-02-16, XMLHTTP requests can now handle more than one request at once. By placing the onreadystatechange event as a local variable inside the actual http() function.
*							Jan:  Added fix for strange IE bug that returned Header Info.
*							Todd: Added the jsmx object to allow users to override defaults and set custom "async", "wait" and "error" methods
*					2.5.0:	Todd: Added JSON Support! So now you can pass JavaScript, XML, or JSON.
*					2.5.1:	Todd: Version 2.5.0 was premature. Needed to fix an eval() bug when I introduced JSON.
*					2.5.2:	Todd: Fixed a bug in the onreadystatechange. Based on the order you call the event handler... "State Change 1" gets called twice. Added code to only process code inside 'CASE 1:' once
*					2.5.3:	Todd: Fixed a bug in the try/catch of the parser by placing the callback() call within the try/catch statement. This caused errors in the callback function to be "masked" and appear as "parsing errors", even when the parse was successful.
*					2.6.0: 	Todd: Added WDDX Parser! Now you can return WDDX Strings as well.
					2.6.1:	Todd: Streamlined the ClassicMode and JSON parser into one function.
*
*	LICENSE:		THIS IS AN OPEN SOURCE API. YOU ARE FREE TO USE THIS API IN ANY APPLICATION,
*               	TO COPY IT OR MODIFY THE FUNCTIONS FOR YOUR OWN NEEDS, AS LONG THIS HEADER INFORMATION
*              	 	REMAINS IN TACT AND YOU DON'T CHARGE ANY MONEY FOR IT. USE THIS API AT YOUR OWN
*               	RISK. NO WARRANTY IS EXPRESSED OR IMPLIED, AND NO LIABILITY ASSUMED FOR THE RESULT OF
*               	USING THIS API.
*
*               	THIS API IS LICENSED UNDER THE CREATIVE COMMONS ATTRIBUTION-SHAREALIKE LICENSE.
*               	FOR THE FULL LICENSE TEXT PLEASE VISIT: http://creativecommons.org/licenses/by-sa/2.5/
*
-----------------------------------------------------------------------------------------------------------------*/
// UNCOMMENT THE FOLLOWING LINE IF YOU WILL BE RETURNING QUERY OBJECTS. (note: you may need to point the SRC to an alternate location.
/*document.writeln('<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="/CFIDE/scripts/wddx.js"></SCRIPT >');*/

var jsmx = new jsmxConstructor();
function jsmxConstructor(){
	this.isJSMX = true;
	this.async = true;
	this.debug = false;
	this.waitDiv = 'JSMX_loading';
	this.http = http;
	this.onWait = _popWait;
	this.onWaitEnd = _killWait;
	this.onError = _onError;
}
// perform the XMLHttpRequest();
function http(verb,url,cb,q) {
	var self = (this.isJSMX) ? this : jsmx ;
	//reference our arguments
	var qryStr = (!q) ? '' : _toQueryString(q);
	var calledOnce = false; //this is to prevent a bug in onreadystatechange... "state 1" gets called twice.
	try{//this should work for most modern browsers excluding: IE Mac
		var xhr = ( window.XMLHttpRequest ) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ;
			xhr.onreadystatechange = function(){
				switch(xhr.readyState){
					case 1:
						if(!calledOnce){
							self.onWait(self.waitDiv);
							calledOnce = true;
						} 	break;
					case 2: break;
					case 3: break;
					case 4:
						self.onWaitEnd(self.waitDiv);
						if ( xhr.status == 200 ){// only if "OK"
							var success = true;
							try{
								var rObj = _parseResponse( xhr );
							}catch(e){
;
								self.onError(xhr,self,1);
								success = false;
							}
							if(success){ cb( rObj ); }
						}else{

							self.onError(xhr,self,2);
						}
					delete xhr.onreadystatechange; //clean this function from memory once we re done with it.
					break;
				}
			};
			xhr.open( verb , _noCache(url) , self.async );
			if(verb.toLowerCase() == 'post') { xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); }
			xhr.send(qryStr);
	}catch(e){
		self.onError(xhr,self,3);
	}
}

/*--- BEGIN: RESPONSE PARSING FUNCTIONS ---*/
function _parseResponse($$){

	var str = _cleanString($$.responseText);
	return str;
	/*

	 var xml = $$.responseXML;
	//FIRST TRY IT AS XML
		if(xml != null && xml.childNodes.length){ return xml; }
	//NEXT TRY IT AS WDDX
		if(str.indexOf("<wddxPacket") == 0){ return _parseWDDX(str); }
	//NEXT TRY IT AS JSON
		try{ return eval('('+str+')'); }
	//NEXT TRY IT AS JavaScript
		catch(e){ return _parseJS(str); }
	*/
}
// jan.jannek@cetecom.de, 2006-02-16, weird error: some IEs show the responseText followed by the complete response (header and body again)
function _cleanString(str){
	//Left Trim
	var rex = /\S/i;
	str = str.substring(str.search(rex),str.length);

	var i = str.indexOf("HTTP/1");
	if (i > -1) {
		str = str.substring(i, str.length);
		i = str.indexOf(String.fromCharCode(13, 10, 13, 10));
		if (i > -1) { str = str.substring(i + 2, str.length); }
	}
	return str;
}
function _parseJS(str){
	eval(str);
	var r = eval(str.split('=')[0].replace(/\s/g,''));
	return r;
}
function _parseWDDX(str){ var wddx = xmlStr2Doc(str); var data = wddx.getElementsByTagName("data"); return _parseWDDXnode(data[0].firstChild); } function xmlStr2Doc(str){ var xml; if(typeof(DOMParser) == 'undefined'){ xml=new ActiveXObject("Microsoft.XMLDOM"); xml.async="false"; xml.loadXML(str); }else{ var domParser = new DOMParser(); xml = domParser.parseFromString(str, 'application/xml'); } return xml; } function _parseWDDXnode(n){ var val; switch(n.tagName){ case 'string': val = _parseWDDXstring(n); break; case 'number': val = parseInt(n.firstChild.data); break; case 'boolean': val = n.getAttribute('value'); break; case 'dateTime': val = Date(n.firstChild.data); break; case 'array': val = _parseWDDXarray(n); break; case 'struct': val = _parseWDDXstruct(n); break; case 'recordset': val = _parseWDDXrecordset(n); break; case 'binary': val = n.firstChild.data; break; case 'char': val = _parseWDDXchar(n);; break; case 'null': val = ''; break; default: val = n.tagName; break; } return val; } function _parseWDDXstring(node){ var items = node.childNodes; var str = ''; for(var x=0;x < items.length;x++){ if(typeof(items[x].data) != 'undefined') str += items[x].data; else str += _parseWDDXnode(items[x]); } return str; } function _parseWDDXchar(node){ switch(node.getAttribute('code')){ case '0d': return '\r'; case '0c': return '\f'; case '0a': return '\n'; case '09': return '\t'; } } function _parseWDDXarray(node){ var items = node.childNodes; var arr = new Array(); for(var i=0;i < items.length;i++){ arr[i] = _parseWDDXnode(items[i]); } return arr; } function _parseWDDXstruct(node){ var items = node.childNodes; var obj = new Object(); for(var i=0;i < items.length;i++){ obj[items[i].getAttribute('name').toLowerCase()] = _parseWDDXnode(items[i].childNodes[0]); } return obj; } function _parseWDDXrecordset(node){ var qry = new Object(); var fields = node.getElementsByTagName("field"); var items; var dataType; var values; for(var x = 0; x < fields.length; x++){ items = fields[x].childNodes; values = new Array(); for(var i = 0; i < items.length; i++){ values[values.length] = _parseWDDXnode(items[i]); } qry[fields[x].getAttribute('name').toLowerCase()] = values; } return qry; }
/*--- END: RESPONSE PARSING FUNCTIONS ---*/


/*--- BEGIN: REQUEST PARAMETER FUNCTIONS ---*/
	function _toQueryString(obj){
		//determine the variable type
		if(typeof(obj) == 'string') { return obj; }
		if(typeof(obj) == 'object'){
			if(typeof obj.elements == 'undefined') {return _object2queryString(obj); }//It's an Object()!
			else{ return _form2queryString(obj); }//It's a form!
		}
	}
	function _object2queryString(obj){
		var ar = new Array();
		for(x in obj){ ar[ar.length] = x+'='+obj[x]; }
		return ar.join('&');
	}
	function _form2queryString(form){
		var obj = new Object();
		var ar = new Array();
		for(var i=0;i < form.elements.length;i++){
			try {
				elm = form.elements[i];
				nm = elm.name;
				if(nm != ''){
					switch(elm.type.split('-')[0]){
						case "select":
							for(var s=0;s < elm.options.length;s++){
								if(elm.options[s].selected){
									if(typeof(obj[nm]) == 'undefined'){ obj[nm] = new Array(); }
									obj[nm][obj[nm].length] = escape(elm.options[s].value);
								}
							}
							break;
						case "radio":
							if(elm.checked){
								if(typeof(obj[nm]) == 'undefined'){ obj[nm] = new Array(); }
								obj[nm][obj[nm].length] = escape(elm.value);
							}
							break;
						case "checkbox":
							if(elm.checked){
								if(typeof(obj[nm]) == 'undefined'){ obj[nm] = new Array(); }
								obj[nm][obj[nm].length] = escape(elm.value);
							}
							break;
						default:
							if(typeof(obj[nm]) == 'undefined'){ obj[nm] = new Array(); }
							obj[nm][obj[nm].length] = escape(elm.value);
							break;
					}
				}
			}catch(e){}
		}
		for(x in obj){ ar[ar.length] = x+'='+obj[x].join(','); }
	return ar.join('&');
	}
/*--- END: REQUEST PARAMETER FUNCTIONS ---*/

//IE likes to cache so we will fix it's wagon!
function _noCache(url){
	var qs = new Array();
	var arr = url.split('?');
	var scr = arr[0];
	if(arr[1]){ qs = arr[1].split('&'); }
	qs[qs.length]='noCache='+new Date().getTime();
return scr+'?'+qs.join('&');
}
function _popWait(id){
	proc = el(id);
	if( proc == null ){
		var p = document.createElement("div");
		p.id = id;
		document.body.appendChild(p);
	}
}
function _killWait(id){
	proc = el(id);
	if( proc != null ){ document.body.removeChild(proc); }
}
function _onError(obj,inst,errCode){
	var msg;

	//alert(obj.responseText);

	switch(errCode){
		case 1:/*parsing error*/
			msg = (inst.debug) ? obj.responseText : 'Parsing Error: The value returned could not be evaluated.';
			break;
		case 2:/*server error*/
			msg = (inst.debug) ? obj.responseText : 'There was a problem retrieving the data:\n' + obj.status+' : '+obj.statusText;
			break;
		case 3:/*browser not equiped to handle XMLHttp*/
			msg = 'Unsupported browser detected.';
			return;/*you can remove this return to send a message to the screen*/
			break;
	}
	if(inst.debug){
		var debugWin = window.open('','error');
		debugWin.document.write(msg);
		debugWin.focus();
	}else{
		alert(msg);
	}
}

//*** end engine.js code