//IMAGE ROLLOVERS
function imgOver(imgName) { 
	if (!document.layers){
		if (document.all) document.all[imgName].src = eval(imgName + "_over.src"); 			
		else document.getElementById(imgName).src = eval(imgName + "_over.src"); 
	}
}
function imgOn(imgName) { 
	if (!document.layers){
		if (document.all) document.all[imgName].src = eval(imgName + "_on.src"); 			
		else document.getElementById(imgName).src = eval(imgName + "_on.src"); 
	}
}
function imgOff(imgName) { 
	if (!document.layers){
		if (document.all) document.all[imgName].src = eval(imgName + "_off.src"); 			
		else document.getElementById(imgName).src = eval(imgName + "_off.src"); 
	}
}
function imgSelected(imgName) { 
	if (!document.layers){
		if (document.all) document.all[imgName].src = eval(imgName + "_sel.src"); 			
		else document.getElementById(imgName).src = eval(imgName + "_sel.src"); 
	}
}

if (document.layers) {
  visible = 'show';
  hidden = 'hide';
} else if (document.all||document.getElementById) {
  visible = 'visible';
  hidden = 'hidden';
}

//IMAGE CACHING
var oImgPath = new Object();	
oImgPath.topnav = "cboe/images/nav/";

function cacheImg(name,src,rollover,type){
	if (!type) var type = "gif";
	if (rollover==true){
		eval(name + "_off =  new Image");
		eval(name + "_off.src = \'" + src + name + "_off." + type + "\'");
		eval(name + "_on =  new Image");
		eval(name + "_on.src = \'" + src + name + "_on." + type + "\'");
		eval(name + "_over =  new Image");
		eval(name + "_over.src = \'" + src + name + "_over." + type + "\'");
		eval(name + "_sel =  new Image");
		eval(name + "_sel.src = \'" + src + name + "_sel." + type + "\'");
	} else {
		eval(name + " = new Image");
		eval(name + ".src = \'"+src+name+"."+type+"\'");
	}
}

function showLayer(id){
	if (!document.layers){
		if (document.all) document.all[id].style.visibility=visible;			
		else document.getElementById(id).style.visibility=visible;
	}
}

function hideLayer(id){
	if (!document.layers){
		if (document.all) document.all[id].style.visibility=hidden;			
		else document.getElementById(id).style.visibility=hidden;
	}
}

function highlightParent(id){		
	setTimeout("imgOver('"+ id +"')",1);	
	
}

function OverParent(id){
	setTimeout("imgOn('"+ id +"')",1);	
	
}

function restoreParents(){
	for(i=0;i<imageArray.length;i++){		
		var tempId = 'btn_' + imageArray[i]
		if (menuId == i) {
			setTimeout("imgSelected('"+ tempId +"')",1);
		} else {
			setTimeout("imgOff('"+ tempId +"')",1);		
		}
	}
}

function restoreChildLayers(){
	for(i=0;i<layerArray.length;i++){		
		var tempId = layerArray[i] + '_layer'
		hideLayer(tempId);
	}
}

function onParent(id,childexists){
	var childid= id+'_layer';
	var parentid = 'btn_' + id;
	if (timerID) clearTimeout(timerID);				
			restoreParents();
			highlightParent(parentid);
			restoreChildLayers();
	if (childexists) showLayer(childid);
}
var timeout = 100;
var timerID;

function offParent(id,childexists){ 
	var parentid = 'btn_' + id;
	if (childexists){ 
		timerID = setTimeout('timeup()',timeout); 
		OverParent(parentid);
	} else { 
		restoreParents();
	} 
}

function onChild(){ clearTimeout(timerID); }

function offChild(){ timerID = setTimeout('timeup()',timeout); }

function timeup(){
	restoreParents();
	restoreChildLayers();
	
}


var layerArray = new Array('mycboe','quotes','data','products','trading_tools','strategies','learning_center','about_cboe','institutional','brokers');
var imageArray = new Array('mycboe','quotes','data','products','trading_tools','strategies','learning_center','about_cboe','institutional','brokers');

for(i=0;i<imageArray.length;i++){		
	var tempId = 'btn_' + imageArray[i]
	cacheImg(tempId,oImgPath['topnav'],true);	
}

//set selected item ON.
function setMenu() {
	if (menuId >= 0) {
		var tempId = 'btn_' + imageArray[menuId];
		setTimeout("imgSelected('"+ tempId +"')",1);
	}
}











// Open help window
function openHelp(id) {
  var objWindow;
  objWindow=window.open ('/help.j?help_id='+id, '_blank', 'scrollbars=yes,status=no,width=450,height=150')
  objWindow.Scroll="Yes";
//  objWindow.focus();
  return ;
}

function openSpreadHelp(id, page) {
  var objWindow;
  objWindow=window.open ('/help.j?help_id='+id.toLowerCase()+'&page='+page, '_blank', 'scrollbars=yes,status=no,width=450,height=150')
  objWindow.Scroll="Yes";
//  objWindow.focus();
  return ;
}

function openBacktestingHelp(id, param) {
  var objWindow;
  objWindow=window.open ('/help.j?help_id='+id.toLowerCase()+'&param='+param, '_blank', 'scrollbars=yes,status=no,width=450,height=150')
  objWindow.Scroll="Yes";
//  objWindow.focus();
  return ;
}
//Setting up cookie for nDays
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + "; path=/; expires="+expire.toGMTString();
}

// reading cookie value
function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetSection(nnSection) {
  var nSection = nnSection;

  if(eval("document.all")==null)
    return;


  if(nnSection<0)
    nSection = (-nnSection);

  if(eval("document.all.section"+(nnSection<0?"_":"")+nSection)==null)
    return;

  var sections = ReadCookie('lSection');
  var sectionVal = eval("document.all.section"+(nnSection<0?"_":"")+nSection+".style.display");
  if(sections==null || sections.length<7 || sections.length>7)
    sections = "0100000";

  SetCookie( "lSection", sections.substring(0,nnSection+1)+(sectionVal==''?"1":"0")+sections.substring(nnSection+2), 30);
  //alert(sections.substring(0,nnSection+1)+(sectionVal==''?"1":"0")+sections.substring(nnSection+2));
}


function restoreSections(itemSec) {
  var sections = ReadCookie('lSection');
  if(sections==null || sections.length<7 || sections.length>7)
    sections = "0100000";

  if(eval("document.all")==null)
    return;

  if(itemSec==1) {
    for(var i=1; i<sections.length; i++) {
      if(eval("document.all.section"+(i-1))==null)
       continue;
      eval("document.all.section"+(i-1)+".style.display="+(sections.charAt(i)=='1'?"''":"'none'"));
    }
  } else {
      if(eval("document.all.section_1")==null)
       return;
      eval("document.all.section_1.style.display="+(sections.charAt(i)=='1'?"''":"'none'"));
  }

}


