Subversion Repositories SmartDukaan

Rev

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