
function doPJ() {
  if($('PjProductName').value.trim().length>0){
     window.location=$('PjProductName').value;
  }else if($('PjAssetClass').value.trim().length>0){
    window.location=$('PjAssetClass').value;
  }
}
function getPJProductName(assetVal) {


     var prodNameHTML=' ';
     var XMLreq=null;
     if (assetVal.selectedIndex<=0){
        $('productSelect').innerHTML="<select id='PjProductName' style='width: 200px;' disabled='disabled' ><option value=''>Select a Product</option></select>";
     } else {
       XMLreq=new Ajax(assetVal.value+'/rightnav/productjump.html', {update:$('productSelect')}).request();
     }
     return XMLreq;
}

function initPJ() {
var requestFromLocation="/cmegroup"+window.location.pathname;

if (requestFromLocation.indexOf("_OO")>=0){
    requestFromLocation=requestFromLocation.replace("_OO",'');
}else{
    requestFromLocation=requestFromLocation.replace("_FO",'');
}

var assetclass=$('PjAssetClass');
var AjaxReq = null;
       //Select the Asset Class
	for(i=1; i<assetclass.length; i++)
	{
        if(requestFromLocation.indexOf(assetclass.options[i].value)>=0 ){
           assetclass.value=assetclass.options[i].value;

        }
       }

       //Get the Product Dropdown, if asset is selected
       if(assetclass.selectedIndex>0){


            AjaxReq =new Ajax(assetclass.value+'/rightnav/productjump.html', {update:$('productSelect'),onComplete: function(){
                             //If Product Is selected, Select it
                           if (requestFromLocation.substr(requestFromLocation.length-1,1)!='/')
                            {
                                 var productSelected=$('PjProductName');
                            	for(i=1; i<productSelected.length; i++)
                            	{
                                   if(requestFromLocation.indexOf(productSelected.options[i].value)>=0 ){
                                     productSelected.value=productSelected.options[i].value;
                                    }
                                 }
                            }
                          }}).request();


          }

     return requestFromLocation;
}

// refreshWithAjax
	function refreshWithAjax(src, update, data, meth, opts){
		if(!src || src == '') return;

		options = {
			shrinkWrap: true,
			imgSize: 'large'
		};

		if($defined(opts)){
			options = $extend(options, opts);
		}

		$(update).innerHTML='';

		ajaxLoader = new Element('img', {'src':'/images/ajax-loader' + (options.imgSize == 'small' ? '_small' : '') + '.gif'}).injectTop($(update));

		doLookup = new Ajax(src,
			{
				evalScripts:true,
				data: data,
				method: meth,
				update: $(update),

				onComplete: function(){
					elmt = $(update);
					if(options.shrinkWrap){
						while(elmt.getTag().toLowerCase() != 'body'){
							elmt.setStyle('height', 'auto');
							elmt = elmt.getParent();
						}
					}
				},

				onFailure: function(){
					$(update).innerHTML = 'We apologize, your request is unavailable at this time, please make another selection or try again later.';
				}
			}
		).request();
	}

// end of refreshWithAjax

// note that I changed the name of the function to showSectionByIndex
// to prevent conflicts
function showSectionByIndex(idx){
	var productSection = $$('.productSection');
	var sectionTabs = $ES('a', $('sectionTabs'));

	productSection.each(
               function(e){
                       e.setStyle('display', 'none');
               }
        );
        sectionTabs.each(
               function(e, i){
                       e.className = '';
               }
        );
        sectionTabs[idx].className = 'on';
        productSection[idx].setStyle('display', 'block');
}


// LEFT NAV FUNCTIONS START HERE
function initLeftnav(sections) {

	var leftnavToggler = $$('dl#navigation_left dd.ddSubnav a.leftNav');

	var leftnavAccordion = $$('dl#navigation_left div.subnav');

	var leftNavAccordion = new Accordion(leftnavToggler, leftnavAccordion,

		{

			openAll: false,

			allowMultipleOpen: true,

			firstElementsOpen: [0],

			start: 'open-first',

			fixedHeight: false,

			fixedWidth: false,

			alwaysHide: true,

			wait: false,

			onActive:function(e, c){

				//e.addClass('over');
				e.getParent().getParent().addClass('over');

			},

			onBackground:function(e, c){

				//e.removeClass('over');
				//e.addClass('under');
				e.getParent().getParent().removeClass('over');
				e.getParent().getParent().addClass('under');

			},

			opacity: true

		}

	);

	// added for keeping the current section open
        // var sections = ['company', 'trading', 'globex', 'market-data', 'clearing', 'market-regulation', 'investor-relations', 'education', 'tools-information'];
	// var sections is initialized automatically outside


		var checkLocation = sections.each(

			function(e, i){
				var sectionRX = new RegExp('/' + e + '/', 'ig');
				if(sectionRX.test(window.location.pathname)){
					//alert(sections[i]);
					$ES('a.leftNavSubLink', $$('div.subnav')[i]).each(

						function(e){
							var uriSubstr = (e.href.substr( e.href.indexOf(sections[i]) + sections[i].length + 1 ));
							if(uriSubstr.substr(0, uriSubstr.indexOf('/')) != '')
								uriSubstr = uriSubstr.substr(0, uriSubstr.indexOf('/'));
							if(new RegExp(uriSubstr).test(window.location) && uriSubstr != ''){
								//if(new RegExp(e.href).test(window.location))
								e.setStyles({'color': '#C60', 'font-weight': 'bold'});
							}

						}

					);

					leftNavAccordion.options.duration = 0;

					leftNavAccordion.display(i);
					setDuration = function(){

						leftNavAccordion.options.duration = 500;

					}

					resetDur = setDuration.delay(501);

				} // end if

			}

        );
}
//USED FOR INTERNATIONAL POPUPS
function initLeftnavMinor(sections) {

	var leftnavToggler = $$('dl#navigation_left_minor dd.ddSubnav a.leftNav');
	var leftnavAccordion = $$('dl#navigation_left_minor div.subnav');

	var leftNavAccordion = new Accordion(leftnavToggler, leftnavAccordion,
		{
			onActive:function(e, c){
				e.getParent().getParent().addClass('over');
			},
			onBackground:function(e, c){
				e.getParent().getParent().removeClass('over');
				e.getParent().getParent().addClass('under');
			},
			alwaysHide:	true,
			start:				true
		}
	);

	// added for keeping the current section open
        // var sections = ['company', 'trading', 'globex', 'market-data', 'clearing', 'market-regulation', 'investor-relations', 'education', 'tools-information'];
	// var sections is initialized automatically outside


		var checkLocation = sections.each(

			function(e, i){
				var sectionRX = new RegExp('/' + e + '/', 'ig');
				if(sectionRX.test(window.location.pathname)){
					//alert(sections[i]);
					$ES('a.leftNavSubLink', $$('div.subnav')[i]).each(

						function(e){
							var uriSubstr = (e.href.substr( e.href.indexOf(sections[i]) + sections[i].length + 1 ));
							if(uriSubstr.substr(0, uriSubstr.indexOf('/')) != '')
								uriSubstr = uriSubstr.substr(0, uriSubstr.indexOf('/'));
							if(new RegExp(uriSubstr).test(window.location) && uriSubstr != ''){
								//if(new RegExp(e.href).test(window.location))
								e.setStyles({'color': '#C60', 'font-weight': 'bold'});
							}

						}

					);

					leftNavAccordion.options.duration = 0;

					leftNavAccordion.display(i);
					setDuration = function(){

						leftNavAccordion.options.duration = 500;

					}

					resetDur = setDuration.delay(501);

				} // end if

			}

        );



}
//LEFT NAV FUNCTIONS END HERE

// Multiple.open.accordion.js
// Used for progressive disclosures
/*	Script: multiple.open.accordion.js
		Creates a Mootools <Fx.Accordion> that allows the user to open more than one element.

		Dependancies:
			 mootools - 	<Moo.js>, <Function.js>, <Array.js>, <String.js>, <Element.js>, <Fx.Base.js>, <Fx.Elements.js>, <Fx.Styles.js>, <Fx.Style.js>

		Author:
			Aaron Newton, <aaron [dot] newton [at] cnet [dot] com>


		Class: MultipleOpenAccordion
		Extends the <Fx.Elements> class from Mootools for an accordion element that allows
		the user to open more than one element.

		Arguments:
		togglers - elements that activate each section
		elements - the elements to resize
		options - the options object of key/value settings

		Options:
		openAll - (boolean) open all elements on startup; defaults to true.
		allowMultipleOpen - (boolean) allows users to open more than one element at a time; defaults to true.
		firstElementsOpen - (array) an array of elements to open on startup;
				only used if openAll = false and allowMultipleOpen = true;
				defaults to [0]; can be empty ([]) to signifiy that all should be closed;
		start - (string) 'first-open' slides open each element in firstElementsOpen;
										 'open-first' opens each element in firstElementsOpen immediately using no effects (default)
		fixedHeight - integer, if you want your accordion to have a fixed height. defaults to false.
		fixedWidth - integer, if you want your accordion to have a fixed width. defaults to false.
		alwaysHide - boolean, if you want the ability to close your only-open item. defaults to true.
		wait - boolean. means that open and close transitions can cancel current ones (so if you click
		 on items before the previous finishes transitioning, the clicked transition will fire canceling the previous).
		 true means that if one element is sliding open or closed, clicking on another will have no effect.
		 for Accordion defaults to false.
		onActive - function to execute when an element starts to show; passed arguments: (toggler, section)
		onBackground - function to execute when an element starts to hide; passed arguments: (toggler, section)
		height - boolean, will add a height transition to the accordion if true. defaults to true.
		opacity - boolean, will add an opacity transition to the accordion if true. defaults to true.
		width - boolean, will add a width transition to the accordion if true. defaults to false,
						css mastery is required to make this work!
	*/
var MultipleOpenAccordion = Fx.Elements.extend({
	options: {
		openAll: true,
		allowMultipleOpen: true,
		firstElementsOpen: [0],
		start: 'open-first',
		fixedHeight: false,
		fixedWidth: false,
		alwaysHide: true,
		wait: false,
		onActive: Class.empty,
		onBackground: Class.empty,
		height: true,
		opacity: true,
		width: false
	},
	initialize: function(togglers, elements, options){
		this.parent(elements, options);
		this.setOptions(options);
		this.previousClick = null;
		this.elementsVisible = [];
		togglers.each(function(tog, i){
			$(tog).addEvent('click', function(){this.toggleSection(i)}.bind(this));
		}, this);
		this.togglers = togglers;
		this.h = {};
		this.w = {};
		this.o = {};
		this.now = [];
		this.elements.each(function(el, i){
			el = $(el);
			this.now[i] = {};
			el.setStyle('overflow','hidden');
			if(!(this.options.openAll && this.options.allowMultipleOpen)) el.setStyle('height', 0);
		}, this);
		if(!this.options.openAll || !this.options.allowMultipleOpen) {
			switch(this.options.start){
				case 'first-open': this.showSection(this.options.firstElementsOpen[0]); break;
				case 'open-first': this.toggleSection(this.options.firstElementsOpen[0]); break;
			}
		}
		if (this.options.openAll && this.options.allowMultipleOpen) this.showAll();
		else if (this.options.allowMultipleOpen) this.openSections(this.options.firstElementsOpen);
	},
	hideThis: function(i){ //sets up the effects for hiding an element
		this.elementsVisible[i] = false;
		if (this.options.height) this.h = {'height': [this.elements[i].offsetHeight, 0]};
		if (this.options.width) this.w = {'width': [this.elements[i].offsetWidth, 0]};
		if (this.options.opacity) this.o = {'opacity': [this.now[i]['opacity'] || 1, 0]};
		this.fireEvent("onBackground", [this.togglers[i], this.elements[i]]);
	},

	showThis: function(i){ //sets up the effects for showing an element
		this.elementsVisible[i] = true;
		if (this.options.height) this.h = {'height': [this.elements[i].offsetHeight, this.options.fixedHeight || this.elements[i].scrollHeight]};
		if (this.options.width) this.w = {'width': [this.elements[i].offsetWidth, this.options.fixedWidth || this.elements[i].scrollWidth]};
		if (this.options.opacity) this.o = {'opacity': [this.now[i]['opacity'] || 0, 1]};
		this.fireEvent("onActive", [this.togglers[i], this.elements[i]]);
	},
/*	Property: toggleSection
		Opens or closes a section depending on its state and the options of the Accordion.

		Argumetns:
		iToToggle - (integer) the index of the section to open or close
	*/
	toggleSection: function(iToToggle){
		//let's open an object, or close it, depending on it's state
		//now, if the index to toggle isn't the previous click
		//or we're going to allow items to be closed (so that all of them are closed
		//or we're allowing more than one item to be open at a time, continue
		//otherwise, we're looking at an item that was just clicked, and it should already be open
		if(iToToggle != this.previousClick || this.options.alwaysHide || this.options.allowMultipleOpen) {
			//save the previous click
			this.previousClick = iToToggle;
			var objObjs = {};
			var err = false;
			//go through each element
			this.elements.each(function(el, i){
				var update = false;
				//set up it's now state
				this.now[i] = this.now[i] || {};
				//if the element is the one clicked
				if(i==iToToggle){
					//if the element is visible, hide it if we allow alwaysHide or multiple
					if (this.elementsVisible[i] && (this.options.allowMultipleOpen || this.options.alwaysHide)){
						//if ! wait and timer
						if(!(this.options.wait && this.timer)) {
							//hide it
							update = true;
							this.hideThis(i);
						} else {
							this.previousClick = null;
							err = true;
						}
					} else if(!this.elementsVisible[i]){
					//else if hidden, show it
						//if ! wait and timer
						if(!(this.options.wait && this.timer)) {
							//show it
							update = true;
							this.showThis(i);
						} else {
							this.previousClick = null;
							err = true;
						}
					}
				} else if(this.elementsVisible[i] && !this.options.allowMultipleOpen) {
				//else (not clicked) if it's visible, hide it, unless we allow multiple open
					//if ! wait and timer
					if(!(this.options.wait && this.timer)) {
						//hide it
						update = true;
						this.hideThis(i);
					} else {
						this.previousClick = null;
						err = true;
					}
				} //else it's not clicked, it's not open, so leave it alone because we allow multiples
				//set up the effect instructions
				if(update) objObjs[i] = $merge(this.h, $merge(this.o, this.w));
			}, this);
			//if there's an error, just stop
			if (err) return false;
			//execute the custom function, which resizes everything.
			return this.custom(objObjs);
		}
		return false;
	},
/*	Property: showSection
		Opens a section of the accordion if it's not open already.

		Arguments:
		i - (integer) the index of the section to show
		useFx - (boolean) open it immediately (false) or slide it open using the effects (true);  defaults to false;
	*/
	showSection: function(i, useFx){
		if($pick(useFx, false)) {
			if (!this.elementsVisible[i]) this.toggleSection(i);
		} else {
			this.setSectionStyle(i,$(this.elements[i]).scrollWidth, $(this.elements[i]).scrollHeight, 1);
			this.elementsVisible[i] = true;
			this.fireEvent("onActive", [this.togglers[i], this.elements[i]]);
		}
	},
/*	Property: hideSection
		Closes a section of the accordion if it's not closed already.

		Arguments:
		i - (integer) the index of the section to hide
		useFx - (boolean) close it immediately (false) or slide it closed using the effects (true);  defaults to false;
	*/
	hideSection: function(i, useFx){
		if($pick(useFx, false)) {
			if (this.elementsVisible[i]) this.toggleSection(i);
		} else {
			this.setSectionStyle(i,0,0,0);
			this.elementsVisible[i] = false;
			this.fireEvent("onBackground", [this.togglers[i], this.elements[i]]);
		}
	},
	//internal function; sets a section (i) to the width (w), height (h), and opacity (o) passed in
	setSectionStyle: function(i,w,h,o){
			if (this.options.opacity) $(this.elements[i]).setOpacity(o);
			if (this.options.height) $(this.elements[i]).setStyle('height',h+'px');
			if (this.options.width) $(this.elements[i]).setStyle('width',w+'px');
	},
/*	Property: showAll
		Opens all the elements in the accordion immediately; used on startup	*/
	showAll: function(){
		if(this.options.allowMultipleOpen){
			this.elements.each(function(el,idx){
					this.showSection(idx, false);
			}, this);
		}
	},
/*	Property: hideAll
		Closes all the elements in the accordion immediately; used on startup	*/
	hideAll: function(){
		if(this.options.allowMultipleOpen){
			this.elements.each(function(el,idx){
				this.hideSection(idx, false);
			}, this);
		}
	},
/*	Property: openSection
		Opens specific sections of the accordion immediately; used on startup.

		Arguments:
		sections - array of indexes to open.
	*/
	openSections: function(sections) {
		if(this.options.allowMultipleOpen){
			this.elements.each(function(el,idx){
				if(sections.test(idx) && this.options.start != 'all-closed') this.showSection(idx, false); /**/
				else this.hideSection(idx, false);
			}, this);
		}
	}
});
MultipleOpenAccordion.implement(new Options);
MultipleOpenAccordion.implement(new Events);

//END MultipleOpenAccordion

// Start Print and Email
function printWindow(e)
{
	var printPopUp = window.open('/CmeWeb/printpopup.jsp', 'cal', 'top=5,left=5,location=0,width=800,height=600,scroll=1');
	function findMain()
	{
		while(!printPopUp.document.getElementById('main')){}
		var tableDiv = new Element('div');
		tableDiv.injectAfter(e);
		tableDiv.adopt(e);
		printPopUp.document.getElementById('main').innerHTML = tableDiv.innerHTML;

	}
	//dofindMain = findMain.delay(1000);
	findMain();
}

function printDaughterWindow(div)
{
	var printPopUp = window.open('/CmeWeb/printpopupforkid.jsp', 'TITLE', 'top=5,left=5,location=0,width=720,height=600,scroll=1');
	function findMain()
	{
		while(!printPopUp.document.getElementById('main')){}
		var tableDiv = new Element('div');
		tableDiv.injectAfter(div);
		tableDiv.adopt(div);
		printPopUp.document.getElementById('main').innerHTML = tableDiv.innerHTML;
		printPopUp.document.getElementById('printanc').style.visibility = 'hidden';
	}
	findMain();
}

function emailIt(e)
{
	dhtmlwindow.open('isv', 'ajax', '/CmeWeb/mailform.ctl?element='+e, 'Email', 'width=640px,height=589px,center=1,resize=0,scrolling=0');
}

// End print and email

// Start chart image loading and switching
function getContractCode(code,date) {
	var venueFlagIfNeeded = "";
	var d = parseInt(date.substr(0,2), 10);
	var month = "FGHJKMNQUVXZ".charAt(date.substr(0,2)-1);
	var year = parseInt(date.substr(2,2),10);

	if(code.indexOf('FLOOR') > -1)
	{
		venueFlagIfNeeded = "=2";
		code = code.substring(0, code.indexOf('FLOOR'));
	}
	else if(code.indexOf('GLOBEX') > -1)
	{
		venueFlagIfNeeded = "=1";
		code = code.substring(0, code.indexOf('GLOBEX'));
	}

	if (d > 0)
	{
		return code+" "+month+year+venueFlagIfNeeded;
	}
	else if (d == 0)
	{
		return code+venueFlagIfNeeded;
	}
	else
	{
		return code+" "+(-d)+"!"; //+venueFlagIfNeeded; Removed 10/06/2009 by James Owens -- the venueFlagIfNeeded var was introducing errors into the chart URL for products such as Asian Gold (QSGLOBEX, QSFLOOR)
	}
}

function DefaultChart(code,date,size) {
	this.url="http://charts.marketcenter.com/cis/cbotcis";
	this.cont=encodeURIComponent(getContractCode(code,date));
	this.period="D";
	this.bartype="BAR";
	this.bardensity="LOW";
	this.showextendednames=true;
	this.headerbackground="255,255,255";
	this.headerforeground="0,0,0";
	this.headerdatacolor="0,0,0";
	this.size=size;
}

function getChartUrl(chart) {
	var params = "";
	for (param in chart) {
		if (param != 'url' && chart[param]!=null) {
			params = params.concat((params.length == 0) ? "?" : "&");
			params = params.concat(param + "=" + chart[param]);
		}
	}
	return chart.url+params;
}

function getChartImage(chart) {
	var chartImage = new Image();
	chartImage.src = getChartUrl(chart);
	return chartImage.src;
}

function switchImage(imgElement,chart) {
	if (waitForChart==null) {
		waitForChart = new Image();
 		waitForChart.src = "/images/ajax-loader.gif";
	}
	imgElement.src=waitForChart.src;
	imgElement.src=getChartImage(chart);
	imgElement.alt=chartParams.cont;
}

function updateChartCode(chart,code,imgElement) {
	chart.cont = encodeURIComponent(code);
	switchImage(imgElement,chart);
}


function updateChartType(chart,type,imgElement) {
	chart.bartype = type;
	switchImage(imgElement,chart);
}

function updateChartContractDate(chart,code,date,imgElement) {
	chart.cont=encodeURIComponent(getContractCode(code,date));
	switchImage(imgElement,chart);
}

function updateChartPeriod(chart,period,imgElement, varminutes) {
	chart.period = period;
	chart.varminutes=(period=='V') ? varminutes : null;
	switchImage(imgElement,chart);
}
function updateChart(chart, code, imgElement, period, varminutes, month, year, study, bartype, bardensity, study0, study1, study2, study3) {
	chart.cont=encodeURIComponent(getContractCode(code,month+""+year));
	chart.period=(period.length > 0) ? period : null;
 	chart.varminutes=(varminutes.length > 0 && period=='V') ? varminutes : null;
	chart.study=(study.length > 0) ? study : null;
	chart.bartype=(bartype.length > 0) ? bartype : null;
	chart.bardensity=(bardensity.length > 0) ? bardensity : null;
	chart.study0=(study0.length > 0) ? study0 : null;
	chart.study1=(study1.length > 0) ? study1 : null;
	chart.study2=(study2.length > 0) ? study2 : null;
	chart.study3=(study3.length > 0) ? study3 : null;
	switchImage(imgElement,chart);
}
var waitForChart;
// End chart image loading and switching