﻿
var debitorcurrency = "";

function FilterNumberKeys(oInput, e, allowdecimals) {
    var ev = RLdesign.Utils.DefineEvent(e);
    var charcode = RLdesign.Utils.DefineEventKeyCode(e);
    var whitelist = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 144];
    if (allowdecimals) {
        whitelist[whitelist.length] = 110;
        whitelist[whitelist.length] = 188;
        whitelist[whitelist.length] = 190;
    }
    if (ev.ctrlKey && charcode == 65) return true; // ctrl+a
    else if (ev.ctrlKey && charcode == 67) return true; // ctrl+c
    else if (ev.ctrlKey && charcode == 86) return true; // ctrl+v
    else if (ev.ctrlKey && charcode == 88) return true; // ctrl+x
    else if (ev.ctrlKey && charcode == 90) return true; // ctrl+z
    else if (RLdesign.Arrays.InArray(whitelist, charcode)) return true;
    else return false;
}

function calctotal() {
	var total = 0;
	$(".fusiontable input:text").each(function (i, o) {
		var amount = 0;
		amount = parseInt($(o).val());
		if (amount != null && amount != "" && amount > 0) {
			var price = parseFloat($(o).closest("td").find('input[name="price"]').val().replace(";", "."));
			var price = price * amount;
			total += price;
		}
	});

	$(".fusiontable tr").each(function (i, o) {
		var tr = $(o);
		var price = 0;
		var amount = 0;
		var rowprice = 0;
		tr.find('input[name="amount"]').each(function (i1, o2) {
			amount = parseInt($(o2).val());
			if (amount != null && amount != "" && amount > 0) {
				price = parseFloat($(o2).closest("td").find('input[name="price"]').val().replace(";", "."));
				price = price * amount;
				rowprice += price;
			}
		});
		$(o).find("span.rowprice").html(rowprice + " " + debitorcurrency);

	});

	$("#totalpricediv span").html(total);
}


function ordercartitemsave(account, itemnumber, amount) {
	var qty = amount;
	if (isNaN(qty) == true) {
		qty = -1;
	}
	$.ajax({
		url: "../cms_files/plugins/fusion/dealerlogin/AjaxPage.ashx",
		dataType: "json",
		type: "GET",
		data: { job: "ordercartsaveitem", account: account, itemnumber: itemnumber, amount: qty },
		success: function (JSON) {
			if (JSON[0] == true) {
				//alert(JSON[1]);
			}
			else {
				//alert(JSON[1]);
			}
		},
		error: function (s, ss, sss) {
			alert(s);
			alert(ss);
			alert(sss);
		}
	});
}
