/**** Scripts für www.panorado.com ****/


function showImage(strParams, width, height) {
  width +=20; height +=20;
  var availWidth  = screen.availWidth - 10;
  var availHeight = screen.availHeight - 32;
  var width  = Math.min(width, availWidth);
  var height = Math.min(height, availHeight);
  var left   = (availWidth - width) / 2;
  var top    = (availHeight - height) / 2;
  var strWidthName  = isMSIE() ? "width" : "innerWidth";
  var strHeightName = isMSIE() ? "height" : "innerHeight";

  var strBig = (width == availWidth || height == availHeight) ? "yes" : "no";

  var strWndParams = "left=" + left + ",top=" + top + "," +
                     strWidthName + "=" + width + "," + strHeightName + "=" + height +
                     ",resizable=" + strBig + ",scrollbars=" + strBig +
                     ",menubar=no,status=no,toolbar=no,directories=no";

  checkCloseImage(); // neue Größe erzwingen
  wndImage = self.open("../ImageViewer.htm?" + strParams, "_Image_Viewer_", strWndParams);
  if (wndImage != null) wndImage.focus();
}


function showPano(strParams) {
  if (!navigator.javaEnabled()) {
    alert("Please enable Java to open the panorama viewer!");
    return;
  }

  var availWidth  = screen.availWidth - 10;
  var availHeight = screen.availHeight - 32;
  var width  = Math.min(840, availWidth);
  var height = Math.min(560, availHeight);
  var left   = (availWidth - width) / 2;
  var top    = (availHeight - height) / 2;
  var strWidthName  = isMSIE() ? "width" : "innerWidth";
  var strHeightName = isMSIE() ? "height" : "innerHeight";

  var strResizable = navigatorSupportsAppletScaling() ? "yes" : "no";
  var strWndParams = "left=" + left + ",top=" + top + "," +
                     strWidthName + "=" + width + "," + strHeightName + "=" + height +
                     ",resizable=" + strResizable +
                     ",scrollbars=no,menubar=no,status=no,toolbar=no,directories=no";

  strParams += "&language=" + getLang();

  wndImage = self.open("../PanoramaViewer.htm?" + strParams, "_Image_Viewer_", strWndParams);
  if (wndImage != null) wndImage.focus();
}


function showMockup() {
  var availWidth  = screen.availWidth - 10;
  var availHeight = screen.availHeight - 32;
  var strWidthName  = isMSIE() ? "width" : "innerWidth";
  var strHeightName = isMSIE() ? "height" : "innerHeight";

  if (navigator.javaEnabled()) {  // Mockup mit Applet
    if (typeof(self.Viewer) != "undefined") self.Viewer.setSpeed(0, 0);
    var width  = Math.min(666, availWidth);
    var height = Math.min(765, availHeight);
    var left   = (availWidth - width) / 2;
    var top    = (availHeight - height) / 2;
    var strWndParams = "left=" + left + ",top=" + top + "," +
                       strWidthName + "=" + width + "," + strHeightName + "=" + height +
                       ",resizable=yes,scrollbars=yes,menubar=no,status=no,toolbar=no,directories=no";
    wndImage = self.open("PanoradoMockup.htm", "_Image_Viewer_Mockup_", strWndParams);
  }
  else {  // Animated GIF
    var width  = Math.min(360, availWidth);
    var height = Math.min(320, availHeight);
    var left   = (availWidth - width) / 2;
    var top    = (availHeight - height) / 2;
    var strWndParams = "left=" + left + ",top=" + top + "," +
                       strWidthName + "=" + width + "," + strHeightName + "=" + height +
                       ",resizable=no,scrollbars=no,menubar=no,status=no,toolbar=no,directories=no";

    wndImage = self.open("PanoradoGifAnimation.htm", "_Image_Viewer_", strWndParams);
  }

  if (wndImage != null) wndImage.focus();
}


function showLogos() {
  var availWidth  = screen.availWidth - 10;
  var availHeight = screen.availHeight - 32;
  var strWidthName  = isMSIE() ? "width" : "innerWidth";
  var strHeightName = isMSIE() ? "height" : "innerHeight";

  var width  = Math.min(480, availWidth);
  var height = Math.min(340, availHeight);
  var left   = (availWidth - width) / 2;
  var top    = (availHeight - height) / 2;
  var strWndParams = "left=" + left + ",top=" + top + "," +
                     strWidthName + "=" + width + "," + strHeightName + "=" + height +
                     ",resizable=no,scrollbars=no,menubar=no,status=no,toolbar=no,directories=no";

  var wnd = self.open("Logos.htm", "_Logos_", strWndParams);
  if (wnd != null) wnd.focus();
}


function checkCloseImage() {
  if (!this.wndImage);
  else if (!(this.wndImage.closed))
    this.wndImage.close();
}


function onLoadHeader() {
  var strPage, nPos, wndPage, wndNav = this;

  if (top.frames.length < 3)
    strPage = "Home";
  else if (wndPage = top.frames[2]) {
    strPage = wndPage.location.href;
    strPage = strPage.substring(strPage.lastIndexOf("/") + 1, strPage.lastIndexOf("."));

    nPos = strPage.lastIndexOf("_");
    if (nPos > 0) strPage = strPage.substring(0, nPos);
  }
  else
    strPage = "Home";

  var Links = wndNav.document.links;
  var Link, length, i, bActive;

  // Akt. Menüpunkt hervorheben:
  for (i = 0, length = Links.length; i < length; i++) {
    Link = Links[i];
    if (!Link.name) continue;
    bActive = (Link.name == strPage);
    Link.style.fontWeight = bActive ? "bold" : "normal";
    Link.style.backgroundRepeat = "no-repeat";
    Link.style.backgroundPosition = "0 3";
    Link.style.backgroundImage = bActive ? "url(../Images/NavBullet2.gif)" : "url(../Images/NavBullet1.gif)";

  }
}


function onLoadIndex() {
  if (isOldBrowser())
    alert("Notice:\nYou are using an old web browser which might not be able to display all style properties correctly!");

  top.location.replace(systemLang() + "/index.htm");
}


function onLoadLangIndex(strLang) {
  var strSearch;

  top.lang = strLang;

  strSearch = self.location.search.substr(1);

  if (strSearch != "") {
    wndPage = top.window[2];
    wndPage.location.replace(strSearch);
  }
}


function onLoadHome() {
  onLoadPage();

  var objBottom = document.getElementById("Bottom");

  if (objBottom != null) {
    var Now = new Date();
    ///var strDisplay = (Now.getTime() > Date.parse("Mon, 12 Jun 2006 00:00:00 GMT")) ? "none" : "block";
    var strDisplay = "block";
    objBottom.style.display = strDisplay;
  }
}


function onLoadGallery() {
  onLoadPage();

  if (!navigator.javaEnabled())
    document.getElementById("JavaWarning").style.display = "block";
}


function onLoadPage() {
  top.defaultStatus = document.title;
}


function onLoadOrderPage(strLang) {
  var strUrl = "https://secure.shareit.com/shareit/checkout.html?PRODUCT[300001562]=1&amp;stylefrom=300001562&amp;language=";
  location.replace(strUrl);
}


function onLoadAppletOrderPage() {
  window.resizeTo(700, Math.min(screen.availHeight - 32, 1000));
  window.moveTo(10, 10);
  window.focus();
  checkLicenseType(document.Order);
  checkVat(document.Order);
}

function update()  {
  // Ggfs. Fenster aus Aufrufer-Frame befreien bzw. Rahmen nachladen:
  if (top == self || top.location.hostname != self.location.hostname) {
    var strPage = self.location.href;
    strPage = strPage.substring(strPage.lastIndexOf("/") + 1);
    top.location.replace("index.htm?" + strPage);
    return;
  }

  // Muss auch bei history.back funktionieren!
  var strLang = (self.location.href.indexOf("/de/") >= 0) ? "de" : "en";
  top.lang = strLang;

  var wndNav = top.window[1];
  wndNav.location.replace("Header.htm");
}


function changeLang(strNewLang) {
  var strOldLang, wndPage, strUrl;

  strOldLang = top.lang;
  top.lang = strNewLang;

  wndPage = top.window[2];
  strUrl = wndPage.location.href;
  strUrl = strUrl.replace("/" + strOldLang + "/", "/" + strNewLang + "/");
  wndPage.location.href = strUrl;
}


function sslAction(form, strRelPath) {
  if (location.hostname.indexOf("panorado.com") < 0) return true; // funktioniert nur auf all-inkl-Server!

  strUrl = "https://ssl-account.com/" +
           location.hostname +
           location.pathname.substr(0, location.pathname.lastIndexOf("/") + 1) +
           strRelPath;

  form.action = strUrl;
  return true;
}


function checkMail(Form) {
  var strMsg;

  Form.useragent.value = navigator.userAgent;

  if (!checkEmpty(Form.name.value)) {
    strMsg = (getLang() == "de") ? "Bitte tragen Sie Ihren Namen ein!" : "Please enter your name!";
    alert(strMsg);
    Form.name.focus();
    return false;
  }

  if (!checkMailAddress(Form.email.value)) {
    strMsg = (getLang() == "de") ? "Bitte tragen Sie Ihre E-Mail-Adresse ein!" : "Please enter your e-mail address!";
    alert(strMsg);
    Form.email.focus();
    return false;
  }

  return true;
}


function checkAppletOrder(Form) {
  var strMsg;

  if (!checkWebsiteAddress(Form.website.value)) {
    strMsg = (getLang() == "de") ? "Bitte tragen Sie die Website-Adresse ein!" : "Please enter the website address!";
    alert(strMsg);
    Form.website.focus();
    return false;
  }

  if (!Form.type[3].checked && !Form.type[4].checked && !Form.type[5].checked)
    Form.upgradekey.value = "";
  else if (!checkLicenseKey(Form.upgradekey.value)) {
    strMsg = (getLang() == "de") ?
    "Bitte tragen Sie Ihren existierenden Lizenzschlüssel ein!" : "Please enter your existing license key!";
    alert(strMsg);
    Form.upgradekey.focus();
    return false;
  }

  if (!checkEmpty(Form.name.value)) {
    strMsg = (getLang() == "de") ? "Bitte tragen Sie Ihren Namen ein!" : "Please enter your name!";
    alert(strMsg);
    Form.name.focus();
    return false;
  }

  if (!checkMailAddress(Form.email.value)) {
    strMsg = (getLang() == "de") ? "Bitte tragen Sie Ihre E-Mail-Adresse ein!" : "Please enter your e-mail address!";
    alert(strMsg);
    Form.email.focus();
    return false;
  }

  if (!Form.vat[2].checked)
    Form.vatid.value = "";
  else if (!checkEmpty(Form.vatid.value)) {
    strMsg = (getLang() == "de") ?
    "Bitte tragen Sie Ihre Umsatzsteuer-ID ein oder wählen Sie eine andere USt-Kategorie!" :
    "Please enter your VAT ID or select another VAT category!";
    alert(strMsg);
    Form.vatid.focus();
    return false;
  }

  return true;
}


function checkLicenseType(Form) {
  var bShow = Form.type[3].checked || Form.type[4].checked || Form.type[5].checked;

  document.getElementById("opt_upgradekey_1").style.display = bShow ? "block" : "none";
  document.getElementById("opt_upgradekey_2").style.display = bShow ? "block" : "none";
}


function checkVat(Form) {
  var bShow = Form.vat[2].checked;

  document.getElementById("opt_vatid_1").style.display = bShow ? "block" : "none";
  document.getElementById("opt_vatid_2").style.display = bShow ? "block" : "none";
}


function checkEmpty(strText)
{
  var filter = /[\S]+/;
  return filter.test(strText) ? true : false;
}


function checkLicenseKey(strKey)
{
  var filter = /^([a-fA-F0-9]){8}(-([a-fA-F0-9]){8}){3}/;
  return filter.test(strKey) ? true : false;
}


function checkMailAddress(strAddress)
{
  var filter = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/;
  return filter.test(strAddress) ? true : false;
}


function checkWebsiteAddress(strAddress)
{
  var filter = /^(http:\/\/|https:\/\/|)([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/;
  return filter.test(strAddress) ? true : false;
}


function clearDefault(element) {
  if (element.value == element.defaultValue) element.value = "";
}


function isMSIE() {
  return (navigator.userAgent.indexOf("MSIE") >= 0);
}


function isNetscape() {
  return (navigator.userAgent.indexOf("Netscape") >= 0);
}


function isFirefox() {
  return (navigator.userAgent.indexOf("Firefox") >= 0);
}


function isOpera() {  // klappt bei Opera 8.5 und allen Fälschungsvarianten
  return (navigator.userAgent.indexOf("Opera") >= 0);
}


function isOldBrowser() {
  if (isMSIE() || isOpera()) // Opera's Default: simuliert MSIE
    return (navigator.appVersion.substring(0,1) < "4");
  else if (isNetscape())
    return (navigator.appVersion.substring(0,1) < "5");
  else                       // Firefox oder unbekannt
    return false;
}


function navigatorSupportsAppletScaling() {
  return (isMSIE() || isFirefox());
}


function getLang() {
  return top.lang;
}


function systemLang() {
  var str = isMSIE() ? navigator.userLanguage : navigator.language;
  str = str.substr(0, 2);
  if (str != "de") str = "en";
  return str;
}


function getParam(strParams, strName) {
  var strVal = null;
  var posName, posEnd;

  if (((posName = strParams.indexOf("?" + strName + "=")) >= 0) ||
  ((posName = strParams.indexOf("&" + strName + "=")) >= 0)) {
    strVal = strParams.substr(posName + strName.length + 2);

    if ((posEnd = strVal.indexOf("&")) >= 0)
      strVal = strVal.substr(0, posEnd);
  }

  return strVal;
}


function writeParam(strParams, strName) {
  var strVal = getParam(strParams, strName);

  if (strVal != null)
    document.writeln('<param name=' + strName + ' value="' + strVal + '">');
}


function centerWindow(cx, cy) {
  if (cx > screen.width) cx = screen.width;
  if (cy > screen.height) cy = screen.height;
  resizeTo(cx, cy);
  moveTo((screen.width - cx) / 2, (screen.height - cy) / 2);
}


function bookmarkPage() {
  title = document.title;
  url = window.location.href;

  if (typeof(window.external) == "object")   // MSIE
    window.external.AddFavorite(url, title);
  else if (typeof(window.sidebar) == "object")  // Netscape
    window.sidebar.addPanel(title, url, "")
}


function bookmarkThisPage() {
  if (typeof(window.external) == "object");
  else if (typeof(window.sidebar) == "object");
  else
    return;

  if (getLang() == "de")
    strMsg = "Lesezeichen für diese Seite setzen...";
  else
    strMsg = "Bookmark this page...";

  document.write('<a href="javascript:bookmarkPage()">' + strMsg + '<\/a>');
}


function mailAFriend(strTopic){
  var strMsg;
  var strSubject;
  var strThisPage = location.href;
  var strPanoradoLink = 'http://www.panorado.com';
  var strBody1, strBody2, strBody3;

  if (strTopic == "Gallery") {
    if (getLang() == "de") {
      strMsg = 'Diese Seite weiterempfehlen...'
      strSubject = 'Panoramabilder';
      strBody1 = 'Hallo,\r\n\r\nich habe eine tolle Bildergalerie mit Panoramabildern gefunden. Hier ist die Adresse:\r\n';
      strBody2 = ' .\r\n\r\nDie Galerie ist auf der Panorado-Website. ' +
                 'Panorado bietet neuartige Bildbetrachter-Software für Windows und fürs Internet an. ' +
                 'Die Website findest du unter ';
      strBody3 = ' .\r\n\r\nViel Spaß dabei!';
    }
    else {
      strMsg = 'Email someone a link to this page...'
      strSubject = 'See great panoramic images';
      strBody1 = 'Hi,\r\n\r\nI wanted to share a gallery with some great panoramic images with you.  Check it out at\r\n';
      strBody2 = ' !\r\n\r\nThe gallery is on the Panorado website. ' +
                 'Panorado offers innovative software products for viewing images locally and on the web. ' +
                 'You can see the whole site at ';
      strBody3 = ' .\r\n\r\nEnjoy it!';
    }
  }
  else if (strTopic == "PanoradoFlyer") {
    if (getLang() == "de") {
      strMsg = 'Diese Seite weiterempfehlen...'
      strSubject = 'Tolles Foto-Tool gefunden!';
      strBody1 = 'Hallo,\r\n\r\nich habe ein kostenloses Tool gefunden, ' +
                 'mit dessen Hilfe man Bilddateien über GPS-Koordinaten mit ihrem Aufnahmeort verknüpfen kann! ' +
                 'Hier ist die Adresse:\r\n';
      strBody2 = ' .\r\n\r\nDas Tool ist auf der Panorado-Website. ' +
                 'Panorado bietet neuartige Bildbetrachter-Software für Windows und fürs Internet an. ' +
                 'Die Website findest du unter ';
      strBody3 = ' .\r\n\r\nViel Spaß dabei!';
    }
    else {
      strMsg = 'Email someone a link to this page...'
      strSubject = 'Found a cool photo tool!';
      strBody1 = 'Hi,\r\n\r\nI want to tell you about a free tool which enables you to link images files to locations, using GPS coordinates! ' +
                 ' Check it out at\r\n';
      strBody2 = ' !\r\n\r\nThe tool is on the Panorado website. ' +
                 'Panorado offers innovative software products for viewing images locally and on the web. ' +
                 'You can see the whole site at ';
      strBody3 = ' .\r\n\r\nEnjoy it!';
    }
  }

  document.write('<a href="' + 'mailto:?subject=' + escape(strSubject) + '&body=' + escape(strBody1) + strThisPage + escape(strBody2) + strPanoradoLink + escape(strBody3) + '">' + strMsg + '<\/a>');
}
