/**********
 * browser tests
 **************************/
var agt=navigator.userAgent.toLowerCase();
var is_ie=(agt.indexOf("msie")!=-1);
var is_ie5_5=(is_ie && agt.indexOf("5.5")!=-1);
var is_nav = (!is_ie && agt.indexOf('mozilla')!=-1);

/**********
 * Responsible for highlighting selected areas
 **************************/

var pieceHolder = "";
function selectPiece(piecenum) { //used to highlight different sections of a form
	var piece = "p" + piecenum;
	var obj = document.getElementById(piece);
	if (obj.className == "pieceOn") return false;
	obj.className = (obj.className == "pieceOff") ? "pieceOn" : "pieceOff";
	
	if (pieceHolder != "") document.getElementById(pieceHolder).className = "pieceOff";
	pieceHolder = "p" + piecenum;
}
 
 /*image buttons - soon to be deleted*/
 function buttonOn(id,src)
 {
 	document.getElementById(id).disabled = false;
	document.getElementById(id).src = src;
	document.getElementById(id).style.cursor = (is_ie5_5) ? "hand" : "pointer";
 }
 
 function buttonOff(id,src)
 {
 	document.getElementById(id).disabled = true;
	document.getElementById(id).src = src;
	document.getElementById(id).style.cursor = "default";
 }

/**********
 * Changes the css style and events for buttons
 **************************/
//button class name constants
var OUTER = "Outer";
var INNER = "Inner";
var PRIORITY = "Priority";
function btnOn(id){
	var linkRef = document.getElementById(id);
	if (linkRef){
		changeBtnClass(id,"On");
		linkRef.onfocus = function(){ changeBtnClass(id,"Over") } ;
		linkRef.onblur = function(){ changeBtnClass(id,"On") } ;
		linkRef.onmouseover = function(){ changeBtnClass(id,"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,"Down");
		} ;
		linkRef.onmouseup = function(){ 
			changeBtnClass(id,"On") 
		};
		linkRef.onmouseout = function(){ //need to also reset onfocus and blur on mousedown for mozilla/firefox conflicts
			changeBtnClass(id,"On");
			if (!is_ie){
				document.getElementById(id).onfocus = function(){changeBtnClass(id,"Over")};
				document.getElementById(id).onblur= function(){changeBtnClass(id,"On")};	
			}
		} ;
		linkRef.onclick = linkRef.inlineonclick; 
	}
 }
 
 function btnOff(id) {
	var linkRef = document.getElementById(id);
	if (linkRef){
		changeBtnClass(id,"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){
		 var prty = document.getElementById(id+PRIORITY);
		 if (prty) prty.className = "priority"+state;


btn.className = "btn" + state;
		 var innerBtn = document.getElementById(id+INNER);
		 if (innerBtn) innerBtn.className = "btn" + state + INNER;
	}
}

function btnInit(id,priority,on,setwidth,mozmargin){
	var linkRef = document.getElementById(id); //get a tag link
	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 =  12; //add extra width padding
		var width = (setwidth) ? setwidth : oswidth + padding; //get width of link, and add padding
		linkRef.firstChild.nodeValue = " "; //erase text link
		linkRef.className = "btnLink"; 
		linkRef.style.width = width; //reset link width
		if (mozmargin) {
			if (!is_ie) linkRef.style.marginRight = mozmargin + "px"; //mozilla firefox need extra margin due to floating left a
		} else {
			if (!is_ie) linkRef.style.marginRight = "6px"; //mozilla firefox need extra margin due to floating left a
		}
		
		//writing out this structure <a href="#"><div><div></div></div></a>
		//double divs for additional borders
		var outerDiv = document.createElement("div"); 
		outerDiv.id = id + OUTER;
		outerDiv.style.width = width + "px";
		
		var innerDiv = document.createElement("div");
		innerDiv.id = id + INNER;
		innerDiv.style.width = (width - 2) + "px";
		
		outerDiv.appendChild(innerDiv);
		innerDiv.appendChild(document.createTextNode(txt));
		
		//if button has priority, add another wrapper div
		if (priority){
			var priorityDiv = document.createElement("div");
			priorityDiv.id = id + PRIORITY;
			priorityDiv.className = "priorityOn";
			priorityDiv.style.width = (width + 2) + "px";
			priorityDiv.appendChild(outerDiv);
			linkRef.appendChild(priorityDiv);
		}
		else linkRef.appendChild(outerDiv);
		
		//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
	}
}

/**********
 * Changes the color of a row
 **************************/
function changeColorRow(rowid,rowclass)
{
	var row = document.getElementById(rowid);
	if (row) row.className = rowclass; 
	//alert(rowclass);
}
function changeColorRow1(rowid,rowclass)
{
	var row = document.getElementById(rowid);
	row.className = rowclass; 
	alert(rowclass);
}

// checks to see if there are ~=| in the orderstring
function invalidChars(value) {
	var regEx = /[~=|]/g;
	var newValue = value.replace(regEx,"");
	return newValue;
}

// generic rollover for the info icon.


function iconRollOver(myObj) {
	document.getElementById(myObj).src = helpicon_over.src;
}

function iconRollOut(myObj) {
	document.getElementById(myObj).src = helpicon_off.src;
}

var showContHelp;

function helpIconShow(txt, secondsToCloseAfterDisplay ) {
	showInfoBox();
	if (txt == "b") {
		infoBoxWidth=findWidth("infobox");
		document.getElementById("infobox").style.top=findPosY("helpIcon")+14;
		document.getElementById("infobox").style.left=findPosX("helpIcon")-infoBoxWidth+10;
	}
	
	//default to 3 seconds if no delay passed in
	if ( secondsToCloseAfterDisplay == null )
	{
			secondsToCloseAfterDisplay = 3;
	}
	
	showContHelp = setTimeout("hideInfoBox()", secondsToCloseAfterDisplay * 1000); 
	
}

function showInfoBox() {
	clearTimeout(showContHelp);
	document.getElementById("infobox").style.visibility = "visible";
}

function hideInfoBox() {
	document.getElementById("infobox").style.visibility = "hidden";
	showContHelp = setTimeout("hideInfoBox()", 3000);
}

function findPosX(obj){
	myobj=document.getElementById(obj)
	var posleft = 0;
	if (myobj.offsetParent){
		while (myobj.offsetParent){
			posleft += myobj.offsetLeft
			myobj = myobj.offsetParent;
		}
	}
	else if (myobj.x) posleft += myobj.x;
	return posleft;
}

function findPosY(obj){
	myobj=document.getElementById(obj)
	var postop = 0;
	if (myobj.offsetParent){
		while (myobj.offsetParent){
			postop += myobj.offsetTop
			myobj = myobj.offsetParent;
		}
	}
	else if (myobj.y) postop += myobj.y;
	return postop;
}

function findWidth(objName){
	page = parent.main.document;
	return document.getElementById(objName).offsetWidth;
}

var printWindow = null;
function printFriendly(pageHandler,form) {
	var target = "printfriendly";
	if (form) {
		form.mode.value = "print"; //must include this in main form
		form.target = target;
		popPrintFriendly('/data/images/clear.gif',target);
		form.submit();
	} else {
		popPrintFriendly('/cgi-bin/apps/u/' + pageHandler + '?mode=print',target);
	}	
}

function popPrintFriendly(url,target) {
	if (printWindow) {
		if (printWindow.closed) printWindow = window.open(url,target,'resizable=1,status=1,scrollbars=1');
		} else printWindow = window.open(url,target,'resizable=1,status=1,scrollbars=1');
	printWindow.focus();
}

function downloadPage(pageHandler,form) {
	if (form) {
		form.mode.value = "download"; //must include this in main form
		form.target = "";
		form.submit();
	} else {
		location.href = '/cgi-bin/apps/u/' + pageHandler + '?mode=download';
	}
}

/**************************
* snapIframe - JP
* IE bug stopper - Snaps an iframe behind the div so that drop down boxes
* do not punch thru on ie. 
****************************/
function snapIframe( iframeId, divToSnapBehindId )
{
	//only snap for ie
	if ( !document.all ) return
	
	//get the iframeId & div objs
	var iframe = document.getElementById( iframeId );
	var divToSnapBehind = document.getElementById( divToSnapBehindId ); 
	
	//copy the divs props to the iframe.
	iframe.style.width = divToSnapBehind.offsetWidth;
	iframe.style.height = divToSnapBehind.offsetHeight;
	iframe.style.top = divToSnapBehind.style.top;
	iframe.style.left = divToSnapBehind.style.left;
	iframe.style.zIndex = divToSnapBehind.style.zIndex - 2;
	iframe.style.display = '';
	
}


<!--
/**************************
* breadCrumb obj
* ****************************/
function breadCrumb( name, linkUrl )
{
	this.name = name;
	this.linkUrl = linkUrl
	
	//returns an anchor node for this bread crumb
	this.getAnchorTag = function()
	{
		//create the anchor
		var breadCrumbAnchor = document.createElement("a");
		var breadCrumbAnchorText = document.createTextNode( this.name );
	
		//set the link
		breadCrumbAnchor.href = this.linkUrl;
		breadCrumbAnchor.appendChild( breadCrumbAnchorText );
		
		return breadCrumbAnchor;
	}
} 


/**************************
* breadCrumb static Constatnts
*****************************/
var BREADCRUMB_MARKET_RESEARCH = new breadCrumb( "Research: Markets" , "/cgi-bin/apps/u/CBSMarkets?landingpage=0&pagehandler=PHCbsMarkets" );
var BREADCRUMB_STOCK_RESEARCH = new breadCrumb( "Research: Stocks" , "/cgi-bin/apps/u/CBSMarkets?landingpage=0&pagehandler=PHCbsStocks" );
var BREADCRUMB_FUNDS_RESEARCH = new breadCrumb( "Research: Funds" , "/cgi-bin/apps/u/CBSMarkets?landingpage=0&pagehandler=PHCbsFunds" );
var BREADCRUMB_FUNDFAMILY_RESEARCH = new breadCrumb( "Fund Families" , "/cgi-bin/apps/u/FundFamilies?pagehandler=PHMutualFundFamily&section=fundFamily&view=listFundFamilies" );
var BREADCRUMB_BONDS_RESEARCH = new breadCrumb( "Research: Bonds" , "/cgi-bin/apps/u/CBSMarkets?landingpage=0&pagehandler=PHCbsBonds" );
var BREADCRUMB_ETF_RESEARCH = new breadCrumb( "Research: ETFs" , "/cgi-bin/apps/u/CBSMarkets?landingpage=0&pagehandler=PHCbsEtf" );
var BREADCRUMB_SCREENER_RESEARCH = new breadCrumb( "Research: Screeners" , "/cgi-bin/apps/u/CBSScreeners" );
var BREADCRUMB_SCREENER_FUND = new breadCrumb( "Mutual Fund Screener" , "/cgi-bin/apps/u/CBSScreeners?pagehandler=PHFundScreenerSelect" );
var BREADCRUMB_LETTER_OF_INSTRUCTION = new breadCrumb( "Letter of Instruction" , "/cgi-bin/apps/u/PLoad?pagename=forms/banking/indexLOI.html" );
// see title.tempate for dynamic bread crumbs.

/**************************
* writeBreadCrumb
* Writes out the breadcrumbs for the page.
* parms: n args of breadcrumb object 
* ****************************/
function writeBreadCrumb()
{
	var dynamicTitle = document.getElementById("dynamicTitle");
	
	//assert bread crumbs are visible on this page.
	if (dynamicTitle == null ) return;
	
	// remove any bread crumbs. Some pages with tabs my need 
	// to rewrite crumbs so clear out crumbs if they are already present.
	if (dynamicTitle.childNodes.length > 0 )
	{
		dynamicTitle.removeChild( dynamicTitle.firstChild )
	}
	
	
	//create a div to hold the breadcrumbs
	breadCrumbDiv = document.createElement('div');
	
	//build out the bread crumbs - you get the home link for free
	breadCrumbDiv.appendChild( BREADCRUMB_HOME.getAnchorTag() );
	breadCrumbDiv.appendChild( document.createTextNode(" > ") );
	
	//read the args list passed into this func and write out crumbs for each
	var breadCrumbLength = writeBreadCrumb.arguments.length -1
	for ( i=0; i < breadCrumbLength; i++)
	{
		var currentCrumb = writeBreadCrumb.arguments[ i ];
		breadCrumbDiv.appendChild( currentCrumb.getAnchorTag() );
		breadCrumbDiv.appendChild( document.createTextNode(" > ") );
	}
	
	//current page is the last arg passed into the function
	var currentPage = writeBreadCrumb.arguments[ breadCrumbLength ];

	//create a span to hold the active page. ( this crumb has no link and looks diffrent [bold] )
	activeBreadCrumbSpan = document.createElement('span');
	activeBreadCrumbSpan.appendChild( document.createTextNode( currentPage ) );
	activeBreadCrumbSpan.className = "breadCrumbActive";
	breadCrumbDiv.appendChild( activeBreadCrumbSpan );

	//add div to breadCrumb table cell
	dynamicTitle.appendChild( breadCrumbDiv );
	
}

function microchartsWin(url){
	var win = window.open(url, 'mcWin', 'width=608,height=330,scrollbars=yes,resizable=yes,status=yes')
}

/**************************
* setCheckedByValue
* selects a value in a drop down list based on value passed in.
* parms: menuobj - ref to the select box to use
* parms: value - the value of the option to select.
* ****************************/
function setCheckedByValue( menuobj, value )
{
	//find the value and select it
	for ( var i=0; i < menuobj.length; i++ ) 
	{
		menuobj[i].checked = ( menuobj[i].value == value ) ? true : false
	}
}

/**************************
* setSelectedByValue
* selects a value in a drop down list based on value passed in.
* parms: menuobj - ref to the select box to use
* parms: value - the value of the option to select.
* ****************************/

function setSelectedByValue( menuobj, value )
{
	//find the value and select it
  for ( var i=0; i < menuobj.options.length; i++ ) 
  {
	//is the value set on the option?
		if( menuobj.options[i].value )
	  {
		  menuobj.options[i].selected = ( menuobj.options[i].value == value ) ? true : false
		}
		//if not check the text on the option
		else
		{
			menuobj.options[i].selected = ( menuobj.options[i].text == value ) ? true : false       
		}
	}   
}


