var aurealHelpPageLoaded = 0;

function aurealDoAction(node) {	
	setTimeout( "window.location.href = " + "'index.php?modAct="+aurealMenuActions[node.actID]+"';", 0 );
}

function aurealHelpSubmit() {
	var f= $('searchHelpBox');
	if(f.value=="" || f.value == "Search Help") {
		f.value = " ";
		alert("Please enter some search terms");
		f.focus();
		return false;
	}
	$("aurealHelp").submit();
}

function aurealHelpInit() {	
	if(typeof(aurealHelpPageID) == "undefined") aurealHelpPageID = 0;
	if(aurealHelpPageID == 0) $("helpArea").style.display = 'none';
}

function aurealInit() {
	aurealHelpInit();
}


function go(module_name) {
	url = './?modAct=' + module_name;
	window.open(url, '_parent');
}

function redirectTo(url) {
	window.open(url, '_parent');
}

function doStuff(node) {
	if ($('helpZone').style.display != 'none') {
		$('helpZone').style.display = 'none';
		$('helpAreaMessage').innerHTML = 'Click <strong>here</strong> if you need help with this module.';
	}
	else {
		$('helpAreaMessage').innerHTML = 'Hide Help';
		$('helpZone').style.display = '';
		if(aurealHelpPageLoaded != aurealHelpPageID && aurealHelpPageID > 0) {
			$("helpAreaFrame").src= "loader.php?modAct=intern_load_help&id=" + aurealHelpPageID;
			aurealHelpPageLoaded =  aurealHelpPageID;
		}
	}
}

function toggleValue(obj, value, isPassword) {

	if(obj.value == value) obj.value = '';
	else
		if(obj.value == '') obj.value = value;
			
	if (isPassword) {
//		replaceObject(obj, 'password', '');
		if (obj.value == value)
			obj.type = 'text';
		if (obj.value == '')
			obj.type = 'password';
	}
}

function replaceObject(obj, type, value) {
	var newO = document.createElement('input');
	newO.setAttribute('type', type);
	newO.setAttribute('value', value);
	newO.setAttribute('name', obj.getAttribute('name'));
	newO.setAttribute('id', obj.getAttribute('id'));
	obj.parentNode.replaceChild(newO, obj);
	newO.focus();
}

function expand(id, MaxObjectHeight) {
	obj = $(id);
	var h = '000'+ obj.style.height;
	var height = parseInt(h.substring(0, h.length-2), 10);
	//alert(height);
	if(height < MaxObjectHeight) {
		obj.style.height = height + 10 + "px";
		setTimeout('expand("'+id+'","'+MaxObjectHeight+'")', 1);
	}
}
function collapse(id) {
//	alert("INALTIMEA: " + $(id).style.height);
	obj = $(id);
	var h = '000'+ obj.style.height;
	var height = parseInt(h.substring(0, h.length-2), 10);
	if(height > 0) {
		obj.style.height = height - 10 + "px";
		setTimeout('collapse("'+id+'")', 1);
	}
}

function toggleMenuContents(liID, id, menuHeight) {
	if ($(id).style.display == 'none') {
		expand(id, menuHeight*22); //22 is a menu entry's height
		if ($(liID).className == 'categ_normal_extensible')
			$(liID).className = 'categ_normal_extended';
		else
			$(liID).className = 'categ_selected_extended';
		
		$(id).style.display = '';
	}
	else {
		collapse(id);
		if ($(liID).className == 'categ_normal_extended')
			$(liID).className = 'categ_normal_extensible';
		else
			$(liID).className = 'categ_selected_extensible';
		
		$(id).style.display = 'none';
	}
}
