Subversion Repositories SmartDukaan

Rev

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

/* 
     Author: Binay Kumar
     Created on: 30.09.2010
     
     Example:
     addResearch(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
     Multiple request: onclick="javascript:addResearch('pane2','multi');"
     Single request: onclick="javascript:addResearch('','single');"
     
     addToCart(refdivid,reqtype) refdivid=pane1, reqtype=single/multi
     Multiple request: onclick="javascript:addToCart('pane2','multi');"
     Single request: onclick="javascript:addToCart('','single');"
     
     NOTE: incase reqtype=list then refdivid should be product id
     
*/

$(function() {

        $("a.addtocart").live('click', function() {
                var catalogid = $(this).attr('catalogid');
                //alert("clicked add to cart" + catalogid);
                
                var radBtn = "";
                var param = "PARAMETERS_" + catalogid;
        
                $.each(eval(param), function(val, text) {
                        radBtn += '<label><input type="radio" name="radColorSel" value="' + val + '" /> <span>' + text + '</span></label>';
                });
                
                radBtn += '<div class="clearBoth"></div>';
                $(".colorSelLightBoxColor .content").html(radBtn);

                $.fn.colorbox({inline:true, href:".colorSelLightBoxColor", open:true, onComplete:function(){
                        var posLeft = (document.documentElement.clientWidth / 2) - (parseInt($('#colorbox').css('width')) / 2);
                        var posTop = (document.documentElement.clientHeight / 2) - (parseInt($('#colorbox').css('height')) / 2);

                        $('#colorbox').css('top', posTop);
                        $('#colorbox').css('left', posLeft);
                }});
                
                /*
                var select = $('#colorselector');
                var options = select.attr('options');
                $('option', select).remove();
                $.each(eval(param), function(val, text) {
                    options[options.length] = new Option(text, val);
                    //alert(val + ": " + text);
                });
                $( "#dialog-form" ).dialog( "open" );
                */
        });
        
        /*
        $( "#dialog-form" ).dialog({
                autoOpen: false,
                height: 200,
                width: 250,
                modal: true,
                buttons: {
                        Ok: function() {
                                var bValid = true;
                                var selected = $("#colorselector option:selected");
                                var itemid = selected.val();
                                addToCart(itemid,'list');
                                $( this ).dialog( "close" );
                                },
                        Cancel: function() {
                                $( this ).dialog( "close" );
                                }
                        },
                        close: function() {
                                
                        }
                });
        */
});
        

function selectColor(){
        var bValid = true;
        var selected = $(".colorSelLightBoxColor .content input[name='radColorSel']:checked");
        var itemid = selected.val();
        
        if(itemid == undefined){
                alert('Please select a color.');
        }else{
                addToCart(itemid,'list');
                $.colorbox.close();
        }
}

function onSelectChange(itemid){
        //alert("selected color is"+itemid);
}


function addResearch(refdivid,reqtype){
     var research_tot=$("#research_total").val();
     var seldata="";
     var tot=0;
     var saprt="";
     
     if(reqtype=="multi"){
          var containerdiv = "#" + refdivid;     
          var par= containerdiv + " input[type=checkbox]:checked";
          $(par).each(function(){
               saprt = (tot>0)? "_":"";
               seldata += saprt+$(this).val();
               tot++;
          });
     }else if(reqtype=="single"){
          var seldata=$("#product_id").val();
          var tot=1;
     }else if(reqtype=="list"){
          
          var seldata=refdivid;
          var tot=1;
     }
     
/*
     var historyitems = "";
     if($.Storage.get("historyitems")){
         historyitems = "&historyitems=" +  $.Storage.get("historyitems");
         $.Storage.remove("historyitems");
     }
     +historyitems
     */
     
     if(tot>0){
          //alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
          jQuery.ajax({
               type: "POST",
                      url: "/addtoresearch",
                      data: "productid="+seldata,
                      success: function(msg){
                           
                           if(msg == 0){
                                alert( "Product is already in my research" );
                           }else {
                                var t=(research_tot*1)+(tot*1);
                                $("#research_total").val(t);
                                if(t > 0){
                                     $("#research_default").css("display","none");
                                }     
                                $("#pane1").prepend(msg);
                                // $('#pane1').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
                                
                                if(reqtype == "multi"){
                                     var arrayprod_id=seldata.split("_");
                                     jQuery.each(arrayprod_id,function(intIndex, objValue){
                                          var tblid="#pane1 #"+objValue+ " td";
                                          $(tblid + " div a").truncate({addtitle: true});
                                          $(tblid + " div div.price").truncate({addtitle: true});
                                          $(tblid + " div div.text").truncate({addtitle: true});
                                          $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');
                                     });
                                     
                                }else if(reqtype == "single"){
                                     var tblid="#pane1 #"+seldata+ " td";
                                     $(tblid + " div a").truncate({addtitle: true});
                                     $(tblid + " div div.price").truncate({addtitle: true});
                                     $(tblid + " div div.text").truncate({addtitle: true});
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
                                }else if(reqtype == "list"){
                                     var tblid="#pane1 #"+seldata+ " td";
                                     $(tblid + " div a").truncate({addtitle: true});
                                     $(tblid + " div div.price").truncate({addtitle: true});
                                     $(tblid + " div div.text").truncate({addtitle: true});
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
                                }    
                           }
                           $.Storage.set("research", $("#myresearch").html());
                           //alert( "Data Saved: " + msg );
                      }
          });
          
     }else{
          alert("Please select atleast one product");
     }
}


function addToCart(refdivid,reqtype){
     var seldata="";
     var tot=0;
     var saprt="";
     if(reqtype == "multi"){
          var containerdiv = "#" + refdivid;
          var par= containerdiv + " input[type=checkbox]:checked";
          var isMulti = false;
          $(par).each(function(){
                  
                   var totalcolors = $(this).attr('totalcolors');
                   //alert(totalcolors);
                   if(totalcolors != 1){
                           isMulti = true; 
                   }
                   saprt = (tot>0)? "_":"";
               seldata += saprt+$(this).attr('itemid');
               tot++;
          });
          //alert("ismulti" + isMulti + " seldata " + seldata + "   refdiv is "+ refdivid + "  par "+ par);
          if(isMulti == true){
                  alert("Some items are available in multiple colors. Please go to product page and select color you want.");
                  return;
          }
     }else if(reqtype == "single"){
          seldata = $("#item_id").val();
          tot=1;
     }else if(reqtype == "list"){
          var seldata=refdivid;
          var tot=1;
     }
     /*
     var historyitems = "";
     if($.Storage.get("historyitems")){
         historyitems = "&historyitems=" +  $.Storage.get("historyitems");
         $.Storage.remove("historyitems");
     }
     +historyitems
     */
     
     if(tot>0){
          //alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
          jQuery.ajax({
               type: "POST",
                      url: "/addtocart",
                      data: "productid="+seldata,
                      success: function(msg){
                           $("#cartItemCount").html(msg*1);
                           window.location="/cart";
                           //alert( "Data Saved: " + msg );
                      }
          });
     }else{
          alert("Please select atleast one product");
     }
     
}

function selectProduct(itemId){
        //alert("Selected item is "+ itemId);
}

function scrollWinToTop(){
    $('html, body').animate({
      scrollTop: $("body").offset().top
    }, 0);
}

function resetShipForm(){
  $('#shipName').val("");
  $('#shipAddress1').val("");
  $('#shipAddress2').val("");
  $('#shipState').val("");
  $('#shipCity').val("");
  $('#shipPin').val("");
  $('#shipPhone').val("");
        $('#newShipAdr').hide();
        scrollWinToTop();
}

function changeShipAddress(id){
  addressId = id.substring(20);
 //alert("TODO AJAX request to change shipping address. " + addressId);
   jQuery.ajax({
      type: "POST",
      url: "./shipping",
      data: "action=change&addressid="+addressId,
      success: function(msg){
         //alert( "Data Saved: " + msg );
         $("#addressid").val(msg);
      }
   });
  //$("#addressid").val(addressId);
  document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;
        $(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');
        $(".proceed-bttn input[disabled='']").removeAttr('disabled');
        
  //document.getElementById('newShipAdr').style.display = 'none';
  $('#newShipAdr').hide();
        scrollWinToTop();

}

function load_research_widget(){
        jQuery.ajax( {
                type : "GET",
                url : "/myresearch",
                cache: false,
                success : function(html) {
                $("#myresearch").html(html);

                // Product Title
                $("#myresearch table td div a").each(
                                function() {
                                        $(this).truncate( {
                                                addtitle : true
                                        });
                                });

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

                // Product Details
                $("#myresearch table td div div.text").each(
                                function() {
                                        $(this).truncate( {
                                                addtitle : true
                                        });
                                });
                $.Storage.set("research", $("#myresearch").html());               
        }
        });
}

function update_browse_history(){
        if($.Storage.get("historyitems")){
                params = $.Storage.get("historyitems");

                jQuery.ajax({
                        type: "POST",
                        url: "/browse-history",
                        data: "historyitems="+params,
                        cache: false,
                        success: function(html){
                                //alert(html);
                        }
                });
        }       
}

function load_history_widget() {
        var params = "";
        if(!($.cookie("uid"))){
                if($.Storage.get("historyitems")){
                        params = "/" + $.Storage.get("historyitems");
                }
        }
        
        jQuery.ajax({
                type: "GET",
                url: "/browse-history" + params,
                cache: false,
                success: function(html){
                $("#browsehistory").html(html);

                // Product Title
                $("#browsehistory table td div a").each(function(){
                        $(this).truncate({addtitle: true}); 
                });

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

                // Product Details
                $("#browsehistory table td div div.text").each(function(){
                        $(this).truncate({addtitle: true});
                });
                $.Storage.set("history", $("#browsehistory").html());
        }
        });
}