function FuseAction(para) {
	// use filename only if get method is forced
	if ( location.search.length > 0 ) { document.forms[0].action ='index.php'; }
//	document.forms[0].sort_by.value='';
	document.forms[0].fuseaction.value=para;
	document.forms[0].submit();
}

function FuseActionClean(para) {
	// use filename only if get method is forced
	if ( location.search.length > 0 ) { document.forms[0].action ='index.php'; }
	kill_form();
	document.forms[0].fuseaction.value=para;
	document.forms[0].submit();
}

function FuseActionPop(para) {
	window.open('index.php?fuseaction='+para)
}

function change_sort(sort_field){
// check and set the sorting direction
	if (document.forms[0].sort_by.value == sort_field) {
		if (document.forms[0].sort_direction.value == 'ASC') {
			document.forms[0].sort_direction.value = 'DESC';
		} else {
			document.forms[0].sort_direction.value = 'ASC';
		}
	} else {
		document.forms[0].sort_direction.value = 'ASC';
	}
	// set the field name to sort on
	document.forms[0].sort_by.value = sort_field;
	// submit
	document.forms[0].submit();
}


function kill_form(){
	//var inputTags = document.getElementsByTagName('INPUT');
	var e = document.forms[0].elements;
	for(i=e.length-1; i>=0; i--){
		if('fuseaction' != e[i].name){
		e[i].parentNode.removeChild(e[i]);
		}
	}
}

function DoFocus(){
	for (var i = 0; i < document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].type!='hidden' && 'FIELDSET' != document.forms[0].elements[i].nodeName ){
			document.forms[0].elements[i].focus();
			break;
		}
	}
}

function checkEnter(e,target){
	if(13 == e){
		document.forms[0].limit_offset.value = 0;
		FuseAction(target);
	}
}

function init_menu() {
	if (window.Go != null) {
		Go();
	}
}

function hi_error(jsonObj) {
	if (null == jsonObj) { return false;}
	this.jObj = jsonObj;
	dojo.addOnLoad(this,'_load');
}

hi_error.prototype._load = function() {
	for (err_key in this.jObj) {
		test = document.forms[0][err_key];
		if (undefined != test) {
			test.className += ' hi_error';
		}
	}
}

dojo.addOnLoad(function() {
	dojo.declare('popover_msg', null, {
		id: 'popover_msg',
		class_name: 'popover_msg',
		msg_elm: null,
		msg_visible: false,
		duration: 2500,
		last_timeout: null,
		constructor: function(args) {
			dojo.mixin(this, args);
			this.msg_elm = this._create_msg();
			dojo.style(this.msg_elm, this.default_style);
		},
		default_style: {
			'opacity' : 0,
			'display' : 'none'
		},
		_create_msg: function() {
			if (undefined == dojo.byId(this.id)) {
				var elm = dojo.doc.createElement('DIV');
				dojo.attr(elm, 'class', this.class_name);
				dojo.attr(elm, 'id', this.id);
				dojo.body().appendChild(elm);
				return elm;
			} else {
				return dojo.byId(this.id);
			}
		},
		_set_message: function(msg) {
			this.msg_elm.innerHTML = msg;
		},
		fade_out: function() {
			this.msg_visible = false;
			dojo.fadeOut({
				node:this.msg_elm,
				duration:200,
				onEnd: function() {
					dojo.style(this.node, {'display': 'none'});}
			}).play();
		},
		fade_in: function() {
			this.msg_visible = true;
			dojo.style(this.msg_elm, { 'display': 'block' });
			dojo.fadeIn({node:this.msg_elm, duration:200}).play();
		},
		// depricated, use _set_message(). Kept for compatability.
		msg_string: function(msg) {
			this._set_message(msg);
		},
		// display the message with an optional duration
		display: function(msg, duration) {
			var no_fade_out = false;
			if (undefined == duration) {
				duration = this.duration;
			} else if (false == duration) {
				no_fade_out = true;
			}
			if (undefined != this.last_timeout) {
				clearTimeout(this.last_timeout);
			}
			this._set_message(msg);
			if (false == this.msg_visible) {
				this.fade_in();
			}
			if (false == no_fade_out && this.msg_visible) {
				this.last_timeout = setTimeout(dojo.hitch(this, 'fade_out'), duration);
			}
		},
		// hide the message with optional duration 
		hide: function(duration) {
			if (undefined == duration) {
				this.fade_out();
			} else {
				this.last_timeout = setTimeout(dojo.hitch(this, 'fade_out'), duration);
			}
		}
	});
});
/*
function popover_msg() {
	this.msg_elm = document.createElement('DIV');
	this.msg_elm.className = 'popover_msg';
	this.fadeout = dojo.fadeOut({node: this.msg_elm, duration: 200, onEnd: function() { this.node.style.display = 'none'; }});
	this.fadein = dojo.fadeIn({node: this.msg_elm, duration: 200});
	if (undefined == document.body) {
		dojo.addOnLoad(this,'_load');
	} else {
		this._load();
	}
}
popover_msg.prototype.msg_string = function(msg_string) {
	this.msg_elm.innerHTML = msg_string;
}
popover_msg.prototype._load = function() {
	document.body.appendChild(this['msg_elm']);
}
popover_msg.prototype.fade_out = function() {
	this.fadeout.play();
}
popover_msg.prototype.fade_in = function() {
	this.msg_elm.style.display = 'block';
	this.fadein.play();
}
*/
function onLoad(functionName){
	if (window.addEventListener) { window.addEventListener("load", functionName, false);
	} else if (window.attachEvent) { document.attachEvent("onreadystatechange", functionName); }
}

// force initilization of dynamic menu after page has loaded
onLoad(init_menu);
