function searchBooks(){
	var query = document.getElementById("query").value;
	if(query.length == ""){
		alert("Vul een zoekterm in. U kunt zoeken op titel en isbn.");
	}else{
		load("zoeken/" + query);
	}
}

function callMe(){
	$.post("callme.php", $("#callmeform").serialize(), function(data){
		if(data!=""){
			alert(data);
		}else{
			alert("Uw gegevens zijn ontvangen. U wordt z.s.m. teruggebeld.");
			load("start.html");
		}
	});
}

var name = "";
var email = "";
var oldTitle = "";
function subscribe(){
	if(email == ""){
		email = document.getElementById("newsletter").value;
		document.getElementById("newsletter").value = '';
		oldTitle = $("#titleSubscribe").html();
		$("#titleSubscribe").html("Vul uw naam in");
		return;
	}else{
		name = document.getElementById("newsletter").value;
		if(name == ""){
			alert("U bent niet aangemeld. Vul uw naam in om aan te melden voor de RoFo nieuwsbrief.");
			return;
		}
		$.get("subscribe.php?email=" + email + "&name=" + name, function(data) {
			if(data!=""){
				alert(data);
			}else{
				$("#titleSubscribe").html(oldTitle);
				document.getElementById("newsletter").value='';
				alert("U bent aangemeld voor de RoFo nieuwsbrief.");
			}
		});
	}
}

function load(url){
	window.location.href= ROOT + url;
}

function init(){
	$("#main").height(getInnerHeight() - getY(document.getElementById("main")) );
}

function addItem(isbn){
	$.get('shoppingbasket.php?add=' + isbn, function(data) {
		load("winkelmandje.html");
	});
}

function removeItem(isbn, title){
	if(confirm("Weet u zeker dat u '" + title + "' uit het winkelmandje wilt halen?")){
		$.get('shoppingbasket.php?remove=' + isbn, function(data) {
			load("winkelmandje.html");
		});
	}
}

function updateItem(isbn, quantity){
	$.get('shoppingbasket.php?update=' + isbn + "&quantity=" + quantity, function(data) {
		load("winkelmandje.html");
	});
}

function saveType(){
	var type = $("input[@name='type']:checked").val();
	if(!type){
		alert("Selecteer de beschrijving die bij u past.");
	}else{
		$.get("ordermanager.php?type=" + type, function(data) {
			if(data!=""){
				alert(data);
			}else{
				load("bestellen/stap2.html");
			}
		});
	}
}

function validateCustomer(){
	$.post("ordermanager.php?customer", $("#customerform").serialize(), function(data){
		if(data!=""){
			alert(data);
		}else{
			load("bestellen/stap3.html");
		}
	});
}

function confirmPaymentMethod(){
	var type = $("input[@name='payment']:checked").val();
	if(!type){
		alert("Selecteer een betaalmethode.");
	}else{
		$.get("ordermanager.php?payment=" + type, function(data) {
			if(data!=""){
				alert(data);
			}else{
				load("bestellen/stap4.html");
			}
		});
	}
}

function confirmOrder(){
	$.post("ordermanager.php?accept", $("#acceptform").serialize(), function(data){
		if(data!=""){
			alert(data);
		}else{
			load("bestellen/afgerond.html");
		}
	});
}

function toggle(id, show){
	if(show){
		$('#' + id).show();
	}else{
		$('#' + id).hide();
	}
}

function getY( oElement ){
	var iReturnValue = 0;
	while( oElement != null ) {
		iReturnValue += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return iReturnValue;
}

function getInnerHeight() {
	  var myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myHeight = window.innerHeight;
	  } else{
	    //IE 6+ in 'standards compliant mode'
	    myHeight = document.documentElement.clientHeight;
	  }
	  return myHeight;
}
