//v2.03, JP reformat
if (typeof jQuery != "undefined") {minisiteBuyPrice();} else { console.log("Please Include jQuery 1.x"); }
function minisiteBuyBox(d) { return '
Buy now
Please purchase all our products from these authorized dealers only to ensure that you receive full support in Warranty and replacement matters.
';}
function minisiteBuyPrice(){
loadCSS = function (href) { var cssLink = jQuery(""); jQuery("head").append(cssLink);};
loadCSS("https://www.garmin.co.in/m/_c/2017/webshopbox.css");
jQuery(document).ready(function() {
var _minisite_event_title = typeof document.title!="undefined" && document.title!="" ? document.title : "event" ;
_minisite_event_title = _minisite_event_title + " | ";
var _buy_country = "in";
var _buy_icon_url = "https://www.garmin.co.in/";
_buy_icon_url = _buy_icon_url.replace(/\/$/,"");
var G_locale = "en_IN";
var G_exclude = ""; //"0,1,2";
var G_prices = {};
var G_currencyFormat = "";
var G_exclude = "";
var G_products = [];
var G_type = "cat";
var G_tax = "";
var G_api = "https://www.garmin.com.my/_js/api_minisite-buy-data/in/";
var G_errors = "- Data cannot be loaded. Please try again later.. :P.";
var G_currency = "INR";
jQuery(".g_products").each(function() {
var _this_sn = jQuery(this).data("sn");
if (_this_sn == "000-00000-00"){jQuery(this).remove();} else {
G_products.push(_this_sn);
jQuery(this).hide();
}
});
jQuery.ajax({
type: "GET",
url: G_api ,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback:"callback",
dataType: "jsonp",
data: {
gpns: G_products.toString(),
country: _buy_country,
type: G_type
},
cache: true,
success: function(data) {
var _isOK = data.status;
if (_isOK) {
// Reset/Empty Price;
jQuery('#spec .classic-price').text( jQuery('#model .premium-rose-gold-gray .price').text() );
jQuery('#spec .sports-price').text( jQuery('#model .sport-seafoam-silver .price').text() );
//get All Prices
jQuery("#device [data-nav]>*").each(function() {
var thisSn = jQuery(this).find(".pd-color-con>*.active").attr("data-sn");
var _p = data.products.find(item => item.gpn === thisSn);
var _price = _p.price ? _p.price : '';
var G_pricePromotion = _p.pricePromotion ? _p.pricePromotion : '';
var G_discount = _price && G_pricePromotion ? ((1-(G_pricePromotion/_price )) * 100).toFixed(0):0;
var G_priceTaxWording = _p.priceTaxWording ? _p.priceTaxWording : '';
if (G_priceTaxWording) { P_price_tax = '('+G_priceTaxWording+')'; }
if (_p && _price) {
var P_price_tax = _p.priceTaxWording ? '('+_p.priceTaxWording+')' : '';
var dp = _p.currencyFormat + " " + parseFloat(_p.price).toLocaleString();
var dpt = _p.currencyFormat + " " + parseFloat(_p.priceTax).toLocaleString();
var ppf = dpt + ' ('+_p.priceTaxWording + ')' +'';
if (_p.pricePromotion) {
var dpp = _p.currencyFormat + " " + parseFloat(_p.pricePromotion).toLocaleString();
dpp += G_locale == "ja_JP" && G_discount > 0 ? '('+ G_discount +'% OFF) ' : '';
var dppt = _p.currencyFormat + " " + parseFloat(_p.pricePromotionTax).toLocaleString();
dppt += G_locale == "ja_JP" && G_discount > 0 ? '('+ G_discount +'% OFF) ' : '' ;
var pptf = dppt + ' ('+ _p.priceTaxWording + ')' +'';
if (G_locale == "ja_JP") {
jQuery(this).find('p.price').html( ''+pptf+'
'+ ''+ppf+'
' );
} else {
jQuery(this).find('p.price').html( dpp + P_price_tax );
}
} else {
if (G_locale == "ja_JP") {
jQuery(this).find('p.price').html( ppf );
} else {
jQuery(this).find('p.price').html( dp + P_price_tax );
}
}
} else {jQuery(this).find('p.price').text("");}
})
jQuery("#device .pd-color-con>*").click(function() {
var thisSn = jQuery(this).attr("data-sn");
var _p = data.products.find(item => item.gpn === thisSn);
var _price = _p.price ? _p.price : '';
var G_pricePromotion = _p.pricePromotion ? _p.pricePromotion : '';
var G_discount = _price && G_pricePromotion ? ((1-(G_pricePromotion/_price )) * 100).toFixed(0):0;
var G_priceTaxWording = _p.priceTaxWording ? _p.priceTaxWording : '';
if (G_priceTaxWording) { P_price_tax = '('+G_priceTaxWording+')'; }
if (_p && _price) {
var P_price_tax = _p.priceTaxWording ? '('+_p.priceTaxWording+')' : '';
var dp = _p.currencyFormat + " " + parseFloat(_p.price).toLocaleString();
var dpt = _p.currencyFormat + " " + parseFloat(_p.priceTax).toLocaleString();
var ppf = dpt + ' ('+_p.priceTaxWording + ')' +'';
if (_p.pricePromotion) {
var dpp = _p.currencyFormat + " " + parseFloat(_p.pricePromotion).toLocaleString();
dpp += G_locale == "ja_JP" && G_discount > 0 ? '('+ G_discount +'% OFF) ' : '';
var dppt = _p.currencyFormat + " " + parseFloat(_p.pricePromotionTax).toLocaleString();
dppt += G_locale == "ja_JP" && G_discount > 0 ? '('+ G_discount +'% OFF) ' : '' ;
var pptf = dppt + ' ('+ _p.priceTaxWording + ')' +'';
if (G_locale == "ja_JP") {
jQuery("#device [data-nav].active>div.active .price").html(''+pptf+'
'+ ''+ppf+'
');
} else {
jQuery("#device [data-nav].active>div.active .price").html( dpp + P_price_tax );
}
} else {
if (G_locale == "ja_JP") {
jQuery("#device [data-nav].active>div.active .price").html( ppf );
} else {
jQuery("#device [data-nav].active>div.active .price").html( dp + P_price_tax );
}
}
} else {jQuery(this).parents().eq(3).find("p.price").text("");}
})
jQuery.each(data.products, function(i, item) {
var _t = item.title;
var _g = item.gpn;
var _u = item.url;
var _p = item.price;
var _pt = item.priceTax;
var _pp = item.pricePromotion;
var _ppt = item.pricePromotionTax;
var _tw = item.priceTaxWording;
var _cry = item.currencyFormat;
// Distributors
if (typeof item.distributors!="undefined") {
if (item.distributors.length == 1) {
var _t = item.title;
var _g = item.gpn;
var _pt = item.distributors[0].title;
var _pl = item.distributors[0].link;
if (item.buy == true && item.url != "") {
var _this = jQuery(".g_products[data-sn='" + item.gpn + "']");
if (_this.length == 0) {
console.log("No set data-sn!!!")
} else {
jQuery(_this)
.show()
.css("display", "inline-block")
.attr({"href":_pl, "title": _pt, "target":"_blank"})
.on("click", function() {
ga("send","event","Minisite", " | " +_minisite_event_title + _t +" | "+ _g +" | "+ _pt + " | " + _pl);
});
}
}
}
else if (item.distributors.length > 1) {
var _t = item.title;
var _g = item.gpn;
var dealer = "";
for(var j = 0, len = item.distributors.length; j < len; j++){
var product = item.distributors[j];
var _st = product.title;
var _sl = product.link;
var _si = product.img;
var _sil = (!_si.search(/^http[s]?:\/\//)) ? _si : _buy_icon_url+_si;
dealer += '';
}
if (item.buy == true && item.url != "") {
var _this = jQuery(".g_products[data-sn='" + item.gpn + "']");
if (_this.length == 0) {
console.log("No set data-sn!!!")
} else {
jQuery("body").append(minisiteBuyBox(i));
jQuery(_this)
.show()
.css("display", "inline-block")
.attr("href", "#webshopbox" + i)
.fancybox({
"hideOnContentClick": true
});
}
}
jQuery("#webshopbox"+i+" #dealer").html(dealer);
}
}
});
} else {
console.log("- No Data :P");
}
},
error: function(xhr) {
console.log("- Data cannot be loaded. Please try again later.. :P");
},
timeout: 60000
});
// fancybox
if (typeof jQuery.fancybox == "function") {
// fancy box loaded;
} else {
console.log("Please Include fancy box plugin !");
}
});
}