Subversion Repositories SmartDukaan

Rev

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

$(function(){
        $('#loopedSlider').loopedSlider();
        
        runEffect();
        
        $(".controls").tabs();
        
        $('#forgot_username_link').tipsy({gravity: 'w'});

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

    var prodid = $("#product_id").val();
    
        add_to_storage_set("histitems", prodid);
    
    load_history_widget();

    load_accessories_widget();
    
    load_most_compared_widget();

    myNotes.getNotes();
    
    // 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(){
        jQuery.ajax({
                        type: "POST",
                        url: "/addtocart",
                        data: "productid=" + getSeletectedItemId(),
                        success: function(msg)  {
                                 if(msg == "") {
                                         trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
                                         window.location = "/cart";
                                 } else {
                                         var productDetail =  $("#productDetail");
                                 var prodInfo = $(productDetail).find("span.brand").html() + $(productDetail).find("span.product-name").html();
                                         displayRelatedProducts(msg);
                                         trackEventWithGA('Order', 'OOS Lightbox', prodInfo);
                                 }
                        }
                });
        });
        
        $("#colorSelector").change(function(){
                var itemid = $("#colorSelector option:selected").val();
                $('#sp').html(PARAMETERS[itemid].SP);
                $('#mrp').html(PARAMETERS[itemid].MRP);
                $('#saving').html(PARAMETERS[itemid].SAVING);
                $("#item_id").val(itemid);
                updateEstimate(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").click(function() {
        return compareProducts();
    });

    $('.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(){
                var productName = $("#mobilename").val();
                var productTwo = typeof(productIdNames['mobiles'][productName]) == 'undefined' ? productIdNames['laptops'][productName] : productIdNames['mobiles'][productName];
                
                if(typeof productTwo == 'undefined'){
                        alert("Please select a valid product");
                        return false;
                }
                var productOne = $("#catalog_id").val();
                window.location = "/compare-mobile-phones?p1="+productOne+"&p2="+productTwo;    
        }
    
    $("#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);
    });
    
});

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: "/estimate/" + $("#zipcode").val() + "_" + itemId,
                beforeSend: function()  {
                        $("#shipping_time").html("Receive in <img src='/images/loader_l.gif'> business days");
                },
                success: function(msg)  {
                        var response = eval('(' + msg + ')');
                        var deliveryEstimate = parseInt(response['delivery_estimate']);
                        var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
                        
                        if(deliveryEstimate == -1)      {
                                $("#shipping_time").html('This Location is not serviceable');
                        } else  {
                                $("#shipping_time").html('Receive in <label class="red">' + deliveryEstimate + ' Business Days</label>');
                        }
                        
                        if (isCODAvailableForLocation)  {
                                $('#cod').show();
                        } else {
                                $('#cod').hide();
                        }
                }
        });
}

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() {
                                        $(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});
                        });
            }
        });
}