Rev 3283 | Rev 4210 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*Example:addResearch(refdivid,reqtype) refdivid=pane1, reqtype=single/multiMultiple request: onclick="javascript:addResearch('pane2','multi');"Single request: onclick="javascript:addResearch('','single');"addToCart(refdivid,reqtype) refdivid=pane1, reqtype=single/multiMultiple request: onclick="javascript:addToCart('pane2','multi');"Single request: onclick="javascript:addToCart('','single');"NOTE: incase reqtype=list then refdivid should be product id*/function trackEventWithGA(eventCategory, actionName, label) {if(typeof _gaq != "undefined" && _gaq != null) {_gaq.push(['_trackEvent', eventCategory, actionName, label, 2]);}}function trackPageWithGA(page) {if(typeof _gaq != "undefined" && _gaq != null) {_gaq.push(['_trackPageview', page]);}}$(function() {$('.add-to-cart-icon').live('click', function() {var items = this.id;var itemsarray = items.split('-');addToCart(itemsarray[1], itemsarray[0]);return false;});$("a.addtocart").live('click', function() {var catalogid = $(this).attr('catalogid');var radBtn = "";var param = "PARAMETERS_" + catalogid;radBtn += '<input type="hidden" id="selected_catalog_id" value=' + 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);}});});$('#notify').live('click', function() {emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;email=$('#emailId').val();if(!email.match(emailExp)){alert("Please enter valid email.");return false;}itemId=$('#itemId').val();emailId=$('#emailId').val();jQuery.ajax({type: "POST",url: "/product-notification",data: "emailId="+emailId+"&itemId="+itemId,success: function(msg){$('#notificationBox').html("<h3>We will notify you once we get the stock.</h3>");}});});$("#query").autocomplete({ autoFocus: true, minLength: 3,source: "/auto-suggest",select: function( event, ui ) {this.value = ui.item.value;$('#frmSearch').submit();return false;}});});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');saprt = (tot>0)? "_":"";seldata += saprt+$(this).attr('itemid');if(totalcolors != 1) {isMulti = true;}tot++;});if(isMulti == true){alert("Some items are available in multiple colors. Please go to product page and select color you want.");return;} else {var items = seldata.split('_');for(var i in items) {trackEventWithGA('Order', 'Add to Cart', items[i]);}}}else if(reqtype == "single"){seldata = $("#item_id").val();trackEventWithGA('Order', 'Add to Cart', seldata + '');tot=1;}else if(reqtype == "list"){var seldata=refdivid;trackEventWithGA('Order', 'Add to Cart', seldata + '');tot=1;}if(tot > 0) {jQuery.ajax({type: "POST",url: "/addtocart",data: "productid=" + seldata,success: function(msg){if(msg==""){window.location = "/cart";}else{displayRelatedProducts(msg);}}});} else {alert("Please select atleast one product");}}function selectColor(){var selected = $(".colorSelLightBoxColor .content input[name='radColorSel']:checked");var itemid = selected.val();trackEventWithGA('Order', 'Select Product Color', itemid);if(itemid == undefined) {alert('Please select a color.');} else {addToCart(itemid,'list');}}function displayRelatedProducts(message){$.colorbox({html:message,maxWidth:"400px",maxHeight:"410px",width:"400px",onComplete: function(){$('#cartRecommendationBox').show().find('.widgetChkBox').hide();},onCleanup: function(){$('#cartRecommendationBox').hide();}});}function addResearch(refdivid, reqtype){var research_tot = $("#research_total").val();var seldata = [];var tot = 0;if(reqtype == "multi") {var containerdiv = "#" + refdivid;var par = containerdiv + " input[type=checkbox]:checked";$(par).each(function(){seldata.unshift($(this).val());tot ++;});}else if(reqtype == "single") {seldata.unshift($("#product_id").val());tot = 1;}else if(reqtype == "list"){seldata.unshift(refdivid);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: "/addtoresearch",data: "productid=[" + seldata + "]",success: function(msg){var postSuccessDOMProcessing = function(objValue) {trackEventWithGA('Research', 'Add to Research', objValue);add_to_storage_set("resitems", objValue);var tblid = "#pane1 #" + objValue + " td";$(tblid + " div a.truncate").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');};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);if(reqtype == "multi") {jQuery.each(seldata,function(intIndex, objValue) {postSuccessDOMProcessing(objValue);});} else if(reqtype == "single") {postSuccessDOMProcessing(seldata);} else if(reqtype == "list") {postSuccessDOMProcessing(seldata);}}}});} else {alert("Please select atleast one product");}}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){$("#addressid").val(msg);}});document.getElementById('shipAddressContainer').innerHTML = document.getElementById(id).innerHTML;$(".proceed-bttn .yellow-image").removeClass('imgDisableButton').addClass('imgEnableButton');$(".proceed-bttn input[disabled='']").removeAttr('disabled');$('#newShipAdr').hide();scrollWinToTop();}function merge_history_items(){params = $.Storage.get("histitems");jQuery.ajax({type: "POST",url: "/browse-history",data: "id="+params,cache: false,success: function(json) {$.Storage.set("histitems", json);load_history_widget();}});}function load_research_items(){jQuery.ajax({type: "GET",url: "/myresearch",cache: false,success: function(json) {$.Storage.set("resitems", json);load_research_widget();}});}function load_research_widget(){if($("#myresearch").length == 0) {return;}var resitems = $.Storage.get("resitems");if (resitems == "[]") {var emptyResWidgetHtml = '<table border="0" width="100%" cellspacing="1" cellpadding="0" id="research_default">\<tbody>\<tr>\<td align="center">\<b>\Add items to research\</b>\</td>\</tr>\</tbody>\</table>';$("#myresearch #pane1").html(emptyResWidgetHtml);$('#winker0').slideToggle('slow', function(){$("#hdr0").addClass('swapy');});return;}var params = "/" + resitems;jQuery.ajax({type : "GET",url : "/myresearch" + params,cache: true,success : function(html) {$("#myresearch").html(html);// Product Title$("#myresearch table td div a.truncate").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});});}});}function load_history_widget() {if($("#browsehistory").length == 0) {return;}var histitems = $.Storage.get("histitems");if (histitems == "[]") {$("#browsehistory #pane5").html("");return;}var params = "/" + histitems;jQuery.ajax({type: "GET",url: "/browse-history" + params,cache: true,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});});}});}function add_to_storage_set(key, id) {var set = eval($.Storage.get(key));if (set) {$.each(set, function(index, value) {if (value == id) {set.splice(index, 1);}});}set.unshift(id);if (set.length>10){set.splice(10, set.length-10);}$.Storage.set(key, "[" + set.toString() + "]");}function delete_from_storage_set(key, id) {var set = eval($.Storage.get(key));if (set) {$.each(set, function(index, value) {if (value == id) {set.splice(index, 1);}});}$.Storage.set(key, "[" + set.toString() + "]");}function add_track_log(event, url, data) {if ($.cookie("uafc")) {jQuery.ajax( {url : "/tracking",type : "POST",data : {"event" : event,"url" : url,"data" : data},cache : false});}}function load_accessories_widget(){if($("#accessories").length == 0) {return;}jQuery.ajax({type : "GET",url : "/related-accessories/" + $("#product_id").val(),cache: true,success : function(html) {$("#accessories").html(html);// Product Title$("#accessories table td div a").each(function() {$(this).truncate({addtitle : true});});// Product Price$("#accessories table td div div.price").each(function() {$(this).truncate({addtitle : true});});// Product Details$("#accessories table td div div.text").each(function() {$(this).truncate( {addtitle : true});});}});}