var browser = navigator.appName;
var version = navigator.version;


function openWindow(page, width, height) {
		if (typeof width == "undefined") { width=800; }
		if (typeof height == "undefined") { height=800; }
		OpenWin = this.open(page, 'CtrlWindow', 'width='+width+',height='+height+',toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');
}

function subframe(l,r,m) {
	if(r == '' || !r) {
		r = 'empty.php';
	}
	//refresh menu if there is no submenu
	if(m)
	{
		parent.menu.location = "menu.php?submenu="+m;
	}
	// patch om te zorgen dat vanuit een main frame ook naar subframes verwezen kan worden
	if(parent.sitemain.frames.length == 0 || parent.sitemain.frames.length == 1) {
		parent.sitemain.location = 'indexsub.php?l=' + escape(l) + '&r=' + escape(r);
	} else {
		parent.sitemain.mainleft.location = l;
		parent.sitemain.mainright.location = r;
	}
}

function mainframe(main, m) {
	//refresh menu if there is no submenu
	if(m)
	{
		parent.menu.location = "menu.php";
	}
	if(parent.frames.length == 2)
	{
		parent.location = main;
	} else
	{
		parent.sitemain.location = main;
	}
}

function HTML_Editor(code,langua) {
		window.open('cms_content_page_editor.php?id=' + code + '&language=' + langua,'popUpWindow','width=640,height=500,bookmarks=no,status=yes,toolbar=no');
}

function popupText(text, windowWidth, windowHeight, style)
{
	WindowObjectReference = window.open('','popUpWindow','width='+ windowWidth +',height='+ windowHeight +',bookmarks=no,status=yes,toolbar=no, resizable=yes, scrollbars=auto');
	WindowObjectReference.document.write('<html><body style="'+style+'">'+text+'</body></html>');
}

function doPopUp(locatie, windowWidth, windowHeight) 
{
	intMaxWidth = screen.availWidth;
	intMaxHeight = screen.availHeight;
	
	if(typeof windowWidth == "undefined")
	{
		windowWidth = 500;
	}
	if(typeof windowHeight == "undefined")
	{
		windowHeight = 500;
	}
	if(locatie != '') 
	{
		if(windowWidth > intMaxWidth || windowHeight > intMaxHeight)
		{
			windowWidth = intMaxWidth;
			windowHeight = intMaxHeight;
			
			if(windowWidth > intMaxWidth)
			{
				photoWidth = intMaxWidth - 5;
				locatie += "/width/" + photoWidth;
			} else
			{
				photoHeight = intMaxHeight - 60;
				locatie += "/height/" + photoHeight;
			}
		}
		//window.open(locatie,'popUpWindow','width=500,height=500,bookmarks=no,status=yes,toolbar=no, resizable=yes');
		content = "<html>";
		content +=		"<head>";
		content +=			"<title></title>";
		content +=		"</head>";
		content +=		"<body>";
		content +=			"<img src='"+ locatie +"'>";
		content +=		"</body>";
		content +=	"</html>";
		NFW = window.open('','_blank','width='+ windowWidth +',height='+ windowHeight +',bookmarks=no,status=yes,toolbar=no, resizable=yes, scrollbars=auto');
		NFW.document.open();
		NFW.document.write(content);
		NFW.document.close();
	} else {
		alert('Er moet een locatie ingevuld worden voor het popup scherm!');
	}
}

function doPopUpLarge(locatie) {
	if(locatie != '') {
		window.open(locatie,'popUpWindow','width=650,height=700,bookmarks=no,status=yes,toolbar=no');
	} else {
		alert('Er moet een locatie ingevuld worden voor het popup scherm!');
	}
}

function doPopUpSections(locatie) {
	if(locatie != '') {
		window.open(locatie,'popUpWindow','width=750,height=600,bookmarks=no,status=yes,toolbar=no,scrollbars=yes,resizable=yes');
	} else {
		alert('Er moet een locatie ingevuld worden voor het popup scherm!');
	}
}

function charsLeft(controller, view, maxchars) {
	alert(controller.value);
	if (controller.value.length > maxchars) {
		controller.value = controller.value.substring(controller.value, maxchars);
	}
	
	view.value = maxchars - controller.value.length;
}

function moveSelectItem(index, to) {
	var list = document.forms[0].list;
	var total = list.options.length - 1;
	
	if (index == -1) {
		return false;
	}
	if (to == +1 && index == total) {
		return false;
	}
	if (to == -1 && index == 0) {
		return false;
	}
	
	var items = new Array;
	var values = new Array;
	
	for (i = total; i >= 0; i--) {
		items[i] = list.options[i].text;
		values[i] = list.options[i].value;
	}
	
	for (i = total; i >= 0; i--) {
		if (index == i) {
			list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
			list.options[i] = new Option(items[i + to], values[i]);
			i--;
		} else {
			list.options[i] = new Option(items[i], values[i]);
		}
	}
	list.focus();
}

function submitSelectForm() {
	var list = document.forms[0].list;
	var theList = "";
	
	for (i = 0; i <= list.options.length - 1; i++) { 
		theList += "list[" + i + "]=" + assocListArray[list.options[i].text];
		if (i != list.options.length - 1) {
			theList += "&";
		}
	}
	document.forms[0].theList.value = theList;
	document.forms[0].submit();
}

function OpenWindow(strZiel, strName, intWidth){
	Picker = window.open(strZiel, strName, 'width='+intWidth+',height=260,scrollbars=no,resizablel');
	
	if (document.all) {
		var ClickX = window.event.x;
		var ClickY = window.event.y;
		if (navigator.appVersion.indexOf("MSIE 5") > 0) {
			Picker.moveTo(ClickX + window.screenLeft + 5, ClickY + window.screenTop - 50);
		}
	}
}

function rtSelectAll( p_blnChecked )
{
	for (var i = 0; i < document.forms[0].elements.length; ++i)
	{
		objField = document.forms[0].elements[i];
		if ( objField.type == 'checkbox' )
		{
			objField.checked = p_blnChecked;
		}
	}
}

function rtHandleFull(p_intElement, p_strFrom, p_bSetChecked_false)
{
	//var objForm = document.forms[0];
	bCheckAll = false;
	
	objRight_inherent = document.getElementById('right_option[' + p_intElement + '][0]');
	objRight_full = document.getElementById('right_full[' + p_intElement + ']');
	if(objRight_full.value == 1)
	{
		bCheckAll = true;
		objRight_full.value = 0;
	} else
	{
		objRight_full.value = 1;
	}
	
	for(var i = 1; i < 7; i++)
	{
		objRight_option = document.getElementById('right_option[' + p_intElement + '][' + i + ']');
		
		if(objRight_option)
		{
			if(p_strFrom == "right_full")
			{
				if(!(objRight_option.disabled))
				{
					objRight_option.checked = bCheckAll == true ? true : false;
				}
			}
			if(p_strFrom == "right_inherent" && objRight_inherent)
			{
				objRight_option.disabled = objRight_inherent.checked == true ? true : false;
				if(p_bSetChecked_false)
				{
					objRight_option.checked = false;
				}
			}
		}
	}
}

function selectChanged(selectbox, subject)
{
	var index = selectbox.selectedIndex;
	
	var selectedValue = selectbox.options[index].value;
	
	if(selectedValue == "0")
	{
		alert("Dit is geen geldige " + subject + ", kies één van de onderliggende items.");
		selectbox.selectedIndex = 0;
	}
} 

function charsLeft(controller, view, maxchars) 
{   
   if (controller.value.length > maxchars) {
		controller.value = controller.value.substring(controller.value, maxchars);
	}
	view.value = maxchars - controller.value.length;	
}

/*
*	Set the days of month, used for the calendar
*/
function setDays(objElementDay, objElementMonth, objElementYear)
{
	day = 1;
	selectDay = 0;
	var bAddDay = false;
	if(objElementDay.options[0].value != "01")
	{
		bAddDay = true;
	}
	if(objElementDay.selectedIndex > -1)
	{
		selectDay = objElementDay.selectedIndex;
		parseInt(objElementDay.options[selectDay].value);
		day = parseInt(objElementDay.options[selectDay].value);
	}
	month = parseInt(objElementMonth.options[objElementMonth.selectedIndex].value,10);
	year = parseInt(objElementYear.options[objElementYear.selectedIndex].value,10);
	month = month - 1; //de array telt anders
	// Nee een array begint bij 0 te tellen :)
	objElementDay.options.length = 0;
	var days = new Array(31, ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var bNoDays = true;
	var i = 0;
	if(bAddDay)
	{
		objElementDay.options.length = objElementDay.options.length + 1;
		objElementDay.options[0].value = "00";
		objElementDay.options[0].text = "--";
		i = 1;
	}
	var j =0;
	for(i; i < days[month]; i++)
	{
		bNoDays = false;
		strDay = (j+1);
		if (strDay<10) { strDay = '0'+strDay; }
		objElementDay.options.length = objElementDay.options.length + 1;
		objElementDay.options[i].value = strDay;
		objElementDay.options[i].text = strDay;
		j++;
	}
	if(bNoDays)
	{
		strDay = "--";
		objElementDay.options.length = objElementDay.options.length + 1;
		objElementDay.options[0].value = '';
		objElementDay.options[0].text = strDay;
	}
	if(selectDay > (objElementDay.options.length-1))
	{
		objElementDay.selectedIndex = (objElementDay.options.length-1);
	} else
	{
		objElementDay.selectedIndex = selectDay;
	}
}

function setMenuPos() {
	objMenubar = document.getElementById('menubar');
	objMenubar.style = 'position: absolute;';
	alert('TEST');
}

/* BEGIN POP-UP MENU BOTTOM  */

function setSubMenuHeight(id, intVerticalOffset) {
	if(!intVerticalOffset) {
		intVerticalOffset = 0;
	}
	var subMenuHeight = document.getElementById(id).offsetHeight + intVerticalOffset;
	document.getElementById(id).style.top = '-' + subMenuHeight + 'px';
}

function showSubMenu(id) {
	showSubMenu[id] = true;
	if(document.getElementById('submenu[' + id + ']')) {
		document.getElementById('submenu[' + id + ']').style.visibility = 'visible';
	}
}

function hideSubMenu(id, intDelay) {
	if(!intDelay) {
		intDelay = 1000
	}
	showSubMenu[id] = false;
	setTimeout('hide(\'' + id + '\')', intDelay);
}

function hide(id) {
	if(!showSubMenu[id]) {
		if(document.getElementById('submenu[' + id + ']')) {
			document.getElementById('submenu[' + id + ']').style.visibility = 'hidden';
		}
	}
}

function reloadParentAndClose()
{
	window.opener.location.reload();
	window.close();
}


/* END POP-UP MENU BOTTOM */