Subversion Repositories SmartDukaan

Rev

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