var currentCategoryId = null;
function setCategory( value ) {
	hideOptionsContainer();

	valueSplit = value.split("|");
	categoryId = valueSplit[0];
	newCategoryDiv = document.getElementById( "questionCategoryContainer_" + categoryId );

	if ( currentCategoryId ) {
		currentCategoryDiv = document.getElementById( "questionCategoryContainer_" + currentCategoryId );
		if ( currentCategoryDiv ) {
			currentCategoryDiv.style.display = "none";
		}
	}
	if ( currentSubCategoryId ) {
		currentSubCategoryDiv = document.getElementById( "questionSubCategoryContainer_" + currentSubCategoryId );
		if ( currentSubCategoryDiv ) {
			currentSubCategoryDiv.style.display = "none";
		}
	}
	
	if ( newCategoryDiv ) {
		newCategoryDiv.style.display = "block";
		selectedMenu = document.getElementById( "questionCategory_" + categoryId );
		if ( selectedMenu ) {
			selectedMenu.selectedIndex = 0;
		}
	}
	
	currentCategoryId = categoryId;
	
	setExtraOptions( valueSplit[1], valueSplit[2] );
	getAnswer( categoryId );
}

var currentSubCategoryId = null;
function setSubCategory( value ) {
	hideOptionsContainer();

	valueSplit = value.split("|");
	subCategoryId = valueSplit[0];
	newSubCategoryDiv = document.getElementById( "questionSubCategoryContainer_" + subCategoryId );

	if ( currentSubCategoryId ) {
		currentSubCategoryDiv = document.getElementById( "questionSubCategoryContainer_" + currentSubCategoryId );
		if ( currentSubCategoryDiv ) {
			currentSubCategoryDiv.style.display = "none";
		}
	}
	
	if ( newSubCategoryDiv ) {
		newSubCategoryDiv.style.display = "block";
		selectedMenu = document.getElementById( "questionSubCategory_" + subCategoryId );
		if ( selectedMenu ) {
			selectedMenu.selectedIndex = 0;
		}
	}
	
	currentSubCategoryId = subCategoryId;
		
	setExtraOptions( valueSplit[1], valueSplit[2] );
	getAnswer( subCategoryId );
}

function setSubSubCategory( value ) {	
	hideOptionsContainer();

	valueSplit = value.split("|");
	subSubCategoryId = valueSplit[0];
	
	setExtraOptions( valueSplit[1], valueSplit[2] );
	getAnswer( subSubCategoryId );
}

function hideOptionsContainer() {
	var optionsContainerdiv = document.getElementById( "optionsContainer" );
	optionsContainerdiv.style.display = "none";
}

function doAnswerResult( text ) {
	var optionsContainerdiv = document.getElementById( "optionsContainer" );
	var answerContainerDiv = document.getElementById( "answerContainer" );

	if( optionsContainerdiv && answerContainerDiv ) {
		answerContainerDiv.style.display = "block";
		if( text.length == 0 ) {
			optionsContainerdiv.style.display = "none";
			answerContainerDiv.innerHTML = "Kies een onderwerp...";
		}
		else {
			optionsContainerdiv.style.display = "block";
			answerContainerDiv.innerHTML = text;
		}
	}
}

function setExtraOptions( allowQuestion ) {
	elementQuestion = document.getElementById( "questionContainer" );
	if ( allowQuestion == "Y" ) {
		elementQuestion.style.display = "block";
	}
	else {
		elementQuestion.style.display = "none";
	}
}

function submitForm() {
	if ( document.faqForm.question.value != '' && document.faqForm.email.value != '' && validateEmail( document.faqForm.email.value ) ) {
		document.faqForm.submit();
	}
	else {
		document.getElementById( "warning" ).style.display = "block";
	}
}

function validateEmail( email ) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = email;
	if( reg.test(address) == false ) {
		return false;
	}
	return true;
}
