var windowLocation = true;
if (self != top){windowLocation = false;}
else {windowLocation = true;}
var activeId = "";
var activeIndicatorId = "";
function subMenu(id){
	var subMenuId=id+"Menu";
	if (activeId != ""){
		var prevMenuId = activeId+"Menu";
		var prevMenuObj = document.getElementById(prevMenuId);
		prevMenuObj.style.display="none";
	}
	else{
		var prevMenuId = subMenuId;
		var prevMenuObj = document.getElementById(prevMenuId);
		prevMenuObj.style.display="none";
	}
	var indicatorId = id+"Indicator";
	
	var activeIdObj = document.getElementById(activeId);
	var activeIndicatorIdObj = document.getElementById(activeIndicatorId);
	
	var topCurveUpper = document.getElementById("topCurveUpper");
	var topCurveLower = document.getElementById("topCurveLower");
	
	if (activeIndicatorId != ""){
		activeIdObj.className="menuOff";
	}
	if (activeIndicatorId != ""){
		activeIndicatorIdObj.style.visibility="hidden";
	}
	if (id == "home"){
		topCurveUpper.style.marginLeft = "0px";
		topCurveUpper.style.marginRight = "2px";
		topCurveLower.style.marginLeft = "0px";
		topCurveLower.style.marginRight = "1px";
	}
	else if (id == "client"){
		topCurveUpper.style.marginLeft = "2px";
		topCurveUpper.style.marginRight = "0px";
		topCurveLower.style.marginLeft = "1px";
		topCurveLower.style.marginRight = "0px";
	}
	else{
		topCurveUpper.style.marginLeft = "2px";
		topCurveUpper.style.marginRight = "2px";
		topCurveLower.style.marginLeft = "1px";
		topCurveLower.style.marginRight = "1px";
	}
	document.getElementById(id).className="menuOn";
	document.getElementById(subMenuId).style.display="inline";
	document.getElementById(indicatorId).style.visibility="visible";
	activeId=id;
	activeIndicatorId=indicatorId;
};

function changeBgColor(element){
	if (element.className != "menuOver" && element.className != "menuOn"){
		element.className = "menuOver";
		element = null;
	}
	else{
		if (element.className == "menuOver"){
			element.className = "menuOff";
			element = null;
		}
	}
};

function changeSubMenuBgColor(element){
	if (element.className != "subMenuOver" && element.className != "subMenuOn"){element.className = "subMenuOver";}
	else{ if (element.className == "subMenuOver"){element.className = "subMenuOff";} }
};

function displayNav(mainSec, subSec){
	var subSectionId = mainSec + subSec;
	var subSection = document.getElementById(subSectionId);
	subMenu(mainSec);
	subSection.className = "subMenuOn";
};

//var topNavSectionArray = ['home','portfolio','trade','research','tools','goals','client'];
var topNavSectionArray = ['home','portfolio','trade','tools','goals','client'];

function topNavIndicatorClass(tableID, sectionArray){
	this.id = tableID;
	this.tableContainer = document.getElementById(this.id);
	this.sectionArray = sectionArray;
	var j = this.sectionArray.length;
	for (var i = 0; i < j; i++){
		var oIndicatorCell = document.createElement("td");
		oIndicatorCell.id = this.sectionArray[i] + "Indicator";
		if (i == 0 || i == (j-1)){oIndicatorCell.colSpan = 2;}
		var oIndicatorDiv1 = document.createElement("div");
		oIndicatorDiv1.className = "indicator1";
		var oIndicatorDiv2 = document.createElement("div");
		oIndicatorDiv2.className = "indicator2";
		oIndicatorCell.appendChild(oIndicatorDiv1);
		oIndicatorCell.appendChild(oIndicatorDiv2);
		this.tableContainer.appendChild(oIndicatorCell);
	}
};

function topNavMainTabClass(tableID){
	this.id = tableID;
	this.tableContainer = document.getElementById(this.id);
};

topNavMainTabClass.prototype.addItem = function(id, text, url){
	var oMainTabCell = document.createElement("td");
	oMainTabCell.id = id;
	oMainTabCell.className = "menuOff";
	oMainTabCell.onmouseover = function(){changeBgColor(this)};
	oMainTabCell.onmouseout = function(){changeBgColor(this)};
	if (windowLocation){
		oMainTabCell.onclick = function(){document.location.href = url;};
	}
	else{
		oMainTabCell.onclick = function(){parent.location.href = url;};
	}
	var oMainTabDiv = document.createElement("div");
	var oMainTabAnchor = document.createElement("a");
	oMainTabAnchor.href = url;
	oMainTabAnchor.appendChild(document.createTextNode(text));
	oMainTabDiv.appendChild(oMainTabAnchor);
	oMainTabCell.appendChild(oMainTabDiv);
	this.tableContainer.appendChild(oMainTabCell);
};

function topNavSubNavClass(tableID){
	this.id = tableID;
	this.tableContainer = document.getElementById(this.id);
	this.initSubnav = true;
};

topNavSubNavClass.prototype.addItem = function(mainSecId, padOverride, pageId, url, text, parentId, last){
	if (parentId){
		var parentRow = document.getElementById(parentId + "MenuRow");
		var oSubNavCell = document.createElement("td");
		oSubNavCell.id = mainSecId + pageId;
		oSubNavCell.className = "subMenuOff";
		oSubNavCell.onmouseover = function(){changeSubMenuBgColor(this);};
		oSubNavCell.onmouseout = function(){changeSubMenuBgColor(this);};
		if (windowLocation){
			oSubNavCell.onclick = function(){document.location.href = url;};
		}
		else{
			oSubNavCell.onclick = function(){parent.location.href = url;};
		}
		if (parentRow.className && parseInt(parentRow.className) > 0){
			oSubNavCell.style.paddingLeft = parseInt(parentRow.className) + "px";
			oSubNavCell.style.paddingRight = parseInt(parentRow.className) + "px";
		}
		var oSubNavCellAnchor = document.createElement("a");
		oSubNavCellAnchor.href = url;
		oSubNavCellAnchor.appendChild(document.createTextNode(text));
		oSubNavCell.appendChild(oSubNavCellAnchor);
		parentRow.appendChild(oSubNavCell);
		if (!last){this.createDivider(parentRow);}
	}
	else{
		if (this.initSubnav){
			this.tableContainer.innerHTML = "";
			this.initSubnav = false;
		}
		var oSubNavDiv = document.createElement("div");
		oSubNavDiv.id = mainSecId + "Menu";
		oSubNavDiv.className = "subMenuItem";
		oSubNavDiv.onclick = function(){this.blur();};
		var oSubNavTable = document.createElement("table");
		oSubNavTable.align = "center";
		oSubNavTable.cellPadding = 0;
		oSubNavTable.cellSpacing = 0;
		var oSubNavTBody = document.createElement("tbody");
		var oSubNavRow = document.createElement("tr");
		oSubNavRow.id = mainSecId + "MenuRow";
		if (padOverride){oSubNavRow.className = padOverride.toString();}
		oSubNavTBody.appendChild(oSubNavRow);
		oSubNavTable.appendChild(oSubNavTBody);
		oSubNavDiv.appendChild(oSubNavTable);
		this.tableContainer.appendChild(oSubNavDiv);
	}
};

topNavSubNavClass.prototype.createDivider = function(parent){
	var oSubNavDividerCell = document.createElement("td");
	oSubNavDividerCell.className = "subdivider";
	oSubNavDividerCell.appendChild(document.createTextNode("|"));
	oSubNavDividerCell.style.paddingLeft = 0;
	oSubNavDividerCell.style.paddingRight = 0;
	oSubNavDividerCell.style.width = "1px";
	parent.appendChild(oSubNavDividerCell);
};

//subnav items always have padOverride set to 0, mainSection items can set a custom value if need be


//WINDOW RESIZE
function onWindowResize(){
	if(document.getElementById('frame') == null){
		return;
	}
	var container = document.getElementById('frame');
	if (document.body.clientWidth < 800){
		container.style.width = "760px";
	}
	else if (document.body.clientWidth >= 1024){
		container.style.width = "984px";
	}
	else{
		container.style.width = "auto";
	}
};

function inputFillCheck (item, initValue) {
	if (item.value==""){
		item.className="inputFillOff";
		item.value=initValue;
	}		
	else if (item.value==initValue){
		item.value="";
		item.className="inputFillOn";
	}	
};

function loadIframeNav(){
	var pageURL = document.location.href;
	var reNav = /nav1=(\w+)&nav2=(\w+)/;
	reNav.test(pageURL);
	var mainSec = RegExp.$1;
	var subSec = RegExp.$2;
	if (mainSec != "" && subSec != ""){
		displayNav(mainSec,subSec);
	}
};

var agt=navigator.userAgent.toLowerCase();
var is_ie=(agt.indexOf("msie")!=-1);
/**********
 * Changes the css style and events for buttons
 **************************/
//button class name constants
var OUTER = "Outer";
var MIDDLE = "Middle";
var INNER = "Inner";
var PRIORITY = "Priority";
function btnOn(id){
	var linkRef = document.getElementById(id);
	if (linkRef){
		var pClass = (linkRef.getAttribute("priority")=="true") ? PRIORITY : ""; //if priority, change class
		changeBtnClass(id,pClass+"On");
		linkRef.onfocus = function(){ changeBtnClass(id,pClass+"Over");} ;
		linkRef.onblur = function(){ changeBtnClass(id,pClass+"On");} ;
		linkRef.onmouseover = function(){ changeBtnClass(id,pClass+"Over");};
		linkRef.onmousedown = function(){//need to also clear onfocus and blur on mousedown for mozilla/firefox conflicts
			if (!is_ie){
				document.getElementById(id).onfocus=null;
				document.getElementById(id).onblur=null;
			}
			changeBtnClass(id,pClass+"Down");
		};
		linkRef.onmouseup = function(){ 
			changeBtnClass(id,pClass+"On") 
		};
		linkRef.onmouseout = function(){ //need to also reset onfocus and blur on mousedown for mozilla/firefox conflicts
			changeBtnClass(id,pClass+"On");
			if (!is_ie){
				document.getElementById(id).onfocus = function(){changeBtnClass(id,pClass+"Over");};
				document.getElementById(id).onblur= function(){changeBtnClass(id,pClass+"On");};	
			}
		};
		linkRef.onclick = linkRef.inlineonclick; 
	}
 };
 
 function btnOff(id) {
	var linkRef = document.getElementById(id);
	if (linkRef){
		var pClass = (linkRef.getAttribute("priority")=="true") ? PRIORITY : ""; //if priority, change class
		changeBtnClass(id,pClass+"Off");
		linkRef.onfocus = null;
		linkRef.onblur = null;
		linkRef.onclick = function(){return false;};
		linkRef.onmouseover = null;
		linkRef.onmousedown = null ;
		linkRef.onmouseup = null;
		linkRef.onmouseout = null;	
	}
 };
 
function changeBtnClass(id,state){
	var btn = document.getElementById(id + OUTER);
	if (btn){
		 btn.className = "btn" + state + OUTER;
		 var middleBtn = document.getElementById(id+MIDDLE);
		 if (middleBtn) middleBtn.className = "btn" + state + MIDDLE;
		 var innerBtn = document.getElementById(id+INNER);
		 if (innerBtn) innerBtn.className = "btn" + state + INNER;
		 innerBtn.style.padding="0";
	}
};

function btnInit(id,priority,on,setwidth,setheight,iconPre,iconPost,smallsize,mini){
	var linkRef = document.getElementById(id); //get a tag link
	var iconImg = "";//for icons
	if (iconPre || iconPost) {
		iconImg = document.createElement("img");
		iconImg.src = (iconPre) ? iconPre: iconPost;
		iconImg.border = "0";
		iconImg.hspace = "4";
		iconImg.style.paddingTop = "2px"
		//iconImg.width = 10;
		//iconImg.height = 10;
	}
	
	if (linkRef){
		var txt = linkRef.firstChild.nodeValue; //get text in link
		var oswidth = linkRef.offsetWidth; //buttons may need to be same width for design, if so, pass width size
		var padding = (smallsize) ?  16 : 21; //add extra width padding
		padding = (mini) ? 0 : padding;
		var width = (setwidth) ? setwidth : oswidth + padding; //get width of link, and add padding
		var height = (setheight) ? setheight : false; //get width of link, and add padding
		linkRef.firstChild.nodeValue = " "; //erase text link
		linkRef.className = "btnLink"; 
		linkRef.style.width = width; //reset link width
		if(height) linkRef.style.height = height;

		if (iconPre || iconPost) {
			width += 11; //size of icon image + buffer
		}
		
		//writing out this structure <a href="#"><div><div></div><div></div></div></a>
		//triple divs for additional borders
		var outerDiv = document.createElement("div"); 
		outerDiv.id = id + OUTER;
		outerDiv.style.width = width + "px";
		if(height) outerDiv.style.height = height + "px";
		
		var middleDiv = document.createElement("div"); 
		middleDiv.id = id + MIDDLE;
		middleDiv.style.width = (width - 2) + "px";
		if(height) middleDiv.style.height = (width - 2) + "px";
		
		var innerDiv = document.createElement("div");
		innerDiv.id = id + INNER;
		innerDiv.style.width = (width - 4) + "px";
		if(height) innerDiv.style.height = (width - 4) + "px";
		if (smallsize) {innerDiv.style.fontSize = "11px";innerDiv.style.lineHeight = "13px";}
		if(mini){innerDiv.style.fontSize = "9px"; innerDiv.style.lineHeight = "9px";}
		
		outerDiv.appendChild(middleDiv);
		middleDiv.appendChild(innerDiv);
		if (iconPre) {
			innerDiv.appendChild(iconImg);
		}
		innerDiv.appendChild(document.createTextNode(txt));
		if (iconPost) {
			innerDiv.appendChild(iconImg);
		}		
		linkRef.appendChild(outerDiv);
						
		if (priority) { //priority setting
		linkRef.setAttribute("priority","true");
		}
		
		//hold on to inline onclick on the original link
		if (linkRef.inlineset!=true) {
			linkRef.inlineonclick = linkRef.onclick; 
			linkRef.inlineset = true;
		}
		on ? btnOn(id) : btnOff(id); //set button states
	}
	return linkRef;
};

function vendorLink(url){
	top.location.href = url;
};



