// 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.
// Last Modified 2/14/2007


function bcfn_CheckDomain() {
	var d = bcfn_GetDomain();
	if ((d == 'barchart') || (d == 'amfdemo') || (d == 'americanfuturestrading'))
		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_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/aft/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" style="color: #000000; font-weight: bold; text-decoration: underline;">User Agreement Applies</a>.<br/>');
	document.write('Intraday data provided by <a target="new" href="http://www.ddfplus.com" style="color: #000000; font-weight: bold; text-decoration: underline;">ddfplus</a> and subject to ');
	document.write('<a href="?page=ddfplus" style="color: #000000; font-weight: bold; text-decoration: underline;">terms of use</a>.<br/>');
	document.write('<p>End of Day and historical data provided by <a target="new" href="http://www.crbtrader.com" style="color: #000000; font-weight: bold; text-decoration: underline;">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);

// 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('<link rel="stylesheet" href="http://sites2.barchart.com/pl/aft/aft.css" type="text/css">');
document.write('<table width="100%" cellpadding="3" cellspacing="4" border="0">');
document.write('<tr><td class="bcTD">');
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('<b>Enter Symbol:</b> &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">');
document.write('<input type="hidden" name="page" value="quote">');
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'] == 'chart') {
		document.write('http://sites2.barchart.com/pl/aft/chart.htx?' + bc_QueryString);
		bc_bShowDisclaimer = false;
	}
	else if (bc_QueryForm['page'] == 'ddfplus') {
		document.write('http://sites2.barchart.com/pl/aft/ddfplus.js');
	}
	else if (bc_QueryForm['page'] == 'portfolio') {
		document.write('http://sites2.barchart.com/pl/aft/portfolio.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'profile') {
		document.write('http://sites2.barchart.com/pl/aft/profile.htx?sym=' + bc_QueryForm['sym']);
	}
	else if (bc_QueryForm['page'] == 'quote') {
		document.write('http://sites2.barchart.com/pl/aft/quote.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'quote2') {
		document.write('http://quotes-cust.barchart.com/pl/aft/quote.htx?' + bc_QueryString);
	}
	else {
		document.write('http://sites2.barchart.com/pl/aft/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');
}
