// popup windows
function openWindow(url, width, height, title){
//	if(!a_opened_window || a_opened_window.closed){
		var window_attributes = "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,menubar=yes"
		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
function go(actionCodeVal) {
  with (document.userAdmin) {
    actionCode.value = actionCodeVal;
    submit();
  }
}
 
// window shades
  var head="display:''"
  img1=new Image()
  img1.src="/images/plus.gif"
  img2=new Image()
  img2.src="/images/minus.gif"
  
  var ns6 = document.getElementById && !document.all
  var ie4 = document.all && navigator.userAgent.indexOf("Opera")==-1
  
  // bulelea: modified to reference plus/minus image directly instead of through parent div
  function showMonths(plusMinusImageId, monthTableObjectId) {

    if(ie4||ns6){
      var plusMinusObject = document.getElementById(plusMinusImageId);
      var monthTableObject = document.getElementById(monthTableObjectId);
      if(monthTableObject.style.display=="none") {
        var displayValue = ns6? "table-row" : "block";
        monthTableObject.style.display = displayValue;
        plusMinusObject.src="/images/minus.gif"
      }else{
        monthTableObject.style.display="none"
        plusMinusObject.src="/images/plus.gif"
      } // end if
    }
  } // end function
    
 // mutual fund selector
function checkMutualFunds(checkboxObject){
  if(ie4||ns6){
    if(checkboxObject.checked){
   if(ns6){
     var visibilityStyle = "table-row";
      }else{
     var visibilityStyle = "block";
   }
    }else{
      var visibilityStyle = "none";
    }
    switch (checkboxObject.value){
      case "mutualInstitutional":
        document.getElementById("asset_223937").style.display = visibilityStyle;
        document.getElementById("asset_218293").style.display = visibilityStyle;
        document.getElementById("asset_301428").style.display = visibilityStyle;
        document.getElementById("asset_301432").style.display = visibilityStyle;
        document.getElementById("unsub_223937").style.display = visibilityStyle;
        document.getElementById("unsub_218293").style.display = visibilityStyle;
        document.getElementById("unsub_301428").style.display = visibilityStyle;
        document.getElementById("unsub_301432").style.display = visibilityStyle;
        if(!checkboxObject.checked){
          if(!document.getElementById("fundSelectorMutualPremium").checked && !document.getElementById("fundSelectorMutualTrust").checked){
            document.getElementById("fundSelectorMutualSelect").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualSelect").checked && !document.getElementById("fundSelectorMutualTrust").checked){
            document.getElementById("fundSelectorMutualPremium").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualPremium").checked && !document.getElementById("fundSelectorMutualSelect").checked){
            document.getElementById("fundSelectorMutualTrust").disabled = true;
          }
        }else{
          document.getElementById("fundSelectorMutualPremium").disabled = false;
          document.getElementById("fundSelectorMutualSelect").disabled = false;
          document.getElementById("fundSelectorMutualTrust").disabled = false;
        }
        break;
      case "mutualPremium":
         document.getElementById("asset_259678").style.display = visibilityStyle;
         document.getElementById("asset_259676").style.display = visibilityStyle;
         document.getElementById("asset_301429").style.display = visibilityStyle;
         document.getElementById("asset_301433").style.display = visibilityStyle;
         document.getElementById("unsub_259678").style.display = visibilityStyle;
         document.getElementById("unsub_259676").style.display = visibilityStyle;
         document.getElementById("unsub_301429").style.display = visibilityStyle;
         document.getElementById("unsub_301433").style.display = visibilityStyle;
        if(!checkboxObject.checked){
          if(!document.getElementById("fundSelectorMutualInst").checked && !document.getElementById("fundSelectorMutualTrust").checked){
            document.getElementById("fundSelectorMutualSelect").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualSelect").checked && !document.getElementById("fundSelectorMutualTrust").checked){
            document.getElementById("fundSelectorMutualInst").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualInst").checked && !document.getElementById("fundSelectorMutualSelect").checked){
            document.getElementById("fundSelectorMutualTrust").disabled = true;
          }
        }else{
          document.getElementById("fundSelectorMutualInst").disabled = false;
          document.getElementById("fundSelectorMutualSelect").disabled = false;
          document.getElementById("fundSelectorMutualTrust").disabled = false;
        }
        break;
      case "mutualSelect":
         document.getElementById("asset_279682").style.display = visibilityStyle;
         document.getElementById("asset_279683").style.display = visibilityStyle;
         document.getElementById("asset_301430").style.display = visibilityStyle;
         document.getElementById("asset_301434").style.display = visibilityStyle;
         document.getElementById("unsub_279682").style.display = visibilityStyle;
         document.getElementById("unsub_279683").style.display = visibilityStyle;
         document.getElementById("unsub_301430").style.display = visibilityStyle;
         document.getElementById("unsub_301434").style.display = visibilityStyle;
        if(!checkboxObject.checked){
          if(!document.getElementById("fundSelectorMutualPremium").checked && !document.getElementById("fundSelectorMutualTrust").checked){
            document.getElementById("fundSelectorMutualInst").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualInst").checked && !document.getElementById("fundSelectorMutualTrust").checked){
            document.getElementById("fundSelectorMutualPremium").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualPremium").checked && !document.getElementById("fundSelectorMutualInst").checked){
            document.getElementById("fundSelectorMutualTrust").disabled = true;
          }
        }else{
          document.getElementById("fundSelectorMutualInst").disabled = false;
          document.getElementById("fundSelectorMutualPremium").disabled = false;
          document.getElementById("fundSelectorMutualTrust").disabled = false;
        }
        break;
      case "mutualTrust":
         document.getElementById("asset_290366").style.display = visibilityStyle;
         document.getElementById("asset_290367").style.display = visibilityStyle;
         document.getElementById("asset_301431").style.display = visibilityStyle;
         document.getElementById("asset_301435").style.display = visibilityStyle;
         document.getElementById("unsub_290366").style.display = visibilityStyle;
         document.getElementById("unsub_290367").style.display = visibilityStyle;
         document.getElementById("unsub_301431").style.display = visibilityStyle;
         document.getElementById("unsub_301435").style.display = visibilityStyle;
        if(!checkboxObject.checked){
          if(!document.getElementById("fundSelectorMutualPremium").checked && !document.getElementById("fundSelectorMutualSelect").checked){
            document.getElementById("fundSelectorMutualInst").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualInst").checked && !document.getElementById("fundSelectorMutualSelect").checked){
            document.getElementById("fundSelectorMutualPremium").disabled = true;
          }
          if(!document.getElementById("fundSelectorMutualPremium").checked && !document.getElementById("fundSelectorMutualInst").checked){
            document.getElementById("fundSelectorMutualSelect").disabled = true;
          }
        }else{
          document.getElementById("fundSelectorMutualInst").disabled = false;
          document.getElementById("fundSelectorMutualPremium").disabled = false;
          document.getElementById("fundSelectorMutualSelect").disabled = false;
        }
        break;
    }
  }
}

function checkMutualFunds(checkboxObject){
  if(ie4||ns6){
    if(checkboxObject.checked){
      if(ns6){
       var visibilityStyle = "table-row";
        }else{
       var visibilityStyle = "block";
      }
    }else{
      var visibilityStyle = "none";
    }
    switch (checkboxObject.value){
      case "caymanInstitutional":
        document.getElementById("asset_298867").style.display = visibilityStyle;
        document.getElementById("unsub_298867").style.display = visibilityStyle;
        if(!checkboxObject.checked){
         document.getElementById("fundSelectorCaymanPremium").disabled = true;
        }
        break;
      case "caymanPremium":
         document.getElementById("asset_298867").style.display = visibilityStyle;
         document.getElementById("unsub_298867").style.display = visibilityStyle;
        if(!checkboxObject.checked){
          document.getElementById("fundSelectorCaymanInst").disabled = true;
        }
        break;
    }
  }
}
 
 // dublin fund selector
 function checkDublinFunds(checkboxObject){
  if(ie4||ns6){
    if(checkboxObject.checked){
   if(ns6){
     var visibilityStyle = "table-row";
      }else{
     var visibilityStyle = "block";
   }
    }else{
      var visibilityStyle = "none";
    }
    switch (checkboxObject.value){
      case "dublinInstitutional":
        document.getElementById("asset_173341").style.display = visibilityStyle;
        document.getElementById("asset_173345").style.display = visibilityStyle;
        document.getElementById("asset_173361").style.display = visibilityStyle;
        document.getElementById("asset_173343").style.display = visibilityStyle;
        document.getElementById("asset_173344").style.display = visibilityStyle;
        document.getElementById("asset_173360").style.display = visibilityStyle;
        if(!checkboxObject.checked){
          document.getElementById("fundSelectorDublinPremium").disabled = true;
        }else{
          document.getElementById("fundSelectorDublinPremium").disabled = false;
        }
        break;
      case "dublinPremium":
         document.getElementById("asset_219516").style.display = visibilityStyle;
         document.getElementById("asset_219517").style.display = visibilityStyle;
         document.getElementById("asset_219518").style.display = visibilityStyle;
         document.getElementById("asset_175770").style.display = visibilityStyle;
         document.getElementById("asset_175771").style.display = visibilityStyle;
         document.getElementById("asset_175772").style.display = visibilityStyle;
        if(!checkboxObject.checked){
          document.getElementById("fundSelectorDublinInst").disabled = true;
        }else{
          document.getElementById("fundSelectorDublinInst").disabled = false;
        }
        break;
    }
  }
 }


 
 // fund detail change
 function fundDetailChange(list){
  var newUrl = "/fund_info/detail.do?asset_reference_id="
  newUrl += list.options[list.selectedIndex].value
  document.location.href = newUrl
 }
 

// reminder to print in landscape for wide pages
function landscapePrintMessage(){
  alert("For proper printing, please change your paper orientation to landscape.")
}

// set browser cookie
if (getCookie("showCalendar") == null){
	setCookie('showCalendar', is_ie5_5up, 3, 'year')
}

// popup windows
var a_opened_window;
function openWindow(url, width, height, title){
  if(!a_opened_window || a_opened_window.closed){
    var window_attributes = "height=" + height + ",width=" + width + ",resizable=yes,scrollbars=yes,menubar=yes"
    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{
    if (a_opened_window.location.href != url) {
      a_opened_window.location.href = url
    }
  }
  a_opened_window.focus();
}

// close window, used to close popup windows
  function closeWindow(){       // taken from CORE
    if(a_opened_window){
      a_opened_window.close();
    }
  } 

/*    lihaze: 09 Auguest 2004:
*       toggleFundCurrencyDisplay and toggleAccountDisplay are almost the same. 
*       toggleFundCurrencyDisplay is for fund and currency drop downs as there is no check for whether "mulitple accounts"
*         has been selected.
*       toggleAccountDisplay is for the accounts selection as this looks for whehter mulitple is selected. 
*       Not put in the subit action as a shared as it muti selected it would re-submit and then open the page which is no hard
*         to the user, but it basically goes and processes the page when there is no reason to
*/  
  
//  lihaze: FUND and CURRENCY dropdown 
  function toggleFundCurrencyDisplay(){        
      document.accountSelectorDropdownForm.submitAccountAction.value = "SAVE";    // Taken from CORE
      document.accountSelectorDropdownForm.submit();    
    }
  
//  lihaze: ACCOUNT dropdown ONLY 
  function toggleAccountDisplay(){        
    var accountSelectValue = document.accountSelectorDropdownForm.clientAccount.value   // the value of select as 'accountSelectValue'. If its the multi select thing open in new window.
    if(accountSelectValue == "SELECTMULTIPLE") {  // if its multi-select then call the openNewWindow function
      openNewWindow("/accounts/accounts_selector.do", "accountsSelector", 
                     "height=500, width=600, top=0, left=0, ScrollBars=yes, resizable=yes, status=yes");
    }
    else{
      document.accountSelectorDropdownForm.submitAccountAction.value = "SAVE";    // Taken from CORE
      document.accountSelectorDropdownForm.submit();    
    }
  }  
  
  function toggleHoldingsFx() {
    with (document.accountSelectorDropdownForm) {
      if (show_fx_summary.value == "Y") {
        show_fx_summary.value = "N";
      }
      else {
        show_fx_summary.value = "Y";
      }
      actionCode.value = "toggleHoldingsFx";
      submit();
    }
  }
  
// lihaze: Close the account selector pop-up and get the parent window to re-load itself  
  function updateAccSelectorParent(){    
    window.close(); 
    opener.document.accountSelectorDropdownForm.submitAccountAction.value = "SAVE";    // Taken from CORE
    opener.document.accountSelectorDropdownForm.submit(); 
  }

 
//lewic: landscape layout for print
function notifyLandscape(){
	alert("For proper printing, please change your page layout orientation to landscape.");
}

//garcger: for reportInfo column sort
function changeSort(sortColumnVal, sortDirectionVal) {
  with (document.accountSelectorDropdownForm) {
    sortColumn.value = sortColumnVal;
    sortDirection.value = sortDirectionVal;
    submit();
  }
}

 
// Document library category dropdown menu change.
function libraryCategoryChange (list)
{

  // Build the new URL.
  var newUrl = "/library/document_list.do?category=" +
    list.options[list.selectedIndex].value;

  // Get the browser to request the new URL.
  document.location.href = newUrl;

}
