Subversion Repositories SmartDukaan

Rev

Rev 1047 | Rev 1199 | 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").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});
                
                /*
                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;
     }
     
     if(tot>0){
          //alert("AJAX request to add products in My research. Product ID: "+seldata+" and total: "+tot);
          jQuery.ajax({
               type: "POST",
                      url: "/myresearch",
                      data: "productid="+seldata,
                      success: function(msg){
                           
                           if(msg == 0){
                                alert( "Please register/signin to use myresearch tool" );
                           }else if(msg == 1){
                                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).animate({ backgroundColor: "#fcffb3" }, 'slow');
                                          $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
                                     });
                                     
                                }else if(reqtype == "single"){
                                     var tblid="#pane1 #"+seldata+ " td";
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');  
                                }else if(reqtype == "list"){
                                     var tblid="#pane1 #"+seldata+ " td";
                                     $(tblid).animate({ backgroundColor: "#fcffb3" }, 'slow');
                                     $(tblid).animate({ backgroundColor: "#F5F5F5" }, 'slow');     
                                }    
                           }
                           //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;
     }
     
     if(tot>0){
          //alert("AJAX request to add products in Cart. Product ID: "+seldata+" and total: "+tot); 
          jQuery.ajax({
               type: "POST",
                      url: "/cart",
                      data: "productid="+seldata,
                      success: function(msg){
                           $("#cartItemCount").html(msg*1);
                           //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();

}

// Google analytics.
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-21662919-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();