Subversion Repositories SmartDukaan

Rev

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