myGlobalHandlers = {

	onCreate: function() {
		var w = $('working');
		if (w) {
			Element.show(w);
		}
	},

	onComplete: function() {
		if(Ajax.activeRequestCount === 0){
			var w = $('working');
			if (w) {
				Element.hide(w);
			}
		}
	},
	
	onException: function(p1, p2) {
		onComplete();
	},

	onError: function() {
		onComplete();
	}
};
Ajax.Responders.register(myGlobalHandlers);

function getKeyCode(e) {
	if (e.which) {
		if (e.which>0) {
			return e.which;
		} else if (e.keyCode) {
			return e.keyCode;
		} else if (e.modifiers !== undefined) {
			return e.modifiers;
		} else {
			return false;
		}
	} else if (e.keyCode) {
		return e.keyCode;
	} else {
		e = window.event;
		return e.keyCode;
	}
}
		
function getChildDivs(el) {
	var divs = new Array();
	el = el.firstChild;
	while (el !== null) {
		if (el.nodeName == "DIV") {
			divs.push(el);
		}
		el = el.nextSibling;
	}
	return divs;
}

function nextLi(el) {
	while (el = el.nextSibling) {
		if (el.nodeName == "LI") {
			break;
		}
	}
	return el;
}

function load(url, placeholder, js) {
	if (js === undefined) {
		js = true;
	}
	var myAjax = new Ajax.Updater( placeholder, url, { method: 'get', evalScripts: js });
}

function action(url, action, id, placeholder, js) {
	load(url + '?action=' + action + '&id=' + id + '&url=' + url + '&ph=' + placeholder, placeholder, js);
}

function saveForm(url, formName, placeholder, js) {
	if (js === undefined) {
		js = true;
	}
	var pars = Form.serialize(formName);
	var myAjax = new Ajax.Updater( placeholder, url, { method: 'post', parameters: pars, evalScripts: js });
}

function postPars(url, pars, placeholder, js) {
	if (js === undefined) {
		js = true;
	}
	var myAjax = new Ajax.Updater( placeholder, url, { method: 'post', parameters: pars, evalScripts: js });
}

function saveMultiForm(url, formNames, placeholder, js) {
	if (js === undefined) {
		js = true;
	}
	var tmp = new Array();
	var someForm;
	for (var i = formNames.length; --i >= 0; ) {
		someForm = $(formNames[i]);
		tmp.push(Form.serialize(someForm));
	}
	var pars = tmp.join('&');
	var myAjax = new Ajax.Updater( placeholder, url, { method: 'post', parameters: pars, evalScripts: js });
}


// Added in May 2010 by Ingo

toggleHelp = function(e) {
    Event.stop(e);
    $('helpContainer').toggle();
    this.blur();
}


init = function() {
    if ($('showHelp')) {
        $('showHelp').observe('click', toggleHelp);
        $('helpContainer').hide();
    }
}

document.observe('dom:loaded', init);





