var http = "http://www.hamrick.com/";
var https = "https://www.hamrick.com/";

var tra_lan = "";
var tra_off = 0;

var bro_lan = "";
var bro_off = 0; 

var reg_lan = "";
var reg_off = 0;

var ath_lan = "";

var i = 0;

var lan = [["en", "English", "Go Back", "Download", "VuePrint", "Purchase", "New Serial", "Support", "Education", "Screen Shot", "About"],
           ["es", "Español", "Volver", "Descargar", "VuePrint", "Compra", "De serie", "Apoyar", "Educación", "Pantalla", "Sobre"],
           ["de", "Deutsch", "Zurück", "Download", "VuePrint", "Kaufen", "Serial", "Unterstützen", "Bildung", "Bildschirm", "Über"],
           ["fr", "Français", "Retour", "Télécharger", "VuePrint", "Acheter", "Serial", "Soutenir", "Education", "Écran", "À propos de"],
           ["it", "Italiano", "Ritorno", "Download", "VuePrint", "Acquistare", "Serial", "Assistenza", "Istruzione", "Schermo", "Circa"],
           ["pt", "Português", "Retornar", "Baixar", "VuePrint", "Adquirir", "Serial", "Suporte", "Educação", "Tela", "Sobre"],
           ["ru", "Русский", "Download", "Скачать", "VuePrint", "Приобретение", "Серийные", "Поддержка", "Образование", "Экран", "О"],
           ["ja", "日本語", "戻る", "ダウンロード", "VuePrint", "購入する", "シリアル", "サポートする", "教育", "画面", "会社概要"],
           ["zh-cn", "中文", "返回", "下载", "VuePrint", "购买", "串行", "支持", "教育", "屏幕", "大约"],
           ["zh-tw", "中文", "返回", "下載", "VuePrint", "購買", "串行", "支持", "教育", "屏幕", "大約"],
           ["hi", "हिन्दी", "लौटें", "डाउनलोड", "VuePrint", "खरीदना", "धारावाहिक", "सहायता", "शिक्षा", "परदा", "के बारे में"],
           ["ar", "العربية", "العودة", "تنزيل", "VuePrint", "يشتري", "المسلسل", "دعم", "التعليم", "شاشة", "حول"],
           ["bg", "български", "Връщане", "Изтегляне", "VuePrint", "Купувам", "Сериен", "Поддържам", "Образование", "Екран", "За"],
           ["cs", "česky", "Zpět", "Stáhnout", "VuePrint", "Nákup", "Serial", "Podpora", "Vzdělávání", "Obrazovka", "O"],
           ["da", "Dansk", "Retur", "Download", "VuePrint", "Købe", "Serial", "Support", "Uddannelse", "Skærm", "Om"],
           ["el", "Ελληνικά", "Επιστροφή", "Download", "VuePrint", "Αγορά", "Αύξων", "Υποστήριξη", "Εκπαίδευση", "Οθόνη", "Σχετικά"],
           ["fi", "Suomi", "Paluu", "Lataa", "VuePrint", "Ostaa", "Serial", "Tuki", "Koulutus", "Näyttö", "Noin"],
           ["hr", "Hrvatski", "Povratak", "Preuzmite", "VuePrint", "Kupiti", "Serijski", "Podrška", "Obrazovanje", "Zaslon", "O"],
           ["ko", "한국어", "돌아가기", "다운로드", "VuePrint", "구매", "시리얼", "지원", "교육", "화면", "정보"],
           ["nl", "Nederlands", "Rendement", "Download", "VuePrint", "Kopen", "Volgnummer", "Ondersteunen", "Onderwijs", "Scherm", "Over"],
           ["no", "Norsk", "Return", "Last ned", "VuePrint", "Kjøp", "Serial", "Støtte", "Utdanning", "Skjerm", "Om"],
           ["pl", "Polski", "Wróć", "Pobierz", "VuePrint", "Zakupić", "Serial", "Wsparcie", "Edukacja", "Ekran", "O"],
           ["ro", "Română", "Revenire", "Descărcaţi", "VuePrint", "Achiziţiona", "Serial", "Susţine", "Educaţie", "Ecran", "Despre"],
           ["sv", "Svenska", "Avkastning", "Hämta", "VuePrint", "Köpa", "Serial", "Support", "Utbildning", "Skärm", "Om"],
           ["ca", "Català", "Tornar", "Descarregar", "VuePrint", "Compra", "De sèrie", "Recolzar", "Educació", "Pantalla", "Sobre"],
           ["tl", "Tagalog", "Bumalik", "Download", "VuePrint", "Bumili","Serial", "Suportahan", "Edukasyon", "Screen", "Tungkol sa"],
           ["iw", "עִברִית", "חזור", "הורדה", "VuePrint", "לרכוש", "סידורי", "תמיכה", "חינוך", "מסך", "על"],
           ["id", "Indonesia", "Kembali", "Download", "VuePrint", "Membeli", "Serial", "Mendukung", "Pendidikan", "Layar", "Tentang"],
           ["lv", "Latviešu", "Atgriezties", "Lejupielādēt", "VuePrint", "Pirkt", "Serial", "Atbalsts", "Izglītība", "Ekrāns", "Par"],
           ["lt", "Lietuvių", "Grįžti", "Parsisiųsti", "VuePrint", "Pirkinys", "Serijos", "Parama", "Švietimas", "Ekranas", "Apie"],
           ["sr", "српски", "Повратак", "Довнлоад", "VuePrint", "Купити", "Часопис", "Подршка", "Образовање", "Екран", "О"],
           ["sk", "Slovenčina", "Späť", "Stiahnuť", "VuePrint", "Nákup", "Serial", "Podpora", "Vzdelávanie", "Obrazovka", "O"],
           ["sl", "Slovenščina", "Nazaj", "Download", "VuePrint", "Kupiti", "Serijska", "Podpora", "Izobraževanje", "Zaslon", "O"],
           ["uk", "Українська", "Повернення", "Завантажити", "VuePrint", "Придбання", "Серійні", "Підтримка", "Освіта", "Екран", "Про"],
           ["vi", "Việt", "Trở lại", "Tải về", "VuePrint", "Mua", "Nối tiếp", "Hỗ trợ", "Giáo dục", "Màn hình", "Về"],
           ["sq", "Shqip", "Kthehuni", "Shkarko", "VuePrint", "Blej", "Serial", "Mbështetje", "Arsimi", "Ekrani", "Rreth"],
           ["et", "Eesti", "Tagasi", "Lae", "VuePrint", "Ostma", "Seerianumber", "Toetama", "Haridus", "Ekraan", "Kohta"],
           ["gl", "Galego", "Voltar", "Descargar", "VuePrint", "Adquisición", "Serial", "Soporte", "Educación", "Pantalla", "Sobre"],
           ["hu", "Magyar", "Vissza", "Letöltés", "VuePrint", "Vásárol", "Serial", "Támogatás", "Oktatás", "Képernyő", "Körülbelül"],
           ["mt", "Malti", "Ritorn", "Download", "VuePrint", "Xirja", "Serial", "Appoġġ", "Edukazzjoni", "Skrin", "Dwar"],
           ["th", "ไทย", "รีเทิร์น", "Download", "VuePrint", "ซื้อ", "อนุกรม", "สนับสนุน", "การศึกษา", "สกรีน", "เกี่ยวกับ"],
           ["tr", "Türkçe", "Dönüş", "Download", "VuePrint", "Satın almak", "Seri", "Desteklemek", "Eğitim", "Ekran", "Ile ilgili"]
          ];

bro_lan = navigator.language ? navigator.language.toLowerCase() : navigator.userLanguage.toLowerCase();

if (bro_lan == "he")
  bro_lan = "iw";

for (i=0; i<lan.length; i++)
{
  if (bro_lan.substr(0,lan[i][0].length) == lan[i][0])
  {
    bro_lan = lan[i][0];
    bro_off = i;
    break;
  }
}

if     (location.href.indexOf(".cgi"  ) != -1)
{
  var of = document.referrer.indexOf("&tl=");

  if (of == -1)
      of = document.referrer.indexOf("reg_");

  if (of != -1)
  {
    tra_lan = document.referrer.substr(of+4, 2);

    if (tra_lan == "zh")
      tra_lan = document.referrer.substr(of+4, 5).toLowerCase();

    if (tra_lan == "jp")
      tra_lan = "ja";
  }
  else if ((bro_lan.length >= 2) && (bro_lan.substr(0,2) != "en"))
  {
    tra_lan = bro_lan;
  }

  for (i=0; i<lan.length; i++)
  {
    if (tra_lan.substr(0,lan[i][0].length) == lan[i][0])
    {
      tra_off = i;
      break;
    }
  }
}
else if (location.href.indexOf("ackppl") != -1)
{
  tra_lan = bro_lan;
  tra_off = bro_off;
}

reg_lan = bro_lan;

if (reg_lan == "uk")
  reg_lan = "ru";

ath_lan = bro_lan.substr(0,2)
if (ath_lan == "iw")
  ath_lan = "he";

for (i=0; i<lan.length; i++)
{
  if (reg_lan.substr(0,lan[i][0].length) == lan[i][0])
  {
    reg_lan = lan[i][0];
    reg_off = i;
    break;
  }
}

function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en',
    gaTrack: true,
    layout: google.translate.TranslateElement.InlineLayout.SIMPLE
  }, 'google_translate_element');
}

function menu_bar(htm, ind)
{
  if (htm == "rep.html")
    document.write('<li><a target=_top href="' + https + htm + '">' + lan[tra_off][ind] + '</a></li>');
  else
    document.write('<li><a target=_top href="' + http  + htm + '">' + lan[tra_off][ind] + '</a></li>');
}

document.write('<div class="topbar">');
document.write(' <div class="topbar-inner">');
document.write('  <div class="container">');

if ((location.href.indexOf(".cgi"           ) != -1) ||
    (location.href.indexOf("sho.html"       ) != -1) ||
    (document.referrer.indexOf("reg.html"   ) != -1) ||
    (document.referrer.indexOf("regm.html"  ) != -1) ||
    (document.referrer.indexOf("regu.html"  ) != -1) ||
    (document.referrer.indexOf("reg_"       ) != -1)    )
{
  document.write('<ul>');
  document.write('<li><a href="javascript:history.go(-1)">' + lan[tra_off][2] + '</a></li>');
}
else if ((location.href.indexOf("mob.html"  ) != -1)    )
{
  document.write('<h3><a class="logo" href="http://www.hamrick.com"><span>Home</span></a></h3>');
  document.write('<ul>');
  document.write('<li><a href="#overview">' + 'Overview' + '</a></li>');
  document.write('<li><a href="#supported-scanners">' + 'Supported Scanners' + '</a></li>');
  document.write('<li><a href="#supported-languages">' + 'Supported Languages' + '</a></li>');
}
else
{
  document.write('<h3><a class="logo" href="http://www.hamrick.com"><span>Home</span></a></h3>');
  document.write('<ul>');

  document.write('<li><a href="http://www.hamrick.com#download">');
  if      (location.href.indexOf("upg.html") != -1)
    document.write('VueScan');
  else
    document.write(lan[tra_off][3]);
  document.write('</a></li>');
  
  if (location.href.indexOf("upg.html") == -1)
  {
    if ((reg_lan == "de") ||
        (reg_lan == "fr") ||
        (reg_lan == "it") ||
        (reg_lan == "jp") ||
        (reg_lan == "ru")    )
      document.write('<li><a target=_top href="https://www.hamrick.com/');
    else
      document.write('<li><a target=_top href="' + https);
    
    document.write('reg.html');
    document.write('">' + lan[tra_off][5] + '</a></li>');
    
    // menu_bar("rep.html", 6);
    menu_bar("sup.html", 7);
  }

  menu_bar("abo.html", 10);
}

if ((location.href.indexOf(".cgi"  ) == -1) &&
    (location.href.indexOf("ackppl") == -1)    )
{
  if (tra_off > 0)
  {
    var url = location.href;

    var off = location.href.indexOf("u=");

    if (off != -1)
    {
      var lst = url.slice(off, off+url.length).indexOf("&");

      if (lst != -1)
        url = url.slice(off+2, off+lst);
    }
    else
    {
      url = "http://www.hamrick.com/";
    }

    if ((url.indexOf("reg.html" ) != -1) ||
        (url.indexOf("reg_"     ) != -1) ||
        (url.indexOf("rep.html" ) != -1)    )
    {
      url = url.replace(/http:/, "https:");
    }

    document.write('<li><a target=_top href="' + url  + '">English</a></li>');
  }
  else if (location.href.indexOf("reg_") != -1)
  {
    document.write('<li><a target=_top href="https://www.hamrick.com/reg.html">' + lan[0][1] + '</a></li>');
  }
}

document.write('      </ul>');
document.write('    </div>');
document.write('  </div>');
document.write('</div>');
document.write('<div style="padding-top:40px;"></div>')

if ((location.href.indexOf(".html"     ) != -1) ||
    (location.href.indexOf(".cgi"      ) != -1)    )
{
  if ((location.href.indexOf("mob.html"  ) == -1) &&
      (location.href.indexOf("index.html") == -1) &&
      (location.href.indexOf("vsm.html"  ) == -1) &&
      (location.href.indexOf("reg.html"  ) == -1) &&
      (location.href.indexOf("regm.html" ) == -1) &&
      (location.href.indexOf("regu.html" ) == -1) &&
      (location.href.indexOf("reg_"      ) == -1) &&
      (location.href.indexOf("abo.html"  ) == -1) &&
      (location.href.indexOf("faq.html"  ) == -1) &&
      (location.href.indexOf("rep.html"  ) == -1) &&
      (location.href.indexOf("sil.html"  ) == -1) &&
      (location.href.indexOf("sup.html"  ) == -1)    )
  {
    document.write('<div class="container">');
    document.write(' <section>');
    document.write('  <div class="row">');
    document.write('    <div class="span12 columns">');
  }
}

function foot_tra(res)
{
  if (!res.error && (res.translation.length > 0))
  {
    var id = document.getElementById("repl");

    if (id)
      id.innerHTML = res.translation;
  }
}

function foot_ini()
{
  var id;

  id = document.getElementById("tran");
  if (id)
    google.language.translate(id.innerHTML, "en", tra_lan, foot_tra);
}

function foot_ppl()
{
  var lan = navigator.language ? navigator.language.toLowerCase() : navigator.userLanguage.toLowerCase();

  var cco = lan.substr(0,2);

  if (google.loader.ClientLocation)
    cco = google.loader.ClientLocation.address.country_code;
  else if (lan.length == 5)
    cco = lan.substr(3, 2);
  else if (cco == "en")
    cco = "us";
  else if (cco == "ja")
    cco = "jp";
  else if (cco == "pt")
    cco = "br";
  else if (cco == "zh")
    cco = "cn";
  else if (cco == "sv")
    cco = "se";
  else if (cco == "nb")
    cco = "no";
  else if (cco == "ar")
    cco = "sa";
  else if (cco == "cs")
    cco = "cz";
  else if (cco == "da")
    cco = "dk";
  else if (cco == "ko")
    cco = "kr";
  else if (cco == "el")
    cco = "gr";
  else if (cco == "uk")
    cco = "ua";
  else if (cco == "et")
    cco = "ee";
  else if (cco == "nn")
    cco = "no";

  cco = cco.toUpperCase();

  if ((cco != "US") &&
      (cco != "CA")    )
  {
    var loc = lan.substr(0,2);

    if ((cco == "CA") || (cco == "US"))
    {
      if      (loc == "fr")
        loc = "fr_XC";
      else if (loc == "es")
        loc = "es_XC";
      else if (loc == "zh")
        loc = "zh_XC";
      else
        loc = "en_US";
    }
    else if (cco == "AU")
    {
        loc = "en_AU";
    }
    else if (cco == "GB")
    {
        loc = "en_GB";
    }
    else if (loc == "de")
    {
        loc = "de_DE";
    }
    else if (loc == "nl")
    {
        loc = "nl_NL";
    }
    else if (loc == "fr")
    {
        loc = "fr_FR";
    }
    else if (loc == "zh")
    {
        loc = "zh_CN";
    }
    else if (loc == "es")
    {
        loc = "es_ES";
    }
    else if (loc == "it")
    {
        loc = "it_IT";
    }
    else if (loc == "ja")
    {
        loc = "ja_JP";
    }
    else if (loc == "pl")
    {
        loc = "pl_PL";
    }
    else
    {
        loc = "en_US";
    }

    var id;

    id = document.getElementById("paypal_lis");
    if (id) id.style.display = "block";

    id = document.getElementById("paypal_opt");
    if (id) id.style.display = "block";

    id = document.getElementById("paypal_cco");
    if (id) id.value = cco;

    id = document.getElementById("paypal_loc");
    if (id) id.value = loc;
  }
}

function foot_loa()
{
  google.load("language", "1", {"callback" : foot_ini});
}

var pageTracker;

var fn = "http://www.hamrick.com/files/vuex3290.exe";

function free_try()
{
  var UA = navigator.userAgent;

  var os = "Windows 7, Vista, XP, 2000";
  var sz = "6";

  var na = "VueScan";
  var ve = "9.0.79";
  var up = "January 29, 2012";

  if       (UA.indexOf("Win") != -1)
  {
    if ((UA.indexOf("WOW64") != -1) ||
        (UA.indexOf("x64"  ) != -1) ||
        (UA.indexOf("Win64") != -1)    )
    {
      fn = "http://www.hamrick.com/files/vuex6490.exe";
      os = "Windows 7 x64, Vista x64, XP x64";
    }
    else
    {
      fn = "http://www.hamrick.com/files/vuex3290.exe";
      os = "Windows 7, Vista, XP, 2000";
    }

    sz = "7";
  }
  else if ((UA.indexOf("Lin") != -1) ||
           (UA.indexOf("X11") != -1)    )
  {
    if (UA.indexOf("x86_64") != -1)
    {
      fn = "http://www.hamrick.com/files/vuex6490.tgz";
      os = "Built with 64-bit Ubuntu 10.10";
    }
    else
    {
      fn = "http://www.hamrick.com/files/vuex3290.tgz";
      os = "Built with 32-bit Ubuntu 10.10";
    }

    sz = "6";
  }
  else if ((UA.indexOf("iPad")   != -1) ||
           (UA.indexOf("iPod")   != -1) ||
           (UA.indexOf("iPhone") != -1)    )
  {
    fn = "http://itunes.apple.com/us/app/vuescan-mobile-free/id486283293?mt=8";
    os = "iOS 4.0 or later";

    sz = "4";

    var na = "VueScan Mobile";
    var ve = "1.1.5";
    var up = "January 17, 2012";
  }
  else
  {
    if ((UA.indexOf("OS X 10_7") != -1))
    {
      fn = "http://www.hamrick.com/files/vuex6490.dmg";
      os = "Mac OS X 10.4-10.7 (Lion)";
    }
    else
    {
      fn = "http://www.hamrick.com/files/vuex3290.dmg";
      os = "Mac OS X 10.4-10.7 (Lion)";
    }

    sz = "9";
  }

  document.write('  <div class="well">');

  document.write('    <center><a href="' + fn + '" onclick="pageTracker._trackPageview(\'' + fn + '\');" class="btn large danger">Try ' + na + ' Free</a></center>');
  document.write('    <br>');
  document.write('    <p>Click to download - you\'ll be scanning in 60 seconds!</p>');
  document.write('    <p><strong>Latest Version:</strong> ' + ve + '</p>');
  document.write('    <p><strong>Updated:</strong> ' + up + '</p>');
  document.write('    <p><strong>Size:</strong> ' + sz + ' MBytes</p>');
  document.write('    <p><small>' + os + '</small></p>');

  document.write('  </div>');
}

function foot_exe()
{
  if ((location.href.indexOf(".html"     ) != -1) ||
      (location.href.indexOf(".cgi"      ) != -1)    )
  {
    if ((location.href.indexOf("mob.html"  ) == -1) &&
        (location.href.indexOf("index.html") == -1) &&
        (location.href.indexOf("vsm.html"  ) == -1) &&
        (location.href.indexOf("reg.html"  ) == -1) &&
        (location.href.indexOf("regm.html" ) == -1) &&
        (location.href.indexOf("regu.html" ) == -1) &&
        (location.href.indexOf("reg_"      ) == -1) &&
        (location.href.indexOf("abo.html"  ) == -1) &&
        (location.href.indexOf("faq.html"  ) == -1) &&
        (location.href.indexOf("rep.html"  ) == -1) &&
        (location.href.indexOf("sil.html"  ) == -1) &&
        (location.href.indexOf("sup.html"  ) == -1)    )
      document.write('</div></div></section></div>');
  }

  document.write('<div id="footer">');
  document.write('  <div class="inner">');
  document.write('    <div class="container">');
  document.write('      <p class="right"><a href="#">Back to top</a></p>');
  document.write('      <p>© 2012 Hamrick Software<br /></p>');
  document.write('    </div>');
  document.write('  </div>');
  document.write('</div>');

  if      (((location.href.indexOf(".cgi"    ) != -1) ||
            (location.href.indexOf("ackppl"  ) != -1)    ) && (tra_off > 0))
  {
    var s = document.createElement("script");
    s.src = "https://www.google.com/jsapi?callback=foot_loa";
    s.type = "text/javascript";
    document.getElementsByTagName("head")[0].appendChild(s);
  }
  else if (location.href.indexOf("reg_de.html") != -1)
  {
    var s = document.createElement("script");
    s.src = "https://www.google.com/jsapi?callback=foot_ppl";
    s.type = "text/javascript";
    document.getElementsByTagName("head")[0].appendChild(s);
  }

  if (bro_off > 0)
  {
    var s = document.createElement("script");
    s.src = (("https:" == document.location.protocol) ? "https:" : "http:") + "//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit";
    s.type = "text/javascript";
    document.getElementsByTagName("head")[0].appendChild(s);
  }

  if ("http:" == document.location.protocol)
  {
    var s = document.createElement("script");
    s.src = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.") + "google-analytics.com/ga.js";
    s.type = "text/javascript";
    s.onloadDone = false;
  
    s.onload = function()
    {
      if (!s.onloadDone)
      {
           s.onloadDone = true;
  
           pageTracker = _gat._getTracker("UA-4497345-1");
           pageTracker._trackPageview();
        }
      };
  
    s.onreadystatechange = function()
    {
      if ((s.readyState === "loaded"  ) ||
          (s.readyState === "complete")    )
      {
        if (!s.onloadDone)
        {
             s.onloadDone = true;
  
             pageTracker = _gat._getTracker("UA-4497345-1");
             pageTracker._trackPageview();
        }
      }
    };
  
    document.getElementsByTagName("head")[0].appendChild(s);
  }
}

