﻿function LelandProduct(prodId, itemNumber, fullName, webPartNum, imageFileName, qtyAvail, regularPrice, compareAtPrice, bestPrice, displayMode, onlineInvMode, availabilityPhrase, canAddToCart, isSoldOut, notifyWhenInStockMode, dealOfTheDayPrice, dealOfTheDayQtyAvail) {
   this.ProductId = prodId;
   this.LelandItemNumber = itemNumber;
   this.FullName = fullName;
   this.WebPartNumber = webPartNum;
   this.ImageFileName = imageFileName;
   this.QuantityAvailable = qtyAvail;
   this.RegularPrice = regularPrice;
   this.CompareAtPrice = compareAtPrice;
   this.BestPrice = bestPrice;
   this.DisplayMode = displayMode;
   this.OnlineInventoryMode = onlineInvMode;
   this.AvailabilityPhrase = availabilityPhrase;
   this.AddToCartVisible = canAddToCart;
   this.IsSoldOut = isSoldOut;
   this.NotifyWhenInStockMode = notifyWhenInStockMode;
   this.DealOfTheDayPrice = dealOfTheDayPrice;
   this.DealOfTheDayQtyAvail = dealOfTheDayQtyAvail;

   this.SizeCode = "invalid web part number";
   this.ColorCode = "invalid web part number";

   if (this.WebPartNumber.length == 26) {
      this.SizeCode = this.WebPartNumber.substring(17, 21);
      this.ColorCode = this.WebPartNumber.substring(22, 26);
   }
}

var CurrentProduct;
var CurrentProducts = new Object();

function AvailableSize(strSizeCode, strSizeName, arrAvailColorCodes, strIconImageUrl) {
   this.SizeCode = strSizeCode;
   this.SizeName = strSizeName;
   this.AvailColorCodes = arrAvailColorCodes;
   this.IconImgSrc = strIconImageUrl;
}
function AvailableColor(strColorCode, strColorName, arrAvailSizeCodes, strIconImageUrl) {
   this.ColorCode = strColorCode;
   this.ColorName = strColorName;
   this.AvailSizeCodes = arrAvailSizeCodes;
   this.IconImgSrc = strIconImageUrl;
}

var AvailableSizes = new Object();
var AvailableColors = new Object();

function SendNotifyWhenInStock() {
   var strEmailAddress = $('#txtNWIS_EmailAddress').val();
   NotifyWhenInStock_Call(strEmailAddress, CurrentProduct.Id);
}
function NotifyWhenInStock_Call(strEmailAddress, intPid) {

   var strData = JSON.stringify({ 'strEmailAddress': strEmailAddress, 'intPid': intPid });

   $.ajax({
      type: "POST",
      contentType: "application/json; charset=utf-8",
      url: "/p/ws/SharedMethods.asmx/NotifyWhenInStock",
      data: strData,
      dataType: "json",
      error: function(data1, data2, data3) { window.alert("err" + data1); },
      success: function(data) {
         NotifyWhenInStock_Callback(data);
      }
   });
}

function NotifyWhenInStock_Callback(data) {
   var strFilData = FilterJSONData(data);

   if (strFilData == "A") { //Added
      $('#scNotifyWhenInStock_Confirmed').show();
      $('#scNotifyWhenInStock_SignUp').hide();
      $('#scNotifyWhenInStock_InvalidEmail').hide();
   } else if (strFilData == "E") { //Exists
      $('#scNotifyWhenInStock_Confirmed').show();
      $('#scNotifyWhenInStock_SignUp').hide();
      $('#scNotifyWhenInStock_InvalidEmail').hide();
   } else if (strFilData == "I") { //Invalid email
      $('#scNotifyWhenInStock_Confirmed').hide();
      $('#scNotifyWhenInStock_SignUp').show();
      $('#scNotifyWhenInStock_InvalidEmail').show();
   } else {

   }
}


function FormatCurrency(strValue) {
   var strReturnValue = "";
   strValue = strValue + "";
   for (var i = strValue.length - 1; i >= 0; i--) {
      if (strValue.length > 6 && strValue.length - i > 6 && ((strValue.length - i - 4) % 3 == 0))
         strReturnValue = "," + strReturnValue;
      strReturnValue = strValue.substr(i, 1) + strReturnValue;
   }
  
   if (strReturnValue.indexOf('.')<0)
      strReturnValue = strReturnValue + ".00";

   if (strReturnValue.substring(strReturnValue.length - 2, strReturnValue.length - 1) == ".")
      strReturnValue = strReturnValue + "0";

   strReturnValue = '$' + strReturnValue;

   return strReturnValue
}
function StripCommasFromNumbers(strValue) {
   var strReturnValue = "";
   strValue = strValue + "";
   for (var i = 0; i < strValue.length; i++) {
      if (strValue.substr(i, 1) != ",")
         strReturnValue = strReturnValue + strValue.substr(i, 1);
   }

   return strReturnValue
}
