/*
(c) 2007-2008 Jean Luc Biellmann
*/

function Main () {
	objMain = this;
}

Main.prototype = {
	disableselect : function () {
		return false;
	},
	innerHtml : function (name,content) {
		var l= $(name).firstChild.length;
		$(name).firstChild.replaceData(0, l, content);
	},
	top : function () {
		$('content').scrollTop=0;
	},
	kwsInit : function (e) {
		$('kws').value = 'Rechercher';
		$('kws').style.color = 'rgb(120,120,100)';
	},
	kwsClick : function (e) {
		$('kws').value = '';
		$('kws').style.color = 'rgb(0,0,128)';
	},
	kwsBlur : function (e) {
		$('kws').style.color = 'rgb(120,120,100)';
		if ($('kws').value.length == 0)
			this.kwsInit();
	},
	startup : function () {

		var formObjects = new Array('INPUT','SELECT','TEXTAREA');

		// private objects for admin only
		$$('.prv').each(function (obj) {
			if (formObjects.indexOf(obj.nodeName)!=-1)
				obj.disable();
			obj.hide();
		});
		// public objects for all
		$$('.pub').each(function (obj) {
			if (formObjects.indexOf(obj.nodeName)!=-1)
				obj.enable();
			obj.show();
		});
		// left menu 
		var uls = $$('.ulmenu');
		
		uls.each(function (ul) {
			ul.select('a').each(function (a) {
				if (a.href==document.location) {
					Cookie.set('gr_lastloc',document.location,7);
					a.style.color='#f0f0f0';
				}
			});
		});	
				
		// no location : get previous
		if (Cookie.get('gr_lastloc')) {
			var lastloc = Cookie.get('gr_lastloc').replace(/^.*index.php/,'');
			if (lastloc != null)
				uls.each(function (ul) {
					ul.select('a').each(function (a) {
						if (a.href.replace(/^.*index.php/,'')==lastloc) {
							a.style.color='#ffffff';
							a.style.textDecoration='underline';
						}
					});
				});
		}
		if ($('kws')) {
			_main.kwsInit();
			Event.observe($('kws'),'blur',_main.kwsBlur.bindAsEventListener(this));	
			Event.observe($('kws'),'click',_main.kwsClick.bindAsEventListener(this));	
		}
	}
};

var _main = new Main();

Event.observe(this, "load", _main.startup);
