Subversion Repositories SmartDukaan

Rev

Rev 5234 | Rev 5358 | 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");
5347 amit.gupta 14
		if(Entity.orderededItems){
15
			$.each(Entity.orderedItems, function(index, sort) {
16
				select.find('option[value="' + sort + '"]').appendTo(select);
17
			});
18
			$("#item_id").val(Entity.orderedItems[0]);
19
		}
4934 amit.gupta 20
		select.find("option:eq(0)").remove();
21
		updateEstimate(getSeletectedItemId());
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();
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) {
5347 amit.gupta 107
    		return compareProducts($("#compare_continue").attr("producttype"));
2236 rajveer 108
        }
109
    });
110
 
111
 
2228 rajveer 112
    $("#compare_continue").click(function() {
5347 amit.gupta 113
    	return compareProducts($(this).attr("producttype"));
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
 
5347 amit.gupta 133
    function compareProducts(productType){
134
		var hyphenatedProductType = productType.replace(/ +/g, '-').toLowerCase();
135
 
136
    	var productName = $("#mobilename").val();
137
		var hypenatedNameTwo = productName.replace(/ +/g, '-').toLowerCase();
4143 varun.gupt 138
 
5347 amit.gupta 139
		var productTwo = productIdNames[productType][productName];
2236 rajveer 140
		if(typeof productTwo == 'undefined'){
141
			alert("Please select a valid product");
142
			return false;
143
		}
2827 rajveer 144
		var productOne = $("#catalog_id").val();
5347 amit.gupta 145
		var prodDetail = $("#productDetail");
146
		var productNameOne = $(prodDetail).find("span.brand").html() + " " + $(prodDetail).find("span.product-name").html();  
147
		var hyphenateNameOne = productNameOne.replace(/ +/g, '-').toLowerCase();  
148
		window.location = "/compare-" + hyphenatedProductType + "/" 
149
			+ hyphenateNameOne + "-vs-" + hypenatedNameTwo + "?p1="+productOne+"&p2="+productTwo;	
2236 rajveer 150
	}
2228 rajveer 151
 
2802 rajveer 152
    $("#accessories table td div a").live('click', function() {
153
    	var productId = $(this).parent().parent().parent().children().find('input[type=checkbox]').val();
154
    	trackEventWithGA('Widget', 'Accessory Click', productId);
155
    });
156
 
1456 varun.gupt 157
});
158
 
159
function changeSignInClass(){
160
	if(document.getElementById("signinClass").className.indexOf("signin1") > -1)	{
161
		document.getElementById("signinClass").className = 'signin';
162
	} else	{
163
		document.getElementById("signinClass").className = 'signin1';
164
	}
165
}
166
 
2228 rajveer 167
 
1456 varun.gupt 168
function updateEstimate(itemId)	{
3830 chandransh 169
	itemId = itemId || $("#colorSelector option:selected").val();
1456 varun.gupt 170
 
171
	jQuery.ajax({
172
		type: "GET",
1919 rajveer 173
		url: "/estimate/" + $("#zipcode").val() + "_" + itemId,
1456 varun.gupt 174
		beforeSend: function()	{
5234 amit.gupta 175
			$("#shipping_time").show();
176
			$("#shipping_time_1").hide();
177
			$("#shipping_time .red").html("<img src='/images/loader_l.gif'> business days");
1456 varun.gupt 178
		},
179
		success: function(msg)	{
3830 chandransh 180
			var response = eval('(' + msg + ')');
181
			var deliveryEstimate = parseInt(response['delivery_estimate']);
182
			var isCODAvailableForLocation = (response['is_cod_available_for_location'] === 'true');
183
 
184
			if(deliveryEstimate == -1)	{
5234 amit.gupta 185
				$("#shipping_time").hide();
186
				$("#shipping_time_1").show();
3830 chandransh 187
			} else	{
5234 amit.gupta 188
				$("#shipping_time .red").html(deliveryEstimate + ' Business Days');
3830 chandransh 189
			}
190
 
4869 rajveer 191
			if (isCODAvailableForLocation)	{
3830 chandransh 192
				$('#cod').show();
193
			} else {
194
				$('#cod').hide();
195
			}
1456 varun.gupt 196
		}
197
	});
2228 rajveer 198
}
199
 
3406 rajveer 200
function load_most_compared_widget(){
201
	jQuery.ajax({
202
		type : "GET",
203
		url : "/most-compared-products/" + $("#product_id").val(),
204
		cache: false,
205
		success : function(html) {
206
   		    $("#mostcompared").html(html);
207
 
208
		    // Product Title
209
		    $("#mostcompared table td div a").each(function() {
210
					$(this).truncate({addtitle : true});
211
		    });
212
 
213
		    // Product Price
214
		    $("#mostcompared table td div div.price").each(function() {
215
					$(this).truncate({addtitle : true});
216
			});
217
 
218
		    // Product Details
219
		    $("#mostcompared table td div div.text").each(function() {
220
					$(this).truncate( {addtitle : true});
221
			});
222
	    }
223
	});
224
}