var ttfb = new Date();

/**
 * This is the Cookie() constructor function.
 *
 * This constructor looks for a cookie with the specified name for the
 * current document.  If one exists, it parses its value into a set of 
 * name/value pairs and stores those values as properties of the newly created
 * object.
 *
 * To store new data in the cookie, simply set properties of the Cookie
 * object.  Avoid properties named "store" and "remove", since these are
 * reserved as method names.
 *
 * To save cookie data in the web browser's local store, call store().
 * To remove cookie data from the browser's store, call remove().
 *
 * The static method Cookie.enabled() returns true if cookies are 
 * enabled and returns false otherwise.
 */
function Cookie(name, debug) 
{
	this.$name = name; // Remember the name of this cookie
	// First, get a list of all cookies that pertain to this document.
	// We do this by reading the magic Document.cookie property.
	// If there are no cookies, we don't have anything to do.
	var allcookies = "";
	allcookies = document.cookie;
	
	if( "" === allcookies) { return;}
	
	// Break the string of allcookies into individual cookie strings
	// Then loop through the cookie string, looking for our name
	var cookies = allcookies.split(';');
	var cookie = null;
	
	
	for(var i = 0; i < cookies.length; i++)
	{
		// Does this cookie string begin with the name we want?
		var start = 0;
		
		var cookievalue = cookies[i];
		
		if( cookievalue.charAt(0) == ' ') { start = 1;}
		var length = cookievalue.indexOf('=') + 1;
		
		var cookiename = cookievalue.substring( start, length );
		
		if(debug){ alert( "cookie name =" + cookiename );}
		
		if( cookies[i].substring(start, length) == (name + "="))
		{
			cookie = cookies[i];
			break;
		}
	}
	
	// If we didn't find a matching cookie, quit now
	if(cookie === null) { return;}
	
	
	// 	The cookie value is the part after the equals sign
	var cookieval = cookie.substring( name.length + 2);
	
	// Now that we've extracted the value of the named cookie, we
	// must break that value down into individual state variable
	// names and values.  The name/value pairs are separated from 
	// each other by ampersands, and the individual names and values are
	// separated from each otehr by colons.  We use the split() method
	// to parse everything.
	var a = cookieval.split('&');  // Break it into an array of name/value pairs
	for( i=0; i < a.length; i++)
	{
		a[i] = a[i].split(':');
	}
	// Now that we've parsed the cookie value, set all the names and values
	// as properties of this Cookie object.  Note taht we decode
	// the property value because the store() method encodes it.
	for( i = 0; i < a.length; i++)
	{
		this[a[i][0]] = decodeURIComponent( a[i][1] );
	}
	
}
/**
 * Arguments:
 * daysToLive: the lifetime of the cookie, in days.  If you set this 
 *   to zero, the cookie will be deleted.  If you set it to null, or 
 *   omit this argument, the cookie will be a session cookie and will
 *   not be retained when the browser exits.  This argument is used to
 *   set the max-age attribute of the cookie.
 * path: the value of the path attribute of the cookie
 * domain: the value of the domain attribute of the cookie
 * secure: if true, the secure attribute of the cookie will be set
 */
Cookie.prototype.store = function(daysToLive, path, domain, secure) 
{
	this.minutesStore( daysToLive * 24 * 60, path, domain, secure);
};
Cookie.prototype.minutesStore = function( minutesToLive, path, domain, secure)
{
	// First, loop through the properties of the Cookie object and
	// put together the value of the cookie.  Since cookies use the
	// equals sign and semicolons as separators, we'll use colons 
	// and ampersands for the individual state variables we store
	// within a single cookie value.  Note that we encode the value 
	// of each property in case it contains punctuation or other
	// illegal characters.
	var cookieval = "";
	var date = new Date();
	date.setTime( date.getTime() + (minutesToLive * 60 * 1000));
	for( var prop in this) 
	{
		// Ignore properties with names that begin with '$' and also methods
		if(( prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
		{
			continue;
		}
		if( cookieval !== "") { cookieval += '&'; }
		cookieval += prop + ":" + encodeURIComponent(this[prop]);
	}
	
	// Now that we have the value of the cookie, put together the
	// complete cookie string, which includes the name and the various
	// attributes specified when the Cookie object was created
	var cookie = this.$name + "=" + cookieval;
	if( minutesToLive || minutesToLive === 0)	{
		cookie += "; expires=" + date.toUTCString();
	}
	
	if(!path) {  path = "/"; }
	cookie += "; path=" + path;
	if(domain){ cookie += "; domain=" + domain;}
	if(secure){ cookie += "; secure";}
	
	// Now store the cookie by setting the magic Document.cookie property
	document.cookie = cookie;
	//alert(cookie);
};

/**
 * This function is the remove() method of the Cookie object; it deletes the 
 * properties of the object and removes the cookie from the browser's 
 * local store.
 *
 * The arguments to this function are all optional, but to remove a cookie
 * you must pass the same values you passed to store().
 */
Cookie.prototype.remove = function(path, domain, secure)
{
	// Delete the properties of the cookie.
	for( var prop in this) 
	{
		if( prop.charAt(0) !== '$' && typeof( this[prop] != 'function') )
		{
			delete this[prop];
		}
	}
	// Then, store the cookie with a lifetime of 0
	this.store(0, path, domain, secure);
};

/**
 * This static method attempts to determine whether cookies are enabled.
 * It returns true if they appear to be enabled and false otherwise.
 * A return value of true does not guarantee that cookies actually persist.
 * Nonpersistent session cookies may still work even if this method
 * returns false.
 */
Cookie.enabled = function() {
	// Use navigator.coookieEnabled if this browser defines it
	//alert( navigator.cookieEnabled) 
	if(navigator.cookieEnabled !== undefined){ return navigator.cookieEnabled;}
	
	// If we've already cached a value, use that value
	//alert( Cookie.enabled.cache)
	if(Cookie.enabled.cache !== undefined) {return Cookie.enabled.cache;}
	
	// Otherwise create a test cookie with a lifetime
	document.Cookie = "testcookie=test; max-age=10000";  // Set cookie
	
	// Now we see if that cookie was saved
	var cookies = document.cookie;
	if(cookies.indexOf("testcookie=test") == -1)
	{
		//The cookie was not saved
		Cookie.enabled.cache = false;
	}
	else
	{
		// Cookie was saved, so we've got to delete it before returning
		document.cookie = "testcookie=test; max-age=0";  // Delete cookie
		Cookie.enabled.cache = true;
	}
	return Cookie.enable.cache;
};
function sleep( numberMillis) 
{
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while(true)
	{
		now = new Date();
		if( now.getTime() > exitTime) {return;}
	}
}
String.prototype.trim = function (str) {
    var str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
    while (ws.test(str.charAt(--i)));
    return str.slice(0, i + 1);
}

/**
 * Function to hide or display help or instruction text on a webpage
 * the function searches for all elements that have the class helptext 
 * assigned to them and modifies their display properties to toggle between
 * showing and hiding the helptext.
 */
function displayhelpstate(debug) {
	var cookie = new Cookie("helpstate");

	if(debug) { alert( "displaystate:" + cookie.displaystate + "<BR>");}
	
	if(!cookie.displaystate) { // Set the cookie if it doesn't exist.
 		cookie.displaystate = "false"; //Null defaults to false.
		cookie.minutesStore(null);
	}

	if(debug){ alert( "displaystate:" + cookie.displaystate + "<BR>");}

	var all = document.getElementsByTagName("DIV");  // Get all elements on the page
	
	for(var i = 0; i < all.length; i++) 
	{
		var element = all[i];
		//if(debug) alert("element: " + element + "<BR>");
		if( element.className == "helptext" ) // only modify he display properties of elements with class = helptext
		{
			if(cookie.displaystate == "true")
			{ 
				element.style.display = "block";
			}
			else if (cookie.displaystate == "false")
			{
				element.style.display = "none";
			}
		}
	}
}
/*
 * This function will switch the helpstate to either true or false
 * depending on the previous value.  Null represents false.
 * the value will be saved in a cookie called "helpstate" and is valid for the whole site.
 */
function switchhelpstate(debug) 
{
	var cookie = new Cookie("helpstate");

	if(debug) { alert( "displaystate:" + cookie.displaystate + "<BR>");}

	if( !cookie.displaystate || cookie.displaystate == "false") { cookie.displaystate = "true";}
	else { cookie.displaystate = "false";}
	
	if(debug) {alert( "displaystate:" + cookie.displaystate + "<BR>");}
	
	cookie.minutesStore(null);  // saved as session cookie. 
	displayhelpstate( debug); // now show the helpstate
}
function viewcookievalues( cookiename) 
{
	var cookie = new Cookie(cookiename);
	
	var cookiestring = "";
	
	for( var prop in cookie)
	{
		if( prop.charAt(0) != '$' && typeof cookie[prop] != 'function' )
			{cookiestring += prop + " : " +  cookie[prop] + "<br>";}
	}
	return cookiestring;
}
function SearchSubmit( elementid)
{
	var data;
	var element;
	if( elementid !== null) 
	{
		element = document.getElementById( elementid);
		data = element.value;	
	}
	else 
	{
		element = document.getElementById( "SearchTextBox");
		data = element.value;
	}
	var url = "/Main/SearchSecurity.aspx";
	location.href = url + "?search="  + escape(data);
}
function ClearText( element) 
{
	element.value = "";
}
function CheckEnter( element, evt)
{
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode :
		( (evt.which) ? evt.which : evt.keyCode);
	
	if( charCode == 13 || charCode == 3)
	{
		SearchSubmit( element.id);
		return false;
	}
	return true;
}
/*
 * This function parses ampersand-separated name=value argument pars from
 * the query string of the URL.  It stores the name=vlaue pairs in
 * properties of an object and returns that object.  Use it like this:
 *
 * var args = getArgs();  // Parse args from URL
 * var q = args.q || ""; // Use argument, if defined, or a default value
 * var n = args.n ? parseInt(args.n) : 10;
 */
 function getArgs() 
 {
	var args = {};
	var query = location.search.substring(1).replace('#','');  // Get query string
	var pairs = query.split("&");
	
	for( var i = 0; i < pairs.length; i++) 
	{
		var pos = pairs[i].indexOf('=');
		if( pos == -1) 
			{continue;}
		var argname = pairs[i].substring( 0, pos);
		var value = pairs[i].substring(pos+1);
		value = decodeURIComponent(value);
		args[argname] = value;
	}
	return args;
}
function appendQuery( query, key, value)
{
	if( value != "")
	{
		query += query == "" ? "?" : "&" ;
		query += key + "=" + value;
	}
	return query;
}
function GetCookieValue( cookiename) 
{
	var cookies = "";
	cookies = document.cookie;
	//alert(cookies);
	var cookielist = cookies.split('; ');
	for( var i = 0; i < cookielist.length; i++) 
	{
		var pair = cookielist[i].split('=');
		//alert( " key = " + pair[0] + " value = " + pair[1]);
		if( pair[0] == cookiename)
			{return pair[1];}
	}
}

function ThisUser() 
{
	this.Type = "Guest";
	var cookievalue = "";
	cookievalue = GetCookieValue("ThisUser");
	if (cookievalue != null) {
	    var cookievaluelist = cookievalue.split('|');
	    this.UserId = cookievaluelist[0];
	    this.GroupId = cookievaluelist[1];
	    //alert("userid = " + this.UserId + " groupid = " + this.GroupId);
	}
	else {
	    this.UserId = "";
	    this.GroupId = "";
	}
}
function logout() {
    var cookie = new Cookie("ThisUser");
    cookie.remove();

    window.location.reload(true);
}
function CreateUniqueString() 
{
	var now = new Date();
	var basestr = now.getTime(); // Returns time in milli seconds since 1/1/1970
	var m = 1000001;
	var n = 9999999;
	var randomstr = Math.floor( Math.random() * (n - m + 1)) + m;
	return basestr + ":" + randomstr;
}
function SetAnalyticsCookie( type) 
{
	var cookie = new Cookie(type,false);
	var now = new Date();
	if( type == "lifetime")
	{
		if( !cookie.Value)
		{
			cookie.Value = "LT:" + CreateUniqueString();
			cookie.DateCreated = now.toUTCString();
			cookie.store(365);
		}
	}
	else if (type == "session") 
	{
		if( !cookie.Value)
		{
			//alert( type + " was here");
			cookie.Value = "S:" + CreateUniqueString();
			//alert( cookie.Value);
			cookie.DateCreated = now.toUTCString();
			//alert( cookie.DateCreated);
			cookie.minutesStore(20);
			
		}
		else
		{
			cookie.minutesStore(20);
		}
	}
	else if (type == "monthly")
	{
		if( !cookie.Value)
		{
			cookie.Value = "M:" + CreateUniqueString();
			cookie.DateCreated = now.toUTCString();
			cookie.store( 31);
		}
	}
}
function SetLoginHelper() {
    var cookie = new Cookie("LoginHelper", false);
    cookie.Value = true;
    cookie.minutesStore(20);
}
function getLoginHelper() {
    var cookie = new Cookie("LoginHelper", false);
    var val = cookie.Value == undefined ? false : cookie.Value;
    return val;
}
function SetAnalyticsCookies() 
{
    //alert( document.cookie);
    SetSessionViews();
	SetAnalyticsCookie( "lifetime");
	SetAnalyticsCookie( "session");
	SetAnalyticsCookie( "monthly");
}
function SetSessionViews() {
    var cookie = new Cookie("SessionViews", false);
    var counter = cookie.Value == undefined ? 0 : parseInt(cookie.Value); 
    cookie.Value = counter + 1;
    cookie.minutesStore(20);
}
function GetSessionViews() {
    var cookie = new Cookie("SessionViews", false);
    var counter = cookie.Value == undefined ? 0 : parseInt(cookie.Value);
    return counter;
}
function GetAnalyticsCookieValue( type) 
{
	var cookie = new Cookie(type,false);
	var val = cookie.Value;
	var dcreated = cookie.DateCreated;
	return val + "|" + dcreated;
}
function LogRequest( tracking) 
{
	var request = HTTPnewRequest();
	var random = Math.random();
	var lifetime = encodeURIComponent(GetAnalyticsCookieValue( "lifetime"));
	var session = encodeURIComponent(GetAnalyticsCookieValue( "session"));
	var monthly = encodeURIComponent(GetAnalyticsCookieValue( "monthly"));
	var ttlb = new Date();
	var loadtime = ttlb.getTime() - ttfb.getTime();
	var referrer = encodeURIComponent(document.referrer);
	if( tracking != null)
	{
		if( location.href.indexOf("?") == -1)
		{
			tracking = "&tracking=" + tracking;
		}
		else
		{
			tracking = "&tracking=" + tracking;
		}
	}
	else
	{
		tracking = "";
	}
	var url = encodeURIComponent(location.href + tracking);
	var title = encodeURIComponent(document.title);
	var cookiesenabled = Cookie.enabled();
	
	var transmissionurl = "/Main/SendAnalytics.aspx?";
	transmissionurl +=  "CookiesEnabled=" + cookiesenabled + "&lifetime=" + lifetime + "&session=" +session + "&monthly=" + monthly;
	transmissionurl += "&ttlb=" + loadtime + "&referrer=" + referrer + "&url=" + url + "&title=" + title + "&random=" + random;
	request.open("GET",transmissionurl,true);
	request.send(null);
	//alert( transmissionurl);
}
//Google analytics tracking helper code
var _GAtrack = {}; 
function _createGAObj(id) 
{ 
	try {
		window._GAtrack[id] = _gat._getTracker(id); 
	}
	catch(e)
	{}
}

function ToggleFeedbackForm() 
{
	var commenttextbox = document.getElementById("FooterNav1_FeedbackForm_titletextbox");
	var submitbutton = document.getElementById("FooterNav1_FeedbackForm_submitButton");
	var elem = document.getElementById("FeedbackFormPanel");
	//alert(elem);
	if( elem.style.display == "none")
	{
		elem.style.display = "block";
		submitbutton.focus();
		commenttextbox.focus();
		commenttextbox.select();
	}
	else
		{elem.style.display = "none";}
}

function SwitchAdvancedState( ) 
{
	var advanced = new Cookie("ValuationState");
	if( !advanced.State  || advanced.State == "0")
	{
		advanced.State = "1";
	}
	else
	{
		advanced.State = "0";
	}
	advanced.store();
	//	element.advanced = !element.advanced;
	SetAdvancedState();
}
function SetAdvancedState() 
{
	var advanced = new Cookie("ValuationState");
	var divs =  document.getElementsByTagName("div");
	var elementLink = document.getElementById("AdvancedLink");
	var elementText = document.getElementById("AdvancedText");
	for(var i = 0; i < divs.length; i++)
	{
		var div = divs[i];
		if(div.className == "AdvancedSection")
			{div.style.display = advanced.State == "1" ? "block" : "none";}
	}
	if( elementLink !== null)
		{elementLink.innerHTML = advanced.State == "1" ? "Simple" : "Advanced";	}
	if( elementText !== null) 
		{elementText.innerHTML = advanced.State == "1" ? "less" : "more";}
}
function SetFocus( elementid)
{
	elementid =  (elementid) ? elementid : "SearchTextBox";
	var textbox = document.getElementById(elementid);
	if( textbox === null)
		{textbox = document.getElementById("SearchTextBox");}
	if( textbox !== null)
		{textbox.focus();}
}
function SetSearchboxFocus( elementid) 
{
	SetFocus(elementid);
}
function ShowHelp( elementid, nopause) 
{
	var e = window.event;
	var iX = e.clientX;
	var iY = e.clientY;
	
	var i = 0;
	while( i++ < sleep(100)) {}
	
	var cX = e.clientX;
	var cY = e.clientY;
	
	var cR = Math.sqrt(Math.pow(iX - cX,2) + Math.pow(iY - cY,2));
	
	if( cR === 0) 
	{
		var element = document.getElementById( elementid);
		if( element.helpDisplayState != "Permanent") 
		{
			element.helpDisplayState = "Transitional";
			if( element !== null)
				{element.style.display = "block";}
		}
	}	
}
function HideHelp( elementid) 
{
	var element = document.getElementById( elementid);
	if( element.helpDisplayState != "Permanent") 
	{
		element.helpDisplayState = "Transitional";
		if( element !== null)
			{element.style.display = "none";}
	}
}
function SwitchHelp( elementid) 
{
	var element = document.getElementById( elementid);
	if( element.helpDisplayState === null || element.helpDisplayState == "Transitional")
	{
		element.style.display = "block";
		element.helpDisplayState = "Permanent";
	}
	else
	{
		if( element.style.display == "block" )
		{
			element.style.display = "none";
			element.helpDisplayState = "Transitional";
		}
		else
		{
			element.style.display = "block";
			element.helpDisplayState = "Permanent";
		}
	}

}
function getSilverlightVersion() {
	var version = '';
	var container = null;
	try {
		var control = null;
		if (window.ActiveXObject) {
			control = new ActiveXObject('AgControl.AgControl');
		}
		else {
			if (navigator.plugins['Silverlight Plug-In']) {
				container = document.createElement('div');
				document.body.appendChild(container);
				container.innerHTML= '<embed type="application/x-silverlight" src="data:," />';
				control = container.childNodes[0];
			}
		}
		if (control) {
			if (control.isVersionSupported('2.0')) { version = 'Silverlight/2.0'; }
			else if (control.isVersionSupported('1.1')) { version = 'Silverlight/1.1';}
			else if (control.isVersionSupported('1.0')) { version = 'Silverlight/1.0'; }
		}
	}
	catch (e) { }
	if (container) {
		document.body.removeChild(container);
	}
	return version;
}
function hideElement( helpElement)
{
	helpElement.style.position = "";
	helpElement.style.display = "none";
	helpElement.style.cssFloat = "";
	helpElement.style.top = "";
	helpElement.style.left = "";
}
function showHelp( element, helpElement)
{
	var offsetTrail = element;
	var offsetLeft = 0;
	var offsetTop = 0;
	while( offsetTrail)
	{
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	var helpParent = document.getElementById("helpMods");
	if( helpParent !== null)
	{
		var children = helpParent.childNodes;
		for( var i = 0; i < children.length; i++)
		{
			var child = children[i];
			if( child.nodeType == 1)
			{
				hideElement(child);
			}
		}
	}
	var size = get_windowSize();
	
	helpElement.style.position = "absolute";
	helpElement.style.display = "block";
	helpElement.style.cssFloat = "left";
	helpElement.style.top = (offsetTop + 20) + "px";
	var width = 0;
	if( window.getComputedStyle)
	{
		var compStyle = window.getComputedStyle( helpElement, "");
		width = parseInt(compStyle.getPropertyValue( "width"));
	}
	if( helpElement.currentStyle)
	{
		width = parseInt( helpElement.currentStyle.width);
	}
	var overEdge = offsetLeft - size.width + width + 10;
	helpElement.style.left = overEdge > 0 ? size.width - width -10 + "px" : offsetLeft + 10 + "px";
	
}

function handleHelpClick(element,helpId)
{
	var helpElement = document.getElementById(helpId);
	if( helpElement !== null)
	{
		if( helpElement.style.display == "none")
		{
			showHelp( element, helpElement);
		}
		else
		{
			hideElement( helpElement);
		}
	}
}
function navigate(choice)
{
	var url = choice.options[choice.selectedIndex].value;
	if( url !== "")
	{
		location.href = url;
	}
}
function navigateDropDown( choice)
{
	var element = document.getElementById(choice);
	if( element !== null)
	{
		navigate( element);
	}
	return false;
}
var glossaryList = 
[	{ name:"EquityHive",link:"/Main/"}
	, {name: "eps", link:"http://en.wikipedia.org/wiki/Earnings_per_share"}
	, {name: "P/E", link:"http://en.wikipedia.org/wiki/P/E_ratio"}
	, {name: "Revenue", link:"http://en.wikipedia.org/wiki/Revenue"} 
	, {name: "Earnings before interest and taxes", link:"http://en.wikipedia.org/wiki/Earnings_before_interest_and_taxes"}
	, {name: "return on capital", link:"http://en.wikipedia.org/wiki/Return_on_capital"}
	, {name: "return on equity", link:"http://en.wikipedia.org/wiki/Return_on_equity"}
	, {name: "working capital", link:"http://en.wikipedia.org/wiki/working_capital"}
	, {name: "accounts payable", link:"http://en.wikipedia.org/wiki/Accounts_payable"}
	, {name: "accrued expenses", link:"http://en.wikipedia.org/wiki/Accrued_liabilities"}
	, {name: "liabilities", link:"http://en.wikipedia.org/wiki/Liabilities#Accounting_liability"}
	, {name: "accounts receivable", link:"http://en.wikipedia.org/wiki/Accounts_receivable"}
	, {name: "inventory", link:"http://en.wikipedia.org/wiki/Inventory"}
	, {name: "deferred taxes", link:"http://en.wikipedia.org/wiki/Deferred_taxes"}
	, {name: "prepaid expenses", link:"http://en.wikipedia.org/wiki/Prepaid_expenses"}
	, {name: "current assets", link:"http://en.wikipedia.org/wiki/Current_assets"}
	, {name: "assets", link:"http://en.wikipedia.org/wiki/Current_assets"}
	, {name: "Acquisitions", link:"http://en.wikipedia.org/wiki/Acquisitions"}
	, {name: "fixed capital investments", link:"http://en.wikipedia.org/wiki/Fixed_investment"}
	, {name: "operating lease", link:"http://en.wikipedia.org/wiki/Operating_lease"}
	, {name: "EBIT", link:"http://en.wikipedia.org/wiki/Earnings_before_interest_and_taxes"}
	, {name: "net income", link:"http://en.wikipedia.org/wiki/Net_income"}
	, {name: "marginal tax rate", link:"http://en.wikipedia.org/wiki/Marginal_tax_rate#Marginal"}
	, {name: "capitalization", link:"http://en.wikipedia.org/wiki/Capital_expenditure"}
	, {name: "capital expense", link:"http://en.wikipedia.org/wiki/Capital_expenditure"}
	, {name: "capitalizing", link:"http://en.wikipedia.org/wiki/Capital_expenditure"}
	, {name: "debt to capital ratio", link:"http://en.wikipedia.org/wiki/Debt_to_capital_ratio"}
	, {name: "debt to equity ratio",link:"http://en.wikipedia.org/wiki/Debt_to_equity_ratio"}
	, {name: "Debt", link:"http://en.wikipedia.org/wiki/Debt"}
	, {name: "cash conversion cycle", link:"http://en.wikipedia.org/wiki/Cash_conversion_cycle"}
	, {name: "days inventory outstanding", link:"http://en.wikipedia.org/wiki/Cash_conversion_cycle"}
	, {name: "days payable outstanding", link:"http://en.wikipedia.org/wiki/Cash_conversion_cycle"}
	, {name: "Days sales outstanding", link:"http://en.wikipedia.org/wiki/Cash_conversion_cycle"}
	, {name: "acid test", link:"http://en.wikipedia.org/wiki/Acid_Test_(Liquidity_Ratio)"}
	, {name: "equity", link:"http://en.wikipedia.org/wiki/Ownership_equity"}
	, {name: "current ratio", link:"http://en.wikipedia.org/wiki/Current_ratio"}
	, {name: "interest coverage ratio", link:"http://en.wikipedia.org/wiki/Interest_coverage_ratio"}
	, {name: "free cash flow to equity", link:"http://en.wikipedia.org/wiki/Free_cash_flow"	}
	, {name: "operating cash flow", link:"http://en.wikipedia.org/wiki/Operating_cash_flow" }
	, {name: "depreciation", link:"http://en.wikipedia.org/wiki/Depreciation"}
];

function createHelpLinks(type,nodeRef)
{
	var urltempl = "/Main/Company/Earnings.aspx?s=<securityid>&y=<year>&tool=1";
	var args = getArgs();
	var secIds = args.s.split(",");
	var date = new Date();
	if( nodeRef === undefined)
	{
		nodeRef = (document.body.parentElement) ? document.body.parentElement : document.body.parentNode;
		if( nodeRef !== null)
		{
			createHelpLinks(type, nodeRef);
		}
	}
	else if( nodeRef.nodeType == 1)
	{
		for( var counter = 0 ; counter < nodeRef.childNodes.length; counter++)
		{
			var pattern;
			var anchor;
			if( nodeRef.childNodes[counter].nodeType == 1 && nodeRef.childNodes[counter].tagName.toLowerCase() == "th")
			{
				if( type == 1)
				{
					for( var year = date.getFullYear(); year > date.getFullYear() - 50; year--)
					{
						pattern = new RegExp(year.toString() ,"gi");
						var url = urltempl.replace( "<securityid>", secIds[0]).replace( "<year>",year);
						anchor = "<a class=\"headerTag\" href=\""+ url + "\">" + year + "</a>";
						nodeRef.childNodes[counter].innerHTML = nodeRef.childNodes[counter].innerHTML.replace( pattern, anchor);
					}
				}
			}
			else if
				( 
					nodeRef.childNodes[counter].nodeType == 3
					&& nodeRef.childNodes[counter].nodeValue.length > 2
					&&
					(	
						nodeRef.nodeType == 1 &&
						(
							nodeRef.tagName.toLowerCase() == "div"
							|| nodeRef.tagName.toLowerCase() == "p"
							|| nodeRef.tagName.toLowerCase() == "li"
							|| nodeRef.tagName.toLowerCase() == "ul"
							|| nodeRef.tagName.toLowerCase() == "ol"
							|| nodeRef.tagName.toLowerCase() == "span"
							|| nodeRef.tagName.toLowerCase() == "td"
						)
					)
				)
			{
				for( var index = 0; index < glossaryList.length; index++)
				{
					pattern = new RegExp( glossaryList[index].name, "gi");
					anchor = "<a href=\"" + glossaryList[index].link + "\">" + glossaryList[index].name +"</a>";
					var firstIndex = nodeRef.childNodes[counter].nodeValue.search(pattern);
					if( firstIndex >= 0)
					{
						var anchorTag = document.createElement("a");
						anchorTag.setAttribute("href", glossaryList[index].link);
						anchorTag.setAttribute("class", "dynamicLinkStyle");
						var txt = nodeRef.childNodes[counter].nodeValue.substring( firstIndex, firstIndex + glossaryList[index].name.length);
						anchorTag.appendChild( document.createTextNode( txt));
						
						var firstPart = document.createTextNode( nodeRef.childNodes[counter].nodeValue.substring( 0, firstIndex) );
						var secondPart = document.createTextNode(nodeRef.childNodes[counter].nodeValue.substring( firstIndex + glossaryList[index].name.length));
						
						nodeRef.replaceChild( secondPart, nodeRef.childNodes[counter]);
						nodeRef.insertBefore( anchorTag, secondPart);
						nodeRef.insertBefore( firstPart, anchorTag);
					}					
					
				}
			}
			else
			{
				try 
				{
					createHelpLinks(type, nodeRef.childNodes[counter]);
				}
				catch( e ){}	
			}
		}
	}	
}
function createGlossaryLinks()
{
	createHelpLinks();
}
function createHelpLink()
{
	setTimeout( createGlossaryLinks, 500);
}


