function switchElement(id, style) {
	var html4El = document.getElementById(id);

	html4El.style.display = (html4El.style.display == style)? 'none': style;

	return false;
}

/**
 *
 * @access public
 * @return void
 **/
function openClose_files(id, image_path) {
	var html4El = document.getElementById('files_' + id);
	html4El.style.display = (html4El.style.display == 'block')? 'none': 'block';

	var imageEl = document.getElementById('fold_' + id);
	imageEl.src = (html4El.style.display == 'block')? image_path + 'subtree_min.gif': image_path + 'subtree_pl.gif';

	return false;
}

/**
 *
 * @access public
 * @return void
 **/
function openClose_folders(id, image_path) {
	var html4El = document.getElementById('group_' + id);
	html4El.style.display = (html4El.style.display == 'block')? 'none': 'block';

	var imageEl = document.getElementById('fold_' + id);
	imageEl.src = (html4El.style.display == 'block')? image_path + 'subtree_min.gif': image_path + 'subtree_pl.gif';

	return false;
}


/**
 *
 * @access public
 * @return void
 **/
function switchMode(){
	document.getElementById('tools_container').style.display = 'none';
	document.getElementById('refresh_tools_container').style.display = 'block';
}

/**
 *
 * @access public
 * @return void
 **/
function dubSermonTitle() {
	document.getElementById('sermon_title').value = document.getElementById('title').value;
	return true;
}

/**
 *
 * @access public
 * @return void
 **/
function jv_insertFileValues(id){
	var file_name = document.getElementById('file_field_' + id).value;
	var pos = file_name.lastIndexOf("\\");

	if(pos == -1) {
		pos = file_name.lastIndexOf("/");
	}

	var pos2 = file_name.lastIndexOf(".");
	var num = pos2 - pos;
	var name = file_name.substr(pos+1, num-1);

	document.getElementById('name_field_' + id).value = name;
}

/**
 *
 * @access public
 * @return void
 **/
function jv_refresh_tools(id) {
	var containerHdl = document.getElementById(id);
	var _childNodes  = containerHdl.childNodes;
	var _regExp		 = /CHK_\w+_(\d+)_(\d+)/;

	for (var i = 0; i < _childNodes.length; i++) {
		if (_childNodes[i].id) {
			if (_childNodes[i].id.match(_regExp)) {
				_regExp.exec(_childNodes[i].id);

				alert(RegExp.$1 + ' und ' + RegExp.$2);
			}
		}
	}
}

/**
 *
 * @access public
 * @return void
 **/
function jv_addPerson(id, newVal){
	var html4El = document.getElementById(id);

	if (html4El.value.replace(/\s*/, '') == '') {
		html4El.value = newVal;
	} else {
	 	html4El.value = html4El.value + "; " + newVal;
	}

	switchElement('user_browser', 'block');

	return false;
}

/**
 *
 * @access public
 * @return void
 **/
function switchElementAndMove(id, style) {
	var html4El = document.getElementById(id);

	if (html4El.style.display != style)
		moveElementLeft(id, 310);
	else
		html4El.style.display = 'none';

	return false;
}

/**
 *
 * @access public
 * @return void
 **/
function moveElementLeft(id, left) {
	var html4El = document.getElementById(id);

	html4El.style.display = 'block';

	html4El.style.left = (mouse_X_Coord - left) + 'px';
	html4El.style.top  = mouse_Y_Coord + 'px';

	document.getElementById('windowX').value = mouse_X_Coord;
	document.getElementById('windowY').value = mouse_Y_Coord;

	return false;
}

/**
 *
 * @access public
 * @return void
 **/
function confirmAnnouncement(form, elName) {
 	var aType = elName.checked? 'anmelden': 'abmelden';
 	if (confirm('Möchten Sie sich für diese Veranstaltung ' + aType + '?')) {
		form.submit();
		return true;
	}
 	return false;
}


function jv_selectAll(form)
{
	for(var i=0;i<document.forms[form].length;++i){
		if (document.forms[form].elements[i].type == "checkbox"){
			document.forms[form].elements[i].checked = true;
		}
	}
	return false;
}

function jv_unselectAll(form)
{
	for(var i=0;i<document.forms[form].length;++i){
		if (document.forms[form].elements[i].type == "checkbox"){
			document.forms[form].elements[i].checked = false;
		}
	}
	return false;
}

