function f_getClientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_getClientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_getScrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_getScrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function f_setScrollTop(val) {
	window.pageYOffset = val;
	document.documentElement.scrollTop = val;
	document.body.scrollTop = val;
}


function getElementsByClassName(classname, node) {
	if(!node) node = document.getElementsByTagName("body")[0];
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node.getElementsByTagName("*");
	for(var i=0,j=els.length; i<j; i++)
	if(re.test(els[i].className))a.push(els[i]);
	return a;
}

/*
Will switch the css property "display" to and from hidden.
*/

function switchDisplay (id, display) {
	var obj = document.getElementById(id);
	
	if (obj.style.display == display) {
		obj.style.display = "none";
	}
	else {
		obj.style.display = display;
	}
}

function hide (id) {
	var obj = document.getElementById(id);
	
	obj.style.display = "none";
}

function show (id) {
	var obj = document.getElementById(id);
	
	obj.style.display = "block";
}

/*
Will add a hidden form element with the state of the whole gui.
*/

function addGuiState (formid) {
	var formObj = document.getElementById(formid);
	
	/* get all elements with class "hideable" */
	var hideable = [];
	
	hideable = getElementsByClassName("hideable");

	value = "";
	
	for (var i=0; i < hideable.length; i++) {
//		alert("id: "+hideable[i].id+" display: "+hideable[i].style.display);
		if ((hideable[i].style.display == "none") || (hideable[i].style.display == "")) {
		} else {
			value += hideable[i].id + " ";
		}
	}
	
	var newInput = document.createElement("input");
	newInput.setAttribute("type","hidden");
	newInput.setAttribute("name", "current_repo");
	newInput.setAttribute("value", document.fselrepo.sel_repo.options[document.fselrepo.sel_repo.selectedIndex].value);
	formObj.appendChild(newInput);
	
	
	scrollTop = f_getScrollTop();
	scrollLeft = f_getScrollLeft();
	
	newInput = document.createElement("input");
	newInput.setAttribute("type","hidden");
	newInput.setAttribute("name", "guiState");
	newInput.setAttribute("value", value);
	formObj.appendChild(newInput);

	newInput = document.createElement("input");
	newInput.setAttribute("type","hidden");
	newInput.setAttribute("name", "scrollTop");
	newInput.setAttribute("value", scrollTop);
	formObj.appendChild(newInput);	

	newInput = document.createElement("input");
	newInput.setAttribute("type","hidden");
	newInput.setAttribute("name", "scrollLeft");
	newInput.setAttribute("value", scrollLeft);
	formObj.appendChild(newInput);		
}


function recallGuiState (listText, scrollLeft, scrollTop) {
	// first, unhide all divs that were open
	var list = listText.split(" ");	
	
	for (var i = 0; i < list.length; i++) {
		if(list[i]) {
			document.getElementById(list[i]).style.display = "block";
		}
	}

	// then scroll to the last position
	window.scrollTo(scrollLeft, scrollTop);
}

/* confirm functions to save code space... */
function confirmAdm(admin, repo) {
	if(repo) {
		return(confirm('Really remove Admin rights for '+admin+' in '+repo+'?'));
	} else {
		return(confirm('Really remove Admin rights for '+admin+'?'));
	}
}

function confirmDelPath(path) {
	return(confirm('Whole path entry ('+path+') will be deleted!'));
}

function confirmRemUser(user, group) {
	return(confirm('Really remove '+user+' from '+group+'?'));
}

function confirmAddAllUsr(group) {
	return(confirm('Really add all users to '+group+'?'));
}

