// Remove Dialog box
function removeDiag(trainingID, theLocation, theTitle){
	var fRet;
	var location = theLocation + trainingID;
	var message = ("Item '" + theTitle + "' verwijderen uit het database?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	}
}

// Activate user Dialog box
function activateDiag(userID, theLocation, theTitle){
	var fRet;
	var location = theLocation + userID;
	var message = ("Gebruiker met ID #" + theTitle + " accepteren en login gegevens versturen?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	}
}

// Deactivate user Dialog box
function deactivateDiag(userID, theLocation, theTitle){
	var fRet;
	var location = theLocation + userID;
	var message = ("Gebruiker met ID #" + theTitle + " deactiveren?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	}
}

// Archive user Dialog box
function archiveDiag(userID, theLocation, theTitle){
	var fRet;
	var location = theLocation + userID;
	var message = ("Nieuws item met ID #" + theTitle + " archiveren?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	}
}

// de-archive user Dialog box
function dearchiveDiag(userID, theLocation, theTitle){
	var fRet;
	var location = theLocation + userID;
	var message = ("Nieuws item met ID #" + theTitle + " actief maken?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	}
}

// Deactivate user Dialog box
function reactivateDiag(userID, theLocation, theTitle){
	var fRet;
	var location = theLocation + userID;
	var message = ("Gebruiker met ID #" + theTitle + " activeren?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	}
}

// Remove old events
function remeventDiag(theLocation){
	var fRet;
	var location = theLocation;
	var message = ("Alle oude/verlopen events verwijderen?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	}
}

// Return pressed?
function returnPress(keyPress){
	if(window.event){
		if(keyPress.keyCode == 13){
			submitLogin();
		}
	} else if(keyPress.which){
		if(keyPress.which == 13){
			submitLogin();
		}
	}
}

// Change user rank
function changeRank(userID, currentSelected, phpBBuserid){
	var optionID = document.getElementById("selectRank_" + userID).selectedIndex;
	var location = "index.php?mode=cms&section=gebruikers&view=overzicht&action=swaprank&srid=" + phpBBuserid + "_" + document.getElementById("selectRank_" + userID).value;
	var message = ("Weet u zeker dat u de rang van gebruiker met ID #" + userID + " wilt wijzigen naar '" + document.getElementById("selectRank_" + userID).options[optionID].text + "'?");
	fRet = confirm(message);
	if(fRet){
		this.location.href = location;
	} else {
		document.getElementById("selectRank_" + userID).value = currentSelected;
	}
}

// Menubuttons
function swapMenuOver(theObject, theImage){
	if(checkBrowser()){
		newImage = "url(templates/images/menuButtons/" + theImage + ")";
		document.getElementById(theObject).style.backgroundImage = newImage;
	} else {
		document.getElementById(theObject).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='templates/images/menuButtons/" + theImage + "')";
	}
}
function swapMenuOut(theObject, theImage){
	if(checkBrowser()){
		newImage = "url(templates/images/menuButtons/" + theImage + ")";
		document.getElementById(theObject).style.backgroundImage = newImage;
	} else {
		document.getElementById(theObject).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='templates/images/menuButtons/" + theImage + "')";
	}
}

// Sidebar
var theSetElement = 0;
function expand(theActivityID){
	// First hide last theActivityID
	if((theActivityID != theSetElement) && (theSetElement != 0)){
		document.getElementById('elementID_' + theSetElement).style.display = 'none';
	}

	// Get display mode on current theActivityID, then change it's display
	theElement = document.getElementById('elementID_' + theActivityID).style.display;
	if(theElement == 'none'){
		theSetElement = theActivityID;
		document.getElementById('elementID_' + theActivityID).style.display = 'block';
	} else {
		document.getElementById('elementID_' + theActivityID).style.display = 'none';
	}
}

// Tooltip functions
var theObj="";
function toolTip(text,me) {
	theObj=me;
	theObj.onmousemove=updatePos;
	document.getElementById('toolTipBox').innerHTML=text;
	document.getElementById('toolTipBox').style.display="block";
	window.onscroll=updatePos;
}
function updatePos() {
	var ev=arguments[0]?arguments[0]:event;
	var x=ev.clientX;
	var y=ev.clientY;
	diffX=24;
	diffY=0;
	document.getElementById('toolTipBox').style.top  = y-2+diffY+document.body.scrollTop+ "px";
	document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px";
	theObj.onmouseout=hideMe;
}
function hideMe() {
	document.getElementById('toolTipBox').style.display="none";
}

// Browser check
function checkBrowser(){
	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer"){
		return false;
	} else {
		return true;
	}
}

function gotoURL(theURL){
	var location = theURL;
	this.location.href = location;
}

// Hover botton for IE6+ and FF using the browser check
function loginOver(elementID){
	document.getElementById(elementID).style.cursor='pointer';
	if(checkBrowser()){
		newImage = "url(templates/images/login_rollover.png)";
		document.getElementById(elementID).style.backgroundImage=newImage;
	} else {
		document.getElementById(elementID).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='templates/images/login_rollover.png')";
	}
}
function loginOut(elementID){
	document.getElementById(elementID).style.cursor='pointer';
	if(checkBrowser()){
		newImage = "url(templates/images/login_off.png)";
		document.getElementById(elementID).style.backgroundImage=newImage;
	} else {
		document.getElementById(elementID).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='templates/images/login_off.png')";
	}
}
function submitLogin(){
	document.getElementById('submitLogin').submit();
}

// Editor image
var theImgObj="";
function displayImageDiv(me){
	theImgObj=me;
	newImage = "url(userfiles/image/nieuws/" + theImgObj.value + ")";
	document.getElementById('displayImage').style.backgroundImage=newImage;
}
function fullSize(me){
	theImgObj=me;
	document.getElementById('displayImage').style.height="175px";
	theImgObj.onmouseout=hideImage;
}
function hideImage() {
	if(checkBrowser()){
		document.getElementById('displayImage').style.height="34px";
	} else {
		document.getElementById('displayImage').style.height="34px";
	}
}
function setImage(me){
	alert(me);
	theImgObj=me;
	newImage = "url(userfiles/image/nieuws/" + theImgObj.value + ")";
	document.getElementById('displayImage').style.backgroundImage=newImage;
}

// Input checks
function checkNiewsFields(theDocument){
	if(theDocument.content_title.value == ""){
		alert('Het veld "Titel" is een verplicht veld.');
		theDocument.content_title.focus;
		return false;
	}
	
	if(theDocument.content_image.selectedIndex == 0){
		if(confirm('U heeft geen afbeelding geselecteerd, weet u zeker dat u het nieuws item op wilt slaan?')){
			// Nothing
		} else {
			theDocument.content_image.focus;
			return false;
		}
	}
	
	if(theDocument.content_niveau.selectedIndex == 0){
		if(confirm('U heeft geen gebruikers niveau geselecteerd, het bericht zou voor iedereen zichtbaar zijn. Weet u dit zeker?')){
			// Nothing
		} else {
			theDocument.content_niveau.focus;
			return false;
		}
	}
	
	if(theDocument.content_intro.value == ""){
		alert('Het veld "Voorpagina tekst" is een verplicht veld.');
		theDocument.content_intro.focus;
		return false;
	}
	
	var oEditor = FCKeditorAPI.GetInstance('contentEditor') ;
	var content = oEditor.GetXHTML(true);
	if(content == ""){
		alert('Het veld "Hoofdtekst" is een verplicht veld.');
		theDocument.contentEditor.focus;
		return false;
	}
	return true;
}

function checkQuestionFields(theDocument){
	if(theDocument.question_name.value == ""){
		alert('Het veld "Naam" is een verplicht veld.');
		theDocument.question_name.focus;
		return false;
	}
	
	if(theDocument.question_email.value == ""){
		alert('Het veld "E-mail" is een verplicht veld.');
		theDocument.question_email.focus;
		return false;
	}
	
	if(theDocument.question_text.length < 1) {
		alert('U heeft bij vraag niets ingevuld.');
		theDocument.question_text.focus;
		return false;
	}
	return true;
}

function checkAlgemeenFields(theDocument){
	if(theDocument.content_title.value == ""){
		alert('Het veld "Titel" is een verplicht veld.');
		theDocument.content_title.focus;
		return false;
	}
	return true;
}

function checkActivFields(theDocument){
	if(theDocument.content_title.value == ""){
		alert('Het veld "Titel" is een verplicht veld.');
		theDocument.content_title.focus;
		return false;
	}
	
	if(theDocument.content_niveau.selectedIndex == 0){
		if(!confirm('U heeft geen gebruikers niveau geselecteerd, het bericht zou voor iedereen zichtbaar zijn. Weet u dit zeker?')){
			return false;
		}
	}
	
	var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
	var matchArray = theDocument.content_date.value.match(datePat);
	if (matchArray == null) {
		alert("Ongeldig invoer, vul bij datum jjjj-mm-dd in.");
		return false;
	}
	
	year = matchArray[1];
	month = matchArray[3];
	day = matchArray[5];
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Ongeldig invoer, maand "+month+" heeft geen 31 dagen.")
		return false;
	}
	
	if (month < 1 || month > 12) { // check month range
		alert("Ongeldig invoer, maand moet een getal zijn van 1 tot 12.");
		return false;
	}
	
	if (day < 1 || day > 31) {
		alert("Ongeldig invoer, dag moet een getal zijn van 1 tot 31.");
		return false;
	}
	
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("Ongeldig invoer, Februari " + year + " heeft geen " + day + " dagen.");
			return false;
		}
	}
	
	if(theDocument.content_time_hour.value == ""){
		alert('Tijdstip is een verplicht veld.');
		theDocument.content_time_hour.focus();
		return false;
	}
	
	if(theDocument.content_time_minute.value == ""){
		alert('Tijdstip is een verplicht veld.');
		theDocument.content_time_minute.focus();
		return false;
	}
	
	var error = 0;
	hour = parseInt(theDocument.content_time_hour.value);
	minute = parseInt(theDocument.content_time_minute.value);
	
	if((hour >= 24) || (hour < 0)){
		error = 1;
	}
	
	if((minute >= 60) || (minute < 0)){
		error = 1;
	}
	
	if(error == 1){
		alert('Ongeldig tijdstip opgegeven.');
		form.agendaTime.focus();
		return false;
	}
	
	if(theDocument.content_location.value == ""){
		alert('Het veld "Locatie" is een verplicht veld.');
		theDocument.content_location.focus;
		return false;
	}
	
	if(theDocument.content_intro.value == ""){
		alert('Het veld "Voorpagina tekst" is een verplicht veld.');
		theDocument.content_intro.focus;
		return false;
	}
	
	var oEditor = FCKeditorAPI.GetInstance('contentEditor') ;
	var content = oEditor.GetXHTML(true);
	if(content == ""){
		alert('Het veld "Hoofdtekst" is een verplicht veld.');
		theDocument.contentEditor.focus;
		return false;
	}
	return true;
}

// Reisverslagen
function checkReisFields(theDocument){
	if(theDocument.content_title.value == ""){
		alert('Het veld "Titel" is een verplicht veld.');
		theDocument.content_title.focus;
		return false;
	}
	
	if(theDocument.content_location.value == ""){
		alert('Het veld "Locatie" is een verplicht veld.');
		theDocument.content_location.focus;
		return false;
	}
	
	var datePat = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
	var matchArray = theDocument.content_date.value.match(datePat);
	if (matchArray == null) {
		alert("Ongeldig invoer, vul bij datum jjjj-mm-dd in.");
		return false;
	}
	
	year = matchArray[1];
	month = matchArray[3];
	day = matchArray[5];
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Ongeldig invoer, maand "+month+" heeft geen 31 dagen.")
		return false;
	}
	
	if (month < 1 || month > 12) { // check month range
		alert("Ongeldig invoer, maand moet een getal zijn van 1 tot 12.");
		return false;
	}
	
	if (day < 1 || day > 31) {
		alert("Ongeldig invoer, dag moet een getal zijn van 1 tot 31.");
		return false;
	}
	
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("Ongeldig invoer, Februari " + year + " heeft geen " + day + " dagen.");
			return false;
		}
	}
	
	if(theDocument.content_niveau.selectedIndex == 0){
		if(!confirm('U heeft geen gebruikers niveau geselecteerd, het bericht zou voor iedereen zichtbaar zijn. Weet u dit zeker?')){
			return false;
		}
	}
	
	if(theDocument.content_intro.value == ""){
		alert('Het veld "Voorpagina tekst" is een verplicht veld.');
		theDocument.content_intro.focus;
		return false;
	}
	
	var oEditor = FCKeditorAPI.GetInstance('contentEditor') ;
	var content = oEditor.GetXHTML(true);
	if(content == ""){
		alert('Het veld "Hoofdtekst" is een verplicht veld.');
		theDocument.contentEditor.focus;
		return false;
	}
	return true;
}

// Profile fields
function checkProfileFields(theDocument){
	if(theDocument.pf_first_name.value == ""){
		alert('Voornaam is een verplicht veld.');
		theDocument.pf_first_name.focus();
		return false;
	}
	
	if(theDocument.pf_last_name.value == ""){
		alert('Achternaam is een verplicht veld.');
		theDocument.pf_last_name.focus();
		return false;
	}
	
	if(theDocument.pf_street_name.value == ""){
		alert('Adres is een verplicht veld.');
		theDocument.pf_street_name.focus();
		return false;
	}
	
	if(theDocument.pf_city_name.value == ""){
		alert('Plaats is een verplicht veld.');
		theDocument.pf_city_name.focus();
		return false;
	}
	
	if(theDocument.pf_postal_code.value == ""){
		alert('Postcode is een verplicht veld.');
		theDocument.pf_postal_code.focus();
		return false;
	}

	year = theDocument.bday_year.selectedIndex;
	month = theDocument.bday_month.selectedIndex;
	day = theDocument.bday_day.selectedIndex;

	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Ongeldig invoer, maand "+month+" heeft geen 31 dagen.")
		return false;
	}
	
	if ((month != 0 || day != 0) && year <= 0) {
		alert("Ongeldig invoer, jaar moet ingevuld worden als er een dag en/of maand aangegeven is.");
		return false;
	}
	
	if (month < 1 || month > 12) { // check month range
		alert("Ongeldig invoer, maand moet een getal zijn van 1 tot 12.");
		return false;
	}
	
	if (day < 1 || day > 31) {
		alert("Ongeldig invoer, dag moet een getal zijn van 1 tot 31.");
		return false;
	}
	
	
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("Ongeldig invoer, Februari " + year + " heeft geen " + day + " dagen.");
			return false;
		}
	}
	
	if(theDocument.pf_email.value == ""){
		alert('E-mail is een verplicht veld.');
		theDocument.pf_email.focus();
		return false;
	}
	
	if(theDocument.pf_password.value != ""){
		if(theDocument.pf_password_2.value == ""){
			alert('Bij het wijzigen van uw wachtwoord is het verplicht om het nieuwe wachtwoord twee maal in te vullen.');
			theDocument.pf_password_2.focus();
			return false;
		} else if (theDocument.pf_password.value != theDocument.pf_password_2.value){
			alert('De door u opgegeven wachtwoorden komen niet overeen.');
			theDocument.pf_password.focus();
			return false;
		}
	}
	return true;
}

// Aanmeld fields
function checkAanmeldFields(theDocument){
	if(theDocument.pf_first_name.value == ""){
		alert('Voornaam is een verplicht veld.');
		theDocument.pf_first_name.focus();
		return false;
	}
	
	if(theDocument.pf_last_name.value == ""){
		alert('Achternaam is een verplicht veld.');
		theDocument.pf_last_name.focus();
		return false;
	}
	
	if(theDocument.pf_street_name.value == ""){
		alert('Adres is een verplicht veld.');
		theDocument.pf_street_name.focus();
		return false;
	}
	
	if(theDocument.pf_city_name.value == ""){
		alert('Plaats is een verplicht veld.');
		theDocument.pf_city_name.focus();
		return false;
	}
	
	if(theDocument.pf_postal_code.value == ""){
		alert('Postcode is een verplicht veld.');
		theDocument.pf_postal_code.focus();
		return false;
	}

	year = theDocument.bday_year.selectedIndex;
	month = theDocument.bday_month.selectedIndex;
	day = theDocument.bday_day.selectedIndex;

	
	if (day < 1 || day > 31) {
		alert("Ongeldig invoer, dag is een verplicht veld.");
		return false;
	}
	
	if (month < 1 || month > 12) { // check month range
		alert("Ongeldig invoer, maand is een verplicht veld.");
		return false;
	}
	
	if (year <= 0) {
		alert("Ongeldig invoer, jaar is een verplicht veld.");
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Ongeldig invoer, maand "+ month +" heeft geen 31 dagen.")
		return false;
	}
	
	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) {
			alert("Ongeldig invoer, Februari " + theDocument.bday_year.value + " heeft geen " + day + " dagen.");
			return false;
		}
	}
	
	if(theDocument.pf_email.value == ""){
		alert('E-mail is een verplicht veld.');
		theDocument.pf_email.focus();
		return false;
	}
	
	if(theDocument.pf_password.value != ""){
		if(theDocument.pf_password_2.value == ""){
			alert('Bij het wijzigen van uw wachtwoord is het verplicht om het nieuwe wachtwoord twee maal in te vullen.');
			theDocument.pf_password_2.focus();
			return false;
		} else if (theDocument.pf_password.value != theDocument.pf_password_2.value){
			alert('De door u opgegeven wachtwoorden komen niet overeen.');
			theDocument.pf_password.focus();
			return false;
		}
	}
	return true;
}