/* Include parse.js */
var s;
s = "<script language=\"javascript\" type=\"text/javascript\" src=\"/inc/parse.js\"></script>";		
document.write(s);

/* Include headbanners.js */
var s;
s = "<script language=\"javascript\" type=\"text/javascript\" src=\"/inc/headbanners.js\"></script>";		
document.write(s);

/* Include append_session.js */
var s;
s = "<script language=\"javascript\" type=\"text/javascript\" src=\"/inc/append_session.js\"></script>";		
document.write(s);

/* Include branch/general.js */
var s;
s = "<script language=\"javascript\" type=\"text/javascript\" src=\"/inc/branch/general.js\"></script>";		
document.write(s);

var lAccntListLastSelIndex=0;
var defaultEmptyOK=false;
var decimalPointDelimiter=".";
var PO_BOX_CONFIRM_MSG="Primary account address cannot be a P.O. Box.\nPlease click \"CANCEL\" and fill-out mailing address fields to route all account correspondence to a P.O. Box.\n\nIf you believe you received this message in error, please click \"OK\" and proceed w/ the new account process.";
var PO_BOX_CONFIRM_MSG2="Primary account address cannot be a P.O. Box.\n\nIf you believe you received this message in error, please click \"OK\" and proceed w/ the new account process.";

function PromptFocus(ctrlName, txtMessage)
{
	sCtrlType=ctrlName.type;
	if (sCtrlType==null)
		sCtrlType=ctrlName[0].type;
	
	if (sCtrlType=="text"){
		ctrlName.select();
		ctrlName.focus();
	}
	else if (sCtrlType=="password"){
		ctrlName.select();
		ctrlName.focus();
	}
	else if (sCtrlType=="textarea"){
		ctrlName.select();
		ctrlName.focus();
	}
	else if (sCtrlType=="checkbox"){
		ctrlName.focus();
	}
	else if (sCtrlType=="radio"){
		ctrlName[0].focus();
	}
    
	window.alert(txtMessage);

	if (sCtrlType=="text"){
		ctrlName.select();
		ctrlName.focus();
	}
    else if (sCtrlType=="password"){
		ctrlName.select();
		ctrlName.focus();
	}
	else if (sCtrlType=="textarea"){
		ctrlName.select();
		ctrlName.focus();
	}
	else if (sCtrlType=="checkbox"){
		ctrlName.focus();
	}
	else if (sCtrlType=="radio"){
		ctrlName[0].focus();
	}
	else if (sCtrlType=="select-one" || sCtrlType=="select-multiple") {
		ctrlName.focus();
	}
	return;
}

// This function provent history back on browser.
// Add this function to the first page.User 
// can not go back to the first page by clicking 
// "Back" button on the second page.
// e.g. <body onload="NoBrowserBack();">
function NoBrowserBack(){
	//window.history.forward(1);
	
}


// Returns true if character c is a digit 
// (0 .. 9).


function GetSessionID() {
	var sSessionID='0';
	var sQueryString=location.search.substring(1);
	var aQueryStringVars=sQueryString.split("&");

	for (var i=0; i<aQueryStringVars.length; i++){
		var nPos=aQueryStringVars[i].indexOf('=');
		var sParamName=aQueryStringVars[i].substring(0,nPos);
			
		if ((nPos==-1) || (sParamName.toLowerCase()!='sessionid')) continue;
		sSessionID=aQueryStringVars[i].substring(nPos+1);
		if (sSessionID==''){
			sSessionID='0';
		}
			break;
		}
		return sSessionID;
}

function GetSessionIDText(frmName) {
	var sSessionID='0';
	var sSessionText='document.' + frmName + '.txtSessionID.value';
	sSessionID=eval(sSessionText);
	return sSessionID;
}

var imgLogout = new Image();
imgLogout.src="/images/welcome/home/log_out.gif";

function LoginOrLogoff(htmlImage)
{
	var s = GetSessionID() ;
	if (s=='0') {
	    if (window.document[0]!=null)
	     	if (window.document[0].txtSessionID !=null)
				s = window.document[0].txtSessionID.value;
	}
	//alert(s);
	if (s=='')
		s='0';
	var d=window.document;
	//input: html image src
	//image src must have id
	//when call this function must 
	//specify id(login): ex LoginOrLogoff(document.login);
	//if (GetSessionID() != '0')
	if (s != '0')
	{ 
	    htmlImage.src=imgLogout.src;
		for (var i=0; i<d.links.length; i++){
			if (d.links[i].href.toLowerCase().indexOf("login.asp",0)!=-1){
				//d.links[i].href="/login.asp?v=0";
				d.links[i].href="javascript:AppendSessionID('/login.asp?v=0')";
				break;
			}
		}
	}
	
}
function ValidAddress(sAddress)
{
	var i=0;
	var sLen=sAddress.length;
	/*
	while (i<sLen)
	{
		if (sAddress.charAt(i) == " ")
		{
			return(true);
		}
		i++;
    }
    */
    if (sLen>=2)
		return(true);
    return(false);
}

/*function ValidEmail(sEmail)
{
	var i=0;
	var checkAt;
	var checkDot;
	var sLen=sEmail.length;
	
	while (i<sLen)
	{
		if (sEmail.charAt(i) == "@")
		{
			checkAt=true;
		}
		if (sEmail.charAt(i) == ".")
		{
			checkDot=true;
		}
		if (checkAt==true && checkDot==true)
		{
			return(true);
		}
	
    return(false);
}
*/
function ValidEmailEmpty(sEmail)
{
	var i=0;
	var checkAt;
	var checkDot;
	var sLen=sEmail.length;
	if (sLen > 0) {
		while (i<sLen)
		{
			if (sEmail.charAt(i) == "@")
			{
				checkAt=true;
			}
			if (sEmail.charAt(i) == ".")
			{
				checkDot=true;
			}
			if (checkAt==true && checkDot==true)
			{
				return(true);
			}
			i++;
		}
		return(false);
	}
	else {
		return(true)
	}
}

function IsFrame()
{
	return (window.parent!=window);
}
function RemoveFrames(sOptionalURL)
{
	if (IsFrame())
	{
		if (arguments.length==0)
			sURL=location.href;
		else
			sURL=sOptionalURL;
		window.open(sURL, target="_top");
	}
}


function enterLivePerson() {
		window.name = "lp_parent";

	domain = window.location.href; 
	if(domain.indexOf("brokersxpress") != -1){ 
		var url = "https://server.iad.liveperson.net/hc/29625551/?cmd=file&file=visitorWantsToChat&site=29625551";
	} else {		
		var url = "http://server.iad.liveperson.net/hc/LPoptionsxpress/?cmd=file&file=visitorWantsToChat&site=LPoptionsxpress";
	}

		var hWnd = window.open(url,"live_person","width=500,height=320,resizable=yes,scrollbars=yes");
		if (hWnd != null) { if (hWnd.opener == null) { hWnd.opener = self; window.name = "home"; hWnd.location.href=url; } }			
}

								  
function OpenSymbolLookup(sForm,sControl,sPageControl,sPageControlValue,contingentFlag,sLookUp,bRefresh){
	var sWindow;
	var sName;
	var sFeatures;

	
	
	if (contingentFlag=="1")
		document.frmTrade.txtFormAction.value="CONTINGENT";	

	sWindow="/symbol_lookup.asp?formname=" + sForm + "&controlname=" + sControl;
	
	if (sPageControl!="")
		sWindow=sWindow+"&pagecontrol=" + sPageControl;
	if (sPageControlValue!="")
 		sWindow=sWindow+"&pagecontrolvalue=" + sPageControlValue;
	//if (sLookUp!="" && sLookUp!=null && sLookUp != undefined)
	//alert(arguments.length);
	if (arguments.length>=6 && sLookUp!="" && sLookUp!=null)
		sWindow=sWindow+"&LookUp=" + sLookUp;
	//if (bRefresh!="" && bRefresh!=null && bRefresh!= undefined)
	if (arguments.length>=7 && bRefresh!="" && bRefresh!=null)
		sWindow=sWindow+"&Refresh=" + bRefresh;
	sName="SymbolLookup";
	sFeatures="width=500,height=500,toolbar=no,scrollbars=yes";	
	window.open(sWindow,sName,sFeatures);
	
}

function OpenSymbolLookupNet(sForm,sControl,sPageControl,sPageControlValue,contingentFlag,bRefresh){
	var sWindow;
	var sName;
	var sFeatures;

	
	
	if (contingentFlag=="1")
		document.frmTrade.txtFormAction.value="CONTINGENT";	

	sWindow="/symbol_lookup.asp?formname=" + sForm + "&controlname=" + sControl;
	
	if (sPageControl!="")
		sWindow=sWindow+"&pagecontrol=" + sPageControl;
	if (sPageControlValue!="")
 		sWindow=sWindow+"&pagecontrolvalue=" + sPageControlValue;
	sWindow=sWindow+"&Refresh=" + bRefresh;
	sName="SymbolLookup";
	sFeatures="width=500,height=500,toolbar=no,scrollbars=yes";
	
	window.open(sWindow,sName,sFeatures);
	
}

function OpenChildWindow(sURL, sName, sWidth, sHeight){

	var sName;
	var sFeatures;
	sFeatures='width=' + sWidth + ',height=' + sHeight + ',toolbar=no,scrollbars=yes';
	
	window.open(sURL,sName,sFeatures);
}

function OpenChildWindowNew(sURL, sName, sWidth, sHeight){

	var sName;
	var sFeatures;
	sFeatures='width=' + sWidth + ',height=' + sHeight + ',toolbar=no,scrollbars=no';
	
	window.open(sURL,sName,sFeatures);
}

function OpenChildWindowSizeable(sURL, sName, sWidth, sHeight){

	var sName;
	var sFeatures;
	sFeatures='width=' + sWidth + ',height=' + sHeight + ',toolbar=no,scrollbars=yes,resizable=yes';
	
	window.open(sURL,sName,sFeatures);
}

function OpenPositionWindow(sURL, sName){

	var sName;
	var sFeatures;
	sFeatures='width=770,height=600,toolbar=no,scrollbars=yes';
	
	window.open(sURL,sName,sFeatures);
}

function okToSendToBeta(chk, sAction, okToSend){
	var ans='';
	var okToSubmit=true;
	
	if (chk!=null && sAction == 'PLACE' && okToSend){
		if (chk.checked){
			ans=window.prompt("Are you sure you do not want to send this order to Exchange!","N");
			if (ans=='y' || ans=='Y')
				okToSubmit=true;
			else
				okToSubmit=false;
		}
	}
	return okToSubmit;
}

function DisableButton(sButtonName){
	//var IE4 = (document.all);
	if (!IsNetscape() && IsWindowsOS()){
		//window.alert("not netscape, win32");
		//if (sButtonName!=null) {
			sButtonName.disabled=true;
		//}
	}
	return;
}

function EnableButton(sButtonName){
	if (!IsNetscape() && IsWindowsOS()){
		//if (sButtonName!=undefined) {
			sButtonName.disabled=false;
		//}	
	}
	return;		
}

function DisablePassport(sTxtName){
	//var IE4 = (document.all);
	if (!IsNetscape() && IsWindowsOS()){
		//window.alert("not netscape, win32");
		if (sTxtName!=undefined) {
			sTxtName.disabled=true;
		}
	}
	return;
}

function EnablePassport(sTxtName){
	if (!IsNetscape() && IsWindowsOS()){
		if (sTxtName!=undefined) {
			sTxtName.disabled=false;	
		}
		
	}
	return;		
}

function DisableState(lstCountry,lstState,lstPassport){
	var oLstCountry=eval("document.frmNewAccnt." + lstCountry);
	var oLstState=eval("document.frmNewAccnt." + lstState);
	var oLstPassport=eval("document.frmNewAccnt." + lstPassport);
	var nSelIndex=oLstCountry.selectedIndex;
	if (nSelIndex<=1){
		if(oLstState != null){
			EnableButton(oLstState);
		}
	
		if (lstPassport!=undefined)
			DisablePassport(oLstPassport);
	}
	else {
		if(oLstState != null){
			oLstState.selectedIndex=0;
			DisableButton(oLstState);
		}
		if (lstPassport!=undefined)
			EnablePassport(oLstPassport);
	}
	return;
}

function NewAccntDisableFlds(){
	if (!IsNetscape() && IsWindowsOS()){
		document.frmNewAccnt.txtPassport.disabled=true;
	}
	return;		
}

function IsNetscape(){
	var sAppName=window.navigator.appName;
	var reNav=/Netscape/i;
		
	return reNav.test(sAppName);
}

function IsWindowsOS(){
	var sOS=window.navigator.platform;
	var reNav=/Win/i;
	//window.alert(reNav.test(sOS));	
	return reNav.test(sOS);
}


function FormatAccountNumber(txtAccountNumber){
	if (txtAccountNumber==null)
		return;
	var s = trim(txtAccountNumber.value);
	if (!InvalidEmailCharactersExist(s) && s.length==7 && s.charAt(0)!='0'){
		s = "0" + s;
		s=s.slice(0,4) + "-" + s.slice(4);
		txtAccountNumber.value=s;
	}
}

function FormatCurrency(dblNumber){
	dblTemp=dblNumber*100;
	dblTemp=Math.round(dblTemp)/100;
	return dblTemp;
}

function OpenMiniChain(sForm,sControl,sSessionID,sControl1,ContingentFlag,bRefreshFlag,sPageIDControl,sPageIDValue,sChainLinkName,bFromOXBranch,sTxtLmtControl,sRadLimitControl,sPage){
	//bFromOXBranch = 1 if it comes from OXBranch as it s in a diff virtual directory
	//bRefreshFlag=1 to refresh 0 not to refresh .
	//sAddlParam= add many number of parameters delimited by |
	/*
	
	*/
	var sURL="";
	var sName="";
	var sFeatures="";
	var sSymbol1="";
	
	var sSymbol=eval("document." + sForm + "." + sControl + ".value");
	//window.alert(l);
	if (sPage==null){
		sPage="MINI";
	}
	if (sSymbol=="" && sControl1!=null)
		sSymbol=eval("document." + sForm + "." + sControl1 + ".value");
	if (bFromOXBranch=="1")
	{
		sURL="/quote_option_chain.asp?" 
	}
	else
	{	
		sURL="/quote_option_chain.asp?" 
	}
	 
	sURL= sURL + "SessionID=" + sSessionID + "&FORM_NAME=" + sForm + "&CONTROL_NAME=" + sControl + "&PAGE=" + sPage;
	if (ContingentFlag=="1")
		document.frmTrade.txtFormAction.value="CONTINGENT";
	if (sSymbol > "")
		sURL=sURL + "&SYMBOL=" + sSymbol;
	if (bRefreshFlag > "")
	{
		sURL += "&REFRESH_FLAG=" + bRefreshFlag;
	}
	if (sPageIDControl > "")
	{
		sURL += "&PAGEID_CONTROL=" + sPageIDControl ;
	}

	if (sPageIDValue > "")
	{
		sURL += "&PAGEID_VALUE=" + sPageIDValue;
	}
	if (sChainLinkName > "")
	{
		sURL += "&LINK_NAME=" + sChainLinkName;
	}

	if (sTxtLmtControl > "")
	{
		sURL += "&TXT_LMT_CONTROL=" + sTxtLmtControl ;
	}	
	
	if (sRadLimitControl > "")
	{
		sURL += "&RAD_LMT_CONTROL=" + sRadLimitControl ;
	}
	//AV 05/10/2004 - Pass MarketID to mini chain
	if (eval("document." + sForm + ".lstMarket") != null && IsNumeric(eval("document." + sForm + ".lstMarket.value")))
	{
		sURL += "&MARKET_ID=" +eval("document." + sForm + ".lstMarket.value") ;
	}
	sName="OptionChain";
	var sHeight=450;
	if(sPage=="MINI_SSF")
		sHeight=725;
	sFeatures="width=580,height=" + sHeight + ",toolbar=no,scrollbars=yes,resizable=yes";
	window.open(sURL,sName,sFeatures);	
}

function OpenMiniChainII(sForm,sControl,sSessionID,sControl1,ContingentFlag,bRefreshFlag,sPageIDControl,sPageIDValue,sChainLinkName){
	//created to not include the document. to the beginning of the javascript object
	//bRefreshFlag=1 to refresh 0 not to refresh .
	//sAddlParam= add many number of parameters delimited by |
	var sURL="";
	var sName="";
	var sFeatures="";
	var sSymbol1="";
	var sSymbol=eval(sForm + "." + sControl + ".value");
	
	if (sSymbol=="" && sControl1!=null)
		sSymbol=eval(sForm + "." + sControl1 + ".value");
	
	
	sURL="/quote_option_chain.asp?SessionID=" + sSessionID + "&FORM_NAME=" + sForm + "&CONTROL_NAME=" + sControl + "&PAGE=MINI";
	if (ContingentFlag=="1")
		document.frmTrade.txtFormAction.value="CONTINGENT";
	if (sSymbol > "")
		sURL=sURL + "&SYMBOL=" + sSymbol;
	if (bRefreshFlag > "")
	{
		sURL += "&REFRESH_FLAG=" + bRefreshFlag;
	}
	if (sPageIDControl > "")
	{
		sURL += "&PAGEID_CONTROL=" + sPageIDControl ;
	}

	if (sPageIDValue > "")
	{
		sURL += "&PAGEID_VALUE=" + sPageIDValue;
	}
	if (sChainLinkName > "")
	{
		sURL += "&LINK_NAME=" + sChainLinkName;
	}

//	else if (sSymbol1 > "")
//		sURL=sURL + "&SYMBOL=" + sSymbol1;
	
	sName="OptionChain";
	sFeatures="width=550,height=450,toolbar=no,scrollbars=yes,resizable=yes";
	window.open(sURL,sName,sFeatures);	
}
function getCookie(name){
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}

function setCookie(name, value, expires, path, domain, secure) {
  document.cookie = name + "=" + escape(value) + 
  ((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function delCookie (name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function appendLinkA() {
    var sLink = "/toolbox_option_chain.asp"+document.frmToolbox.txtSymbol.value;
    return AppendSession (sLink);
}

function appendLinkB() {
    var sLink = "/toolbox_option_chain.asp"+document.frmToolbox.txtSymbol.value;
    return AppendSession (sLink);
}


function addLink() {
	var sLink;
    var sAppendChar='&';
	var nLastSlash=location.pathname.lastIndexOf('/');
	var sPath=location.pathname.substring(0, nLastSlash+1);
	var sURL='/position_chart.asp';

	if (sURL.indexOf('?')==-1)
	{
		sAppendChar='?';
	}
	if (sURL=='login.asp'){
		sURL='https://'+location.host+sPath+sURL;
	}
	sLink=sURL+sAppendChar+'SessionID='+GetSessionID();
    OpenChildWindow(sLink,'PositionChart', height='850',  width='675', scrollbars='yes');
}

function OpenCSWindow(sSubSelect) {
	var s;
	s=GetSessionID();
	OpenChildWindowNew('/welcome.asp?PageID=customerservice&SessionID='+s+'&hidSelValue='+sSubSelect,'','550','380');
}

function loadMe()
{
	document.frmLogin.txtUserID.focus();
}
/*
function PromptFocus(ctrlName, txtMessage){
	window.alert(txtMessage);
	ctrlName.value="";
	ctrlName.focus();
	return;
}
*/
function CheckForm()
{
	if (document.frmLogin.txtUserID.value=="")
	{
		PromptFocus(document.frmLogin.txtUserID, "Please enter your user name.");
		return(false);
	}
	if (document.frmLogin.txtPassword.value=="")
	{
		PromptFocus(document.frmLogin.txtPassword, "Please enter your password.");
		return(false);
	}
	else
	{
		return(true);
	}
}

function Friend() {
	var s=GetSessionID();
	OpenChildWindowSizeable('/welcome.asp?PageID=FriendReferral&amp;SessionID='+s,'False',425,450);
}

function ProcessAccntSel(frm){
 	frm.submit();
	return;
}

function dateDisplay(){
var todaysDate=now();
var month=todaysDate.getMonth();
var date=todaysDate.getDate();
var year=todaysDate.getFullYear();
document.write(month + "/" + date + "/" + year); 
}

function ExpMonthChanged(){
	return;
}

function IsRadSelected(oRadioButton){
	var bChecked=false;	
	for (i=0;i<oRadioButton.length;i++)
		if (oRadioButton[i].checked==true)
			bChecked=true;
	return(bChecked);
}

function UCaseLeadChar(txtName){
	var sString=trim(txtName.value);
	var sValue="";
	sString=sString.toLowerCase();
	var sValArr = sString.split(" ");
	for(var j=0; j<sValArr.length; j++){
		sValue = sValue + sValArr[j].substr(0,1).toUpperCase() + sValArr[j].substr(1) + " ";	
	}
	txtName.value=sValue;
	return;	
}


function OpenNewAccntDoc(sDocType,lInitAccntID,sSession,bNewAccnt){
	var sSessionID;
	var sURL="/cust_service.asp?PageID=ACCNT_DOCS&ACTION=" + sDocType;
	var sGUID = "";
	if(sSession!=null && sSession != ""){
		sSessionID = sSession;
	}
	else{
		sSessionID = GetSessionID();
	}
	if(document.getElementById("txtGUID")!=null){
		sGUID = document.getElementById("txtGUID").value;
	}
	if (sSessionID>"")
		sURL+="&SESSIONID=" + sSessionID;
	if (lInitAccntID!=null && lInitAccntID != "" && lInitAccntiD != 0)
		sURL+="&INIT_ACCNT_ID=" + lInitAccntID;
	if (sDocType=="OPXS_ACH" && sSessionID!="" && sSessionID!="0") {
		if(bNewAccnt){
			sURL="/cust_service.asp?PageID=ACH_ESTABLISHMENT&SESSIONID=" + sSessionID +"&newaccount=1";			
		}
		else{
			sURL="/cust_service.asp?PageID=ACH_ESTABLISHMENT&SESSIONID=" + sSessionID;
		}
		OpenChildWindowSizeable(sURL,'','680','750');
		//window.open(sURL,"DocWindow","menubar=yes,toolbar=yes,location=no,scrollbars=yes,resizable,height=600,width=660");
	}
	else if (sDocType=="OPXS_ACH" && sGUID!="" && sGUID!="0") {
		sURL="/cust_service.asp?PageID=ACH_ESTABLISHMENT&GUID=" + sGUID +"&newaccount=1";		
		OpenChildWindowSizeable(sURL,'','680','750');
		//window.open(sURL,"DocWindow","menubar=yes,toolbar=yes,location=no,scrollbars=yes,resizable,height=600,width=660");
	}
	else {				
		window.open(sURL,"DocWindow","menubar=yes,toolbar=yes,location=no,scrollbars=yes,resizable,height=600,width=660");
	}
	return;
}

function OpenNewACAT(bPrint,AccountID,sSession) {
	var s;
	var sSessionID;
	var sGUID = "";
	if(sSession!=null && sSession != ""){
		sSessionID = sSession;
	}
	else{
		sSessionID = GetSessionID();
	}
	if(document.getElementById("txtGUID")!=null){
		sGUID = document.getElementById("txtGUID").value;
	}
	if ((sSessionID=="" || sSessionID=="0") && (sGUID=="" || sGUID=="0")) {
		s="/cust_service.asp?PageID=ACCNT_DOCS&ACTION=OPXS_ACAT";
	}
	else {
		if (bPrint==true) {
			s="/new_account.asp?FORM_ACTION=ACAT_APPLICATION&action=print&SESSIONID=" + sSessionID + "&accountid=" + AccountID + "&GUID=" +sGUID;
		}
		else {
			s="/new_account.asp?FORM_ACTION=ACAT_APPLICATION&SESSIONID=" + sSessionID +"&GUID=" +sGUID;
		}
	}
	OpenChildWindowSizeable(s,'','650','750');
}

function OpenNewIRADistribution(bPrint,AccountID) {
	var s;
	var sSessionID;
	
	sSessionID=GetSessionID();
	s = "/OxNetAccnt/Account/transferfunds/request_ira_distribution.aspx?SESSIONID=" + sSessionID;
	OpenChildWindowSizeable(s,'','650','750');
}

function GetQueryStrValue(sURL,sParam){
//a("here");
	var sResult="";
	if (arguments.length<2 || sURL.length==0 || sParam.length==0){
//a("bad args");
		sResult="";
	}
	else {
		var aQueryStr=sURL.split("?");
		//var sNewURL=aQueryStr[0];
		var sQueryStr="";
		if (aQueryStr.length<=1){
//a("bad split");		
			sResult="";
		}
		else {
			sQueryStr=aQueryStr[1];
//a("sQueryStr="+sQueryStr);			
			var aQueryStrVars=sQueryStr.split("&");
			var nPos=0;
			var sParamName="";
			//var bParamSet=false;
		
			if (aQueryStrVars.length>0){
				for (var i=0; i<aQueryStrVars.length; i++){
					nPos=aQueryStrVars[i].indexOf("=");
					sParamName=aQueryStrVars[i].substring(0,nPos);
					if (sParamName.toUpperCase()==sParam.toUpperCase()){
						sResult=aQueryStrVars[i].substring(nPos+1);
					}
				}
			}
		}
	}
	return(sResult);
}

function AppendQueryStr(sURL,sParam,sValue,bDupParam){
	if (arguments.length<3 || sURL.length==0 || sParam.length==0 || sValue.length==0){
		return(sURL);
	}
	else {
		if (bDupParam){
			sNewURL=sURL;
			if (sNewURL.indexOf("?")==-1){
				sNewURL+="?";
			}
			else{
				sNewURL+="&";
			}
			sNewURL+=sParam+"="+sValue;			
		}
		else {
			var aQueryStr=sURL.split("?");
			var sNewURL=aQueryStr[0];
			var sQueryStr="";
			if (aQueryStr.length>1){
				sQueryStr=aQueryStr[1];
			}
			var aQueryStrVars=sQueryStr.split("&");
			var nPos=0;
			var sParamName="";
			var bParamSet=false;
		
			if (aQueryStrVars.length>0){
				for (var i=0; i<aQueryStrVars.length; i++){
					nPos=aQueryStrVars[i].indexOf("=");
					sParamName=aQueryStrVars[i].substring(0,nPos);
					if (sParamName.toUpperCase()==sParam.toUpperCase()){
						var sTemp=sParam+"="+sValue;
						aQueryStrVars[i]=sTemp;
						bParamSet=true;				
					}
					if (sNewURL.indexOf("?")==-1){
						sNewURL+="?";
					}
					else{
						sNewURL+="&";
					}
					sNewURL+=aQueryStrVars[i];
				}
			}
			if (!bParamSet){
				if (sNewURL.indexOf("?")==-1)
					sNewURL+="?";
				else
					sNewURL+="&";
				sNewURL+=sParam + "=" + sValue;						
			}
		}
		return(sNewURL);			
	}
}



function SetDefaults(lPreferenceID,sValue,sRedirect)
{
	var s;
	s=GetSessionID();
	OpenChildWindowNew('/support.asp?PageID=Default&PreferenceID='+lPreferenceID+'&Value='+sValue+'&SessionID='+s+'&Redirect='+sRedirect,'',400,400);
	//AppendSessionID('support.asp?PageID=Default&PreferenceID='+lPreferenceID+'&Value='+sValue+'&Redirect='+sRedirect,'',1,1);
}


function VerifyOutsideTrade(sSessionId) {
	//alert(location.search.substring(1));
	var sParamName='';
	var sSource='';
	var sQueryString=location.search.substring(1);
	var aQueryStringVars=sQueryString.split("&");		
	for (var i=0; i<aQueryStringVars.length; i++){		
		var sParamName=aQueryStringVars[i];		
		if ((sParamName.toLowerCase()).indexOf("source") >= 0) {
			sSource = sParamName;
			break;	
		}
		else {
			continue;
		}
	}
	if (sSource == '')
	{
		sSource = 'source=';
	}
	if (sSessionId=='outside_trade') {
		if (ValidateFields()){
		OpenChildWindowNew('/login.asp?v=outside_trade' + '&' + sSource,'Login','159','260');
		}
		return false;	
	}
	else {
		return true;
	}
}


function AddtoWatch(sSymbol,sSymbol1,sSubPageID) {
	var s,sString;
	s=GetSessionID();

	if (s=="0") {
   		window.alert("You must be logged in to use this feature");
	} else {
		
		if (sSymbol != "") {
			sString ="txtSymbol=" + sSymbol;
		}
		
		// SPR: 10/24/2003 - Commented out if statement that checks if sSymbol1 is undefined.  When undefined is used, it causes the function to not work on the Mac.
		//if (sSymbol1 != "" && sSymbol1 != undefined) {
		if (arguments.length >= 2 && sSymbol1 != "") {
			sString =sString + "&txtSymbol=" + sSymbol1 ;
		}
			
		// Same issue as mentioned above.
		//if (sSubPageID != "" && sSubPageID != undefined) {
		if (arguments.length >= 3 && sSubPageID != "") {
			// Changed URL so that adding alerts from Quote Detail brings you to Watchlist Select popup
			sString ="/quote_watch_list.asp?" + sString + "&refid=select&SessionID="+s ;
			sString =sString + "&RefSubID=" + sSubPageID;
			OpenChildWindow(sString,'',800,400);
		}else{
			sString ="/quote_watch_list.asp?" + sString + "&refid=select&SessionID="+s ;				
			OpenChildWindow(sString,'',450,400);
		}
		
		// OpenChildWindow(sString,'',450,400);
	}
}


function OpenOptionBook(sSymbol1,sSymbol2){
	var s;
	s=GetSessionID();
	window.open('/quote_detail.asp?SessionId=' + s + '&PAGE_ID=OPTION_BOOK&Symbol1=' + sSymbol1 + '&Symbol2=' + sSymbol2 + '&PopUp=1',"",'width=442,height=350,resizable=1,toolbars=0,scrollbars=0');
}


function OpenSpreadBook(sSymbol1,sSymbol2)
{
	var s,sString;
	s=GetSessionID();
	if (s=="0")
		window.alert("You must be logged in to use this feature");
	else
	{
		if (sSymbol1 != "")
			sString ="Symbol1=" + sSymbol1 ;
		if (sSymbol2 != "") 
			sString =sString + "&Symbol2=" + sSymbol2 ;
	
		sString ="/quote_option_chain.asp?" + sString + "&page=spread_book&SessionID="+s ;
		//window.alert (sString);
		OpenChildWindow(sString,'',350,370);
		
	}
}

function OpenXSpreadBook() {
	var s,sString;
	s=GetSessionID();
	sString ="/order_support.asp?pageid=orderbook&SessionID=" + s;
	window.open(sString,"", 'width=735,height=700,resizable=yes,scrollbars=yes');
}

function powerOptionsEncrypt(sAccountId) {
	var checksum=0;
	for (j=0; j<sAccountId.length; j++) 
	{
	if ((j+1)%2==1) 
	   checksum = checksum + parseInt(sAccountId.charAt(j));
	else
	   checksum = checksum + (parseInt(sAccountId.charAt(j))*2);
	}
	checksum = checksum%6;
	return (sAccountId + checksum);
}


function powerOptionsOpen(sURL, sAccountId)
{
	var s,a,ca;
	s=GetSessionID();
	a=sAccountId;
	ca = powerOptionsEncrypt(a);
	if(s!="0")
	{
		sURL = sURL + "a="+s+"&b="+ca;
		window.open(sURL); 
	}
	else
	{
		window.open('http://www.poweropt.com/oxUsers/index.asp?page=info');
	}
}


function SpeedTradePopUp()
{
	OpenChildWindow('/account/p_speed_trade.aspx','SpeedTrade','300','710');
}

/* OpenUpdate function used in Paper Trading */
function OpenUpdate(formName,bBalance)
	{
		var SessionID=eval("document." + formName + ".txtSessionID.value;");
		var sOutsideVT = eval("document." + formName + ".txtOutsideVT.value;");
		var sBranchID = ''		
		var sBranchID = eval("document." + formName + ".txtBranchID.value;");
		//alert(sOutsideVT);
		var sURL="/OXWPaperTrade/paper_account_update.aspx?SessionID=" + SessionID + "&Balance=" + bBalance + "&OUTSIDE_VT=" + sOutsideVT + "&BRANCH_ID=" +sBranchID;
		var sName="AccountUpdate";
		var sFeatures="width=420,height=370,toolbar=no,scrollbars=no,resizable=yes";
		window.open(sURL,sName,sFeatures);
	}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function EditLinkedAccount(){
	setTimeout('resetQuote()',500);	

	var sValue;
	var i;
	var n=0;
	var s;
	
	i=document.forms.length;
	if (i > 1) {
		for (n=0;n<i;n++) {
			if (document.forms[n].lstAccounts!='undefined' && document.forms[n].lstAccounts!=null) {
				sValue=document.forms[n].lstAccounts.value;
				break;
			}
		}
	}
	else {
		sValue=document.forms[0].lstAccounts.value;
	}
	if (sValue=='-1') { // Edit Linked Accounts
		s=GetSessionID();
		OpenChildWindow('/account_profile.asp?PageID=LINKEDACCOUNT&SessionID='+s,'true','430','400');
		//document.forms[n].lstAccounts.value=document.forms[n].lstAccounts[0].value;
		//document.forms[n].submit();
	} else if (sValue=='-2') { // Open New Account
		s=GetSessionID();
		document.forms[n].lstAccounts.value=document.forms[n].lstAccounts[0].value;
		OpenChildWindowSizeable('/new_account.asp?page_id=popup&asid=51&sessionid='+s,'true','750','650');
	} else if (sValue=='0') { // Spacer
		document.forms[n].lstAccounts.selectedIndex = lAccntListLastSelIndex;
		return(false);
	} else {
		if(document.forms[n].name != "frmAccountDeposit")
		{
			ProcessAccntSel(document.forms[n]);
			document.forms[n].lstAccounts.disabled = true;
		}
	}
}

function resetQuote(){
	if(parent.frames[0]){
		var qFrame = parent.frames.length-1;
		//alert(qFrame);
		parent.frames[qFrame].document.location.reload(true);
	}
}

// JY - lstAccounts onfocus event handler
function AccntListFocusReceived() {
	var i;
	var n = 0;
	
	i = document.forms.length;
	if (i > 1) {
	  for (n=0; n<i; n++) {
	    if (document.forms[n].lstAccounts!='undefined' && document.forms[n].lstAccounts!=null) {
	     break;
	    }
	  }
	}
	lAccntListLastSelIndex = document.forms[n].lstAccounts.selectedIndex;
}

/* Pop Up Window Section */

/* SPR - Functions used for Arca and Island pop up books */
              
function NewArcaPop() {
	var symbol = document.forms[0].txtSymbol.value;
	if (symbol == null)
		symbol = document.forms[0].txtSymbol[0].value;
	var iHeight = 455;
	var iWidth = 489;
	var iTop = (screen.availHeight - iHeight) / 2;
	var iLeft = (screen.availWidth - iWidth) / 2;
	createArcaWindow('http://datasvr.tradearca.com/arcadataserver/JArcaBook.php?userID=optionsXpress',symbol,'javabook','489','455');
	//window.open("http://datasvr.tradearca.com/arcadataserver/JArcaBook.php?Symbol=" + symbol,'',"height=455,width=489,scrollbars=no,resize=no");
}

function createArcaWindow (url, symbol, name, width, height) {
	var rand_num=Math.floor(Math.random()*999999);
	name = name + rand_num;
	if (symbol != null){
		url = url + "&Symbol=" + symbol

	}
	//tearWin=window.open(url, name, 'personalbar=no,toolbar=no,status=no,scrolling=yes,location=no,resizable=no,menubar=no,width=' + width + ',height=' + height);
	tearWin=window.open("/symbol_lookup.asp?SESSIONID=" + GetSessionID() + "&PAGE_ID=ARCA_WEBBOOK&URL="+url, name, 'personalbar=no,toolbar=no,status=no,scrolling=yes,location=no,resizable=no,menubar=no,width=' + width + ',height=' + height);	
}

function islandPopUpBook() { 
	var symbol = document.forms[0].txtSymbol.value;
	window.open("http://" + location.hostname + "/island_book.asp?symbol=" + symbol,"Active", 'width=260,height=530,resizable=yes');
}

function IslandPopUpBook(symbol) { 
     if (symbol != '') 	
		window.open("http://" + location.hostname + "/island_book.asp?symbol=" + symbol,"Active", 'width=260,height=530,resizable=yes');
}



/* SPR - End Functions used for Arca and Island pop up books */

function OpenJavaOptionBook(sSymbol1){
	launchQuoteBook(sSymbol1);
}

function SniffProtocol(server)
{
	var http=location.protocol;	
	var h;
	var url;
	h=http.substring(0,5);
	if (h=='http:')
	{
		http='http';
	}
	else
	{
		http='http';
	}
	server=(server.substring(7,(server.length-1)));
	
	
	if (server.length > 0)
	{
		url = http +':/'+ server+ '/'
	}
	else
	{
		url = '';
	}
	
	return url;
}

/* SPR - Function used for pop-up Analyzer  */
function openPLChart(url) {
	window.open(url,"","width=730,height=500,resizable=no,scrollbars=yes");
}

function OpenTradersDiary(server,session) {
	if (server == "" || server == "/"){
		server="https://" + location.hostname;
	}
	var path='/OXNetAccnt/Account/account_trader_diary.aspx?SessionID=' + session;
	url=server + path;
	window.open(url ,"",'width=442,height=500,resizable=0,toolbars=0,scrollbars=1');
}

//function OpenCommissionCalculator(server,session) {
function OpenCommissionCalculator() {
	//var path='OXNetAccnt/Trade/trade_commission_calculator.aspx?SessionID=' + session;
	var server="https://" + location.hostname;
	/*if (location.hostname!='wayne') {
		server='http://oxbranch.optionsxpress.com/';
	}*/
	var path='/OXNetAccnt/Trade/trade_commission_calculator.aspx';
	url=server + path;
	//url=server + path;
	window.open(url ,"",'width=317,height=183,resizable=0,toolbars=0,scrollbars=0');
	//window.open(url ,"",'width=320,height=180,resizable=0,toolbars=0,scrollbars=0');
}

function GetPrintableConfirmsURL(server,session) {
	var path='/OXNetAccnt/Account/confirms/account_confirms_printable.aspx?SessionID=' + session;
	url=server + path;
	window.open(url ,"",'width=442,height=500,resizable=0,toolbars=0,scrollbars=1');
}

// This is a function for the chain body include file header
function SubmitChainsLinksBody(page){
        document.forms[0].lstOption.value = page;
        document.forms[0].submit();
}

function OpenHTMLConfirm(sList,Price,Bust,Date,DRID,StartDate,EndDate)
{
	var Type='HTML';
	var s=GetSessionID();
	window.open ('/OXNetAccnt/Account/confirms/account_confirms_printable_display.aspx?PageID=account_confirms_printable&Price=' + Price + '&Date=' + Date + '&Bust=' + Bust + '&Type=' + Type + '&SessionID=' + s + '&DRID=' + DRID + '&SelectedList=' + sList + '&SD=' + StartDate + '&ED=' + EndDate,"",'width=742,height=950,resizable=1,toolbars=1,scrollbars=1');
}

function OpenTimeSeries() {
	var s=GetSessionID();
	var symbol = document.forms[0].txtSymbol.value;
	window.open("/quote_detail.asp?SESSIONID=" + s + "&PAGE_ID=TIME_SERIES&symbol=" + symbol, "frmTimeSeries", "width=450,height=500,toolbar=no,scrollbars=yes");
}
function OpenCenterPieceDownLoad()
{
	var s=GetSessionID();
	window.open ('/OXNetAccnt/Account/DownLoads/account_down_load_data.aspx?&SessionID=' + s  ,"",'width=650,height=360,resizable=1,toolbars=1,scrollbars=1');
	
}

function notrade(url)
{
		newwindow=window.open(url,'name','height=250,width=300');
		if (window.focus) {newwindow.focus()}
}

function CheckLstDate(win)
{
	var aLstValue,bLstValue,sLstValue,sLstValue1,bFlag;
	sLstValue=win.hidEndDates.value;
	sLstValue1=win.hidStartDates.value;
	aLstValue=sLstValue.split("+");
	bLstValue=sLstValue1.split("+");		

	for (var i=0; i<12; i++)
	//for (var i=1; i<aLstValue.length + 1; i++)
	{
		if (win.lstDateRange.value == 11)
		{
			if (win.txtStartDate!=null) {
				win.txtStartDate.value="";
				win.txtEndDate.value="";	
			}
		}
		else
		{
			if (win.lstDateRange.value == i)
			{		
				win.txtStartDate.value=bLstValue[i];
				win.txtEndDate.value=aLstValue[i];	
			}
		}	
	}
	win.hidStartDate.value = win.txtStartDate.value;
	win.hidEndDate.value = win.txtEndDate.value;

}

function SetDateRange(frm)
{
	
	//Determine if value has changed before changing the period
	//in some cases the value of Date Range is 7
  if (frm.lstDateRangeID != undefined && frm.lstDateRangeID != null)
 {
	
	 if (frm.lstDateRangeID.value !=7)
	{
	
		if (frm.txtStartDate.value != frm.hidStartDate.value || frm.txtEndDate.value != frm.hidEndDate.value)
		{
			frm.lstDateRangeID.value=7;
		}	
	}
	else
	{
		frm.lstDateRangeID.value=7;
	}
 }
 else if (frm.lstDateRange != undefined && frm.lstDateRange != null)
 {
	if (frm.lstDateRange.value !=11)
	{
	
		if (frm.txtStartDate.value != frm.hidStartDate.value || frm.txtEndDate.value != frm.hidEndDate.value)
		{
			frm.lstDateRange.value=11;
		}	
	}
	else
	{
		frm.lstDateRange.value=11;
	}
 }
}
function ValidateDateRange(frm)
{
	RemSpaces(frm.txtEndDate,'A');
	RemSpaces(frm.txtStartDate,'A');
	var datStartDate=frm.txtStartDate.value;
	var datEndDate=frm.txtEndDate.value;
	
	if (frm.lstDateRange.value==11)
	{
		if (datStartDate.length==0)
		{
			PromptFocus(frm.txtStartDate, "Please enter start date.");
			return(false);
		}
		if (datEndDate.length==0)
		{
			PromptFocus(frm.txtEndDate, "Please enter end date.");
			return(false);
		}	
		if (IsAnyAlphaCharactersExist(datStartDate,0))
		{
			PromptFocus(frm.txtStartDate, "Please enter a valid start date.");
			return false;
		}
		
	
		if (IsAnyAlphaCharactersExist(datEndDate,0))
		{
			PromptFocus(frm.txtEndDate, "Please enter a valid end date.");
			return false;
		}
		
		var nValidDate=isValidDate(datStartDate);
		if (nValidDate==1)
		{
			frm.txtStartDate.value="";
			PromptFocus(frm.txtStartDate, "Please enter a date in the following format: mm/dd/yyyy.");
			return(false);
		}
		if ((nValidDate==2) || (nValidDate==3)) 
		{
			frm.txtStartDate.value="";
			PromptFocus(frm.txtStartDate, "Please enter a valid date.");
			return(false);
		}
		nValidDate=isValidDate(datEndDate);
		if (nValidDate==1)
		{
			frm.txtEndDate.value="";
			PromptFocus(frm.txtEndDate, "Please enter a date in the following format: mm/dd/yyyy.");
			return(false);
		}
		if ((nValidDate==2) || (nValidDate==3)) 
		{
			frm.txtEndDate.value="";
			PromptFocus(frm.txtEndDate, "Please enter a valid date.");
			return(false);
		}
		var oStartDate=new Date(datStartDate);
		var oEndDate=new Date(datEndDate);
		if(isNaN(oStartDate) || isNaN(oEndDate)){
			window.alert("Please make sure the start and end dates are in mm/dd/yyyy format.");
			return(false);
		}
		if (oStartDate>oEndDate)
		{
			frm.txtEndDate.value="";
			PromptFocus(frm.txtEndDate, "Please enter a date after the Start Date.");
			return(false);
		}
		return(true);			
	
	}
	return(true);			
}

function trim(inputString) {   
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function setLstBox(oLstBox,sValue){
	if(oLstBox!=null){
		//window.alert(oLstBox.options.length);
		var nCount=oLstBox.options.length;
		for(var n=0; n<nCount; n++){
			if(oLstBox.options[n].text==sValue){
				oLstBox.selectedIndex=n;
			}
		}
	}
}
//DS : 21581 : 1/24/2007
function setLstBoxByValue(oLstBox,sValue){	
	if(oLstBox!=null){		
		var nCount=oLstBox.options.length;
		for(var n=0; n<nCount; n++){
			if(oLstBox.options[n].value==sValue){				
				oLstBox.selectedIndex=n;
				break;
			}
		}
	}
}

function getRadSelIndex(oRad){
	var nCount=oRad.length;
	var nRet=-1;

	for(var i=0;i<nCount;i++){
		if(oRad[i].checked){
			nRet=i;
			break;
		}
	}
	return(nRet);
}

function MutualFundLookUp(sForm,sControl,sPageControl,sPageControlValue) {	
	var s=GetSessionID();
	OpenChildWindowSizeable('/symbol_lookup.asp?PAGE_ID=FIND_MF&FORM=' + sForm + '&CONTROL=' + sControl + '&PageControl=' + sPageControl + '&PageControlValue=' + sPageControlValue + '&SessionID=' + s,'','575','215');
}

// Displays Prophet Chart in a popup window
function openProphetCharts() {
	var s, sym, sTemp;
	sym = "QQQ";
	s=GetSessionID();
	sTemp = 'https://www.optionsxpress.com/quote_charts.asp?sessionid=' + s + '&symb=' + sym + '&PageID=STREAMING_CHARTS';
	OpenChildWindowSizeable(sTemp,'StreamingChart','550', '435');
}

// SPR: Sets focus in input boxes when page loads (e.g. home page, quote detail, etc.
function BoxFocus(form, element) {
	var loadfocus;
	loadfocus = "document." + form + "." + element + " != null";
	if (eval(loadfocus))
	{	
		loadfocus = "document." + form + "." + element + ".focus();";
		eval(loadfocus);
	}
}

//AV Detachable Calculator 03/24/2004
function DetachCalculator(symbol1, symbol2, symbol3, symbol4, type1, type2, type3, type4) {
	var s;
	s = GetSessionID();
	OpenChildWindowSizeable('/position_chart.asp?PageID=trade_calculator&DETACH=TRUE&CALCULATE=FALSE&txtSymbol1='+symbol1+'&txtSymbol2='+symbol2+'&txtSymbol3='+symbol3+'&txtSymbol4='+symbol4+'&txtAct1='+type1+'&txtAct2='+type2+'&txtAct3='+type3+'&txtAct4='+type4+'&SessionID='+s,'','748','550');
}

/**
* Checks if a window pops up without a session - AV Issue 6964 - 03/29/04
*/
function checkOpener(href){
    
     if (opener && !opener.closed){
	  
		window.opener.location.href = href;
		window.close();
		}
	
}

function ResetLeapAndMonth(){
	document.frmOptChain.txtMonths.value = "";
	document.frmOptChain.txtLeap.value = "";
}


// Selects all check boxes in the string as in the master checkbox
// sCheckboxes is the list of names of the checkboxes without the prefix and comma-separated
// sPrefix is the prefix for each checkbox name (usually chk)
// sForm is the form name
// sMasterCheckBox is the name of the master checkbox
function MatchCheckboxesToMaster(sCheckboxes,sPrefix,sForm, sMasterCheckBox)
{
 var checklist_array=sCheckboxes.split(",");
 
 for (i=0; i < checklist_array.length; i++)
 {
	s = sForm+"."+sPrefix+checklist_array[i]+".checked = " + sForm+"."+sMasterCheckBox+".checked;";
	eval(s);
 }
}


// Enables or disables the command button based on the checkboxes
// sCheckboxes is the list of names of the checkboxes without the prefix and comma-separated
// sPrefix is the prefix for each checkbox name (usually chk)
// sForm is the form name
// sButton is the button to be enabled or disabled
// schkAll is the master chkAll box that becomes checked or unchecked
function SetButtonToCheckboxes(sCheckboxes,sPrefix,sForm, sButton,schkAll)
{
 var checklist_array=sCheckboxes.split(",");
 checkboxeson=0;
 for (i=0; i < checklist_array.length; i++)
 {
	s = sForm+"."+sPrefix+checklist_array[i]+".checked == true";
	if (eval(s)) {
		checkboxeson = checkboxeson + 1;
        }
 }
 if (checkboxeson == 0){
    s=sForm+"."+sButton+".disabled = true;";
    d=sForm+"."+schkAll+".checked = false;";
    eval(d);
 }
 else{
    s=sForm+"."+sButton+".disabled = false;";
    if (checkboxeson == checklist_array.length){
	d=sForm+"."+schkAll+".checked = true;";	
        eval(d);
    }
 }
 eval(s);
}

/* Used for links in popup windows.  Place around link so it will load in the main window. */
function Detach(sValue) {		
	window.opener.location = sValue;
	window.opener.focus(); 
}


function AddBeneficiary(nInitAccountID) {
	var s=GetSessionID();
	OpenChildWindowSizeable('/new_accnt_support.asp?PageID=ACCOUNT_BENEFICIARY&SessionID=' + s + '&INIT_ACCNT_ID=' +nInitAccountID,'','1100','650');
}

/* Expand/Collapse */
function RowsShowHide(sImg,sTrid,nLegs,startindex,usesmallimages) 
{
	/**********************************************
	Clean the Start index if not passed 
	**********************************************/
        if (startindex==null)
	{startindex=0;}
	if (!IsNumeric(startindex))
	{startindex=0;}
   	if (usesmallimages==null)
	{usesmallimages=0;}
	if (!IsNumeric(usesmallimages))
	{usesmallimages=0;}
	/***************************************************
	Start Index Used for Nested ShowHide
	  - Is StartIndex > 0 Indicates Nested ShowHide
	***************************************************/
	
	var bForce=0;
	var expanded=0;
		
	/***************************************************
	If top level is selected. 
	 - Check Icon of top strid&startindex
	   if minus then need to hide all sub rows
	   if plus then show all sub rows

	***************************************************/
	if (startindex==0)
	{
		bForce=1
		var test;
		var gif;

		test = 'document.' + sImg + '.src'
		var parts=eval(test).split("/");
		gif=parts[parts.length-1];			
		if (gif!='minus.gif' && gif!='minus_sm.gif' && gif!='minus_bg.gif')
		{
			expanded=1;
		}
		if(gif=='minus_bg.gif' || gif=='plus_bg.gif'){
			usesmallimages=2;
		}
		
	}
	RowsShowHideBase(sImg,sTrid,nLegs,bForce,expanded,startindex,usesmallimages)
}
function RowsShowHideBase(sImg,sTrid,nLegs,bForce,expanded,startindex,usesmallimages) 
{
/**********************************************
Cleans the Start index
**********************************************/
   if (startindex==null)
   {
  	startindex=0;
   }
   if (!IsNumeric(startindex))
   {
  	startindex=0;
   }
   if (usesmallimages==null)
   {
  	usesmallimages=0;
   }
   if (!IsNumeric(usesmallimages))
   {
  	usesmallimages=0;
   }
   var i;
   var trid; 
   var s;
   var lastvalidtrid;
   var lastvalidimg;
   var count;
	count= Number(startindex) +Number(nLegs);
	for (i = startindex; i < count; i++) 
	{
   		try
   		{
			trid = sTrid + i;
			if (bForce==1)
			{
				if (expanded==0)
				{       	
					document.getElementById(trid).style.display='none';       
				}
				else 
				{
					document.getElementById(trid).style.display='';
				}
			
			}
			else
			{
				if (document.getElementById(trid).style.display == '') 
				{       	
					document.getElementById(trid).style.display='none';       
				}
				else 
				{
					document.getElementById(trid).style.display='';
				}
			}
			
			
			
			lastvalidtrid =trid;
		}
		catch(exception)
		{
			break;
		}
   	}
	/*****************************************************
	StartIndex > 0 indicates that nested showhide
	 - Use plus_sm.gif/minus_sm.gif
	*****************************************************/
   	if (document.getElementById(lastvalidtrid).style.display == 'none') 
	{       	
			
		if (usesmallimages==1)
		{
	   		s = 'document.' + sImg + '.src="/images/icons/plus_sm.gif"' ;  	        
		}
		else if(usesmallimages==2){
			s = 'document.' + sImg + '.src="/images/icons/plus_bg.gif"' ;
		}
		else
		{
	   		s = 'document.' + sImg + '.src="/images/icons/plus.gif"' ;  	        
		}
   	}
   	else 
   	{       
		if (usesmallimages==1)
		{
		   	s = 'document.' + sImg + '.src="/images/icons/minus_sm.gif"';    	
		}
		else if(usesmallimages==2){
			s = 'document.' + sImg + '.src="/images/icons/minus_bg.gif"' ;
		}		
		else
		{
			s = 'document.' + sImg + '.src="/images/icons/minus.gif"';    	
		}

   		
   	}
	eval(s);
}

function ShowHideElementId(sTrid,bShow)
{
	if(bShow) 
	{
		document.getElementById(sTrid).style.display='';
	}
	else
	{
		document.getElementById(sTrid).style.display='none';
	}
}

/* for external links dm 10/20/04 */
function OpenExit(sLink,sName) {
	OpenChildWindowSizeable('/exit_popup.aspx?site=' + sLink + '&name=' + sName,'','405','295');
}

function SetContributionYear(sForm) {
	var nContributionID=sForm.lstContributionCode.value;

	if (nContributionID==6 || nContributionID==8 || nContributionID==9) {
		var todaysDate= new Date();	
		var year=todaysDate.getFullYear();
		sForm.lstContributionYear.value=year;
		sForm.lstContributionYear.disabled=true;
	}
	else {
		//sForm.lstContributionYear.value="";
		sForm.lstContributionYear.disabled=false;	
	}
}

function ViewUncleardFunds() {
	var s=GetSessionID();
	OpenChildWindowSizeable('/account_balance.asp?SessionID=' + s + '&PageID=AccountUnClearFunds', 'AccountUnClearFunds', '700','400');
}

function PopulateProvince(sForm,sTxtControl,sLstControl) {
	var s;

	s = "document.forms." + sForm.name + "." + sTxtControl + ".value=document.forms." + sForm.name + "." + sLstControl + "[document.forms." + sForm.name + "." + sLstControl + ".selectedIndex].text";
	eval(s);
}

function ReloadProvinces(sForm) {
	sForm.txtReloadProvince.value="true";
	sForm.submit();
}

function OpenDisclosure(sName) {
	var s='/newaccount/disclosures/' + sName + '.htm';
	OpenChildWindowSizeable(s,'','600','500');
}

function ValidQQQSymbol(sSymbol,sCtrl){
	//alert(sSymbol.toUpperCase);
	if (trim(sSymbol).toUpperCase() =="QQQ"){
		PromptFocus(sCtrl, "The Symbol 'QQQ' has been changed to 'QQQQ'");
		sCtrl.value = "QQQQ";
		return false;
	}
	else {
		return true;
	}
}

//AV check whether cookies are enabled
function IsCookieEnabled(){
		document.cookie = "test=cookiesEnabled";
		var pos = document.cookie.indexOf( "test=" );
		if( pos == -1 ) {
			return false;
		}
		else {
			return true;
		}
    }

// JY 02/09/2005 - Used in Web Broker - Opens popup for adding notes on XView and Broker View pages
function OrderNotePopup(sOrderID) {
  var s;
  s=GetSessionID();
  OpenChildWindow('/broker_report.asp?pageid=brokerordernote&subPageID=view&orderID='+sOrderID+'&SessionID='+s,'','350','250');
}

// MB 03/04/2005 - Market Data tab script for index page
var oldTab = "ex1"
function exTab(tab){
        if (oldTab != null){ 
                document.getElementById(oldTab).className="exch"; 
        }
        document.getElementById(tab).className="exch2"; 
        oldTab=tab; 
}

//AV Changes the color of the highlighted row
function ChangeColor(target, changeClass, clsName){	
	if (clsName == null || clsName == 'undefined'){
		clsName = getElement(target).className;				
		if ( clsName != changeClass ) {
			getElement(target).className = changeClass;
		} 
		else {
			getElement(target).className = clsName;	      
		} 
	}
	else {		
		getElement(target).className = clsName;	  
	}
}

function getElement(eid) {
	if (document.all) {
		return document.all[eid];
	}
	if (document.getElementById) {
		return document.getElementById(eid);
	}
}

//DM 3/23/05 Javascript hide contents function. call as lotechHide(0,0,1,1);  0=don't hide, 1=hide for (ox,oxi,ob,bx)
//tag content block with id="hideContent". get firm on page with:
//firm = "<WC@FIRMNAME>optionsXpress</WC@FIRMNAME>"; or for webbase pages:
//firm = '<span value=WC@FIRMNAME runat=server><WC@FIRMNAME></WC@FIRMNAME></span>';
//firm = firm.substring(firm.indexOf(">")+1);
//firm = firm.substring(0,firm.indexOf("<"));
//useful for pages that don't rescan tags
	function lotechHide(ox,oxi,ob,bx){
		if (ox == "1" && firm == "optionsXpress"){
			document.getElementById("hideContent").style.display = "none";
		}
		if (oxi == "1" && firm == "optionsXpress"){
			document.getElementById("hideContent").style.display = "none";
		}
		if (ob == "1" && firm == "optionsXpress Australia"){
			document.getElementById("hideContent").style.display = "none";
		}
		if (bx == "1" && firm == "brokersXpress"){
			document.getElementById("hideContent").style.display = "none";
		}
	}

	//AV not used for now
	function CheckExceptionSymbol(sSymbol) {
		if (trim(sSymbol).toUpperCase() =="S"){
			alert("Corporate action in process and pricing is complex. \n Contact LiveHelp or call if you have questions.");
		}
		return true;	
	}

//dm 3/24/05 for FAQ pages.  different targets for popup vs. onsite version of page.
function popCheck(){
	var s=GetSessionID();
      if (pop == 1)
       {
         location.href="/welcome/faq/p_faq.aspx?SessionID=" + s;
       }
      else
       {
         location.href="/welcome/faq/index.aspx?SessionID=" + s;
       }  
	}

function changeLink (par) {
	var s=GetSessionID();
      if (pop == 1)
       {
    window.opener.location.href = "javascript:AppendSessionID('" + par + "')";
     } else  {
         location.href =  "javascript:AppendSessionID('" + par + "')";
       } 
}

function ValidateSeqID(sRoute, sSeqID) {
   /* return codes:
         0 = Pass
        -1 = Fail - zero-length string or string "0"
        -2 = Fail - too many chars.
        -3 = Fail - not all numeric (if route not ISE_OM and route not RJO) */ 
   var nReturnCode = 0;
   var bContinue = true;

   // first check if user typed in a value
   if (sSeqID.length == 0 || sSeqID == "0") {
     nReturnCode = -1;
     bContinue = false;
   }

   // next check length (<= 16 chars)
   if (sSeqID.length > 16 && bContinue) {
     nReturnCode = -2;  
     bContinue = false;
   }     
      
   // next check if numeric (if route not ISE_OM and route not RJO)
   if (sRoute != "ISE_OM" && sRoute != "RJO" && !IsNumeric(sSeqID) && bContinue) {
     nReturnCode = -3;
   }

   return nReturnCode;   
}

function IsNumeric(strString) {
   //  check for valid numeric strings	
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;


   for (i = 0; i < strString.length && blnResult == true; i++) {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) {
        blnResult = false;
      }
   }
   return blnResult;
}	

//AV Used in Stock Preview
function showHaltedStockWarning(bShowWarning){
	if (bShowWarning.toUpperCase() == "TRUE"){
		window.alert("Trading has been halted for this security. \nIf placing a market order, your order could execute at "+
				"a price significantly different from the last trading quotation." + 
			"\nLimit orders may be used to protect against adverse price movement, however," +
			" limit orders by their nature are not guaranteed execution.");
	}
}

//JY 20050511 - Used on Balances page - Broker with a perm. will have popup to edit 'Pending Dividends' value
function ViewPendDividends(nForeignMarketID) {
	var s=GetSessionID();
	OpenChildWindowSizeable('/account_balance.asp?SessionID=' + s + '&PageID=AccntBalPendDividends' + '&lstMarket=' + nForeignMarketID, 'AccntBalPendDividends', '375','275');
}
function launchQuoteBook(symbol){
var s;
s=GetSessionID();
var sFeatures="width=435,height=450,toolbar=no,scrollbars=no,resizable=yes";
var sName = "http://www.optionsxpress.com/quotes/quote_box.htm?sessionid="+s+"&symbol="+symbol;
window.open(sName,"", sFeatures);
}

//JY 20050526
function OpenFutureLookup(sForm, sControl, bShowExpDate, sSymbol) {
	var sUrl;
	var sPageID;

	if (bShowExpDate)
		sPageID = "find_futures_date";
	else
		sPageID = "find_futures";

	sUrl = "/symbol_lookup.asp?page_id=" + sPageID + "&form=" + sForm + "&control=" + sControl;

	if(sSymbol != "")
	{
		sUrl = sUrl + "&Symbol=" + sSymbol;
	}
	
	OpenChildWindow(sUrl,'FuturesLookup','500','215');
}
//SC
function OpenFutureOptionLookup(sForm, sControl, bShowExpDate, sSymbol) {
	var sUrl;
	var sPageID;
	var option;
	if (bShowExpDate)
		sPageID = "option";
	else
		sPageID = "find_futures";
	sUrl = "/symbol_lookup.asp?page_id=" + sPageID + "&form=" + sForm + "&control=" + sControl + "&PageControl=option" ;

	if(sSymbol != "")
	{
		sUrl = sUrl + "&Symbol=" + sSymbol;
	}
	
	OpenChildWindow(sUrl,'FuturesLookup','500','215');
}

//JY 20050707
function OrderStatusCheck(sValue,sSeqId,sAccntNum,sOrderStatus) {
	var s,sTemp;
	s=GetSessionID();
	sTemp = "/order_support.asp?PageID=OrderStatusCheck&sessionid=" + s + "&OrderNumber=" + sValue + "&SeqID=" + sSeqId + "&AccntNum=" + sAccntNum + "&OrderStatus=" + sOrderStatus;
	OpenChildWindow(sTemp,'true','330','300');
}
//MB 20050713
function LaunchXtendlite() { 
	LaunchXtend();
} 

function LaunchXtend() {
	var s;
	s=GetSessionID();
	window.open("http://xtend.optionsxpress.com/xtend/index.asp?s=btn_xtend&SessionID="+s,"","width=1000,height=800,resizable=1,toolbars=0,scrollbars=0");
}

// SPR Search Functions
searchFocus='false';
function searchSubmit(bFramed) {
	if(searchFocus == 'true'){

	if(document.forms[0]){
		for(i=0;i<document.forms[0].elements.length;i++){  
    	        document.forms[0].elements[i].disabled = true; // disable form for enter key submit on search
		}
	}
	window.onUnload = enableForm();
	var isFramed = bFramed;
	
	var s;
	s=GetSessionID();
	
	var searchValue = document.getElementById("qt").value;
	searchValue = StripIllegalChars(searchValue);
					
	if (searchValue != "") {
		if (isFramed == "1") { // Used for triple framed pages
			parent.location.href =  location.protocol + "//" + location.hostname + "/OXNetTools/Search/SearchInterceptor.aspx?sessionid=" + s + "&qt=" + searchValue + "&col=oxps&charset=iso-8859-1&la=en";
		} else if (isFramed == "0") { // Used for non-session and two framed pages
			var is_opera = navigator.userAgent.toLowerCase().indexOf("opera") != -1; 
			var is_mac = navigator.userAgent.toLowerCase().indexOf("mac") != -1; 			
			if(is_opera || is_mac){ // mac and opera have location.href issues
				parent.location.href = location.protocol + "//" + location.hostname + "/OXNetTools/Search/SearchInterceptor.aspx?sessionid=" + s + "&qt=" + searchValue + "&col=oxps&charset=iso-8859-1&la=en";
			}
			else{
				location.href = location.protocol + "//" + location.hostname + "/OXNetTools/Search/SearchInterceptor.aspx?sessionid=" + s + "&qt=" + searchValue + "&col=oxps&charset=iso-8859-1&la=en";
			}
		}
	} else {
		window.alert("Please enter your search request.");
		enableForm();
	}

	}else{
		return false;
	}
				
}

function enableForm(){
	if(document.forms[0]){
		for(i=0;i<document.forms[0].elements.length;i++){ 
    		document.forms[0].elements[i].disabled = false; // re-enable form on empty search query & back button
		}
	}
}

//EA 10/27/2006
function searchSubmitButton(bFramed) {

	if(document.forms[0]){
		for(i=0;i<document.forms[0].elements.length;i++){  
    	        document.forms[0].elements[i].disabled = true; // disable form for enter key submit on search
		}
	}
	window.onUnload = enableForm();
	var isFramed = bFramed;
	
	var s;
	s=GetSessionID();
	
	var searchValue = document.getElementById("search").value;
	searchValue = StripIllegalChars(searchValue);
					
	if (searchValue != "") {
		if (isFramed == "1") { // Used for triple framed pages
			parent.location.href =  location.protocol + "//" + location.hostname + "/OXNetTools/Search/SearchInterceptor.aspx?sessionid=" + s + "&qt=" + searchValue + "&col=oxps&charset=iso-8859-1&la=en";
		} else if (isFramed == "0") { // Used for non-session and two framed pages
			var is_opera = navigator.userAgent.toLowerCase().indexOf("opera") != -1; 
			var is_mac = navigator.userAgent.toLowerCase().indexOf("mac") != -1; 			
			if(is_opera || is_mac){ // mac and opera have location.href issues
				parent.location.href = location.protocol + "//" + location.hostname + "/OXNetTools/Search/SearchInterceptor.aspx?sessionid=" + s + "&qt=" + searchValue + "&col=oxps&charset=iso-8859-1&la=en";
			}
			else{
				location.href = location.protocol + "//" + location.hostname + "/OXNetTools/Search/SearchInterceptor.aspx?sessionid=" + s + "&qt=" + searchValue + "&col=oxps&charset=iso-8859-1&la=en";
			}
		}
	} else {
		window.alert("Please enter your search request.");
		enableForm();
	}			
}

function disableEnterKey(e) {
	var key;

	if(window.event) {
		key = window.event.keyCode;     //IE
	} else {
		key = e.which;     //firefox
	}

	if(key == 13) {
		return false;
	} else {
		return true;
	}
}

//DM 11/21/05
function getFirmType(){
	var urlFirm = location.href;
	urlFirm = urlFirm.toLowerCase();
	var firm = '';
	if(urlFirm.indexOf('.sg')!=-1 || urlFirm.indexOf('sg.eqdesign')!=-1 || getCookie('Firm')=='SN'){
		firm = 'SN';
	}
	else if(urlFirm.indexOf('.ca')!=-1 || urlFirm.indexOf('ca.eqdesign')!=-1 || getCookie('Firm')=='CA'){
		firm = 'CA';
	}
	else if(urlFirm.indexOf('.au')!=-1 || urlFirm.indexOf('au.eqdesign')!=-1 || getCookie('Firm')=='OB'){
		firm = 'OB';
	}
	else if(urlFirm.indexOf('brokersxpress')!=-1 || urlFirm.indexOf('bx.eqdesign')!=-1 || getCookie('Firm')=='BX'){
		firm = 'BX';
	}
	else if(urlFirm.indexOf('optionsxpress.europe')!=-1 || urlFirm.indexOf('optionsxpress.eu')!=-1 || urlFirm.indexOf('eu.eqdesign')!=-1 || getCookie('Firm')=='EU'){
		firm = 'EU';
	}
	else if(urlFirm.indexOf('oxint')!=-1 || urlFirm.indexOf('oxint.eqdesign')!=-1 || getCookie('Firm')=='OXI'){
		firm = 'OXI';
	}	
	else {
		firm = 'OX';
	}
	//alert(firm);
	return firm;
}

//DM 12/01/05 For IE browser data tables.  Will insert &nbsp; into empty cells so styles will be applied.
function emptyCells(){
	var numTd = document.getElementsByTagName("td").length;
	for(i=0;i<=numTd;i++){
		if(document.getElementsByTagName("td")[i]){
			if (document.getElementsByTagName("td")[i].innerHTML == '') {
	      		document.getElementsByTagName("td")[i].innerHTML = '&nbsp;';
			}
	    }
	}
}

//AV 12/09/2005 - Generic Function called from Future Lookup - can be overridden
function PopulateFuturesSymbol(sForm, sControl, sSymbol, sSymbolDescription) {
		s="self.opener.document." + sForm + "." + sControl;
		eval(s + ".value='"+ sSymbol + "'");
		if(sForm == "frmQuoteDetail" || sForm == "frmOptChain"){
			s="self.opener.document." + sForm + ".submit()";
			eval(s);
		}
		else if(sForm == "frmTrade"){
			eval(s + ".onchange();");
		}
}


function OnChangeSymFutures(){
	var sSessionID = '';

	sSessionID=document.frmTrade.txtSessionID.value;
	if (document.frmTrade.txtSymbol!= null && trim(document.frmTrade.txtSymbol.value) == "")
	{
		return;
	}
	if(document.getElementById("spanFUTPRODDESC") != null) 
	{
		document.getElementById("spanFUTPRODDESC").innerHTML = "";
	}

	if(window.frames[0]!= null && window.frames[0].document.frmQuoteBox != null && window.frames[0].document.frmQuoteBox.action!=null)
	{
		window.frames[0].document.frmQuoteBox.action = window.frames[0].document.frmQuoteBox.action + "&SessionID=" + sSessionID + "&Symbol=" + document.frmTrade.txtSymbol.value;
		window.frames[0].document.frmQuoteBox.submit();
	}
	else if(window.frames[1]!= null && window.frames[1].document.frmQuoteBox != null && window.frames[1].document.frmQuoteBox.action!=null) 
	{
		window.frames[1].document.frmQuoteBox.action = window.frames[1].document.frmQuoteBox.action + "&SessionID=" + sSessionID + "&Symbol=" + document.frmTrade.txtSymbol.value;
		window.frames[1].document.frmQuoteBox.submit();
	}
}

function CFutActivToDisplay(sSymbol)
{
	var nPos = sSymbol.indexOf('/');

	if(nPos > 0 && sSymbol.length == nPos + 4)
	{
		var sRootSymbol = sSymbol.substr(0, nPos)
		var sExpMonth = sSymbol.substr(nPos + 3, 1);
		var sExpYear = sSymbol.substr(nPos + 2, 1);

		sSymbol = sRootSymbol + sExpMonth + sExpYear;
	}
	
	return sSymbol;
}

function ChangeSymDescr(sSymbolDescription){
	if(document.getElementById("spanFUTPRODDESC") != null) {				
			document.getElementById("spanFUTPRODDESC").innerHTML = sSymbolDescription;
	}

	document.frmTrade.txtSymbol.value = CFutActivToDisplay(document.frmTrade.txtSymbol.value.toUpperCase());
}

function ChangeLastTradeDateMsg(sDescription){
	if(document.getElementById("SpanLASTTRADEDATEMSG") != null)
	{
		document.getElementById("SpanLASTTRADEDATEMSG").innerHTML = sDescription;
	}
}

//DS : 8838 : 12/20/2005
// Returns true if passed username is valid
// Used in: \source\Web\OXAccnt\OXAccnt_Local\account_linked_list.htm
function IsValidAccountUserName(sValue){
	var i=0;
	var sChar;
	
	do
	{
		sChar=sValue.substring(i,i+1);
		if ( (InvalidCharactersExist(sChar) && (sChar!='_') ))
		{
			return(false);
		}
		i++;	
	}
	while (i<sValue.length);
	return(true);
}

// SPR: 1/20/06
// Show Selected sub navigation tab
function showSelectedTab(pageId) {
	
	var pageName, tab;
	
	pageName = pageId.substring(3,99);		// id of page; set in the body.

	if (pageName == "spread" || pageName == "covered_call") {
		tab = "tab" + pageName;					// id of soon-to-be-selected tab
	} else {
		tab = "sub_" + pageName;				// id of soon-to-be-selected tab
		if(document.getElementById(tab)){
			document.getElementById(tab).className = "sub_selected";	// turn the tab on!
		}
	}
	
	switch (pageName) {						// setting the pipes for certain links
		/* Account Activity */
		case "activity":
			document.getElementById("sub_econfirms_link").className = "";
			
			if (document.getElementById("sub_statements_link")) {
				document.getElementById("sub_statements_link").className = "";
			}
			
			if (document.getElementById("sub_tax_link")) {
				document.getElementById("sub_tax_link").className = "";
			}
			break;
		case "analysis":
			if (document.getElementById("sub_statements_link")) {
				document.getElementById("sub_statements_link").className = "";
			}
			
			if (document.getElementById("sub_tax_link")) {
				document.getElementById("sub_tax_link").className = "";
			}
			break;
		case "econfirms":
			document.getElementById("sub_analysis_link").className = "";
			if (document.getElementById("sub_tax_link")) {
				document.getElementById("sub_tax_link").className = "";
			}
			break;
		case "statements":
			document.getElementById("sub_analysis_link").className = "";
			document.getElementById("sub_econfirms_link").className = "";
			break;
		case "tax":
			document.getElementById("sub_analysis_link").className = "";
			document.getElementById("sub_econfirms_link").className = "";
			document.getElementById("sub_statements_link").className = "";
			break;
		/* Transfer Funds */
		case "request":				// New Request
			if(document.getElementById("sub_setup_link")){
				document.getElementById("sub_setup_link").className = "";
				document.getElementById("sub_pending_link").className = "first";
				if (document.getElementById("sub_chase_link")){
					document.getElementById("sub_chase_link").className = "";
				}
			}
			break;
		case "setup":				// Bank Information
			if(document.getElementById("sub_pending_link")){
				document.getElementById("sub_pending_link").className = "";
				document.getElementById("sub_setup_link").className = "first";
				if (document.getElementById("sub_chase_link")){
					document.getElementById("sub_chase_link").className = "first";
				}
			}
			break;
		case "pending":				// requests in progress
			if(document.getElementById("sub_pending_link")){
				document.getElementById("sub_request_link").className = "first";
				document.getElementById("sub_setup_link").className = "first";
				if (document.getElementById("sub_chase_link")){				
					document.getElementById("sub_chase_link").className = "";
				}
				document.getElementById("sub_pending_link").className = "first";
			}
			break;
		case "chase":				// visa rewards page
			if(document.getElementById("sub_chase_link")){
				document.getElementById("sub_request_link").className = "first";
				document.getElementById("sub_setup_link").className = "";
				document.getElementById("sub_pending_link").className = "";
				document.getElementById("sub_chase_link").className = "first";
			}
			break;
		/* Trade */
		case "spread":
			switch (document.frmTrade.txtSecTypeID.value) {
				case "3":			// Spread
					document.getElementById("sub_straddle_link").className = "";
					document.getElementById("sub_butterfly_link").className = "";
					document.getElementById("sub_condor_link").className = "";
					document.getElementById("sub_oco_link").className = "";					
					break;
				case "10":			// Combo
					document.getElementById("sub_butterfly_link").className = "";
					document.getElementById("sub_condor_link").className = "";
					document.getElementById("sub_oco_link").className = "";	
					break;
				case "5":			// Straddle
					document.getElementById("sub_combo_link").className = "";
					document.getElementById("sub_condor_link").className = "";
					document.getElementById("sub_oco_link").className = "";	
					break;
				case "8":			// Butterfly
					document.getElementById("sub_combo_link").className = "";
					document.getElementById("sub_straddle_link").className = "";
					document.getElementById("sub_oco_link").className = "";						
					break;
				case "11":			// Condor
					document.getElementById("sub_combo_link").className = "";
					document.getElementById("sub_straddle_link").className = "";
					document.getElementById("sub_butterfly_link").className = "";				
				break;
				case "12":			// OCO
					document.getElementById("sub_combo_link").className = "";
					document.getElementById("sub_straddle_link").className = "";
					document.getElementById("sub_butterfly_link").className = "";
				break;				
				default:
					break;
			}
			break;
		case "covered_call":
			switch (document.frmTrade.txtSecTypeID.value) {
				case "4":			// Covered Call
					document.getElementById("sub_collar_link").className = "";
					break;
				case "9":			// Collar
					document.getElementById("sub_protective_put_link").className = "";
					break;
				default:
					break;
			}
			break;
		/* Quotes > Charts */
		case "snap":
			if ( document.getElementById("sub_volatility_link") != null){
			document.getElementById("sub_volatility_link").className = "";
			}
			break;
		case "volatility":
			document.getElementById("sub_java_link").className = "";
			break;
		default:
			break;
	}
}

//SB 030706 DT 10047
function checkPhone(ctrl1,ctrl2,ctrl3){
	var phone1;
	var phone2;
	var phone3;
	phone1 = ctrl1.value;
	phone2 = ctrl2.value;
	phone3 = ctrl3.value;
	if(!isValidPhone(phone1,phone2,phone3)){
		return(false);
	}
	return(true);
}

function isValidPhone(p1,p2,p3){
	if ((p1.length!=3)||(p2.length!=3)||(p3.length!=4)) {
		return(false);		
	}	
	if ((!isInteger(p1)) || (!isInteger(p2)) ||(!isInteger(p3))){
		return(false);
	}
	return(true);
}
//SB 032106 moved from newaccount general.js 
function moveTab(theControl){
	
	if (theControl.value.length==theControl.maxLength){
		if (theControl.id=='txtSSN1'){
			if (document.getElementById("txtSSN2")!=null) {
				document.getElementById("txtSSN2").focus();
			}
		}
		else if (theControl.id=='txtSSN2'){
			if (document.getElementById("txtSSN3")!=null) {
				document.getElementById("txtSSN3").focus(); 
			}
		}
		else if (theControl.id=='txtJointSSN1'){
			if (document.getElementById("txtJointSSN2")!=null) {
				document.getElementById("txtJointSSN2").focus();
			}
		}
		else if (theControl.id=='txtJointSSN2'){
			if (document.getElementById("txtJointSSN3")!=null) {
				document.getElementById("txtJointSSN3").focus(); 
			}
		}
		else if (theControl.id=='txtTaxID1'){
			if (document.getElementById("txtTaxID2")!=null) {
				document.getElementById("txtTaxID2").focus();
			}
		}
		else if (theControl.id=='txtDOB1'){
			if (document.getElementById("txtDOB2")!=null) {
				document.getElementById("txtDOB2").focus();
			}
		}
		else if (theControl.id=='txtDOB2'){
			if (document.getElementById("txtDOB3")!=null) {
				document.getElementById("txtDOB3").focus();
			}
		}
		else if (theControl.id=='txtJointDOB1'){
			if (document.getElementById("txtJointDOB2")!=null) {
				document.getElementById("txtJointDOB2").focus();
			}
		}
		else if (theControl.id=='txtJointDOB2'){
			if (document.getElementById("txtJointDOB3")!=null) {
				document.getElementById("txtJointDOB3").focus();
			}
		}
		else if (theControl.id=='txtDayPhone1'){
			if (document.getElementById("txtDayPhone2")!=null) {
				document.getElementById("txtDayPhone2").focus();
			}
		}
		else if (theControl.id=='txtDayPhone2'){
			if (document.getElementById("txtDayPhone3")!=null) {
				document.getElementById("txtDayPhone3").focus();
			}
		}
		else if (theControl.id=='txtEvePhone1'){
			if (document.getElementById("txtEvePhone2")!=null) {
				document.getElementById("txtEvePhone2").focus();
			}
		}
		else if (theControl.id=='txtEvePhone2'){
			if (document.getElementById("txtEvePhone3")!=null) {
				document.getElementById("txtEvePhone3").focus();
			}
		}
		else if (theControl.id=='txtFax1'){
			if (document.getElementById("txtFax2")!=null) {
				document.getElementById("txtFax2").focus();
			}
		}
		else if (theControl.id=='txtFax2'){
			if (document.getElementById("txtFax3")!=null) {
				document.getElementById("txtFax3").focus();
			}
		}
		else if (theControl.id=='txtEmployerPhone1'){
			if (document.getElementById("txtEmployerPhone2")!=null) {
				document.getElementById("txtEmployerPhone2").focus();
			}
		}
		else if (theControl.id=='txtEmployerPhone2'){
			if (document.getElementById("txtEmployerPhone3")!=null) {
				document.getElementById("txtEmployerPhone3").focus();
			}
		}
		else if (theControl.id=='txtMobilePhone1'){
			if (document.getElementById("txtMobilePhone2")!=null) {
				document.getElementById("txtMobilePhone2").focus();
			}
		}
		else if (theControl.id=='txtMobilePhone2'){
			if (document.getElementById("txtMobilePhone3")!=null) {
				document.getElementById("txtMobilePhone3").focus();
			}
		}
		else if (theControl.id=='txtJointDayPhone1'){
			if (document.getElementById("txtJointDayPhone2")!=null) {
				document.getElementById("txtJointDayPhone2").focus();
			}
		}
		else if (theControl.id=='txtJointDayPhone2'){
			if (document.getElementById("txtJointDayPhone3")!=null) {
				document.getElementById("txtJointDayPhone3").focus();
			}
		}
		else if (theControl.id=='txJointEmployerPhone1'){
			if (document.getElementById("txtJointEmployerPhone2")!=null) {
				document.getElementById("txtJointEmployerPhone2").focus();
			}
		}
		else if (theControl.id=='txtJointEmployerPhone2'){
			if (document.getElementById("txtJointEmployerPhone3")!=null) {
				document.getElementById("txtJointEmployerPhone3").focus();
			}
		}
		else if (theControl.id=='txtTrustDate1'){
			if (document.getElementById("txtTrustDate2")!=null) {
				document.getElementById("txtTrustDate2").focus();
			}
		}
		else if (theControl.id=='txtTrustDate2'){
			if (document.getElementById("txtTrustDate3")!=null) {
				document.getElementById("txtTrustDate3").focus();
			}
		}
		else if (theControl.id=='txtVerifySSN1'){
			if (document.frmNewAccnt.txtVerifySSN2!=null) {
				document.frmNewAccnt.txtVerifySSN2.focus();
			}
		}
		else if (theControl.id=='txtVerifySSN2'){
			if (document.frmNewAccnt.txtVerifySSN3!=null) {
				document.frmNewAccnt.txtVerifySSN3.focus(); 
			}
		}
		else if (theControl.id=='txtVerifyJointSSN1'){
			if (document.frmNewAccnt.txtVerifyJointSSN2!=null) {
				document.frmNewAccnt.txtVerifyJointSSN2.focus();
			}
		}
		else if (theControl.id=='txtVerifyJointSSN2'){
			if (document.frmNewAccnt.txtVerifyJointSSN3!=null) {
				document.frmNewAccnt.txtVerifyJointSSN3.focus(); 
			}
		}
	
	}
}

//DM - 3/28/06 - Code to hide links in OXI header
function hideOxiLink(){
	var f=getFirmType();
	//alert(f);
	if(f=='OXI'){
		var m = document.getElementById("menu");
		var lis = m.getElementsByTagName("LI");
		var hLI = lis.length;
		for(var i=0;i<hLI;i++){
			if(lis[i].id.indexOf('oxiHide')!=-1){ //SV 5/15/07 hides coaching link for OXI
				lis[i].style.display='none';
			}
		}
	}
	if (navigator.appVersion.indexOf('Mac') != -1){
		if(document.getElementById('searchL')){
	 	 document.getElementById('searchL').style.display='none';
	  	 document.getElementById('searchR').style.display='none';
	  	 document.getElementById('qt').style.background='none';	 
	  	 document.getElementById('qt').style.border='1px solid silver';	 
		 }
	}
	randomSearch();
}

function randomSearch(){
	var f=getFirmType();
	var sID = GetSessionID();
	var rNumber;
	
	searchQ = new Array();
	searchQ[0]="Account Transfers"
	searchQ[1]="Do you have load funds?"
	searchQ[2]="How do I wire funds?"
	searchQ[3]="Can I set up ACH?"
	searchQ[4]="Can I trade futures?"
	searchQ[5]="What is Xtrends?"
	searchQ[6]="How do I fund my account?"
	searchQ[7]="What are Chart Patterns?"	
	searchQ[8]="Money Market Interest Rate"
	searchQ[9]="I want to learn about ETFs"
	searchQ[10]="Account minimums and fees"
	searchQ[11]="Can I cross margin futures?"
	searchQ[12]="Do options trade after hours?"

	if(f=='OX' || f=='BX'){
		searchQ[13]="Can I trade options in IRA?";
		rNumber = Math.floor(Math.random()*14);
		if(sID=='0'){
			searchQ[14]="How do I open an account?";
			rNumber = Math.floor(Math.random()*15);
		}
	}
	else{
		if(sID=='0'){
			searchQ[13]="How do I open an account?";
			rNumber = Math.floor(Math.random()*14);
		}
		else{
			rNumber = Math.floor(Math.random()*13);
		}
	}
	
	if(document.getElementById('qt')){
		document.getElementById('qt').value = searchQ[rNumber];
	}
}

// DS : 14176 : 3/30/2006
function SetCheckboxValue(checkbox){	
	if (checkbox!=null){
		if(checkbox.checked==true){
			checkbox.value="ON";
		}
		else{
			checkbox.value="OFF";
		}
	}
}

function OpenAlertManager(sSource,sSymbol1,sSymbol2)
{
	var s = GetSessionID();
	
	if (sSymbol1 == undefined) sSymbol1 = "";
	if (sSymbol2 == undefined) sSymbol2 = "";
	
	OpenChildWindowSizeable("/OXNetTools/AlertManager/set_up.aspx?SessionID=" + s + "&REQUEST_SOURCE=" + sSource + "&Symbol=" + sSymbol1 + "&ComboSymbol=" + sSymbol2, 'AlertManager', '650', '600');
}	


//*****************************FUNCTIONS USED BY WATCHLIST****************************


// EA : 15691 : 06/23/2006
function StripIllegalWatchChars(sQueryStr){
	sQueryStr=StrReplace(sQueryStr,"`","");
	sQueryStr=StrReplace(sQueryStr,"~","");
	sQueryStr=StrReplace(sQueryStr,"!","");
	sQueryStr=StrReplace(sQueryStr,"@","");
	sQueryStr=StrReplace(sQueryStr,"#","");
	sQueryStr=StrReplace(sQueryStr,"$","");
	sQueryStr=StrReplace(sQueryStr,"%","");
	sQueryStr=StrReplace(sQueryStr,"^","");

	sQueryStr=StrReplace(sQueryStr,"|","");
	
	sQueryStr=StrReplace(sQueryStr,";","");
	sQueryStr=StrReplace(sQueryStr,":","");
	sQueryStr=StrReplace(sQueryStr,"\'","");
	sQueryStr=StrReplace(sQueryStr,"\"","");
	
	// sQueryStr=StrReplace(sQueryStr,",","");
	sQueryStr=StrReplace(sQueryStr,"<","");
	sQueryStr=StrReplace(sQueryStr,">","");
	// sQueryStr=StrReplace(sQueryStr,".","");
	// sQueryStr=StrReplace(sQueryStr,"/","");

	return(sQueryStr);
}

// EA : 15691 : 06/23/2006
function ChangeSubmit()
{
document.frmWatchList.RefID.value="VIEW";
document.frmWatchList.submit();
}

// EA : 15691 : 06/23/2006
function SetDefault()
{
var s;
s=GetSessionID();
alert(s);
document.frmWatchList.RefID.value="DEFAULT";
document.frmWatchList.action="/quote_watch_list.asp?RefID=Default&SessionID="+s+"";
window.alert("This has been set as your default WatchList."); 
document.frmWatchList.submit();
}

// EA : 15691 : 06/23/2006
function ChangeOrderBy(sCtlName,sFromAutoRefresh){	
	if(sFromAutoRefresh != true)
	{ 	
		if (sCtlName.value=="DESC"){
			sCtlName.value="ASC";
		}
		else {
			sCtlName.value="DESC";		
		}
	}
	document.frmWatchList.txtSortSymbol.value="true";
	document.frmWatchList.RefID.value = "VIEW";
	ProcessAccntSel(document.frmWatchList);
	return;
}

// EA : 15691 : 06/23/2006
function SubmitValue(sValue,sSubValue)
{	
	var sNameLength,sname;
	
	
	if (sValue == "DELETE")
	{		
		if (!confirm("Are you sure you want to delete this Watchlist?")) 			
			return ;
	}
	if (document.frmWatchList.ID.value =="CREATE_NEW")
	{		
	sName = document.frmWatchList.lstWatch.value;  		
	if(sName.indexOf('#') >= 0)
	{
		PromptFocus(document.frmWatchList.lstWatch,"Please do not enter # character in the watch list name.");
		return;	 
	}	
	sNameLength= sName.length; 	
	if(sNameLength > 15 )
		{			
			document.frmWatchList.lstWatch.value =  document.frmWatchList.lstWatch.value.substring(0,15);
		}
	if (!LstToString())
		return;	
	document.frmWatchList.RefID.value = "NEW";
	if (document.frmWatchList.lstWatch.value == "")
		{
		PromptFocus(document.frmWatchList.lstWatch,"Please enter a Watchlist name.");
		return;
		}
	}
	else
	document.frmWatchList.RefID.value = sValue;
	
	if (sValue == "ADD")
	{
		if(!ValidateDataAllowBlank(document.frmWatchList.txtWatchSymbol[0].value,document.frmWatchList.txtWatchSymbol[0] )) {		
			return false;
		}

		if(!ValidateDataAllowBlank(document.frmWatchList.txtWatchSymbol[1].value,document.frmWatchList.txtWatchSymbol[1] )) {		
			return false;
		}
	}

	if (document.frmWatchList.txtWatchSymbol[1].value == document.frmWatchList.txtWatchSymbol[0].value)
		document.frmWatchList.txtWatchSymbol[1].value="";
	document.frmWatchList.txtWatchSymbol[0].value = StrReplace(document.frmWatchList.txtWatchSymbol[0].value,"'","",true);
	document.frmWatchList.txtWatchSymbol[1].value = StrReplace(document.frmWatchList.txtWatchSymbol[1].value,"'","",true);	
	document.frmWatchList.txtWatchSymbol[2].value = StrReplace(document.frmWatchList.txtWatchSymbol[2].value,"'","",true);
	document.frmWatchList.txtWatchSymbol[0].value = StripIllegalChars(document.frmWatchList.txtWatchSymbol[0].value);
	document.frmWatchList.txtWatchSymbol[1].value = StripIllegalChars(document.frmWatchList.txtWatchSymbol[1].value);
	document.frmWatchList.txtWatchSymbol[2].value = StripIllegalWatchChars(document.frmWatchList.txtWatchSymbol[2].value);	
	document.frmWatchList.RefSubID.value = sSubValue;		
	document.frmWatchList.submit();

}

// EA : 15691 : 06/23/2006
function Edit()
{
	var sUrl,s;
	s=GetSessionID();
	sUrl = '/quote_watch_list.asp?RefID=Edit&sessionid='+s+'';
	OpenChildWindow(sUrl,'','350','350');
}

// EA : 15691 : 06/23/2006
function DuplicateExists()
{
	var sLstValue,aLstValue;	
	sLstValue=document.frmWatchList.hidStkOptValues.value;
	aLstValue=sLstValue.split(",");		
	for (var i=0; i<aLstValue.length; i++)
		{		
		window.alert(document.frmWatchList.radContract1.value);
		if (document.frmWatchList.radContract1.value !="S")
		{
		if(document.frmWatchList.txtSymbol1.value == aLstValue[i] ) 	
			{
			alarm="true";
			PromptFocus(document.frmWatchList.txtSymbol1,aLstValue[i] + " exists in your present Watchlist.");			
			return true;
			}
		else
			{alarm="false";}
		}
		window.alert(document.frmWatchList.radContract2.value);
		if (document.frmWatchList.radContract2.value !="S")
		{
		if(document.frmWatchList.txtSymbol2.value == aLstValue[i] ) 	
			{
			alarm="true";
			PromptFocus(document.frmWatchList.txtSymbol2,aLstValue[i] + " exists in your present Watchlist.");
			return true;
			}
		else
			{alarm="false";}		
		
		}
		}				
		return false;
}

// EA : 15691 : 06/23/2006
function LstToString()
	{	
	if (document.frmWatchList.ID.value=="CREATE_NEW")
	{		
	var sLstValue,i;
	var aLstValue;
	sLstValue=document.frmWatchList.hiddenLst.value;
	aLstValue=sLstValue.split(",");	
	var alarm;
	if(document.frmWatchList.lstWatch.value == "") 	
		{
		window.alert("Enter new WatchList Name !");
		document.frmWatchList.lstWatch.focus();				
		alarm="true";
		return false;
		}		
	else
		{
		for (var i=0; i<aLstValue.length; i++)
		{
		if(document.frmWatchList.lstWatch.value == aLstValue[i] ) 	
			{
			alarm="true";
			break;
			}
		else
			{alarm="false";}
		
		}			
		if (alarm=="false")
		{	
   			
			if (document.frmWatchList.ID.value !="CREATE_NEW")
				document.frmWatchList.submit();
   			return true;
   		}
   		else 
   		{   		
   			window.alert("A watchlist with this name already exists.  Please choose another.");      					
   			document.frmWatchList.lstWatch.focus();
   			document.frmWatchList.lstWatch.value="";
   			return false;
		}
		
		}	
	
	}
	else
		{			
			if (document.frmWatchList.ID.value !="CREATE_NEW")
				document.frmWatchList.submit();
			return true;
		}
	}


// EA : 15691 : 06/23/2006
function CheckAutoReload()
{
document.frmWatchList.RefID.value="AUTO-REFRESH";
document.frmWatchList.DIRTY.value="ON";
if(document.frmWatchList.chkAutoReload.checked==true)
	document.frmWatchList.chkAutoReload.value="ON";
else
	document.frmWatchList.chkAutoReload.value="OFF";
//document.frmWatchList.submit();
ChangeOrderBy(document.frmWatchList.txtSymbol,true);

}


// EA : 15691 : 06/23/2006
function CheckMe()
{	
	if (document.frmWatchList.chkAutoReload.checked==true){
		InitializeTimer();
		return;
	}
	else {
		StopTheClock();
		return;
	}
}


// EA : 15691 : 06/23/2006
function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 30;
    StopTheClock();
    StartTheTimer();
    return;
}




// EA : 15691 : 06/23/2006
function StopTheClock()
{
    if(timerRunning){
        clearTimeout(timerID);
		timerRunning = false;
	}
	return;
}

// EA : 15691 : 06/23/2006
function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock();
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
         document.frmWatchList.RefID.value="AUTO-REFRESH";
		 ChangeOrderBy(document.frmWatchList.txtSymbol,true);
    }
    else
    {
        self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
    return;
}

// EA : 15691 : 06/23/2006
function LookUp(sFrmName,sCtrlName,sSessionID)
{
var sValue,sRefresh;
if (document.frmWatchList.ID.value =="CREATE_NEW")
	sRefresh="NEW";
else
	sRefresh="REFRESH";
sValue=document.frmWatchList.lstWatch.value;
sValue="RefID="+sRefresh+"|lstWatch="+sValue;
if (sRefresh=="NEW")
	OpenMiniChain(sFrmName,sCtrlName,sSessionID,'txtWatchSymbol[0]',0,0,"RefID","VIEW","Add");
else
	{
	if (document.frmWatchList.txtWatchSymbol[1].value == "")
		OpenMiniChain(sFrmName,sCtrlName,sSessionID,'txtWatchSymbol[0]',0,1,"RefID","VIEW","Add");	
	else
		OpenMiniChain(sFrmName,sCtrlName,sSessionID,null,0,1,"RefID","VIEW","Add");	
	}
}

// EA : 15691 : 06/23/2006
function NotesSpread(sWatchID,sComboWatchID,sSymbol,sComboSymbol) 
{
var s;
s=GetSessionID();
OpenChildWindow('/quote_watch_list.asp?RefID=NOTES_REQUEST&RefSubID=SPREAD&txtSymbol='+sSymbol+'&txtComboSymbol='+sComboSymbol+'&SecWatchID='+sWatchID+'&SecWatchID1='+sComboWatchID+'&SessionID='+s,'','350','250');
}

// EA : 15691 : 06/23/2006
function Notes(sWatchID,sSymbol)
{
var s;
s=GetSessionID();
OpenChildWindow('/quote_watch_list.asp?RefID=NOTES_REQUEST&txtSymbol='+sSymbol+'&SecWatchID='+sWatchID+'&SessionID='+s,'','350','250');
}

// EA : 15691 : 06/23/2006
function Alert(sWatchID,sSymbol)
{
var s;
s=GetSessionID();
OpenChildWindow('/quote_watch_list.asp?RefID=ALERT_REQUEST&txtSymbol='+sSymbol+'&SecWatchID='+sWatchID+'&SessionID='+s+'&txtAccountWatchID='+document.frmWatchList.txtAccountWatchID.value+'&txtWatchListName='+document.frmWatchList.lstWatch[document.frmWatchList.lstWatch.selectedIndex].text,'','800','475');
}

// EA : 15691 : 06/23/2006
function AlertSpread(sWatchID,sComboWatchID,sSymbol,sComboSymbol) 
{
var s;
s=GetSessionID();
OpenChildWindow('/quote_watch_list.asp?RefID=ALERT_REQUEST&RefSubID=SPREAD&txtSymbol='+sSymbol+'&txtComboSymbol='+sComboSymbol+'&SecWatchID='+sWatchID+'&SecWatchID1='+sComboWatchID+'&SessionID='+s+'&txtAccountWatchID='+document.frmWatchList.txtAccountWatchID.value+'&txtWatchListName='+document.frmWatchList.lstWatch[document.frmWatchList.lstWatch.selectedIndex].text,'','800','475');
}

// EA : 15691 : 06/23/2006
function Delete(sWatchID)
{
document.frmWatchList.RefID.value="DELETE";
document.frmWatchList.RefSubID.value="ITEM";
document.frmWatchList.SecWatchID.value=sWatchID;
document.frmWatchList.submit();
}

// EA : 15691 : 06/23/2006
function DeleteSpread(sWatchID1,sWatchID2,sStrategyID)
{
document.frmWatchList.RefID.value="DELETE";
document.frmWatchList.RefSubID.value="ROW"
document.frmWatchList.SecWatchID.value=sWatchID1;
document.frmWatchList.SecWatchID1.value=sWatchID2;
document.frmWatchList.StrategyWatchID.value=sStrategyID;
document.frmWatchList.submit();
}

// EA : 15691 : 06/23/2006
function VerifyCheckBoxes()
{
 SetButtonToCheckboxes(document.frmWatchList.hidWatchIDList.value,"chk","document.frmWatchList","cmdDelete","chkAll")
}

// EA : 15691 : 06/23/2006
function SelectAll()
{
 MatchCheckboxesToMaster(document.frmWatchList.hidWatchIDList.value,"chk","document.frmWatchList","chkAll");
 VerifyCheckBoxes();
}

// EA : 15691 : 06/23/2006
function AddMultiple()
{

var nWatchID,sWatchListName,s;
s=GetSessionID();

if(document.frmWatchList.lstWatch.value == null){
	nWatchID = 0;
	sWatchListName = "";		
}
else{
	nWatchID = document.frmWatchList.lstWatch.value; 
	if (nWatchID == "") 
	{ 
		nWatchID = 0;
		sWatchListName = "";
	}
	else
	{
		sWatchListName = document.frmWatchList.lstWatch[document.frmWatchList.lstWatch.selectedIndex].text;
	}
}
OpenChildWindow('quote_watch_list.asp?RefID=ADD_MULTIPLE&ViewType=MULTIPLE&SessionID='+s+'&lstWatch='+nWatchID+'&txtWatchListName='+sWatchListName,'','450','350');
}

// EA : 15691 : 06/23/2006
function Rename()
{
	var sUrl,s;
	var nWatchID;
	s=GetSessionID();
	
	if(document.frmWatchList.txtAccountWatchID == null){
		nWatchID = 0;	
	}
	else{
		nWatchID = document.frmWatchList.txtAccountWatchID.value; 
	}
	sUrl = '/quote_watch_list.asp?RefID=RENAME&sessionid='+s+'&WatchID=' + nWatchID;
//	window.alert(sUrl);
	OpenChildWindow(sUrl,'','350','350');
}

//*****************************************************************************************

//SB : DT 21479 10/06/2006 Postal code validation. Used by all broker edit pages for 
//     different postal codes

var sDomesticMsg = new String();				
function validatePostalCode(objZip,nCountryID,sDomMsg){
	var sZip;
	var nInd;
	sZip=objZip.value.substring(0, 5);
		
	if(objZip.value == ""){
		if(nCountryID == 1){
			sDomMsg.value = "\n Correct Format : ##### OR #####-####";
		}
		else if(nCountryID == 43){
			sDomMsg.value = "\n Correct Format : ANANAN OR ANA NAN (A=Alphabet N=Number)";
		}
		else{
			sDomMsg.value = "";
		}
		return(false);
	}
	if(nCountryID == 1){	
		if (!isInteger(sZip) || objZip.value.length<5) {
			sDomMsg.value = "\n Correct Format : ##### OR #####-####";
			return(false);
		}
		if(objZip.value.length>5){
			if(objZip.value.length == 10){	
				sZip=objZip.value.substring(5, 6);
				if(sZip != "-"){
					sDomMsg.value = "\n Correct Format : ##### OR #####-####";
					return(false);
				}
				else {
					sZip=objZip.value.substring(6, 10);
					if (!isInteger(sZip) || sZip.length != 4) {
						sDomMsg.value = "\n Correct Format : ##### OR #####-####";
						return(false);
					}
				}
			}
			else{
				sDomMsg.value = "\n Correct Format : ##### OR #####-####";
				return(false);
			}
		}
	}
	if(nCountryID == 43){
		if (objZip.value.length != 6 && objZip.value.length != 7) {
			sDomMsg.value = "\n Correct Format : ANANAN OR ANA NAN (A=Alphabet N=Number)";
			return(false);
		}
		else{
			if(objZip.value.length == 7){
				if(objZip.value.substring(3,4) != " "){
					sDomMsg.value = "\n Correct Format : ANANAN OR ANA NAN (A=Alphabet N=Number)";
					return(false);
				}
				else{
					objZip.value = objZip.value.substring(0,3) + objZip.value.substring(4,7);
				}
			}
			for(nInd = 0; nInd < objZip.value.length; nInd++){
				sZip = objZip.value.substring(nInd, nInd+1);
				if((nInd+1) % 2 == 0){
					if(!isInteger(sZip)){
						sDomMsg.value = "\n Correct Format : ANANAN OR ANA NAN (A=Alphabet N=Number)";
						return(false);				
					}
				}
				else{
					if ((sZip < 'a' || sZip > 'z') && (sZip < 'A' || sZip > 'Z') ) {
						sDomMsg.value = "\n Correct Format : ANANAN OR ANA NAN (A=Alphabet N=Number)";
						return(false);					
					}
				}
			}
		}
	}
	return(true);
}

//SB DT 21163

function resetAuthorizedTraderData(frmObj){
	frmObj.lstAPAType.value = "-1";
	frmObj.txtFirstNameAuthorization.value = "";	
	frmObj.txtLastNameAuthorization.value = "";
}

function noErrorMessages(){
	return true;
}
//DM - 11/7/06 DT 21902 - change stylesheet functions for font and browser size
if(window.opener){
    window.onerror = noErrorMessages;
	if(window.opener.parent.frames[0].document.getElementById('spSiteStyleColor')){
		if(window.opener.parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0]){
			if(window.opener.parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0].nodeValue!='' || window.opener.parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0].nodeValue!=null){
				var mySize = window.opener.parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0].nodeValue;
				setStylesheet(mySize);
				//alert('popup');
			}		
		}		
	}
}

function checkFont(val){
	if (getCookie('oxps_sizing')) {
		document.cookie = 'oxps_sizing' + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	if (getCookie('oxps_font')) {
		document.cookie = 'oxps_font' + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	if (getCookie('oxps_color')) {
		document.cookie = 'oxps_color' + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	
	if(val=='quote'){
		if(document.getElementById('spSiteStyleFontSize')){
			if(document.getElementById('spSiteStyleFontSize').childNodes[0]){
				if(document.getElementById('spSiteStyleFontSize').childNodes[0].nodeValue!='' || document.getElementById('spSiteStyleFontSize').childNodes[0].nodeValue!=null){
					var myFont = document.getElementById('spSiteStyleFontSize').childNodes[0].nodeValue;
					setStylesheet(myFont);
				}		
			}
		}		
	checkColor(val);
	}
	else{
		if(parent.frames[0]){
			if(parent.frames[0].document.getElementById('spSiteStyleFontSize')){
				if(parent.frames[0].document.getElementById('spSiteStyleFontSize').childNodes[0]){
					if(parent.frames[0].document.getElementById('spSiteStyleFontSize').childNodes[0].nodeValue!='' || parent.frames[0].document.getElementById('spSiteStyleFontSize').childNodes[0].nodeValue!=null){
						var myFont = parent.frames[0].document.getElementById('spSiteStyleFontSize').childNodes[0].nodeValue;
						setStylesheet(myFont);
					}		
				}
			}
		checkColor();
		}
	}
}

function checkColor(val){
	if(val=='quote'){
		if(document.getElementById('spSiteStyleColor')){
			if(document.getElementById('spSiteStyleColor').childNodes[0]){
				if(document.getElementById('spSiteStyleColor').childNodes[0].nodeValue!='' || document.getElementById('spSiteStyleColor').childNodes[0].nodeValue!=null){
					var myColor = document.getElementById('spSiteStyleColor').childNodes[0].nodeValue;
					setStylesheet(myColor);
				}		
			}	
		}
		resize(val);		
	}
	else{
		if(parent.frames[0]){	
			if(parent.frames[0].document.getElementById('spSiteStyleColor')){
				if(parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0]){
					if(parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0].nodeValue!='' || parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0].nodeValue!=null){
						var myColor = parent.frames[0].document.getElementById('spSiteStyleColor').childNodes[0].nodeValue;
						setStylesheet(myColor);
					}		
				}	
			}
		resize();
		}
	}
}

function resize(val){
	if(val=='quote'){
		if(document.getElementById('spSiteStyleAlignment')){
			if(document.getElementById('spSiteStyleAlignment').childNodes[0]){
				if(document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue!='' || document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue!=null){
					var mySize = document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue;
					setStylesheet(mySize);
				}		
			}		
		}	
	}
	else{
		if(parent.frames[0]){	
			if(parent.frames[0].document.getElementById('spSiteStyleAlignment')){
				if(parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0]){
					if(parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue!='' || parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue!=null){
						var mySize = parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue;
						setStylesheet(mySize);
					}		
				}		
			}
		resizeHeader();
		}
	}
}

function styleTab(){  //writes element to frameset file so we can detect and display "site layout" tab after reload
	var d = parent.document.createElement('div'); 
    d.id = 'prefs'; 
	var el = parent.document.getElementsByTagName('noframes');
	if(el[0]){
	    el[0].parentNode.appendChild(d); 	
	}
}

function setStylesheet(styleTitle){
	if(document.location.href && document.location.href.indexOf('broker_view')==-1){ //don't apply styles to web broker
		if(document.getElementsByTagName('STYLE')){
			var s = document.getElementsByTagName('STYLE'); 
			if(s[0]){
				newStyle=document.createElement('Link');
				newStyle.rel="stylesheet";
				newStyle.type="text/css";
				newStyle.href="/inc/"+styleTitle+".css";
				s[0].parentNode.appendChild(newStyle);
			}
		}
	}
}

//dm - 9/22/06 - resize headers based on page width
function resizeHeader(){
if(!document.getElementById('txtOXWebServer') || document.getElementById('txtOXWebServer')==null){
	if(document.getElementById('mainTable')){
		var a = document.getElementById('mainTable');
		var mt = parseInt(a.scrollWidth);
		var lmt = parseInt(a.offsetLeft);
	}
	if(document.getElementById('content')){	
		var b = document.getElementById('content').clientWidth;
	}

	subArray = new Array();
	subArray[0] = "welcome";
	subArray[1] = "account";
	subArray[2] = "trade";
	subArray[3] = "quotes";
	subArray[4] = "toolbox";
	subArray[5] = "educate";
	subArray[6] = "help";
	
	if(document.getElementById('sidebar')){
		var c = document.getElementById('sidebar').clientWidth;
		var x = b+c;
	}
	else{
		var x = b;
	}
	
	if(parent.frames[0]){	
		if(parent.frames[0].document.getElementById('spSiteStyleAlignment')){
			if(parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0]){
				if(parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue!='' || parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue!=null){
					var cSize = parent.frames[0].document.getElementById('spSiteStyleAlignment').childNodes[0].nodeValue;
				}		
			}		
		}
	}
	if(cSize){
		if(cSize.indexOf('_sm')!=-1 && x >=700){
			var smResize = true;
		}
	}

	if(x >= 835 || smResize == true){ 
		var y = document.body.clientWidth;
		document.getElementById('header_table').style.width = x+'px';	
	
		document.getElementById('header_wrapper').style.width = x+'px';	

		for(i=0;i<subArray.length;i++){
			document.getElementById('sub_'+subArray[i]).style.width = x-13+'px';
		}
		if(document.getElementById('footer')){
			document.getElementById('footer').style.width = x+'px';
		}
		if(document.getElementById('Footer')){
			document.getElementById('Footer').style.width = x +'px';	
		}
		document.getElementById('mainTable').style.width = x +'px';
	}
}
}

//DS : 22238 : 12/8/2006
function textCounter(sMsg,sTxtCounter,nCharsLimit) {
	if (sMsg.value.length > nCharsLimit) 
		sMsg.value = sMsg.value.substring(0, nCharsLimit);
	else 
		sTxtCounter.value = nCharsLimit - sMsg.value.length;
}

//SV 12/19/06 DT# 22574 Hides "ready to switch" link in BX header when user is logged in.
function hideReadyLink(newClass){
	var s = GetSessionID();
	if (s == '0') {
		 document.getElementById('ready').style.display="inline";	
	 } else {	 
		 document.getElementById('ready').style.display="none";
		 document.getElementById('advantageLink').className=newClass;
	}
}

//SB 05/14/2007 Account number validation at different places
function ValidateAccountNum(txtAccountNum,txtPrevAccntNum){
	var sAccountNum = txtAccountNum.value;
	var sPrevAccountNum = txtPrevAccntNum.value;
	if(sAccountNum == ""){
		PromptFocus(txtAccountNum,"Account Number cannot be empty");
		return false;
	}
	if(sAccountNum != "pending" && sAccountNum != "w broker"){
		if(txtAccountNum.value.length != 9){
			PromptFocus(txtAccountNum,"Account Number must be exactly 9 characters long");
			return false;		
		}
	}
	if(sAccountNum != sPrevAccountNum){
		if ((confirm("Please confirm the following:\nThe new account number must already be updated at Phase3.\nNo other fields can be changed if account number is changed.\nClick 'Cancel' to undo Account Number change. Click 'OK' to continue"))!=true){
			txtAccountNum.select();
			txtAccountNum.focus();
			txtAccountNum.value = document.frmBrokerCustomerEdit.txtPrevAccntNum.value;
			return(false);	
		}

	}
	return(true);
}