


function zoomImage(objForm, strImage)
{
	strImageZoomPage = objForm.strImageZoomPage.value;
	popupUrl = strImageZoomPage + "?strImage="+strImage
	
	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 + "_amount";
	
	//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 formatThisAmount(objElement)
{
	var strValue = objElement.value;
	
	//remove spaces
	strValue = strValue.replace(" ", "");
	
	//replace comma's
	strValue = strValue.replace(".", ",");
	
	//cut off decimals
	positionOfComma = strValue.indexOf(",");
	if (positionOfComma > 0) {
		strValue = strValue.substring(0, positionOfComma + 2);
	} 
	
	//set new value
	objElement.value = strValue;
}

function cleanAmountWhenNotValid(objElement)
{
	var strValue = objElement.value;
	if (!isValidAmount(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.amount;
	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 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 setFocusToSearchField()
{
	objSearchForm = document.zoekformulier;

	if ((objSearchForm != null) && (objSearchForm != "undefined")) {
		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/artikelsubgroep/"+ asg + "/" 
	
	window.parent.opener.location.href = newLocation;
	
	window.parent.close();
}


function kopieerAfname(strItemCode, intYear, newLocation)
{
	//check if this action has been done before
	strItemID = strItemCode
	strActionName = "AFNAMEKOPIE#"+ intYear + " GROEP#"+ strItemID;
	//alert(strActionName);
	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;
}



/* BASKET */




function isValidCatalogusBestelForm(objForm)
{
	//showProgressBar();
}

function isValidSnelBestelForm(objForm)
{
	strArticleNumber = objForm.intArticleNumber.value;
	strAmount = objForm.amount.value;

	if ((strArticleNumber != "") && (strAmount == "")) 
	{
		objForm.amount.focus();
		return false;
	} 
	else 
	{
		return isValidBestelForm(objForm, true);		
	}
	
}


function isValidBestelForm(objForm, blnCheckArticleNumber)
{
	var strAlert = "";
	
	objArticleID = objForm.intArticleNumber;
	objAmount = objForm.amount;
	
	if (blnCheckArticleNumber) {
		strAlert += checkArtikelNummer(objArticleID);
	}
	
	strAlert += checkAmount(objAmount);
	
		
	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 setFormAction(objForm, strAction)
{
	//SET action
	objForm.action = strAction;
}

function setSuccessUrl(objForm, strNewSuccessUrl)
{
	objForm.strSuccessUrl.value = strNewSuccessUrl;
}


function checkArtikelNummer(objInputField)
{
	// GET value
	strArtikelNummer = ""+ objInputField.value;
	
	// is valid?
	isValid = isValidArtikelNummer(strArtikelNummer);

	if (isValid==false) {
		return "> Artikelnummer onbekend, uitverkocht of uit de collectie\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 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)
{
	isValid = false;
	
	if (strValue != "") 
	{
		var objRegExp = /^\d+\,\d+$/;
		if ((!isNaN(strValue) || objRegExp.test(strValue))) {
			isValid = true;
		}
	}
	
	return isValid;
}




function ensureAmount(objInputField)
{
	strAlert = checkAmount(objInputField);
	if (strAlert != "") {
		alert("Een aantal mag alleen cijfers bevatten");
	}
}

function checkAmount(objInputField)
{
	strAmount = objInputField.value;

	if (isValidAmount(strAmount)==false) {
		return "> Aantal\n";
	} else {
		return "";
	}
}

function handleToevoegenButton(objForm, intSelectedArticleNumber)
{
	strInputName = "amount";
			
	strNameOfAmountElement = intSelectedArticleNumber +"_"+ strInputName;
	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";
	} 
	
	// 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 +"_amount";
	objAmountField = getElementByName(objForm, strNameOfAmountElement);
	objForm.amount.value = objAmountField.value;
}




function removeItemFromBasket(intArticleNumber, strArticleFullName)
{
	objForm = document.winkelwagenformulier;
	
	strArticleCode = getArticleCode(intArticleNumber);
	
	if (confirm("Het onderstaande artikel wordt uit uw winkelwagen verwijderd:\n\n"+ strArticleFullName + " (" + strArticleCode + ")")) {
		setFormAction(objForm, "/winkelwagen/itemverwijderen/");
		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?")) 
	{
		setFormAction(objForm, "/winkelwagen/alleitemsverwijderen/");
		objForm.submit();
	}
	else 
	{
		// do nothing	
	}
}





function updateBasket(objForm)
{
	setFormAction(objForm, "/winkelwagen/updateitems/");
	
	objForm.submit();
}


function getArticleCode(intArticleNumber)
{
	strArticleCode = ""+intArticleNumber;
	strArticleCode = strArticleCode.substring(0,3) + "." + strArticleCode.substring(3);
	return strArticleCode;
}

function deleteBasket(url, strBasketName)
{	
	var strConfirmationQuestion = "Weet u zeker dat u de winkelwagen '"+ strBasketName +"' wilt verwijderen?";
	isConfirmed = confirm(strConfirmationQuestion);	

	if (isConfirmed)	
	{
		window.location.href = url;	
	}
	
}


function setActiveBasket(objSelect, strActiveerURL, strRedirectURL)
{
	selIndex = objSelect.selectedIndex;
	guid = objSelect.options[selIndex].value;
	
	window.location.href = strActiveerURL + guid + "/?url="+ strRedirectURL;
}


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)	
	{
		setFormAction(objForm, "/winkelwagen/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(8);
				if ((strSubString == "amount") && (strElementName != intSelectedArticleNumber + "_amount")) {
					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 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();
			}
		}
	}
}

function setRowClass(objSelect, rowID, originalClass)
{
	if (objSelect.value != "") {	
		objRow = document.getElementById(rowID);
		objRow.className = "selected";
	} else {
		objRow.className = originalClass;
	}
}




