function alertSize() {
  myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
  return myHeight;
}

alertSize();

maxHeight = myHeight - 72;
maxWidth = myWidth - 63;

	
function show(obj) {
	var item = document.getElementById(obj);
	$(item).show("slow");
}
	
function hide(obj) {
	var item = document.getElementById(obj);
	$(item).hide("slow");
}

function toggle(obj) {
	var item = document.getElementById(obj);
	$(item).toggle("slow");
}

function fadeIn(obj) {
	var item = document.getElementById(obj);
	$(item).fadeIn("slow");
}

function fadeOut(obj) {
	var item = document.getElementById(obj);
	$(item).fadeOut("slow");
}

function fadeToggle(obj) {
	var item = document.getElementById(obj);
	
	if(item.style.display == 'block') {
		$(item).fadeOut("slow");
	}
	else {
		$(item).fadeIn("slow");
	}
}

function slideToggle(obj) {
	var item = document.getElementById(obj);
	$(item).slideToggle("slow");
}

	
//innerhtmlfunctie die dmv eval ook javascript uit zal voeren
function setAndExecute(divId, innerHTML)
		{
		   var div = document.getElementById(divId);
		   div.innerHTML = innerHTML;
		   var x = div.getElementsByTagName("script"); 
		   for(var i=0;i<x.length;i++)
		   {
		       eval(x[i].text);
		   }
		}	
	

		
function toonbeschikbaarheidlarge() {
	
	
   for (var i=0; i < document.kamerselector.kamerid.length; i++)
	   {
	   if (document.kamerselector.kamerid[i].checked)
	      {
	      		kamerid = document.kamerselector.kamerid[i].value;
	      }
	   }
	   
	$.ajax({
		type: "POST",
		url: "toonbeschikbaarheid.php",
		data: "kamerid=" + kamerid,
		success: function(response) {
			setAndExecute("calendar_content", response);
		}
	})
	
}
		

function addtocart(productID) {
	
	var changediv = "bestel" + productID;
	
	var besteldiv = "productbesteld" + productID;
	
	$.ajax({
		type: "POST",
		url: "cartfunctions.php",
		data: "productID=" + productID + "&action=addproduct",
		success: function(response) {
			hide(changediv);
			fadeIn(besteldiv);
			updatecart();
		}
	})
}


function removefromcart(productID) {
	
	$.ajax({
		type: "POST",
		url: "cartfunctions.php",
		data: "productID=" + productID + "&action=removefromcart",
		success: function(response) {
			setAndExecute("cart_container", response);
			updatecart();
		}
	})
}


function change_product_amount(productID) {
	
	var selectid = "changeaantal" + productID;	
	var aantal = document.getElementById(selectid).value;
	
	//alert(selectid);
	
	$.ajax({
		type: "POST",
		url: "cartfunctions.php",
		data: "productID=" + productID + "&aantal=" + aantal + "&action=updateamount",
		success: function(response) {
			setAndExecute("cart_container", response);
			updatecart();
		}
	})
	
}

function updatecart() {
	
	$.ajax({
		type: "POST",
		url: "cartfunctions.php",
		data: "action=updatecart",
		success: function(response) {
			setAndExecute("cart_content", response);
		}
	})
}


function swap_occ_pic(picID) {
	
	var picID = picID;
	
	$.ajax({
		type: "POST",
		url: "ajaxfunctions.php",
		data: "action=swapimage&picID=" + picID,
		success: function(response) {
			setAndExecute("occ_large_pic", response);
			
			$("#enlarge").addClass("thickbox");
			
			tb_init('a.thickbox, area.thickbox, input.thickbox');

		}
	})
}

function swap_occ_default(occID) {
	
	var occID = occID;
	
	$.ajax({
		type: "POST",
		url: "ajaxfunctions.php",
		data: "action=swapdefault&occID=" + occID,
		success: function(response) {
			setAndExecute("occ_large_pic", response);
			
			$("#enlarge").addClass("thickbox");
			
			tb_init('a.thickbox, area.thickbox, input.thickbox');
		}
	})
}



function submit_bestaand() {
	
	var email = document.getElementById('email_bestaand').value;
	var password = document.getElementById('password_bestaand').value;
	
	if(email == '' || password == '') {
		
		alert('Vul aub uw e-mailadres en wachtwoord in');
		
	}
	
	else {
		
		$.ajax({
			type: "POST",
			url: "ajaxfunctions.php",
			data: "action=checkbestaandeuser&email=" + email + "&password=" + password,
			success: function(response) {
				
				if(response == "1") {
					
					updatecart();
					document.form_bestaand.submit();
					
				}
				
				else {
					
					alert('Klant niet gevonden. Controleer uw e-mailadres en wachtwoord.');
					
				}
				
			}
			
		});
		
	}
	
}


function submit_nieuw() {
	
	var voorletters = document.getElementById('voorletters').value;
	var achternaam = document.getElementById('achternaam').value;
	var adres = document.getElementById('adres').value;
	var postcode1 = document.getElementById('postcode1').value;
	var postcode2 = document.getElementById('postcode2').value;
	var plaats = document.getElementById('plaats').value;
	var telefoon = document.getElementById('telefoon').value;
	var email = document.getElementById('email_nieuw').value;
	var chassis = document.getElementById('chassis').value;
	
	if(email == '' || voorletters == '' || achternaam == '' || adres == '' || postcode1 == '' || postcode2 == '' || plaats == '' || email == '') {
		
		alert('U heeft niet alle verplichte velden ingevuld');
		
	}
	
	else {
		
		$.ajax({
			type: "POST",
			url: "ajaxfunctions.php",
			data: "action=nieuweuser&email=" + email + "&voorletters=" + voorletters + "&achternaam=" + achternaam + "&adres=" + adres + "&postcode1=" + postcode1 + "&postcode2=" + postcode2 + "&plaats=" + plaats + "&telefoon=" + telefoon + "&chassis=" + chassis,
			success: function(response) {
				
				if(response == "1") {
					
					updatecart();
					document.form_bestaand.submit();
					
				}
				
				else {
					
					alert('Er bestaat al een klant met dit e-mailadres.');
					
				}
				
			}
			
		});
		
	}
	
}




function check_gegevens() {
	
	var voorletters = document.getElementById('voorletters').value;
	var achternaam = document.getElementById('achternaam').value;
	var adres = document.getElementById('adres').value;
	var postcode1 = document.getElementById('postcode1').value;
	var postcode2 = document.getElementById('postcode2').value;
	var plaats = document.getElementById('plaats').value;
	var telefoon = document.getElementById('telefoon').value;
	var email = document.getElementById('email_check').value;
	var chassis = document.getElementById('chassis').value;
	
	if(email == '' || voorletters == '' || achternaam == '' || adres == '' || postcode1 == '' || postcode2 == '' || plaats == '' || email == '') {
		
		alert('U heeft niet alle verplichte velden ingevuld');
		
	}
	
	else {
		
		$.ajax({
			type: "POST",
			url: "ajaxfunctions.php",
			data: "action=updateuser&email=" + email + "&voorletters=" + voorletters + "&achternaam=" + achternaam + "&adres=" + adres + "&postcode1=" + postcode1 + "&postcode2=" + postcode2 + "&plaats=" + plaats + "&telefoon=" + telefoon + "&chassis=" + chassis,
			success: function(response) {
				
				if(response == "1") {
					
					updatecart();
					document.checkgegevens.submit();
					
				}
				
				else {
					
					alert('Er bestaat al een klant met dit e-mailadres.');
					
				}
				
			}
			
		});
		
	}
	
}


function set_verzenden() {
	
	var ver_afh = $("input[@name='ver_afh']:checked").val();
	
	if(typeof(ver_afh)=="undefined") {
		
		alert('Geef aub aan of u de bestelling wil laten verzend of wil afhalen');
		
	}
	
	else {
		
		$.ajax({
			type: "POST",
			url: "ajaxfunctions.php",
			data: "action=set_verzenden&ver_afh=" + ver_afh,
			success: function() {
				updatecart();
				document.verzenden_afhalen.submit();
			}
		})
	}
	
}



