Subversion Repositories SmartDukaan

Rev

Rev 4869 | Rev 5145 | 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");
14
		$.each(Entity.orderedItems, function(index, sort) {
15
			select.find('option[value="' + sort + '"]').appendTo(select);
16
		});
17
		select.find("option:eq(0)").remove();
18
		$("#item_id").val(Entity.orderedItems[0]);
19
		updateEstimate(getSeletectedItemId());
20
	}
1456 varun.gupt 21
 
1761 vikas 22
    var prodid = $("#product_id").val();
23
 
24
	add_to_storage_set("histitems", prodid);
25
 
1623 rajveer 26
    load_history_widget();
1761 vikas 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();
1456 varun.gupt 77
		$('#sp').html(PARAMETERS[itemid].SP);
78
		$('#mrp').html(PARAMETERS[itemid].MRP);
79
		$('#saving').html(PARAMETERS[itemid].SAVING);
80
		$("#item_id").val(itemid);
81
		updateEstimate(itemid);
82
		return false;
83
	});
84
 
3830 chandransh 85
/*	$("a.colorselector").click(function() {
1456 varun.gupt 86
		$('.a.colorselector').addClass('deselect');
87
		$(this).addClass('deselect');
1567 vikas 88
		var itemid = $(this).attr('itemid');
1456 varun.gupt 89
		$('#sp').html(" "+PARAMETERS[itemid].SP);
90
		$('#mrp').html(" "+PARAMETERS[itemid].MRP);
91
		$('#saving').html(PARAMETERS[itemid].SAVING);
92
		$("#item_id").val(itemid);
93
		return false;
3830 chandransh 94
	});*/
2228 rajveer 95
 
3830 chandransh 96
	$(".util_compare").click(function() {
2755 rajveer 97
		$.colorbox({
98
			inline:true, 
99
			href:"#compareLightBox",
100
    		width:"350px",
101
    		height:"230px",
102
 
103
    		onComplete: function(){
104
    			$('#compareLightBox').show();
105
    		},
106
    		onCleanup: function(){
107
    			$('#compareLightBox').hide();
108
    		}
109
    	});
2228 rajveer 110
	});
3830 chandransh 111
 
112
	$('.util_addnewresearch').click(function(){
113
		addResearch('', 'single');
114
	});
115
 
2236 rajveer 116
    $('#mobilename').keypress(function(e) {
117
    	if(e.keyCode == 13) {
118
    		return compareProducts();
119
        }
120
    });
121
 
122
 
2228 rajveer 123
    $("#compare_continue").click(function() {
2236 rajveer 124
    	return compareProducts();
2228 rajveer 125
    });
2236 rajveer 126
 
3305 rajveer 127
    $('.tooltip').click(function() {
128
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
129
    });
130
 
2320 rajveer 131
    $('.tooltip').each(function(index) {
132
    	   $(this).qtip({
133
    		style: { width: 300, overflow: 'auto',
134
    			tip: { corner: 'topLeft' }, 
135
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
136
    		show: { when: { event: 'click' } },
137
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
138
    		hide: { when: { event: 'unfocus' } },
139
    		position: { adjust: {screen: true} }
140
    		});
141
    	});
142
 
143
 
2236 rajveer 144
    function compareProducts(){
145
		var productName = $("#mobilename").val();
4143 varun.gupt 146
		var productTwo = typeof(productIdNames['mobiles'][productName]) == 'undefined' ? productIdNames['laptops'][productName] : productIdNames['mobiles'][productName];
147
 
2236 rajveer 148
		if(typeof productTwo == 'undefined'){
149
			alert("Please select a valid product");
150
			return false;
151
		}
2827 rajveer 152
		var productOne = $("#catalog_id").val();
2236 rajveer 153
		window.location = "/compare-mobile-phones?p1="+productOne+"&p2="+productTwo;	
154
	}
2228 rajveer 155
 
2802 rajveer 156
    $("#accessories table td div a").live('click', function() {
157
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
158
    	trackEventWithGA('Widget', 'Accessory Click', productId);
159
    });
160
 
1456 varun.gupt 161
});
162
 
163
function changeSignInClass(){
164
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
165
		document.getElementById("signinClass").className = 'signin';
166
	} else	{
167
		document.getElementById("signinClass").className = 'signin1';
168
	}
169
}
170
 
2228 rajveer 171
 
1456 varun.gupt 172
function updateEstimate(itemId)	{
3830 chandransh 173
	itemId = itemId || $("#colorSelector option:selected").val();
1456 varun.gupt 174
 
175
	jQuery.ajax({
176
		type: "GET",
1919 rajveer 177
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 178
		beforeSend: function()	{
3830 chandransh 179
			$("#shipping_time").html("Receive in <img src='/images/loader_l.gif'> business days");
1456 varun.gupt 180
		},
181
		success: function(msg)	{
3830 chandransh 182
			var response = eval('(' + msg + ')');
183
			var deliveryEstimate = parseInt(response['delivery_estimate']);
184
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
185
 
186
			if(deliveryEstimate == -1)	{
187
				$("#shipping_time").html('This Location is not serviceable');
188
			} else	{
189
				$("#shipping_time").html('Receive in <label class="red">' + deliveryEstimate + ' Business Days</label>');
190
			}
191
 
4869 rajveer 192
			if (isCODAvailableForLocation)	{
3830 chandransh 193
				$('#cod').show();
194
			} else {
195
				$('#cod').hide();
196
			}
1456 varun.gupt 197
		}
198
	});
2228 rajveer 199
}
200
 
3406 rajveer 201
function load_most_compared_widget(){
202
	jQuery.ajax({
203
		type : "GET",
204
		url : "/most-compared-products/" + $("#product_id").val(),
205
		cache: false,
206
		success : function(html) {
207
   		    $("#mostcompared").html(html);
208
 
209
		    // Product Title
210
		    $("#mostcompared table td div a").each(function() {
211
					$(this).truncate({addtitle : true});
212
		    });
213
 
214
		    // Product Price
215
		    $("#mostcompared table td div div.price").each(function() {
216
					$(this).truncate({addtitle : true});
217
			});
218
 
219
		    // Product Details
220
		    $("#mostcompared table td div div.text").each(function() {
221
					$(this).truncate( {addtitle : true});
222
			});
223
	    }
224
	});
225
}