function ProductPrijsAanpassen() {
	var ProductAantal = parseFloat(document.getElementById('ProductAantal').value);
	var ProductPrijs = parseFloat(document.getElementById('ProductPrijs').value);
	var ProductKortingAantal = parseFloat(document.getElementById('ProductKortingAantal').value);
	var ProductKortingPrijs = parseFloat(document.getElementById('ProductKortingPrijs').value);
	var AantalCombies = parseFloat(document.getElementById('AantalCombies').value);
	var AantalMeebestellers = parseFloat(document.getElementById('AantalMeebestellers').value);
	var ProductTotaalPrijs, c, d, e;
	var IsKortingAantal;
	var aantGeenKorting = 0;

	if(ProductKortingAantal!=0 && ProductAantal>=ProductKortingAantal) {
		var aantGeenKorting, aantVoorKorting;
		aantGeenKorting = ProductAantal % ProductKortingAantal;
		aantVoorKorting = (ProductAantal - aantGeenKorting) / ProductKortingAantal;
		ProductTotaalPrijs = (aantVoorKorting * ProductKortingPrijs) + (aantGeenKorting * ProductPrijs);
		IsKortingAantal = true;
	} else {
		ProductTotaalPrijs = ProductAantal * ProductPrijs;
		IsKortingAantal = false;
	}
	if(AantalCombies!=0) {
		var PrijsCorrectie = 0;
		for(c=1;c<=5;c++) {
			if(c<=ProductAantal) {
				var a, CombinatieId;
				document.getElementById('ProductCombinatie' + c).style.display = '';
				for (a=1;a<=AantalCombies;a++) {
					CombinatieId = document.getElementById('ProductCombinatie' + c + '_' + a).value;
					//if(!IsKortingAantal || (IsKortingAantal && c == ProductAantal && c > (ProductAantal - aantGeenKorting))) {
						PrijsCorrectie = PrijsCorrectie + parseFloat(document.getElementById('ProductCombinatiePrijsCorrectie' + CombinatieId).value);
					//}
				}
			} else {
				document.getElementById('ProductCombinatie' + c).style.display = 'none';
			}
		}
		ProductTotaalPrijs = ProductTotaalPrijs + PrijsCorrectie;
	}
	if(AantalMeebestellers!=0) {
		for(d=1;d<=AantalMeebestellers;d++) {
			var ProductMeebestellerMaxAantal = document.getElementById('ProductMeebesteller' + d + 'MaxAantal').value;
			if(ProductMeebestellerMaxAantal == "1PerProduct") {
				if(document.getElementById('ProductMeebesteller' + d + 'Aantal').checked) {
					var AantalPerMeebestellers = 1;
				} else {
					var AantalPerMeebestellers = 0;
				}
			} else {
				var AantalPerMeebestellers = parseFloat(document.getElementById('ProductMeebesteller' + d + 'Aantal').value);
			}
			if(ProductMeebestellerMaxAantal == "Bestelaantal") {
				if(AantalPerMeebestellers>ProductAantal) {
					var PullDownMeebesteller = document.getElementById('ProductMeebesteller' + d + 'Aantal');
					PullDownMeebesteller.options.length = 0;
					for(e=0;e<=5;e++) {
						PullDownMeebesteller.options[e] = new Option(e, e, e==ProductAantal, e==ProductAantal);
					}
					AantalPerMeebestellers = ProductAantal;
				}
			} else {
				AantalPerMeebestellers = AantalPerMeebestellers;
			}
			ProductTotaalPrijs = ProductTotaalPrijs + (AantalPerMeebestellers * parseFloat(document.getElementById('ProductMeebesteller' + d + 'Prijs').value));
		}
	}
	document.getElementById('ProductTotaalPrijs').innerHTML = Format(ProductTotaalPrijs);
}

function Format(Number)	{
	Number = Math.round(Number*100)/100;
	var NumberText = Number + '';
	if((Number) == Math.round(Number)) {
	  	NumberText += ".00";
	} else if((Number*10) == Math.round(Number*10))	{
	  	NumberText += "0";
	}
	return NumberText;
}

function ToggleBetaalOptie(BetaalOptie) {
	document.getElementById('iDeal').style.display = 'none';
	document.getElementById('Machtiging').style.display = 'none';
	document.getElementById('VISA').style.display = 'none';
	document.getElementById('MasterCard').style.display = 'none';
	document.getElementById('Maestro').style.display = 'none';
	document.getElementById('AcceptGiro').style.display = 'none';
	
	document.getElementById(BetaalOptie).style.display = '';
	document.getElementById('BetaalToeslag').innerHTML = document.getElementById('BetaalToeslag' + BetaalOptie).value;
	document.getElementById('TotaalBedrag').innerHTML = document.getElementById('TotaalBedrag' + BetaalOptie).value;
}

function ToggleWinkelwagenInloggen(Tabblad) {
	if(Tabblad=='Winkelwagen') {
		document.getElementById('GridWinkelwagen').style.display = '';
		document.getElementById('GridInloggen').style.display = 'none';
		document.getElementById('HeaderGrid').style.backgroundPosition = '0 0';
		
	} else {
		document.getElementById('GridWinkelwagen').style.display = 'none';
		document.getElementById('GridInloggen').style.display = '';
		document.getElementById('HeaderGrid').style.backgroundPosition = '0 -72px';
	}
}

function MaakZoekveldBlanco(Veld) {
	if(Veld.value==document.getElementById('DefaultZoektekst').value) {
		Veld.value = "";
	} else if (Veld.value=="") {
		Veld.value = document.getElementById('DefaultZoektekst').value;
	}
}

function MaakOpmerkingenveldBlanco(Veld) {
	if(Veld.value=="Vul hier eventuele opmerkingen bij uw bestelling in.") {
		Veld.value = "";
	} else if (Veld.value=="") {
		Veld.value = "Vul hier eventuele opmerkingen bij uw bestelling in.";
	}
}

function BekijkAfbeelding() {
	window.open('/Images/' + LaatsteProductAfbeelding, 'Afbeelding', 'width=' + (LaatsteProductAfbeeldingw + 15) + ',height=' + (LaatsteProductAfbeeldingh + 15) + ',menubar=no,scrollbars=0,resizable=1')
}

function PreviewAfbeelding(Afbeelding, FotoNr) {
	if(YouTubeId!='') {
		document.getElementById('YouTubeFilm').style.display='none';
		document.getElementById('Preview').style.display='block';
	}
	document.getElementById('Preview').src='/Images/Thumbnail/Fixed250/' + Afbeelding;
	FotoSelectedId = FotoNr;
}

function ShowYouTube() {
	document.getElementById('YouTubeFilm').style.display='block';
	document.getElementById('Preview').style.display='none';
}

function Zoeken(Pagina) {
	if(Pagina!='') {
		document.getElementById('frmZoeken').action = "/Zoeken/Pagina-" + Pagina + ".html";
	} else {
		document.getElementById('frmZoeken').action = "/Zoeken.html";
	}
	document.getElementById('frmZoeken').submit();
}

function VeranderMediumCode(MediumCode) {
	MediumCode = MediumCode.slice(MediumCode.indexOf('|') + 1);
	if(MediumCode=="1") {
		//document.getElementById('WinkelwagenBezorgEnBetaalinfoMediumCodeCatalogusCode').style.display = '';
		document.getElementById('MediumCode').style.display = '';
	} else {
		//document.getElementById('WinkelwagenBezorgEnBetaalinfoMediumCodeCatalogusCode').style.display = 'none';
		document.getElementById('MediumCode').style.display = 'none';
	}
}

function GratisVerzenden(JaNee) {
	var StandaardVerzendkosten = document.getElementById('StandaardVerzenkosten').value;
	var SpecialeVerzenkosten = document.getElementById('SpecialeVerzenkosten').value;
	var NormaalTotaalBedrag = document.getElementById('NormaalTotaalBedrag').value;
	var GratisVerzendenTotaalBedrag = document.getElementById('GratisVerzendenTotaalBedrag').value;
	
	if(JaNee) {
		document.getElementById('htmlStandaardVerzenkosten').innerHTML = "0,00";
		document.getElementById('htmlSpecialeVerzenkosten').innerHTML = "0,00";
		document.getElementById('TotaalBedrag').innerHTML = GratisVerzendenTotaalBedrag;
	} else {
		document.getElementById('htmlStandaardVerzenkosten').innerHTML = StandaardVerzendkosten;
		document.getElementById('htmlSpecialeVerzenkosten').innerHTML = SpecialeVerzenkosten;
		document.getElementById('TotaalBedrag').innerHTML = document.getElementById('TotaalBedrag' + document.getElementById('BetaalOptie').value).value;
	}
}

function Ajax(Actie, Data) {
	var xmlHttp=null;

	if (window.XMLHttpRequest) { 
		xmlHttp = new XMLHttpRequest();     // Firefox, Safari, ...
	} else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
	}
	
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4) {
			if(!xmlHttp.responseText=='') {eval(xmlHttp.responseText)}
		}
	}
	xmlHttp.open('POST', Actie, true);
	xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	xmlHttp.send(Data);
}

function OpenProducten() {
	document.getElementById('VerborgenArtikelen').style.display = 'block';
	document.getElementById('ProductenOpenen').style.display = 'none';
}

function ToggleLogin() {
	if (document.getElementById('InloggenEMailadres').value == 'Uw e-mailadres') {
		document.getElementById('InloggenEMailadres').value = '';
		document.getElementById('InloggenWachtwoord').value = '';
	} else if (document.getElementById('InloggenEMailadres').value == '') {
		document.getElementById('InloggenEMailadres').value = 'Uw e-mailadres';
		document.getElementById('InloggenWachtwoord').value = 'Wachtwoord';		
	}
}

function CreateBookmarkLink() {
	title = document.title;
	url = window.location.href;

	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if(window.external) {
		window.external.AddFavorite( url, title);
	} else {
		alert('Uw browser ondersteund geen mogelijkheid\nom deze pagina automatisch aan uw\nfavorieten/bookmarks toe te voegen.\n\nU kunt dit zelf doen via het menu van uw browser.');
	}
}

function WinkelwagenToevoegen(ProductCategorieId, ProductId, ProductAantal) {
	frm = document.createElement("form");
	frm.setAttribute("method", "post");
	frm.setAttribute("id", "tmpWinkelwagen");
	frm.setAttribute("name", "tmpWinkelwagen");
	frm.setAttribute("action", "/Winkelwagen.html");
	
	MaakFormInput("a", "ProductToevoegen", "hidden", frm);
	MaakFormInput("ProductCategorieId", ProductCategorieId, "hidden", frm);
	MaakFormInput("ProductId", ProductId, "hidden", frm);
	MaakFormInput("ProductAantal", ProductAantal, "hidden", frm);
	document.body.appendChild(frm);
	frm.submit()
}

function MaakFormInput(Name, Value, Type, Form) {
	inp = document.createElement("input");
	inp.setAttribute("name", Name);
	inp.setAttribute("value", Value);
	inp.setAttribute("type", Type);
	Form.appendChild(inp);
}