

function showElement(strElementID) 
{
	objElement = document.getElementById(strElementID);
	objElement.style.visibility = "visible";
	objElement.style.display = "block";
}

function hideElement(strElementID) 
{
	objElement = document.getElementById(strElementID);
	objElement.style.visibility = "hidden";
	objElement.style.display = "none";
}

function toggleElement(strElementID) 
{
	objElement = document.getElementById(strElementID);
	
	if ((objElement.style.visibility == "") || (objElement.style.visibility == "hidden"))
	{
		showElement(strElementID) 
	} else {
		hideElement(strElementID) 
	}
}

function toggleElementByCheckBox(strElementID, objCheckBox)
{
	if (objCheckBox.checked)
	{
		showElement(strElementID);
	} else {
		hideElement(strElementID);
	}
}

function setMainImage(newSrc)
{
	document.mainimage.src = newSrc;
}

function borderOn(objImg)
{
	objImg.style.borderTop = "2px solid #000";
	objImg.style.borderBottom = "2px solid #000";
}

function borderOff(objImg)
{
	objImg.style.borderTop = "2px solid #fff";
	objImg.style.borderBottom = "2px solid #fff";
}

function showNextMonth(thisMonth)
{
	strPrefix = "maand-";

	hideElement(strPrefix + thisMonth);
	
	nextMonth = thisMonth + 1;
	showElement(strPrefix + nextMonth);

}


function showPreviousMonth(thisMonth)
{
	strPrefix = "maand-";

	hideElement(strPrefix + thisMonth);
	
	previousMonth = thisMonth - 1;
	showElement(strPrefix + previousMonth);

}


function calculatePrice(objSelect)
{
	var showTotal = false;
	var totaal = 0;
	
	myForm = document.forms[0];
	objAllElements = myForm.elements;
	
	for (i=0;i < objAllElements.length;i++)
	{
		objElement = objAllElements[i];
		if ((objElement.type == "select-one") && (objElement.name.indexOf("aantal_personen") > -1))
		{
			strRowID = objElement.name.substring(16);
			aantal = objElement.value;
			if (aantal > 0) {
				
				showElement(strRowID);
				showTotal = true;
				
				// set aantal
				objAantalElement = document.getElementById(strRowID + "-aantal");
				objAantalElement.firstChild.data = aantal;
				
				// show naam (enkelvoud/meervoud)
				objNaamElement = document.getElementById(strRowID + "-naam");
				objNaamElement.firstChild.data = getNaamForAantal(strRowID, aantal);
				
				// get price
				objPrijsElement = document.getElementById(strRowID + "-prijscalculate");
				var prijs = objPrijsElement.firstChild.data;
				
				// set subtotaal
				var subtotaal = aantal * prijs;
				
				totaal += subtotaal;
				
				objSubtotaalElement = document.getElementById(strRowID + "-subtotaal");
				objSubtotaalElement.firstChild.data = Math.round(subtotaal*100)/100;;
				
			} else {
				hideElement(strRowID);
			}
		}
	}
	
	if (showTotal) {
		total = Math.round(totaal*100)/100;
		objTotaalElement = document.getElementById("totaal-bedrag");
		totaal_string = ""+ totaal;
		objTotaalElement.firstChild.data = totaal_string.replace(".", ",");
		showElement("totaal");
	}
	
}


function getNaamForAantal(strRowID, aantal)
{
	var naam;
	
	if (strRowID == "adult") {
		if (aantal == 1) {
			naam = "volwassene";
		} else {
			naam = "volwassenen";
		}
	} else if (strRowID == "baby") {
		if (aantal == 1) {
			naam = "baby";
		} else {
			naam = "baby";
		}
	} else if (strRowID == "child") {
		if (aantal == 1) {
			naam = "kind";
		} else {
			naam = "kinderen";
		}
	} else if (strRowID == "sixtyfive") {
		if (aantal == 1) {
			naam = "65-plusser";
		} else {
			naam = "65-plussers";
		}
	}
	
	return naam;
}

function checkTotaalAantalPersonen(objSelect)
{
	objForm = document.forms[0];
	objAllElements = objForm.elements;
	
	var totaal_aantal_personen = 0;
	
	for (i=0;i < objAllElements.length;i++)
	{
		objElement = objAllElements[i];
		if ((objElement.type == "select-one") && (objElement.name.indexOf("aantal_personen") > -1))
		{
			aantal = objElement.value;
			if (aantal > 0) {
				totaal_aantal_personen = totaal_aantal_personen + parseInt(aantal);
			}
		}
	}
	
	if (totaal_aantal_personen > 20) 
	{
		alert("U kunt reserveren tot maximaal 20 personen.\nWilt u met meer mensen komen vraag dan een offerte aan.");
		
		difference = totaal_aantal_personen - 20;
		objSelect.value = objSelect.value - difference;
	}

}


function isValidVerdelingForm(objForm)
{
	var aantal_groepen = objForm.aantal_groepen.value;
	
	var aantal_materiaalpakketten = parseInt(objForm.aantal_materiaalpakketten.value);
	var aantal_leskisten = parseInt(objForm.aantal_leskisten.value);
	var aantal_excursies = parseInt(objForm.aantal_excursies.value);
	
	var totaal = aantal_materiaalpakketten + aantal_leskisten + aantal_excursies;
	
	if (totaal > aantal_groepen || totaal < aantal_groepen) {
		alert("U heeft nu "+ totaal +" groepen verdeeld terwijl u er "+ aantal_groepen +" had gekozen.");
		return false;
	} else {
		return true;
	}
	
	
}

function isValidActiviteitenForm(objForm)
{
	blnHasOneEmptyProduct = false;	

	for (i=0; i < objForm.elements.length; i++) 
	{
		objElement = objForm.elements[i];
		strElementName = objElement.name;
		var product_id_value;
		var aanvragen_to_product_id;
		
		if (strElementName.indexOf("product_id_for_id_") > -1) {
			
			// RETRIEVE ID
			aanvragen_to_product_id = strElementName.substring(strElementName.lastIndexOf("_")+1)
			
			// PRODUCT
			objProductElement = objElement;
			product_id_value = objProductElement.value
			if (product_id_value == "") {
				blnHasOneEmptyProduct = true;
				objProductElement.style.backgroundColor = "#ffccff";
			} else {
				objProductElement.style.backgroundColor = "#ffffff";
			}
			
			if (product_id_value != "nvt")
			{
				// LEERKRACHT VELD
				objLeerkrachtElement = document.getElementById("Naam_Leerkracht_for_id_"+ aanvragen_to_product_id);
				leerkracht_value = objLeerkrachtElement.value
				
				if (leerkracht_value == "") {
					blnHasOneEmptyProduct = true;
					objLeerkrachtElement.style.backgroundColor = "#ffccff";
				} else {
					objLeerkrachtElement.style.backgroundColor = "#ffffff";
				}
				
				// LEERJAAR VELD
				objLeerjaarElement = document.getElementById("Leerjaar_for_id_"+ aanvragen_to_product_id);
				leerjaar_value = objLeerjaarElement.value
				if (leerjaar_value == "") {
					blnHasOneEmptyProduct = true;
					objLeerjaarElement.style.backgroundColor = "#ffccff";
				} else {
					objLeerjaarElement.style.backgroundColor = "#ffffff";
				}
			}
			
		}
		
	}

	if (blnHasOneEmptyProduct) {
		alert("U heeft nog niet alle specificaties ingevuld.");
		return false;
	} else {
		return true;
	}
}



function isValidForm(objForm, main, action)
{
	isValid = true;
	
	// do autocheck
	isValid = autocheck(objForm);
	
	// check for educatie aanvragen aantallen
	if ( (main == "educatie") && (action == "aanvragen") )
	{
		Gemeente = objForm.Gemeente.value;
		totaal_aantal_groepen = objForm.totaal_aantal_groepen.value;
		aantal_groepen = objForm.aantal_groepen.value;
		
		if (Gemeente == "Alphen a/d Rijn")
		{
			if ( (totaal_aantal_groepen != "") && (aantal_groepen != "") ) 
			{
				if (parseInt(aantal_groepen) > parseInt(totaal_aantal_groepen)) 
				{
					isValid = false;
					alert("Scholen uit Alphen a/d Rijn kunnen niet meer activiteiten bestellen dan het totaal aantal groepen.");
					objForm.aantal_groepen.style.backgroundColor = "#ffccff";
				}
			}
		}
		
	}
	
	return isValid;
}



function checkSelectedProduct(objSelect, product_id)
{
	objOption = objSelect.options[objSelect.selectedIndex];
	
	if (objOption.className == "nietbeschikbaar")
	{
		alert("U heeft een activiteit geselecteerd die niet meer beschikbaar is.\nKlik op OK en selecteer opnieuw.");
		objSelect.selectedIndex = 0;
	}
	
		
}