// Status of the event to be checked
var keyDownEventEnabled = true;

var Netscape = new Boolean();
Netscape = false;
if (navigator.appName == "Netscape")  Netscape = true;

// Status informations
// document.write(navigator.appName + "<br>" + navigator.appVersion + "<br>" + navigator.appCodeName + "<br><br><br>");


function disableEvent(e) {

  if (!e) var e = window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();

  if (e.preventDefault) {
     if (e.cancelable) e.preventDefault();
  } else {
    e.keyCode = 0;
    e.returnValue = 0;
    // e.cancelBubble = true;
  }
  keyDownEventEnabled = false;
}

function actionEvent(task) {
  if (task == "admin") {
     if (this.top.iname == "job_edit") {
        top.opener.top.location.href = "../admin/menu_fs.php?navigationLevel=2&navigationPoint=verwaltung";
        // top.opener.top.maincontent.focus();
        top.opener.top.closeJobEdit();
     } else {
        top.location.href = "../admin/menu_fs.php?navigationLevel=2&navigationPoint=verwaltung";
        top.maincontent.focus();
     }
  }
  if (task == "job_edit") {
     if (this.top.iname == "job_edit") {
        this.focus();        
     } else {
       if (!top.job_edit) {
          top.jb_edit = window.open("../jobs/job_edit.php","job_edit"); 
       } else {
         if (top.job_edit.open) {
             top.job_edit.focus();
         } else {
             top.jb_edit = window.open("../jobs/job_edit.php","job_edit");
         }
       }
     }
  }
  if (task == "job_edit2") {
     if (this.top.iname == "job_edit2") {
        this.focus();        
     } else {
       if (!top.job_edit) {
          top.jb_edit = window.open("../jobs2/job_edit.php","job_edit"); 
       } else {
         if (top.job_edit.open) {
             top.job_edit.focus();
         } else {
             top.jb_edit = window.open("../jobs2/job_edit.php","job_edit");
         }
       }
     }
  }
  if (task == "job_list") {
     if (this.top.iname == "job_edit") {
        // top.opener.top.menu.location.href = "../admin/menu.php";
        if (!top.opener.top.maincontent.iname || top.opener.top.maincontent.iname != "job_list") {
           top.opener.top.maincontent.location.href = "../admin/jb_list.php";
        }   
        // top.opener.top.maincontent.focus();
        top.opener.top.closeJobEdit();
     } else {
        top.menu.location.href = "../admin/menu.php";
        // if (top.maincontent.iname != "job_list") {
           top.maincontent.location.href = "../admin/jb_list.php";
        // }
        top.maincontent.focus();
     }
  }
}

function actionMapEvent(e, eKeyCode) {
  // Verwaltung
  if (e.altKey && eKeyCode == 49) {  // "alt-1"
     disableEvent(e);
     actionEvent("admin");      
  }
  // Auftragserfassung
  if (e.altKey && eKeyCode == 50) {  // "alt-2"
     disableEvent(e);     
     actionEvent("job_edit");
  }
  // Auftragslisten
  if (e.altKey && eKeyCode == 51) {  // "alt-3"
     disableEvent(e);
     actionEvent("job_list");
  }
}

function eventKeyDownPressed(e) {
  if (e.altKey) {
     keyDownEventEnabled = true;
  }
  return true;
}

function eventKeyUpPressed(e) {
  // if (e.altKey) {
     keyDownEventEnabled = true;
  // }
  return true;
}

function eventKeyPressed(e) {
 if (Netscape) {
   // Verwaltung
   if (keyDownEventEnabled && e.altKey && e.which == 49) {  // "alt-1"
      disableEvent(e);
      actionEvent("admin");
   }   
   // Auftragserfassung
   if (keyDownEventEnabled && e.altKey && e.which == 50) {  // "alt-2"
      disableEvent(e);
      actionEvent("job_edit");
   }
   // Auftragslisten
   if (keyDownEventEnabled && e.altKey && e.which == 51) {  // "alt-3"
      disableEvent(e);
      actionEvent("job_list");
   }
 }   
};


if (Netscape) {
   document.addEventListener("keydown", eventKeyDownPressed, true);
   document.addEventListener("keyup", eventKeyUpPressed, true);
   document.addEventListener("keypress", eventKeyPressed, true);
}
