var uriwindow;
function $(id)
{
	if(document.getElementById(id))
	{
		return document.getElementById(id);
	}
}

function maxKeyLength(obj, length)
{
	if(obj.value.length > length)
	{
		obj.value = obj.value.substring(0, length);
	}
}
function max_text_length(o_textObj, i_maxChars, o_counterObj)
{
	if(typeof o_textObj != "object")
	{
		o_textObj = $(o_textObj);
	}
	if(typeof o_counterObj != "object")
	{
		o_counterObj = $(o_counterObj);
	}

	if(o_textObj)
	{
		i_diff = i_maxChars - o_textObj.value.length;

		if(i_diff < 0)
		{
			if (window.event)
			{
				window.event.returnValue = false;
			}

			o_textObj.value = o_textObj.value.substring(0,i_maxChars);
			i_diff = i_maxChars - o_textObj.value.length;
		}

		if(o_counterObj)
		{
			if(o_counterObj.tagName.toLowerCase() == "input")
			{
				o_counterObj.value = o_textObj.value.length;
			}
			else
			{
				o_counterObj.innerHTML = o_textObj.value.length;
			}
		}
	}
}

function moveElement(target, newParent)
{
	$(newParent).appendChild($(target));
}
var a_helpText = new Array();
function createHelpText(s_helpText, o_parentNode)
{
	var positionHelpTextIcon = function(obj)
	{
		var myEffect = new Fx.Morph(obj, {duration: 1000, transition: Fx.Transitions.linear.easeIn});

		obj.style.left = (o_parentNode.getWidth() - obj.getPosition(o_parentNode).x - obj.getWidth() - 5) + "px";
		myEffect.start({'opacity': [0,100]});

		obj.removeEvent("load", positionHelpTextIcon);
	}
	var showHelpTextIcon = function() {
		if(!a_helpText[s_helpText])
		{
			helpTextDiv = new Element("div", {
				'html': s_helpText,
				'styles': {
					'position': 'absolute',
					'left': o_helpTextIcon.getPosition($('contentContainer')).x + o_helpTextIcon.getWidth(),
					'top': o_helpTextIcon.getPosition($('pageContent')).y + o_helpTextIcon.getHeight(),
					'width': '200px',
					'padding': '5px',
					'background-color': '#EFEFEF',
					'border': '1px solid black'
				},
				'events': {
					'mouseover': function() {
						this.closeTimeout = true;
						this.mouseOverDiv = true;
					},
					'mouseout': function() {
						this.mouseOverDiv = false;
						closeHelpTextIcon();
					}
				}
			});
			helpTextDiv.mouseOverIcon = false;
			helpTextDiv.mouseOverDiv = false;
			helpTextDiv.closeTimeout = true;
			a_helpText[s_helpText] = helpTextDiv;
			helpTextDiv.inject(o_parentNode);
		}

		o_helpTextIcon.src = "/images/help_hov.gif";
		a_helpText[s_helpText].mouseOverIcon = true;
	}

	var closeHelpTextIcon = function() {
		if(a_helpText[s_helpText])
		{
			if(a_helpText[s_helpText].mouseOverDiv == false && a_helpText[s_helpText].mouseOverIcon == false)
			{
				if(helpTextDiv.closeTimeout == true)
				{
					setTimeout(function()
					{
						helpTextDiv.closeTimeout = false;
						closeHelpTextIcon();
					}, 200);
				}
				else
				{
					o_helpTextIcon.src = "/images/help.gif";
					a_helpText[s_helpText].destroy();
					a_helpText[s_helpText] = undefined;
				}
			}
		}
	}

	var o_helpTextIcon = new Element("img", {
		'src': '/images/help.gif',
		'class': 'helptextdiv',
		'styles': {
			'position': 'relative',
			'opacity': '0'
		},
		'events': {
			'mouseover': function() {
				if(a_helpText[s_helpText])
				{
					a_helpText[s_helpText].closeTimeout = true;
					a_helpText[s_helpText].mouseOverIcon = true;
				}
				showHelpTextIcon();
			},
			'mouseout': function() {
				if(a_helpText[s_helpText])
				{
					a_helpText[s_helpText].mouseOverIcon = false;
				}
				closeHelpTextIcon();
			}//,
			//'load': positionHelpTextIcon
		}
	});

	o_helpTextIcon.positionIcon = function()
	{
		positionHelpTextIcon(this);
	}
	o_helpTextIcon.inject(o_parentNode);
	setTimeout(function()
	{
		o_helpTextIcon.positionIcon();
	}, 100);
}

debugArray = new Array();
debugOn = true;
function debug(msg, targetId)
{
	if(debugOn)
	{
		curDate = new Date();
		dateStr = "["+curDate.getHours()+":"+curDate.getMinutes()+":"+curDate.getSeconds()+"] ";

		debugArray.push(dateStr + msg);
		$(targetId).innerHTML = " <b>-- javascript debug --</b> <br />";
		for(var i = 0; i < debugArray.length && i < 5; i++)
		{
			var c = debugArray.length-i-1;
			$(targetId).innerHTML += debugArray[c]+" <br />";
		}
	}
}

function addArg(s_url, s_newArg)
{
	if(s_url.indexOf("?") > -1)
	{
		return s_url + "&" + s_newArg;
	}
	else
	{
		return s_url + "?" + s_newArg;
	}
}

function getDivContent(s_pageUrl, contentDivId, evalOnComplete)
{
	loadingId = contentDivId;
	if($(contentDivId+'_loading'))
	{
		loadingId = contentDivId+'_loading';
	}

	drawLoading(loadingId);

	new Request.HTML({url: s_pageUrl, update:$(contentDivId), evalScripts:true, onComplete: function(reps) {
		removeLoading(loadingId);
		if(evalOnComplete != undefined)
		{
			eval(evalOnComplete);
		}
	}}).get({'ajax': 1});

	return false;
}

var loadingTextArray = new Array();
var loadingImage = document.createElement('img');
loadingImage.src = "/images/ajax-loader.gif";

function drawLoading(contentDivId)
{
	if(loadingTextArray.indexOf("loading_"+contentDivId) == -1)
	{
		loadingTextArray.push("loading_"+contentDivId);

		if(!$("loading_"+contentDivId))
		{
			loadingText = document.createElement('div');
			loadingText.id = "loading_"+contentDivId;

			var myValues = $(contentDivId).getCoordinates();

			newTop = (myValues["top"] + (myValues['height']/2)) - 16;
			newLeft = (myValues["left"] + (myValues['width']/2)) - 16;
			loadingText.style.position = "absolute";
			loadingText.style.top = newTop + "px";
			loadingText.style.left = newLeft + "px";

			loadingText.style.backgroundColor = "white";
			loadingText.style.border = "1px solid black";
			loadingText.style.width = "32px";
			loadingText.style.height = "32px";
			loadingText.style.padding = "16px";

			document.body.appendChild(loadingText);
			loadingText.appendChild(loadingImage);
		}
		else
		{
			var myFx = new Fx.Morph("loading_"+contentDivId).set({
		    'opacity': 100
			});
		}
	}
}

function removeLoading(contentDivId)
{
	if(loadingTextArray.indexOf("loading_"+contentDivId) != -1)
	{
		key = loadingTextArray.indexOf("loading_"+contentDivId);
		loadingTextArray.erase(loadingTextArray[key]);

		loadingText = $("loading_"+contentDivId);
		var myEffect = new Fx.Morph(loadingText, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
		myEffect.start({'opacity': [100, 0]});

		//loadingText.dispose();
	}
}
var lightbox_container;
var lightbox_center;
var lightbox_contents;
function createLightBox()
{
	if(!$('lightbox_container'))
	{
		lightbox_container = new Element("div", {id:'lightbox_container','styles':{'display':'none'}}).inject(document.body,'top');
		lightbox_center = new Element("div", {id:'lightbox_center','styles':{'display':'none'}}).inject(document.body,'top');
		lightbox_contents = new Element("div", {id:'lightbox_contents','styles':{'display':'none'}}).inject(lightbox_center,'top');
	}
}

function closeLightBox()
{
	if($('lightbox_container'))
	{
		lightbox_container.dispose();
		lightbox_center.dispose();
		lightbox_contents.dispose();
	}
}

function showLightBox(content, b_closeButton)
{
	createLightBox();

	newCenterTop = 0;
	contentOnTheMove = false;
	$('lightbox_container').style.display = 'block';
	$('lightbox_center').style.display = 'block';
	$('lightbox_contents').style.display = 'block';

	if(typeof(content) == "object")
	{
		$('lightbox_contents').innerHTML = "";
		$('lightbox_contents').appendChild(content);
	}
	else
	{
		$('lightbox_contents').innerHTML = content;
	}
	if(b_closeButton)
	{
		//$('lightbox_close').style.display = 'block';
	}
	setTimeout("$('lightbox_center').style.marginLeft = '-' + ($('lightbox_contents').offsetWidth/2) + 'px';", 1);

	this.close = function () {
		$('lightbox_container').style.display = 'none';
		$('lightbox_center').style.display = 'none';
		$('lightbox_contents').style.display = 'none';

		closeLightBox();
	}

	this.slideCenter = function () {
		if(newCenterTop > $('lightbox_center').offsetTop)
		{
			if(newCenterTop - $('lightbox_center').offsetTop < 4)
			{
				moveCenterTop = (newCenterTop - $('lightbox_center').offsetTop);
			}
			else
			{
				moveCenterTop = 4;
			}
		}
		else if(newCenterTop < $('lightbox_center').offsetTop)
		{
			if($('lightbox_center').offsetTop - newCenterTop < 4)
			{
				moveCenterTop = -(newCenterTop - $('lightbox_center').offsetTop);
			}
			else
			{
				moveCenterTop = -4;
			}
		}
		else
		{
			contentOnTheMove = false;
			return false;
		}
		$('lightbox_center').style.top = ($('lightbox_center').offsetTop + moveCenterTop) + 'px';
		setTimeout("this.slideCenter();",10);
	}

	this.position = function (b_initialPos) {
		if($('lightbox_container'))
		{
			if(b_initialPos)
			{
				$('lightbox_center').style.top = '0px';
			}


			newTop = window.getScrollTop()-document.body.offsetHeight;
			newHeight = window.getHeight()+document.body.offsetHeight;

			newTop = 0;
			newHeight = window.getScrollSize().y;

			offset = document.body.offsetHeight - window.getScrollTop() - window.getHeight();
			if(offset < 0) offset = 0;
			newHeight = newHeight + offset;



			$('lightbox_container').style.top = newTop+'px';
			$('lightbox_container').style.height = newHeight+'px';

			//newCenterTop = window.getScrollTop() + (window.getHeight() / 2) - 100;
			newCenterTop = window.getScrollTop() + (window.getHeight() / 2) - ($('lightbox_center').offsetHeight / 2);
			newCenterTop = Math.round(newCenterTop);

			if($('lightbox_center').getHeight() > window.getHeight())
			{
				heightOffset = $('lightbox_center').getHeight() - window.getHeight();
				newCenterTop -= Math.round(heightOffset);
			}
			if(newCenterTop + $('lightbox_center').getHeight() > window.getScrollSize().y)
			{
				newCenterTop = Math.round(window.getScrollSize().y - $('lightbox_center').getHeight());
			}
			if(newCenterTop < 0) newCenterTop = 0;


			if(b_initialPos)
			{
				$('lightbox_center').style.top = newCenterTop+'px';
			}
			else if(!contentOnTheMove)
			{
				contentOnTheMove = true;
				setTimeout("this.slideCenter();",10);
			}
		}
	}

	$('lightbox_container').onclick = this.close;
	if(b_closeButton)
	{
		$('lightbox_close').onclick = $('lightbox_container').onclick;
	}

	window.addEvent('scroll', this.position);
	window.addEvent('resize', this.position);
	setTimeout("this.position(true);",1);

}

function toggleDisplay(id, toggles)
{
	toggles = toggles.split("|");
	if(document.getElementById(id))
	{
		object = document.getElementById(id);
		if(object.style)
		{
			if(object.style.display == toggles[0] && toggles[1])
			{
				object.style.display = toggles[1];
			}
			else if(object.style.display == toggles[1] && toggles[2])
			{
				object.style.display = toggles[2];
			}
			else
			{
				object.style.display = toggles[0];
			}
		}
	}

	return false;
}

function cropTextBlock(target, lines) {
	var textNode = $(target);
	var temp = textNode.innerHTML;
	var newHTML = "";
	for(var i = 0; i < lines; i++)
	{
		newHTML += " <br />";
	}
	textNode.innerHTML = newHTML;
	var aimForHeight = textNode.offsetHeight;
	aimForHeight += (1 * i);
	textNode.innerHTML = temp;
	newHTML = textNode.innerHTML;
	while(textNode.offsetHeight > aimForHeight)
	{
		newHTML = newHTML.substring(0,newHTML.length-2);
		textNode.innerHTML = newHTML+"...";
	}
}

function formValueHints(id)
{
	form = $(id);
	var formElements = form.elements;
	for(i = 0; i < formElements.length; i++)
	{
		if(formElements[i].title != "" && formElements[i].value == "")
		{
			formElements[i].value = formElements[i].title;
			formElements[i].onfocus = function () {
				if(this.value == this.title)
				{
					this.value = "";
				}
			};
			formElements[i].onblur = function () {
				if(this.value == "" && this.title != "")
				{
					this.value = this.title;
				}
			};
		}
	}

	form.onsubmit = function () {
		var formElements = this.childNodes;
		for(i = 0; i < formElements.length; i++)
		{
			if(formElements[i].title != "" && formElements[i].value == formElements[i].title)
			{
				formElements[i].value = "";
			}
		}
	};
}

function function_exists( function_name ) {
	if (typeof function_name == 'string'){
		return (typeof window[function_name] == 'function');
	} else {
		return (function_name instanceof Function);
	}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function getElementsByClassName(searchName, target)
{
	if(target == undefined)
	{
		target = document;
	}

	elementArray = target.getElementsByTagName('*');
	arrayLength = elementArray.length;
	returnArray = new Array();
	for(i = 0; i < arrayLength; i++)
	{
		if(elementArray[i].className == searchName)
		{
			returnArray.push(elementArray[i]);
		}
	}

	return returnArray;
}

function windowURI(url, w, h,time,resizable)	// windowURI(link,width,height,time(close the new window after x seconds),resizable(1 -> true)
{
	if(time == undefined)
		time = 0;

	if(resizable == undefined)
		resizable = 1;

	uriwindow = window.open(url,"window_print","menubar=no,scrollbars=1,left=10,top=0,width="+w +" ,height="+h +",resizable="+resizable);

	if(time != 0 && time != -1)
	{
		setTimeout('uriwindow.close();',time);
	}
}

function windowPrint(url, w, h)
{
	//alert(url);
	printwindow=window.open(url,"window_print","menubar=no,scrollbars=1,left=10,top=1,width="+w +" ,height="+h +",resizable=1")
}

var examplewindow;
function windowExample(url, w, h)
{
	//alert(url);
	if(examplewindow)
		examplewindow.focus();
	examplewindow=window.open(url,"window_print","menubar=no,scrollbars=1,left=10,top=1,width="+w +" ,height="+h +",resizable=1")
}

function openwindow(text)
{
	while((text.indexOf("%BR%") != -1))
	{
		text = text.replace("%BR%","<BR>");
	}
	myWin = window.open("","nCt", "left=400, top=300,width=180,height=30,status=no,toolbar=no,menubar=no,scrollbars=auto,resizable=yes");
	myWin.document.write("<html><head><title>Note</title></head>");
	myWin.document.write ("<body><script>function closewindow(){window.close()} \n\n setTimeout(\"closewindow()\",1000);</script>"+text+"</body></html>");
	//setTimeout("myWin.close()",200);
	//myWin.document.write("<center><p><input type='button' value='Afsluiten' name='close' onClick='window.close()'></p><center>");
}

function CheckTab(el)
{
	if ((document.all) && (9==event.keyCode) && (event.ctrlKey))
	{
		el.selection=document.selection.createRange();
	    setTimeout("ProcessTab('" + el.id + "')",0);
	}
	if ((document.all) && (83==event.keyCode) && (event.ctrlKey))
	{
		document.forms[0].submit();
		openwindow('De pagina is opgeslagen');
	}
}

function ProcessTab(id)
{
	document.all[id].selection.text=String.fromCharCode(9);
	document.all[id].focus();
}

function changeColor(el, color1, color2)
{
	//alert(el);
	document.getElementById(el).style.background = (document.getElementById(el).style.background == color1) ? color2 : color1;
}

function test(cell,color1,color2)
{
	cell.style.background = (cell.style.background == color1) ? color2 : color1;
}

function checkUserForm()
{
	if(document.forms[0].username.value=="")
	{
		alert('U moet een gebruikersnaam opgeven!');
		return false;
	}

	/*if(document.forms[0].email.value=="")
	{
		alert('U moet email opgeven!');
		return false;
	}*/

	if(document.forms[0].password.value=="")
	{
		alert('U moet password opgeven!');
		return false;
	}

	var value = false;

	for(i=0;i<document.forms[0].elements.length;i++)
	{
		if(document.forms[0].elements[i].type=='checkbox')
		{
			if(document.forms[0].elements[i].checked==true)
			{
					value=true;
					break;
			}
		}
	}
	if(value==false)
	{
		alert('U dient minimaal 1 groep te selecteren!');
		return false;
	}
	return true;
}

function checkUpdateUserPropertiesForm()
{
	if(document.forms[0].username.value=="")
	{
		alert('U moet een gebruikersnaam opgeven!');
		return false;
	}

	/*if(document.forms[0].email.value=="")
	{
		alert('U moet email opgeven!');
		return false;
	}*/

	if(document.forms[0].password.value=="")
	{
		alert('U moet password opgeven!');
		return false;
	}

	return true;
}

function checkGroupForm()
{
	if(document.forms[0].name.value=="")
	{
		alert('U moet een naam voor de groep opgeven!');
		return false;
	}

	if(document.forms[0].profileId.value=="")
	{
		alert('U moet een profiel selecteren!');
		return false;
	}
}

function checkDescriptionAmount(maxAmount)
{
	if(document.descForm.personAmount.value<maxAmount)
	{
		return true;
	}
	else
	{
		alert("U kunt niet meer dan " + maxAmount + " personen inschrijven");
		return false;
	}
}

function TrackCount(fieldObj,countFieldName,maxChars)
{
	var countField = eval("fieldObj.form."+countFieldName);
	var diff = maxChars - fieldObj.value.length;

	// Need to check & enforce limit here also in case user pastes data
	if (diff < 0)
	{
		fieldObj.value = fieldObj.value.substring(0,maxChars);
		diff = maxChars - fieldObj.value.length;
	}
	countField.value = diff;
}

function limit_text(obj, max)
{
	if (obj.value.length > max)
	{
		obj.value = obj.value.substring(0, max);
		return false;
	}
}

function LimitText(fieldObj,maxChars)
{
	var result = true;
	if (fieldObj.value.length >= maxChars)
		result = false;

	if (window.event)
		window.event.returnValue = result;
	return result;
}

function imgOn(menuObj)
{
	name = menuObj.name;
	leftImage = "img"+name+1;
	rightImage = "img"+name+2;
	document.images[leftImage].src="images/menu_low.gif";
	document.images[rightImage].src="images/menu2_low.gif";
}

function imgOut(menuObj)
{
	name = menuObj.name;
	leftImage = "img"+name+1;
	rightImage = "img"+name+2;
	document.images[leftImage].src="images/menu_hi.gif";
	document.images[rightImage].src="images/menu2_hi.gif";
}

function imgSubOn(menuObj)
{
	name = menuObj.name;
	leftImage = "subimg"+name+1;
	rightImage = "subimg"+name+2;
	document.images[leftImage].src="images/menu_sub_low.gif";
	document.images[rightImage].src="images/menu2_low.gif";
}

function imgSubOut(menuObj)
{
	name = menuObj.name;
	leftImage = "subimg"+name+1;
	rightImage = "subimg"+name+2;
	document.images[leftImage].src="images/menu_sub_hi.gif";
	document.images[rightImage].src="images/menu_sub2_hi.gif";
}

function checkAllFields(element)
{
	if(confirm("Hiermee gaat een eventuele selectie verloren"))
	{
		for(var i=0;i<document.forms[0].elements.length;i++)
		{
			document.forms[0].elements[i].checked=checkFields;
		}
		checkFields = !checkFields;
		if(checkFields)
			element.value = "alles aan";
		else
			element.value = "alles uit";
	}
}

function emptyForm()
{
	for(var i=0;i<document.forms[2].elements.length;i++)
	{
		if(document.forms[2].elements[i].type=="text")
			document.forms[2].elements[i].value="";
	}
}

function changeImage(img, newSrc)
{
	img.src = newSrc;
}

function open_new_window(location)
{
	new_window = window.open(location,"mailafriend","width=400,height=450,scrollbars=yes,left=10,top=10");
}

function checkAll(formName)
{
	for(var i=0;i<document.forms[formName].elements.length;i++)
	{
		if(document.forms[formName].elements[i].type=='checkbox' && document.forms[formName].elements[i].alt!='none')
			document.forms[formName].elements[i].checked = true;
	}
}

function unCheckAll(formName)
{
	for(var i=0;i<document.forms[formName].elements.length;i++)
	{
		if(document.forms[formName].elements[i].type=='checkbox' && document.forms[formName].elements[i].alt!='none')
			document.forms[formName].elements[i].checked = false;
	}
}

function checkElement(elementId)
{
	document.getElementById(elementId).checked = true;
}

/*function checkForm(formName, userId)
{
	var found = false;
	for(var i=0;i<document.forms[formName].elements.length;i++)
	{
		if(document.forms[formName].elements[i].type=='checkbox')
		{
			if(document.forms[formName].elements[i].checked==true)
			{
				found = true;
				break;
			}
		}
	}
	if(!found)
	{
		alert('Gelieve minimaal 1 gebruiker aan te vinken');
		checkElement('author_'+userId);
	}
	return found;
}*/

dropDownEdited = false;

function setEndHour(beginDropDown)
{
	var endHouresDropDown = document.getElementById('endhoures');
	var startMinutesDropDown = document.getElementById('startminutes');
	if(endHouresDropDown.selectedIndex<beginDropDown.selectedIndex)
	{
		endHouresDropDown.options[beginDropDown.selectedIndex].selected = true;
	}
	setEndMinute(startMinutesDropDown);
}

function setEndMinute(beginDropDown)
{
	var startHouresDropDown = document.getElementById('starthoures');
	var endHouresDropDown = document.getElementById('endhoures');
	var endMinutesDropDown = document.getElementById('endminutes');
	if(startHouresDropDown.selectedIndex==endHouresDropDown.selectedIndex)
	{
		if(endMinutesDropDown.selectedIndex<beginDropDown.selectedIndex)
		{
			endMinutesDropDown.options[beginDropDown.selectedIndex].selected = true;
		}
	}
}

function checkEmpty(elementNames)
{
	var errorElements = new Array();
	var j=0;
	for(var i=0;i<elementNames.length;i++)
	{
		if(document.getElementById(elementNames[i]).value=='')
		{
			errorElements[j] = elementNames[i];
			j++;
		}
	}
	return errorElements;
}

function checkAgenda()
{
	var elementArray = new Array("mainhead");
	var errorElements = checkEmpty(elementArray);
	var errorMessage = '';
	if(errorElements.length != 0)
	{
		for(var k=0;k < errorElements.length;k++)
		{
			if(errorElements[k]=='mainhead')
			{
				errorMessage += 'Gelieve een titel in te vullen';
			}
		}
		alert(errorMessage);
		return false;
	}
	return true;
}

var currentlySelected = -1;
function selectOne(dropDown,optionid)
{
	if(currentlySelected!=-1 || optionid)
	{
		for(var i=0;i<dropDown.options.length;i++)
		{
			if(optionid)
			{
				if(dropDown.options[i].id==optionid)
					dropDown.options[i].selected = true;
				else
					dropDown.options[i].selected = false;
			}
			else
			{
				if(i==currentlySelected)
					dropDown.options[i].selected = false;
				if(i==dropDown.selectedIndex)
					dropDown.options[i].selected = true;
			}
		}
	}
	currentlySelected = dropDown.selectedIndex;
}

function mouseOver(adminButton)
{
	var splittedSrc = adminButton.src.split("/");
	var restSrc = "";
	fileName = splittedSrc[splittedSrc.length-1];
	for(var i=0;i<splittedSrc.length-1;i++)
	{
		restSrc += splittedSrc[i] + "/";
	}
	var splittedFileName = fileName.split(".");
	adminButton.src =  restSrc + splittedFileName[0] + "_hov" + "." + splittedFileName[1];
}

function mouseOut(adminButton)
{
	var splittedSrc = adminButton.src.split("/");
	var restSrc = "";
	fileName = splittedSrc[splittedSrc.length-1];
	for(var i=0;i<splittedSrc.length-1;i++)
	{
		restSrc += splittedSrc[i] + "/";
	}
	var splittedFileName = fileName.split(".");
	var newFileName = splittedFileName[0].substring(0,splittedFileName[0].length-4);
	adminButton.src =  restSrc + newFileName + "." + splittedFileName[1];
}

function checkGroups()
{
	for(var i=0;i<document.forms.sendGroups.elements.length;i++)
	{
		if(document.forms.sendGroups.elements[i].type=="checkbox" && document.forms.sendGroups.elements[i].checked)
		{
			return true;
		}
	}
	alert('Gelieve een groep te kiezen.');
	return false;
}

function checkGroupAmount()
{
	var currentForm = document.forms[0];
	for(var i=0;i<currentForm.elements.length;i++)
	{
		if(currentForm.elements[i].type=="checkbox")
		{
			if(currentForm.elements[i].checked)
				return true;
		}
	}
	return confirm("Deze gebruiker is nu niet meer gekoppeld aan een groep. U vindt hem nu alleen nog terug in het overzicht van alle gebruikers.");
}

function displayFormat(dropDown)
{
	if(dropDown.options[dropDown.selectedIndex].value == 322)
		document.getElementById("obl_format").style.display = "";
	else
		document.getElementById("obl_format").style.display = "non";
}

function executeAction(action,actionObject)
{
	//alert(actionObject.id + ":" + action);
	switch(action)
	{
		case "display":
		{
			if(actionObject.style.display!="")
				actionObject.style.display = "";
			break;
		}
		case "hide":
		{
			if(actionObject.style.display!="none")
				actionObject.style.display = "none";
			break;
		}
	}
}

function getElementValue(elementName)
{
	return document.getElementById(elementName).value;
}

function getElementLength(elementName)
{
	//alert(document.getElementById(elementName).value.length);
	return document.getElementById(elementName).value.length;
}

function setVisibility(elementId,visible)
{
	if(visible)
		document.getElementById(elementId).style.display = "";
	else
		document.getElementById(elementId).style.display = "none";
}

function displayFormat(dropDown)
{
	if(dropDown.options[dropDown.selectedIndex].value == 1656)
		document.getElementById("obl_format").style.display = "";
	else
		document.getElementById("obl_format").style.display = "none";
}

function checkEmptyId(inputId)
{
	var translationArray = new Array(2);
	translationArray['content'] = '[[TRANSLATION.error_content]]';
	translationArray['mainhead'] = '[[TRANSLATION.error_mainhead]]';

	if(document.getElementById(inputId).value == '')
	{

		alert(translationArray[inputId]);
		return false;
	}
	return true;
}

function copyInputTo(copyFromElement,copyElementId) /* Copy the value from an element to another element onchange (e.g. menutitle to mainhead) */
{
	document.getElementById(copyElementId).value = document.getElementById(copyFromElement).value;
}

function createTarget(t)
{
    window.open("", t, "width=600,height=550,scrollbars=1");
    return true;
}

function getHTTPObject() {

  var xmlhttp;

  /*@cc_on

  @if (@_jscript_version >= 5)

    try {

      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (E) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}

function popUp(URL, width, height)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+",left = 320,top = 272');");
}

function checkNumeric(textfield,message)		// Checks whether the userinput is numeric or not
{
	inputstring = textfield.value;
	for (i = 0; i < inputstring.length; i++)
	{
		ch = inputstring.substring(i, i+1);
		if (ch < "0" || ch > "9")
		{
			if(message != '')
				alert(message);
			textfield.value = textfield.value.substring(0, i);
			textfield.focus();
			return false;
		}
	}
	return true;
}


function handleLoginSubmit(form)
{

	if(!md5_vm_test())
	{
		return true;
	}
	else
	{

		p = document.getElementById('password').value;
		c = document.getElementById('challenge').value;

		document.getElementById('passwordS').value = hex_md5(hex_md5(p) + c);
		document.getElementById('loginnameS').value = document.getElementById('loginname').value
		document.getElementById('shadowForm').submit();
		return false;
	}

}

function generateRandomString(length)
{

	var retVal = '';

	for (i=0; i < length; i++)
	{
		retVal += String.fromCharCode((parseInt(Math.random() * 1000) % 94) + 33);
	}

	return retVal;
}

var emptiedElements = new Array();
function js_in_array(the_needle, the_haystack)
{
	var the_hay = the_haystack.toString();
	if(the_hay == ''){
		return false;
	}
	var the_pattern = new RegExp(the_needle, 'g');
	var matched = the_pattern.test(the_haystack);
	return matched;
}

function emptyValue(element)
{
	if(!js_in_array(element.id,emptiedElements))
	{
		emptiedElements[emptiedElements.length] = element.id;
		element.value='';
	}
}

var fixedModulewindows = new Array();

function showModuleInfoDiv(elmId)
{
	if (!js_in_array(elmId, fixedModulewindows))
	{
		scrollTop = window.getScrollTop();
		topCoord = scrollTop+20;

		document.getElementById(elmId).style.top = topCoord+'px';
		document.getElementById(elmId).style.left = '20px';
		document.getElementById(elmId).style.display = 'block';
	}
}

function clickModulewindow(elmId)
{
	if (js_in_array(elmId, fixedModulewindows))
	{
		// Remove this module window from the array
		tempArray = new Array();

		for (i=0; i<fixedModulewindows.length; i++ )
		{
			if (fixedModulewindows[i] != elmId)
			{
				tempArray[tempArray.length] = fixedModulewindows[i];
			}
		}

		fixedModulewindows = tempArray;
		delete tempArray;

		document.getElementById(elmId).style.display = 'none'; // Hide the module window
	}
	else
	{
		fixedModulewindows[fixedModulewindows.length] = elmId; // Put this module window in the array
		new Drag.Move($(elmId), {'container': bodyC});
		$(elmId).style.cursor = 'move';
	}
}

function modulewindowOut(elmId)
{
	if (!js_in_array(elmId, fixedModulewindows))
	{
		document.getElementById(elmId).style.display = 'none'; // Hide the module window
	}
}