Subversion Repositories SmartDukaan

Rev

Rev 1463 | Rev 2696 | 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
 
1463 varun.gupt 5
	changeEstimate();
1190 varun.gupt 6
 
1463 varun.gupt 7
	$('#cartTable td img.remove-quantitybttn').click(function(){
8
		var prodID = $(this).parent().parent().parent().children().find("span.pro").attr("id");
9
		window.location.href = "/cart/"  + prodID + "?_method=delete" + "&productid=" + prodID;
10
	});
1981 varun.gupt 11
 
12
	$('#applyCoupon').click(function(){
13
		$('#couponAction').val('applycoupon');
14
		$('#frmCouponCode').submit();
15
	});
16
 
17
	$('#removeCoupon').click(function(){
18
		$('#couponAction').val('removecoupon');
19
		$('#frmCouponCode').submit();
20
	});
1463 varun.gupt 21
});
22
 
1190 varun.gupt 23
function changeQty(obj,itempriceID,totalPriceID)	{
24
	var prodID = $(obj).parent().parent().parent().parent().parent().parent().children().find("span.pro").attr("id");
25
	var quantity = parseInt(obj.value);
26
 
1460 varun.gupt 27
	if (quantity > 5)	{
28
		alert("You can not order more than 5 pieces of same product.");
29
		$(obj).focus();
30
	}
31
	else	{
32
		jQuery.ajax({
33
			type: "POST",
34
			url: "/cart/" + prodID + "?_method=put&productid=" + prodID + "&quantity=" + quantity,
35
			data: "productid=" + prodID + "&quantity=" + quantity,
36
			success: function(msg){
37
				window.location.reload();
38
			}
39
		});
40
	}
794 rajveer 41
}
42
 
1463 varun.gupt 43
function sumOfColumns(tableID, columnIndex, hasHeader)	{
44
	var tot = 0;
45
	var inc = 1;
46
	var tableElement = $("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : ""));
47
	var tableChildren = tableElement.children("td:nth-child(" + columnIndex + ")");
48
 
49
	tableChildren.each(function() {
50
		var currentVal = document.getElementById('totalPrice' + inc).innerHTML;
51
		inc ++;
52
		var splitVal = currentVal.split("Rs.");
53
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
54
		tot += parseFloat(num);
55
	});
56
	totalAmount = tot;
57
	var formated_value = $().number_format(tot, {
58
		numberOfDecimals:2,
59
		decimalSeparator: '.',
60
		thousandSeparator: ',',
61
		symbol: 'Rs.'
62
	});
63
	return formated_value;
794 rajveer 64
}
65
 
66
function subtractionOfColumns(tableID, columnIndex, hasHeader) {
1463 varun.gupt 67
	var tot = 0;
68
 
69
	$("#" + tableID + " tr" + (hasHeader ? ":gt(0)" : "")).children("td:nth-child(" + columnIndex + ")").each(function(){
70
		var currentVal=$(this).html();
71
		var splitVal=currentVal.split("Rs.");
72
		var num = parseFloat(splitVal[1].replace(/[^\d\.-]/g,''));
73
		tot += parseInt(num);
74
	});
75
 
76
	var formated_value = $().number_format(tot, {
77
		numberOfDecimals: 2,
78
		decimalSeparator: '.',
79
		thousandSeparator: ',',
80
		symbol: 'Rs.'
81
	});
82
	return formated_value;
794 rajveer 83
}
84
 
1463 varun.gupt 85
function changeEstimate(item_id)	{
86
	if(item_id == null )	{
87
		for(var i = 0; ; i ++)	{
88
			var obj = $("#itemID" + (i + 1));
89
			var itemId = $(obj).parent().parent().find("span.pro").attr("id");
90
			if(itemId == null)	{
91
				break;
92
			}
93
			changeEstimate(itemId);
94
		}
95
	} else	{
96
		jQuery.ajax({
97
			type: "GET",
98
			url: "/estimate/" + $("#zipcode").val() + "_" + item_id,
99
			beforeSend: function(){
100
				$("#days" + "_" + item_id).html("<img src='/images/loader_l.gif'>");
101
			},
102
			success: function(msg){
103
				$("#shipping_time" + "_" + item_id).html(msg);
104
			}
105
		});
106
	}
107
}