var ContentFrameDoc = null;

var ELEMENT_NODE = 1;
var ATTRIBUTE_NODE = 2;
var TEXT_NODE = 3;
var CDATA_SECTION_NODE = 4;
var ENTITY_REFERENCE_NODE = 5;
var ENTITY_NODE = 6;
var PROCESSING_INSTRUCTION_NODE = 7;
var COMMENT_NODE = 8;
var DOCUMENT_NODE = 9;
var DOCUMENT_TYPE_NODE = 10;
var DOCUMENT_FRAGMENT_NODE = 11;
var NOTATION_NODE = 12;

function getOffsetX(Item) 
{	
	var x;

	x = Item.offsetLeft;
	if (Item.offsetParent != null)
		x += getOffsetX(Item.offsetParent);

	return x;
}

function getOffsetY(Item) 
{	
	var y;

	y = Item.offsetTop;
	if (Item.offsetParent != null)
		y += getOffsetY(Item.offsetParent);

	return y;
}

function buildQueryString(theForm, includeQM) 
{
	var qs = '';
	var qm = ((includeQM == null) || (includeQM == true)) ? "?" : ""
	for (e=0;e<theForm.elements.length;e++) {
		if (theForm.elements[e].name!='') {
			qs+=(qs=='')?qm:'&'
				qs+=theForm.elements[e].name+'='+encodeURIComponent(theForm.elements[e].value)
		}
	}
	return qs;
}

function showTip(Elem, Tip, Pos)
{
	var ToolTip = document.getElementById("ToolTip");

	ToolTip.innerHTML = Tip;
	ToolTip.style.visibility = "visible";
	ToolTip.style.left = getOffsetX(Elem) + "px";
	
	if ((typeof(Pos) == "undefined") || (Pos == "below"))
		ToolTip.style.top = getOffsetY(Elem) + Elem.offsetHeight + "px";
	else
		ToolTip.style.top = getOffsetY(Elem) - ToolTip.offsetHeight + "px";
}

function hideTip()
{
	var ToolTip = document.getElementById("ToolTip");
	ToolTip.style.visibility = "hidden";
}

function getElementText(Element)
{
	try
	{
		ElementNodes = Element.childNodes;
	
		var NodeCount = ElementNodes.length;
		var Result = "";
	
		for (var n = 0; n < NodeCount; n++)
		{
			Node = ElementNodes.item(n);
			
			if (Node.nodeType == TEXT_NODE)
				Result += Node.nodeValue;
		}
	
		return Result;
	}
	catch (e)
	{
		return "";
	}
}

function findSingleElementByTag(Nodes, TagName)
{
	var NodeCount = Nodes.length;
	
	for (var n = 0; n < NodeCount; n++)
	{
		Node = Nodes.item(n);
		
		if (Node.nodeType != ELEMENT_NODE)
			continue;

		if (!TagName || (Node.tagName == TagName))
			return Node;
	}
	
	return null;
}

function spotTest(Type, SubType)
{
	var Filter = "";
	
	if (Type == "General")
	{
		if ((SubType == "TheGreeks1") || (SubType == "TheGreeks2"))
			Filter = "type=Greeks&subtype=" + SubType;
		else
			Filter = "type=General&subtype=" + SubType;
	}
	else if (Type == "Strategy")
	{
		Filter = "type=Strategy&subtype=" + SubType;
	}
	
	if (Filter != "")
	{
		var NewWindow = window.open("SpotTest.asp?" + Filter,
			"SpotTest",
			"width=525, height=300, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no");

		NewWindow.opener = window;
		NewWindow.focus();
	}
	else
	{
		alert("No spot test filter for Type: " + Type + " SubType: " + SubType);
	}
}

function showUserGuide(Section, Page)
{
	var URL = "Guide.asp?";

	if (typeof(Section) != "undefined")
		URL += "Section=" + Section;
	if ((typeof(Section) != "undefined") && (typeof(Page) != "undefined"))
		URL += "&";
	if (typeof(Page) != "undefined")
		URL += "Page=" + Page;

	var NewWindow = window.open(URL,
		"UserGuide",
		"width=620, height=440, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no");
		
	NewWindow.focus();
}

function showBigUserGuide(Section, Page)
{
	var URL = "Guide.asp?Layout=Big&";

	if (typeof(Section) != "undefined")
		URL += "Section=" + Section;
	if ((typeof(Section) != "undefined") && (typeof(Page) != "undefined"))
		URL += "&";
	if (typeof(Page) != "undefined")
		URL += "Page=" + Page;

	var NewWindow = window.open(URL,
		"BigUserGuide",
		"width=780, height=560, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no");
		
	NewWindow.focus();
}

function showHelp(File, Page)
{
	try
	{
		ChainSelectWnd = window.open("Help.asp?File=" + File + ((typeof(Page) != "undefined") ? "&Page=" + Page : ""),
			"HelpWindow",
			"width=400, height=300, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no");

		ChainSelectWnd.opener = window;
		ChainSelectWnd.focus();
	}
	catch (e)
	{
		alert("Error in showHelp: " + showException(e));
	}
}

function preloadImages()
{
	var ImageList = new Array();
	
	for (var i = 0; i < preloadImages.arguments.length; i++)
	{
		ImageList[i] = new Image();
		ImageList[i].src = preloadImages.arguments[i];
	}
	
	return ImageList;
}

Number.prototype.toFixed = oeToFixed;
function oeToFixed(Prec)
{
	if (isNaN(this))
		return "n/a";

	var MultFactor = Math.pow(10, Prec);
	var StrVal = new String(Math.round(this * MultFactor) / MultFactor);
	
	if (Prec == 0)
		return StrVal;
	
	if (StrVal.indexOf(".") < 0)
	{
		StrVal += ".";
		for (var i = 0; i < Prec; i++)
			StrVal += "0";
	}
	else
	{
		var MissingZeros = Prec - (StrVal.length - StrVal.indexOf(".") - 1);
		for (var i = 0; i < MissingZeros; i++)
			StrVal += "0";
	}
	
	return StrVal;
}

Number.prototype.toCurrency = oeToCurrency;
function oeToCurrency()
{
	if (isNaN(this))
		return "n/a";
		
	var StrVal = (Math.abs(this)).toFixed(2);
	for (var CurPos = StrVal.indexOf(".") - 3; CurPos > 0; CurPos = CurPos - 3)
		StrVal = StrVal.substr(0, CurPos) + "," + StrVal.substr(CurPos);

	if (this < 0)
		return "<span class='Negative'>(" + StrVal + ")</span>";
	else
		return StrVal;
}

Number.prototype.toPercent = oeToPercent;
function oeToPercent(Prec)
{
	if (isNaN(this))
		return "n/a";

	return (this*100).toFixed(Prec) + "%";
}
