﻿var serviceUrl = "/Ajax/Wishlist/WishlistUtility.svc/";
var proxy = new ServiceProxy(serviceUrl);
function rateWishlistItem(nRatingId, nWishItemId) {
proxy.invoke("rateWishlistItem",
{
psid: $("#hdnPs").val(),
ratingid: nRatingId,
wishlistitemid: nWishItemId
},
function(success, status, xhr) {
if (success) {
var drId = ".rateVote" + nWishItemId;
$(drId).html("<div class=\"confirmationRateIt\">Thanks for voting!</div>");
}
},
onPageError, false);
}
function sendWishListNew(_mode) {
var message = $('#message').val();
if (message.match('<(.|\n)*?>')) {
alert('Invalid message! The message must be plain text and can NOT contain any html characters.');
return;
}
proxy.invoke("sendWishlistNew",
{
name: $('#name').val(),
emails: $('#emails').val(),
message: $('#message').val(),
psid: $('#hdnPs').val(),
mode: _mode
},
function(res, status) {
if (res != null) {
if (res == "") {
$('.email-wrapper').html("<div>Thanks for sending this wishlist!</div>");
}
else {
$('.divWishlistError').html(res);
$('.divWishlistError').show();
}
}
},
onPageError, false);
}
function sendWishListInvite(_mode) {
proxy.invoke("sendWishlistInvite",
{
name: $('#name').val(),
emails: $('#emails').val(),
message: $('#message').val(),
psid: $('#hdnPs').val(),
mode: _mode
},
function(res, status) {
if (res != null) {
if (res == "") {
$('.email-wrapper').html("<div>Thanks for sending a wishlist invitation!</div>");
}
else {
$('.divWishlistError').html(res);
$('.divWishlistError').show();
}
}
},
onPageError, false);
}
function sendWishListPoster(_mode) {
proxy.invoke("sendWishListPoster",
{
name: $('#name').val(),
emails: $('#emails').val(),
message: $('#message').val(),
psid: $('#hdnPs').val(),
mode: _mode
},
function(res, status) {
if (res != null) {
if (res == "") {
$('.email-wrapper').html("<div>Thanks for sending a wishlist poster!</div>");
}
else {
$('.divWishlistError').html(res);
$('.divWishlistError').show();
}
}
},
onPageError, false);
}
function sendWishListPosterInvite(_mode, isTeaseEmail) {
var message = $('#message').val();
if (message.match('<(.|\n)*?>')) {
alert('Invalid message! The message must be plain text and can NOT contain any html characters.');
return;
}
proxy.invoke("sendWishListPosterInvite",
{
name: $('#name').val(),
emails: $('#emails').val(),
message: $('#message').val(),
accountid: $('#hdnAccountId').val(),
psid: $('#hdnPs').val(),
mode: _mode,
bIsTeaseEmail: isTeaseEmail
},
function(res, status) {
if (res != null) {
if (res == "") {
$('.email-wrapper').html("<div>Thanks for sending a poster invitation!</div>");
}
else {
$('.divWishlistError').html(res);
$('.divWishlistError').show();
}
}
},
onPageError, false);
}
function onPageError() {
}
$(function () {
this.DomEmailStoreButton = ".emailStoreButton";
this.DomSendEmailFormButton = "#sendEmailForm";
this.DomShowPriceInCart = ".showPriceInCart";
this.DomShowInCartClose = ".showInCartClose";
this.DomPreviewPrice = ".previewPrice";
this.DomBtnContinueCheckout = " .btnContinueCheckout";
$(this.DomBtnContinueCheckout).click(function () {
var preview = $(".previewPrice");
var qty = preview.find(".continueToCheckoutQty").val();
var itemno = preview.find("input#previewItemno").val();
var sQry = "?qty=" + qty + "&itemno=" + itemno + "&isaccess=0&isitemendpage=1";
var redirectHref = location.href;
// This is to force the redirection to go to http: and not https:. If it redirects to
// https:, this throws a page not found error and redirects to http: causing duplicate items
// to be inserted into the cart.
if ($.trim(location.port) != "") {
redirectHref = "http://" + location.hostname + ":" + location.port + "/MyAccount/Cart.aspx" + sQry;
}
else {
redirectHref = "http://" + location.hostname + "/MyAccount/Cart.aspx" + sQry;
}
location.href = redirectHref;
return false;
});
$(this.DomEmailStoreButton).click(function () {
var storeno = $(this).attr("storeno");
var storename = $(this).attr("storename");
var contacttype = $(this).attr("contacttype");
var itemno = $(this).attr("itemno");
$.WishListUtilities.showEmailManagerForm(storeno, storename, contacttype, itemno);
});
$(this.DomSendEmailFormButton).click(function () {
$.WishListUtilities.sendEmailManagerForm();
});
$(this.DomShowPriceInCart).click(function () {
$.WishListUtilities.showShowPriceInCart(this);
});
$(this.DomShowInCartClose).click(function () {
$.WishListUtilities.hideShowPriceInCart();
});
$(this.DomPreviewPrice).find("input.inputQty").change(function () {
$.WishListUtilities.updateShowPriceInCart(this);
});
(function (jQuery) {
this.DomHiddenEmailManagerForm = "#hdnEmailManagerForm";
this.DomPreviewPrice = ".previewPrice";
this.DomShowInCartClose = ".showInCartClose";
this.DomFade = ".fade";
this.updateShowPriceInCart = function updateShowPriceInCart(sender) {
var preview = $(".previewPrice");
var quantity = $(sender).val();
var price = preview.find(".cartNowPrice").text().replace("$", "").replace(",", "");
var shipping = preview.find(".shippingCost").text().replace("$", "").replace(",", "");
var subtotal = quantity * (parseFloat(price) + parseFloat(shipping));
subtotal = Math.round(subtotal * 100) / 100;
$(".cartSubTotal").html(formatMoney(subtotal));
}
this.showShowPriceInCart = function showShowPriceInCart(sender) {
var parentItem = $(sender).parents(".item-profile");
var preview = $(".previewPrice");
preview.find("input#previewItemno").val($(sender).parents(".item").find("input[id$='itemno']").val());
preview.find("input.inputQty").val(parentItem.find("input[id$='cartQty']").val());
preview.find(".cartLink").html(parentItem.find("input#item-title").val());
preview.find(".cartLink").attr("href", parentItem.find(".item-link").attr("href"));
preview.find(".cart11_b").html("(" + parentItem.find("input#item-id").val() + ")");
preview.find(".cartNowPrice").html(parentItem.find("input#item-price").val());
preview.find(".shippingCost").html(parentItem.find("input#item-shippingCost").val());
preview.find(".crossOut").html(parentItem.find("input#item-listprice").val());
$.WishListUtilities.updateShowPriceInCart(preview.find("input.inputQty"));
$.WishListUtilities.SetAvailabilityText(sender);
$.WishListUtilities.SetConditionText(sender);
$(DomShowInCartClose).attr('checked', false);
$(DomPreviewPrice).show();
$(DomFade).show();
}
this.hideShowPriceInCart = function hideShowPriceInCart() {
$(DomPreviewPrice).hide();
$(DomFade).hide();
}
this.SetConditionText = function SetConditionText(sender) {
var parentItem = $(sender).parents(".item-profile");
var preview = $(".previewPrice");
var condition = $.trim(parentItem.find("input#item-condition").val());
if (condition != "") {
preview.find(".optionCondition").html("Condition: " + condition);
}
}
this.SetAvailabilityText = function SetAvailabilityText(sender) {
var parentItem = $(sender).parents(".item-profile");
var preview = $(".previewPrice");
var availability = parentItem.find(".item-availability").text();
var isInSpoMode = $.trim(parentItem.find("input#item-isInSpoMode").val()) == "True";
var aoh = $.trim(parentItem.find("input#item-aoh").val());
switch (availability) {
case "In Stock":
if (!isInSpoMode) {
preview.find(".availability").html("<span class='instock'><img src=\"/includes/guitarcenter/Images/inventory_status-green.png\" height=\"25\" width=\"25\"/>In-Stock</span>");
}
else {
preview.find(".availability").html(availability);
}
break;
case "Limited Quantity In Stock":
if (isInSpoMode) {
preview.find(".availability").html(availability);
}
else if (aoh == "0") {
preview.find(".availability").html("<span class='instock'><img src=\"/includes/guitarcenter/Images/inventory_status-yellow.png\" height=\"25\" width=\"25\"/>Limited Quantity In Stock</span>");
}
break;
default:
preview.find(".availability").html(availability);
}
}
this.showEmailManagerForm = function showEmailManagerForm(storeno, storename, type, itemno) {
$(DomHiddenEmailManagerForm).show();
var validator = $("#managerContactForm").validate();
$('#contactformarea').show();
validator.resetForm();
$(".message").hide();
$("input#selectedstorenumber").val(storeno);
$("input#selectedstorename").val(storename);
$("input#contacttype").val(type);
$("input#contactitemno").val(itemno);
$.fn.colorbox({
width: "650px",
height: "530px",
inline: true,
href: this.DomHiddenEmailManagerForm,
onClosed: function () {
$($.WishListUtilities.DomHiddenEmailManagerForm).hide();
}
});
}
this.sendEmailManagerForm = function sendEmailManagerForm() {
var bIsValid = true;
var validator = $("#managerContactForm").validate({
rules: {
contactsenderphonenumber: {
required: true,
phoneUS: true
}
}
});
bIsValid = $("#managerContactForm").valid();
if (bIsValid) {
var params = {
contactsenderfirstname: $('#contactsenderfirstname').val(),
contactsenderlastname: $('#contactsenderlastname').val(),
contactsenderphonenumber: $('#contactsenderphonenumber').val(),
contactsenderemail: $('#contactsenderemail').val(),
contactsenderconfirmemail: $('#contactsenderconfirmemail').val(),
contactcontactby: $('input[name="contactcontactby"]:checked').val(),
contactbesttime: $('input[name="contactbesttime"]:checked').val(),
contactmessage: $('#contactmessage').val(),
contacttype: $('#contacttype').val(),
itemno: $('#contactitemno').val(),
storeno: $('#selectedstorenumber').val()
};
$.ajax({
type: "POST",
dataType: 'json',
url: "/ajax/itemend/ItemEndService.svc/sendManagerEmail",
data: params,
success: function (res) {
if (res != null) {
if (res.d == "") {
$('#contactformarea').hide();
$('.message').html("<div><h1>We have received your request, and an Associate from the " + $("input#selectedstorename").val() + " store will contact you shortly.</h1></div>");
$('.message').show();
}
else {
$('.errorMessage').html(res.d);
$('.error').show();
}
}
},
error: function (xhr, status, error) {
}
});
}
}
jQuery.WishListUtilities = this;
return jQuery;
})(jQuery);
});
function formatMoney(num) {
sign = (num == (num = Math.abs(num)));
return (((sign) ? '' : '-') + '$' + formatDecimal(num));
}
function formatDecimal(num) {
num = num.toString().replace(/\$|\,/g, '');
if (isNaN(num)) {
num = "0";
return parseFloat(num).toFixed(2);
}
num = Math.floor(num * 100 + 0.50000000001);
cents = num % 100;
num = Math.floor(num / 100).toString();
if (cents < 10) {
cents = "0" + cents;
}
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
}
return num + '.' + cents;
}
