Subversion Repositories SmartDukaan

Rev

Rev 4489 | Rev 4869 | 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());
11
 
3830 chandransh 12
    updateEstimate(getSeletectedItemId());
1456 varun.gupt 13
 
1761 vikas 14
    var prodid = $("#product_id").val();
15
 
16
	add_to_storage_set("histitems", prodid);
17
 
1623 rajveer 18
    load_history_widget();
1761 vikas 19
 
2652 rajveer 20
    load_accessories_widget();
3406 rajveer 21
 
22
    load_most_compared_widget();
2754 rajveer 23
 
2731 varun.gupt 24
    myNotes.getNotes();
25
 
4489 varun.gupt 26
    // Fix to always show first image's title on page load
4530 mandeep.dh 27
    if ("undefined" != typeof(title_1)){
28
        $('.slides .modelName').html(title_1[0]);
29
    }
4489 varun.gupt 30
 
4530 mandeep.dh 31
 
3830 chandransh 32
    function getSeletectedItemId(){
33
    	 return $("#item_id").val();
34
    }
35
 
36
 
1922 varun.gupt 37
    /**
38
     * Code to track user clicks on Product slides and 'Proceed to Payment' option
39
     */
40
	$('a.vt').click(function(){
41
		trackEventWithGA('Product', $(this).children('span').text(), $('title').text().split('|')[0].trim());
42
	});
43
 
3830 chandransh 44
	$('#computeShippingEstimate').click(function(){
45
		updateEstimate(getSeletectedItemId());
46
	});
47
 
48
    $("#addToCart").click(function(){
2811 rajveer 49
    	jQuery.ajax({
1456 varun.gupt 50
			type: "POST",
1614 rajveer 51
			url: "/addtocart",
3830 chandransh 52
			data: "productid=" + getSeletectedItemId(),
1456 varun.gupt 53
			success: function(msg)	{
4530 mandeep.dh 54
	   			 if(msg == "") {
3830 chandransh 55
	   				 trackEventWithGA('Order', 'Add to Cart', getSeletectedItemId() + '');
2036 rajveer 56
					 window.location = "/cart";
4530 mandeep.dh 57
				 } else {
2810 rajveer 58
					 displayRelatedProducts(msg);
4530 mandeep.dh 59
				 }
2754 rajveer 60
	   		}
1456 varun.gupt 61
		});
62
	});
63
 
3830 chandransh 64
	$("#colorSelector").change(function(){
65
		var itemid = $("#colorSelector option:selected").val();
1456 varun.gupt 66
		$('#sp').html(PARAMETERS[itemid].SP);
67
		$('#mrp').html(PARAMETERS[itemid].MRP);
68
		$('#saving').html(PARAMETERS[itemid].SAVING);
69
		$("#item_id").val(itemid);
70
		updateEstimate(itemid);
71
		return false;
72
	});
73
 
3830 chandransh 74
/*	$("a.colorselector").click(function() {
1456 varun.gupt 75
		$('.a.colorselector').addClass('deselect');
76
		$(this).addClass('deselect');
1567 vikas 77
		var itemid = $(this).attr('itemid');
1456 varun.gupt 78
		$('#sp').html(" "+PARAMETERS[itemid].SP);
79
		$('#mrp').html(" "+PARAMETERS[itemid].MRP);
80
		$('#saving').html(PARAMETERS[itemid].SAVING);
81
		$("#item_id").val(itemid);
82
		return false;
3830 chandransh 83
	});*/
2228 rajveer 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
 
4395 rajveer 181
			if (isCODAvailableForLocation && parseInt($('#sp').html()) < 10000 && parseInt($('#sp').html()) > 100)	{
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
}