// from http://www.tek-tips.com/faqs.cfm?fid=4862
function addOnLoadHandler(myHandler) { 
  if ( typeof window.addEventListener != "undefined" )
      window.addEventListener( "load", myHandler, false );
  else if ( typeof window.attachEvent != "undefined" )
      window.attachEvent( "onload", myHandler );
  else {
      if ( window.onload != null ) {
          var oldOnload = window.onload;
          window.onload = function ( e ) {
              oldOnload( e );
              myHandler();
          };
      }
      else
          window.onload = myHandler;
  }
}

function openHelpTextWindow(url) {

   var newUrl = url;
  
   if(navigator.appName.indexOf("Netscape") > -1) {
  
   var version = parseInt(navigator.appVersion);
   
   if(version <= 5) {
      for(x=0; x < url.length; x++) {
          var c = url.charAt(x);
          newUrl += (c == ' ') ? "%20" : c;          
      } //for   
   } //if
   
   } //if
  
   //alert(newUrl);
   help_window=window.open(newUrl,
               "details_window",
               "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=250");

   help_window.onClose = window.focus();
   help_window.focus();
} //openHelpTextWindow		

// Idea from http://domscripting.com/presentations/xtech2006/ by Jeremy Keith // Fix to IE bug with getAttribute described at http://www.glennjones.net/Post/809/getAttributehrefbug.htm
// Opera 9 and greater appear not to have this problem.
// IE reportedly offers a workaround 2-arg version of getAttribute, where the second arg of 2 means to // do what the DOM Level 2 spec says to do, and what Opera and Firefox do already.
function doLabelHelpLinks() {
  if (document.getElementsByTagName) {
    var links = document.getElementsByTagName("a");
    for (var i=0; i < links.length; i++) {
      if (links[i].className.match("labelHelpLink")) {
        links[i].onclick = function() {
          var url = null;
          try {
            url = this.getAttribute("href", 2);
          } catch (e) {
            url = this.getAttribute("href");
          } 
          openHelpTextWindow(url);
          return false;
        };
      }
    }
  }
} 

//Global variable since addOnLoadHandler also defined and used in js_functions.js
//Check this flag to see if addOnLoadHandler already loaded
if(typeof(addonloadhandler_global_flag) == "undefined") { 
  	addonloadhandler_global_flag = 1;  
	addOnLoadHandler(doLabelHelpLinks);
}

function openWorkflowWindow(url) {

   var newUrl = url;
  
   if(navigator.appName.indexOf("Netscape") > -1) {
  
   var version = parseInt(navigator.appVersion);
   
   if(version <= 5) {
      for(x=0; x < url.length; x++) {
          var c = url.charAt(x);
          newUrl += (c == ' ') ? "%20" : c;          
      } //for   
   } //if
   
   } //if
  
   //alert(newUrl);
   help_window=window.open(newUrl,
               "details_window",
               "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=450");
} //openWorkflowWindow	


function handleUserMenuEvent(formdoc) {
  
   var eventText = formdoc.ActionBar.choicemenu.value;
   
   if(eventText != null && eventText != "null") {
      if(eventText == "Edit") {
         formdoc.ActionBar.action="ListUserDetailPage.jsp";
      } else if(eventText == "ChangeDomain") {
         formdoc.ActionBar.action="ChangeDomainPage.jsp"; 
      } else if(eventText == "ChangePassword") {
         formdoc.ActionBar.action="ChangeUserPasswordPage.jsp";
      } else if(eventText == "ChangeUserName") {
         formdoc.ActionBar.action="ChangeUserNamePage.jsp";
      } else if(eventText == "Delete") {
         formdoc.ActionBar.action="ConfirmDeleteUserPage.jsp";
      } //if-else if
      
      formdoc.ActionBar.submit();
   } //if
   
} //handleEvent


function handleGroupMenuEvent(formdoc) {

   var eventText = formdoc.ActionBar.choicemenu.value;
   //alert("eventText = " + eventText);
   
   if(eventText != null && eventText != "null") {
      if(eventText == "Delete") {
         formdoc.ActionBar.action="ConfirmDeleteGroupPage.jsp";
      } else if(eventText == "Edit") {
         formdoc.ActionBar.command.value = "Edit";
         formdoc.ActionBar.action="ListGroupDetailPage.jsp";
      } else if(eventText == "ChangeOwner") {
         formdoc.ActionBar.action="ChangeOwnerPage.jsp";
      } else if(eventText == "ChangeDomain") {
         formdoc.ActionBar.action="ChangeGroupDomainPage.jsp";
      } else if(eventText == "MailTo") {
         formdoc.ActionBar.action="MailToGroupPage.jsp";
      } //if-else if
      
      formdoc.ActionBar.submit();
   } //if

}
