


/* BASKET functions */

function setActiveBasket(objSelect, strActiveerURL, strRedirectURL)
{
	selIndex = objSelect.selectedIndex;
	guid = objSelect.options[selIndex].value;
	
	window.location.href = strActiveerURL + "?guid="+ guid + "&url="+ strRedirectURL;
}


function isValidCatalogusBestelForm(objForm)
{
	//showProgressBar();
}

function isValidSnelBestelForm(objForm)
{
	strArticleNumber = objForm.intArticleNumber.value;
	strAmount = objForm.intAmount.value;

	if ((strArticleNumber != "") && (strAmount == "")) 
	{
		objForm.intAmount.focus();
		return false;
	} 
	else 
	{
		return isValidBestelForm(objForm, true);		
	}
	
}


function isValidBestelForm(objForm, blnCheckArticleNumber)
{
	var strAlert = "";
	
	objArticleID = objForm.intArticleNumber;
	objAmount = objForm.intAmount;
	
	if (blnCheckArticleNumber) {
		strAlert += checkArtikelNummer(objArticleID);
	}
	
	strAlert += checkAmount(objAmount, false);
		
	if (strAlert == "")	{
		return true;
	} else {
		alert("De volgende velden zijn niet goed ingevuld:\n"+ strAlert);
		return false;
	}
}

function isValidAdvancedBestelForm(objForm)
{
	strValue = objForm.strArticleNumberList.value;

	if (strValue != "") {
		return true;
	} else {
		alert("Er is een fout opgetreden.");
		return false;
	}
}


function setAction(objForm, strAction)
{
	strApplicationPath = objForm.strApplicationPath.value;
	//SET action
	objForm.action = strApplicationPath + strAction +"/html.aspx";
}

function setSuccessUrl(objForm, strNewSuccessUrl)
{
	objForm.strSuccessUrl.value = strNewSuccessUrl;
}


function checkArtikelNummer(objInputField)
{
	// GET value
	strArtikelNummer = ""+ objInputField.value;
	
	// is valid?
	isValidID = isValidArtikelNummer(strArtikelNummer);

	if (isValidID==false) {
		return "> ArtikelNummer\n";
	} else {
		return "";
	}
}

function cleanUpArtikelNummerValue(objInputField)
{
	//get value
	strRawValue = objInputField.value;
	
	//clean up
	strCleanValue = xReplace(strRawValue, ".", "");
	strCleanValue = xReplace(strCleanValue, " ", "");
	
	//set value
	objInputField.value = strCleanValue;
}

function cleanUpAmountValue(objInputField)
{
	//get value
	strRawValue = objInputField.value;
	
	//clean up
	strCleanValue = xReplace(strRawValue, ".", "");
	strCleanValue = xReplace(strCleanValue, " ", "");
	
	//set value
	objInputField.value = strCleanValue;
}



function isValidArtikelNummer(strArtikelNummer) 
{
	isValidID = false;
	
	if ((strArtikelNummer != "") && (strArtikelNummer.length > 6))
	{
		if (!isNaN(strArtikelNummer)) 
		{
			for (i=0; i < arrayArticleNumbers.length; i++) 
			{
				pID = arrayArticleNumbers[i];
				if (pID == strArtikelNummer) {
					isValidID = true;
				}
			}
		}
	}
	
	return isValidID;
}


function isValidAmount(strValue, allowZero)
{
	isValid = false;
	
	if ( (strValue != "") || ( (strValue == "") && (allowZero) ) ) 
	{
		if (isNaN(strValue)==false) {
			intAmount = parseInt(strValue);
			if ((intAmount >= 1) || (allowZero)) {
				isValid = true;
			}
		}
	}
	
	return isValid;
}


function ensureAmount(objInputField, allowZero)
{
	strAlert = checkAmount(objInputField, allowZero);
	if (strAlert != "") {
		alert("Een aantal mag alleen cijfers bevatten");
		var currentClassName = objInputField.className;
		objInputField.className = currentClassName + " errorfield";
	}
}


function checkAmount(objInputField, allowZero)
{
	strAmount = objInputField.value;

	if (isValidAmount(strAmount, allowZero)==false) {
		return "> Aantal\n";
	} else {
		return "";
	}
}

function handleToevoegenButton(objForm, intSelectedUniqueID)
{
	//showProgressBar();
	
	strNameOfAmountElement = intSelectedUniqueID +"_intAmount";
	objAmountField = getElementByName(objForm, strNameOfAmountElement);
	strAmountValue = objAmountField.value;
	
	// CLEAR THE REST - because the user has clicked on a particular toevoegen button
	//clearAllAmountsExceptTheOneClicked(objForm, intSelectedArticleNumber)
	
	// FILL THE ONE CLICKED when empty
	if (strAmountValue == "")
	{
		objAmountField.value = "1";
	} else if (strAmountValue.indexOf(".") > -1) {
		objAmountField.value = strAmountValue.replace('.', '');
	}
	
	// FILL SINGLE ARTICLE FIELD
	//objSingleArticleNumber = getElementByName(objForm, "strSingleArticleNumberAndAmount");
	//objSingleArticleNumber.value = intSelectedArticleNumber + "_" + objAmountField.value;
	
	objForm.submit();
}

function clearAllAmountsExceptTheOneClicked(objForm, intSelectedArticleNumber) 
{
	insertValueInGroup(objForm, "", intSelectedArticleNumber);
}

function setHiddenValuesForProduct(objForm, intSelectedArticleNumber)
{
	//check amount
	fillEmptyAmount(objForm, intSelectedArticleNumber);
	
	//set articlenr
	setArticleNumber(objForm, intSelectedArticleNumber);
	// set amount
	setAmount(objForm, intSelectedArticleNumber);
}

function setArticleNumber(objForm, intSelectedArticleNumber)
{
	objForm.intArticleNumber.value = intSelectedArticleNumber;
}

function setAmount(objForm, intSelectedArticleNumber)
{
	strNameOfAmountElement = intSelectedArticleNumber +"_intAmount";
	objAmountField = getElementByName(objForm, strNameOfAmountElement);
	objForm.intAmount.value = objAmountField.value;
}

function removeItemFromBasket(lUniqueID, strArticleFullName)
{
	objForm = document.winkelwagenformulier;
	
	if (confirm("Het onderstaande artikel wordt uit uw winkelwagen verwijderd:\n\n - "+ strArticleFullName)) {
		setAction(objForm, "itemverwijderen");
		objForm.lUniqueID.value = lUniqueID;
		objForm.submit();
	} else {
		//do nothing
	}
}

function removeItemFromBasketByArticleNumber(intArticleNumber, strArticleFullName)
{
	objForm = document.winkelwagenformulier;
	
	if (confirm("Het onderstaande artikel wordt uit uw winkelwagen verwijderd:\n\n - "+ strArticleFullName)) {
		setAction(objForm, "itemverwijderen_op_artikelnummer");
		objForm.intArticleNumber.value = intArticleNumber;
		objForm.submit();
	} else {
		//do nothing
	}
}

function removeAllItemsFromBasket(objForm)
{
	if (confirm("Weet u zeker dat u ALLE artikelen uit uw winkelwagen wilt verwijderen?")) 
	{
		setAction(objForm, "alleitemsverwijderen");
		objForm.submit();
	}
	else 
	{
		// do nothing	
	}
}



function updateBasket(objForm)
{
	setAction(objForm, "updateitems");
	
	objForm.submit();
}


function deleteBasket(guid, url)
{	
	var strConfirmationQuestion = "Weet u zeker dat u deze winkelwagen wilt verwijderen?";
	isConfirmed = confirm(strConfirmationQuestion);	

	if (isConfirmed)	
	{
		window.location.href = url + "?guid="+ guid;	
	}
	
}


function getArticleCode(intArticleNumber)
{
	strArticleCode = ""+intArticleNumber;
	strArticleCode = strArticleCode.substring(0,3) + "." + strArticleCode.substring(3);
	return strArticleCode;
}

function addSelection(objForm, blnIsLoggedIn, blnIsGroup)
{
	
	if (blnIsGroup) {
		strConfirmationQuestion = "Alle onderstaande artikelen worden toegevoegd aan uw winkelwagen.";
	} else {
		strConfirmationQuestion = "Alle ingevoerde aantallen worden toegevoegd aan uw winkelwagen.";
	}
	
	if (blnIsLoggedIn == 'false') 
	{
		strConfirmationQuestion = "U bent nog niet ingelogd.\nWilt u nu inloggen?";
	}
	
	isConfirmed = confirm(strConfirmationQuestion);	

	if (isConfirmed)	
	{
		setAction(objForm, "selectietoevoegen");
		//showProgressBar();
		objForm.submit();
	}

}

function addGroupToBasket(objForm, blnIsLoggedIn) 
{
	insertOneInGroup(objForm);
	addSelection(objForm, blnIsLoggedIn, true);
}

function insertOneInGroup(objForm)
{
	insertValueInGroup(objForm, "1", 0);
}

function insertValueInGroup(objForm, strAmountValue, intSelectedArticleNumber)
{
	if (objForm != "undefined")
	{
		for (i=0; i < objForm.elements.length; i++)
		{
			objElement = objForm.elements[i];
			if (objElement.type == "text") {
				strElementName = objElement.name;
				strSubString = strElementName.substring(strElementName.indexOf("_")+1);
				if ((strSubString == "intAmount") && (strElementName != intSelectedArticleNumber + "_intAmount")) {
					objElement.value = strAmountValue;
				}
			}
		}
	}
}


function getFormObjectByName(nameOfForm)
{
	for (i=0; i < document.forms.length; i++)
	{
		if (document.forms[i].name == nameOfForm)
		{
			return document.forms[i];
		}
	}
}


function getElementByName(objForm, strElementName)
{
	for (i=0; i < objForm.elements.length; i++)
	{
		if (objForm.elements[i].name == strElementName)
		{
			return objForm.elements[i];
		}
	}
}



function showProgressBar()
{
	objImage = document.progressbar;
	
	strSourceCurrent = ""+objImage.src;
	strSourceCut     = strSourceCurrent.substring(0, strSourceCurrent.lastIndexOf("/")+1);
	strSourceNew     = strSourceCut + "progressbar.gif";
		
	objImage.src     = strSourceNew;
}

function setRowClass(objSelect, rowID, originalClass)
{
	if (objSelect.value != "") {	
		objRow = document.getElementById(rowID);
		objRow.className = "selected";
	} else {
		objRow.className = originalClass;
	}
}



/* CATALOGUE functions */


// load arrays
loadArrays();



// define levels
level = new Array();
level[0] = tab;
level[1] = S1;
level[2] = S2;
level[3] = S3;
level[4] = S4;

var tabValue;
var S1value;
var S2value;
var S3value;
var S4value;

var selectBoxPrefix = "form-select-";

function openPanel(tabID) 
{
	// show panel
	showElement("browsepanel");
	
	// set bgcolor and tabline
	setPanelColor(tabID);
}

function openPanelAndSelectBox1(tabID)
{
	openPanel(tabID);
	showAndFillSelectBox(1, tabID, false, -1);
}

function showAndFillSelectBox(intSelectBoxNr, intID, blnShowProducts, selectedValue)
{
	//hide next ones
	hideAllBoxesNotNeeded(intSelectBoxNr);
	
	//resize
	resizeFormSelects(intSelectBoxNr);
	
	
	// set selected values
	if (intSelectBoxNr == 1) {
		tabValue = intID;
	}
	if (intSelectBoxNr == 2) {
		S1value = intID;
	}
	if (intSelectBoxNr == 3) {
		S2value = intID;
	}
	if (intSelectBoxNr == 4) {
		S3value = intID;
	}
	
	// get array 
	var objTheRightArray = getArrayBySelectedValues(intSelectBoxNr, tabValue, S1value, S2value, S3value);
		
	if (objTheRightArray.length > 0)
	{
		//show div
		showElement(selectBoxPrefix + intSelectBoxNr);
		
		// get select object
		strSelectName = selectBoxPrefix + intSelectBoxNr;
		objFormSelect = document.getElementById(strSelectName);
		
		// clear previous options
		clearOptions(objFormSelect);
			
		// generate options by array
		for (m=0; m < objTheRightArray.length; m++)
		{
			itemArray = objTheRightArray[m];
			txt = itemArray[1];
			val = itemArray[0];
			
			if (txt.indexOf("&amp;") > -1) {
				txt = txt.replace("&amp;", "&");
			}
					
			objFormSelect.options[m] = new Option(txt, val);
			//alert("val: "+ val + " en txt: "+ txt + "en selectedvalue: "+ selectedValue);
			if (val == selectedValue) {
				objFormSelect.options[m].selected = true;
			}
		}
	} else {
		if (blnShowProducts) {
			showProductsForID(intID);
		}
	}
}

function setSelectedOptionsForCatalogue(strDirectory, strAction, intArticleSubGroupID, intGroupID) 
{
	if ( (strDirectory == 'catalogus') && (strAction == 'zoeken') && (intArticleSubGroupID != "") && (intGroupID != "") ) 
	{
		setSelectedOptionForSelectBox(1);
		setSelectedOptionForSelectBox(2);
		setSelectedOptionForSelectBox(3);
		setSelectedOptionForSelectBox(4);
	}
}

function setSelectedOptionForSelectBox(intSelectBoxNr)
{
	objFormSelect = document.getElementById(selectBoxPrefix + intSelectBoxNr);
	if (objFormSelect.options.length > 0) {
		intSelectedIndex = objFormSelect.options.selectedIndex;
		objFormSelect.options[intSelectedIndex].selected = true;
	}
}	



function getArrayBySelectedValues(intSelectBoxNr, tabValue, S1value, S2value, S3value)
{
	// get array for level
	objArrayForLevel = level[intSelectBoxNr];
	
	var theRightArray = new Array();
	k = 0;
	
	//loop door alle arrays heen van dit level
	for (i = 0; i < objArrayForLevel.length; i++)
	{
		//haal 1 array op
		objItemArray = objArrayForLevel[i];
		
		if (intSelectBoxNr == 1)
		{
			if (objItemArray[2] == tabValue) {
				// vul de nieuwe array 
				theRightArray[k] = objItemArray;
				k = k + 1;
			}
		} 
		else if (intSelectBoxNr == 2) 
		{
			if ( (objItemArray[2] == S1value) && (objItemArray[3] == tabValue) )
			{
				// vul de nieuwe array 
				theRightArray[k] = objItemArray;
				k = k + 1;
			}
		}
		else if (intSelectBoxNr == 3) 
		{
			if ( (objItemArray[2] == S2value) && (objItemArray[3] == S1value) && (objItemArray[4] == tabValue) )
			{
				// vul de nieuwe array 
				theRightArray[k] = objItemArray;
				k = k + 1;
			}
		}
		else if (intSelectBoxNr == 4) 
		{
			if ( (objItemArray[2] == S3value) && (objItemArray[3] == S2value) && (objItemArray[4] == S1value)  && (objItemArray[5] == tabValue) )
			{
				// vul de nieuwe array 
				theRightArray[k] = objItemArray;
				k = k + 1;
			}
		}
		
	}
	return theRightArray;
	
}

function showPanelAndSelectBoxes(intArticleSubGroupID, intGroupID)
{
	
	//get tab
	tabID = getTabByGroupID(intGroupID)
	
	//show panel
	openPanel(tabID);
	
	
	// get the right array and count
	objOneArray = getArrayByArticleSubGroupID(intArticleSubGroupID, tabID);	
	intNumberOfBoxes = objOneArray.length - 2;
	
	if (intNumberOfBoxes == 4) 
	{
		selectedValueBox1 = objOneArray[4];
		selectedValueBox2 = objOneArray[3];
		selectedValueBox3 = objOneArray[2];
		
		showAndFillSelectBox(1, tabID, false, selectedValueBox1);
		showAndFillSelectBox(2, selectedValueBox1, false, selectedValueBox2);
		showAndFillSelectBox(3, selectedValueBox2, false, selectedValueBox3);
		showAndFillSelectBox(4, selectedValueBox3, false, intArticleSubGroupID);
	}
	else if (intNumberOfBoxes == 3) 
	{
		selectedValueBox1 = objOneArray[3];
		selectedValueBox2 = objOneArray[2];
		selectedValueBox3 = intArticleSubGroupID;
		
		showAndFillSelectBox(1, tabID, false, selectedValueBox1);
		showAndFillSelectBox(2, selectedValueBox1, false, selectedValueBox2);
		showAndFillSelectBox(3, selectedValueBox2, false, selectedValueBox3);
	}
	else if (intNumberOfBoxes == 2) 
	{
		selectedValueBox1 = objOneArray[2];
		selectedValueBox2 = intArticleSubGroupID;
		
		showAndFillSelectBox(1, tabID, false, selectedValueBox1);
		showAndFillSelectBox(2, selectedValueBox1, false, selectedValueBox2);
	}
	else if (intNumberOfBoxes == 1) 
	{
		selectedValueBox1 = intArticleSubGroupID;
		
		showAndFillSelectBox(1, tabID, false, selectedValueBox1);
	}

}


function getTabByGroupID(intGroupID)
{
	tabID = intGroupID
	
	if (intGroupID == 10) {
		tabID = 78;
	} else if (intGroupID == 8) {
		tabID = 60;
		tabID = 229;
	} else if ((intGroupID == 6) || (intGroupID == 5) || (intGroupID == 4) || (intGroupID == 2)) {
		tabID = 0;
	}

	return tabID;
}


function getTabByArticleSubGroupID(intArticleSubGroupID)
{
	// LEVEL 4
	for (x = 0; x < S4.length; x++) 
	{
		OneArray = S4[x];
		if (intArticleSubGroupID == OneArray[0]) {
			return OneArray[5];
		}
	}
	
	// LEVEL 3
	for (x = 0; x < S3.length; x++) 
	{
		OneArray = S3[x];
		if (intArticleSubGroupID == OneArray[0]) {
			return OneArray[4];
		}
	}
	
	// LEVEL 2
	for (x = 0; x < S2.length; x++) 
	{
		OneArray = S2[x];
		if (intArticleSubGroupID == OneArray[0]) {
			return OneArray[3];
		}
	}
			
	// LEVEL 1
	for (x = 0; x < S1.length; x++) 
	{
		OneArray = S1[x];
		if (intArticleSubGroupID == OneArray[0]) {
			return OneArray[2];
		}
	}
}
 

function getArrayByArticleSubGroupID(intArticleSubGroupID, intTabID)
{
	// LEVEL 4
	for (x = 0; x < S4.length; x++) 
	{
		OneArray = S4[x];
		if ((intArticleSubGroupID == OneArray[0]) && (intTabID== OneArray[5])) {
			return OneArray;
		}
	}
	
	// LEVEL 3
	for (x = 0; x < S3.length; x++) 
	{
		OneArray = S3[x];
		if ((intArticleSubGroupID == OneArray[0]) && (intTabID == OneArray[4])) {
			return OneArray;
		}
	}
	
	// LEVEL 2
	for (x = 0; x < S2.length; x++) 
	{
		OneArray = S2[x];
		if ((intArticleSubGroupID == OneArray[0]) && (intTabID == OneArray[3])) {
			return OneArray;
		}
	}
	
	// LEVEL 1
	for (x = 0; x < S1.length; x++) 
	{
		OneArray = S1[x];
		if ((intArticleSubGroupID == OneArray[0]) && (intTabID == OneArray[2])) {
			return OneArray;
		}
	}
	
}



function showProductsForID(intArticleSubGroupID) 
{
	strApplicationPath = document.produktenzoekformulier.strApplicationPath.value;
	var strNewUrl = strApplicationPath + "ASG" + intArticleSubGroupID + "/html.aspx";
	
	location.href = strNewUrl;
}


function clearOptions(objFormSelect)
{
	objFormSelect.options.length = 0;
}


function resizeFormSelects(intCurSelectNr)
{
	//expand current select
	if (intCurSelectNr < 4) {
		objCurSelect = document.getElementById(selectBoxPrefix + intCurSelectNr);
		objCurSelect.style.width = "390px";
	}
	
	//shrink previous select
	intPrevNr = (intCurSelectNr - 1);
	if (intPrevNr > 0) {
		objPrevSel = document.getElementById(selectBoxPrefix + intPrevNr);
		objPrevSel.style.width = "210px";
	}
}

function hideAllBoxesNotNeeded(intSelectNr) 
{
	if (intSelectNr == 1) {
		hideElement(selectBoxPrefix + "4");
		hideElement(selectBoxPrefix + "3");
		hideElement(selectBoxPrefix + "2");
	}
	
	if (intSelectNr == 2) {
		hideElement(selectBoxPrefix + "4");
		hideElement(selectBoxPrefix + "3");
		hideElement(selectBoxPrefix + "2");
	}
	
	if (intSelectNr == 3) {
		hideElement(selectBoxPrefix + "4");
	}
}


function setSelectedOption(intSelectNr, intSelectedValue)
{
	objFormSelect = document.getElementById(selectBoxPrefix + intSelectNr);
		
	for (i = 0; i < objFormSelect.options.length; i++)
	{
		if (objFormSelect.options[i].value == intSelectedValue) {
			objFormSelect.options[i].selected = true;
		}
	}
	
}


function setPanelColor(tabID)
{
	//get panel object
	objBrowsePanel = document.getElementById("browsepanel");
	
	
	// set background
	if (tabID == "1") {
		objBrowsePanel.style.background = "#A33A9B";
	} else if (tabID == "0") {
		objBrowsePanel.style.background = "#F49220";
	} else if (tabID == "7") {
		objBrowsePanel.style.background = "#24B6E3";
	} else if ((tabID == "60") || (tabID == "229")) {
		objBrowsePanel.style.background = "#0072BC";
	} else if (tabID == "9") {
		objBrowsePanel.style.background = "#EC1D24";
	} else if (tabID == "78") {
		objBrowsePanel.style.background = "#8AB93A";
	}

}


function showNextImage(imageArray, objImage)
{
	var curImageSource = objImage.src;
	var newImageName = "";
	var newPrefix;
	var j;
	
	var curImageName = curImageSource.substring(curImageSource.lastIndexOf("/")+1, curImageSource.lastIndexOf("."));
	var curPrefix = 'KOK/'+ curImageName.substring(7);
	
	var arrayLength = imageArray.length;
	var lastI = arrayLength - 1;
		
	for (i=0; i < arrayLength; i++)
	{
		if (imageArray[i] == curImageName)
		{
			if (i == lastI) {
				j = 0;
			} else {
				j = i + 1;
			}
			newImageName = imageArray[j];
		}
	}
	
	newPrefix = 'KOK/'+ newImageName.substring(7);
	newImageSource = curImageSource.replace(curImageName, newImageName);
	newImageSource = newImageSource.replace(curPrefix, newPrefix);
		
	objImage.src = newImageSource;
	
	objZoomLink = document.getElementById("zoomlink");
	
	curHref = objZoomLink.href;
	newHref = curHref.replace(curImageName, newImageName);
	
	objZoomLink.href = newHref;

}


/* GENERAL functions */


function zoomImage(objForm, strImage)
{
	strImageZoomPage = objForm.strImageZoomPage.value;
	popupUrl = strImageZoomPage + "?strImage="+strImage
	
	//alert(popupUrl);
	
	window.open(popupUrl, '', 'scrollbars=no,menubar=no,width=680,height=550,resizable=yes,toolbar=no,location=no,status=no');
}



function showArticleInfo(popupUrl) 
{
	window.open(popupUrl, '', 'scrollbars=no,menubar=no,height=500,width=500,resizable=yes,toolbar=no,location=no,status=no');
}


function decreaseAmount(objForm, strArticleNumber)
{
	InOrDecreaseAmount(objForm, strArticleNumber, "decrease");
}

function increaseAmount(objForm, strArticleNumber)
{
	InOrDecreaseAmount(objForm, strArticleNumber, "increase");
}

function InOrDecreaseAmount(objForm, strArticleNumber, strAction)
{
	strFieldName = strArticleNumber + "_intAmount";
	
	//get amount input object
	objElement = getElementByFieldName(objForm, strFieldName);
		
	//get current value
	var intCurrentValue = 0;
	if (objElement.value != "") {
		intCurrentValue = parseInt(objElement.value);
	}
		
	// change amount
	if (strAction == "increase") {
		if (intCurrentValue < 9999) {
			objElement.value = intCurrentValue+1;
		}
	} else if (strAction == "decrease") {
		if (intCurrentValue > 0) {
			objElement.value = intCurrentValue-1;
		}
	} 
}

function insertSpace(objElement)
{
	if (objElement.value == "") {
		objElement.value = " ";
	}
}

function checkThisAmount(objElement)
{
	strValue = objElement.value;
	objElement.value = strValue.replace(" ", "");
	
	if (isNaN(strValue)) {
		objElement.value = "";	
	}
}

function submitAdvancedOrderForm(objForm)
{
	if (objForm.strArticleNumberList.value == "")
	{
		alert("U heeft nog geen artikelnummers ingevoerd.");		
	} 
	else 
	{
		if (confirm("Alle artikelen en aantallen uit onderstaande lijst worden toegevoegd aan uw winkelwagen")) {
			objForm.submit();
		} else {
			// do nothing
		}
	}
}

function setCursorToInputField(objForm)
{
	objArticleNumber = objForm.intArticleNumber;
	objArticleNumber.focus();
}

function addValueOnReturnKey(objForm) 
{ 
	var keyCodeIE = event.keyCode; 
	if (keyCodeIE == 13) { 
		addArticleNumberToList(objForm); 
	} 
}


function addArticleNumberToList(objForm)
{
	
	
	objArticleNumber = objForm.intArticleNumber;
	strArticleNumber = objArticleNumber.value;
	
	objAmount = objForm.intAmount;
	strAmount = objAmount.value;
	
	//validate values
	validNr = isValidArtikelNummer(strArticleNumber);
	validAmount = isValidAmount(strAmount);
		
	if (validNr && validAmount) {
		strArticleNumberListValue = objForm.strArticleNumberList.value;	
		strNewArticleAmountLine = strAmount +" x "+strArticleNumber + "; \n";
		objForm.strArticleNumberList.value = strNewArticleAmountLine + strArticleNumberListValue;
		objArticleNumber.value = "";
		objAmount.value = "";
		objArticleNumber.focus();
	} else {
		if ((strArticleNumber != "") && (strAmount != "")) 
		{
			strErrorFields = "";
			if (validNr==false) {
				strErrorFields += "> Artikelnummer \n";
			}
			if (validAmount==false) {
				strErrorFields += "> Aantal \n";
			}
			alert("De volgende velden zijn niet goed ingevuld: \n"+ strErrorFields);
		} 
		else if ((strArticleNumber != "") && (strAmount == "")) 
		{
			objAmount.focus();
		}
		else 
		{
			objArticleNumber.focus();
		}
	}
		
	// don't submit
	return false;
}


function removeInitialTextAndChangeColor(objInput)
{
	objInput.value = "";
	objInput.style.color = "#000000";
}


function deleteInitialText(theInput) 
{
	if (theInput.value == "Type een trefwoord of artikelnr.") 
	{
		theInput.value = "";
	}
}

function insertInitialText(theInput)
{
	if (theInput.value == "") {
		theInput.value = "Type een trefwoord of artikelnr.";
	}
}

function toggleSelectAll(objSelectAllElement, objForm)
{
	newState = objSelectAllElement.checked;

	for (i=0; i < objForm.elements.length; i++)
	{
		objElement = objForm.elements[i];
		if (objElement.type == "checkbox") {
			strElementName = objElement.name;
			if (strElementName == "AddToBasket") {
				objElement.checked = newState;
			}
		}
	}
}



function checkForSelectAll(objCheckboxElement, objForm)
{
	objCheckAllElement = objForm.CheckAll;
	
	if (objCheckboxElement.checked == false) {
		
		objCheckAllElement.checked = false;
	
	} else {
		
		checkSelectAll = true;
		
		for (i=0; i < objForm.elements.length; i++)
		{
			objElement = objForm.elements[i];
			if (objElement.name == "AddToBasket") {
				if (objElement.checked == false) {
					checkSelectAll = false;
					break;
				}			
			}
		}
		
		if (checkSelectAll == true) {
			objCheckAllElement.checked = true;
		}
		
	}
}


function xReplace(inputString, toBeReplaced, replaceWith)
{ 
	var returnString = inputString; 
	var i = returnString.indexOf(toBeReplaced); 
	while(i > -1){ 
		returnString = returnString.replace(toBeReplaced, replaceWith); 
		i = returnString.indexOf(toBeReplaced); 
	} 
	return returnString; 
} 




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 setFocusToField()
{
	objSnelBestelForm = document.snelbestelformulier;
	objAdditioneleWinkelwagenForm = document.additionelewinkelwagen;
	objSearchForm = document.zoekformulier;
	objMeerdereArtikelenForm = document.meerdereartikelenformulier;
	
	if ((objAdditioneleWinkelwagenForm != null) && (objAdditioneleWinkelwagenForm != "undefined")) {
		objAdditioneleWinkelwagenForm.one_strBasketName.focus();
	}
	else if ((objSnelBestelForm != null) && (objSnelBestelForm != "undefined")) {
		objSnelBestelForm.intArticleNumber.focus();
	}
	else if ((objMeerdereArtikelenForm != null) && (objMeerdereArtikelenForm != "undefined")) {
		objMeerdereArtikelenForm.intArticleNumber.focus();
	}
	else if ((objSearchForm != null) && (objSearchForm != "undefined")) {
		// switched off because focus deletes the initial text
		//objSearchForm.strKeyword.focus();
	}
	
}


function emptyMethode(objInput) {
	if (objInput.value == "Type hier de naam van de methode") {
		objInput.value = "";
	}
}


function goToCatalogueAndCloseWindow(asg)
{
	curLocation = window.location.href;
	
	newLocation = curLocation.substring(0, curLocation.lastIndexOf("externewebsite"))
	
	newLocation = newLocation + "catalogus/zoeken/ASG"+ asg + "/html.aspx" 
	
	window.parent.opener.location.href = newLocation;
	
	window.close();
}


function kopieerAfname(strItemCode, intYear, newLocation)
{
	//check if this action has been done before
	strItemID = strItemCode.substring(3)
	strActionName = "AFNAMEKOPIE#"+ intYear + " GROEP#"+ strItemID;
	
	blnHasBeenCopiedBefore = false;
	
	for (var i=0; i < afnameCopyActionArray.length; i++)
	{
		if (strActionName == afnameCopyActionArray[i]) 
		{
			blnHasBeenCopiedBefore = true;
		}
	}
	
	// set confirmation text
	strConfirmText = "Alle artikelen en aantallen uit onderstaande lijst worden toegevoegd aan uw winkelwagen.";
	
	if (blnHasBeenCopiedBefore) {
		strConfirmText = "U heeft onderstaande lijst al eens toegevoegd aan uw winkelwagen!\nWeet u zeker dat u dit nogmaals wilt doen?"
	}
	
	if (confirm(strConfirmText)) {
		document.kopieerbutton.style.visibility = "hidden";
		document.kopieerbutton.height = "1";
		showElement("evengeduld");
		window.location.href = newLocation;
	} else {
		// do nothing
	}

}


function kopieerWinkelwagen(newLocation)
{
	// set confirmation text
	strConfirmText = "Alle artikelen en aantallen uit onderstaande lijst worden toegevoegd aan uw winkelwagen.";
	
	if (confirm(strConfirmText)) {
		document.kopieerbutton.style.visibility = "hidden";
		document.kopieerbutton.height = "1";
		showElement("evengeduld");
		window.location.href = newLocation;
	} else {
		// do nothing
	}
}


function setShowFotoCookie(newState)
{
	strCurrentLocation = window.location.href;
	
	// clean
	strCurrentLocation = strCurrentLocation.substring(0, strCurrentLocation.lastIndexOf(".aspx")+5);
	
	//alert(strCurrentLocation);
	
	//set
	strNewLocation =  strCurrentLocation + "?fotocookie="+ newState;
	
	//do it
	window.location.href = strNewLocation;
}

function cleanForm(action)
{
	if (action == "meerdereartikelentegelijk")
	{
		document.meerdereartikelenformulier.strArticleNumberList.value = "";
	}
}

/* FORM validation GENERIC */

function ensureInput(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
		
	if (strValue == "") {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}

function ensureGebruikersNaam(objForm, strFieldName, strCultureCode) 
{
	strReturn = ensureInput(objForm, strFieldName, strCultureCode);
	
	gebruikersnaamValue = getValueByFieldName(objForm, strFieldName);
		
	if (strReturn == "") 
	{
		if ((gebruikersnaamValue != "") && (gebruikersnaamValue.indexOf(" ")) > -1) {
			strReturn = "\n> Gebruikersnaam\nLet op: uw gebruikersnaam bevat 1 of meerdere spaties.\nWij raden u aan om een korte gebruikersnaam zonder spaties te kiezen.\n\n";
		}
	}
	return strReturn;

}


function ensureNumber(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
		
	if ( (strValue == "") || (isNaN(strValue)) ) {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}

function ensureKlantNummer(objForm, strFieldName, strCultureCode) 
{
	objForm.strKlantNummer.value = objForm.strKlantNummer.value.replace(".", "");
	
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
	
	if (strValue != "") {
		if ((strValue.length == 7) && (strValue.substring(0,1) == "0"))  {
			objForm.strKlantNummer.value = strValue.substring(1,7);
		}
	}
		
	if ( (strValue == "") || (isNaN(strValue)) || (strValue.indexOf(".") > -1) ) {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}


function ensurePhone(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strValue = strValue.replace(" ","");
	strValue = strValue.replace("-","");
	
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
	
	isEmpty = false;
	if (strValue == "") {
		isEmpty = true;
	}
	
	var objRegExp = /^[0-9]*$/;
	objRegExp.IgnoreCase = true;

	isNumerical = objRegExp.test(strValue);

	is10characters = true;
	if (strValue.length !== 10) {
		is10characters = false;
	}
	
	if ((isEmpty) || !(isNumerical) || !(is10characters)) {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}


function ensureEmailAddress(objForm, strFieldName, strCultureCode) 
{
	strValue = getValueByFieldName(objForm, strFieldName);
	strLabel = getLabelByCultureCode(strFieldName, strCultureCode);
		
	if (isValidEmailAddress(strValue)==false) {
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	} else {
		return "";
	}
}

function checkRadioControl(objForm, strFieldName, strLabel)  {
	
	var objFormField = objForm.elements[strFieldName];	
	intControlLength = objFormField.length;
	bolSelected = false;
	
	objFormField.className = "="; //remove error css class
	
	for (i=0; i < intControlLength;i++){
		if(objFormField[i].checked){
			bolSelected = true;
			return "";
		}
	}     

	if(! bolSelected){
		setBackgroundColorToElement(objForm, strFieldName);
		return "> " + strLabel + "\n";
	}
}


function setBackgroundColorToElement(objForm, strFieldName)
{
	//get object
	objElement = getElementByFieldName(objForm, strFieldName);

	if (objElement.type == "text") {
		objElement.style.backgroundColor = "#ffccff";
	}
}


function getElementByFieldName(objForm, strFieldName)
{
	for (i=0; i < objForm.elements.length; i++) 
	{
		objElement = objForm.elements[i];
		if (objElement.name == strFieldName) {
			return objElement;
		}
	}
}


function getValueByFieldName(objForm, strFieldName)
{
	strValue = "";
	
	for (i=0; i < objForm.elements.length; i++) 
	{
		objElement = objForm.elements[i];
		if (objElement.name == strFieldName) {
			strValue = objElement.value;
		}
	}
	
	return strValue;
}



function isValidEmailAddress(strValue)
{
	var objRegExp  = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	return objRegExp.test(strValue);
}

function getLabelByCultureCode(strFieldName, strCultureCode)
{
	strLabel = "";

	if (strFieldName == "strFirstName") {
		if (strCultureCode == "nl-NL") { strLabel = "Voornaam"; }
		if (strCultureCode == "en-US") { strLabel = "First name"; }
	}
	else if (strFieldName == "strLastName") {
		if (strCultureCode == "nl-NL") { strLabel = "Achternaam"; }
		if (strCultureCode == "en-US") { strLabel = "Last name"; }
	}
	else if (strFieldName == "strFullName") {
		if (strCultureCode == "nl-NL") { strLabel = "Uw naam"; }
		if (strCultureCode == "en-US") { strLabel = "Your name"; }
	}
	else if (strFieldName == "strJobTitle") {
		if (strCultureCode == "nl-NL") { strLabel = "Uw functie"; }
		if (strCultureCode == "en-US") { strLabel = "Your jobtitle"; }
	}
	else if (strFieldName == "strSchool") {
		if (strCultureCode == "nl-NL") { strLabel = "Naam school"; }
		if (strCultureCode == "en-US") { strLabel = "Name School"; }
	}
	else if (strFieldName == "strPhone") {
		if (strCultureCode == "nl-NL") { strLabel = "Telefoon (bestaande uit 10 cijfers: 0XXXXXXXXX)"; }
		if (strCultureCode == "en-US") { strLabel = "Phone"; }
	}
	else if (strFieldName == "strCity") {
		if (strCultureCode == "nl-NL") { strLabel = "Plaats"; }
		if (strCultureCode == "en-US") { strLabel = "City"; }
	}
	else if (strFieldName == "strGebruikersNaam") {
		if (strCultureCode == "nl-NL") { strLabel = "Gebruikersnaam"; }
		if (strCultureCode == "en-US") { strLabel = "Username"; }
	}
	else if (strFieldName == "strEmailAddress") {
		if (strCultureCode == "nl-NL") { strLabel = "E-mail adres"; }
		if (strCultureCode == "en-US") { strLabel = "Emailaddress"; }
	}
	else if (strFieldName == "strKlantNummer") {
		if (strCultureCode == "nl-NL") { strLabel = "Klantnummer"; }
		if (strCultureCode == "en-US") { strLabel = "ClientNumber"; }
	}
	else if (strFieldName == "strZipCode") {
		if (strCultureCode == "nl-NL") { strLabel = "Postcode"; }
		if (strCultureCode == "en-US") { strLabel = "Zipcode"; }
	}
	else if (strFieldName == "strStreet") {
		if (strCultureCode == "nl-NL") { strLabel = "Straat"; }
		if (strCultureCode == "en-US") { strLabel = "Street"; }
	}
	else if (strFieldName == "strHuisNummer") {
		if (strCultureCode == "nl-NL") { strLabel = "Huisnummer"; }
		if (strCultureCode == "en-US") { strLabel = "Number"; }
	}
	else if (strFieldName == "strBasketName") {
		if (strCultureCode == "nl-NL") { strLabel = "Naam"; }
		if (strCultureCode == "en-US") { strLabel = "Name"; }
	}
	else if (strFieldName == "one_strBasketName") {
		if (strCultureCode == "nl-NL") { strLabel = "Naam huidige winkelwagen"; }
		if (strCultureCode == "en-US") { strLabel = "Name current basket"; }
	}
	else if (strFieldName == "ordernummer") {
		if (strCultureCode == "nl-NL") { strLabel = "Ordernummer"; }
		if (strCultureCode == "en-US") { strLabel = "Ordernumber"; }
	}
	else if (strFieldName == "strJaarorderContactName") {
		if (strCultureCode == "nl-NL") { strLabel = "Naam contactpersoon"; }
		if (strCultureCode == "en-US") { strLabel = "Name contact"; }
	}
	else if (strFieldName == "strJaarorderContactEmail") {
		if (strCultureCode == "nl-NL") { strLabel = "E-mailadres contactpersoon"; }
		if (strCultureCode == "en-US") { strLabel = "E-mail contact"; }
	}
	else if (strFieldName == "strJaarorderContactMobile") {
		if (strCultureCode == "nl-NL") { strLabel = "Mobiel nummer contactpersoon (bestaande uit 10 cijfers: 06XXXXXXXX)"; }
		if (strCultureCode == "en-US") { strLabel = "Mobile phone"; }
	}
	else if (strFieldName == "strContactKlantNaam") {
		if (strCultureCode == "nl-NL") { strLabel = "Contactpersoon bij klant"; }
		if (strCultureCode == "en-US") { strLabel = "Contact"; }
	}
	else if (strFieldName == "strContactKlantTelefoonnummer") {
		if (strCultureCode == "nl-NL") { strLabel = "Telefoonnummer (bestaande uit 10 cijfers: 06XXXXXXXX)"; }
		if (strCultureCode == "en-US") { strLabel = "Phone"; }
	}		
	else 
	{
		strLabel = "Veldnaam";
	}
	
 	return strLabel;
}








/* FORM validation CUSTOM */




function isValidBasketSelectForm(objForm)
{
	
}


function isValidAfleverFormMultipleBaskets(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";


	if (objForm.blnIsVakantieLevering.value == "1") {
		strError += checkRadioControl(objForm, "blnIsJaarorder", "Is uw bestelling een jaarorder?");
	}
	
	if (objForm.strFirstMondayLeverweek.value == "") {
		strError += "> Kies een gewenste leverweek"
	}
	
	if (objForm.strFirstMondayLeverweek.options[objForm.strFirstMondayLeverweek.selectedIndex].disabled ) {
		strError += "> Kies een beschikbare leveringsweek.\n";
	}
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);
		// if the radios are hidden, in case of a refresh:
		if (objForm.blnIsVakantieLevering.value == "1") {
			// if the radios are hidden, in case of a refresh:
			showElement('vakantielevering');	
		}			
		return false;
	} else  {
		return true;
	}		

}


function isValidAdditioneleWinkelwagenForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";
	
	if ((objForm.one_strBasketName != "undefined") && (objForm.one_strBasketName != null)) {
		strError += ensureInput(objForm, "one_strBasketName", strCultureCode);
	}
	
	strError += ensureInput(objForm, "strBasketName", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		return true;
	}	

}



function isValidAfleverForm(objForm)
{
	
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";
	var intUserTypeID = objForm.intUserTypeID.value;
	
	var labelNaamBestelling = "Naam Bestelling";
	if (intUserTypeID == "2") {
		labelNaamBestelling = "Naam Offerte";
	}
	
	if (objForm.intUserTypeID.value == "3")
	{
		strError += ensureInput(objForm, "strFirstName", strCultureCode);
		strError += ensureInput(objForm, "strLastName", strCultureCode);
		strError += ensureEmailAddress(objForm, "strEmailAddress", strCultureCode);
		strError += ensurePhone(objForm, "strPhone", strCultureCode);
		strError += ensureInput(objForm, "strStreet", strCultureCode);
		strError += ensureInput(objForm, "strHuisNummer", strCultureCode);
		strError += ensureInput(objForm, "strZipCode", strCultureCode);
		strError += ensureInput(objForm, "strCity", strCultureCode);
	} 
	else if (objForm.intUserTypeID.value == "1")
	{
		strError += ensureEmailAddress(objForm, "strEmailAddress", strCultureCode);

		if (objForm.blnIsVakantieLevering.value == "1") {
			strError += checkRadioControl(objForm, "blnIsJaarorder", "Bevat uw bestelling een (deel)jaarorder en\/of een methode invoering?");
		}
			
		if (objForm.strFirstMondayLeverweek.options[objForm.strFirstMondayLeverweek.selectedIndex].disabled ) {
			strError += "> Kies een beschikbare leveringsweek.\n";
		}
	}
	
	if (objForm.strFirstMondayLeverweek.value == "") {
		strError += "> Kies een gewenste leverweek"
	}
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);
		if (objForm.blnIsVakantieLevering.value == "1") {
			// if the radios are hidden, in case of a refresh:
			showElement('vakantielevering');	
		}		
		return false;
	} else  {
		return true;
	}	

}

function isValidLeveringsinstructiesForm(objForm)
{
	
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";

	strError += checkRadioControl(objForm, "strJaarorderGewensteLeverdag", "Gewenste leverdag");
	strError += ensureInput(objForm, "strJaarorderContactName", strCultureCode);
	strError += ensureEmailAddress(objForm, "strJaarorderContactEmail", strCultureCode);
	strError += ensurePhone(objForm, "strJaarorderContactMobile", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);	
		return false;
	} else  {
		return true;
	}	

}



function isValidBasketName(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";

	if (objForm.strBasketName.value == "") {
	   strError += "Naam \n";
	}
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld";
		alert(strErrorIntro+ ":\n"+ strError);			
		return false;
	} else  {
		return true;
	}	
	
}


function isValidLoginForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";

	strError += ensureInput(objForm, "strGebruikersNaam", strCultureCode);
	strError += ensureEmailAddress(objForm, "strEmailAddress", strCultureCode);
	strError += ensureKlantNummer(objForm, "strKlantNummer", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld";
		alert(strErrorIntro+ ":\n"+ strError);			
		return false;
	} else  {
		return true;
	}	
	
}


function isValidAanmeldForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";

	strError += ensureKlantNummer(objForm, "strKlantNummer", strCultureCode);
	strError += ensureInput(objForm, "strGebruikersNaam", strCultureCode);
	strError += ensureInput(objForm, "strFirstName", strCultureCode);
	strError += ensureInput(objForm, "strLastName", strCultureCode);
	strError += ensurePhone(objForm, "strPhone", strCultureCode);
	strError += ensureEmailAddress(objForm, "strEmailAddress", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld";
		alert(strErrorIntro+ ":\n"+ strError);			
		return false;
	} else  {
		return true;
	}	

}


function isValidVergeetForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";

	strError += ensureInput(objForm, "strFirstName", strCultureCode);
	strError += ensureInput(objForm, "strLastName", strCultureCode);
	strError += ensureEmailAddress(objForm, "strEmailAddress", strCultureCode);
	strError += ensureNumber(objForm, "strKlantNummer", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld";
		alert(strErrorIntro+ ":\n"+ strError);			
		return false;
	} else  {
		return true;
	}	
}




function isValidAccountForm(objForm)
{
	var strCultureCode = "nl-NL";
	var strError = "";
	var strErrorIntro = "";

	strError += ensureInput(objForm, "strFirstName", strCultureCode);
	strError += ensureInput(objForm, "strLastName", strCultureCode);
	strError += ensureEmailAddress(objForm, "strEmailAddress", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld";
		alert(strErrorIntro+ ":\n"+ strError);			
		return false;
	} else  {
		return true;
	}	

}

function isValidSearchForm(objForm)
{
	isValid = true;
	strValue = objForm.strKeyword.value;
	
	if (strValue == "") {
		isValid = false;
	}
	if ( (strValue != "") && (strValue.length < 2) ) {
		alert("Het zoekwoord moet minimaal 2 letters bevatten");
		isValid = false;
	}
	
	return isValid;
}

function isValidBestelling(objForm)
{
	var strError = "";

	if (objForm.intNumberOfItems.value == "0") {
		strError += "FOUT: U kunt geen lege winkelwagen bestellen";
	}
			
	if (strError != "")  {
		alert(strError);			
		return false;
	} else  {
		return true;
	}	
}

function isValidAanvraagForm(objForm) 
{
	var strError = "";
	var strCultureCode = "nl-NL";
	
	strError += ensureInput(objForm, "strFullName", strCultureCode);
	strError += ensureInput(objForm, "strJobTitle", strCultureCode);
	strError += ensureInput(objForm, "strSchool", strCultureCode);
	strError += ensureInput(objForm, "strStreet", strCultureCode);
	strError += ensureInput(objForm, "strHuisNummer", strCultureCode);
	strError += ensureInput(objForm, "strZipCode", strCultureCode);
	strError += ensureInput(objForm, "strCity", strCultureCode);
	strError += ensureEmailAddress(objForm, "strEmailAddress", strCultureCode);
	strError += ensurePhone(objForm, "strPhone", strCultureCode);
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		return true;
	}	

}

function hideSubmitButtons()
{
	document.bestelformulier.disable = true;
	
	hideElement("button-top");
	hideElement("button-bottom");
}






/* POPUP.js */

popup = {
    defaultwidth : 917,
    defaultheight: 738,
    popwin : null,
    
    open : function(aObj, w, h)
    {

        if (typeof(aObj) == 'undefined')
            return false;

        if (typeof(w) != 'undefined' && typeof(h) != 'undefined')
        {

            var my = screen.height - 35;   // Assume some sort of taskbar
            var mx = screen.width;
            
            if (w > mx)
                w = mx;
            if (h > my)
                h = my;
        }
        else
        {
            w = this.defaultwidth;
            h = this.defaultheight;
        }
        
        this.popwin = open(aObj.href, 'folder', 'width=' + w + ',height=' + h + ',status=no,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no');
        return false;
    },
    
    redirect : function(aObj)
    {
       
        if (typeof(aObj) == 'undefined')
            return false;
            
        if (opener.closed)
            return true;    // Lost my parent :(

        opener.location.href = aObj.href;
        close();
        
        return false;
    }
}

/* Klantenservice */



function isValidMeldingsFormulier(objForm)
{
	var oneSelected = false;
	
	for (i=0; i < objForm.elements.length; i++)
	{
		objElement = objForm.elements[i];
		if (objElement.type == "select-one")
		{
			if (objElement.selectedIndex > 0) {
				oneSelected = true;
			}
		}	
	}
	
	if (oneSelected == false)  {
		alert("Je hebt nog geen melding geselecteerd.");			
		return false;
	} else  {
		return true;
	}

}

function isValidRetourenFormulier(objForm)
{
	var oneSelected = false;
	var strCultureCode = "nl-NL";
	var strError = "";
	
	if (objForm.bitTeWeinigOnly.value == "0")  {
		for (i=0; i < objForm.elements.length; i++)
		{
			objElement = objForm.elements[i];
			if (objElement.type == "select-one")
			{
				if (objElement.selectedIndex > 0) {
					oneSelected = true;
				}
			}	
		}
		
		if (oneSelected == false)  {
			strError = "> Selecteer een aantal dozen.\n";			
		}
	}
	
	if (objForm.intUserTypeID.value == "5")  {
		strError += ensureInput(objForm, "strContactKlantNaam", strCultureCode);
		strError += ensureInput(objForm, "strContactKlantTelefoonnummer", strCultureCode);
	} 
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		return true;
	}
}



function isValidSpecificeerForm(objForm)
{
	var strError = "";
	
	for (i=0; i < objForm.elements.length; i++)
	{
		var inputValue = objForm.elements[i].value;
		var className = objForm.elements[i].className;
		var inputID = objForm.elements[i].id;
		
		if (className.indexOf("required") > -1) {
			if (className.indexOf("number") > -1) {
				if (isNaN(inputValue)) {
					strError = "> Aantal \n";
				}
			} else if (inputID.indexOf("opmerking_1") > -1) {
				if (inputValue == "") {
					strError = "> Opmerking \n";
				}
				
			}
		}	
	}
	
	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		return true;
	}	

}


function isValidKlachtenFormulier(objForm)
{
	var strError = "";
	var strCultureCode = "nl-NL";
		
	if (objForm.ordernummer) { strError += ensureInput(objForm, "ordernummer", strCultureCode); }
	
	if (objForm.opmerking.value == "")
	{
		objForm.opmerking.style.backgroundColor = "#ffccff";
		strError += "> Opmerking";
	}

	if (strError != "")  {
		strErrorIntro = "De volgende velden zijn niet (goed) ingevuld: \n\n";
		alert(strErrorIntro + strError);			
		return false;
	} else  {
		return true;
	}	
}


function checkIsVakantieLevering(strSummerHolidayStartdate,strSummerHolidayEnddate,strApplicationPath,strAction) 
{
	var objForm = document.aflevergegevens;
	var objDeliveryDate = getDateByString(objForm.strFirstMondayLeverweek.value);
	var objSummerHolidayStartdate = getDateByString(strSummerHolidayStartdate);
	var objSummerHolidayEnddate = getDateByString(strSummerHolidayEnddate);
	
	//check if desired DeliveryDate is in holidayperiod 
	if ((objDeliveryDate >= objSummerHolidayStartdate) && (objDeliveryDate <= objSummerHolidayEnddate)) {
		showElement('vakantielevering');
		// set hidden formfield blnIsVakantieLevering to "1" so isValidAfleverForm will ensure that input 'jaarorder' has a value
		objForm.blnIsVakantieLevering.value = "1";
	}
	else {
		// hide div#vakantielevering and reset values hidden formfields
		hideElement("vakantielevering");
		var radios = objForm.blnIsJaarorder;
		for (var i = 0; i < radios.length; ++i)
		{
			radios[i].checked = false;
		}
		objForm.blnIsVakantieLevering.value = "0";
		if (strAction == "aflevergegevens") {
			objForm.strSuccessUrl.value = strApplicationPath + "/kassa/bestellingcontroleren/html.aspx";
		}
		else {
			objForm.strSuccessUrl.value = strApplicationPath + "/kassa/meerderebestellingencontroleren/html.aspx";
		}
	}
}

function getDateByString(strDate) 
{
	var Year = strDate.substr(6,4);
	var Month = strDate.substr(0,2);
	Month = (parseInt(Month,10) - 1);
	var Day = strDate.substr(3,2);
	
	var objDate = new Date(Year,Month,Day);
	return objDate
}

function setSuccesUrlAfleverForm(strApplicationPath,strNewSuccessUrl,strOriginalSuccessUrl)
{
	var objForm = document.aflevergegevens;
	var radios = objForm.blnIsJaarorder;
	
	//check wich radio is selected and set value hidden formfield strSuccessUrl
	for (var i = 0; i < radios.length; ++i)
	{
		if (radios[i].checked) {
			if (radios[i].value == "1") {
				objForm.strSuccessUrl.value = strApplicationPath + strNewSuccessUrl //strApplicationPath + "/kassa/leveringsinstructies/html.aspx";
			}
			else {
				objForm.strSuccessUrl.value = strApplicationPath + strOriginalSuccessUrl //strApplicationPath + "/kassa/bestellingcontroleren/html.aspx";
			}
		}
	}
	
}

function showVakantielevering(strSummerHolidayStartdate,strSummerHolidayEnddate,strAction)
{
	if ((strAction == "aflevergegevens") || (strAction == "aflevergegevensmeerderewinkelwagens")) {
		var objForm = document.aflevergegevens;
		var objDeliveryDate = getDateByString(objForm.strFirstMondayLeverweek.value);
		var objSummerHolidayStartdate = getDateByString(strSummerHolidayStartdate);
		var objSummerHolidayEnddate = getDateByString(strSummerHolidayEnddate);

		if ((objDeliveryDate >= objSummerHolidayStartdate) && (objDeliveryDate <= objSummerHolidayEnddate)) {
				showElement("vakantielevering");
				objForm.blnIsVakantieLevering.value = "1";
		}
	}

}


function checkInputLenght(x,y)
{
	if (y.length==x.maxLength) {
		var objForm = document.ticketitemformulier;
		var intTabindex = x.tabIndex;
		for (var i = 0; i < objForm.elements.length; i++) {
				if (objForm.elements[i].tabIndex == intTabindex + 1) {
					objForm.elements[i].focus();
			}
		}
	}
}

