﻿if (typeof (UAS) === 'undefined' || UAS === null) {
UAS = {};
}
(function (rootNamespace, $, undefinedValue) {
this.IsNumberKey = function (evt) {
var char = (evt.which) ? evt.which : evt.keyCode
if (char == 8) return true;
if (char == 9) return true;
if (char == 13) return true;
if (char == 35) return true;
if (char == 36) return true;
if (char == 46) return true;
if (char >= 48 && char <= 57) return true;
if (char > 111 && char <= 123) return true;
if (char > 95 && char <= 105) return true;
return false;
};
this.IsValidZip = function (evt) {
if ($('.countryField').val() == 'us') {
return IsNumberKey(evt);
}
return true;
};
this.IsEnterKey = function (event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13)
return true;
else
return false;
}
this.SetCookie = function (name, value, expires, path, domain) {
// set time, it's in milliseconds
var today = new Date();
today.setTime(today.getTime());
/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if (expires) {
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date(today.getTime() + (expires));
document.cookie = name + '=' + escape(value) +
((expires) ? ';expires=' + expires_date.toGMTString() : '') +
((path) ? ';path=' + path : '') +
((domain) ? ';domain=' + domain : '');
};
this.LoadCartFlyoutHover = function () {
// Cart
cartHoverConfig = {
sensitivity: 3, 
interval: 150, 
timeout: 200, 
over: function() {
UAS.LoadCartFlyout(false, "hover");
}, 
out: function() { 
$(this).find(".sub").hide();
} 
}
$('.second-nav .cart').hoverIntent(cartHoverConfig);
};
this.LoadCartFlyout = function (content, title) {
$('.second-nav .cart').find(".sub").html("<span class='navcartload'>Loading</span>").show();
if (!content) {
$.ajax({
type: "GET",
url: "/Cart/CartFlyout",
success: function (response) { 
$(".second-nav .cart .sub").html(response);
},
error: function (xhr, status, error) {
}
});
}
else {
var contentTemplate = $(content);
$('.product-title', contentTemplate).html(title);
$('.confirmation', contentTemplate).show();
$('.second-nav .cart').find(".sub").html(contentTemplate).show();
$('.second-nav .cart').hoverIntent(null);
setTimeout("$('.second-nav .cart').find('.sub').hide(200);this.LoadCartFlyoutHover();",4000);
}
};
this.ResetCartFlyout = function () {
$(".second-nav .cart .sub").html('')
}
this.UpdateHeaderTotals = function() {
$.ajax({
type: "GET",
url: "/Cart/Totals",
async: false,
beforeSend: function (x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
dataType: "json",
success: function (data) {
$('#cart-itemqty').html(data.LineCount);
$('.cart > .cart-total').html(data.SubTotal);
$('.cart > .cart-yousave').html(data.SaveAmount);
},
error: function (jqXhr, textStatus, errorThrown) {
alert("Unfortunately an Error occured while processing your request. - " + errorThrown);
},
complete: function () {
}
});
}
this.LoadHoverMenus = function () {
topNavHoverConfig = {
sensitivity: 3, 
interval: 150, 
timeout: 200, 
over: function() {
$(this).find(".sub").show();
$(this).find(".sub-container").show();
}, 
out: function() { 
$(this).find(".sub").hide();
$(this).find(".sub-container").hide();
} 
}
$('#top-nav > li').hoverIntent(topNavHoverConfig);
$('.storelocator').hoverIntent(topNavHoverConfig);
this.LoadCartFlyoutHover();
emailHoverConfig = {
sensitivity: 3, 
interval: 150, 
timeout: 200, 
over: function() {
$(this).find(".sub").show();
}, 
out: function() { 
$(this).find(".sub").hide();
} 
}
// Sign up for Email
$('.email').hoverIntent(emailHoverConfig);
// Shop By Catalog
$('.catalog').hoverIntent(emailHoverConfig);
};
this.HideShowCompany = function (show, companyRowId, companyInputId) {
if (show)
$('#' + companyRowId).show();
else {
$('#' + companyRowId).hide();
$('#' + companyInputId).val('');
}
};
this.EmailSignup = function (inputSelector, divIdToUpdate, source) {
var emailInputSelector = $(inputSelector);
var emailAddress = emailInputSelector.val();
if (!UAS.ValidateEmail(emailAddress))
{
emailInputSelector.val('');
alert('Invalid Email Address!');
emailInputSelector.focus();
emailInputSelector.css("border", "solid 1px red");
return;
}
var divSelector = "#" + divIdToUpdate;
var updateDiv = $(divSelector);
this.BlockUi(divSelector, "");
$.ajax({
url: "/Home/EmailSignup?emailAddress=" + emailAddress + "&source=" + source,
type: "GET",
success: function (data) {
updateDiv.html(data);
},
error: function (jqXhr, textStatus, errorThrown) {
alert("Unfortunately an Error occured while processing your request.");
},
complete: function () { 
UAS.UnblockUi(divSelector);
}
});
}
this.ValidateEmail = function (elementValue){ 
var emailPattern = /.+@.+\..+/; 
return emailPattern.test(elementValue); 
} 
this.GetModalOptions = function (message) {
var baseMessage = '<div style="height: 30px; line-height: 30px;"><h2><img src="/content/ajax-loader.gif" style="vertical-align: middle; height: 25px; width: 25px;"/>&nbsp;&nbsp;' + message + '</h2></div>';
return { message: baseMessage, timeout: 60000, baseZ: 9999 };
}
this.BlockUi = function (divSelector, message) {
$(divSelector).block(this.GetModalOptions(message));
}
this.UnblockUi = function (divSelector) {
$(divSelector).unblock();
}
this.LoadScrollables = function() {
try {
if ($('.feat-1').length != 0) {
this.LoadCarousel(".feat-1");
}
if ($('.feat-2').length != 0) {
this.LoadCarousel(".feat-2");
}
if ($('.feat-3').length != 0) {
this.LoadCarousel(".feat-3");
}
}
catch (err) { }
};
this.CertonaCallback = function() {
this.LoadScrollables();
UAS.Quickview.LoadClickEventHover('.featured-products-container');
};
this.LoadCarousel = function(targetDiv) {
var scrollCount = 4;
if ($(targetDiv).width() > 730) {
scrollCount = 5; 
}
$(targetDiv + ' .product-container').wrap("<li />");
$(targetDiv + ' .scrollable .items').wrapInner('<ul />');
$(targetDiv + ' .scrollable .items').jCarouselLite({
btnNext: targetDiv + " .next",
btnPrev: targetDiv + " .prev",
scroll: scrollCount,
visible: scrollCount
});
};
rootNamespace.SetCookie = this.SetCookie;
rootNamespace.IsNumberKey = this.IsNumberKey;
rootNamespace.IsValidZip = this.IsValidZip;
rootNamespace.LoadHoverMenus = this.LoadHoverMenus;
rootNamespace.LoadCartFlyout = this.LoadCartFlyout;
rootNamespace.LoadCartFlyoutHover = this.LoadCartFlyoutHover;
rootNamespace.IsEnterKey = this.IsEnterKey;
rootNamespace.HideShowCompany = this.HideShowCompany;
rootNamespace.ResetCartFlyout = this.ResetCartFlyout;
rootNamespace.EmailSignup = this.EmailSignup;
rootNamespace.GetModalOptions = this.GetModalOptions;
rootNamespace.BlockUi = this.BlockUi
rootNamespace.UnblockUi = this.UnblockUi;
rootNamespace.ValidateEmail = this.ValidateEmail;
rootNamespace.UpdateHeaderTotals = this.UpdateHeaderTotals;
rootNamespace.LoadCarousel = this.LoadCarousel;
rootNamespace.LoadScrollables = this.LoadScrollables;
rootNamespace.CertonaCallback = this.CertonaCallback;
$(document).ready(function () {
UAS.LoadHoverMenus();
$('.storelocator #btn-go').click(function (e) { 
window.location = "/stores/?zip=" + $('.storelocator #store-search-zip').val();
});
$('.countryField').live(
{
change: function () {
var countryCode = $(this).val().toLowerCase();
var parent = $(this).closest('.addressForm');
if (parent.length == 0) {
return;
}
var statesList = $('.stateField', parent);
//clear out the list and reinitialize the base option
var baseOption = $('.stateField option:first', parent)
statesList.empty();
statesList.append(baseOption);
statesList.val('');
if (countryCode == '')
return;
if (countryCode != 'us')
$('.zipcodeField').removeClass('zipcodeField').addClass('zipcodeField_inactive');
else
$('.zipcodeField_inactive').removeClass('zipcodeField_inactive').addClass('zipcodeField');
var parsedStates = false;
for (var i = 0; i < statesJson.length; i++) {
if (statesJson[i].CountryCode.toLowerCase() == countryCode) {
parsedStates = true;
$.each(statesJson[i].States, function () {
statesList.append($('<option/>').val(this.Code).html(this.Code));
});
}
}
if (parsedStates) {
$('.stateRow', parent).show();
}
else {
$('.stateRow', parent).hide();
}
}
});
$(".brandlogos-container .brandlogos-carousel").jCarouselLite({
btnNext: ".brandlogos-container .next",
btnPrev: ".brandlogos-container .prev",
scroll: 1,
visible: 5, 
auto: 10,
speed: 6000
});
});
})(UAS, jQuery);
