
function setNewOptionInBox(strValue,strText,selectionBox,selectedOption){
//add a new option to a designated selection box.
		defaultSelected = false;
		selected = false;		
		if(strValue == selectedOption){selected = true;}
		optionName = new Option(strText,strValue, defaultSelected, selected);
		var length = selectionBox.length;
		selectionBox.options[length] = optionName;

}

function deleteOptions(selectionBox){
//delete the existing options except the two (these are the remark and the dotted line)
	nrOfOptions = selectionBox.options.length;
	for (var x=2; x<nrOfOptions; x++){
		selectionBox.options[2] = null;
	}
}

function fillMainGroupSelectionBox(){
//fill the main group selection box
	objField = document.forms[0].maincategory;
	deleteOptions(objField);
	for(intX = 0; intX < arrMainGroup.length; intX++){
		setNewOptionInBox(arrMainGroup[intX][0],arrMainGroup[intX][1],objField,'')
	}
}

function fillSubGroupSelectionBox(strSelectedValue){
//fill the sub group selection box based on the choice made in the main group selection box
	if(strSelectedValue != ""){
		objField = document.forms[0].subcategory;
		deleteOptions(objField);
		for(intX = 0; intX < arrSubGroup.length; intX++){
			if(arrSubGroup[intX][0] == strSelectedValue){
				setNewOptionInBox(arrSubGroup[intX][1],arrSubGroup[intX][2],objField,'')
			}
		}
	}
}

function searchSellers(strSubGroup){
//reload screen including the subgroup id to invoke the search
	if(strSubGroup != ""){
		var strLocation = document.location.toString();
		var intSIDPosition = strLocation.indexOf('SID=');
		if(intSIDPosition > -1){
			strTemp = strLocation.slice(0,intSIDPosition);
			document.location = "http://www.goedkoop.nl/NewSite/voordelig.nl/index.php?SID=" + strSubGroup;
		}
		else{
			document.location = "http://www.goedkoop.nl/NewSite/voordelig.nl/index.php?SID=" + strSubGroup;
		}
	}
}

function setSelectionBoxesSelected(){
//if location contains SID=, a selection has been made, so show that selection in the boxes.
	var strLocation = document.location.toString();
	var intSIDPosition = strLocation.indexOf('SID=');
	if(intSIDPosition > -1){
		strSubGroup = strLocation.slice(intSIDPosition+4)
		//now find the subGroup, and the belonging mainGroup
		for(intX = 0; intX < arrSubGroup.length; intX++){
			if(arrSubGroup[intX][1] == strSubGroup){
				strMainGroup = arrSubGroup[intX][0];
				//now set the main selection box
				objField = document.forms[0].maincategory;
				for(intY = 0; intY < objField.options.length; intY++){
					if(objField.options[intY].value == strMainGroup){
						objField.options[intY].selected = true;
						fillSubGroupSelectionBox(strMainGroup)
						break;
					}			
				}
				//and set the sub selection box
				objField = document.forms[0].subcategory;
				for(intY = 0; intY < objField.options.length; intY++){
					if(objField.options[intY].value == strSubGroup){
						objField.options[intY].selected = true;
						break;
					}					
				}

				break;
			}
		}
	}	
	
}
