// DO NOT COPY LIBRARY GENERIC FROM TOOL TO HERE.!!!!!!!!!!!!!11111111111111111111111111
// DO NOT COPY LIBRARY GENERIC FROM TOOL TO HERE.!!!!!!!!!!!!!11111111111111111111111111
// DO NOT COPY LIBRARY GENERIC FROM TOOL TO HERE.!!!!!!!!!!!!!11111111111111111111111111
// DO NOT COPY LIBRARY GENERIC FROM TOOL TO HERE.!!!!!!!!!!!!!11111111111111111111111111

function getStrikeSelect(e, leg)
{
	var obj = getObject(e)
	if(!leg)
		var leg = ""
	var items = bi("strikeSelectTD" + leg).getElementsByTagName("select")
	{
		for(var x = 0; x < items.length; x++)
		{
			items[x].style.display = (items[x].getAttribute("id") == ("select" + leg + "_" + obj[obj.selectedIndex].value))?"":"none";
		}
	}
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ get iframe obj
function getFrameForCall(frame)
{
	var element = bi(frame)
	if(element.contentWindow)
	{
		element = element.contentWindow
	}
	return element
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ get iframe obj
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ request
function getXSLobjLocation(path)
{
	if(ie)
	{
		var xml = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
		xml.async = false;
		xml.resolveExternals = false;
		try
		{
			xml.load(path);
			if(!xml.load(path))
			{
				alert("The path supplied at " + path + " has produced no document")
				return false;			
			}
			return(xml)
		}
		catch(e)
		{
			throw(xml.parseError.reason)
		}
	}
	else
	{
		return getXSLTProcessor(getXSLforFireFox(path))
	}
}
function getXSLTProcessor(oXsl)
{
	var xsltProcessor = new XSLTProcessor();
	xsltProcessor.importStylesheet(oXsl);
	return  xsltProcessor
}
function getXSLforFireFox(path)
{
	var myXMLHTTPRequest = new XMLHttpRequest();					
	myXMLHTTPRequest.open("GET", path, false);
	myXMLHTTPRequest.send(null);
	return myXMLHTTPRequest.responseXML
}


//----------- above is fine

var xmlObjs = new Array()
function getHttpXMLReq(oReq, fn)
{
	try
	{
		var initial = new Date()
		var xmlRequest = new Object()
		xmlRequest.xmlhttp = getXMLHttpObj()	
		xmlRequest.oReq = oReq
		xmlRequest.fn = fn
		xmlRequest.startTime = initial.getTime()	
		if(ie)
			xmlRequest.xmlhttp.open("POST", "/m", true);
		xmlRequest.xmlhttp.onreadystatechange= function() {onReadySC(xmlRequest)};
		if(!ie)
			xmlRequest.xmlhttp.open("POST", "/m", true);
		xmlRequest.xmlhttp.setRequestHeader("Content-Type", "text/xml");
		xmlRequest.xmlhttp.send(oReq);
	}
	catch(e)
	{
		window.setTimeout(	function(){getHttpXMLReq(oReq, fn)},250	)
	}
}
function onReadySC(xmlRequest)
{
	if(checkReadyState(xmlRequest))
	{
		clearTimeout(xmlRequest.timeout)
		if(xmlRequest.xmlhttp.status==200)
		{
			setLatencyMeterVal(xmlRequest.startTime)
			if(resolveAlertandAccess(xmlRequest.xmlhttp.responseXML))
			{
				xmlRequest.fn(xmlRequest.xmlhttp.responseXML)
			}
		}
		else
		{
			if(xmlRequest.xmlhttp.status == 12029 || xmlRequest.xmlhttp.status == 12030 || xmlRequest.xmlhttp.status == 12031 || xmlRequest.xmlhttp.status == 12152)
			{
				xmlRequest.xmlhttp.abort()
				window.setTimeout(	function(){getHttpXMLReq(xmlRequest.oReq, xmlRequest.fn)},2000)
			}
			else if(xmlRequest.xmlhttp.status < 12000)
			{
				xmlRequest.xmlhttp.abort()		
				if(top.bi("latencyMeter"))
				{
					top.bi("latencyMeter").style.left = -25
					showErrorsAlertBox("A connection to the server can not be made. Please wait. If the problem does not resolve itself, you may have to login again. Thank you.")
				}
				window.setTimeout(	function(){getHttpXMLReq(xmlRequest.oReq, xmlRequest.fn)},2000)
			}
		}
	}
	else
	{
		clearTimeout(xmlRequest.timeout)
		var cd = new Date()
		var cdTime = cd.getTime()
		var delay = 60000
		var httpTimer = (xmlRequest.startTime + delay) - cdTime
		if(httpTimer < 0){httpTimer = 1}
		window.status = "Time left for request:" + httpTimer
		xmlRequest.timeout = window.setTimeout(
			function()
			{
				if(!checkReadyState(xmlRequest))
				{
					xmlRequest.xmlhttp.onreadystatechange = function(){};
					xmlRequest.xmlhttp.abort()
					if(top.bi("latencyMeter"))
					{
						top.bi("latencyMeter").style.left = -25
					}
					window.setTimeout(	function(){getHttpXMLReq(xmlRequest.oReq, xmlRequest.fn)},2000)
				}
			},httpTimer
		)
	}
}
function getXMLHttpObj()
{
	var makeObj = true;
	if(xmlObjs.length > 0)
	{
		for(var i = 0; i < xmlObjs.length; i++)
		{
			if(xmlObjs[i].readyState == 4)
			{
				makeObj = false
				return xmlObjs[i]
				i = xmlObjs.length
			}
			else
			{
				makeObj = true
			}
		}
	}
	if(makeObj == true)
	{
		if(window.XMLHttpRequest)
		{
			xmlObjs[xmlObjs.length] = new XMLHttpRequest();
		}
		else
		{
			xmlObjs[xmlObjs.length] = new ActiveXObject("Msxml2.XMLHTTP");
		}
		return xmlObjs[xmlObjs.length - 1]
	}
}
function checkReadyState(xmlRequest)
{
	switch(xmlRequest.xmlhttp.readyState)
	{
		case 1: case 2: case 3:
			return false;
		break;
		case 0: case 4:
			return true;
		break;			
	}
}


/*

function getHttpXMLReq(httpObj, oReq, fCall, msgNum)
{

	if(httpObj.locked == true)
	{
		return false;
	}
	var initial = new Date()
	httpObj.startTime = initial.getTime()
	httpObj.locked = true
	httpObj.oReq = oReq
	httpObj.fCall = fCall
	httpObj.requestNumber = (httpObj.requestNumber == 2)?2:1;
	httpObj.msgNum = (msgNum)?msgNum:"0";
	if(ie)
	{
		httpObj.o.open("POST", baseURL + "/m",true)
	}
	httpObj.o.onreadystatechange= function() {onReadySC(httpObj)}
	if(!ie)
	{
		httpObj.o.open("POST", baseURL + "/m",true)
	}
	httpObj.o.send(oReq) 
}
function checkReadyState(httpObj)
{
	switch(httpObj.o.readyState)
	{
		case 1: case 2: case 3:
			return false;
		break;
		case 0: case 4:
			return true;
		break;			
	}
}
function onReadySC(httpObj)
{
	if(checkReadyState(httpObj))
	{
		httpObj.locked = false
		clearTimeout(httpObj.timeout)
		httpObj.requestNumber = 1
		if(httpObj.o.status==200)
		{
			setLatencyMeterVal(httpObj.startTime)
			if(resolveAlertandAccess(httpObj.o.responseXML))
			{
				httpObj.fCall(httpObj.o.responseXML)
			}
		}
		else
		{
			top.timerPaused = false
			window.status = "Problem retrieving XML data:" + httpObj.o.status
			if(httpObj.o.status == 12029 || httpObj.o.status == 12030 || httpObj.o.status == 12031 || httpObj.o.status == 12152)
			{
				getHttpXMLReq(httpObj, httpObj.oReq, httpObj.fCall)
			}
			else if(httpObj.o.status < 12000)
			{
				if(top.bi("latencyMeter"))
				{
					top.bi("latencyMeter").style.left = -25
					showErrorsAlertBox("A connection to the server can not be made. Please wait. If the problem does not resolve itself, you may have to login again. Thank you.")
				}
			}
		}
	}
	else
	{
		clearTimeout(httpObj.timeout)
		var cd = new Date()
		var cdTime = cd.getTime()
		var delay = 7500
		var timer = (httpObj.startTime + (delay * httpObj.requestNumber)) - cdTime
		if(timer < 0){timer = 1}
		window.status = "Time left for request:" + timer +" // Request number:"+ httpObj.requestNumber		
		httpObj.timeout = window.setTimeout(
			function()
			{
				if(!checkReadyState(httpObj))
				{
					top.timerPaused = false
					httpObj.o.onreadystatechange = function(){};
					httpObj.o.abort()
					httpObj.locked = false;
					if(top.bi("latencyMeter"))
					{
						top.bi("latencyMeter").style.left = -25
					}
					if(httpObj.requestNumber == 1)
					{
						httpObj.requestNumber = 2
						getHttpXMLReq(httpObj, httpObj.oReq, httpObj.fCall, httpObj.msgNum)
											
					}
					else
					{
						httpObj.requestNumber = 1
						var tryAgain =confirm(timeoutMsgs[httpObj.msgNum]);
						if (tryAgain==true)
						{
							getHttpXMLReq(httpObj, httpObj.oReq, httpObj.fCall, httpObj.msgNum)
						}
					}
				}
			},timer
		)
	}
}

*/

var timeoutMsgs = new Array()
timeoutMsgs[0] = "Your request timed out for Symbol lookup. Would you like to try again?" //function symbolLookup(companyName) library_main.js
timeoutMsgs[1] = "Your request timed out for Exchange View. Would you like to try again?" //function exchangeViewLookup(secKey, sym, desc) library_main.js, function getNewOOLPData() exchange_view.js
timeoutMsgs[2] = "Your request timed out for Account Activity lookup. Would you like to try again?" //function myAccountActivity() library_main.js
timeoutMsgs[3] = "Your request timed out for Account Settings lookup. Would you like to try again?" //function myAccountLookup() library_main.js
timeoutMsgs[4] = "Your request timed out for Account Details lookup. Would you like to try again?" //function refreshAccountDetails() library_main.js
timeoutMsgs[5] = "Your request timed out for Account Positions lookup. Would you like to try again?" //function refreshAccountPositions() library_main.js
timeoutMsgs[6] = "Your request timed out for Account Orders lookup. Would you like to try again?" //function refreshAccountOrders() library_main.js
timeoutMsgs[7] = "Could not load a symbol. Would you like to try again?" //function quoteLookupFull() library_main.js
timeoutMsgs[8] = "Could not load News. Would you like to try again?" //function getNews() library_main.js
timeoutMsgs[9] = "" //function timedForm_getQuote() library_main.js
timeoutMsgs[10] = "Could not load a symbol. Would you like to try again?" //function form_getQuote(sym) library_main.js
timeoutMsgs[11] = "Could not load Account Information. Would you like to try again?" //function form_getAccountInfo() library-main.js
timeoutMsgs[12] = "Could not open a Ticket. Would you like to try again?" //function getTicketWindow(oReq, func, window) libaray_main.js
timeoutMsgs[13] = "Logout attempt timed out. Closing this window with auto logout your account." //function logout() library_main.js
timeoutMsgs[14] = "Could not load Hotlist information. Would you like to try again?" //function hotlistUpdater(oReq, func) hotlist_main.js
timeoutMsgs[15] = "Could not load Marketview information. Would you like to try again?" //function marketViewUpdater(oReq) market_view.js
timeoutMsgs[16] = "" //function getChainData() quotes_chain.js
timeoutMsgs[17] = "" //function getNewOOLPData() tickets_common.js
timeoutMsgs[18] = "" //function updateSpreadOOLPData() tickets_common.js
timeoutMsgs[19] = "Unable to update status information. Would you like to try again?" //function requestNewOrderStatus() tickets_common.js
timeoutMsgs[20] = "Unable to Cancel order. Would you like to try again?" //function cancelTicketOrder(orderId) tickets_common.js
timeoutMsgs[21] = "Could not load Watchlists. Would you like to try again?" //function getWatchlists(modeType), function watchlistWatch(id, name) watchlist_main.js
timeoutMsgs[22] = "Could not load Symbols for Watchlist. Would you like to try again?" //function getWatchListData(id, name) watchlist_main.js
timeoutMsgs[23] = "Unable to Save new Watchlist. Would you like to try again?" //function watchlistSave(id) watchlist_main.js
timeoutMsgs[24] = "Unable to Delete Watchlist. Would you like to try again?" //function watchlistDelete(id) watchlist_main.js
timeoutMsgs[25] = "Unable to update Watchlists. Would you like to try again?" //function updateWatchListList() watchlist_main.js
timeoutMsgs[26] = "Unable to add Symbol to Watchlist. Would you like to try again?" // function watchlistAddSymbol() watchlist_main.js
timeoutMsgs[27] = "Unable to delete Symbol from Watchlist. Would you like to try again?"// function watchlistDeleteSymbol(sym) watchlist_main.js
timeoutMsgs[28] = "Unable to process password recovery. Would you like to try again?"//function doAction() auth_login.js
timeoutMsgs[29] = "Unable to validate login. Would you like to try again?" //function logon() auth_login.js
timeoutMsgs[30] = "Unable to login. Would you like to try again?" //function logon() auth_login.js
timeoutMsgs[31] = "Could not load Chart information. Would you like to try again?" //function init() chart_table.js
timeoutMsgs[32] = "Could not load Account Signup. Would you like to try again?" //function getAccountSignup() library_main.js
timeoutMsgs[33] = "Could not load Help. Would you like to try again?" //function getHelp() library_main.js
timeoutMsgs[34] = "Could not load Execution Report. Would you like to try again?" //function getExecutionReport() library_main.js (temporarily in execution_report.js)

var averageTime = new Array()
var aveTimeCount = 0;
var aveReqUse = 8;
function setLatencyMeterVal(startTime)
{
	var current = new Date()
	var newTime = current.getTime()
	var dif = newTime - startTime
	averageTime[aveTimeCount] = dif
	aveTimeCount  = aveTimeCount + 1
	if(aveTimeCount > aveReqUse - 1)
	{
		aveTimeCount = 0
	}	
}
function latencyMeter()
{
	if(averageTime.length > aveReqUse - 1)
	{
		var oTotal = 0;
		for(var x = 0; x < averageTime.length; x++)
		{
			oTotal = Number(oTotal) + Number(averageTime[x])
		}
		top.bi("latencyCover").setAttribute("title",Math.round(Number(oTotal)/aveReqUse) + "ms")
		var LM = Math.round(Math.round(Math.round(Number(oTotal)/aveReqUse) / 100) / 5)
		if(LM > 25)LM = 25
		else if(LM < 7)LM = 7
		top.bi("latencyMeter").style.left = -LM
	}
}
function resolveAlertandAccess(oXml)
{
		if(oXml.selectSingleNode("//errors"))
		{
			if(oXml.selectSingleNode("//errors/access"))
			{
				if(oXml.selectSingleNode("//errors/access/text()").nodeValue.toLowerCase() == "denied")
				{
					//location.href = "/"
				}
			}
		}
		return true
}
function transFormWObj(oXml, oXsl, obj)
{
	var element = cleanPassedObj(getPassedBody(obj))
	if(ie)
	{
		element.innerHTML = oXml.transformNode(oXsl)
	}
	else
	{
		element.appendChild(oXsl.transformToFragment(oXml, document));	  				
	}	
}
function transForm(oXml, oXsl)
{
	if(ie)
	{
		return  oXml.transformNode(oXsl)
	}
	else
	{
		return   oXsl.transformToFragment(oXml, document);			
	}	
}
function getPassedObj(obj)
{
	var obj = bi(obj)	
	if(obj.contentDocument)
	{
		obj= obj.contentDocument
	}
	else if(obj.contentWindow)
	{
		obj= obj.contentWindow.document
	}
	return obj	
}
function getPassedBody(obj)
{	
	var obj = bi(obj)	
	if(obj.contentDocument)
	{
		obj= obj.contentDocument.body
	}
	else if(obj.contentWindow)
	{
		obj= obj.contentWindow.document.body
	}
	return obj	
}
function cleanPassedObj(obj)
{
	obj.innerHTML = ''
	if(obj.childNodes.length > 0)
	{
		for(var x = 0; x < obj.childNodes.length; x++)
		{
			obj.removeChild(obj.childNodes[obj.childNodes.length - 1]);
		}
	}
	return obj;
}
function requestEnv(action, requestObj)
{
	var acct = (top.accountNumber== "null" || top.accountNumber== null)?"":top.accountNumber;
	var aTok = top.authToken;
	if(action)
	{
		var request = "<EZMessage action='" + action +"'><data><authToken>" + aTok + "</authToken>"
		switch(action)
		{
			case "account.info":
				request += "";
			break;
			case "load.preferences":
				request += "";
			break;
			case "auth.logout":
				request += "";
			break;

			case "view.quote":
				if(requestObj.secKey)
				{
					request += 	"<securityKey>" + requestObj.secKey + "</securityKey>";
					request +=	"<account>" + acct + "</account>";
				}
				else
				{
					var desc = (requestObj)?requestObj.desc:"true";
					var sym = (requestObj)?requestObj.symbol: top.defaultSymbol;
					request +=	"<description>" + desc + "</description>" +
								"<fundamentals>true</fundamentals>" +
								"<bs>true</bs>" +
								"<symbol>" + sym  + "</symbol>" +
								"<account>" + acct + "</account>";
					if(requestObj.newSymbol == true)
					{
						request += "<setDefault>" + top.defaultSymbol + "</setDefault>";
					}
				}
			break;			
			case "view.series":
				var sym = (requestObj)?requestObj.symbol: top.defaultSymbol;	
				request +=	"<symbol>" + sym  + "</symbol>";
				if(acct != null && acct != "null" && acct != "")
				{
					request +=	"<account>" + acct + "</account>";
				}
			break;
			case "stock.lookup":
				var company = (requestObj)?requestObj.company: '';
				request +=	"<company>" + company + "</company>";
			break;
			case "account.cash":
				request += "<account>" +acct + "</account><portfolio>true</portfolio>";
				request += "<historical>true</historical>";
			break;
			case "view.exchange.quote":
				request += "<k>" + requestObj.secKey+ "</k>";
			break;
			case "account.positions":
				request += "<account>" +acct + "</account>";
			break;
			case "account.orders":
				request += "<account>" +acct + "</account>";		
			break;
			case "account.activity":
				request += "<account>" +acct + "</account>";		
			break;
			case "news.symbol":
				var sym = (requestObj)?requestObj.symbol: top.defaultSymbol;	
				request +=	"<symbol>" + sym  + "</symbol>";
				if(acct != null && acct != "null" && acct != "")
				{
					request +=	"<account>" + acct + "</account>";
				}
			break;
			case "view.chain":
				var gr = (requestObj)?requestObj.greeks:"true";
				var sym = (requestObj)?requestObj.symbol: top.defaultSymbol;
				var ts = (requestObj && requestObj.timeStamp)?requestObj.timeStamp:"";
				request += 	"<greeks>"  + gr + " </greeks>" + 
							"<quotesAfter>" + ts  +"</quotesAfter>" +
							"<symbol>" + sym + "</symbol>";
				if(acct != null && acct != "null" && acct != "")
				{
					request +=	"<account>" + acct + "</account>";
				}
			break;
			case "echo":
				var echo = (requestObj)?requestObj.echo:"";
				echo += "<basePageId>" + top.basePageId + "</basePageId>";
				echo += "<pathName>" + ("/" +  top.pathName) + "</pathName>";
				echo += "<configXML>" + top.configXML + "</configXML>";		
				request += "<echo>" + echo + "</echo>";
			break;			//			case "echo":
//				var echo = (requestObj)?requestObj.echo + "<pathName>" + ("/" + top.pathName) + "</pathName>":"<pathName>" + ("/" + top.pathName) + "</pathName>";
//				request += "<echo>" + echo + "</echo>";		
//			break;
//			case "echo":
//				request += "<echo>" + requestObj.echo + "</echo>";		
//			break;
			case "security.definition":
				request += "<securityKey>" + requestObj.secKey+ "</securityKey>";
			break;
		}
		request += "</data></EZMessage>"
		return request
	}
}
function requestEnvMod(action, requestObj)
{
	var acct = (top.accountNumber== "null" || top.accountNumber== null)?"":top.accountNumber;
	var aTok = top.authToken;
	if(action)
	{
		var request = "<EZMessage action='" + action +"'><data><authToken>" + aTok + "</authToken>"
		switch(action)
		{
			case "view.quote":
				var desc = (requestObj)?requestObj.desc:"true";
				var sym = (requestObj)?requestObj.symbol: top.defaultSymbol;
				request +=	"<description>" + desc + "</description>" +
							"<fundamentals>true</fundamentals>" +
							"<symbol>" + sym  + "</symbol>";
				if(acct != null && acct != "null" && acct != "")
				{
					request +=	"<account>" + acct + "</account>";
				}
			break;
			case "account.orders":
				var orderId = (requestObj)?requestObj.orderId:"";
				request += 	"<account>" +acct + "</account>" +
							"<id>" + orderId + "</id>";
			break;
			case "account.activity":
				var orderId = (requestObj)?requestObj.orderId:"";
				request += 	"<account>" +acct + "</account>" +
							"<orderId>" + orderId + "</orderId>";
			break;
			case "order.cancel":
				var orderId = (requestObj)?requestObj.orderId:"";
				request += 	"<account>" +acct + "</account>" +
							"<orderId>" + orderId + "</orderId>";
			break;			
			case "security.definition":
				request += "<optionSymbol>" + requestObj.sym+ "</optionSymbol>";
			break;		
		}
		request += "</data></EZMessage>"
		return request
	}
}
function requestEnvModNoToken(action, requestObj)
{
	if(action)
	{
		var request = "<EZMessage action='" + action +"'><data>"
		switch(action)
		{
			case "security.definition":
				request += "<optionSymbol>" + requestObj.sym+ "</optionSymbol>";
			break;		
		}
		request += "</data></EZMessage>"
		return request
	}
}
function requestEnvSecKey(action, requestObj)
{
	var acct = (top.accountNumber== "null" || top.accountNumber== null)?"":top.accountNumber;
	var aTok = top.authToken;
	if(action)
	{
		var request = "<EZMessage action='" + action +"'><data><authToken>" + aTok + "</authToken>"
		switch(action)
		{
			case "view.quote":
				request += 	"<securityKey>" + requestObj.secKey+ "</securityKey>";
				if(acct != null && acct != "null" && acct != "")
				{
					request +=	"<account>" + acct + "</account>";
				}
			break;		
		}
		request += "</data></EZMessage>"
		return request
	}
}
// ------------------------------------------------------------------ ticket requests
function form_getStockTicket(type, action, key, sym)
{
	var requestObj = new Object()
	requestObj.echo = "<ticket type='" + type + "' action='"  + action + "' />"	
	requestObj.symbol = sym
	var oListReq = 	"<EZList>" + requestEnv('view.quote', requestObj) + 
					"" + requestEnv('account.info') + 
					"" + requestEnv('echo', requestObj) + "</EZList>"
	runTicketWindow(oListReq)
}
function form_getTradeTicket(sym, secKey, type, transaction, qty, qtyFil, priceType, duration, price, stopPrice, orderId, desc)
{
	var requestObj = new Object()
	
	if(type == "replicate_stock_ticket" || type == "replicate_option_ticket")
	{
		var action = "replicate"
	}
	else if(type == "modify_stock_ticket")
	{
		var type = "replicate_stock_ticket"
		var action = "modify"
	}
	else if(type == "modify_option_ticket")
	{
		var type = "replicate_option_ticket"
		var action = "modify"
	}
	else
	{
		var action = "trade"
	}
	requestObj.echo = 	"<ticket type='" + type + 
						"' action='" + action + 
						"' transaction='" + transaction + 
						"'  qty='" + qty + 
						"'  qtyFil='" + qtyFil + 
						"'  priceType='" + priceType + 
						"' duration='" + duration + 
						"' price='" + price + 
						"' stopPrice='" + stopPrice +
						"' secKey='" + secKey +
						"' orderId='" + orderId +
						"' desc='" + desc + "'/>"
	requestObj.secKey = secKey
	requestObj.symbol = sym
	
	if(type == "replicate_option_ticket" || type == "option_ticket")
	{
		var oListReq = 	"<EZList>" + requestEnv('account.info') + 
						"" + requestEnv('echo', requestObj) + 
						"" + requestEnvSecKey('view.quote', requestObj) + 
						"" + requestEnv('view.series', requestObj) + 
						"</EZList>";
	}
	else if(type == "stock_ticket_blank")
	{
		requestObj.echo = "<ticket type='stock_ticket'/>"
		var oListReq = 	"<EZList>" + requestEnv('account.info') + 
						"" + requestEnv('echo', requestObj) + 
						"" + requestEnv('view.quote', requestObj) + 
						"</EZList>";
	}
	else if(type == "option_ticket_blank")
	{
		requestObj.echo = "<ticket type='option_ticket'/>"
		var oListReq = 	"<EZList>" + requestEnv('account.info') + 
						"" + requestEnv('echo', requestObj) + 
						"" + requestEnv('view.quote', requestObj) + 
						"" + requestEnv('view.series', requestObj) + 
						"</EZList>";
	}	
	else
	{
		var oListReq = 	"<EZList>" + requestEnv('account.info') + 
						"" + requestEnv('echo', requestObj) + 
						"" + requestEnv('view.quote', requestObj) +
						"</EZList>";
	}
	runTicketWindow(oListReq)	
}

function form_getExerciseTicket(sym, secKey,  type, desc)
{
	var requestObj = new Object()
	requestObj.echo = "<ticket type='exercise_ticket' action='exercise' desc='" + desc+ "' secKey='"+ secKey +"'/>"
	requestObj.secKey = secKey
	requestObj.symbol = sym
	
	var oListReq = 	"<EZList>" + requestEnv('account.info') + 
					"" + requestEnvSecKey('view.quote', requestObj) +
					"" + requestEnv('echo', requestObj) + "</EZList>"
	runTicketWindow(oListReq)
}
function form_getCancelTicket(orderId)
{
	var requestObj = new Object()
	requestObj.orderId = orderId
	requestObj.echo = "<ticket type='cancel_ticket' action='cancel' />"	
	var oListReq = 	"<EZList>" + requestEnvMod('account.orders', requestObj) + 
					"" + requestEnv('echo', requestObj) + "</EZList>"
	runTicketWindowCancel(oListReq)
}
function form_getSpreadTicket(secKey, sym, orderId, legs, evt)
{
	var requestObj = new Object()
	if(orderId)
	{
		var oLegsArray = legs.split("-");
		var oReqLegs = ""		
		requestObj.orderId = orderId
		
		for(var x = 0; x < oLegsArray.length; x++)
		{
			if(oLegsArray[x] != "")
			{
				requestObj.secKey = oLegsArray[x]
				oReqLegs = oReqLegs + requestEnvSecKey('view.quote', requestObj)
			}
		}
		requestObj.echo = "<ticket type='spread_ticket' action='modify' secKey='" + legs + "' />"
		var oReq = 	"<EZList>" + 
					"" + oReqLegs + 
					"" + requestEnvSecKey('account.info', requestObj) +
					"" + requestEnvMod('account.orders', requestObj) + 
					"" + requestEnv('echo', requestObj) + "</EZList>"
	}
	else
	{
		requestObj.symbol = sym
		requestObj.secKey = secKey
		requestObj.echo = "<ticket type='spread_ticket' action='trade' secKey='"  + secKey + "' evt='" + evt + "' />"
		var oReq = 	"<EZList>" + 
					requestEnvSecKey('account.info', requestObj) + 
					"" + requestEnvSecKey('view.quote', requestObj) + 
					"" + requestEnv('echo', requestObj) + 
					"" + requestEnv('view.series', requestObj) + "</EZList>"
	}
	runSpreadWindow(oReq)
}
function getXMLforValidate(mode)
{
	var oPos = bi("ticketType").value
	
	if(bi("duration"))
		var oDur = bi("duration")[bi("duration").selectedIndex].value
	else
		var oDur = "0"
	

	if(bi("priceType"))
		var oOT = radioValue(document.orderTicketForm.priceType).value
	else
		var oOT = "M"
	
	if(oOT == "L")
	{
		var oPrice = bi("lPrice").value
	}
	else if(oOT == "H")
	{
		var oPrice = bi("hPrice").value
		var oPrice2 = bi("hPrice").value
	}
	else if(oOT == "S")
	{
		var oPrice = bi("sPrice").value
		var oPrice2 = bi("sPrice2").value
	}	
	if(oPos != "exercise_ticket")
	{
		var posType = getActionType().getAttribute("actionType")
		var side =  getActionType().value
		if(side == "B" || side == "BO" || side == "BC")
		{
			side = "B"
			if(oOT == "M" || oOT == "MC")
			{
				var oPrice = bi("loadAsk").value
			}
		}
		else
		{
			side = "S" 
			if(oOT == "M" || oOT == "MC")
			{
				var oPrice = bi("loadBid").value
			}
		}
		var aon = (bi("allornone").checked)?true:false;
	}
	else
	{
		var side = "S" 
	}
	if(oPos == "stock_ticket" || oPos == "replicate_stock_ticket")
	{
		var securityType = "S"
	}
	else
	{
		var securityType =  "O"
	}
	if(bi("orderId"))
	{
		if(bi("orderId").value != "null")
		{
			var modify = bi("orderId").value
		}
		else
		{
			var modify = "0"
		}
	}
	if(bi("oSecKey").value != "" && bi("oSecKey").value != "null")
	{
		var oSKey = bi('oSecKey').value
	}
	else
	{
		var oSKey = bi('symbolFull').value + ":::S"
	}
//	var oTime =  new Date()
//	var clientID = oTime.getTime()
	var oReq;

	if(oPos != "exercise_ticket")
	{
		if(!mode)
		{
			oReq = "<EZMessage action='account.margin'><data><numLegs>1</numLegs>"
		}
		else if(mode == "execute")
		{
			oReq = "<EZMessage action='order.create'><data><numLegs>1</numLegs>"
			if(bi("ticketAction").value == "modify")
			{
				oReq = "<EZMessage action='order.modify'><data><numLegs>1</numLegs>"
			}
		}
		if(bi("ticketAction").value == "modify")
		{
			oReq = oReq + "<modifyOrder>" + modify+ "</modifyOrder>"
		}
		oReq = oReq + 	"<legs>" +
							"<posType>" + posType + "</posType>" + 
							"<index>0</index>" + 
							"<securityType>" + securityType + "</securityType>" + 
							"<securityKey>" +  oSKey + "</securityKey>" + 
							"<multiplier>" + bi('spc').value + "</multiplier>" + 
							"<quantity>" + bi('quantity').value + "</quantity>" + 
							"<side>" + side + "</side>" + 
						"</legs>" +
						"<account>" + top.accountNumber + "</account>" +
						"<orderType>" + oOT + "</orderType>" +
						"<timeInForce> " + oDur + "</timeInForce>" + 
						"<clientId>" + clientID + "</clientId>" + 
						"<allOrNone>" + aon + "</allOrNone>" +
						"<symbol>" + bi('symbolFull').value + "</symbol>" + 
						"<authToken>" + top.authToken + "</authToken>"
		if(oPrice2)
		{
			oReq = oReq + "<stopPrice>" + oPrice + "</stopPrice><price>" + oPrice2 + "</price>"
		}
		else
		{
			oReq = oReq + "<price>" + oPrice + "</price>"
		}
		oReq = oReq + 	"</data></EZMessage>";
	}
	else
	{	
		if(!mode)
		{
			oReq = 	"<EZMessage action='account.margin'><data><exercise>true</exercise>";
		}
		else if(mode == "execute")
		{
			oReq = 	"<EZMessage action='order.exercise'><data>";
		}
		oReq = oReq +	"<securityKey>" +  oSKey + "</securityKey>" +
						"<account>" + top.accountNumber + "</account>" +
						"<clientId>" + clientID + "</clientId>" +
						"<authToken>" + top.authToken + "</authToken>" +
						"<quantity>" + bi('quantity').value + "</quantity>" + 
						"</data></EZMessage>";
	}
	top.clearRefreshTimers()
	if(!mode)
	{
//		getHttpXMLReq(top.httpObjsHolder.marginhttp, oReq, setValidateMsg)
		getHttpXMLReq(oReq, setValidateMsg)
		
	}
	else if(mode == "execute")
	{
//		getHttpXMLReq(top.httpObjsHolder.marginhttp, oReq, setExeValidateMsg)
		getHttpXMLReq(oReq, setExeValidateMsg)
	}
}
function buildSpreadMarginRequest(mode)
{
	var oReq = ""
	if(bi("orderId"))
	{
		if(bi("orderId").value != "null")
		{
			var modify = bi("orderId").value
		}
		else
		{
			var modify = "0"
		}
	}	
	if(!mode)
	{
		oReq = "<EZMessage action='account.margin'><data>"
	}
	else if(mode == "execute")
	{
		oReq = "<EZMessage action='order.create'><data>"
		if(bi("ticketAction").value == "modify")
		{
			oReq = "<EZMessage action='order.modify'><data>"
		}
	}
	if(bi("ticketAction").value == "modify")
	{
		oReq = oReq + "<modifyOrder>" + modify+ "</modifyOrder>"
	}	
	var numLegs = 0
	for(var x = 1; x < 5; x++)
	{
		if(bi("series" + x))
		{
			if(bi("series" + x).value.indexOf("null") < 0)
			{
				var side = radioValue(eval("document.orderTicketForm.actionType" + x)).value
				var posType;		
				if(side == "B" || side == "BO" || side== "BC")
				{
					side = "B"
					if(bi("pos" + x).value >= 0)
					{
						posType = "O"
					}
					else
						posType = "C"
				}
				else
				{
					side = "S"
					if(bi("pos" + x).value <= 0)
					{
						posType = "O"
					}
					else
						posType = "C"
				}
				oReq = oReq + 	"<legs>" +
								"<index>" + numLegs + "</index>" + 
								"<posType>" + posType + "</posType>" + 
								"<securityKey>" +  bi('series' + x).value + "</securityKey>" + 
								"<multiplier>" + bi('spc' + x).value + "</multiplier>" + 
								"<quantity>" + bi('qty' + x).value + "</quantity>" + 									
								"<side>" + side + "</side>" + 
								"</legs>";
				numLegs++;								
			}
		}
	}
	var oPType = radioValue(document.orderTicketForm.priceType)
	if(oPType.value == "M")
	{
		var oOT = "M"
		var oPrice = getDollarAmount(getSpreadMarketPrice())
	}
	else if(oPType.value == "L" && oPType.getAttribute("atype") != "E")
	{
		var oOT = "L"
		var oPrice = (Number(bi("lPrice").value) *  Number(bi("gcd").value))
		if(oPType.getAttribute("atype") == "S")
		{
			oPrice = oPrice * -1
		}
	}
	else if(oPType.value == "L" && oPType.getAttribute("atype") == "E")
	{
		var oOT = "L"
		var oPrice =0;
	}
	if(bi("duration"))
		var oDur = bi("duration")[bi("duration").selectedIndex].value
	else
		var oDur = "0"
//	var oTime =  new Date()
//	var clientID = oTime.getTime()	
	oReq = oReq + "<price>" + oPrice + "</price>"
	oReq = oReq + "<account>" + top.accountNumber + "</account>" +
					"<orderType>" + oOT + "</orderType>" +					
					"<timeInForce> " + oDur + "</timeInForce>" + 
					"<allOrNone>false</allOrNone>" +			
					"<clientId>" + clientID + "</clientId>" + 
					"<symbol>" + bi('symbol').value + "</symbol>" + 
					"<authToken>" + top.authToken + "</authToken>"					
	oReq = oReq + "<numLegs>" + numLegs + "</numLegs>"
	oReq = oReq + "</data></EZMessage>"
	top.clearRefreshTimers()
//	alert(oReq)
	if(!mode)
	{
//		getHttpXMLReq(top.httpObjsHolder.marginhttp, oReq, setValidateMsg)
		getHttpXMLReq(oReq, setValidateMsg)
	}
	else if(mode == "execute")
	{
//		getHttpXMLReq(top.httpObjsHolder.marginhttp, oReq, setExeValidateMsg)
		getHttpXMLReq(oReq, setExeValidateMsg)
	}
}

// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ request
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ selectNode / selectSingleNode
if( document.implementation.hasFeature("XPath", "3.0") )
{  
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; }
		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)
		{
			aResult[i] =  aItems.snapshotItem(i);
		}
		return aResult;  
	}
	Element.prototype.selectNodes = function(cXPathString)
	{
		if(this.ownerDocument.selectNodes)
		{
			return this.ownerDocument.selectNodes(cXPathString, this);
		}
		else{throw "For XML Elements Only";}  
	}
}
if( document.implementation.hasFeature("XPath", "3.0") )
{  
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
	{
		if( !xNode ) { xNode = this; }
		var xItems = this.selectNodes(cXPathString, xNode);
		if( xItems.length > 0 )
		{
			return xItems[0];
		}
		else
		{
			return null;
		}
	}
	Element.prototype.selectSingleNode = function(cXPathString)
	{
		if(this.ownerDocument.selectSingleNode)
		{
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
	}
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ selectNode / selectSingleNode  
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ functions for showing / hiding columns
function showColumns()
{
	var objArray = bt("table")
	for(var x = 0; x < objArray.length; x++)
	{
		if(objArray[x].className == "tableScrollMinQuotesChain" || objArray[x].className == "tableScrollMinQuotesChainD")
		{
			alert(objArray[x].className)
		}
	}
}
function showCols()
{
	top.timerPaused = true
	var objArray = bt("tr")
	for(var x = 0; x < objArray.length; x++)
	{
		if(objArray[x].className == "rowOff" || objArray[x].className == "rowOn" || objArray[x].id == "headerTRforSort")
		{
			var objArrayTD = objArray[x].getElementsByTagName("td")
			for(var y = 0; y < objArrayTD.length; y++)
			{
				if(objArrayTD[y].className == "hiddenTD")
				{
					objArrayTD[y].className = "hiddenTDShown"
				}
				if(objArrayTD[y].getAttribute("oldClass"))
				{
					if(objArrayTD[y].getAttribute("oldClass") == "hiddenTD")
					{
						objArrayTD[y].className = "hiddenTDShown" + objArrayTD[y].getAttribute("atmClass")
						objArrayTD[y].setAttribute("oldClass","hiddenTDShown");
					}
				}
			}
		}
	}
	top.timerPaused = false
}
function hideCols()
{
	top.timerPaused = true
	var objArray = bt("tr")
	for(var x = 0; x < objArray.length; x++)
	{
		if(objArray[x].className == "rowOff" || objArray[x].className == "rowOn" || objArray[x].id == "headerTRforSort")
		{
			var objArrayTD = objArray[x].getElementsByTagName("td")
			for(var y = 0; y < objArrayTD.length; y++)
			{
				if(objArrayTD[y].className == "hiddenTDShown")
				{
					objArrayTD[y].className = "hiddenTD"
				}
				if(objArrayTD[y].getAttribute("oldClass"))
				{
					if(objArrayTD[y].getAttribute("oldClass") == "hiddenTDShown")
					{
						objArrayTD[y].className = "hiddenTD" + objArrayTD[y].getAttribute("atmClass")
						objArrayTD[y].setAttribute("oldClass","hiddenTD");
					}
				}
			}
		}
	}
	top.timerPaused = false
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ functions for showing / hiding columns
