//second event is used to pass in data from trigger on item page
$(function() {
var hideBar = false;
if(typeof(is_items_page) !== 'undefined' && is_items_page) {
var filter = parseURI('filter');
if (filter != "") {
var tmp = [];
filter.split(";").forEach(function (item) {
var name = item.substr(0, item.indexOf("~"));
var vals = item.substr(item.indexOf("~")+1);
vals.split(",").forEach(function (val) {
if (val != "") {
$('#' + name + "_" + val).prop('checked', true);
$('#F' + name + "_" + val).prop('checked', true);
$('#button_' + name + "_" + val).show();
}
});
});
filter_disable.split(",").forEach(function (item) {
if($("#" + item).prop('checked')) {
//do nothing
} else {
$("#" + item).attr("disabled", true).closest( "li" ).addClass("text-muted");
$("#F" + item).attr("disabled", true).closest( "li" ).addClass("text-muted");
}
});
}
$("#filter-buttons [id^=button_]").click(function(){
$("#" + this.id.replace("button_", "")).removeAttr('checked');
go_to_search_results("refine25");
});
$('.dropdown-menu').on('click', function(e){
if($(this).hasClass('filter-dropdown')){
e.stopPropagation();
}
});
var timer;
$("#filter-nav input[type=checkbox]").change( function() {
try{ clearTimeout(timer); } catch(ex){}
//submit_search_changes();
timer = setTimeout(function() {go_to_search_results("refine25");}, 10000);
});
$("#filter-nav [id^=apply_]").click( function() {
go_to_search_results("refine25");
});
$("#filter-nav2 [id^=apply_]").click( function() {
go_to_search_results("refine35");
});
$("#filter-apply").click( function() {
go_to_search_results("refine25");
});
$("#filter-nav [id^=reset_]").click(function(event){
event.preventDefault();
$("#filter-nav [id^=" + this.id.substring(6) + "]").each(function(){
$(this).prop('checked', false);
});
go_to_search_results("refine25");
});
$("#filter-nav2 [id^=reset_]").click(function(event){
event.preventDefault();
$("#filter-nav2 [id^=F" + this.id.substring(6) + "]").each(function(){
$(this).prop('checked', false);
});
go_to_search_results("refine35");
});
$("#filter-clear").click(function(event){
$("#refine25 input[type=checkbox]").each( function() {
$(this).prop('checked', false);
});
go_to_search_results("refine25");
});
$("#refine25 input[type=checkbox]").change( function() {
$("#filter-apply").show();
displayClear();
});
$("#show").change(function () {
$("#per-page-txt").text($("#show").find(":selected").text());
$("#frmMain").submit();
});
$("#show2").change(function () {
$("#per-page-txt2").text($("#show2").find(":selected").text());
$("#frmMain2").submit();
});
$("#sortby-text").text($("#sortby").find(":selected").text());
$("#sortby").change(function () {
$("#sortby-text").text($("#sortby").find(":selected").text());
$("#frmMain").submit();
});
$("#sortby-text2").text($("#sortby2").find(":selected").text());
$("#sortby2").change(function () {
$("#sortby-text2").text($("#sortby2").find(":selected").text());
$("#frmMain2").submit();
});
$('.dropdown-menu input, .dropdown-menu label').click(function(e) {
e.stopPropagation();
});
displayClear();
$(".avail_contact_us").click(function (e) {
console.log(this);
e.preventDefault();
var compId = this.parentNode.id;
var id = compId.substring(compId.indexOf('-')+1);
$.ajax({
url: '/servers/get_watch_info.php',
type: 'POST',
dataType: "json",
data: 'ajax=1&item_id=' + id,
success: function (msg) {
$('#availability').modal('hide');
$("#avail_item_id").val(msg.item_id);
$("#avail_brand").text(msg.brand);
$("#avail_series").text(msg.series);
$("#avail_model_no").text(msg.model_no);
$("#avail_img").attr('src', '/images/watches/'+msg.pic_big);
$('#availability').modal('show');
},
error: function (xhr, status, error) {
}
});
});
$("#availsubmit").click(function(){
if($('#availability_frm [name="g-recaptcha-response"]').val()=="") {
alert('Captcha was not clicked.');
return false;
}
if(!$('#availability_frm').valid())
return false;
$.ajax({
type: "POST",
url: "/popup/availability.php",
data: $('#availability_frm').serialize(),
success: function(msg){
$('#avail_content').html('
');
return false;
},
error: function(){
alert("There was a problem sending your email.\nPlease refresh the page and try again.");
return false;
}
});
return false;
});
}
$("[id^=compare-]").click( function(event, second_event) {
var second_btn = $(second_event);
if(document.getElementById('compare_count').innerHTML == "4") {
$("#addedtocompare-limit").modal();
return;
}
var compare_btn = $(this);
var item_id = compare_btn.attr('id').substring($(this).attr('id').indexOf("-")+1);
if(!isNumeric(item_id))
return;
var compare_qty = "";
$.ajax({
type: "POST",
url: "/servers/add_to_compare.php",
data: "item_id="+item_id,
success: function(msg){
if(isNumeric(msg))
document.getElementById('compare_count').innerHTML = msg;
compare_btn.html(' Comparing');
second_btn.html(' Comparing');
compare_qty = msg;
$("#comp-img").attr("src",$("#img-"+item_id).attr("src"));
$("#comp-text").html(''+$("#brand-"+item_id).text()+' '+$("#series-"+item_id).text()+
'
Model Number: '+$("#model_no-"+item_id).text()+
'
Price: '+$("#price-"+item_id).text()+'');
$("#addedtocompare").modal();
}
});
});
$("[id^=wishlist-]").click( function(event, second_event) {
var second_btn = $(second_event);
var wishlist_btn = $(this);
var item_id = wishlist_btn.attr('id').substring($(this).attr('id').indexOf("-")+1);
if(!isNumeric(item_id))
return;
var wishlist_qty = "";
$.ajax({
type: "POST",
url: "/servers/add_to_wishlist.php",
data: "item_id="+item_id,
success: function(msg){
if(isNumeric(msg))
document.getElementById('wishlist_count').innerHTML = msg;
wishlist_btn.html(' In Wishlist');
second_btn.html(' In Wishlist');
wishlist_qty = msg;
$("#wish-img").attr("src",$("#img-"+item_id).attr("src"));
$("#wish-text").html(''+$("#brand-"+item_id).text()+' '+$("#series-"+item_id).text()+
'
Model Number: '+$("#model_no-"+item_id).text()+
'
Price: '+$("#price-"+item_id).text()+'');
$("#addedtowishlist").modal();
}
});
});
$("[id^=cart-]").click( function(event) {
var cart_btn = $(this);
var item_id = cart_btn.attr('id').substring($(this).attr('id').indexOf("-")+1);
const modelNo = $("#model_no-"+item_id).text();
const brand = $(".brand-item a")[0].text;
const series = $(".series a")[0].text;
const price = $("#price-"+item_id).text();
if(!isNumeric(item_id))
return;
var cart_qty = "";
$.ajax({
type: "POST",
url: "/servers/add_to_cart.php",
data: "item_id="+item_id,
success: function(msg){
if($.isNumeric(msg))
$('[id^=cart-count]').text(msg);
cart_qty = msg;
$("#cart-img").attr("src",$("#img-"+item_id).attr("src"));
$("#cart-text").html(''+brand+' '+series+
'
Model Number: '+modelNo+
'
Price: '+price+'');
$("#addedtocart").modal();
sendToAnalytics(item_id, modelNo, brand, price, series);
}
});
});
function go_to_search_results(formId)
{
$.ajax({
type: "POST",
url: "/servers/search.php",
data: $("#" + formId).serialize(),
success: function (msg) {
var href = window.location.href.replace("#", "");
if(href.indexOf("&filter") > -1)
href = href.substr(0, href.indexOf("&filter"));
if(href.indexOf("&page") > -1)
href = href.replace("&page", "&1");
window.location = href + msg;
}
});
}
function parseURI(val) {
var result = "", tmp = [];
location.href.split("&").forEach(function (item) {
tmp = item.split("=");
if (tmp[0] === val) result = decodeURIComponent(tmp[1]);
});
return result;
}
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function displayClear()
{
$("#refine25 input[type=checkbox]").each( function() {
if($(this).prop('checked')) {
$("#filter-clear").show();
return false;
} else {
$("#filter-clear").hide();
}
});
}
$(window).scroll(function(){
if(!hideBar) {
if ($(this).scrollTop() > 200) {
$('#hidden-header').fadeIn(300);
} else {
$('#hidden-header').fadeOut(300);
}
}
});
$('#main_navbar3 .dropdown-menu , #main_navbar3 .dropdown > a').hover(function() {
$(this).parent().find('a:first-child').addClass('menu-pointer');
}, function() {
$(this).parent().find('a:first-child').removeClass('menu-pointer');
});
$("#hide-filters").click(function(){
$("#filter-nav").hide(0);
});
$("#show-filters").click(function(){
$("#filter-nav").show(0);
});
$('#filter-trigger').click(function () { // on button click
$("html, body").animate({ // catch the `html, body`
scrollTop: $("#filter-nav").offset().top // button's offset - 10
}, 500); // in 1000 ms (1 second)
});
$("#filter-trigger").on("click", function () {
if($(this).find("i").hasClass("ion-minus-round")) {
$(this).find("i").removeClass("ion-minus-round").addClass("ion-plus-round");
} else {
$(this).find("i").removeClass("ion-plus-round").addClass("ion-minus-round");
}
});
$("#dismiss-hh").click(function () {
$("#hidden-header").hide();
hideBar = true;
})
});
function sendToAnalytics(item_id, modelNo, brand, price, series) {
console.log(item_id, modelNo, brand, price, series);
gtag('event', 'add_to_cart', {
'items': [
{
'id': item_id,
'name': series,
'brand': brand,
'variant': modelNo,
'price': price
},
]
});
}