Subversion Repositories SmartDukaan

Rev

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