Subversion Repositories SmartDukaan

Rev

Rev 19711 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(function(){
        
        jQuery('.mk_videoclick').click(function(){
                var clicked = jQuery(this);
            var scrollTo = jQuery("#recommendedvids");
            if(currentVideoId!=currentVideoIds[clicked.attr("slidecounter")]){
                scrollTo.find('li[ytid=' + currentVideoIds[clicked.attr("slidecounter")] + ']').click();
            }
                //trackEventWithGA('Product', 'VideoTabClicked',  $('title').text().split('|')[0].trim()  + "|" + clicked.attr("slidename"));
                jQuery('html, body').animate({ scrollTop: scrollTo.offset().top }, 'medium');
        return false;
        });
        
        
        $('#loopedSlider').loopedSlider();
        
        runEffect();
        
        $(".controls").tabs();
        
        $('#forgot_username_link').tipsy({gravity: 'w'});

        $("#zipcode").val($("#defaultpincode").val());
        
        if(typeof Entity != 'undefined'){
                var select = $("#colorSelector");
                if(Entity.orderedItems){
                        $.each(Entity.orderedItems, function(index, sort) {
                                select.find('option[value="' + sort + '"]').appendTo(select);
                        });
                        $("#item_id").val(Entity.orderedItems[0]);
                        onColorSelectorChange(Entity.orderedItems[0]);
                }
                select.find("option:eq(0)").remove();
        }

    var prodid = $("#product_id").val();


    
    // Fix to always show first image's title on page load
    if ("undefined" != typeof(title_1)){
        $('.slides .modelName').html(title_1[0]);
    }
    
    
    function getSeletectedItemId(){
         return $("#item_id").val();
    }
    
    
    /**
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
     */
        $('a.vt').click(function(){
                trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
        });
        
        $('#computeShippingEstimate').click(function(){
                updateEstimate(getSeletectedItemId());
        });
        
    $("#addToCart").click(function(){
        window.location = "/storewebsite/order-details?product_id=" + getSeletectedItemId() + "&price=" + $('#mrp').text();
        });
        
        $("#colorSelector").change(function(){
                var itemid = $("#colorSelector option:selected").val();
                onColorSelectorChange(itemid);
                return false;
        });
        
        $(".util_compare").click(function() {
                $.colorbox({
                        inline:true, 
                        href:"#compareLightBox",
                width:"350px",
                height:"230px",
                
                onComplete: function(){
                        $('#compareLightBox').show();
                },
                onCleanup: function(){
                        $('#compareLightBox').hide();
                }
        });
        });
        
        $('.util_addnewresearch').click(function(){
                addResearch('', 'single');
        });
        
    $('#mobilename').keypress(function(e) {
        if(e.keyCode == 13) {
                return compareProducts($("#compare_continue").attr("producttype"));
        }
    });
    
    
    $("#compare_continue").click(function() {
        return compareProducts($(this).attr("producttype"));
    });

    $('.tooltip').click(function() {
        trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
    });
    
    $('.tooltip').each(function(index) {
           $(this).qtip({
                style: { width: 300, overflow: 'auto',
                        tip: { corner: 'topLeft' }, 
                        border: { width: 2, radius: 2, color: '#DDDDDD' } },
                show: { when: { event: 'click' } },
                content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
                hide: { when: { event: 'unfocus' } },
                position: { adjust: {screen: true} }
                });
        });
        
        
    function compareProducts(productType){
                var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
        
        var productName = $("#mobilename").val();
                var hypenatedNameTwo = productName.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
                
                var productTwo = productIdNames[productType][productName];
                if(typeof productTwo == 'undefined'){
                        alert("Please select a valid product");
                        return false;
                }
                var productOne = $("#catalog_id").val();
                var prodDetail = $("#productDetail");
                var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
                var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();  
                window.location = "/compare-" + hyphenatedProductType + "/" 
                        + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=product_page";   
        }
    
    $("#accessories table td div a").live('click', function() {
        var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
        trackEventWithGA('Widget', 'Accessory Click', productId);
    });
    
        
        $('.nextSlide-anchorLink').live('click', function() {
            var nextSlideLink = $(this).attr('nextSlideId');
            $('a[href="' + nextSlideLink +'"]').click();
            return false;
        });
    
    $('a.compare-now').live('click', function(){
                var productType = $(this).attr('producttype');
                productType = productType.replace(/ +/g, '-').toLowerCase();
                
                var productOne = $("#catalog_id").val();
                var prodDetail = $("#productDetail");
                var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();
                var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
                
                var productTwo = $(this).attr("value");
                var hypenatedNameTwo = $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
                
                window.location = "/compare-" + productType + "/" + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=most_compared_widget";
    });
    jQuery('div.bread-crumbs, div.compare-links, #social-plugins-div').remove();
});

function changeSignInClass(){
        if(document.getElementById("signinClass").className.indexOf("signin1") > -1)    {
                document.getElementById("signinClass").className = 'signin';
        } else  {
                document.getElementById("signinClass").className = 'signin1';
        }
}


function updateEstimate(itemId) {
        itemId = itemId || $("#colorSelector option:selected").val();
        jQuery.ajax({
                type: "GET",
                url: "/storewebsite/estimate/" + $("#zipcode").val() + "_" + itemId,
                beforeSend: function()  {
                        $("#shipping_time").show();
                        $("#shipping_time_1").hide();
                        $("#shipping_time .red").html("<img src='/storewebsite/images/loader_l.gif'>");
                },
                success: function(msg)  {
                        var response = eval('(' + msg + ')');
                        var deliveryEstimate = (response['delivery_estimate']);
                        var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
                        var isOTG = (response['on_time_guarantee'] === 'true');
                        
                        var isActive = (response['is_active'] === 'true');
                        var isActiveOnStore = (response['active_on_store'] === 'true');
                        var selling_price = parseFloat(response['selling_price']).toFixed(2);
                        var absoluteMinPrice = parseFloat(response['absolute_min_price']).toFixed(2);

                        if(deliveryEstimate === '01 January 1970')      {
                                $("#shipping_time").hide();
                                $("#shipping_time_1").show();
                        } else  {
                                $("#shipping_time").html("Get this product on <label class='red'>" + deliveryEstimate + "</label>");
                        }
                        
                        if(!isActiveOnStore) {
                                $("#addToCart").text("NOT AVAILABLE");
                                $("#addToCart").css("color", "black");
                                $("#addToCart").unbind();
                        } else if(!isActive) {
                                $("#addToCart").text("NOT AVAILABLE");
                                $("#addToCart").css("color", "black");
                                $("#addToCart").unbind();
                        } else {
                                $("#addToCart").text("ADD TO CART");
                                $("#addToCart").css("color", "white");
                                $("#addToCart").unbind();
                                $("#addToCart").bind('click', function(){
                                $('<form action="/storewebsite/order-details" method="POST">' +
                                        '<input name="product_id" value="' + getSeletectedItemId()+'"/>' +
                                        '<input name="price" value="' + $('#mrp').text() +'"/>' +
                                '</form>').submit();
                                });
                        }
                        
                        if(selling_price == 0) {
                                $("#addToCart").text("NOT AVAILABLE");
                                $("#addToCart").css("color", "black");
                                $("#addToCart").unbind();
                                
                                $('#sellingPriceBox').val('N/A');
                                $('#mrp').html('N/A');
                                $('#minPrice').html('N/A');
                                $('#maxPrice').html('N/A');
                                $('#absMin').val(0);
                                $('#cod').hide();
                                $('#otg').hide();
                                $('#item_id').val(itemId);
                                
                                $('#editSellingPriceButton').hide();
                                $("#shipping_time").html("<label class='red'>Error in getting price.Please refresh this page.</label>");
                        } else {
                                $('#editSellingPriceButton').show();
                                $('.warranty').html(response['best_deal_text']);
                                $('#mrp').html(selling_price);
                                $('#minPrice').html(parseFloat(response['min_selling_price']).toFixed(2));
                                $('#maxPrice').html(parseFloat(response['max_selling_price']).toFixed(2));
                                $('#sellingPriceBox').val(selling_price);
                                $('#absMin').val(absoluteMinPrice);
                                $('#cod').hide();
                                $('#otg').hide();
                                $('#item_id').val(itemId);
                        }
                }
        });
}

function load_most_compared_widget(){
        jQuery.ajax({
                type : "GET",
                url : "/most-compared-products/" + $("#product_id").val(),
                cache: false,
                success : function(html) {
                    $("#mostcompared").html(html);

                    // Product Title
                    $("#mostcompared table td div a").each(function() {
                                if($(this).attr('class') != "compare-now"){
                                        $(this).truncate({addtitle : true});
                                }
                    });

                    // Product Price
                    $("#mostcompared table td div div.price").each(function() {
                                        $(this).truncate({addtitle : true});
                        });

                    // Product Details
                    $("#mostcompared table td div div.text").each(function() {
                                        $(this).truncate( {addtitle : true});
                        });
            }
        });
}
function onColorSelectorChange(itemid){
        if($('#sp').length>0){
                $('#sp').html(PARAMETERS[itemid].SP);
                $('#mrp').html(PARAMETERS[itemid].MRP);
                $('#saving').html(PARAMETERS[itemid].SAVING);
                $("#item_id").val(itemid);
        }
        updateEstimate(itemid);
}