function showhideMenu(type) {
	if (type=='cats') {
		$('.left .cats').show();
		$('.left .labels').hide();
		$('.left .filtertype div').removeClass('active');
		$('.left .filtertype #catsbtn').addClass('active');
	} else if (type=='labels') {
		$('.left .cats').hide();
		$('.left .labels').show();
		$('.left .filtertype div').removeClass('active');
		$('.left .filtertype #labelsbtn').addClass('active');
	}
}

function changeAccount() {
    var answer = confirm('Weet u zeker dat u uw wachtwoord wilt wijzigen? Als u uw wachtwoord niet wilt wijzigen laat dan het veld bij wachtwoord leeg.');    
    return answer;  
}

function loadOrder(id) {
	id = id.split('_');
	$.ajax({
		type: "POST",
		url: "/services/loadOrder.php",
		data: "id="+id[1],
		success: function(msg){
			if (msg!='wrongOrder') {
				$('.small-col a').removeClass('orderlnkact');
				$(".small-col a").each(function(){this.onmouseup = this.blur();});
				$('#order_'+id[1]+'_'+id[2]).addClass('orderlnkact');
				$('.medium-col').html(msg);
				$('#center').html(id[2]);
			} else alert('Er is iets fout gegaan bij het ophalen van uw order. Weet u zeker dat u deze mag inzien?');
		}
	});
}

function loadFilter(id) {
	id = id.split('_');
	$.ajax({
		type: "POST",
		url: "/services/setSession.php",
		data: "val="+id[0]+'&type=filter',
		success: function(msg){
			if (msg=='goodValue') {
				$('.fastchoice div').removeClass('active');
				$('#'+id[0]+"_btn").addClass('active');
				$('.left #cats, .left #labels').hide();
				$('.left #'+id[0]).show();
			} else if (msg=='wrongValue') {
				$('.left #cats, .left #labels, .left #showcats').hide();
				$('.left #'+id[0]).show();
				$('.left #dontshowcats').show();
			}
		}
	});
}

function changeLblLetter(val) {
	$.ajax({
		type: "POST",
		url: "/services/setSession.php",
		data: "val="+val+'&type=labelLetter',
		success: function(msg){
			if (msg=='goodValue') window.location.href = '/shop/merken/'+val.toLowerCase();
		}
	});
}

function changeAmount(amount, id) {
	if (amount==''||!isInteger(amount)) alert('Voer een geldig aantal in.');
	else {
		id = id.split('_');
		$.ajax({
			type: "POST",
			url: "/services/changeAmount.php",
			data: "amount="+amount+'&id='+id,
			success: function(msg){
				if (msg=='goodValue') window.location.reload();
				else alert('Er is iets foutgegaan met het wijzigen. Probeer het nogmaals of neem contact met ons op.');
			}
		});
	}
}

function add2cart(amount,id,conttype) {
	if (amount==''||!isInteger(amount)) alert('Voer een geldig aantal in.');
	else {
		$.ajax({
			type: "POST",
			url: "/services/add2cart.php",
			data: "amount="+amount+'&id='+id,
			success: function(msg){
				msg = msg.split(';');
				if (msg[0]=='goodRequest') {
					if (msg[1]=='') $('#shopamount').html(parseInt($('#shopamount').html())+1);
					if (conttype=='continue') alert('Het artikel is toegevoegd aan uw winkelwagen.');
					else window.location.href='/winkelwagen';
				} else alert('Er is iets fout gegaan bij het toevoegen aan uw winkelwagen.\r\nProbeer het nogmaals of neem contact met ons op.');
			}
		});
	}
}

function delfromcart(id) {
	var answer = confirm('Dit artikel verwijderen uit uw winkelwagen?');
	if (answer) {
		$.ajax({
			type: "POST",
			url: "/services/delFromCart.php",
			data: 'id='+id,
			success: function(msg){
				if (msg=='goodRequest') window.location.reload();
				else alert('Er is iets fout gegaan bij het verwijderen uit uw winkelwagen.\r\nProbeer het nogmaals of neem contact met ons op.');
			}
		});
	}
}

function getCode() {
	if ($('input[name=coupon]').val()=='') alert('Voer een geldige actiecode in.');
	else {
		$.ajax({
			type: "POST",
			url: "/services/getCode.php",
			data: "val="+$('input[name=coupon]').val()+"&totalPrice="+$('input[name=totval]').val(),
			success: function(msg){
				if (msg=='goodRequest') window.location.reload();
				else {
					msg = msg.split(';');
					if (msg[1]=='toolow') alert('Deze actiecoupon is alleen te gebruiken bij een order totaal van 45 EURO.');
					else alert('De actie code kan niet worden gevonden of is niet meer geldig.');
				}
			}
		});
	}
}

function search() {
	var val = $('input[name=searchval]').val();
	if (val!=''&&val!='Zoek op artikel of merk') {
		$.ajax({
			type: "POST",
			url: "/services/setSearch.php",
			data: "val="+val,
			success: function(msg){
				if (msg=='goodValue') window.location.href = '/zoeken';
			}
		});
	} else alert('Geef een artikel of een merk op.');
}

function clearFld(btn,stand) {
	if (encodeURIComponent(btn.val())==encodeURIComponent(stand)) btn.val('');
}

function isInteger(s) {
  return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function checkFld(btn,stand) {
	if (btn.val()=='') btn.val(decodeURIComponent(stand));
}
