/*
BrowserDetector()
Parses User-Agent string into useful info.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Richard Blaylock
Author Email: blaylock@wired.com

Usage: var bd = new BrowserDetector(navigator.userAgent);
*/


// Utility function to trim spaces from both ends of a string
function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.charAt(start) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
    --end;
  }
  retVal = inString.substring(start, end);
  return retVal;
}

function BrowserDetector(ua) {

// Defaults
  this.browser = "Unknown";
  this.platform = "Unknown";
  this.version = "";
  this.majorver = "";
  this.minorver = "";
  this.netBrow = "";
  this.netBrowVer = "";

  uaLen = ua.length;

// ##### Split into stuff before parens and stuff in parens
  var preparens = "";
  var parenthesized = "";

  var j = ua.indexOf(")");
  var postParens = ua.substring(j+1, uaLen);
  var postToken = postParens.split(" ");
  for(var x = 0; x < postToken.length; ++x){
  	var currentToken = postToken[x].split("/");
  	if(currentToken.length == 2){
		this.netBrow = currentToken[0];
		this.netBrowVer = currentToken[1];
  	}
  }
  //alert(postParens);


  i = ua.indexOf("(");
  if (i >= 0) {
    preparens = Trim(ua.substring(0,i));
        parenthesized = ua.substring(i+1, uaLen);
        j = parenthesized.indexOf(")");
        if (j >= 0) {
          parenthesized = parenthesized.substring(0, j);
        }
  }
  else {
    preparens = ua;
  }

// ##### First assume browser and version are in preparens
// ##### override later if we find them in the parenthesized stuff
  var browVer = preparens;

  var tokens = parenthesized.split(";");
  var token = "";
// # Now go through parenthesized tokens
  for (var i=0; i < tokens.length; i++) {
	token = Trim(tokens[i]);
	//## compatible - might want to reset from Netscape
	if (token == "compatible") {
	  //## One might want to reset browVer to a null string
	  //## here, but instead, we'll assume that if we don't
	  //## find out otherwise, then it really is Mozilla
	  //## (or whatever showed up before the parens).
	//## browser - try for Opera or IE
	}else if (token.indexOf("Opera") >= 0) {
		browVer = token;
	}else if (token.indexOf("MSIE") >= 0) {
		browVer = token;
	}
        //'## platform - try for X11, SunOS, Win, Mac, PPC
    	else if ((token.indexOf("X11") >= 0) || (token.indexOf("SunOS") >= 0) ||(token.indexOf("Linux") >= 0)) {
      		this.platform = "Unix";
        }
    	else if (token.indexOf("Win") >= 0) {
      	//this.platform = token;
      	//## Changed to simplify the logic at the end of the page
      		this.platform = "Windows";
        }
    	else if ((token.indexOf("Mac") >= 0) || (token.indexOf("PPC") >= 0)) {
      	//this.platform = token;
      	//## Changed to simplify the logic at the end of the page
      		this.platform = "Mac";
        }
  }

  var msieIndex = browVer.indexOf("MSIE");
  if (msieIndex >= 0) {
    browVer = browVer.substring(msieIndex, browVer.length);
  }

  var leftover = "";
  if (browVer.substring(0, "Opera".length) == "Opera") {
    this.browser = "Opera"
    	leftover = browVer.substring("Opera".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Mozilla".length) == "Mozilla") {
    this.browser = "Netscape";
        leftover = browVer.substring("Mozilla".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Lynx".length) == "Lynx") {
    this.browser = "Lynx";
        leftover = browVer.substring("Lynx".length+1, browVer.length);
  }
  else if (browVer.substring(0, "MSIE".length) == "MSIE") {
    this.browser = "IE";
    	leftover = browVer.substring("MSIE".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Microsoft Internet Explorer".length) == "Microsoft Internet Explorer") {
    this.browser = "IE"
        leftover = browVer.substring("Microsoft Internet Explorer".length+1,browVer.length);
  }

  leftover = Trim(leftover);

  // # Try to get version info out of leftover stuff
  i = leftover.indexOf(" ");
  if (i >= 0) {
    this.version = leftover.substring(0, i);
  }
  else
  {
    this.version = leftover;
  }
  j = this.version.indexOf(".");
  if (j >= 0) {
    this.majorver = this.version.substring(0,j);
    this.minorver = this.version.substring(j+1, this.version.length);
  }
  else {
    this.majorver = this.version;
  }

  if(this.netBrow!="") this.browser=this.netBrow;
  if(this.netBrowVer!="") this.version=this.netBrowVer;

} // function BrowserCap

function incompatibleBrowser(){
//we'll take a liberal approach and only lock out those browsers we know are bad
/*
	document.writeln("agent="+navigator.userAgent+"<BR>");
	document.writeln("this.browser="+this.browser+"<BR>");
	document.writeln("this.platform="+this.platform+"<BR>");
	document.writeln("this.version="+this.version+"<BR>");
	document.writeln("this.majorver="+this.majorver+"<BR>");
	document.writeln("this.minorver="+this.minorver+"<BR>");
	document.writeln("this.netBrow="+this.netBrow+"<BR>");
	document.writeln("this.netBrowVer="+this.netBrowVer+"<BR>");
*/
	if(this.browser.indexOf("Netscape")>-1 && Number(this.version)<6) return true;
	else if(this.browser=="IE" && Number(this.majorver)<5) return true;
	else if(this.browser=="IE" && Number(this.majorver)<6 && this.platform=="Mac") return true;
	else return false;
}

function DISCLAIMER_Window(url) {
	window.open(url,'DISCLAIMER_Window','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=640,height=400');
}

function showDisclaimer(doc,delayedQuotes,quoteDisclaimer){

	doc.writeln('<br><br>');
	doc.writeln('<table width="90%" border="0" cellspacing="0" cellpadding="0">');
	doc.writeln('<tr>');
	doc.writeln('<td align="left" class=footer>&copy;&nbsp;Chicago Investment Group, L.L.C. Member FINRA, SIPC, All Rights Reserved.</td>');
	doc.writeln('</tr>');
	doc.writeln('<tr>');
	doc.write('<td align="left" class=footer>');
	//doc.write('&nbsp;<a href="javascript:DISCLAIMER_Window(\'/docs/SEC_Rule_11Ac1-6.html\');" class="footerAnchor" onMouseOver="self.status=\'SEC Rule 11Ac1-6\'; return true" onMouseOut="self.status=\'\'; return true">SEC Rule 11Ac1-6</a>');
	doc.write('&nbsp;<a href="javascript:DISCLAIMER_Window(\'/docs/privacy_statement.html\');" class="footerAnchor" onMouseOver="self.status=\'Privacy Policy\'; return true" onMouseOut="self.status=\'\'; return true">Privacy Policy</a>');
	//doc.write('&nbsp;|&nbsp;<a href="javascript:DISCLAIMER_Window(\'/docs/user_agreement.html\');" class="footerAnchor" onMouseOver="self.status=\'User Agreement\'; return true" onMouseOut="self.status=\'\'; return true">User Agreement</a>');
	//doc.write('&nbsp;|&nbsp;<a href="javascript:DISCLAIMER_Window(\'/docs/margin_disclosure.html\');" class="footerAnchor" onMouseOver="self.status=\'Margin Disclosure\'; return true" onMouseOut="self.status=\'\'; return true">Margin Disclosure</a>');
	//doc.write('&nbsp;|&nbsp;<a href="javascript:DISCLAIMER_Window(\'/docs/commissions_and_fees.html\');" class="footerAnchor" onMouseOver="self.status=\'Commissions and Fees\'; return true" onMouseOut="self.status=\'\'; return true">Commissions and Fees</a>');
	doc.writeln('</td>');
	doc.writeln('</tr>');
	doc.writeln('<tr>');
	doc.writeln('<td>&nbsp;</td>');
	doc.writeln('</tr>');
	if(quoteDisclaimer){
		doc.writeln('<tr>');
		doc.writeln('<td align="left" class=footer>Quote data provided by Automated Financial Systems Corp.</td>');
		doc.writeln('</tr>');
		doc.writeln('<tr>');
		if(delayedQuotes || top.session_get_session_info.data[0].is_demo!="N"){
			doc.writeln('<td align="left" class=footer>NYSE and AMEX quotes are delayed by at least 20 minutes. All other quotes are delayed by at least 15 minutes.</td>');
		}else{
			doc.writeln('<td align="left" class=footer>Quotes are real time.  Quote times are Eastern Time Zone (EST/EDT).  Real time quotes are deducted from your quote bank.</td>');
		}
		doc.writeln('</tr>');
		doc.writeln('<tr>');
		doc.writeln('<td>&nbsp;</td>');
		doc.writeln('</tr>');
	}
/*  browser upgrade links, commented out

	if (this.platform == "Windows") {
		if (this.browser == "IE" && this.majorver < "6"){
			doc.writeln('<tr>');
			doc.writeln('<td align="left" class=footer>Upgrading to <a href="http://www.microsoft.com/windows/ie/default.mspx" class="footerAnchor" target="_new" onMouseOver="self.status=\'Download the latest Internet Explorer\'; return true" onMouseOut="self.status=\'\'; return true">Internet Explorer 6.0</a> will greatly improve your online experience.</td>');
			doc.writeln('</tr>');
		} else if (this.browser == "IE" && this.majorver >= "6"){
			// do nothing
		} else if (this.browser.indexOf("Netscape")>-1 && this.netBrowVer < "7"){
		 	doc.writeln('<tr>');
			doc.writeln('<td align="left" class=footer>Upgrading to <a href="http://channels.netscape.com/ns/browsers/default.jsp" class="footerAnchor" target="_new" onMouseOver="self.status=\'Download the latest Netscape\'; return true" onMouseOut="self.status=\'\'; return true">Netscape 7.2</a> will greatly improve your online experience.</td>');
			doc.writeln('</tr>');
		} else if (this.browser.indexOf("Netscape")>-1 && this.netBrowVer >= "7"){
			// do nothing
		} else {
			doc.writeln('<tr>');
			doc.writeln('<td align="left" class=footer>Upgrading to <a href="http://www.microsoft.com/windows/ie/default.mspx" class="footerAnchor" target="_new" onMouseOver="self.status=\'Download the latest Internet Explorer\'; return true" onMouseOut="self.status=\'\'; return true">Internet Explorer 6.0</a> will greatly improve your online experience.</td>');
			doc.writeln('</tr>');
		}

	} else if (this.platform == "Mac") {
		if ((this.browser == "IE") || (this.netBrow == "Safari")){
		 	doc.writeln('<tr>');
			doc.writeln('<td align="left" class=footer>Upgrading to <a href="http://www.mozilla.org/products/firefox" class="footerAnchor" target="_new" onMouseOver="self.status=\'Download the latest Firefox\'; return true" onMouseOut="self.status=\'\'; return true">Firefox 1.0.2</a> will greatly improve your online experience.</td>');
			doc.writeln('</tr>');
		} else if (this.browser.indexOf("Netscape")>-1 && this.netBrowVer < "7"){
		 	doc.writeln('<tr>');
			doc.writeln('<td align="left" class=footer>Upgrading to <a href="http://channels.netscape.com/ns/browsers/download.jsp" class="footerAnchor" target="_new" onMouseOver="self.status=\'Download the latest Netscape\'; return true" onMouseOut="self.status=\'\'; return true">Netscape 7.2</a> will greatly improve your online experience.</td>');
			doc.writeln('</tr>');
		} else if (this.browser.indexOf("Netscape")>-1 && this.netBrowVer >= "7"){
			// do nothing
		} else if (this.browser == "Firefox" && this.netBrowVer >= "1"){
			// do nothing
		} else {
		 	doc.writeln('<tr>');
			doc.writeln('<td align="left" class=footer>Upgrading to <a href="http://www.mozilla.org/products/firefox" class="footerAnchor" target="_new" onMouseOver="self.status=\'Download the latest Firefox\'; return true" onMouseOut="self.status=\'\'; return true">Firefox 1.0.2</a> will greatly improve your online experience.</td>');
			doc.writeln('</tr>');
		}
	}else{ //UNIX,etc
	 	doc.writeln('<tr>');
		doc.writeln('<td align="left" class=footer>Upgrading to <a href="http://www.mozilla.org/products/firefox" class="footerAnchor" target="_new" onMouseOver="self.status=\'Download the latest Firefox\'; return true" onMouseOut="self.status=\'\'; return true">Firefox 1.0.2</a> will greatly improve your online experience.</td>');
		doc.writeln('</tr>');
	}
*/


 	doc.writeln('<tr>');
	doc.writeln('<td align="left" class=footer>You can download the latest compatible browsers <a href="javascript:void(0);" onClick="window.open(\'/browser_upgrade.html\',\'browser_upgrade\',\'width=400,height=600,left=200,top=50\'); return false;" class="footerAnchor" onMouseOver="self.status=\'Download Browser\'; return true" onMouseOut="self.status=\'\'; return true">here</a>.</td>');
	doc.writeln('</tr>');

	doc.writeln('</table>');
}

var bd = BrowserDetector(navigator.userAgent);
