
var Buy = {
	
	init: function() {
		$('#firma').click(function() {
			$('.personal').hide();
			$('.company').show();
		});
		$('#eraisik').click(function() {
			$('.personal').show();
			$('.company').hide();
		});
	},
	
	drawLicences: function (element) {
		if (element.value != undefined) {
			element = element.value;
		}
		var from = 0;
		var to = 0;
		if (element <= 2) {
			from = 1;
			to = 5;
		} else if (element <= 4) {
			from = 5;
			to = 100;
		} else if (element <= 5) {
			from = 101;
			to = 999;
		} else if (element <= 7) {
			from = 5;
			to = 999;
		}
		var html = '<option value="0">-Vali-</option>';
		for (i = from; i <= to; i++) {
			html += '<option value="' + i + '">' + i + ' arvutit</option>';
		}
		$('#licences').html(html);
		$('#computers-' + element).html(html);
	},
	
	calculate: function (id) {
		var licences = $('#computers-' + id).val();
		var years = $('#years-' + id).val();
		var productname = $('#productname-' + id).val();
		$.ajax({
			  url: '?act=buy&action=calculate&licencetime=' + years + '&licences=' + licences + '&productname=' + productname,
			  success: function(data) {
			    $('#sum-' + id).html(data);
			  }
			});
	},
	
	calculate2: function () {
		var licences = $('#licences').val();
		var years = $('#licencetime').val();
		var productname = $('#productname').val();
		$.ajax({
			  url: '?act=buy&action=calculate&renew=1&licencetime=' + years + '&licences=' + licences + '&productname=' + productname,
			  success: function(data) {
				$('#price').html(data);
			  }
			});
	}
};

$(document).ready(function(){
	Buy.init();

});

