// Main JavaScript Include File
// Copyright (C) 2005 by Barchart.com, Inc. All Rights Reserved.
// This file may only be used by an authorized firm, on an authorized website.
// Any unauthorized use is expressly prohibited.


function bcfn_CheckDomain() {
	var d = bcfn_GetDomain();
	if ((d == 'barchart') || (d == 'lightmixdesign') || (d == 'empirefutures') || (d == 'efgdirect'))
		return true;
	else
		return false;
}

function bcfn_GetDomain() {
	var s = document.domain;
	s = s.toLowerCase();
	if (s.substring(0, 7) == 'http://') {
		s = s.substring(7);
	}

	var ary1 = s.split('/');
	var ary2 = ary1[0].split('.');

	var d = '';

	if ((ary2[ary2.length - 1] == 'com') ||
			(ary2[ary2.length - 1] == 'org') ||
			(ary2[ary2.length - 1] == 'net') ||
			(ary2[ary2.length - 1] == 'edu') ||
			(ary2[ary2.length - 1] == 'gov')) {
		if (ary2.length > 1)
			d = ary2[ary2.length - 2];
	}
	else {
		if (ary2.length > 2)
			d = ary2[ary2.length - 3];
	}

	return d;
}

function bcfn_GetChart(sym2, sp, nasdaq, dow, overlay){
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	if(sp.checked){ sp = "true"; }else{ sp = ""; }
	if(nasdaq.checked){ nasdaq = "true"; }else{ nasdaq = ""; }
	if(dow.checked){ dow = "true"; }else{ dow = ""; }
	location.href = sPage + "?page=ccharts&sym=" + sym2 + "&overlay=" + overlay.value + "&sp=" + sp + "&nasdaq=" + nasdaq + "&dow=" + dow;
}

function bcfn_GetColor(s) {
	var c = s.substring(0, 1);
	if (c == '+')
		return '#008800';
	else if (c == '-')
		return '#ee0000';
	else
		return '#0000ff';
}

function bcfn_GetImageColor(s) {
	var c = s.substring(0, 1);
	if (c == '+')
		return bc_ImageURL + '/up.gif';
	else if (c == '-')
		return bc_ImageURL + '/dn.gif';
	else
		return bc_ImageURL + '/noch.gif';
}

function bcfn_OpenFlipbook(u, p) {
	var url = 'http://quotes-cust.barchart.com/pl/empire/flipbook.asp?list=' + p;
	window.open(url, '_blank', 'width="614",height="429",left="25",top="10"');
}


function bcfn_ParseQuery(s) {
	var ary = new Array();
	var pairs = s.split('&');

	for (var i = 0; i < pairs.length; i++) {
		var tmp = pairs[i].split('=');
		ary[tmp[0]] = tmp[1];
	}

	return ary;
}


function bcfn_PrintDisclaimer() {
	document.write('<hr size="1">');//document.write('<CENTER><HR size=1>');
	document.write('<table width="100%" cellpadding="0" cellspacing="0"><tr><td align="center" class="bcDisclaimer">');
	document.write('Website provided by Barchart.com. <a href="?page=agreement">User Agreement Applies</a>.<br/>');
	document.write('Intraday data provided by <a target="new" href="http://www.ddfplus.com">ddfplus</a> and subject to ');
	document.write('<a href="?page=ddfplus">terms of use</a>.<br/>');
	document.write('<p>End of Day and historical data provided by <a target="new" href="http://www.crbtrader.com">CRB - Commodity Research Bureau</a>.<br/>');
	document.write('Data is exchange delayed. 10 minutes for CME, CBOT, KCBT, WCE, and MGEX. 30 minutes for NYBOT and NYMEX.</p>');
	document.write('<p>Data and information is provided for informational purposes only, and is not intended for trading purposes.</p>');
	document.write('</td></tr></table>');
	//document.write('</CENTER>');
}

var bc_bShowDisclaimer = true;
var bc_QueryString = (new String(document.location.search)).substring(1);
var bc_QueryForm = bcfn_ParseQuery(bc_QueryString);
var tiger_PAGE = "TradingMain2";

// Core URL's for some of the support files
var bc_ImageURL = 'http://images.barchart.com/pl';


if (!bc_QueryForm['sym'])
	bc_QueryForm['sym'] = '';


// Start Universal Header

document.write('<table width="100%" cellpadding="3" cellspacing="4" border="0">');
document.write('<tr><td class="bcTD"><b>Quotes &amp; Charts</b></td></tr>');
document.write('<tr><td class="bcTD"><a href="?">Futures Main</a> | <a href="?page=cquotes">Custom Quotes</a> | <a href="?page=ccharts">Custom Charts</a></td>');
document.write('<td align="right" valign="top">');
document.write('<table cellpadding="0" cellspacing="0" border="0">');
document.write('<tr>');
document.write('<form>');
document.write('<td class="bcTD">');
document.write('<a href="?page=lookup">Enter Symbol:</a> &nbsp;');
document.write('<input type="text" name="sym" size="5" maxlength="10" value="' + bc_QueryForm['sym'] + '" class="bcInput">');
document.write('<input type="submit" value="Get" class="bcSubmit">');
document.write('</td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td align="right" class="bcTD">');

if (bc_QueryForm['page'] == 'optqte') {
	document.write('<input type="radio" name="page" value="quote">Quote');
	document.write('<input type="radio" name="page" value="chart">Chart');
	document.write('<input type="radio" name="page" value="optqte" checked="yes">Option');
}
else if (bc_QueryForm['page'] == 'chart') {
	document.write('<input type="radio" name="page" value="quote">Quote');
	document.write('<input type="radio" name="page" value="chart" checked="yes">Chart');
	document.write('<input type="radio" name="page" value="optqte">Option');
}
else {
	document.write('<input type="radio" name="page" value="quote" checked="yes">Quote');
	document.write('<input type="radio" name="page" value="chart">Chart');
	document.write('<input type="radio" name="page" value="optqte">Option');
}
document.write('</td>');
document.write('</form>');
document.write('</tr>');
document.write('</table>');
document.write('</td>');
document.write('</tr>');
document.write('</table>');
document.write('<hr size="1" color="#295294" width="100%" align="left" />');



if (bcfn_CheckDomain()) {

	document.write('<scr' + 'ipt type="text/javascript" src="');

	if (bc_QueryForm['page'] == 'agreement') {
		document.write('http://content.barchart.com/shared/agreement.php');
	}
	else if (bc_QueryForm['page'] == 'calendar') {
		document.write('http://www.insidefutures.com/calendar/indexPL.php?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'chart') {
		document.write('http://sites3.barchart.com/pl/empire/chart.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'ccharts') {
		document.write('http://sites3.barchart.com/pl/empire/chart.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'commentary') {
		document.write('http://content.barchart.com/shared/commentary/mktcom.phpx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'cquotes') {
		document.write('http://sites3.barchart.com/pl/empire/cquotes.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'custom') {
		document.write('http://sites3.barchart.com/pl/empire/support/custom.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'ddfplus') {
		document.write('http://sites3.barchart.com/pl/empire/ddfplus.js');
	}
	else if (bc_QueryForm['page'] == 'lookup') {
		document.write('http://sites3.barchart.com/pl/empire/lookup.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'portfolio') {
		document.write('http://sites3.barchart.com/pl/empire/portfolio.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'profile') {
		document.write('http://sites3.barchart.com/pl/empire/profile.htx?sym=' + bc_QueryForm['sym']);
	}
	else if (bc_QueryForm['page'] == 'quote') {
		document.write('http://sites3.barchart.com/pl/empire/quote.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'quote2') {
		document.write('http://quotes-cust.barchart.com/pl/empire/quote.htx?' + bc_QueryString);
	}
	else if ((bc_QueryForm['page'] == 'support') && (bc_QueryForm['section'] == 'learning')) {
		document.write('http://sites3.barchart.com/pl/empire/support/learning.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'texpert') {
		document.write('http://quotes-cust.barchart.com/pl/empire/texpert.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'optqte') {
		document.write('http://sites3.barchart.com/pl/common/optqte.htx?' + bc_QueryString);
	}
	else {
		document.write('http://sites3.barchart.com/pl/empire/default.htx?' + bc_QueryString);
	}
	document.write('"></scr' + 'ipt>\n');

}
else {
	document.write('!!! Unauthorized Access !!!');
}

if (bc_bShowDisclaimer) {
	document.write('<scr' + 'ipt type="text/javascript" src="http://content.barchart.com/shared/disclaimer.php?logo=true"></scr' + 'ipt>\n');
}
