var _lastq = 100;

function _corp() {
	$("#companyRow").show();
	$("#kvkRow").show();
	_lv["Company"].enable();
	$("input[id$='hidType']").val($("input[id$='TypeCorp']").val());
}
function _priv() {
	$("#companyRow").hide();
	$("#kvkRow").hide();
	_lv["Company"].disable();
	$("input[id$='hidType']").val($("input[id$='TypePriv']").val());
}
function _show(elm) {
	$(elm).css({visibility:"visible", height:"auto"});
}
function _search(tag) {
	var query = location.search;
	if (query && query.indexOf("+" + tag) >= 0)
		query = query.replace("+" + tag, "");
	else
		query += ((query ? "+" : "?") + tag);
	location.href = location.pathname + query;
}
function _quant(e) {
	if (e == undefined || e.keyCode==13) {
		var q = document.getElementById("aantalStuksText").value;
		var pos = location.href.indexOf("?");
		location.href = location.href.substring(0, pos) + "?" + q;
	}
}
function _checkquant() {
	var q = 0;
	$(".numberField").each(function(i,e) {
		var i = parseInt($(e).val());
		q += isNaN(i) ? 0 : i;
	});
	if (q == 0)
		alert("U heeft nog geen aantallen ingevuld");
	return q != 0;
}
function _checkcol(v) {
	$("input:radio[name=kleuren][value=" + v + "]").attr("checked", true);
	_show("#plaats");
}
function _checkpos(v) {
	$("input:radio[name=bedrukking][value=" + v + "]").attr("checked", true)
	doPostBack('registration','register',null);
}
function _getprice() {
	var q = 0;
	$(".numberField").each(function(i,e) {
		var i = parseInt($(e).val());
		q += isNaN(i) ? 0 : i;
	});
	q = q || 100;
	if (q != _lastq) {
		$.ajax({
			url: "/getprice.aspx",
			data: {"p": product, "q": q},
			success: function(data, status, request) {
				var prices = eval(data);
				$("#imagePriceLabel").html("&euro;" + prices[0] + " bij " + q + " stuks");
				$("div.prijs").each(function(i, e) {
					$(e).html("&euro;" + prices[i + 1]);
				});
				$("span#quantityLabel").html(q);
				_lastq = q;
			}
		});
	}
}
function _setquantity() {
	var q = [];
	$(".quantityField").each(function(i,e) {
		var i = parseInt($(e).val());
		if (isNaN(i) || i < 1) {
			i = 1;
			$(e).val("1");
		}
		q.push(i);
	});
	$.ajax({
		url: "/setquantity.aspx",
		data: {"q": q.join(",")},
		success: function(data, status, request) {
			eval("x=" + data);
			$("table#product-table td.price").html("&euro;" + x.p[0]);
			$("table#product-table td.prices").each(function(i, e) {
				$(e).html("&euro;" + x.p[i + 1]);
			});
			$("table#print-table td.price").html("&euro;" + x.n[0]);
			$("table#print-table td.prices").each(function(i, e) {
				$(e).html("&euro;" + x.n[i + 1]);
			});
			$("div.prijs").each(function(i, e) {
				$(e).html("&euro;" + x.c[i + 1]);
			});
			$("span#quantityLabel").html(x.z);
		}
	});
}

$(document).ready(function() {
	$(".numberField").blur(function() {
		_getprice();
	});
	$(".quantityField").blur(function() {
		_setquantity();
	});
	$("a.iframe").fancybox({
		width: 600, height: 350, scrolling: "no"
	});
});

