Subversion Repositories SmartDukaan

Rev

Rev 3305 | Rev 4143 | 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());

    updateEstimate($("#colorselector option:selected").val());
    
    var prodid = $("#product_id").val();
    
        add_to_storage_set("histitems", prodid);
    
    load_history_widget();

    load_accessories_widget();
    
    load_most_compared_widget();

    myNotes.getNotes();
    
    /**
     * 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());
        });
        
    $("#addcart").click(function(){
        jQuery.ajax({
                        type: "POST",
                        url: "/addtocart",
                        data: "productid=" + $("#item_id").val(),
                        success: function(msg)  {
                                 if(msg==""){
                                         trackEventWithGA('Order', 'Add to Cart', $("#item_id").val() + '');
                                         window.location = "/cart";
                                 }else{
                                         displayRelatedProducts(msg);
                                 }                      
                        }
                });
        });
        
        $("#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;
        });
        
        $("a.colorselector").click(function() {
                $('.a.colorselector').addClass('deselect');
                $(this).addClass('deselect');
                var itemid = $(this).attr('itemid');
                $('#sp').html(" "+PARAMETERS[itemid].SP);
                $('#mrp').html(" "+PARAMETERS[itemid].MRP);
                $('#saving').html(PARAMETERS[itemid].SAVING);
                $("#item_id").val(itemid);
                return false;
        });

        $("#util_compare").click(function() {
                $.colorbox({
                        inline:true, 
                        href:"#compareLightBox",
                width:"350px",
                height:"230px",
                
                onComplete: function(){
                        $('#compareLightBox').show();
                },
                onCleanup: function(){
                        $('#compareLightBox').hide();
                }
        });
        });

        /* This code is for compare with button */
        var availableNames = [];
        for (var k in productIdNames)availableNames.push(k);
    $("#mobilename").autocomplete({  autoFocus: true, minLength: 3, 
        source: availableNames
    });


    $('#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 = productIdNames[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 || $("#item_id").val();
        
        jQuery.ajax({
                type: "GET",
                url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
                beforeSend: function()  {
                        $("#shipping_time").html("Within <img src='/images/loader_l.gif'> business days");
                },
                success: function(msg)  {
                        $("#shipping_time").html(msg);
                }
        });
}

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});
                        });
            }
        });
}