Subversion Repositories SmartDukaan

Rev

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