
//Webshop item toevoegen aan winkelwagen
function addWesbhopItem(itemID){
		
	var url='shoppingcart.php?action=1&id='+itemID;
	
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {						
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
		
			var target = document.getElementById('shoppingcart');
			target.innerHTML = '('+xmlhttp.responseText+')<img src="images/shoppingcart_menu_hover.gif" width="15" height="16" />Winkelwagen / Afrekenen';
			
			alert('Artikel is toegevoegd aan uw winkelwagen.');
			
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

}

function updateWebshopItem(amountObject, itemID){

	amountObject.disabled = true;
	
	var currentAmount = amountObject.getAttribute("currentamount");
	var newAmount = amountObject.value	
	
	if(currentAmount != newAmount){
	
		var price = amountObject.getAttribute("price");
		
		var price_subtotal_old = currentAmount*price;
		var price_subtotal_new = newAmount*price;
		
		//money_format('%.2n',price_subtotal_old);
		
		var url='shoppingcart.php?action=2&id='+itemID+'&new_value='+newAmount;
		
		if (window.XMLHttpRequest) {
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		} else {						
			// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				
				//Update nieuw aantal stuks
				amountObject.setAttribute("currentamount",newAmount);
				
				//Update nieuwe subtotaalprijs van het artikel
				var target = document.getElementById('productID_'+itemID);						
				target.innerHTML = '<strong>&euro; '+money_format(price_subtotal_new)+'</strong>';
				
				//Update nieuwe subtotaalprijs
				var subtotalPrice = document.getElementById('subtotalPrice');
				
				var currentSUB = subtotalPrice.getAttribute("currentValue");
				var newSUB = (currentSUB*1.19) - price_subtotal_old + price_subtotal_new;
				
				/*alert(currentSUB); 
				alert(price_subtotal_old);
				alert(price_subtotal_new);
				*/
				//alert(newSUB); 
				
				
				var newBTW = Math.round((newSUB/119)*19);
				//alert(newBTW);
				var newTOT = Math.round(newSUB);
				newSUB = newTOT-newBTW;
				
				subtotalPrice.setAttribute("currentValue", newSUB);
				
				subtotalPrice.innerHTML = '<span>Subtotaal</span>&euro; '+money_format(newSUB);
				
				//Update nieuwe btw
				var btw = document.getElementById('btw');
				btw.innerHTML = '<span>BTW (19%)</span>&euro; '+money_format(newBTW);
				//Update nieuwe totaalprijs
				var totalPrice = document.getElementById('totalPrice');
				totalPrice.innerHTML = '<span>Totaal</span>&euro; '+money_format(newTOT);
				
				amountObject.disabled = false;						
				
			}
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);

	}else{
		
		amountObject.disabled = false;
	
	}

}

//Webshop item toevoegen aan winkelwagen
function deleteWebshopItem(itemID){
	
	if(confirm('Weet u zeker dat u dit artikel uit uw winkelwagen wilt verwijderen?')){
	
		var url='shoppingcart.php?action=3&id='+itemID;
		
		if (window.XMLHttpRequest) {
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		} else {						
			// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
			
				//var target = document.getElementById('shoppingcart');
				//target.innerHTML = '('+xmlhttp.responseText+')<img src="images/shoppingcart_menu_hover.gif" width="15" height="16" />Winkelwagen / Afrekenen';
				location.href = "?PID=5";
				//alert(xmlhttp.responseText);
				
			}
		}
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);

	}

}

function money_format(amount) {

	total = String(amount);
	
	format_total = '';
	offset = total.length;
	
	//Centen
	cents = ','+total.substr((offset-2), 2);
	
	total = total.substr(0, offset-2);
	offset = total.length;
	
	if (total.length > 3) {
		for (var i = 0; i < total.length; i += 3) {
			if ((offset -3) > 0) {
				format_total =  "."  + total.substr((offset-3), 3)  + format_total;
				offset -= 3;
			}
		}
 
		format_total = total.substr(0, offset)  +  format_total;
		total = format_total;
	}
 
	return total+cents;
}

function onKeyPressNumeric(evt) {

	var oEvent = (window.event) ? window.event : evt;

	var key = 0;
	if (document.all)
		key = oEvent.keyCode;
	else
		key = oEvent.which;

	blnValidChar = true;

	if (key==8 || (key>=48 && key<=57) || key==0)
		blnValidChar=false;
			
	if(blnValidChar) {			
		oEvent.returnValue = false;	
		if (oEvent.cancelable)
			oEvent.preventDefault();
	}
}

function submitForm(formID){

	var ref_form = document.getElementById(formID);

	ref_form.submit();

}

var slideShows = [];

function run_script(){
	
	var elements = getElementsByClassName("slides",document.getElementById("projecten"));
	
	//alert(elements.length);
		
	for(var i=0; i<elements.length; i++){
		
		slideShows.push(new SlideShow(elements[i],elements[i].getAttribute("imgwidth"),elements[i].getAttribute("imgheight"),elements[i].getAttribute("type")));
		
	}
	
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
function kill(){
	
	var light=document.getElementById("light");
	var fade=document.getElementById("fade");
	
	fade.style.display="none";
	light.style.display="none";
	
}
function popup(productID){
	
	var url = 'product.php?productID='+productID;
	
	var xmlhttp = null;
					
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else {						
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			document.getElementById('lightcontent').innerHTML = xmlhttp.responseText;
			
			//De website begint met de header;
			var header= document.getElementById('header');
			var headerHeight = header.offsetHeight;
			//Vervolgens moet de hoogte van de container opgevraagd worden/
			var container= document.getElementById('container');
			var containerHeight = container.offsetHeight;
			
			//Overig
			var padding = 40;

			//Dat is het voor nu even, houdt rekening met nog 2 elementen (footer en de daaronder 2e content div)
			
			var totalHeight = headerHeight+containerHeight+padding;

			var light=document.getElementById("light");
			var fade=document.getElementById("fade");
			var elem=document.getElementById("lightcontent");
			
			fade.style.display="block";
			light.style.display="block";
			//27 hieronder is ook overig, geen onderzoek gedaan
			fade.style.minHeight=(totalHeight+27)+"px";
			
			var margin=0;
			var windowHeight = window.innerHeight || document.documentElement.clientHeight;
			var helft = windowHeight/2;

			margin-=totalHeight;
			fade.style.marginTop=margin+"px";

			if(browser == "IE 7")
				elem.style.marginTop=f_scrollTop()+"px";
			else
				elem.style.marginTop=(f_scrollTop()+helft-(elem.offsetHeight/2))+"px";
			
		}
	}
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	
}
