// 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
/*
if (top.location != self.location) {
	self.location.href = 'http://sites3.barchart.com/pl/vsn/quotes.html';
	window.open(self.location.href);
}
*/
function bcfn_CheckDomain() {
	var d = bcfn_GetDomain();
	if ((d == 'barchart') || (d == 'pfgbest') || (d == 'pfg') || (d == 'pfgcanada') || (d == 'peregrineasset'))
		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] == 'ru') ||
			(ary2[ary2.length - 1] == 'ca') ||
			(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_GetQuote(page, sym){
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	for (var i = 0; i < page.length; i++) {
		if (page[i].checked) {
			location.href = sPage + "?page=" + page[i].value + "&sym=" + sym;
		}
	}
}

function bcfn_GetChart(sym2, sp, nasdaq, dow){
	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 + "&sp=" + sp + "&nasdaq=" + nasdaq + "&dow=" + dow;
}

function bcfn_GetCustomQuote(fullquery){
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	var symlist = '';
	var count = 1;
	for(var i = 0; i < fullquery.length; i++) { 
		if(fullquery[i].value != ""){
			symlist = symlist + '&sym' + i + "=" + fullquery[i].value; 
			count = count + 1; 
		}
	}
	location.href = sPage + "?page=cquotes&what=change&action=update" + symlist + "&maxcnt=" + count;
}

function bcfn_OpenFlipbook(u, p) {
	var url = 'http://quotes-cust.barchart.com/pl/pfg/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 pfg_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


if (bc_QueryForm['page'] == 'futs101') {
	document.write('<div id="content"><table width="100%" cellpadding="0" cellspacing="4" border="0">');
	document.write('<tr><td class="pageTitle"><b><h1>Futures 101</h1></b></td></tr></table><br></div>');
}else{
	
	document.write('<form method="get">');
	document.write('<table width="95%" cellpadding="3" cellspacing="4" border="0">');
	document.write('<tr><td class="bcTD" valign="bottom"><a href="?">Futures Main</a> | <a href="?page=cquotes">Custom Quotes</a> | <a href="?page=ccharts">Custom Charts</a>');
	document.write('<td align="right" valign="top">');
	document.write('<table cellpadding="0" cellspacing="0" border="0">');
	document.write('<tr>');
	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="button" value="Get" class="bcSubmit" onclick="location.href=\'?page=' + this.page + '\'">');
	document.write('<input type="button" value="Get" class="bcSubmit" onclick="bcfn_GetQuote(this.form.page, this.form.sym.value)">');

	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('</tr>');
	document.write('</table>');
	document.write('</td>');
	document.write('</tr>');
	document.write('</table>');
	document.write('</form>');
	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/pfg/chart.htx?' + bc_QueryString);
		bc_bShowDisclaimer = false;
	}
	else if (bc_QueryForm['page'] == 'ccharts') {
		document.write('http://sites2.barchart.com/pl/pfg/ccharts.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'cquotes') {
		document.write('http://sites2.barchart.com/pl/pfg/cquotes.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'custom') {
		document.write('http://sites2.barchart.com/pl/pfg/support/custom.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'ddfplus') {
		document.write('http://sites2.barchart.com/pl/pfg/ddfplus.js');
	}
	else if (bc_QueryForm['page'] == 'futs101') {
		document.write('http://sites2.barchart.com/pl/pfg/futs101.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'lookup') {
		document.write('http://sites2.barchart.com/pl/pfg/lookup.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'portfolio') {
		document.write('http://sites2.barchart.com/pl/pfg/portfolio.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'profile') {
		document.write('http://sites2.barchart.com/pl/pfg/profile.htx?sym=' + bc_QueryForm['sym']);
	}
	else if (bc_QueryForm['page'] == 'quote') {
		document.write('http://sites2.barchart.com/pl/pfg/quote.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'quote2') {
		document.write('http://quotes-cust.barchart.com/pl/pfg/quote.htx?' + bc_QueryString);
	}
	else if ((bc_QueryForm['page'] == 'support') && (bc_QueryForm['section'] == 'learning')) {
		document.write('http://sites2.barchart.com/pl/pfg/support/learning.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'texpert') {
		document.write('http://quotes-cust.barchart.com/pl/pfg/texpert.htx?' + bc_QueryString);
	}
	else if (bc_QueryForm['page'] == 'optqte') {
		document.write('http://sites2.barchart.com/pl/pfg/optqte.htx?' + bc_QueryString);
	}
	else {
		document.write('http://sites2.barchart.com/pl/pfg/default.htx?' + bc_QueryString);
	}
	document.write('"></scr' + 'ipt>\n');
	if(bc_bShowDisclaimer){	
  		document.write('<scr' + 'ipt type="text/javascript" src="http://content.barchart.com/shared/disclaimer.php?logo=true"></scr' + 'ipt>\n');
	}
} else {
	document.write('!!! Unauthorized Access !!!');
}


