// **************
// * Navigation *
// **************


// *** Core menu code (BEGIN) **********************************************

// Shows a container
function myshow(elem_id) {
  if (elem_id != undefined && elem_id != '') {
      elem_id = '#' + elem_id;
      $(elem_id).show();
  };
}

// Hides a container
function myhide(elem_id) {
  if (elem_id != undefined && elem_id != '') {
     elem_id = '#' + elem_id;
     $(elem_id).hide();
  };
}

// Hides or shows the menu by clicking the page title container
function activateMenusByPageTitle() {
  if (menuSwitchActivationStateEnabled) {
     if (menuActiveByPageTitel) {  	 
        menuActiveByPageTitel = false;
        $('#menu').hide();
        $('#menu_reduced').hide();
     } else {
        menuActiveByPageTitel = true;
        $('#menu').show();
     }
  };
  menuSwitchActivationStateEnabled = true;
}


// Switch activation status of the menu
function activateMenu(activateId, deactivateId) {
  if (menuSwitchActivationStateEnabled) {
     activateId = '#' + activateId;
	   deactivateId = '#' + deactivateId;
	   // if (deactivateId != '' && document.getElementById(deactivateId)) {
	   if (deactivateId != '' && $(deactivateId)) {
 	      $(deactivateId).hide();
 	   }; 	   
	   // if (activateId != '' && document.getElementById(activateId)) {
	   if (activateId != '' && $(activateId)) {
 	      $(activateId).show();
 	   };
  };
  menuSwitchActivationStateEnabled = true;
}

// Call for loading one image
function changeContent(objectName,mode,navLevel) {
  if (navLevel == "") {navLevel = 0};
  navLevel = parseInt(navLevel);
  objName = '#' + objectName;
  
  useCascade = true;
  if (navLevel < 0) {
  	 useCascade = false;
  	 navLevel = 0;
  };
	tmpIndex = 0;    // "off"
 	if (mode == "over") {tmpIndex = 1;};
 	if (mode == "active") {tmpIndex = 2;};
 	if (mode == "deactive") {tmpIndex = 0;};

  if (objectName != activeElement[navLevel] || mode == "active" || mode == "deactive") {
       $(objName).css('background', 'url(' + navBgImg[navLevel][tmpIndex] + ')'); 
  };
  
  if (useCascade) {
     if (objectName != activeElement[navLevel]) {
        if (mode == "off") {
           if (activeElement[navLevel] == "") {
              // Hide elements of sub-navigation
              for (i = navLevel; i <= menuNavigationDeep; i++) {
                  len = menuStruct[i].length;
                  for (j = 0; j < len; j++) {
                      if (subMenu[menuStruct[i][j]]) {
                         len2 = subMenu[menuStruct[i][j]].length;
                         for (k = 0; k < len2; k++) {
                             myhide(subMenu[menuStruct[i][j]][k]);
                         };
                      };
                  };
              };
           };
        };
        if (mode == "over") {
           if (activeElement[navLevel] == "") {
              // Show element of sub-navigation
              if (subMenu[objectName]) {
                 len = subMenu[objectName].length;
                 for (i = 0; i < len; i++) {
                     myshow(subMenu[objectName][i]);
                 };
              };
           };
        };
     };
  };
}

// Call for enable a sub menu as active and disable the old active element
function setMenu(objectName,navLevel) {
  if (navLevel == "") {navLevel = "0"};

  // Disable current displayed sub menus
  for (i = navLevel; i <= menuNavigationDeep; i++) {
      // Reset menu
      len = menuStruct[i].length;
      for (j = 0; j < len; j++) {
     	   if (document.getElementById(menuStruct[i][j])) {
     	      changeContent(menuStruct[i][j],'deactive',i);
     	   };      	
      	
      	  // Hide sub menus if exist
          if (subMenu[menuStruct[i][j]]) {         	
             len2 = subMenu[menuStruct[i][j]].length;
             for (k = 0; k < len2; k++) {
                 myhide(subMenu[menuStruct[i][j]][k]);
             };
          };
      };
  };

  if (objectName != activeElement[navLevel] || activeElement[navLevel] == "") {
     // Enable new submenu
     if (subMenu[objectName]) {
        len = subMenu[objectName].length;
        for (i = 0; i < len; i++) {
            myshow(subMenu[objectName][i]);
        };
     };

     // Define active element and delete cascade
     for (i = (navLevel + 1); i <= menuNavigationDeep; i++) {
         activeElement[i] = "";
     };
     activeElement[navLevel] = objectName;
     changeContent(activeElement[navLevel],'active',navLevel);
  } else { 
     for (i = navLevel; i <= menuNavigationDeep; i++) {
         activeElement[i] = "";
     };
  };
}

// Gets the id of the parent element
// if parentLevel==0 then take parent, if parentLevel==1 then take parent of the parent, etc.
function getParentId(objectId, parentLevel) {
	if (parentLevel == '') {parentLevel = 0};
	parentLevel = parseInt(parentLevel);
	objId = '#' + objectId;
	parentId = $(objId).parents()[parentLevel].id;
	return parentId;
}

// Displays (hides and shows) sub menus (if does exist) according to an item
// E.g. it shows all elements (menu containers) like subMenu["preise"] => "menu_01_02_01
function displaySubmenu(itemId, mode) {
if (mode == '') {mode = 'show'};
  if (itemId) {         	
     len = subMenu[itemId].length;
     for (i = 0; i < len; i++) {
     	   if (mode == 'show') {
            myshow(subMenu[itemId][i]);
         } else {
         	  myhide(subMenu[itemId][i]);
         };
     };
  };
}

// Initiates the menu
function setMenuOnLoad(objectName,navLevel) {
  if ($(objectName)) {
     navLevel = parseInt(navLevel);
// alert('objectName=' + objectName + ' navLevel=' + navLevel + ' activeElement[' + navLevel + ']=' + activeElement[navLevel]);

     // Activate current item
     changeContent(objectName,'active',navLevel);
     activeElement[navLevel] = objectName;

     // Get id of the parent element  
     // E.g. objectName == "servicepreise" => parentId = "menu_01_02_01"
     parentId = getParentId(objectName,0);

     // Lookup for item of next parent navigation level having "parentId" in associated Array
     // E.g. "menu_01_02_01" is element of subMenu["preise"] => Get all elements of subMenu["preise"]
     for (tmpNavLevel = (navLevel - 1); tmpNavLevel >= 0; tmpNavLevel--) {

         // Iterate all items of the navigation level in menuStruct[tmpNavLevel]
         len = menuStruct[tmpNavLevel].length;
         for (j = 0; j < len; j++) {

             if (subMenu[menuStruct[tmpNavLevel][j]]) {

                len2 = subMenu[menuStruct[tmpNavLevel][j]].length;
                tmpActivateSubmenu = false;
                for (k = 0; k < len2; k++) {
                	   if (subMenu[menuStruct[tmpNavLevel][j]][k] == parentId) {
                       tmpActivateSubmenu = true;
                    };
                };
                if (tmpActivateSubmenu) {
                	  // E.g. show all containers of subMenu["preise"]
                	  displaySubmenu(menuStruct[tmpNavLevel][j], 'show');
                	
                	  // Activate parent item e.g. "preise" (= menuStruct[tmpNavLevel][j])
                	  changeContent(menuStruct[tmpNavLevel][j],'active',tmpNavLevel);
                	  activeElement[tmpNavLevel] = menuStruct[tmpNavLevel][j];

                	  parentId = getParentId(menuStruct[tmpNavLevel][j],0);
                };
             };
         };
     };
  };
}

// Sets all links of a special link class to "hidefocus"
function hideFocusOfLinkClass() {
  // $$('#a_menu').each(function(i) {i.hideFocus = "true";}); 
}


// C9E9FE   hellgrün
// 47B868   grün
// 2091C9   blau

var menuActive = true;
// var menuActiveByPageTitel = true;
<?php if ($menuActiveByPageTitel) : ?>
   var menuActiveByPageTitel = true;
<?php else : ?>
   var menuActiveByPageTitel = false;
<?php endif; ?>
var menuNavigationDeep = <?php echo $jsMenuNavigationDeep ?>;

var menuSwitchActivationStateEnabled = true;

// Init parameter for current displayed submenus
var activeElement = new Array();
<?php
for ($j = 0; $j <= $jsMenuNavigationDeep; $j++) :
    echo "activeElement[" . $j . "] = '';";
endfor;
?>
var activeElementLen = activeElement.length;

var navBgColor = new Array();
navBgColor[0] = "#1b12b9";   // menu_01 blau  (27, 18, 185)
navBgColor[1] = "#4e45ec";   // menu_02 blau  (78, 69, 236)
navBgColor[2] = "#97bcFF";   // menu_03 blau  (151, 188, 255)
navBgColor[3] = "#97bcFF";

var navBgImg = new Array();
navBgImg[0] = new Array("../images/navItemBgOffMenu01.jpg", "../images/navItemBgOverMenu01.jpg", "../images/navItemBgActiveMenu01.jpg");
navBgImg[1] = new Array("../images/navItemBgOffMenu02.jpg", "../images/navItemBgOverMenu02.jpg", "../images/navItemBgActiveMenu02.jpg");
navBgImg[2] = new Array("../images/navItemBgOffMenu03.jpg", "../images/navItemBgOverMenu03.jpg", "../images/navItemBgActiveMenu03.jpg");
navBgImg[3] = new Array("../images/navItemBgOffMenu03.jpg", "../images/navItemBgOverMenu03.jpg", "../images/navItemBgActiveMenu03.jpg");

// Array of the menu structure
var menuStruct = new Array();
// menuStruct[0] = new Array("verwaltung","auftraege", ...);
// menuStruct[1] = new Array("kunden","transporteure",... ,"uebersicht","pdf_ausgabe");
// ...
<?php
for ($j = 1; $j < $menuLevels; $j++) :
    echo "menuStruct[" . ($j - 1) . "] = new Array(" . $jsMenuStruct[$j] . ");\n";
endfor;
?>

// Array of containers be visible by hovering and click
var subMenu = new Array();
// subMenu["verwaltung"] = new Array("menu_01_01","menu_01_02","menu_01_03");
// subMenu["rechnungen"] = new Array("menu_02_01");
// ...
<?php
$jsMenuOut = "";
$tmpLen = count($jsSubMenu);  
for ($j = 0; $j < $tmpLen; $j++) :
    $jsMenuOut .=  "subMenu[\"" . $jsSubMenu[$j][0] . "\"] = new Array(";
    $tmpLen2 = count($jsSubMenu[$j][1]);
    for ($k = 0; $k < $tmpLen2; $k++) :
        $jsMenuOut .= "\"" . $jsSubMenu[$j][1][$k] . "\"";
        if ($k < ($tmpLen2 - 1)) : 
           $jsMenuOut .= ",";
        endif;          
    endfor;
    $jsMenuOut .= ");\n";
endfor;
echo $jsMenuOut;
?>


// *** Core menu code (END) **********************************************



// *** Framework Wrapper (BEGIN) ***************************************

function vShow(selector) {
	myshow(selector);
};

function vHide(selector) {
  myhide(selector);
};

function vSetCss(selector, cssStyles) {
  selector = '#' + selector;
  $(selector).css(cssStyles);
};

function vSetElementContent(selector, content) {
  selector = '#' + selector;
  $(selector).html(content);
};

function vGetElementContent(selector) {
  selector = '#' + selector;
  return $(selector).html();
};

function vConfirmFunc(msg, fn, height, selector) {
  if (height == "" || height == undefined) { height = '160'; };
  if (selector == "" || selector == undefined) { selector = 'dialog-confirm'; };
  selector = '#' + selector;
  genConfirm(msg);
	$(function() {
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		$( selector ).dialog({
			resizable: false, height:160, modal: true,
			buttons: {
				"Ja": function() { fn(); },
				"Nein": function() { $( this ).dialog( "close" ); }
			}
		});
	});
};

function vConfirmFuncPar(msg, fn, height, selector, par1, par2, par3, par4, par5, par6, par7, par8, par9) {
  if (height == "" || height == undefined) { height = '160'; };
  if (selector == "" || selector == undefined) { selector = 'dialog-confirm'; };
  selector = '#' + selector;
  genConfirm(msg);
	$(function() {
		$( "#dialog:ui-dialog" ).dialog( "destroy" );
		$( selector ).dialog({
			resizable: false, height:160, modal: true,
			buttons: {
				"Ja": function() { 
				        if (par9 != '') { 
				           fn(par1, par2, par3, par4, par5, par6, par7, par8, par9); 
				        } else if (par8 != '') {
				           fn(par1, par2, par3, par4, par5, par6, par7, par8); 
				        } else if (par7 != '') {
				           fn(par1, par2, par3, par4, par5, par6, par7); 
				        } else if (par6 != '') {
				           fn(par1, par2, par3, par4, par5, par6); 
				        } else if (par5 != '') {
				           fn(par1, par2, par3, par4, par5); 
				        } else if (par4 != '') {
				           fn(par1, par2, par3, par4); 
				        } else if (par3 != '') {
				           fn(par1, par2, par3); 
				        } else if (par2 != '') {
				           fn(par1, par2); 
				        } else if (par1 != '') {
				           fn(par1);
				        }
				      },
				"Nein": function() { $( this ).dialog( "close" ); }
			}
		});
	});
};

// *** Framework Wrapper (END) ******************************************



// *** DHTML (BEGIN) ****************************************************

var activeButton = '';
var disabledButtons = new Array();   // E.g. for export to disable all buttons after selecting one of them

function checkButtonIsDisabled(buttonName) {
  notDisabled = true;
  disabledButtonsLen = disabledButtons.length;
  for (i = 0; i < disabledButtonsLen; i++) {
      if (buttonName == disabledButtons[i]) {notDisabled = false;};
  };
  return notDisabled;
}

function changeButton(mode,buttonName,content,paddingLeft,paddingTop) {

  elem = '#' + buttonName;
  // elem = $(buttonName);
  notDisabled = checkButtonIsDisabled(buttonName);
  
  if (buttonName != activeButton && notDisabled) {
     if (mode == "off") {
     	  // elem.setStyle({color: '#FFFFFF'});
	  $(elem).css('color', '#FFFFFF');
        // elem.innerHTML = '<div style="margin-left:' + paddingLeft + '; margin-top:' + paddingTop + ';">' + content + '</div>\n';
     };
     if (mode == "over") {
     	  // buttonWidth = elem.getStyle('width');
	  buttonWidth = $(elem).css('width');
     	  buttonWidth = parseInt(buttonWidth.substring(0, (buttonWidth.length - 2))) - 2;
     	  // buttonHeight = elem.getStyle('height');
	  buttonHeight = $(elem).css('height');
     	  buttonHeight = parseInt(buttonHeight.substring(0, (buttonHeight.length - 2))) - 2;
     	  // elem.setStyle({color: '#97bcFF'});
	  $(elem).css('color', '#97bcFF');

     	  // elem.innerHTML = '<div style="margin-left:' + paddingLeft + '; margin-top:' + paddingTop + '; color:#FFFFFF;">' + 'x' + content + '</div>\n';
/*
     	  tmpInnerHTLM  = eval('<div style="height:1px; background:#FFFFFF;"></div>\n' +
     	                  '<div style="height:' + buttonHeight + 'px;">\n' +
     	                  '  <div style="width:1px; height:100%; background:#FFFFFF;"></div>\n' +
     	                  '  <div style="width:' + buttonWidth + 'px; height:' + buttonHeight + 'px;">' + content + '</div>\n' +
     	                  '  <div style="width:1px; height:100%; background:#000000;"></div>\n' +
     	                  '</div>\n' +
                        '<div style="height:1px; background:#000000;"></div>\n');
        // elem.innerHTML = tmpInnerHTLM;
	$(elem).text(tmpInnerHTLM);
*/        
     };
  };
}

// *** DHTML (END) ****************************************************

// JQuery.Request (POST)
function ajax_request(url, data) {
  $.ajax({
     type: "POST",
     url: url,
     data: data,
     success: function(msg){ajax_response(msg);}
  });
}
// JQuery.Response (POST)
function ajax_response(msg) {
    if(!bHasRedirect) {
        $('maincontent').innerHTML = msg;
    }
    else {
        bHasRedirect = false;
        ajax_request(msg, "");
    }
}

// JQuery.Request (GET)
function ajaxRequestGet(url, data) {
  $.ajax({
     type: "GET",
     url: url,
     data: data,
     async: false,
     cache: false,
     success: function(msg){eval(msg);}
  });
}

var statusMessage = "<?php echo $statusMessage ?>";

function displayStatusMessage() {
 if (statusMessage != "") {
    alert(statusMessage);
 }
};

function hqCheckAll(numOfHq) {
  for (i = 0; i < numOfHq; i++) {
	  document.getElementsByName('f_hq_id[]')[i].checked = true;
	}
}

function hqUncheckAll(numOfHq) {
  for (i = 0; i < numOfHq; i++) {
	  document.getElementsByName('f_hq_id[]')[i].checked = false;
  }
}

function mkImpressumPopupWin() {

  var widthPopupWin = 250;
  var heightPopupWin = 310;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin=window.open("../admin/impressum.html", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin);
};

function mkLanguagePopupWin() {

  var widthPopupWin = 250;
  var heightPopupWin = 310;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin=window.open("../admin/language.php", "","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin);
};

function submitPage(navItem) {
  if (document.forms[0].currentNavigationItem) {
     document.forms[0].currentNavigationItem.value = navItem;
  }
  if (document.forms[0].menuActiveByPageTitel) {
     if (menuActiveByPageTitel) {
        document.forms[0].menuActiveByPageTitel.value = '0';
     } else {
        document.forms[0].menuActiveByPageTitel.value = '1';
     }
  }
  document.forms[0].submit();
};

function genConfirm(text, headline, appendSelector) {
  if (headline == '' || headline == undefined) {headline = '<?php echo getLngt("Bestätigung") ?>';};
  if (text == '' || text == undefined) {text = '<?php echo getLngt("Wirklich?") ?>';};
  if (appendSelector == '' || appendSelector == undefined) {appendSelector = '#maincontent';};
  $(appendSelector).append('<div id="dialog-confirm" title="' + headline + '"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>' + text + '</p></div>');
}

function logout() {
  if (confirm('<?php echo getLngt("Möchten Sie sich wirklich abmelden?") ?>')) {
     document.location.href = "../admin/logout.php";
  };
};

<?php if ($browserOk) : ?>
function redirectLocation(locUrl) {
  if (locUrl && locUrl != '') {
     document.location.href = locUrl;
  }
};

function metasearchSpecial (objType, containerNo = '1') {
  var searchVal = $("#metaSearch").val();  
  var searchProcessOk = false;  
  var ctNum = padl(containerNo.toString(),2,'0');
  if (!objType) {objType = ''};
  searchVal = searchVal.trim();
  searchValLen = searchVal.length;
  if (objType != '' && searchVal != ''&& searchValLen >= 4) {
	   ajaxRequestGet('../include/ajaxReqSearch.php', 'retMode=0&objType=' + objType + '&searchValue=' + encodeURI(escape(searchVal)));
	   searchProcessOk = true;
	   if (searchResult != '') {
	   	  $('#metaSearchResult_' + ctNum).html(searchResult);
	   }
  } else {
  	$('#metaSearchResult_' + ctNum).html('<center><span style="color:red"><?php echo getLngt("Bitte mindestens 4 Zeichen eingeben!") ?></span></center>');
  }
  return searchProcessOk;
};

function metasearch (objType = '') {
	// Init container
	$('#metaSearchResult_01').html('');
	$('#metaSearchResult_02').html('');
	$('#metaSearchResult_03').html('');
	$('#metaSearchResult_04').html('');
	// Search in categories
	var searchProcessOk = true;
	var ctNum = 0;
	if (objType == '' || objType == 'jb') {
	   ctNum++;
	   searchProcessOk = metasearchSpecial('jb', ctNum);
	}
	if (searchProcessOk && (objType == '' || objType == 'cs')) {
	   ctNum++;
		 searchProcessOk = metasearchSpecial('cs', ctNum);
	}
	if (searchProcessOk && (objType == '' || objType == 'cr')) {
	   ctNum++;
		 searchProcessOk = metasearchSpecial('cr', ctNum);
	}
	if (searchProcessOk && (objType == '' || objType == 'crvh')) {
	   ctNum++;
		 searchProcessOk = metasearchSpecial('crvh', ctNum);
	}
};
<?php endif; ?>

function openMfHistory() {
  var widthPopupWin = 900;
  var heightPopupWin = 700;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/mf_history.php","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openJobInvoiceAssoc() {
  var widthPopupWin = 1200;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../jobs/jb_inv_assoc.php","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};

function openVehicleDisposition() {
  var widthPopupWin = 1800;
  var heightPopupWin = 1024;
  var leftPopupWin = (screen.width / 2) - (widthPopupWin / 2) - 12;
  var topPopupWin = (screen.height / 2) - (heightPopupWin / 2) - 50;
  var popupWin;
  popupWin = window.open("../admin/vehicle_disposition.php","","dependent=yes,width=" + widthPopupWin + ",height=" + heightPopupWin +",left=" + leftPopupWin + ",top=" + topPopupWin + ",scrollbars=yes");
};


// Changes user state regarding context
// context         : Context like "usr_state_dispo", etc.
// activationState : State value for GDC content (if empty then toggle between 0 and 1, otherwise it could be e.g. an ID or so on)
function changeButtonMenuState (context,buttonName,buttonText,buttonSwichMode,activationState,textColor1,textColor2,bgColor1,bgColor2) {
  elem = '#' + buttonName;

  if (!activationState || activationState == '') { activationState = '1' };

  // Avoid switching the menu
  menuSwitchActivationStateEnabled = false;

  if (context != '' && buttonName != '') {

     // Check for defaults
     buttonSwichMode
     if (!buttonSwichMode || buttonSwichMode == '') { buttonSwichMode = '0' }; // Toggle button between colors
     
     var textColor = 'rgb(255, 255, 255)';                                     // White (Default)
     if (!textColor1 || textColor1 == '') { textColor1 = 'rgb(255, 0, 0)' };   // Red
     if (!textColor2 || textColor2 == '') { textColor2 = 'rgb(0, 255, 0)' };   // Green
     var bgColor = 'rgb(78, 69, 236)';                                         // Blue [constMenuBackground[2] <=> "#4e45ec"] (Default)
     if (!bgColor1 || bgColor1 == '') { bgColor1 = 'rgb(78, 69, 236)' };       // Blue [constMenuBackground[2] <=> "#4e45ec"]
     if (!bgColor2 || bgColor2 == '') { bgColor2 = 'rgb(78, 69, 236)' };       // Blue [constMenuBackground[2] <=> "#4e45ec"]     

     $(elem).css('background-color', bgColor);
     retValue = '';

     // 0 : Toggles between colors [default] (e.g. manually enabling/disabling item)
     // 1 : Set textColor2 in every case (read receipt by user)
     if (buttonSwichMode == '1') {
        $(elem).css('color', textColor2);
        ajaxRequestGet('../include/ajaxReqLib.php', 'mode=500&wrap_html=1&value_01=usr&value_02=<?php echo ec($usr_id) ?>&value_03=' + context + '&value_04=' + activationState + '&value_05=');

     } else if (buttonSwichMode == '2') {
        // Get activation state of the current user
    	  ajaxRequestGet('../include/ajaxReqLib.php', 'mode=6&db_table=genericdatacontainer&id_01=gdc_obj_type&value_01=usr&id_02=gdc_obj_id&value_02=<?php echo $usr_id ?>&id_03=gdc_gen_fieldname&value_03=' + context + '&db_return_field=gdc_content');
    	  if (retValue != '') {
    	     activationState = retValue;
           if (activationState == '0') {
              $(elem).css('color', textColor1);
           }
           if (activationState == '1') {
              $(elem).css('color', textColor2);
           }
        }
     } else {
        // Get activation state of the current user
    	  ajaxRequestGet('../include/ajaxReqLib.php', 'mode=6&db_table=genericdatacontainer&id_01=gdc_obj_type&value_01=usr&id_02=gdc_obj_id&value_02=<?php echo $usr_id ?>&id_03=gdc_gen_fieldname&value_03=' + context + '&db_return_field=gdc_content');
    	  if (retValue != '') {
   	       activationState = retValue;
   	    }
        if (activationState == '0') {
           // Activate the state regarding context
           activationState = 1;
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=500&wrap_html=1&value_01=usr&value_02=<?php echo ec($usr_id) ?>&value_03=' + context + '&value_04=' + activationState + '&value_05=');
           if (retValue != '') {
              $(elem).css('color', textColor2);
           }
        } else {
           // Deactivate the state regarding context
           activationState = 0;
           ajaxRequestGet('../include/ajaxReqLib.php', 'mode=500&wrap_html=1&value_01=usr&value_02=<?php echo ec($usr_id) ?>&value_03=' + context + '&value_04=' + activationState + '&value_05=');
           if (retValue != '') {
              $(elem).css('color', textColor1);
           }
        };
     }
  };
}

// Get current user states an other informations for output in page info
function menuGetInfodata (context, par_01, par_02, par_03, par_04, par_05) {
  var htmlMenuOut = '';
  var htmlContentOut = '';

  htmlMenuOut = '<button type="button" class="buttonMenuUserInfo" onClick="myhide(\'page_info\');"><?php echo getLngt("Schließen") ?></button>';

  var usrStateKey = '';
  var usrStateText = '';
  var usrStateTriggerKey = '';
  
  <?php
    if (!isset($menuItemListKeyArrayLen)) : $menuItemListKeyArrayLen = 0; endif;
    if ($menuItemListKeyArrayLen > 0) : 
       for ($i = 0; $i < $menuItemListKeyArrayLen; $i++) :
           $menuItemKey = "usr_state_" . $menuItemListKeyArray[$i];       
           echo "if (context == '" . $menuItemKey . "') {\n";
           echo "   usrStateKey = '" . $menuItemKey . "';\n";
           echo "   usrStateText = '" . getLngt($menuItemListArray[$menuItemListKeyArray[$i]]) . "'\n";
           echo "   usrStateTriggerKey = 'trigger_" . $menuItemKey . "';\n";
           echo "};\n";
       endfor;
    endif;
  ?>

  if (usrStateKey != '' && usrStateText != '' && usrStateTriggerKey != '') {
     // Get all employees being activated for the current state
     ajaxRequestGet('../include/ajaxReqGeneric.php', 'mode=html&incFile=inc_user.inc&fun=getUserByState&fixNumOfPars=4&par_01=' + usrStateKey + '&par_02=1&par_03=1&par_04=' + usrStateText + '&retIdx=0');
     htmlContentOut += retValue;

     // Get activation state of the current user
     ajaxRequestGet('../include/ajaxReqLib.php', 'mode=6&db_table=genericdatacontainer&id_01=gdc_obj_type&value_01=usr&id_02=gdc_obj_id&value_02=<?php echo $usr_id ?>&id_03=gdc_gen_fieldname&value_03=' + context + '&db_return_field=gdc_content');

     htmlMenuOut += '<button type="button" class="buttonMenuUserState" name="' + usrStateTriggerKey + '" id="' + usrStateTriggerKey + '" onClick="changeButtonMenuState(\'' + usrStateKey + '\',\'' + usrStateTriggerKey + '\',\'' + usrStateText + '\',\'\',\'' + retValue + '\'); changeButtonMenuState(\'' + usrStateKey + '\',\'' + usrStateKey + '\',\'' + usrStateText + '\',\'2\'); menuGetInfodata(\'' + usrStateKey + '\');">' + usrStateText + '</button>';
     
     $('#page_info_menu').html(htmlMenuOut);
     $('#page_info_content').html(htmlContentOut);

     changeButtonMenuState(usrStateKey,usrStateTriggerKey,'','2');
  };

  if (context == 'usr_state_newsticker') {
     htmlMenuOut += '<button type="button" class="buttonMenuUserInfo" onClick="myhide(\'page_info\'); document.location.href = \'../admin/newsticker.php?currentNavigationItem=newsticker\';"><?php echo getLngt("Bisherige") ?></button>';

     // Get all news for the curent user having activated the button "Mitteilungen"
     ajaxRequestGet('../include/ajaxReqGeneric.php', 'mode=html&incFile=inc_user.inc&fun=getUserMessages&fixNumOfPars=2&par_01=' + par_01 + '&par_02=' + par_02 + '&retIdx=0');
     htmlContentOut += retValue;
     
     $('#page_info_menu').html(htmlMenuOut);
     $('#page_info_content').html(htmlContentOut);
  };

  menuSwitchActivationStateEnabled = false;
  myshow('page_info');
}
