function updateList(form_name) {
	$.post('/functions/update_list.php', 
	$('#'+form_name).serialize()+'&form='+form_name, function(data) { if (data) { eval(data); } });
}

function refreshList() {
	$.post('/functions/refresh_list.php', function(data) { if (data) { $("#order_list").html(data); updateList('order'); /* Opdaterer bl.a. total når varelisten er loaded */ } });
}

function placeOrder(form_name, loc) {
	$.post('/functions/check_list.php', 
	$('#'+form_name).serialize()+'&form='+form_name+"&location="+loc, function(data) { if (data) { eval(data); } });	
}

function addNewItem(e) {
	var code = e.keyCode || e.which;
	if (code == '13') {
		$.post('/functions/add_item.php', 
		$('#order').serialize()+'&n=0&form=order&mode=advanced', function(data) { if (data) { eval(data); } });
		document.getElementById("error_0").innerHTML = "";
	}
}

function clearAddItem() {
	$("#code_0").val("");
	$("#name_0").html("&nbsp;");
	$("#parameters_0").html("&nbsp;");
	$("#hidden_0").html("");
	$("#add_0").html("&nbsp;");
	$("#price_0").html("-");
	$("#sum_0").html("-");
	$("#position_0").val("");
	$("#quantity_0").val("1");
	
	$("#code_0").focus();
	
}

$(document).ready(function() {
	$("#code_0").focus();
	
	$("#code_0").keyup(function(e) {
		if ($(this).val() != '') {
			$("#parameters_0").html('<img src="/images/loader.gif" width="20" height="20" border="0" style="margin-top: 13px;" />');	
		} else {
			$("#parameters_0").html('');	
		}
		var code = e.keyCode || e.which;
		if (code != '9') { // Alt undtagen tab
			//$.post('/functions/check_if_item.php', $("#order").serialize(), function(data) { if (data) { eval(data); } });
			$("#name_0").load('/functions/check_if_item.php #name', { 'code_0': $('#code_0').val() });
			$("#parameters_0").load('/functions/check_if_item.php #parameters', { 'code_0': $('#code_0').val() });
			$("#hidden_0").load('/functions/check_if_item.php #hidden', { 'code_0': $('#code_0').val() });
			$("#add_0").load('/functions/check_if_item.php #add', { 'code_0': $('#code_0').val() });
		}
	});
});
