Subversion Repositories SmartDukaan

Rev

Rev 5166 | Rev 5347 | 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
 
2652 rajveer 26
    load_accessories_widget();
3406 rajveer 27
 
28
    load_most_compared_widget();
2754 rajveer 29
 
2731 varun.gupt 30
    myNotes.getNotes();
31
 
4489 varun.gupt 32
    // Fix to always show first image's title on page load
4530 mandeep.dh 33
    if ("undefined" != typeof(title_1)){
34
        $('.slides .modelName').html(title_1[0]);
35
    }
4489 varun.gupt 36
 
4530 mandeep.dh 37
 
3830 chandransh 38
    function getSeletectedItemId(){
39
    	 return $("#item_id").val();
40
    }
41
 
42
 
1922 varun.gupt 43
    /**
44
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
45
     */
46
	$('a.vt').click(function(){
47
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
48
	});
49
 
3830 chandransh 50
	$('#computeShippingEstimate').click(function(){
51
		updateEstimate(getSeletectedItemId());
52
	});
53
 
54
    $("#addToCart").click(function(){
2811 rajveer 55
    	jQuery.ajax({
1456 varun.gupt 56
			type: "POST",
1614 rajveer 57
			url: "/addtocart",
3830 chandransh 58
			data: "productid=" + getSeletectedItemId(),
1456 varun.gupt 59
			success: function(msg)	{
4530 mandeep.dh 60
	   			 if(msg == "") {
3830 chandransh 61
	   				 trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
2036 rajveer 62
					 window.location = "/cart";
4530 mandeep.dh 63
				 } else {
4934 amit.gupta 64
					 var productDetail =  $("#productDetail");
65
    				 var prodInfo = $(productDetail).find("span.brand").html() + $(productDetail).find("span.product-name").html();
2810 rajveer 66
					 displayRelatedProducts(msg);
4934 amit.gupta 67
					 trackEventWithGA('Order', 'OOS Lightbox', prodInfo);
4530 mandeep.dh 68
				 }
2754 rajveer 69
	   		}
1456 varun.gupt 70
		});
71
	});
72
 
3830 chandransh 73
	$("#colorSelector").change(function(){
74
		var itemid = $("#colorSelector option:selected").val();
1456 varun.gupt 75
		$('#sp').html(PARAMETERS[itemid].SP);
76
		$('#mrp').html(PARAMETERS[itemid].MRP);
77
		$('#saving').html(PARAMETERS[itemid].SAVING);
78
		$("#item_id").val(itemid);
79
		updateEstimate(itemid);
80
		return false;
81
	});
82
 
3830 chandransh 83
	$(".util_compare").click(function() {
2755 rajveer 84
		$.colorbox({
85
			inline:true, 
86
			href:"#compareLightBox",
87
    		width:"350px",
88
    		height:"230px",
89
 
90
    		onComplete: function(){
91
    			$('#compareLightBox').show();
92
    		},
93
    		onCleanup: function(){
94
    			$('#compareLightBox').hide();
95
    		}
96
    	});
2228 rajveer 97
	});
3830 chandransh 98
 
99
	$('.util_addnewresearch').click(function(){
100
		addResearch('', 'single');
101
	});
102
 
2236 rajveer 103
    $('#mobilename').keypress(function(e) {
104
    	if(e.keyCode == 13) {
105
    		return compareProducts();
106
        }
107
    });
108
 
109
 
2228 rajveer 110
    $("#compare_continue").click(function() {
2236 rajveer 111
    	return compareProducts();
2228 rajveer 112
    });
2236 rajveer 113
 
3305 rajveer 114
    $('.tooltip').click(function() {
115
    	trackEventWithGA('Product', 'Helpdoc Click', $(this).attr('name'));
116
    });
117
 
2320 rajveer 118
    $('.tooltip').each(function(index) {
119
    	   $(this).qtip({
120
    		style: { width: 300, overflow: 'auto',
121
    			tip: { corner: 'topLeft' }, 
122
    			border: { width: 2, radius: 2, color: '#DDDDDD' } },
123
    		show: { when: { event: 'click' } },
124
    		content: { url: "/helpdocs/" + $(this).attr('name'), title: { text: ' ', button: 'Close'} },
125
    		hide: { when: { event: 'unfocus' } },
126
    		position: { adjust: {screen: true} }
127
    		});
128
    	});
129
 
130
 
2236 rajveer 131
    function compareProducts(){
132
		var productName = $("#mobilename").val();
4143 varun.gupt 133
		var productTwo = typeof(productIdNames['mobiles'][productName]) == 'undefined' ? productIdNames['laptops'][productName] : productIdNames['mobiles'][productName];
134
 
2236 rajveer 135
		if(typeof productTwo == 'undefined'){
136
			alert("Please select a valid product");
137
			return false;
138
		}
2827 rajveer 139
		var productOne = $("#catalog_id").val();
2236 rajveer 140
		window.location = "/compare-mobile-phones?p1="+productOne+"&p2="+productTwo;	
141
	}
2228 rajveer 142
 
2802 rajveer 143
    $("#accessories table td div a").live('click', function() {
144
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
145
    	trackEventWithGA('Widget', 'Accessory Click', productId);
146
    });
147
 
1456 varun.gupt 148
});
149
 
150
function changeSignInClass(){
151
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
152
		document.getElementById("signinClass").className = 'signin';
153
	} else	{
154
		document.getElementById("signinClass").className = 'signin1';
155
	}
156
}
157
 
2228 rajveer 158
 
1456 varun.gupt 159
function updateEstimate(itemId)	{
3830 chandransh 160
	itemId = itemId || $("#colorSelector option:selected").val();
1456 varun.gupt 161
 
162
	jQuery.ajax({
163
		type: "GET",
1919 rajveer 164
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 165
		beforeSend: function()	{
5234 amit.gupta 166
			$("#shipping_time").show();
167
			$("#shipping_time_1").hide();
168
			$("#shipping_time .red").html("<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)	{
5234 amit.gupta 176
				$("#shipping_time").hide();
177
				$("#shipping_time_1").show();
3830 chandransh 178
			} else	{
5234 amit.gupta 179
				$("#shipping_time .red").html(deliveryEstimate + ' Business Days');
3830 chandransh 180
			}
181
 
4869 rajveer 182
			if (isCODAvailableForLocation)	{
3830 chandransh 183
				$('#cod').show();
184
			} else {
185
				$('#cod').hide();
186
			}
1456 varun.gupt 187
		}
188
	});
2228 rajveer 189
}
190
 
3406 rajveer 191
function load_most_compared_widget(){
192
	jQuery.ajax({
193
		type : "GET",
194
		url : "/most-compared-products/" + $("#product_id").val(),
195
		cache: false,
196
		success : function(html) {
197
   		    $("#mostcompared").html(html);
198
 
199
		    // Product Title
200
		    $("#mostcompared table td div a").each(function() {
201
					$(this).truncate({addtitle : true});
202
		    });
203
 
204
		    // Product Price
205
		    $("#mostcompared table td div div.price").each(function() {
206
					$(this).truncate({addtitle : true});
207
			});
208
 
209
		    // Product Details
210
		    $("#mostcompared table td div div.text").each(function() {
211
					$(this).truncate( {addtitle : true});
212
			});
213
	    }
214
	});
215
}