Subversion Repositories SmartDukaan

Rev

Rev 5572 | Rev 5607 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1463 varun.gupt 1
var totalAmount = 0.00;
2
 
794 rajveer 3
$(document).ready(function(){
801 rajveer 4
 
3830 chandransh 5
	checkIfUserHasAddress();
6
 
4453 varun.gupt 7
	$('#checkout').click(function(){
3830 chandransh 8
		window.location.href = "/shipping";
9
	});
10
 
4453 varun.gupt 11
	$('#poplogin').click(function(){
4222 varun.gupt 12
		$.colorbox({
13
    		width: "860px",
4458 varun.gupt 14
    		height: "340px",
4222 varun.gupt 15
    		iframe: false,
16
    		href: "/login-mini",
17
 
18
    		onComplete: function(){
4372 varun.gupt 19
    			trackEventWithGA('Cart', 'Login/Register Popup', '');
4222 varun.gupt 20
    		}
21
    	});
22
	});
23
 
3830 chandransh 24
	$('#proceedToPay').click(function(){
4222 varun.gupt 25
		var canProceedToPay = parseInt($('#canProceedToPay').val());
3830 chandransh 26
 
27
		if (canProceedToPay == 1)	{
28
 
29
			trackProceedToPay();
30
			$('#formProceedToPay').submit();
31
		} else	{
5040 varun.gupt 32
			var reasonActionDisability = $('#reasonActionDisability').val();
3830 chandransh 33
 
5040 varun.gupt 34
			if(reasonActionDisability.indexOf('Location not serviceable') >= 0)	{
35
				trackEventWithGA('Cart', 'Location not serviceable', $('#selectedPincode').val());
36
			}
37
			alert(reasonActionDisability);
3830 chandransh 38
		}
39
	});
4791 varun.gupt 40
 
41
	$('#viewOrders').click(function(){
42
		window.location.href = "/myaccount";
43
	});
1190 varun.gupt 44
 
3830 chandransh 45
	$('#cart .remove-quantitybttn').click(function(){
46
		var itemId = $(this).attr('id').split('_')[1];
47
		window.location.href = "/cart/"  + itemId + "?_method=delete" + "&productid=" + itemId;
1463 varun.gupt 48
	});
1981 varun.gupt 49
 
3830 chandransh 50
	$('#computeEstimate').click(function(){
51
		changeEstimate();
3941 varun.gupt 52
		$('#cartDetail').find('thead .dev-pincode').html($('#zipcode').val());
3830 chandransh 53
	});
54
 
1981 varun.gupt 55
	$('#applyCoupon').click(function(){
56
		$('#couponAction').val('applycoupon');
57
		$('#frmCouponCode').submit();
58
	});
59
 
60
	$('#removeCoupon').click(function(){
61
		$('#couponAction').val('removecoupon');
62
		$('#frmCouponCode').submit();
63
	});
3830 chandransh 64
 
65
	$('.cart-item-quantity').change(function(){
66
		var itemId = $(this).attr("id").split('_')[1];
67
		var quantity = parseInt($(this).val());
68
 
69
		if (quantity > 5)	{
70
			alert("You can not order more than 5 pieces of same product.");
71
			$(obj).focus();
72
		}
73
		else	{
74
			jQuery.ajax({
75
				type: "POST",
76
				url: "/cart/" + itemId + "?_method=put&productid=" + itemId + "&quantity=" + quantity,
77
				data: "productid=" + itemId + "&quantity=" + quantity,
78
				success: function(msg){
79
					window.location.reload();
80
				}
81
			});
82
		}
83
	});
84
 
85
	$('#submitAddress').click(function(){
86
		$('#frmShippingAddress').submit();
87
	});
88
 
4325 mandeep.dh 89
	$('#addAddress').live('click', function(){
3830 chandransh 90
		showAddAddressForm();
91
	});
4325 mandeep.dh 92
 
93
	$('#closeAddAddressForm').live('click', function() {
3830 chandransh 94
		showAddressList();
95
	});
96
 
97
	$('#addresses .button-address-select').click(function(){
98
		var addressId = $(this).attr('id').split('_')[1];
99
		$('#formChangeAddressTo_' + addressId).submit();
100
	});
101
 
5572 anupam.sin 102
	$('.shipping-page-addresses .delete-address').click(function(){
3830 chandransh 103
		var addressId = $(this).attr('id').split('_')[1];
104
 
1460 varun.gupt 105
		jQuery.ajax({
106
			type: "POST",
3830 chandransh 107
			url: "/address",
108
			data: "action=delete&addressid=" + addressId,
1460 varun.gupt 109
			success: function(msg){
110
				window.location.reload();
111
			}
112
		});
3830 chandransh 113
	});
114
 
5594 anupam.sin 115
	function checkIfUserHasAddress(){
3830 chandransh 116
		var addressEmpty = parseInt($('#addressEmpty').val());
117
 
118
		if (addressEmpty == 1)	{
119
			showAddAddressForm();
120
		}
1460 varun.gupt 121
	}
3830 chandransh 122
 
123
	function showAddAddressForm(){
5594 anupam.sin 124
		//$('#main-right-container').hide();
125
		$('#shipping-address-div').hide();
126
		$('#billing-address-div').hide();
3830 chandransh 127
		$('#frmShippingAddress').show();
128
	}
129
 
130
	function showAddressList()	{
131
		$('#frmShippingAddress').hide();
5594 anupam.sin 132
		//$('#main-right-container').show();
133
		$('#shipping-address-div').show();
134
		$('#billing-address-div').show();
3830 chandransh 135
	}
136
});
794 rajveer 137
 
1463 varun.gupt 138
function sumOfColumns(tableID, columnIndex, hasHeader)	{
139
	var tot = 0;
140
	var inc = 1;
141
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
142
	var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
143
 
144
	tableChildren.each(function() {
145
		var currentVal = document.getElementById('totalPrice' + inc).innerHTML;
146
		inc ++;
147
		var splitVal = currentVal.split("Rs.");
148
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
149
		tot += parseFloat(num);
150
	});
151
	totalAmount = tot;
152
	var formated_value = $().number_format(tot, {
153
		numberOfDecimals:2,
154
		decimalSeparator: '.',
155
		thousandSeparator: ',',
156
		symbol: 'Rs.'
157
	});
158
	return formated_value;
794 rajveer 159
}
160
 
161
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
1463 varun.gupt 162
	var tot = 0;
163
 
164
	$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : "")).children("td:nth-child(" + columnIndex + ")").each(function(){
165
		var currentVal=$(this).html();
166
		var splitVal=currentVal.split("Rs.");
167
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
168
		tot += parseInt(num);
169
	});
170
 
171
	var formated_value = $().number_format(tot, {
172
		numberOfDecimals: 2,
173
		decimalSeparator: '.',
174
		thousandSeparator: ',',
175
		symbol: 'Rs.'
176
	});
177
	return formated_value;
794 rajveer 178
}
179
 
1463 varun.gupt 180
function changeEstimate(item_id)	{
181
	if(item_id == null )	{
3830 chandransh 182
		$("#cartDetail tbody tr").each(function(index, item){
183
			var itemId = $(item).attr("id");
1463 varun.gupt 184
			changeEstimate(itemId);
3830 chandransh 185
		});
186
 
1463 varun.gupt 187
	} else	{
188
		jQuery.ajax({
189
			type: "GET",
190
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
191
			beforeSend: function(){
192
				$("#days" + "_" + item_id).html("<img src='/images/loader_l.gif'>");
3830 chandransh 193
				$("#shipping_time_" + item_id).html('<img src="/images/loader_l.gif">');
1463 varun.gupt 194
			},
3830 chandransh 195
			success: function(data){
196
				var response = eval('(' + data + ')');
197
				var deliveryEstimate = parseInt(response['delivery_estimate']);
198
 
199
				if(deliveryEstimate == -1)	{
200
					$("#shipping_time_" + item_id).html('Location is not serviceable');
201
 
202
				} else if(deliveryEstimate == 1)	{
203
					$("#shipping_time" + "_" + item_id).html('FREE DELIVERY in 1 Business Day');
204
				}
205
				else	{
206
					$("#shipping_time" + "_" + item_id).html('FREE DELIVERY in ' + deliveryEstimate + ' Business Days');
207
				}
1463 varun.gupt 208
			}
209
		});
210
	}
211
}