Subversion Repositories SmartDukaan

Rev

Rev 5862 | Rev 6021 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1456 varun.gupt 1
$(function(){
2
	$('#loopedSlider').loopedSlider();
3
 
4
	runEffect();
5
 
6
	$(".controls").tabs();
7
 
8
	$('#forgot_username_link').tipsy({gravity: 'w'});
9
 
10
	$("#zipcode").val($("#defaultpincode").val());
4934 amit.gupta 11
 
12
	if(typeof Entity != 'undefined'){
13
		var select = $("#colorSelector");
5373 rajveer 14
		if(Entity.orderedItems){
5347 amit.gupta 15
			$.each(Entity.orderedItems, function(index, sort) {
16
				select.find('option[value="' + sort + '"]').appendTo(select);
17
			});
18
			$("#item_id").val(Entity.orderedItems[0]);
5889 amit.gupta 19
			onColorSelectorChange(Entity.orderedItems[0]);
5347 amit.gupta 20
		}
4934 amit.gupta 21
		select.find("option:eq(0)").remove();
22
	}
1456 varun.gupt 23
 
1761 vikas 24
    var prodid = $("#product_id").val();
25
 
26
	add_to_storage_set("histitems", prodid);
27
 
2652 rajveer 28
    load_accessories_widget();
3406 rajveer 29
 
30
    load_most_compared_widget();
2754 rajveer 31
 
2731 varun.gupt 32
    myNotes.getNotes();
33
 
4489 varun.gupt 34
    // Fix to always show first image's title on page load
4530 mandeep.dh 35
    if ("undefined" != typeof(title_1)){
36
        $('.slides .modelName').html(title_1[0]);
37
    }
4489 varun.gupt 38
 
4530 mandeep.dh 39
 
3830 chandransh 40
    function getSeletectedItemId(){
41
    	 return $("#item_id").val();
42
    }
43
 
44
 
1922 varun.gupt 45
    /**
46
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
47
     */
48
	$('a.vt').click(function(){
49
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
50
	});
51
 
3830 chandransh 52
	$('#computeShippingEstimate').click(function(){
53
		updateEstimate(getSeletectedItemId());
54
	});
55
 
56
    $("#addToCart").click(function(){
2811 rajveer 57
    	jQuery.ajax({
1456 varun.gupt 58
			type: "POST",
1614 rajveer 59
			url: "/addtocart",
3830 chandransh 60
			data: "productid=" + getSeletectedItemId(),
1456 varun.gupt 61
			success: function(msg)	{
4530 mandeep.dh 62
	   			 if(msg == "") {
3830 chandransh 63
	   				 trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
2036 rajveer 64
					 window.location = "/cart";
4530 mandeep.dh 65
				 } else {
4934 amit.gupta 66
					 var productDetail =  $("#productDetail");
67
    				 var prodInfo = $(productDetail).find("span.brand").html() + $(productDetail).find("span.product-name").html();
2810 rajveer 68
					 displayRelatedProducts(msg);
4934 amit.gupta 69
					 trackEventWithGA('Order', 'OOS Lightbox', prodInfo);
4530 mandeep.dh 70
				 }
2754 rajveer 71
	   		}
1456 varun.gupt 72
		});
73
	});
74
 
3830 chandransh 75
	$("#colorSelector").change(function(){
76
		var itemid = $("#colorSelector option:selected").val();
5889 amit.gupta 77
		onColorSelectorChange(itemid);
1456 varun.gupt 78
		return false;
79
	});
80
 
3830 chandransh 81
	$(".util_compare").click(function() {
2755 rajveer 82
		$.colorbox({
83
			inline:true, 
84
			href:"#compareLightBox",
85
    		width:"350px",
86
    		height:"230px",
87
 
88
    		onComplete: function(){
89
    			$('#compareLightBox').show();
90
    		},
91
    		onCleanup: function(){
92
    			$('#compareLightBox').hide();
93
    		}
94
    	});
2228 rajveer 95
	});
3830 chandransh 96
 
97
	$('.util_addnewresearch').click(function(){
98
		addResearch('', 'single');
99
	});
100
 
2236 rajveer 101
    $('#mobilename').keypress(function(e) {
102
    	if(e.keyCode == 13) {
5347 amit.gupta 103
    		return compareProducts($("#compare_continue").attr("producttype"));
2236 rajveer 104
        }
105
    });
106
 
107
 
2228 rajveer 108
    $("#compare_continue").click(function() {
5347 amit.gupta 109
    	return compareProducts($(this).attr("producttype"));
2228 rajveer 110
    });
2236 rajveer 111
 
3305 rajveer 112
    $('.tooltip').click(function() {
113
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
114
    });
115
 
2320 rajveer 116
    $('.tooltip').each(function(index) {
117
    	   $(this).qtip({
118
    		style: { width: 300, overflow: 'auto',
119
    			tip: { corner: 'topLeft' }, 
120
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
121
    		show: { when: { event: 'click' } },
122
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
123
    		hide: { when: { event: 'unfocus' } },
124
    		position: { adjust: {screen: true} }
125
    		});
126
    	});
127
 
128
 
5347 amit.gupta 129
    function compareProducts(productType){
130
		var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
131
 
132
    	var productName = $("#mobilename").val();
5358 amit.gupta 133
		var hypenatedNameTwo = productName.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
4143 varun.gupt 134
 
5347 amit.gupta 135
		var productTwo = productIdNames[productType][productName];
2236 rajveer 136
		if(typeof productTwo == 'undefined'){
137
			alert("Please select a valid product");
138
			return false;
139
		}
2827 rajveer 140
		var productOne = $("#catalog_id").val();
5347 amit.gupta 141
		var prodDetail = $("#productDetail");
142
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
5358 amit.gupta 143
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();  
5347 amit.gupta 144
		window.location = "/compare-" + hyphenatedProductType + "/" 
5552 phani.kuma 145
			+ hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=product_page";	
2236 rajveer 146
	}
2228 rajveer 147
 
2802 rajveer 148
    $("#accessories table td div a").live('click', function() {
149
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
150
    	trackEventWithGA('Widget', 'Accessory Click', productId);
151
    });
152
 
5862 amit.gupta 153
 
154
	$('.nextSlide-anchorLink').live('click', function() {
155
	    var nextSlideLink = $(this).attr('nextSlideId');
156
	    $('a[href="' + nextSlideLink +'"]').click();
157
	    return false;
158
	});
159
 
5552 phani.kuma 160
    $('a.compare-now').live('click', function(){
161
		var productType = $(this).attr('producttype');
162
		productType = productType.replace(/ +/g, '-').toLowerCase();
163
 
164
		var productOne = $("#catalog_id").val();
165
		var prodDetail = $("#productDetail");
166
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();
167
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
168
 
169
		var productTwo = $(this).attr("value");
170
		var hypenatedNameTwo = $(this).attr("title").replace(/ +/g, '-').replace(/\/+/g,'-').replace(/-+/g,'-').toLowerCase();
171
 
172
		window.location = "/compare-" + productType + "/" + hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo+"&fromsrc=most_compared_widget";
173
    });
174
 
1456 varun.gupt 175
});
176
 
177
function changeSignInClass(){
178
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
179
		document.getElementById("signinClass").className = 'signin';
180
	} else	{
181
		document.getElementById("signinClass").className = 'signin1';
182
	}
183
}
184
 
2228 rajveer 185
 
1456 varun.gupt 186
function updateEstimate(itemId)	{
3830 chandransh 187
	itemId = itemId || $("#colorSelector option:selected").val();
1456 varun.gupt 188
 
189
	jQuery.ajax({
190
		type: "GET",
1919 rajveer 191
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 192
		beforeSend: function()	{
5234 amit.gupta 193
			$("#shipping_time").show();
194
			$("#shipping_time_1").hide();
195
			$("#shipping_time .red").html("<img src='/images/loader_l.gif'> business days");
1456 varun.gupt 196
		},
197
		success: function(msg)	{
3830 chandransh 198
			var response = eval('(' + msg + ')');
199
			var deliveryEstimate = parseInt(response['delivery_estimate']);
200
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
201
 
202
			if(deliveryEstimate == -1)	{
5234 amit.gupta 203
				$("#shipping_time").hide();
204
				$("#shipping_time_1").show();
3830 chandransh 205
			} else	{
5234 amit.gupta 206
				$("#shipping_time .red").html(deliveryEstimate + ' Business Days');
3830 chandransh 207
			}
208
 
4869 rajveer 209
			if (isCODAvailableForLocation)	{
3830 chandransh 210
				$('#cod').show();
211
			} else {
212
				$('#cod').hide();
213
			}
1456 varun.gupt 214
		}
215
	});
2228 rajveer 216
}
217
 
3406 rajveer 218
function load_most_compared_widget(){
219
	jQuery.ajax({
220
		type : "GET",
221
		url : "/most-compared-products/" + $("#product_id").val(),
222
		cache: false,
223
		success : function(html) {
224
   		    $("#mostcompared").html(html);
225
 
226
		    // Product Title
227
		    $("#mostcompared table td div a").each(function() {
5552 phani.kuma 228
		    		if($(this).attr('class') != "compare-now"){
229
		    			$(this).truncate({addtitle : true});
230
		    		}
3406 rajveer 231
		    });
232
 
233
		    // Product Price
234
		    $("#mostcompared table td div div.price").each(function() {
235
					$(this).truncate({addtitle : true});
236
			});
237
 
238
		    // Product Details
239
		    $("#mostcompared table td div div.text").each(function() {
240
					$(this).truncate( {addtitle : true});
241
			});
242
	    }
243
	});
5889 amit.gupta 244
}
245
function onColorSelectorChange(itemid){
246
	$('#sp').html(PARAMETERS[itemid].SP);
247
	$('#mrp').html(PARAMETERS[itemid].MRP);
248
	$('#saving').html(PARAMETERS[itemid].SAVING);
249
	$("#item_id").val(itemid);
250
	updateEstimate(itemid);
3406 rajveer 251
}