function runOnLoad(){
  // dummy function
}

String.prototype.trim = function() {
  return this.replace(/^\s*/,"").replace(/\s*$/,"");
}
String.prototype.startsWith = function(str) {
  return (this.indexOf(str) == 0);
}
String.prototype.endsWith = function(str) {
  return (this.length - this.indexOf(str) == str.length);
}

// popup windows
var a_opened_window;
function openWindow(url, width, height, title, showMenu){
  if(!a_opened_window || a_opened_window.closed){
    if (showMenu) {
      var window_attributes = "height=" + height + ",width=" + width + ",statusbar=no,resizable=yes,scrollbars=yes,menubar=1,left=120,top=120"
    } else {
      var window_attributes = "height=" + height + ",width=" + width + ",statusbar=no,resizable=yes,scrollbars=yes,menubar=no,left=120,top=120"
    }
    if(openWindow.arguments.length > 4){
    var i=4
      for(i; i < openWindow.arguments.length; i++){
        window_attributes += openWindow.arguments[i]
      }
    }
    if(!title || title.length == 0){
      title = "subwindow"
    }
    a_opened_window = window.open(url,title,window_attributes);
  }else{
    a_opened_window.location.href = url
  }
  a_opened_window.focus();
}

// close window, used to close popup windows
function closeWindow(){
  if(a_opened_window){
    a_opened_window.close();
  }
}


function openWindowSelf(url) {
    document.location.href=url
}

//fund dropdown on fund detail page
function selectFund(selObj){
  //document.fundSelect.fundId.value = "SAVE";
  if (selObj.options[selObj.selectedIndex].value.trim() != "") {
    document.fundSelect.submit();
  }
}

function printAlert(alertMessage){
  alert(alertMessage);
}

function printPage(){
  window.print();
}

// selects/deselects all checkboxes in the given form
function updateAllCheckboxes(form, checked) {
  for(i = 0; i < form.elements.length; i++) {
    if(form.elements[i].type == "checkbox") {
      if(checked == true) {
        form.elements[i].checked = true;
      }
      else {
        form.elements[i].checked = false;
      }
    }
  }
}

// ensure that at least one checkbox has been
// checked in the given form
function isAtLeastOneSelected(form) {
  for(i = 0; i < form.elements.length; i++) {
    if(form.elements[i].type == "checkbox") {
      if(form.elements[i].checked == true) {
        return true;
      }
    }
  }
  return false;
}

// disables part of the email notify form
// if the user has selected "Do not notify me"
function doFundDist(enable) {
  if(!enable) {
    // disable stuff
    document.forms["email_notify"].includeAllDistributions[0].disabled = true;
    document.forms["email_notify"].includeAllDistributions[1].disabled = true;
    document.forms["email_notify"].funds.disabled = true;
    document.forms["email_notify"].change_funds.disabled = true;
    document.getElementById("intervalSelect").disabled = true;
  }
  else {
    // enable stuff
    document.forms["email_notify"].includeAllDistributions[0].disabled = false;
    document.forms["email_notify"].includeAllDistributions[1].disabled = false;
    document.forms["email_notify"].funds.disabled = false;
    document.forms["email_notify"].change_funds.disabled = false;
    document.getElementById("intervalSelect").disabled = false;
  }
}

// lihaze: home page show/hide table rows and text and arrow
function showHide(showText, hideText, theRadio, theClass) {
  if (browser.isIE){
    hideRowClass =  "block"
  }
  else{
    hideRowClass =  "table-row"
  }

  textShow = document.getElementById(showText);
  textHide = document.getElementById(hideText);
  tBody = theRadio.parentNode;
    if (textShow.style.display == "none") {
      textShow.style.display="";
      textHide.style.display="none";
        while(tBody.nodeName!="TBODY"){
          tBody = tBody.parentNode;
                                      }
        rows = tBody.rows;
        for(i=0;i<rows.length;i++){
        if(rows[i].className==theClass) {
        rows[i].style.display = hideRowClass;
                                        }
                                   }
    }
    else {
      textShow.style.display="none";
      textHide.style.display="";
        while(tBody.nodeName!="TBODY"){
          tBody = tBody.parentNode;
                                      }
        rows = tBody.rows;
        for(i=0;i<rows.length;i++){
        if(rows[i].className==theClass){
        rows[i].style.display = "none";
                                        }
                                        }
                                   }
  }

function switchNavArrow(imageId, offOrOn){
  if(offOrOn == 'on'){
    document.images[imageId].src = '/images/side_nav_arrow.gif';
  }
  else if(offOrOn == 'off') {
    document.images[imageId].src = '/images/transparent_spacer.gif';
  }
}

// lihaze: function to reload to the parent window form the pop
function reLoadParent(urlToReload)
{
  top.opener.window.location.href = urlToReload;
  top.opener.window.focus();
}

// lihaze: function used to un/check radio or checkboxes from a link
function checkBoxChecked(formName, formElement){
  if(document.forms[formName].elements[formElement].checked){
    document.forms[formName].elements[formElement].checked = false;
  }
  else{
    document.forms[formName].elements[formElement].checked = true;
  }
}

// lihaze: function used to switch a bgcolor - am using this on the fund navigation
  function switchColour(elementName, colour){
    document.getElementById(elementName).bgColor = colour;
  }

//----------------------------------------------------------------------------
// Code to determine the browser and version. Taken from core navigation.js
//----------------------------------------------------------------------------

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}


//lewic: taken from core and modified
function displayFormat(expandImage, collapseImage, expandText, collapseText, useCookie){
			this.expandImage = expandImage;
			this.collapseImage = collapseImage;
			this.expandText = expandText;
			this.collapseText = collapseText;
      this.useCookie = useCookie;
		}

		var displayFormats = new Array();
		displayFormats["controlPanel"] = new displayFormat("/images/plus.gif", "/images/minus.gif", "Show", "Hide", "cpState");
		displayFormats["fundDetail"] = new displayFormat("/images/arrow_blue_right.gif", "/images/arrow_blue.gif");

		function toggleDisplay(imageObject, textObject, hideObject, format){
			var browser = new Browser();
			if(hideObject.style.display == "none"){
				if(imageObject != null){
					imageObject.src = displayFormats[format].collapseImage
				}
				if(textObject != null){
					textObject.innerHTML = displayFormats[format].collapseText
				}
				//block doesn't work in NS, change based on browser type
				if (browser.isIE) {
			    hideObject.style.display = "block"
				}  else if (browser.isNS) {
			   hideObject.style.display = "table-row"
				}	else {
					hideObject.style.display = "block"
				}

        if(displayFormats[format].useCookie != null){
          setCookie(displayFormats[format].useCookie, "block", 1, 'year')
        }
			}else{
				if(imageObject != null){
					imageObject.src = displayFormats[format].expandImage
				}
				if(textObject != null){
					textObject.innerHTML = displayFormats[format].expandText
				}
				hideObject.style.display = "none"
        if(displayFormats[format].useCookie != null){
          setCookie(displayFormats[format].useCookie, "none", 1, 'year')
        }
			}
		}

function setMousePointer(obj) {
  obj.style.cursor='pointer';
}

// lihaze: this is a simple switch out of images to the same target - name of the image and then where the img src
  function switchImg(image_name, img_chg, link_name, link_ref) {
      document.getElementById(image_name).src = img_chg;
      //document.getElementById(image_name).alt = img_chg;
      document.getElementById(link_name).href = link_ref;
  }


function switchStyle(id, newClass) {
identity=document.getElementById(id);
identity.className=newClass;
}



// owenoli scripts
var aImg = ['_nav_home.gif', '_nav_about.gif', '_nav_ishares.gif', '_nav_library.gif', '_nav_tools.gif']

function setLeftNavHeight(){
	var oTNProps = GL_GetLayoutProps('top_nav', null);				// Top Nav
	if(oTNProps == undefined){
		return;
	}
	var oLNProps = GL_GetLayoutProps('left_nav', null, true);		// Left Nav
	var oFProps = GL_GetLayoutProps('footer', null, true);			// Footer
	var oMCProps = GL_GetLayoutProps('main_content', null, true);	// Main Content
	var oMCAnchor = GL_GetLayoutProps('mc_anchor', null, false);		// Anchor Span

	var nAnchorX = (oMCAnchor.xPos) - (oTNProps.xPos + oTNProps.height)
    if (nAnchorX < 541){
       var nMinHeight = oLNProps.height+50;
    }
    else {
       var nMinHeight = 541;
    }
    var nMinXPos = (nMinHeight + oTNProps.xPos + oTNProps.height + 10); // Footer margin-top=10px
	var nXPos	= (nAnchorX + oTNProps.xPos + oTNProps.height + 10); // Footer margin-top=10px

	//alert("nAnchorX = " + nAnchorX + "\n" +	"oLNProps.height = " + oLNProps.height + "\n");
	//alert(document.getElementById('mc_anchor').offsetTop + ' : ' + oMCAnchor.xPos)

	if(nAnchorX > oLNProps.height ){
		//alert('Anchor is beyond Left Nav height');
		GL_SetLayoutProps('left_nav', ['height'], {height:nAnchorX});
		GL_SetLayoutProps('main_content', ['height'], {height:nAnchorX});
		GL_SetLayoutProps('footer', ['xPos'], {xPos:nXPos});
	}
	else if((nAnchorX < oLNProps.height ) && (nAnchorX < nMinHeight)){
		//alert('Anchor is above Left Nav height AND less than min height ');
		GL_SetLayoutProps('main_content', ['height'], {height:nMinHeight});
		GL_SetLayoutProps('left_nav', ['height'], {height:nMinHeight});
		GL_SetLayoutProps('footer', ['xPos'], {xPos:nMinXPos});
	}
	else if((nAnchorX < oLNProps.height ) && (nAnchorX > nMinHeight)){
		//alert('Anchor is above Left Nav height AND more than min height ');
		GL_SetLayoutProps('main_content', ['height'], {height:nAnchorX});
		GL_SetLayoutProps('left_nav', ['height'], {height:nAnchorX});
		GL_SetLayoutProps('footer', ['xPos'], {xPos:nXPos});
	}
	else {
		//alert('alternative condition');
		GL_SetLayoutProps('main_content', ['height'], {height:nMinHeight});
		GL_SetLayoutProps('left_nav', ['height'], {height:nMinHeight});
		GL_SetLayoutProps('footer', ['xPos'], {xPos:nMinXPos});
	}
}

function setTertiaryItemStyle(sType){
	var oOnItem = GL_GetEl(sType);
	var aTertiaryitems = document.getElementsByName("tertiaryItem");
	for(var ii=0; ii<aTertiaryitems.length; ii++){
		aTertiaryitems[ii].className = '';
	}
	oOnItem.className = 'tertiary_item';
}

function selectDocument(sType){
	setTertiaryItemStyle(sType);
	buildGrid(sType);
	setLeftNavHeight();
}



// All About ETFs
var sCurrentFadeMenu = '';
var aFadeMenuIds = ['ETFS_BASICS', 'INVESTMENT_STRATEGIES', 'TRADING_ISHARES']

function toggleFadeMenu(oEvent){
	var sId = (oEvent.srcElement) ? oEvent.srcElement.id : oEvent.target.id;
	var menuOn = (oEvent.srcElement) ? oEvent.srcElement.menuOn : oEvent.target.getAttribute('menuOn');

	if((sId) && (menuOn == 'true')){
		//alert('show menu for ' + sId)

		if(sId != sCurrentFadeMenu){
			//alert('different menu selected');
			hideFadeMenu();
		}

		var dMain = GL_GetEl('all_about_main');
		dMain.className = 'all_about_main_' + sId;
		var dTHB = GL_GetEl(sId);
		dTHB.className += ' thb_on';
		var dFadeMenuContent = GL_GetEl('fade_menu_' + sId);
		dFadeMenuContent.style.display = 'block';
		var dFadeMenu = GL_GetEl('fade_menu');
		dFadeMenu.style.display = 'block';

		sCurrentFadeMenu = sId;
	}
	else if(menuOn == 'true'){
		//alert('dont do anything');
		return;
	}
	else {
		//alert('hide all menus' + '\n' + sCurrentFadeMenu);
		if(sCurrentFadeMenu != ''){
			hideFadeMenu();
		}
	}
}


function hideFadeMenu(){
	var dMain = GL_GetEl('all_about_main');
	dMain.className = 'all_about_main_default';
	var dFadeMenu = GL_GetEl('fade_menu');
	dFadeMenu.style.display = 'none';

	for(var i=0; i<aFadeMenuIds.length; i++){
		var dTHB = GL_GetEl(aFadeMenuIds[i]);
		dTHB.className = aFadeMenuIds[i];
		var dFadeMenuContent = GL_GetEl('fade_menu_' + aFadeMenuIds[i]);
		dFadeMenuContent.style.display = 'none';
	}

	sCurrentFadeMenu = '';
}

// COMPARE ETFS - Force secondary nav link to 'on' state
function swapLinkForText(){
	var dLinkContainer = GL_GetEl('secondary_nav');
	var aLinks = dLinkContainer.getElementsByTagName("A");
	var aHeadings = document.getElementsByTagName("H1");
	var sPageTitle = aHeadings[0].innerHTML;

	for(var i=0; i<aLinks.length; i++){
		if(aLinks[i].innerHTML == sPageTitle){
			aLinks[i].outerHTML = sPageTitle;
		}
	}
}

// HOME PAGE
var newwindow;
function homeResources(url)
{
    if (url == '/index.do') {
        return false;
    }
    else {
        newwindow = window.open(url, 'name');
        if (window.focus) {
            newwindow.focus()
        }
    }

}

// The show hide for the content page
function showHideBlock(textBlock, imgBlock) {
	textShow = document.getElementById(textBlock);
	imgShow = document.getElementById(imgBlock);
	showImgPath = '/assets/show_text.gif';
	hideImgPath = '/assets/hide_text.gif';

	if (textShow.style.display == 'none'){
		textShow.style.display="block";
		imgShow.src=hideImgPath;
	}
	else{
		textShow.style.display="none";
		imgShow.src=showImgPath;
	}
	setLeftNavHeight();
}


var IE = (document.all)?1:0;
var dynamic_uri = "";
var product_info_ajax_uri = "/fund_returns";

/* TODO:  ADD COMMENTS */

var currTab = "";

function tabName(tab_title) {

  var currTab = tab_title;
  var isExtendPage = (page_code == "PRODUCT_INFO" || page_code == "FUND_HISTORY" || page_code == "FUND_RETURNS")
  var ext = (isExtendPage && tab_title == "your_view") ? "_ext" : ""

  document[currTab].src = '/images/' + user_locale + '/navigation/nav_' + currTab + ext + '_on.gif';

}

function tabNameOff(tab_title) {

  var currTab = tab_title;
  var isExtendPage = (page_code == "PRODUCT_INFO" || page_code == "FUND_HISTORY" || page_code == "FUND_RETURNS")
  var ext = (isExtendPage && tab_title == "your_view") ? "_ext" : ""

  document[currTab].src = '/images/' + user_locale + '/navigation/nav_' + currTab + ext + '.gif';

}

var set_menu_timeout = 750;
var selectedImages = "";

function primary_nav() {

  if (document.getElementById("primary_nav")) {
    var navItems = document.getElementById("primary_nav").getElementsByTagName("LI");

    for (var i=0; i<navItems.length; i++) {
      if(navItems[i].className == "menuparent") {
        navItems[i].onmouseover=function() {
          this.className = "over";
          this.style.cursor = 'pointer';
          this.style.zIndex = 99;

//  	    document[currTab].src = '/images/' + user_locale + '/navigation/nav_' + currTab + '_on.gif';
//          replaceImgNode(this.previousSibling, "/images/" + user_locale + "/navigation/nav_divider_on.gif");
//          replaceImgNode(this.nextSibling, "/images/" + user_locale + "/navigation/nav_divider_on.gif");
        }
        navItems[i].onmouseout=function() {
          this.className = "menuparent";

//         document[currTab].src = '/images/' + user_locale + '/navigation/nav_' + currTab + '.gif';
//          replaceImgNode(this.previousSibling, "/images/" + user_locale + "/navigation/nav_divider_off.gif");
//          replaceImgNode(this.nextSibling, "/images/" + user_locale + "/navigation/nav_divider_off.gif");
       }
      }
    }
  }
}

var ca_curr_menu = '';
var menu_timer = 0;

function fund_nav() {

  var obj_ca = document.getElementById('au_fund_menu_widget');

  if (obj_ca) {
    var navItems = obj_ca.getElementsByTagName("li");

    for (var i=0; i<navItems.length; i++) {
      if(navItems[i].className == "menuparent") {
        navItems[i].onmouseover=function() {
          clearTimeout(menu_timer);
          if (ca_curr_menu && (ca_curr_menu != this.id)) {
            document.getElementById(ca_curr_menu).className = 'menuparent';
            ca_curr_menu = '';
          }
          fund_timer();
          this.className += " over";
          ca_curr_menu = this.id;
        }
        navItems[i].onmouseout=function() {
          clearTimeout(menu_timer);
          menu_timer = setTimeout("menu_timeout('" + this.id + "')", set_menu_timeout);
        }
      }
    }
  }

}

function menu_timeout(menu_id) {
  document.getElementById(menu_id).className = 'menuparent';
}

var fund_layer_on = 0;
var fund_timeout = 0;
var curr_fund_menu1 = '';
var curr_fund_menu2 = '';
var curr_fund_menu3 = '';

function show_fund_menu(parent_menu, menu, top_adj, left_adj, extra_adj) {


  /* Internet Explorer Div Position CSS Error Adjustment */
  var ie_adjust = 0;
  var extra_mod = 0;

  if (parent_menu == 'l0_menu_au') {
    if (IE) {
      //extra_mod = dom_obj(parent_menu).offsetTop - 2;
      extra_mod = dom_obj(parent_menu).offsetTop;
    } else {
      extra_mod = 0;
    }
  } else if (parent_menu == 'us_fund_menu' && IE) {
    //extra_mod = (dom_obj(parent_menu)).offsetTop + 57;
    extra_mod = (dom_obj(parent_menu)).offsetTop-32;
  } else {
    //lihaze extra_mod = find_pos_y(dom_obj(parent_menu));
   extra_mod = (dom_obj(parent_menu)).offsetTop;
    //alert('extra_mod : ' + extra_mod);
  }


  if (ca_curr_menu) {
    document.getElementById(ca_curr_menu).className = 'menuparent';
    ca_curr_menu = '';

  }


  clearTimeout(fund_timeout);
  var level_test = (menu.indexOf('l1') != - 1)?1:(menu.indexOf('l2') != - 1)?2:(menu.indexOf('l3') != - 1)?3:0;



  if (level_test == 3) {
    if (curr_fund_menu3 && (curr_fund_menu3 != menu)) {
      //  alert("level 3");
      dom_obj(curr_fund_menu3).style.visibility = 'hidden';
    }
    curr_fund_menu3 = menu;
  }
  else if (level_test == 2) {
    if (curr_fund_menu2 && (curr_fund_menu2 != menu)) {
      //  alert("level 2");
      dom_obj(curr_fund_menu2).style.visibility = 'hidden';
    }
    if (curr_fund_menu3 && (curr_fund_menu3 != menu)) {
      dom_obj(curr_fund_menu3).style.visibility = 'hidden';
    }
    curr_fund_menu2 = menu;
  }
  else if (level_test == 1) {
    if (curr_fund_menu1 && (curr_fund_menu1 != menu)) {
       // alert("level 1");
      dom_obj(curr_fund_menu1).style.visibility = 'hidden';

      swapStyle(get_fund_parent_name(curr_fund_menu1))

    }
    if (curr_fund_menu2 && (curr_fund_menu2 != menu)) {
      dom_obj(curr_fund_menu2).style.visibility = 'hidden';
    }
    if (curr_fund_menu3 && (curr_fund_menu3 != menu)) {
      dom_obj(curr_fund_menu3).style.visibility = 'hidden';
    }
    curr_fund_menu1 = menu;
  }


  fund_layer(1);

  var menu_top = extra_mod + top_adj + ((IE && (parent_menu == 'us_fund_menu'))?extra_adj:0);
  var menu_left = find_pos_x(dom_obj(parent_menu)) + left_adj + dom_obj(parent_menu).offsetWidth - 1;

  // var page_height = (IE)?document.body.clientHeight:window.innerHeight;
  // we'd like to see the menu to fit in the window 1024x768 instead of scroll down to the end of the page. 
  var page_height = 700; 
  var menu_height = dom_obj(menu).offsetHeight;
  var menu_bottom = menu_height + menu_top;


  if (menu_height > page_height) {
    dom_obj(menu).style.top = '0px';
  }
  else if (menu_bottom > page_height) {
    dom_obj(menu).style.top = menu_top - (menu_bottom - page_height) + 'px';
  }
  else {
    dom_obj(menu).style.top = menu_top + 'px';
  }


  /*alert("find_pos_y(dom_obj(" + parent_menu + ")) = " + find_pos_y(dom_obj(parent_menu)) + "\n"
        + "top_adj = " + top_adj + "\n"
        + "menu_top = " + menu_top + "\n"
        + "dom_obj(" + menu + ").style.top = " + dom_obj(menu).style.top);*/

  dom_obj(menu).style.left = menu_left + 'px';
  dom_obj(menu).style.visibility = 'visible';
  dom_obj(menu).style.zIndex = 99;

}

function hide_fund_menu() {
		// clear main menu item
  clearTimeout(fund_timeout);
  fund_layer(0);
  fund_timeout = setTimeout('fund_timer()', set_menu_timeout);
}

function fund_timer() {
  if (!fund_layer_on) {
    if (curr_fund_menu3) {
      dom_obj(curr_fund_menu3).style.visibility = 'hidden';
    }
    if (curr_fund_menu2) {
      dom_obj(curr_fund_menu2).style.visibility = 'hidden';
    }
    if (curr_fund_menu1) {
      dom_obj(curr_fund_menu1).style.visibility = 'hidden';
    }
		swapStyle(get_fund_parent_name(curr_fund_menu1))
    
  }
}

function get_fund_parent_name(submenu) {
    mainMenuId = submenu.replace(/(_au)$/, "")
    mainMenuId = mainMenuId.replace(/l1_/, "")
    mainMenuId = mainMenuId.replace(/_/, " ")
    menuWords = mainMenuId.split(" ")
    for (i=0; i<menuWords.length; i++) {
    	menuWords[i] = menuWords[i].substring(0,1).toUpperCase() + menuWords[i].substring(1,menuWords[i].length)
    }
    return "//AUFundMenu//" + menuWords.join(" ")
}

function fund_layer(n) {
  fund_layer_on = n;
}

function dom_obj(id) {
  return eval(document.getElementById(id));
}

function find_pos_x(obj) {
  var curleft = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}

function find_pos_y(obj) {
  var curtop = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}


function replaceImgNode(x, alt_src) {
  for (var i=0;i<x.childNodes.length;i++) {
    if (x.childNodes[i].nodeName == "IMG") {
      if (selectedImages.match(x.childNodes[i].id) <= 0) {
        x.childNodes[i].src = alt_src;
      }
    }
  }
}


function forwardUrl(url) {
  window.location = url;
}


function showStatus(url) {
  window.status = (url) ? window.location.protocol + "//" + window.location.host + url: '';
  return true;
}


function swapStyle(menuName, turnOn) {
    // alert(menuName + "  " + turnOn);
    menuItem = document.getElementById(menuName)
    if (menuItem) {
        // keep blue if any submenus are visible
        menuNameArray = menuName.split("//")
        txtMenuName = menuNameArray[menuNameArray.length - 1].toLowerCase()
        txtMenuName = txtMenuName.replace(/ /, "_")
        submenuLayerName = "l1_" + txtMenuName + "_au"
        submenu = document.getElementById(submenuLayerName)

        if (submenu)
            turnOn = (submenu.style.visibility == "visible" || turnOn) ? true : false

            // for some reason, className isn't working with IE6 in this case
            menuItem.style.backgroundColor = (turnOn) ? "#3281d0" : "#f5f5f5"
            menuItem.style.backgroundImage = (turnOn) ? "url(/assets/nav_arrow_blue.gif)" : "url(/assets/nav_arrow_gray.gif)"
            menuItem.style.color = (turnOn) ? "#ffffff" : "#5f5e63"
            menuItem.style.borderTop = (turnOn) ? "1px solid #7fb7e6" : "1px solid #f5f5f5"
            menuItem.style.borderBottom = (turnOn) ? "1px solid #7fb7e6" : "1px solid #f5f5f5"
            menuItem.style.backgroundPosition = "right"
            menuItem.style.backgroundRepeat = "no-repeat"
    }
}


    // ajax sort on doc library : http://www.inspired-evolution.com/AJAX_Table_Sort.php
    <!--
	var sortedOn = 0;
/*    var libDownArrow = '/assets/library/sort_arrow_gray_down.gif';
    var LibUpArrow = '/assets/library/sort_arrow_gray_up.gif';
    var LibOnArrow - '/assets/library/sort_arrow_gray_right.gif';*/

    function SortTable(sortOn) {
        
		var table = document.getElementById('documentList');
		var tbody = table.getElementsByTagName('tbody')[0];
        var thead = table.getElementsByTagName('thead')[0];
        var rows = tbody.getElementsByTagName('tr');
        var hRows = thead.getElementsByTagName('th');
        var rowArray = new Array();

        for (var i=0, length=rows.length; i<length; i++) {
			rowArray[i] = rows[i].cloneNode(true);
        }



        if (sortOn == sortedOn) 
        /* if this column has already been sorted, when click on the same cloumn again, reverse the order */ 
        {
            for (var i=0, length=hRows.length; i<length; i++) {
             if (sortOn != i)
             /* this column is not requested to be sorted */ 
             {
                 document.getElementById('imgR'+i).style.display = 'none';
                 document.getElementById('imgU'+i).style.display = 'none';
                 document.getElementById('img'+i).style.display  = 'inline';
                 }

             else  {
                 if (document.getElementById('imgR'+sortOn).style.display == 'inline') 
                 /* when the original sort was displayed in descending order, change it to be displayed in ascending order*/ 
                 {
                     document.getElementById('imgR'+sortOn).style.display  = 'none';
                     document.getElementById('imgU'+sortOn).style.display  = 'inline';
                     document.getElementById('img'+sortOn).style.display  = 'none';
                 }
                 else 
                 /* when the original sort order was displayed in ascending order, change it to be displayed in descending order*/ 
                 {
                     document.getElementById('imgR'+sortOn).style.display  = 'inline';
                     document.getElementById('imgU'+sortOn).style.display  = 'none';
                     document.getElementById('img'+sortOn).style.display  = 'none';
                 }                         
             }
            }
            rowArray.reverse();
            /* reverse the order of the same column */ 
        }
		else 
		/* sort on different column */ 
		{
            sortedOn = sortOn;
            /* mark the column being sorted */ 
            
            switch(sortedOn)
            {
 				case 0: /* to be sorted on column Document Name */ 
					rowArray.sort(RowCompareTagA);
					break; 
				case 2: /* to be sorted on Nofity Date */ 
					rowArray.sort(RowCompareDate);
					break; 
				case 3: /* to be sorted on column Size */ 
					rowArray.sort(RowCompareNumbers);
					break; 
				case 5: /* to be sorted on Order by email */ 
					rowArray.sort(RowCompareMail);
					break; 
				default:
				    rowArray.sort(RowCompare);
				    break;       
	        }

            for (var i=0, length=hRows.length; i<length; i++) 
            {
             if (sortOn != i)
             /* this column is not the one to be sorted, display the arrow Right*/ 
             {
                 document.getElementById('imgR'+i).style.display  = 'none';
                 document.getElementById('imgU'+i).style.display  = 'none';
                 document.getElementById('img'+i).style.display  = 'inline';
                 }
             else  
             /* this column is the one to be sorted */ 
             {
                 if (document.getElementById('imgR'+sortOn).style.display == 'inline') 
                 /* the column was displayed in descending order, change it to be displayed in ascending */
                 {
                     document.getElementById('imgR'+sortOn).style.display  = 'none';
                     document.getElementById('imgU'+sortOn).style.display  = 'inline';
                     document.getElementById('img'+sortOn).style.display  = 'none';
                 }
                 else 
                 /* the column was displayed in ascending order, change it to be displayed in descending order */
                 {
                     document.getElementById('imgR'+sortOn).style.display  = 'inline';
                     document.getElementById('imgU'+sortOn).style.display  = 'none';
                     document.getElementById('img'+sortOn).style.display  = 'none';
                 }
             }
           }
		}

        var newTbody = document.createElement('tbody');
		for (var i=0, length=rowArray.length; i<length; i++) {
			newTbody.appendChild(rowArray[i]);
		}

		table.replaceChild(newTbody, tbody);
	}

	function RowCompareTagA(a, b) {
		var aVal = a.getElementsByTagName('a')[0].firstChild.nodeValue.toUpperCase();
		var bVal = b.getElementsByTagName('a')[0].firstChild.nodeValue.toUpperCase();
		return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));
    }

	function RowCompareDate(a, b) {
		/* convert dd/mm/yy to yymmdd before comparing*/ 
		var aVal = a.getElementsByTagName('td')[sortedOn].firstChild.nodeValue;
		var bVal = b.getElementsByTagName('td')[sortedOn].firstChild.nodeValue;
		var dateRE1 = /^(\d)[\/\- ](\d{2})[\/\- ](\d{2})/;
		aVal = aVal.replace(dateRE1,"0$1/$2/$3");
		/* add leading 0 to day if day has only 1 digit, eg 9/11/07 will be 09/11/07 */ 
		bVal = bVal.replace(dateRE1,"0$1/$2/$3");
		var dateRE2 = /^(\d{2})[\/\- ](\d{2})[\/\- ](\d{2})/;
		aVal = aVal.replace(dateRE2,"$3$2$1");
		/* convert dd/mm/yy to yymmdd before comparing*/ 
		bVal = bVal.replace(dateRE2,"$3$2$1");
		return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));
    }
    
	function RowCompareMail(a, b) {
		var aVal = a.getElementsByTagName('td')[sortedOn].firstChild.nodeValue;
		var bVal = b.getElementsByTagName('td')[sortedOn].firstChild.nodeValue;
		if (aVal == null)aVal = "Order by email"; 
		if (bVal == null)bVal = "Order by email"; 
		return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));   
    }	
    
    function RowCompare(a, b) {
		var aVal = a.getElementsByTagName('td')[sortedOn].firstChild.nodeValue;
		var bVal = b.getElementsByTagName('td')[sortedOn].firstChild.nodeValue;
		return (aVal == bVal ? 0 : (aVal > bVal ? 1 : -1));
        
    }
    
	function RowCompareNumbers(a, b) {

		var aVal = parseInt(a.getElementsByTagName('td')[sortedOn].firstChild.nodeValue);
		var bVal = parseInt(b.getElementsByTagName('td')[sortedOn].firstChild.nodeValue);
		return (aVal - bVal);
	}

	function RowCompareDollars(a, b) {

		var aVal = parseFloat(a.getElementsByTagName('td')[sortedOn].firstChild.nodeValue.substr(1));
		var bVal = parseFloat(b.getElementsByTagName('td')[sortedOn].firstChild.nodeValue.substr(1));
		return (aVal - bVal);
	}

	//-->


/*
 * @author        chris.geheran lise.latorre 
 * @description   Background Cache Control: This function helps the nav images from refreshing, which slows down
 *                the navigation speed in some browsers like ie6.
*/
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) { }
/* End BG Cache controller */

/*
 * @function      fixMenu(ULNode,lnav)
 * @author        chris.geheran lise.latorre
 * @parameters    UL Element, string
 *
 * @description   This is run in the doOnload function of each page including the top navigation element.
 *                The function runs through the menu to execute a hover fix for ie6 that uses class names rather
 *                than hover to show/hide the tiered navigation.
*/
function fixMenu(ULNode,nav) {
  //ie6 fix. This fixes the issue ie6 has with using hover by setting mouse events to change class name
	if (document.all&&document.getElementById) {
		for (i=0; i<ULNode.childNodes.length; i++) {
			node = ULNode.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover 	= function() { this.className+=" over1"; }
			  node.onmouseout		= function() { this.className=this.className.replace(" over1",""); }
        if (node.lastChild.nodeName=="UL") {
					for (j=0; j<node.lastChild.childNodes.length; j++) {
						level2Node = node.lastChild.childNodes[j];
            if (level2Node.nodeName=="LI") {
              level2Node.onmouseover 	= function() { this.className+=" over2"; }
              level2Node.onmouseout		= function() { this.className=this.className.replace(" over2",""); }
              level2Node.background = "";
            } //end if
					} //end for j
				} //end if lastChild
			} //end if node LI
		} //end for i
	} //end browser check
} //end function

/* Function: Used to open popup windows */
/* This was taken from ishares.ca: Possible refactor here */
var asset_illustrator_win;
var correlation_calculator_win;
function openPopup(url, name, attributes) {
	if (url) {
		if (name == 'asset_illustrator') { // this logic prevents a second pop-up after the user logs in
			if (asset_illustrator_win && !asset_illustrator_win.closed && asset_illustrator_win.focus) {
				asset_illustrator_win.focus();
			}
			else {
    			asset_illustrator_win = window.open(url, "asset_illustrator", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
		    	asset_illustrator_win.focus();
    		}
    	}
		if (name == 'correlation_calculator') { // this logic prevents a second pop-up after the user logs in
			if (asset_illustrator_win && !asset_illustrator_win.closed && asset_illustrator_win.focus) {
				asset_illustrator_win.focus();
			}
			else {
    			asset_illustrator_win = window.open(url, "correlation_calculator", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
		    	asset_illustrator_win.focus();
    		}
    	}
    	else {
			var newWindow = window.open(url, (name)?name:"_blank", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
			newWindow.focus();
		}
	}
}

/*No non-numerical values in material order form*/


      function displayunicode(e){
          var unicode=e.keyCode? e.keyCode : e.charCode
          return unicode;
      }

      function hasNumericKeys(unicode){
          return (unicode > 47 && unicode < 58);
      }

      function hasRelatedKeys(unicode){

          // allow tab
          return (unicode == 8 || unicode == 39);
      }

      function blockNonNumbers(e){

          var unicode = displayunicode(e);

          // ensure that the user has entered a number, backspace, arrow, del, etc.
          var validEntryMade = (hasNumericKeys(unicode) || hasRelatedKeys(unicode));

          return validEntryMade;
      }
/*limit material quantity*/	  
function checkInputs(itemValue,formRef,itemId,maxOrder) {
	if (itemValue > maxOrder) {
		document.getElementById(itemId).value='';
		alert ("You may order up to " + maxOrder + " copies of a document. Please call 1-300-iShares to request additional copies.");
	} 
}


/*lihaze: change class*/
function changeClass(className, itemId){
    var className = className
    var itemId = itemId
    document.getElementById(itemId).className = className;
    //alert(document.getElementById('1').className);
}

/*dhtml selects on home page
author: Chris Gehran
applied by: latolis
 * @functions     linksChange
 * @description   Uses javascript to show a hidden div as a dropdown menu.
 *                For link-cluster-e content (homepage right links)
 *
*/

function linksChange(aRef) {
  var dropdiv = aRef.parentNode.parentNode;
  //alert (dropdiv.className);
  if (dropdiv.className.indexOf("showlinks") == -1) {
    var allSubMenus = dropdiv.parentNode.getElementsByTagName("div");
    for (i=0; i<allSubMenus.length; i++) {
      if (allSubMenus[i].className.indexOf("showlinks") != -1) {
        allSubMenus[i].className = allSubMenus[i].className.substring(0,allSubMenus[i].className.indexOf(" "));
        dropdiv.className += " showlinks";
        break;
      }
    }
    dropdiv.className += " showlinks";
  } else {
    dropdiv.className = dropdiv.className.substring(0,dropdiv.className.indexOf(" "));
  }
}

/*
 * @functions     closeParent(node)
 * @description   Closes twisty parent.
 * $author        nassmic
 *
*/
function closeParent(node){
  var element = findParent(node);
  if(element != null){
    element.className = element.className.replace('showlinks', 'showmenu');
  }
}

function none() {
var foo=0;
}

function isParent(child, parent){
    var ie = ((document.all && document.getElementById) ? true : false);
    if(ie == true){
      if(!child.offsetParent){
        return false;
      }
      if(child.offsetParent.innerHTML == parent.innerHTML){
        return true;
      } else {
        return isParent(child.offsetParent, parent);
      }
    } else {
      if(child.tagName == "BODY"){
        return false;
      }
      if(child.parentNode.innerHTML == parent.innerHTML){
        return true;
      } else {
        return isParent(child.parentNode, parent);
      }
    }
  }

