﻿function useEnterKey(buttonName, e) {
var key;
if (window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13 && buttonName == 'enterKeyInvGroup') {
btnInvSearchClick(btnInvSearchClick);
}
}
function applyFilter() {
loadStores();
}
function clearZip() {
if ($(activePurchasingPanel + " #txtInvZip").val().toLowerCase().indexOf("zip") > -1) {
$(activePurchasingPanel + " #txtInvZip").val("");
}
}
function captureUnica() {
if (typeof ntptEventTag == 'function') {
var sCapture = "PageName=GC:Check Store Popup&rtv=&lc=http://www.guitarcenter.com/checkstore-popup-submitted&checkstorezip=" + $(activePurchasingPanel + ' #txtInvZip').val() + "&checkstorecity=" + $(activePurchasingPanel + ' #txtInvCity').val().toLowerCase() + "&checkstorestate=" + $(activePurchasingPanel + ' #selInvState>option:selected').text().toLowerCase() + "&checkstoremiles=" + $(activePurchasingPanel + ' #selMiles>option:selected').text().toLowerCase();
ntptEventTag(sCapture);
}
}
function btnInvSearchClick(isInitial) {
if (activePurchasingPanel != "#purchasing-store") {
return;
}
$(activePurchasingPanel + ' #divNote').hide();
$(activePurchasingPanel + ' #divInvFilters').hide();
$(activePurchasingPanel + ' #divInitialMsg').show();
$(activePurchasingPanel + ' #divInitialMsg').show();
clearResults();
if (isInitial || validateInvForm(isInitial)) {
captureUnica();
$(activePurchasingPanel + ' #divNote').show();
$(activePurchasingPanel + ' #divInvFilters').show();
$(activePurchasingPanel + ' #divInitialMsg').hide();
$(activePurchasingPanel + ' #divInvInnerResults').show();
loadStores(isInitial);
}
}
function clearResults() {
$(activePurchasingPanel + ' #divInitialMsg').show();
$(activePurchasingPanel + ' #divInvInnerResults').hide();
}
function validateInvForm(isInitial) {
if (isInitial == null) {
isInitial = true;
}
var bIsValid = false;
if ($(activePurchasingPanel + ' #txtInvZip').val() != "" && $(activePurchasingPanel + ' #txtInvZip').val() != "zip code") {
bIsValid = true;
}
if (!bIsValid) {
if ($(activePurchasingPanel + ' #txtInvCity').val() != "" && $(activePurchasingPanel + ' #txtInvCity').val() != "city" && $(activePurchasingPanel + ' #selInvState option:selected').val() != "") {
bIsValid = true;
}
}
//Home Zip will trunp geo city and state
if (isInitial) {
if ($(activePurchasingPanel + ' #txtInvZip').val() == "" || $(activePurchasingPanel + ' #txtInvZip').val() != "zip code") {
if ($('#homeStoreZip').val() != "") {
$(activePurchasingPanel + ' #txtInvZip').val($('#homeStoreZip').val());
bIsValid = true;
}
}
}
if (isInitial) {
if (!bIsValid) {
if ($(activePurchasingPanel + ' #txtInvCity').val() == "" && $(activePurchasingPanel + ' #txtInvCity').val() != "city" && $(activePurchasingPanel + ' #selInvState option:selected').val() == "") {
//if we have geo values for city and state use them. But if the homestorezip is set that trumps the geo city and state.
if ($('#ipCity').val() != "" && $('#ipState').val() != "") {
$(activePurchasingPanel + ' #txtInvCity').val($('#ipCity').val());
$(activePurchasingPanel + ' #selInvState').val($('#ipState').val());
bIsValid = true;
}
}
}
}
if (bIsValid) {
return true;
}
else {
//window.alert("You must enter either a City/State or Zip Code.");
alert("INVALID FORM");
return false;
}
}
function getExtSysId(nSelectedOptionItemno) {
var sRtn = "";
$(activePurchasingPanel + ' .selOptionInfo option').each(function (index) {
if ($(this).val() == nSelectedOptionItemno) {
sRtn = $(this).attr("sExtSysId");
}
});
sRtn = sRtn.replace("_C", "");
sRtn = sRtn.replace("_V", "");
sRtn = sRtn.replace("_U", "");
sRtn = sRtn.replace("_P", "");
return sRtn;
}
function GetStoreLocatorParams(sExtSysId, serialNum, sOptionStatus) {
var params;
var city = $("#ipCity").val();
var state = $("#ipState").val();
var zip = $("#homeStoreZip").val();
var sHomeStore;
sExtSysId = sExtSysId.replace("_C", "");
sExtSysId = sExtSysId.replace("_V", "");
sExtSysId = sExtSysId.replace("_U", "");
sExtSysId = sExtSysId.replace("_P", "");
var city;
var state;
var zip;
var distance;
city = $(activePurchasingPanel + ' #txtInvCity').val();
state = $(activePurchasingPanel + ' #selInvState option:selected').val();
zip = $(activePurchasingPanel + ' #txtInvZip').val();
distance = $(activePurchasingPanel + ' #selMiles option:selected').val();
sHomeStore = $('#hdnHomeStoreNo').val();
if (sHomeStore == "") {
sHomeStore = $('#selectedstoreno').val();
}
var params;
if (serialNum == null || serialNum == "") {
if (zip != "") {
params = { "nStartIndex": 0, "nPageSize": 10, "sCity": "", "sState": "", "sZip": zip, "sDistance": distance, "sStoreFilter": "1", "sHomeStore": "", "sExtSysId": sExtSysId, "sSerialNum": '', "sOptionStatus" : sOptionStatus};
}
else {
params = { "nStartIndex": 0, "nPageSize": 10, "sCity": city, "sState": state, "sZip": zip, "sDistance": distance, "sStoreFilter": "1", "sHomeStore": "", "sExtSysId": sExtSysId, "sSerialNum": '', "sOptionStatus": sOptionStatus };
}
}
else {
if (zip != "") {
params = { "nStartIndex": 0, "nPageSize": 1, "sCity": "", "sState": "", "sZip": zip, "sDistance": distance, "sStoreFilter": "1", "sHomeStore": "", "sExtSysId": sExtSysId, "sSerialNum": serialNum, "sOptionStatus": sOptionStatus };
}
else {
params = { "nStartIndex": 0, "nPageSize": 1, "sCity": city, "sState": state, "sZip": zip, "sDistance": distance, "sStoreFilter": "1", "sHomeStore": "", "sExtSysId": sExtSysId, "sSerialNum": serialNum, "sOptionStatus": sOptionStatus };
}
}
return params;
}
function GetCleanExternalSystemId(extsysid) {
var cleanid;
if (extsysid != undefined) {
cleanid = extsysid.replace("_C", "");
cleanid = cleanid.replace("_V", "");
cleanid = cleanid.replace("_U", "");
cleanid = cleanid.replace("_P", "");
}
return cleanid;
}
function loadStores(isInitial) {
if (isInitial == undefined) {
isInitial = true;
}
// clear previous results
$(activePurchasingPanel + ' .store-results').html("<ul id=stores-slider><li></li></ul>");
// show loading
$(activePurchasingPanel + ' .resultsLoading').show();
var selitemno;
var selserialnum;
var sExtSysId;
var storefilter;
storefilter = $(activePurchasingPanel + ' .selFilterStores option:selected').val();
storefilter = "0";
selitemno = $(activePurchasingPanel + ' .itemno option:selected').val();
sExtSysId = getExtSysId($(activePurchasingPanel + ' .itemno option:selected').val()); ;
var sOptionStatus = $(activePurchasingPanel + ' .itemno option:selected').attr('OptionStatus');
selserialnum = $("#selectedserialno").val();
$("#selecteditemno").val(selitemno);
$("#selectedserialno").val(selserialnum);
$("#selectedextsysid").val(sExtSysId);
sExtSysId = GetCleanExternalSystemId(sExtSysId);
// //If clean external system id != 9 that means the product is not an inventoried product so no need to check the service for inventory.
if (sExtSysId.length != 9) {
$(activePurchasingPanel + ' .store-results').html("<div style=height:100px>The product is not available in the selected stores.</div>");
$(activePurchasingPanel + ' #divNumberOfStoresInStock').hide();
$(activePurchasingPanel + ' .resultsLoading').hide();
return;
}
if (!validateInvForm(isInitial)) {
$(activePurchasingPanel + ' .resultsLoading').hide();
return;
}
if (selitemno == "") {
$(activePurchasingPanel + ' .resultsLoading').hide();
}
params = GetStoreLocatorParams(sExtSysId, selserialnum, sOptionStatus);
$.ajax({
type: "POST",
dataType: 'json',
contentType: "application/json",
url: "/ajax/itemend/Inventory.asmx/GetStores",
data: JSON2.stringify(params, '', ''),
success: function (response) {
loadStores_callback(response.d)
if ($('#selectedstoreno').val() != "" && $('#findinstoreventsource').val() == "map") {
showStoreExpanded($('#selectedstoreno').val());
}
},
error: function (xhr, status, error) {
$(activePurchasingPanel + ' .store-results').html("<div style=height:100px>The product is not available in the selected stores.</div>");
$(activePurchasingPanel + ' #divNumberOfStoresInStock').hide();
$(activePurchasingPanel + ' .resultsLoading').hide();
}
});
}
function loadStores_callback(res) {
// initialize
var nSlideOffset = 4;
var nChange = 3;
var storeSlide = "";
var startSlide = "<li class=slide><ul class=reviews>";
var endSlide = "</ul></li>";
var finalMarkupInsert = "";
var stores = res.Stores;
// no stores
if (stores.length == 0) {
$(activePurchasingPanel + ' .store-results').html("<div style=height:100px>The product is not available in the selected stores.</div>");
//$(activePurchasingPanel + ' #divFilterStores').hide();
$(activePurchasingPanel + ' #divNumberOfStoresInStock').hide();
}
// stores
else {
for (var i = 0; i < stores.length; i++) {
// grab and replace template
var storeRowTemplate = $(activePurchasingPanel + ' .storeRowTemplate').html();
storeRowTemplate = storeRowTemplate.replace("|address|", stores[i].StoreAddress);
storeRowTemplate = storeRowTemplate.replace("|name|", stores[i].StoreName);
storeRowTemplate = storeRowTemplate.replace("|storename|", stores[i].StoreName);
storeRowTemplate = storeRowTemplate.replace("|city|", stores[i].StoreCity);
storeRowTemplate = storeRowTemplate.replace("|state|", stores[i].StoreState);
storeRowTemplate = storeRowTemplate.replace("|zip|", stores[i].StoreZipCode);
storeRowTemplate = storeRowTemplate.replace("|phone|", stores[i].StorePhone);
storeRowTemplate = storeRowTemplate.replace("|phone2|", stores[i].StorePhone);
storeRowTemplate = storeRowTemplate.replace("|manager|", stores[i].Manager);
storeRowTemplate = storeRowTemplate.replace("|storedistance|", stores[i].StoreDistance);
storeRowTemplate = storeRowTemplate.replace("|info|", stores[i].StoreInfo);
storeRowTemplate = storeRowTemplate.replace("|monHours|", stores[i].monHours);
storeRowTemplate = storeRowTemplate.replace("|monHours|", stores[i].monHours);
storeRowTemplate = storeRowTemplate.replace("|tueHours|", stores[i].tueHours);
storeRowTemplate = storeRowTemplate.replace("|wedHours|", stores[i].wedHours);
storeRowTemplate = storeRowTemplate.replace("|thurHours|", stores[i].thurHours);
storeRowTemplate = storeRowTemplate.replace("|friHours|", stores[i].friHours);
storeRowTemplate = storeRowTemplate.replace("|satHours|", stores[i].satHours);
storeRowTemplate = storeRowTemplate.replace("|sunHours|", stores[i].sunHours);
storeRowTemplate = storeRowTemplate.replace("|storeno|", stores[i].StoreNo);
storeRowTemplate = storeRowTemplate.replace("|storeno2|", stores[i].StoreNo);
storeRowTemplate = storeRowTemplate.replace("|storeno3|", stores[i].StoreNo);
storeRowTemplate = storeRowTemplate.replace("|storeno4|", stores[i].StoreNo);
storeRowTemplate = storeRowTemplate.replace("|storeno5|", stores[i].StoreNo);
storeRowTemplate = storeRowTemplate.replace("|storeno6|", stores[i].StoreNo);
storeRowTemplate = storeRowTemplate.replace("|storeno7|", stores[i].StoreNo);
storeRowTemplate = storeRowTemplate.replace("|storeimage|", stores[i].storeimage);
var row = (i + 1) % 2;
storeRowTemplate = storeRowTemplate.replace("|row|", "row" + row);
// availability
var availability = "";
var availableInStore = false;
if (stores[i].StoreAvailability.toLowerCase() == "instock") {
availability = $(activePurchasingPanel + " .instock").html();
availableInStore = true;
}
else if (stores[i].StoreAvailability.toLowerCase() == "callstore") {
availability = $(activePurchasingPanel + " .callstore").html();
}
else if (stores[i].StoreAvailability.toLowerCase() == "oos") {
availability = $(activePurchasingPanel + " .oos").html();
}
else if (stores[i].StoreAvailability.toLowerCase() == "limited") {
availability = $(activePurchasingPanel + " .limited").html();
availableInStore = true;
}
storeRowTemplate = storeRowTemplate.replace("|availability|", availability);
storeRowTemplate = storeRowTemplate.replace("|inventorytext|", availability.replace("In-Stock", stores[i].quantity_on_hand + " Available"));
var EnquiryFormat = 'CustomerService/StoreItemEnquiry.aspx?storeno=|storeno|&itemno=|itemno|&type=|type|';
EnquiryFormat = EnquiryFormat.replace('|storeno|', stores[i].StoreNo);
EnquiryFormat = EnquiryFormat.replace('|itemno|', $(activePurchasingPanel + ' .invOptions option:selected').val()); //GetItemNo
if (availableInStore) {
storeRowTemplate = storeRowTemplate.replace("|buystore|", "<a href=\"javascript:;\" class=\"hrefShowBuyNow\" storeno=" + stores[i].StoreNo + " storename='" + stores[i].StoreName + "' contacttype='BuyNow'>Buy Now</a>");
}
else {
storeRowTemplate = storeRowTemplate.replace("|buystore|", '');
}
storeRowTemplate = storeRowTemplate.replace("|getInfo|", "<a href=\"javascript:;\" class=\"hrefShowStore\" storeno=" + stores[i].StoreNo + " storename='" + stores[i].StoreName + "' contacttype='MoreInfo'>More Info</a>");
// home store
var sHomeStoreHTML = "";
if (stores[i].StoreNo == $('#hdnHomeStoreNo').val()) {
sHomeStoreHTML = "<label style='font-weight:bold'>My Home Store</label>";
}
else {
sHomeStoreHTML = "<a href=\"javascript:;\" class=\"hrefMakeHomeStore\" storeno=" + stores[i].StoreNo + " city=\"" + stores[i].City + "\" zip=\"" + stores[i].StoreZipcode + "\">Make this my home store</a>";
}
storeRowTemplate = storeRowTemplate.replace("|homestore|", sHomeStoreHTML);
// store filter
if ($(activePurchasingPanel + ' .selFilterStores option:selected').val() == "0") {
$(activePurchasingPanel + ' .spnStoreFilter').html("All");
}
else {
$(activePurchasingPanel + ' .spnStoreFilter').html("In Stock Only");
}
// finish up
storeSlide += storeRowTemplate;
if (i == nChange || i == (stores.length - 1)) {
// wrap it
storeSlide = startSlide + storeSlide + endSlide;
finalMarkupInsert += storeSlide;
// reset
storeSlide = "";
nChange += nSlideOffset;
}
}
// final insert
$(activePurchasingPanel + ' #stores-slider').html(finalMarkupInsert);
// misc show/hide
//$(activePurchasingPanel + ' #divFilterStores').show();
$(activePurchasingPanel + ' .storesInStock').html(res.TotalNumberStoresInStock);
$(activePurchasingPanel + ' #divNumberOfStoresInStock').show();
// click event for expander
$(activePurchasingPanel + ' .hrefShowStore').click(function (e) {
$(activePurchasingPanel + ' #divNumberOfStoresInStock').hide();
showStoreExpanded($(this).attr("storeno"));
});
$(activePurchasingPanel + ' .hrefShowBuyNow').click(function (e) {
$(activePurchasingPanel + ' #divNumberOfStoresInStock').hide();
showEmailManagerForm($(this).attr("storeno"), $(this).attr("storename"), $(this).attr("contacttype"));
});
$(activePurchasingPanel + ' .hrefGetDirections').click(function (e) {
GetDirections($(this).attr("storeno"));
});
$(activePurchasingPanel + ' .hrefShowManagerContact').click(function (e) {
$(activePurchasingPanel + ' #divNumberOfStoresInStock').hide();
showEmailManagerForm($(this).attr("storeno"), $(this).attr("storename"), $(this).attr("contacttype"));
});
// click event for make home store
$(activePurchasingPanel + ' .hrefMakeHomeStore').click(function (e) {
makeHomeStore($(this).attr("storeno"), $(this).attr("city"), $(this).attr("zip"));
});
// click event for hide expanded store info
$(activePurchasingPanel + ' .hrefHideStore').click(function (e) {
showStoreExpanded($(this).attr("storeno"), true);
});
}
// hide loading
$(activePurchasingPanel + ' .resultsLoading').hide();
if (stores.length == 1) {
showStoreExpanded(stores[0].StoreNo);
}
}
function runSearch() {
btnInvSearchClick(true);
}
function executeSearch(isInitial) {
//clear out if arrived via a map click from purchasing module
$('#findinstoreventsource').val("");
btnInvSearchClick(isInitial);
}
function showStoreExpanded(storeno, bIsHide) {
var store = activePurchasingPanel + ' #store' + storeno;
if (bIsHide == undefined)
bIsHide = false;
if (!bIsHide) {
showStoreMap(storeno);
$(store).show(300);
}
else {
$(store).hide(300);
}
}
function GetDirections(storeno) {
var selectorStore = activePurchasingPanel + " #store" + storeno;
var selectorMap = activePurchasingPanel + " .map" + storeno;
var sAddress = $(selectorStore + " .street").html();
var sCity = $(selectorStore + " .city").html();
var sZip = $(selectorStore + " .zip").html();
$(activePurchasingPanel + ' .hrefGetDirections').each(function (index) {
if ($(this).attr('storeno') == storeno) {
link = $(this);
}
});
var location = "http://maps.google.com/maps?daddr=" + encodeURIComponent(sAddress + ' ' + sCity + ' ' + sZip);
$(link).attr('target', '_blank');
$(link).attr('href', location);
}
function showStoreMap(storeno) {
var selectorStore = activePurchasingPanel + " #store" + storeno;
var selectorMap = activePurchasingPanel + " .map" + storeno;
var sAddress = $(selectorStore + " .street").html();
var sCity = $(selectorStore + " .city").html();
var sState = $(selectorStore + " .state").html();
var sZip = $(selectorStore + " .zip").html();
var sLat = $(selectorStore + " .lat").html();
var sLong = $(selectorStore + " .long").html();
var sMapUrl = $(selectorStore + " .mapUrl").html();
var sFullAddress = sAddress + "," + sCity + "," + sState + "," + sZip;
sFullAddress = sFullAddress.replace(/ /g, "+");
var sLatLong = sLat + "," + sLong;
//Backwards compatible cause some stores still have Mapquest stored as the url.
if (sMapUrl != "" && sMapUrl != null && sMapUrl.toUpperCase().indexOf("MAPQUEST") < 0) {
var mapHtml;
sMapUrl = sMapUrl.replace(/ /g, "+");
if (sMapUrl != "") {
var mapHtml = "<div align=center style=\"width:360px\"><iframe width=360 height=280 frameborder=0 scrolling=no marginheight=0 marginwidth=0 src=" + sMapUrl + "&amp;z=16&amp;output=embed></iframe><a style=\"color: #AA0000; font-size:11px;font-weight:bold\" href=\"http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=" + sFullAddress + "&amp;sll=" + sLatLong + "&amp;sspn=0.097371,0.126858&amp;ie=UTF8&amp;hq=&amp;hnear=" + sFullAddress + "&amp;z=16\" target=\"_blank\">View Larger Map/Directions</a></div>";
}
else {
var mapHtml = "<div align=center style=\"width:360px\"><iframe width=360 height=280 frameborder=0 scrolling=no marginheight=0 marginwidth=0 src=http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=" + sFullAddress + "&amp;sll=" + sLatLong + "&amp;sspn=0.097371,0.126858&amp;ie=UTF8&amp;hq=&amp;hnear=" + sFullAddress + "&amp;z=16&amp;output=embed></iframe><a style=\"color: #AA0000; font-size:11px;font-weight:bold\" href=\"http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=" + sFullAddress + "&amp;sll=" + sLatLong + "&amp;sspn=0.097371,0.126858&amp;ie=UTF8&amp;hq=&amp;hnear=" + sFullAddress + "&amp;z=16\" target=\"_blank\">View Larger Map/Directions</a></div>";
}
}
else {
var mapHtml = "<div align=center style=\"width:360px\"><iframe width=360 height=280 frameborder=0 scrolling=no marginheight=0 marginwidth=0 src=http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=" + sFullAddress + "&amp;sll=" + sLatLong + "&amp;sspn=0.097371,0.126858&amp;ie=UTF8&amp;hq=&amp;hnear=" + sFullAddress + "&amp;z=16&amp;output=embed></iframe><a style=\"color: #AA0000; font-size:11px;font-weight:bold\" href=\"http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=" + sFullAddress + "&amp;sll=" + sLatLong + "&amp;sspn=0.097371,0.126858&amp;ie=UTF8&amp;hq=&amp;hnear=" + sFullAddress + "&amp;z=16\" target=\"_blank\">View Larger Map/Directions</a></div>";
}
$(selectorMap).html(mapHtml);
}
function makeHomeStore(sStoreNo, sStoreName, sStoreZip) {
if (typeof ntptEventTag == 'function') {
ntptEventTag('PageName=GC:Check Store Popup&rtv=&lc=http://www.guitarcenter.com/checkstore-popup&HomeStore=Yes');
}
var params = { "sStoreNo": sStoreNo, "sStoreName": sStoreName, "sStoreZip": sStoreZip };
$('#txtInvZip').val(sStoreZip);
$.ajax({
type: "POST",
dataType: 'json',
contentType: "application/json",
url: "/ajax/itemend/Inventory.asmx/makeHomeStore",
data: JSON2.stringify(params),
success: function (response) {
makeHomeStore_callback(response.d)
},
error: function (xhr, status, error) {
}
});
}
function makeHomeStore_callback(sStoreNo) {
$('#hdnHomeStoreNo').val(sStoreNo);
//clear any available in stores that may have been cached since the store could have changed.
$.jCache.clear();
if (activePurchasingPanel == "#purchasing-store") {
loadStores();
}
else {
$(activePurchasingPanel + ' .ClosestStore_HomeStore').hide();
}
}
jQuery.fn.extend({
outerHtml: function (replacement) {
// We just want to replace the entire node and contents with
// some new html value
if (replacement) {
return this.each(function () { $(this).replaceWith(replacement); });
}
var tmp_node = $("<div></div>").append($(this).clone());
var markup = tmp_node.html();
// Don't forget to clean up or we will leak memory.
tmp_node.remove();
return markup;
}
});
function handleEnterInventory(event, inputid) {
if (isEnterKey(event)) {
btnInvSearchClick(false);
return false;
}
else {
if (inputid == 'txtInvZip') {
$('#txtInvCity').val('');
$('#selInvState').val('');
}
else {
$('#txtInvZip').val('');
}
return true;
}
}
function isEnterKey(event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13)
return true;
else
return false;
}
