/********************************************************
PDF Report Navigation
Created:  20030315 
Updated:  20040224 Donald 
Updated:  20060307 Wendelin (gotoPage() und search() nicht bei leerer Eingabe)

Copyright (c) 2003-04 by Donald Lessau, donald@xbeat.net
********************************************************/

function thisPage(){
  if (idxPage-offset<1) {
    document.write("Cover "+idxPage.toString());
  } else {
    document.write(sPage+" "+(idxPage-offset).toString()+"/"+(idxPageLast-offset).toString());
  }
}
function thisObjFile(){
  return sFileObj;
}
function printObj() {
  //beachten: print_page.css muss manuell ins output-Verzeichnis kopiert werden!
  window.print();
}
function gotoStart() {
	location.href=pageToFilename(idxPageFirst);
}
function gotoEnd() {
	location.href=pageToFilename(idxPageLast);
}
function gotoPageAbs(idxAbs) {
	location.href=pageToFilename(idxAbs);
}
function gotoPageRel(idxRel) {
	location.href=pageToFilename(idxPage+idxRel);
}
function pageToFilename(idx) {
  idx=Math.max(idxPageFirst,idx);
  idx=Math.min(idx,idxPageLast);
  var suffixNew=suffixNum+idx.toString();
  suffixNew=suffixNew.slice(suffixNew.length-suffixNum.length);
  suffixNew+=suffixPostnum; //empty if not jpg
  //alert(stem+suffixNew+ext);
  return stem+suffixNew+ext;
}
function gotoPage() {
//if(isNaN(document.formNav.txtGoto.value)||document.formNav.txtGoto.value==""||document.formNav.txtGoto.value>idxPageLast)
if(document.formNav.txtGoto.value=="")
  {
  alert("Please enter a valid page number");
  //alert("Bitte eine gültige Seitenzahl eingeben");
  }
else
  {
  var idxAbs=parseInt(document.formNav.txtGoto.value);
  idxAbs+=offset;
  gotoPageAbs(idxAbs);
  }
}
function switchLanguage() {
  //get value from cockpit select
  var newLa=document.getElementById("cboLanguage").value;
  //call the switch in the target location: there we find the validating data
  //need suffixPostnum to fork pdf/jpg
  location.href = "../"+newLa+"/"+switchfile+"?page=" + idxPage + "&sp=" + suffixPostnum;
}
function gotoIndex() {
  //get value from cockpit select
  var idxAbs=parseInt(document.getElementById("selectIndex").value);
	gotoPageAbs(idxAbs);
}

function search() {
if(document.getElementById("qt").value)
  {
  var url=searchlink + "?qt=" + document.getElementById("qt").value;
  if (suffixPostnum=="jpg") url+="&jpg=1"; //let search find jpeg-embedding pages
  url=encodeURI(url);
  //alert (url);
  location.href=url; //same win
  //window.open(url);  //new win
  }
}

function synchIndex() {
  // synch bookmark(=index) to current page
  document.getElementById("selectIndex").selectedIndex=idxBookmark-1;
}

// capture keys: nodo inside homesite
document.onkeypress = keypress;
function keypress(e) {
  KeyCode = window.event.keyCode;
	if(KeyCode==13) {
    event.keyCode = 0; //kill key, else beep
    if (window.event.srcElement.id == "txtGoto") {
  		gotoPage();
    }
    else if (window.event.srcElement.id == "qt") {
  		search();
  	}
  }
}
