Subversion Repositories SmartDukaan

Rev

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