var userIsLogin = false;
var cbolWin;
function checklogin() {
	
	var LoginStatusnon = "ssoSESSIONNONS" + "=";
	var LoginStatus = "ssoSESSION" + "=";
	var CookieValuenon = getcookie(LoginStatusnon);
	var CookieValue = getcookie(LoginStatus);

	var isNav = (navigator.appName == 'Netscape')
	var is_getElementById   = (document.getElementById) ? true : false;
	var isNav6 = isNav && is_getElementById;
	var bV=parseInt(navigator.appVersion);
	var NS4=(document.layers) ? true : false;
	var IE4=((document.all)&&(bV>=4))?true:false;


		if ( location.hostname == "fa.smithbarney.com" )
		{
			var Login_on = '<a href="https://www.smithbarney.com/cgi-bin/login/checklogout.cgi" target="_top"><span class="amtplus">Log On</span></a>';
		}
		else
		{

			var Login_on = '<a href="/cgi-bin/login/login.cgi" target="_top"><span class="amtplus">Log On</span></a>';
		}


		var Login_off = '<a href="javascript:SBlogoff();" target="_self"><span class="amtminus">Log Off</span></a>';


	var specialDomain1 = "www.cboe.com";
	var specialDomain2 = "prosearch.mycititrade.telescan.com";
	var specialDomain3 = "www.mastercard.com";

	var currentLocation = window.location.toString().toLowerCase();
	if (currentLocation.indexOf(specialDomain1.toLowerCase())!= -1) {
		
	} else if (currentLocation.indexOf(specialDomain3.toLowerCase())!= -1) {
		
	} else if (currentLocation.indexOf(specialDomain2.toLowerCase())!=-1) {
		
		if (NS4) {
			document.layers["headlinksDiv"].document.write(Login_off);
		} else {
			document.write(Login_off);
		}
		userIsLogin = true;

	} else {

		if ((CookieValue.toLowerCase() == "logout") || (CookieValuenon.toLowerCase() == "logout")) {

			if (NS4) {
				document.layers["headlinksDiv"].document.write(Login_on);
			} else {
				document.write( Login_on );
			}
			userIsLogin = false;

		} else if ((CookieValue == "empty") && (CookieValuenon == "empty")) {

			if (NS4) {
				document.layers["headlinksDiv"].document.write(Login_on);
			} else {
				document.write( Login_on );
			}
			userIsLogin = false;

		} else {

			if (NS4) {
				document.layers["headlinksDiv"].document.write(Login_off);
			} else {
				document.write(Login_off);
			}
			userIsLogin = true;

		}
	}
}


function getcookie(in_cookiename) {
	var objCookies = document.cookie;
	var pos = objCookies.indexOf(in_cookiename);
	var begin = pos + in_cookiename.length;
	var end = objCookies.indexOf(";", begin);
	if (end  == -1) end= objCookies.length;
	var tempvalue = unescape(objCookies.substring(begin,end));
	if (pos == -1)  tempvalue = 'empty';
	return tempvalue;
}


if ( typeof core_user == "undefined" )
{
	var core_user = false;
	
	if( getcookie('CORE_CTX'))
	{
		var core_ctx = getcookie("CORE_CTX");

		if ( core_ctx != null && core_ctx != "" && core_ctx != "empty" )
		{ core_user = true; }
		else
		{
			if (getcookie('BRAND_CTX')) 
			{ 
				if(getcookie('BRAND_CTX').indexOf('MSSB')!= -1) 
				{ core_user = true; } 
			}
		}
	}
	else
	{
		if (getcookie('BRAND_CTX')) 
		{ 
			if(getcookie('BRAND_CTX').indexOf('MSSB')!= -1) 
			{ core_user = true; } 
		}
	}
}

if ( typeof cbol_user == "undefined" )
{
	var cbol_user = false;
	var cis_ctx = getcookie("CIS_CTX");
	var cbol_bc = getcookie("CBOLBreadcrumbs");
	var cis_exists = false;
	var cbolbc_exists = false;

	if ( cis_ctx != null && cis_ctx != "" && cis_ctx != "empty" )
	{
		if ( cbol_bc != null && cbol_bc != "" && cbol_bc != "empty" )
		{
			cis_exists = true;
			cbolbc_exists = true;
			cbol_user = true;
		}
		else
		{
			cis_exists = true;
			cbolbc_exists = false;
		}
	}
}

if ( typeof fls_user == "undefined" )
{
	var fls_user = false;
	
	if( getcookie('FLS_CTX'))
	{
		var fls_ctx = getcookie('FLS_CTX');

		if ( fls_ctx != null && fls_ctx != "" && fls_ctx != "empty" )
		{ 
			if (getcookie('BRAND_CTX')) 
			{ 
				if(getcookie('BRAND_CTX').indexOf('MyFi')!= -1 || getcookie('BRAND_CTX').indexOf('Citi')!= -1 ) 
				{ fls_user = true; } 
			}
		}
		else
		{
			if (getcookie('BRAND_CTX')) 
			{ 
				if(getcookie('BRAND_CTX').indexOf('MyFi')!= -1) 
				{ fls_user = true; } 
			}
		}
	}
	else
	{
		if (getcookie('BRAND_CTX')) 
		{ 
			if(getcookie('BRAND_CTX').indexOf('MyFi')!= -1) 
			{ fls_user = true; } 
		}
	}
}


if ( typeof non_jv_user == "undefined" )
{
	var non_jv_user = false;
	if (getcookie("NON_JV_CTX"))
	{
		var non_jv_ctx = getcookie("NON_JV_CTX");
		if ( non_jv_ctx != null && non_jv_ctx != "" && non_jv_ctx != "empty" )
		{ non_jv_user = true; }
		else
		{
			if (getcookie('BRAND_CTX')) 
			{ 
				if(getcookie('BRAND_CTX').indexOf('Citi')!= -1) 
				{ non_jv_user = true; } 
			}
		}
	}
	else
	{
		if (getcookie('BRAND_CTX')) 
		{ 
			if(getcookie('BRAND_CTX').indexOf('Citi')!= -1) 
			{ non_jv_user = true; } 
		}
	}
}

if ( typeof pcr_user == "undefined" )
{
	var pcr_user = false;
	var pcr_ctx = getcookie("PCR_CTX");

	if ( pcr_ctx != null && pcr_ctx != "" && pcr_ctx != "empty" )
	{
		pcr_user = true;
	}
}

if ( typeof cbb_user == "undefined" )
{
	var cbb_user = false;
}

if ( cbol_user )
{
	var cbb_ctx = getcookie("CBB_CTX");

	if ( cbb_ctx != null )
	{
		cbb_user = true;
	}
}

if ( typeof pzn_user == "undefined" )
{
	var pzn_user = false;
	var pzn_ctx = getcookie("PZN_CTX");

	if ( pzn_ctx != null && pzn_ctx != "" && pzn_ctx != "empty" )
	{ 
		if (getcookie('PZN_CTX').indexOf('ID')!= -1)	
		{ pzn_user = true; } 
	}
}

if ( typeof ew8_user == "undefined" )
{
	var ew8_user = false;
	var ew8_ctx = getcookie("EW8Session");

	if ( ew8_ctx != null && ew8_ctx != "" && ew8_ctx != "empty" )
	{ ew8_user = true; }
}

function checkLoginImage() {
	if (document.images["login"]){
		document.images["login"].src =
			(userIsLogin) ? "images/0_btn_logoff.gif" : "images/0_btn_logon.gif";
	}
}

var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var isNav = (navigator.appName.indexOf("Netscape") != -1 );
var isIE = (navigator.appName.indexOf("Microsoft") != -1 );

function handleEnterSubmission(field, evt)
{
	var keyCode = evt.which ? evt.which : evt.keyCode;

	if ( keyCode == 13 )
	{
		if(document.getElementById("btnLogin")) { document.getElementById("btnLogin").click(); return false;}
		else { document.getElementById("submitbtn").click(); return false; }
	}
	else
	{
		return true;
	}
}

function handleEnterSubmission2(evt)
{
	var keyCode = 0;
	if ( isIE )
	{
		keyCode = event.keyCode;
		var nKey = 0;
	}
	if ( isNav )
	{
		keyCode = evt.which;
		var ieKey = 0;
	}
	if ( keyCode == 13 )
	{
		if ( isNav || isIE )
		{
			document.forms["logon"].submit();
		}
		return false;
	}
	else
	{
		return true;
	}
}

if ( isNav && ns4 )
{
	document.onkeydown = handleEnterSubmission
	document.captureEvents(Event.KEYDOWN)
}

function form_funcs()
{
	if ( document.forms["logon"].username.value == "" )
	{
		document.forms["logon"].username.focus();
		document.forms["logon"].username.select();
	}
}
var FORM_NAME='logon';

function getInternetExplorerVersion() {
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function checkCopy(f){ 
	if (f.value=="") 
	{   

		if (f.id == 'marketSearchTxt') { document.getElementById(f.id).value = "Enter Symbol"; }

		if (f.id == 'searchTxt') { document.getElementById(f.id).value = "Enter search term"; }
		
		if (f.id == 'username')
		{ f.value="Enter User Name" }
		else if (f.id == 'password')
		{

			var browser=navigator.appName;
			var version = getInternetExplorerVersion();
  
  			if (browser=="Microsoft Internet Explorer" && version <=8)
  			{
    			var input = document.getElementById(f.id);

    			var input2 = document.createElement('<input name=\'password\' type=\'text\' id=\'password\' value=\'Enter Password\' onblur=\'checkCopy(this)\' onfocus=\'swapfield(this,\"password\")\' onkeyup=\'return handleEnterSubmission(this.form,event)\'  maxlength=\'16\' autocomplete=\'off\' />');
    			input.parentNode.appendChild(input2);
    			input.parentNode.removeChild(input);
			}
    		else
 			{	
				document.getElementById(f.id).type = "text";
	  			document.getElementById(f.id).value = "Enter Password";
 			}  
		}	
	}
}

function returnKeypress_org(e){
var unicode=e.keyCode? e.keyCode : e.charCode;
if ((unicode <=46) || typeof unicode =='undefined') { unicode = ""; }
else
{
  switch(unicode)
  {
    case 65: return "a"; break;
    case 66: return "b"; break;
    case 67: return "c"; break;
    case 68: return "d"; break;
    case 69: return "e"; break;
    case 70: return "f"; break;
    case 71: return "g"; break;
    case 72: return "h"; break;
    case 73: return "i"; break;
    case 74: return "j"; break;
    case 75: return "k"; break;
    case 76: return "l"; break;
    case 77: return "m"; break;
    case 78: return "n"; break;
    case 79: return "o"; break;
    case 80: return "p"; break;
    case 81: return "q"; break;
    case 82: return "r"; break;
    case 83: return "s"; break;
    case 84: return "t"; break;
    case 85: return "u"; break;
    case 86: return "v"; break;
    case 87: return "w"; break;
    case 88: return "x"; break;
    case 89: return "y"; break;
    case 90: return "z"; break;
  }
}	
return unicode; 
}

function returnKeypress(e){
var unicode=e.keyCode? e.keyCode : e.charCode;
return String.fromCharCode(unicode);
}

function swapfield_orig(f, lcType)
{
  var browser=navigator.appName;
  
  if (browser=="Microsoft Internet Explorer")
  { 
    var something = returnKeypress(event); 
    document.getElementById(f.id).value = "";
    var input = document.getElementById(f.id);

    var input2 = document.createElement('<input name=\'password\' type=\'password\' id=\'password\' onblur=\'checkCopy(this)\' onkeyup=\'return handleEnterSubmission(this.form,event)\'  maxlength=\'16\' autocomplete=\'off\' onfocusin=\'checkValue(this.value, this.id)\' />');
    input.parentNode.appendChild(input2);
    input.parentNode.removeChild(input);

    if(something!="") { input2.value = something; }
    input2.focus();
  }
  else
  {	
	if(f.id=="password")
	{ 
		if(document.getElementById(f.id).value=="Enter Password")
		{ document.getElementById(f.id).value = ""; }
		else
		{ document.getElementById(f.id).value = document.getElementById(f.id).value; }
	}
	document.getElementById(f.id).type = lcType;
  }
}

function swapfield(f, lcType){
  var browser=navigator.appName;
  var version = getInternetExplorerVersion();
  
  if (browser=="Microsoft Internet Explorer" && version <=8)
  { 
    var something = returnKeypress(event); 
    document.getElementById(f.id).value = "";
    var input = document.getElementById(f.id);

    var input2 = document.createElement('<input name=\'password\' type=\'password\' id=\'password\' onblur=\'checkCopy(this)\' onkeyup=\'return handleEnterSubmission(this.form,event)\'  maxlength=\'16\' autocomplete=\'off\' onfocusin=\'checkValue(this.value, this.id)\' />');
    input.parentNode.appendChild(input2);
    input.parentNode.removeChild(input);

    if(something!="") { input2.value = something; }
    input2.focus();
  }
  else
  {	
	//if(navigator.appCodeName=="Mozilla" && navigator.userAgent.indexOf("Firefox/3.6.9")!=-1)
	if(navigator.appCodeName=="Mozilla" && navigator.userAgent.indexOf("Firefox/3.6")!=-1)
	{ 
		//alert("I'm in Firefox"); 
		document.getElementById(f.id).type = lcType;
		if(document.getElementById(f.id).value == "Enter Password") { document.getElementById(f.id).value = ""; }
	}
	else
	{	if(f.id=="password")
		{ 
			if(document.getElementById(f.id).value=="Enter Password")
			{ document.getElementById(f.id).value = ""; }
			/*else
			{ document.getElementById(f.id).value = document.getElementById(f.id).value; }*/
		}
		document.getElementById(f.id).type = lcType;
	}
  }
}

function checkValue(lcValue, lcID)
{ 	var browser=navigator.appName;

	switch (lcID)
	{
		case "username":
		{	if(lcValue==="Enter User Name") 
		    { document.getElementById(lcID).value=""; } 
  			else 
  			{ 
  				document.getElementById(lcID).value=lcValue; 
				// If IE, then need to place the cursor at the end & not the beginning
  				if (browser=="Microsoft Internet Explorer")
  				{
					el = document.getElementById("username");
					tr = el.createTextRange()
					tr.collapse(false)
					tr.select();
				}
   			}
			break; 
		}
		case "password":
		{	if(lcValue==="Enter Password") { 
				document.getElementById(lcID).value=""; } 
  			else 
  			{ 
				document.getElementById(lcID).value=lcValue; 
				// If IE, then need to place the cursor at the end & not the beginning
  				if (browser=="Microsoft Internet Explorer")
  				{
					el = document.getElementById("password");
					tr = el.createTextRange()
					tr.collapse(false)
					tr.select();
				}
   			}
			break; 
		}
		default : break;
	} //ends switch statement
}

function getCookieNames_oneciti() { 
	if (typeof(window.nameList)=="undefined" || window.nameList.length==0)
	{

		document.write('<input type="text" id="username" name="username" value="Enter User Name" onblur="checkCopy(this)" onfocus="checkValue(this.value, this.id)" maxlength="35" autocomplete="off">');
		return;
	}
        var l=[];
        if (typeof(window.nameList)!="undefined")
        {
			l = window.nameList.split("\&");

        }
        l=l.join('|').split('|');

        var elSelect='';
        elSelect+='<select name="username" id="username" onChange="onSelectUser(this);">';

        elSelect+='<option>------ Sign on as: -------</option>';
        for( var i = 0; i < l.length; i++ )
        {
					elSelect+='<option value="'+l[i]+'"'+(i==l.length-1?' selected':'')+'>'+l[i]+'</option>';

        }
        elSelect+='<option>----- Other Options -----';
        elSelect+='<option value="inputUserName">A different user</option>';
        elSelect+='<option value="removeUserName">Remove a User ID (cookie)</option>';
        elSelect+='</select>';


        document.write(elSelect);
		//alert(document.getElementById('username').value); alert(document.getElementById('username').type);
		//I have to figure out where to place to check for cookies
}


function getCookieNames() {
	if (typeof(window.nameList)=="undefined" || window.nameList.length==0)
	{
		document.write('<input type="text" id="username" name="username" class="tbox3 unpw"  maxlength="35" autocomplete="off">');

		

		document.forms["logon"].username.focus();
		return;
	}

        var l=[];
        if (typeof(window.nameList)!="undefined")
        {
			l = window.nameList.split("\&");

        }
        l=l.join('|').split('|');

        var elSelect='';
        elSelect+='<select name="username" id="username" class="tbox3 unpw" onChange="onSelectUser(this);">';

        elSelect+='<option>------ Sign on as: -------';
        for( var i = 0; i < l.length; i++ )
        {
					elSelect+='<option value="'+l[i]+'"'+(i==l.length-1?' selected':'')+'>'+l[i];

        }
        elSelect+='<option>----- Other Options -----';
        elSelect+='<option value="inputUserName">A different user';
        elSelect+='<option value="removeUserName">Remove a User ID (cookie)';
        elSelect+='</select>';

        elSelect+='<input style="display:none; padding-left:3px; margin-top:-1px; margin-bottom:-1px;" class="tbox3 unpw" type="text" name="username2" id="username2" value="" />';


        document.write(elSelect);
}


function getCheckBox4RememberID_new() {
	if (typeof(window.nameList)=="undefined" || window.nameList.length==0) {
		document.write('<input type="checkbox" id="rememberId"  name="rememberId" />');
		document.write('<label for="rememberId">Remember User Name</label>&nbsp;');
                return;
	}
}

function getCheckBox4RememberID() {

	if (typeof(window.nameList)=="undefined" || window.nameList.length==0) {
		document.write('<input type="checkbox" id="rememberId"  name="rememberId" />');
		document.write('<label for="rememberId" style="font-weight:normal; color:black;">Remember User Name</label>&nbsp;');
                return;
	}

	else
	{
		document.forms["logon"].password.focus();
	}
}

function onSelectUser(e)
{
        var n=e[e.selectedIndex].value;
        if(n=="") {

                e.selectedIndex=1;
                return;
        }
        if(n=='inputUserName')  {
				

				var passwordValue = document.forms[FORM_NAME].password.value;
				if(passwordValue !="")
				{
					document.forms[FORM_NAME].password.value = ""
				}

                document.forms[FORM_NAME].submit();
                return;
        }
        if(n=='removeUserName') {
                document.forms[FORM_NAME].submit();
                return;
        }
}


function SBlogoff()
{
	if ( typeof core_user != "undefined" )
	{

		if ( ( core_user ) && ( getcookie("CORE_CTX").indexOf("ON") != -1 ) )
		{
			if ( confirm("Would you like to log off of Citibank Online as well?") )
			{
				CBOLLogOffWin = window.open("", "CBOLLogOff");

				CBOLLogOffWin.location.href = "https://web.da-us.citibank.com/cgi-bin/citifi/portal/sb/checkSessionStatus.do?SignOff=SIGNOFF&BV_UseBVCookie=Yes&pageType=SIGNOFF&eACE-TOKEN=null";
			}
		}
		

		if ( location.hostname == "fa.smithbarney.com" )
		{
			document.location.href = "https://www.smithbarney.com/cgi-bin/login/logout.cgi";
		}
		else
		{
			document.location.href = "/cgi-bin/login/logout.cgi"; 
		}
	}

	if ( location.hostname == "fa.smithbarney.com" )
	{
		document.location.href = "https://www.smithbarney.com/cgi-bin/login/logout.cgi";


		var MSG = "https://www.smithbarney.com/kill_window.html"
		window.open( MSG , 'PCR' , 'top=10000,left=-1000,height=1,width=1,alwaysLowered=yes' );
	}
	else
	{

		var MSG = window.location.protocol + "//" + window.location.hostname + "/kill_window.html"
		window.open( MSG , 'PCR' , 'top=10000,left=-1000,height=1,width=1,alwaysLowered=yes' );
	}
}

function relaunch_pcr_window( URL )
{

	var MSG = window.location.protocol + "//" + window.location.hostname + "/kill_window.html"
	window.open( MSG , 'PCR' , 'top=10000,left=-1000,height=1,width=1,alwaysLowered=yes' );
	
	
	MSG = window.location.protocol + "//" + window.location.hostname + URL
	window.open( URL , 'PCR' , 'top=100,left=100,height=600,width=800,status=1,menubar=1,location=1,toolbar=1,scrollbars=1,resizable=1' ); 
}

function flashInitialized()
{ 	  
	var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	  
	if (isInternetExplorer)
	{
		if(document.getElementById('username').value === "Enter User Name")
		{ return; }
		else
		{ document.getElementById('password').select(); }
	}
	else
	{ 
		if(document.getElementById('username').value==="Enter User Name") { /*document.forms["logon"].username.focus(); document.forms["logon"].username.value="Enter User Name"; document.forms["logon"].username.select(); */ }
		else { document.forms["logon"].password.focus(); document.getElementById('password').select();  }
	}
}

function checkCookiedUser()
{  
	var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	 
	if(document.getElementById('username').value==="Enter User Name") 
	{ return; }
	else
	{
		if (isInternetExplorer)
		{ document.getElementById('password').select(); } 
		else { document.forms["logon"].password.focus(); document.getElementById('password').select(); }
	}
}

