﻿//#region Methods To Get Product ETA Information For BO Products
  function GetETAInformation(sProductCode, imgID, NetDocID, CultureID) {
    if ($j("img[id=" + imgID + "]").attr("title").length == 0) {
      //Do AJAX Call
      var tooltip = "No ETA currently available for this product.";

      $.ajax({
        type: "POST",
        url: "/Services/WebsiteCalls.asmx/GetProductETAInformation",
        contentType: "application/json; charset=utf8",
        data: "{'sProductCode':'" + sProductCode + "','gNetDocumentID':'" + NetDocID + "', 'sCultureID':'" + CultureID + "'}",
        dataType: "json",
        success: function (msg) {
          tooltip = msg.d;
          $("img[id=" + imgID + "]").attr("title", tooltip).attr("alt", tooltip);
        },
        error: function (xhr, err) {
          if (xhr.readyState != 4 && xhr.status == 200) {
            var file = xhr.responseText;
            alert("readyState: " + xhr.readyState + "  status: " + xhr.status + "\n\nresponseText: " + xhr.responseText);
          }

          var iStartIndex = xhr.responseText.indexOf("<string");
          var iEndIndex = xhr.responseText.indexOf("</string");
          var rtValue = xhr.responseText.substring(iStartIndex + 36, iEndIndex);
          $("img[id=" + imgID + "]").attr("title", rtValue).attr("alt", rtValue);
        }
      });
    }
  }

  //#endregion 

  //#region Search Methods for Nextopia

function endsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; }

  function CallSearchPage() {
    var sSearchText = $("input[id*=txtSearch]").val();
    location.href = "http://www.robotshop.com/search/search.aspx?locale=" + GetLocale() + "&keywords=" + sSearchText;
  }

  function CheckIfEnterAndRunSearch(e) {
    var evt = e ? e : window.event;
    if (evt.keyCode == 13) {
      if (e.preventDefault) {
        e.preventDefault();
      }
      else {
        e.returnValue = false;
      }
      CallSearchPage();
    }
  }

  function GetCulture() {
    var sCulture = $("a[id*=lnkSwitchLanguage]").html();
    if (sCulture.toUpperCase().substr(0, 2) == "FR") {
      return "en-US";
    }
    return "fr-CA";
  }

  function GetWebsite() {
    var sUrl = document.location.href;
    if (sUrl.indexOf('.com/ca/') > -1 || endsWith(sUrl, '.com/ca') || sUrl.indexOf('locale=en_ca') > -1 || sUrl.indexOf('locale=fr_ca') > -1) {
      return "robotshopca";
    }
    else if (sUrl.indexOf('.com/world/') > -1 || endsWith(sUrl, '.com/world') || sUrl.indexOf('locale=en_world') > -1 || sUrl.indexOf('locale=fr_world') > -1) {
      return "robotshopworld";
    }
    else if (sUrl.indexOf('.com/eu/') > -1 || endsWith(sUrl, '.com/eu') || sUrl.indexOf('locale=en_eu') > -1 || sUrl.indexOf('locale=fr_eu') > -1) {
      return "robotshopeu";
    }
    else {
      return "robotshopstore";
    }
  }

  function GetLocale() {
    var sCulture = GetCulture();
    var sWebsiteCode = GetWebsite();

    if (sCulture == "en-US") {
      if (sWebsiteCode == "robotshopca") {
        return "en_ca";
      }
      else if (sWebsiteCode == "robotshopstore") {
        return "en_us";
      }
      else if (sWebsiteCode == "robotshopeu") {
        return "en_eu";
      }
      else if (sWebsiteCode == "robotshopworld") {
        return "en_world";
      }
    }
    else {
      if (sWebsiteCode == "robotshopca") {
        return "fr_ca";
      }
      else if (sWebsiteCode == "robotshopstore") {
        return "fr_us";
      }
      else if (sWebsiteCode == "robotshopeu") {
        return "fr_eu";
      }
      else if (sWebsiteCode == "robotshopworld") {
        return "fr_world";
      }
    }
  }

  function GetCID() {
    var sCulture = GetCulture();
    var sWebsiteCode = GetWebsite();

    if (sCulture == "en-US") {
      if (sWebsiteCode == "robotshopca") {
        return "b9b76f374874269c1df4aaf9ab802903";
      }
      else if (sWebsiteCode == "robotshopstore") {
        return "fbf9011607c92ced539e14f67cc9c8c1";
      }
      else if (sWebsiteCode == "robotshopeu") {
        return "ee0511fcab7d27975626dc74352d2540";
      }
      else if (sWebsiteCode == "robotshopworld") {
        return "6036782015601c566736e5355554d299";
      }
    }
    else {
      if (sWebsiteCode == "robotshopca") {
        return "782231b73ff52ed0431f402ac51f760a";
      }
      else if (sWebsiteCode == "robotshopstore") {
        return "1fad571c989bf0b644438c92a4e2a5f4";
      }
      else if (sWebsiteCode == "robotshopeu") {
        return "c4ac463a06c8fbe781e77e74bebe3c75";
      }
      else if (sWebsiteCode == "robotshopworld") {
        return "6df599f128c315277d60f7086c4bec90";
      }
    }
  }
  //#endregion 
