Subversion Repositories SmartDukaan

Rev

Rev 5614 | Rev 5747 | 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
 
5716 anupam.sin 102
	function checkIfUserHasAddress(){
3830 chandransh 103
		var addressEmpty = parseInt($('#addressEmpty').val());
104
 
105
		if (addressEmpty == 1)	{
106
			showAddAddressForm();
107
		}
1460 varun.gupt 108
	}
3830 chandransh 109
 
110
	function showAddAddressForm(){
5716 anupam.sin 111
		//$('#main-right-container').hide();
112
		$('#shipping-address-div').hide();
113
		$('#billing-address-div').hide();
3830 chandransh 114
		$('#frmShippingAddress').show();
115
	}
116
 
117
	function showAddressList()	{
118
		$('#frmShippingAddress').hide();
5716 anupam.sin 119
		//$('#main-right-container').show();
120
		$('#shipping-address-div').show();
121
		$('#billing-address-div').show();
3830 chandransh 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
}