var PHPKOD_IMG_ACCEPT_SMALL_SRC = apcphpkod.constantes.ICO_PATH + 'small/accept.png';
var PHPKOD_IMG_DENY_SMALL_SRC = apcphpkod.constantes.ICO_PATH + 'small/deny.gif';
var ICO_PATH = apcphpkod.constantes.ICO_PATH;
var AX_appController = Class.create();
/**
 *	Static apc main class
 *	
 *	APC PHPKOD FRAMEWORK
 *	Core Group
 *
 *	Classe de base
 *	
 *	************************
 *	(c) 2012 / AP netCONCEPT
 *	All Rights Reserved
 *	http://www.apconcept.net
 *	contact@apconcept.net
 *	Author : Antoni Paligot
 *	************************
 *	
 *	@package	Core
 *	@author		Antoni Paligot <contact@apconcept.net>
 *	@revision	beta
 */
AX_appController.prototype = {
	
	version : '5.3.0.2',
	// Conteneur des frames
	frames: null,
	// Timer pour le controller de connexion
	timer: null,
	
	_frm:[],
	_cfrm : 0,
	_ts : null,
	
	// Frame pour les messages
	_fmsg : null,
	
	_onLoadFunction: [],
	
	// ID / # de l'erreur / message?
	_traceId : 1,
	/*
	 * Instance du controler de la page d'accueil
	 */
	_home : null,
	
	options:{//set all the options here
	},
	
	initialize: function()
		{
			this._frm = new Array();
			this._onLoadFunction = new Array();
			this.trace('******************************************');
			this.trace('Welcome to APCPHPKOD AdminXtration program');
			this.trace('(c)2012 AP netCONCEPT / Antoni PALIGOT.');
			this.trace('All rights reserved');
			this.trace('');
			this.trace('http://www.apconcept.fr');
			this.trace('contact@apconcept.net');
			this.trace('');
			this.trace('Version '+this.version);
			this.trace('******************************************');
			document.observe(
					'dom:loaded', 
					function () {
						try{
							document.fire('dom:axinit');
							Ax.loadInit();
						} catch(e){
						Ax.trace('JsError | AX_appController::initialize says : '+e);
						}
					}
				);			
		},
	
	loadInit: function(options){
		// on lance le controlleur de frames
		this.frames = new AX_appFrameController();
		// on instancie le timer de controle de la connexion
		this.timer = new AX_connexionController();
		// On lance quelques plmugins
		phpkod.plugins.tooltips();
		// On lance un évènement come quoi le programme est pret
		document.fire('dom:axloaded');
		if(this._onLoadFunction.length > 0)
			$(this._onLoadFunction).each(function(o,i){ o(); });
	},
	
	onLoad: function(func){
		
		this._onLoadFunction.push(func);
		
	},
	
	/**
	 * 	Send report to prompt console
	 */
    trace: function(data, report)
        {
            this._traceId++;
			if(typeof(console) !== 'undefined' && typeof(console.log) == 'function')
                console.log('oJs : '+data);

            if(report === true || typeof(report) == 'object')
                Ax.msg(data, report);
			
			this.prompt( data );
			
        },
	
	/**
	 * 	Send alert to final user
	 */
	msg : function( msg, opts )
		{
			this._traceId++;
			opts = (typeof(opts) == 'object' || typeof(opts) == 'array') ? opts : {};
			var options = {
				
				duration : opts.duration || 0.3,
				autoclose : true,
				className : opts.className || ''
				
			}
			
			try{
				
				if(!Ax._fmsg)
					this._buildFmsg();
				
				Ax._fmsg.innerHTML += Ax._mkmsg( msg, options );
				if(options.autoclose === true)
					var tm = window.setTimeout('Effect.Fade(\'axmsg_'+this._traceId+'\', {duration:'+options.duration+', afterFinnish: function(){ $(\'axmsg_'+this._traceId+'\').remove(); }});', 5000 );
				
			} catch(e){
				
				alert(msg);
				this.trace('Error occuring durong prompt message tu user : '+e);
			
			}
			//alert(msg);
		},
	
	_buildFmsg : function( )
		{
			var f = document.createElement('div');
			f.className = 'ax-frame-msg-top';
			$(document.body).appendChild(f);
			Ax._fmsg = f;
		},
	
	_mkmsg : function( msg, options ) 
		{
			var o  = '<div class="msg ax-main-msg'+(options.className ? ' '+options.className : '')+'" id="axmsg_'+this._traceId+'" onclick="Effect.Fade(\'axmsg_'+this._traceId+'\', {duration:'+options.duration+', afterFinnish: function(){ $(\'axmsg_'+this._traceId+'\').remove(); }});" style="cursor:pointer;" title="Cliquez pour fermer...">';
				o += '<span class="ax-msg-content">'+msg+'</span>';
				o += '</div>';
			return o;
		},
	
	/**
	 * 	Send report to user prompt
	 */
	prompt : function(msg)
		{
			
			if($('MASTER_PROMPT'))
				$('MASTER_PROMPT').innerHTML = msg;
			
		},
			
	getFrame: function()
		{
			return this.frames;
		},
	
	/*
	 * Retourne l'instance du contrôleur de la frame en cours (MASTER_FRAME_X)
	 */
	getLayer: function(layer)
		{
			return this.frames.tab();
		},

	getWindow: function()
		{
		
			return this._frm;
		
		},

	progress: function( msg )
		{
			//if(this._frm)
			//	this.closeWin();
				
			var frm = new AX_popFrm;
			this._frm.push(frm);
			var w = (this._frm.length - 1)
			this._cfrm = w;
			frm.open();
			frm.grow(100,45);
			frm.msg('<div style="text-align:center;"><img src="'+apcphpkod.constantes.ICO_PATH+'normal/loading.gif" /><br />'+msg+'</div>');
		},


	frm: function( url, opts )
		{
			opts = opts || {};
			var opt = {
				width: opts.width || 650,
				height: opts.height || 450,
				close: opts.close || true,
				onLoad : ( opts.onLoad || function(){} ),
				title : opts.title || 'Untitled',
				foot : opts.foot || ''
			}					

			/*if(this._frm)
				this.closeWin();*/

			var frm = new AX_popFrm;
			this._frm.push(frm);
			var w = (this._frm.length - 1)
			this._cfrm = w;
			frm.open();
			frm.setTitle(opt.title);
			if(opt.foot)
				{
					frm.setFooter(opt.foot);
				}
			frm.grow(opt.width,opt.height);
			var o = '<iframe class="DHTML_frm" style="width:100%; height:100%; border:none; margin:none;" id="DHTML_frm"  src="'+url+'" frameborder="0">';
			o += '</iframe>';
			$(frm._cnt).innerHTML = o;
			$(frm._cnt).setStyle('overflow:hidden;');
			if(opt.close === false)
				return;
				
			Event.observe(frm._bg, 'click',function(){ Ax.closeWin(w); });
		  	Event.observe(frm._close,'click',function(){ Ax.closeWin(w); });
		 	$(frm._close).show();
			return frm;

			
		},


	jxfrm: function( url, onLoad, opts )
		{
			opts = opts || {};
			var opt = {
				width: opts.width || 650,
				height: opts.height || 450,
				onLoad : onLoad || ( opts.onLoad || function(){} ),
				foot : opts.foot || '',
				close: opts.close || true,
				title : opts.title || 'Untitled'
			}
			if(typeof(onLoad) == 'function')
				opt.onLoad = onLoad;
			if(typeof(onLoad) == 'object')
				{
					typeof(onLoad.onLoad == 'function')
						opt.onLoad = onLoad.onLoad;
					opt.width = onLoad.width || 550;
					opt.height = onLoad.height || 450;
				}
			/*if(this.frame)
				{
					this.frame.close();
				}*/
			window.Ax._ts = (new Date()).getTime();
			var frm = new AX_popFrm;
			this._frm.push(frm);
			var w = (this._frm.length - 1)
			this._cfrm = w;
			frm.open();
			frm.setTitle(opt.title);
			if(opt.foot)
				{
					frm.setFooter(opt.foot);
				}
			frm.grow(80,80);
			frm.msg('<img src="http://icos.apconcept.net/normal/loading.gif" alt="Loading" />');
			var _frm = frm;
			new Ajax.Request( url,
			  {
				method:'get',
				onSuccess: function(transport){
				  _frm.grow(opt.width,opt.height, opt.onLoad );
				  $(_frm._cnt).innerHTML = transport.responseText;
				  Event.observe(_frm._bg,'click',function(){ window.Ax.closeWin(w); });
				  Event.observe(_frm._close,'click',function(){ window.Ax.closeWin(w); });
				  $(_frm._close).show();
				  var te = (Math.round(((new Date()).getTime() - window.Ax._ts))/1000);
				  window.Ax.trace('End loading frame content in '+te+' s');
				  opt.onLoad();
				},
				onFailure: function(transport){
					var response = transport.responseText || "no response text";
					alert(response);
					window.Ax.closeWin();
					window.Ax.trace('Error on return script');
					
				}
			  });
			  return frm;
			
		},

	
	win:function(c, opts){
		
		opts = opts || {};
		var opt = {
			width: opts.width || 600,
			height: opts.height || 450,
			close: opts.close || true,
			onLoad : ( opts.onLoad || function(){} ),
			title : opts.title || 'Untitled',
			foot : opts.foot || '',
			noescape : opts.noescape || false,
			grow : opts.grow === false ? false : true
		}
		/*if(this._frm)
			this.closeWin()*/
		var frm = new AX_popFrm;
		this._frm.push(frm);
		var w = (this._frm.length - 1)
		this._cfrm = w;
		frm.open();
		frm.setTitle(opt.title);
		if(opt.foot)
			frm.setFooter(opt.foot);
		
		frm.grow( opt.width, opt.height, function(){ frm._cnt.innerHTML = c; opt.onLoad() }, opts.grow);
		
		if(opt.noescape !== true)
			{
				Event.observe(frm._bg, 'click',function(){ Ax.closeWin(w); });
				Event.observe(frm._close,'click',function(){ Ax.closeWin(w); });
				$(frm._close).show();
			}
			
		return frm;
		
	},
	
	ask : function(msg, yes, no, opts){
		
		var opts = opts || {};
		var opt = { 
					ico: opts.ico || false, 
					save : opts.save || false, 
					skip : opts.skip || false, 
					title : opts.title || 'Message :',
					width : opts.width || 300,
					height : opts.height || 150,
					// Possibilite de fermer la fenetre.
					noescape : opts.noescape || false,
					};
		
		var o ='';
		o += '  <div align="center">';
		
		if(opt.ico !== false && opt.ico != 'undefined') 
			{
				o += '<table width="100%"><tr>';
				o += '<td><img name="'+name+'" src="'+ICO_PATH+opt.ico+'" hspace="10" /></td>';
				o += '<td><p style="font-size:13px; color:#333333;">'+msg+'</p></td>';
				o += '</tr></table>';
				
			} 
		else
			o += '<p style="font-size:13px; color:#333333; margin:15px;">'+msg+'</p>';
			
		if(yes != false)
			o +=  mkButton('yes',yes);
		if(no != false)
			o +=  mkButton('no',no);
		if(opt.save != false && opt.save != null)
			o +=  mkButton('save',opt.save);
		if(opt.skip === true)
			o += mkButton('annul','C_close();');
			
		o += '</div>';
		
		return Ax.win(o,{close:false,width:opt.width,height:opt.height,title:opt.title,noescape:opt.noescape});
				
	},
	
	gw: function(id){
		
		var w = id || (this._frm.length-1);
		return this._frm ? this._frm[w] : null;
		
	},
	
	cw: function(w){ this.closeWin(w); },
	
	closeWin: function(winId)
	{
		if(typeof(this._frm) != 'object')
			return false;
		var w = winId || (this._cfrm);
		this._frm[w].close();
		this._frm[w] = null;
		this._cfrm-= 1;
	},
	
	includeScript: function(src, attributes)
		{
			try {
				attributes = attributes || {};
				attributes.type = "text/javascript";
				attributes.src = src;
		 
				var script = document.createElement("script");
				for(aName in attributes)
					script[aName] = attributes[aName];
		 
				document.body.appendChild(script);
				return true;
			} catch(e) { return false; }
			
		},
	
	homeInit: function( mods )
		{
			
			this._home = new AX_homeController(  );
			this._home.loadModules( mods );
			
		}
	
	
};
var AX_appFrameController = Class.create();
AX_appFrameController.prototype = {

	display:'standard',		// set actual display mode
	
	topframe: null,			// Haut du programme (widget, logo...)
	mainframe: null,		// Contenu du programme (tabs, menus etc...)
	tabframe: null,			// Menu Tabs
	tablayerframe: null,	// Contenu des tabs (layers)
	tabs: [],
	maintab: null,			// Tab en cours
	ism:null,
	
	constantes: {
		
		PATH: '',
		HTTP_LOGIN_PATH: '',
		HTTP_TPL_PATH: '',
		HTTP_PLUGIN_PATH: '',
		ICO_PATH: '',
		IDS: '',
		
	},
	
	options: {
	},
	
	initialize: function(constantes,options){
	
		this.topframe = $('MASTER_TOP');
		this.mainframe = $('MASTER_CONTENT');
		this.tabframe = $('MAIN_MENU_TOP');
		this.tablayerframe = $('MASTER_FRAMES');
		this.tabs[0] = new AX_appTabController('MASTER_FRAME_0');
		this.ism = new AX_appIsmController;
		this.maintab = this.tabs[0];
		return this;
	
	},
	
	tab: function(i){
		
		var k = i || 0;
		return this.tabs[k];
		
	},
	
	switchFs: function()
		{
			switch(this.display)
				{
					case 'standard' :	this.minimize(); break;
					case 'minimize' : 	
					default			:	this.standard(); break;
				}
		},
	
	minimize: function()
		{
			this.maintab.menu.style.display = 'none';
			this.topframe.style.display = 'none';
			this.tabframe.style.display = 'none';
			this.display = 'minimize';
		},
	
	standard: function()
		{
			this.maintab.menu.style.display = 'block';
			this.topframe.style.display = 'block';
			this.tabframe.style.display = 'block';
			this.display = 'standard';
		}
	

};
var AX_appTabController = Class.create();
AX_appTabController.prototype = {

	id: null,
	tab:null,
	top:null,
	menu:null,
	main:null,	
	
	menuStatement: 'open',
	lay: 'MAJOR',
	
	options:{

	},
	
	initialize: function(id){
		this.tab = $(id);
		this.id = id;
		//alert(this.id);
		this.top = this.tab.childNodes[1];
		this.menu = this.tab.childNodes[3];
		this.main = this.tab.childNodes[5];
		this.resize();
	},
	
	append : function( c ){
		
		this.main.innerHTML += c;
		
	},
	
	prepend : function( c ){
		
		var _t = this.main.innerHTML;
		this.main.innerHTML = c + _t;
		
	},
	
	html : function( c ){
		
		this.main.innerHTML = c;
		
	},
	
	// Met a jour la hauteur des layers
	resize:function(){
		
		var finalHeight = this.getHeight();
		$(this.id+'_MENU').setAttribute('style','height:'+finalHeight+'px;');
		$(this.id+'_BODY').setAttribute('style','height:'+finalHeight+'px;');
		
		
	},
	
	getHeight : function(){
		
		var OffsetScreenHeight = $(document.body).getHeight();
		var topOffsetHeight = $('MASTER_TOP').getHeight();
		topOffsetHeight += $('MAIN_MENU_TOP').getHeight();
		topOffsetHeight += $('MASTER_MAIN_MENU').getHeight();
		topOffsetHeight += 44;
		return OffsetScreenHeight - topOffsetHeight;
		
	},
	
	switchMenu: function(menu){
		
		if(this.menuStatement === 'close')
			this.openMenu();
		if(this.lay === 'MAJOR')
			{
				$( this.id+'_MAJOR_MENU' ).hide();
				$( this.id+'_MODULE_MENU' ).show();
				$( this.id+'_MAJOR_ONGLET').removeClassName('onglet_over').addClassName('onglet');
				$( this.id+'_MODULE_ONGLET').addClassName('onglet_over').removeClassName('onglet');
				this.lay = 'MODULE';
			}
		else
			{
				$( this.id+'_MAJOR_MENU' ).show();
				$( this.id+'_MODULE_MENU' ).hide();
				$( this.id+'_MAJOR_ONGLET').addClassName('onglet_over').removeClassName('onglet');
				$( this.id+'_MODULE_ONGLET').removeClassName('onglet_over').addClassName('onglet');
				this.lay = 'MAJOR';
			}
		
	},
	
	closeMenu: function()
		{
			Effect.BlindUp( this.id+'_MENU_LAYER' ,{scaleX:true, scaleY:false,duration:0.3});
			$( this.id+'_MAJOR_ONGLET').removeClassName('onglet_over').addClassName('onglet');
			$( this.id+'_MODULE_ONGLET').removeClassName('onglet_over').addClassName('onglet');
			this.menuStatement = 'close';
		},
		
	openMenu: function()
		{
			Effect.BlindDown( this.id+'_MENU_LAYER' ,{scaleX:true, scaleY:false,duration:0.3});
			$( this.id+'_'+this.lay+'_ONGLET').addClassName('onglet_over').removeClassName('onglet');
			this.menuStatement = 'open';
		},
	
	dispMenu: function()
		{
			if(this.menuStatement === 'open')
				this.closeMenu();
			else
				this.openMenu();
		}

};

var AX_connexionController = Class.create();
AX_connexionController.prototype = {
	
	// Le timer
	ctimer: null,
	// Le décompte de temps
	cinterval: null,
	// Le nb de sec restante avant expiration
	climit: 60,
	// Le temps de connexion avant expiration du cookie, en secondes
	cCookieTime: 1600,
	// ce qu'on enleve en période de sécurité
	cMinusCookie: 200,
	
	initialize: function(){
		var cTime = ( ( this.cCookieTime - this.cMinusCookie ) * 1000 );
		this.ctimer = setTimeout("Ax.timer.askTimeOut()", cTime);
	},
	
	askTimeOut: function(){
		Ax.ask(
			'Votre session va expirer prochainement.<br />Souhaitez-vous prolonger la session ?<br />Temps restant : <span id="timerOutExpire">60</span> s',
			'Ax.timer.continueSession();',
			'Ax.timer.closeSession();',
			{title:'Expiration de la session', ico:'normal/clock_32.png', width:350,noescape:true}
			);
		this.cinterval = window.setInterval("Ax.timer.nextInterval();",1000);
	},
	
	nextInterval: function(){
		this.climit = this.climit-1;
		if(this.climit == 0)
			{
				this.resetInterval();
				this.closeSession();
			}
		else
			{
				$('timerOutExpire').innerHTML = this.climit;
				document.title = this.climit+' s avant expiration de la session';
			}
	},
	
	continueSession: function(){
		if(this.cinterval)
			{
				this.resetInterval();
			}
		xajax_AX_timerSession();
		C_close();
		MkProgress('Prolongation de la session en cours...');
		document.title = 'AdminXtration';
	},
	
	closeSession: function(){
		if(this.cinterval)
			{
				this.resetInterval();
			}
		C_close();
		MkProgress('Fermeture de la session en cours...');
		window.location = '/logout.php?IDS='+apcphpkod.constantes.IDS;
	},
	
	resetInterval: function(){
		this.climit = 60;
		window.clearInterval(this.cinterval);
		this.cinterval = null;
	},
	
	timerReset: function(){
		this.initialize();
	}
	
};

var AX_appIsmController = Class.create();
AX_appIsmController.prototype = {

	// Statement
	statment: 'init',	
	// Main widget layer
	l: null,
	f: null,
	img : null,
	txt : null,
	handler: null,
	
	user : null,
	lu:[],
	
	// Liste des utilisateurs connectes
	plist: null,
	mplist:[],
	// Liste des messages
	mlist: null,
	mfrm: [],
	
	_open:false,
	
	countmsg:0,
	countu:0,
	
	_tm: null,
	
	options:{

	},
	
	initialize: function(){
		this.l = $('WIDGET_ISM');
		this.f = $('WIDGET_USER_ISM');
		this.handler = $('TOP_PROMPT');
		this.img = $('TOP_PROMPT_IMG');
		this.txt = $('TOP_PROMPT_MSG');
		this.plist = $('ISM_U_LIST');
		this.mlist = $('WIDGET_USER_ISM_M');
		this.statment = 'init';
		this.handler.onclick = function(){ Ax.getFrame().ism.open(); };
		this.user = apcphpkod.constantes.ADMIN_USER_ID;
		// On créé la première div dans la liste des messages, pour afficher les erreurs etc...
		var f = document.createElement('div');
		f.className = 'ISM_MFRM home';
		this.mlist.appendChild(f);
		this.mfrm[0] = f;
		
		this.disp();
		this.queryMsg();
		
	},
	
	disp : function(msg){
		var _img;
		var _msg;
		switch(this.statment)
			{
				case 'init'		:	_img = 'mail_info.png'; 
									_msg = 'Veuillez patienter...'; 
									break;
				case 'refresh' 	: 	_img = 'mail_receive.png'; 
									_msg = 'Patientez...'; 
									break;
				case 'wait'		:	if(!this.countmsg)
										{
											_msg = 'Aucun message';
											_img = 'mail.png';
										}
									else
										{
											_msg = 'Vous avez '+this.countmsg+' message';
											if(this.countmsg > 1)
												_msg+='s';
											_img = 'mail_accept.png';
											this.open();
										}
									break;
				default			:	_img = 'mail_warning.png'; 
									_msg = 'Error'; 
									break;
			}
		this.img.src = window.apcphpkod.constantes.ICO_PATH+'small/'+_img;
		this.txt.innerHTML = _msg;
	},
	
	/*
	 * Retour de la requete Ajax
	 */
	q: function(ls, lu){
		// Un liste les utilisateurs
		this.countu = 0;
		if(lu)
			{
				lu.each(this.Uparse.bind(this))
			}
		// On remet a 0 les pages de message
		if(this.mfrm)
			{
				this.mfrm.each(function(e){
						if(!e['id'])
							return;
						e.resetMsg();
						});
			}
		// On affiche les messages...
		this.countmsg = 0;
		if(ls && ls.size() > 0)
			{
				ls.each(this.Qparse.bind(this))
				
				if(this.mfrm && this._open === true)
					{
						var o = ls.last();
						var u = (o['to'] !== this.user) ? o['to'] : o['from'];
						this.msgfrm(u).focus();
					}
			} 
			
		if(!this.mplist['970001'])
			{
				// et on créer l'utilisateur Support
				var u = {num_live:'970001',nom:'',prenom:'Support',icon:'users_comments.png',online:0};
				if( this.lu['970001'] )
					u['online'] = this.lu['970001']['online'];
				var s = new AX_IsmLiUser(u);
				this.mplist['970001'] = s;
			}
		this.statment = 'wait';
		this.disp();
	},
	
	/** 
	 * Met a jour contacts et messages
	 */
	u: function(l, u){
		if(u)
			{
				var _t = this;
				u.each(function(o,i){ _t.getUser(o.num_live) })
			}
	},
	
	// Retourne les infos sur un utiilisateur
	getUser: function(id){
		return this.lu[id] ? this.lu[id] : {num_live:id};
	},
	
	// On parsde les utilisateurs
	Uparse: function(u){
		
		this.lu[u['num_live']] = u;
		
		if(u['num_live'] === this.user)
			return;
		
		if(!this.mplist[u['num_live']])
			{
				this.countu+=1;
				this.mkUsrLi(u);
			}
		else
			{
				this.mplist[u['num_live']].refresh(u);
			}
	},
	
	// On parse les messages
	Qparse: function(o)
		{
			var dest = o['to'];
			var from = o['from'];
			if(from != this.user)
				this.countmsg+=1;
			
			if(this._open !== true)
				return;
			
			var u = (dest !== this.user) ? dest : from;
			if(!this.mplist[u])
				this.mkUsrLi(this.getUser(u));

			//alert(Ax.getFrame().ism.msgfrm(u));
			Ax.getFrame().ism.msgfrm(u).addMsg(o, (o.id ? false : true));
		},
	
	err: function(msg){
		var o = '<div class="error">';
		o+= '<p align="center"><img src="'+apcphpkod.constantes.ICO_PATH+'large/comment_remove.png"></p>';
		o+= '<p align="center">'+msg+'</p>';
		o+= '</div>';
		this.msgfrm(0).innerHTML = o;
		this.statment = 'error';
		this.disp();
	},
	
	queryMsg: function(){
		
		if(this._open === true)
			return;
			
		this.statment = 'refresh';
		this.disp();
		xajax_getIsm(window.apcphpkod.constantes.IDS);
		
		if(this._tm !== null)
			window.clearTimeout(this._tm);
		this._tm = window.setTimeout(this.queryMsg.bind(this),(60 * 1000));
		
	},
	
	open: function(){
		if(this._open === true)
			return;
		Effect.BlindDown(this.f);
		this.handler.onclick = function(){ Ax.getFrame().ism.close(); };
		this.queryMsg();
		this._open = true;
		
	},
	
	close: function(){
		if(this._open === false)
			return;
		this.f.style.display = 'none';
		this.handler.onclick = function(){ Ax.getFrame().ism.open(); };
		this._open = false;
		
		if(this._tm !== null)
			window.clearTimeout(this._tm);
		this._tm = window.setTimeout(this.queryMsg.bind(this),(60 * 1000));
	},
	
	refresh: function(){
		/*if(this._open !== true)
			return;
		xajax_getIsm(apcphpkod.constantes.IDS, this.id);*/
		/*window.setTimeout(this.refresh.bind(this),10000);*/
	},

	
	msgfrm: function(id){
		return this.mfrm[id] ? this.mfrm[id] : this.mkFrm(id);
	},
	
	mkFrm: function(id){
		if(!id)
			alert('Empty id for building frame on Ax_appsIsmController');
		var o = new AX_IsmFrm(id);
		this.mfrm[id] = o;
		return o;
	},
	
	mkUsrLi:function(u){
		var l = new AX_IsmLiUser(u);
		this.mplist[u['num_live']] = l;
	},
	// envoi un message
	send:function(to, val){
		if(!val)
			alert('Empty message');
		this.Qparse({from:this.user,to:to,msg:val},true);
		xajax_ism_send(apcphpkod.constantes.IDS, to, val);
	}
};

var AX_IsmLiUser = Class.create();
AX_IsmLiUser.prototype = {

	id : null,

	u: null,
	l: null,
	online: false,
	
	initialize: function(u){
		this.id = u['num_live'];
		this.online = u['online'];
		var l = document.createElement('li');
		this.l = l;
		this.u = u;
		this.buildLi();
		this.l.onclick = this.clik.bind(this);
		if(this.online == true)
			Insertion.Top(Ax.getFrame().ism.plist, this.l);
		else
			Ax.getFrame().ism.plist.appendChild(l);
	},
	
	buildLi:function(){
		var dsp = this.u['prenom'] ? this.u['prenom']+' '+this.u['nom'] : this.u['num_live'];
		var ol = (this.u['online']==1) ? true: false;
		var icon = this.u['icon'] ? this.u['icon'] : (ol ? 'user_comment.png' : 'user_1.png');
		var infop = (this.id === '970001') ? 'Support' : '&nbsp;';
		this.l.innerHTML = '<img src="'+apcphpkod.constantes.ICO_PATH+'normal/'+icon+'" align="left" vspace="5">';
		this.l.innerHTML += '<span class="level">'+infop+'</span>';
		this.l.innerHTML += '<span class="name">'+dsp+'</span>';
		this.l.innerHTML += '<span class="state">'+(ol?'En ligne':'Hors ligne')+'</span>';
	},
	
	clik: function(){
		Ax.getFrame().ism.msgfrm(this.id).focus();
	},

	focus: function(){
		this.l.className = 'active';
	},
	
	hide:function(){
		this.l.className = '';
	},
	
	refresh: function(u){
		if(u['online'] !== this.online)
			{
				this.u = u;
				this.online = u['online'];
				this.buildLi();
				Insertion.Top(Ax.getFrame().ism.plist, this.l);
			}
	}

};

var AX_IsmFrm = Class.create();
AX_IsmFrm.prototype = {
	
	id:null,
	
	frm:null,
	mfrm:null,
	
	i:null,
	
	_from:null,
	
	_msgtmp:null,
	
	_open:false,
	
	_lsm : null,
	
	_tm : null,
	
	initialize: function(id){
		
		this._lsm = new Array;
		
		this.id = id;
		this.frm = document.createElement('div');
		this.frm.className = 'ISM_MFRM';
		this.frm.id = 'ISM_MSG_'+id;
		this.frm.style.display = 'none';
		this.mfrm = document.createElement('div');
		this.mfrm.className = 'ISM_MSG';
		var ip = document.createElement('div');
		ip.className = 'ISM_INP';
		this.i = document.createElement('input');
		this.i.type = 'text';
		this.i.onkeypress = this.key.bind(this);
		this.i.maxlength = 255;
		
		var lk = document.createElement('span');
		lk.className = 'actionTools';
		var la = document.createElement('a');
		la.href= 'javascript:void(0);';
		la.onclick = this.eraseAll.bind(this);
		la.innerHTML = 'Effacer la discussion';
		lk.appendChild(la);
		ip.appendChild(lk);
		ip.appendChild(this.i);
		this.frm.appendChild(this.mfrm);
		this.frm.appendChild(ip);
		Ax.getFrame().ism.mlist.appendChild(this.frm);
		return this;
	},
	
	eraseAll: function(){
		xajax_ism_delFromSender(apcphpkod.constantes.IDS,this.id);
		//this.resetMsg();
	},
	
	key: function(e){
		
		var myevent=window.Event?e:event;
		var ascii=window.Event?e.which:event.keyCode;
		if(myevent.keyCode == 13)	
			{
				Ax.getFrame().ism.send(this.id,this.i.value);
				this.i.value = '';
			}
	},
	
	hide: function(){
		this.frm.style.display = 'none';
		this._open = false;
	},
	
	focus: function(){
		Ax.getFrame().ism.mfrm.each(function(e){ e.hide(); });
		Ax.getFrame().ism.mplist.each(function(e){ e.hide(); });
		Ax.getFrame().ism.mplist[this.id].focus();
		this.frm.style.display = 'block';
		this.i.focus();
		this._open = true;
		if(Ax.getFrame().ism._open === true)
			this.refresh();
	},
	
	// Remet a 0 la page des messages...
	resetMsg: function(){
		this.mfrm.innerHTML = '';
		this._from = null;
		this.i.focus();
	},
	
	addMsg: function(m, fromSend){
		
		
		if(this._from != m['from'])
			{
				var u = Ax.getFrame().ism.lu[m['from']];
				if(u)
					var name = u['prenom'] + ' '+ u['nom'];
				else
					var name = m['from'];
				this.mfrm.innerHTML += '<span class="isminfos">'+name+''+(m['send']?' ,'+m['send']:'')+'</span>';
			}
		var cl = (m['from'] == this.id) ? 'u' : 'i';
		cl += ' '+(fromSend === true ? 'fromsend' : '');
		cl += ' '+(m['id']?'sent':'send');
		this.mfrm.innerHTML += '<div class="ismmsg '+cl+'" id="'+(m['id']?'ISM_MSG_'+m['id']:'ISM_MSG_'+this.id+'_send')+'">'
							  +'<span class="quote">'+m['msg']+'</span>';
							  +'</div>';
		this._from = m['from'];
		
		this._lsm.push(m.id);
		
	},
	
	sok: function(id){
		$('ISM_MSG_'+this.id+'_send').id = 'ISM_MSG_'+id;
		$('ISM_MSG_'+id).className = 'ismmsg i sent';
		this._lsm.push(id);
	},
	
	serr: function(e){
		this.mfrm.innerHTML += '<span class="ismerr">Votre message n\'a pas pu etre envoye : '+e+'</span>';
	},
	
	refresh: function(){
		
		if(this._open !== true)
			return;
		
		xajax_getIsm(apcphpkod.constantes.IDS, this.id);
		Ax.getFrame().ism.statment = 'refresh';
		Ax.getFrame().ism.disp();
		
		if(this._tm !== null)
			window.clearTimeout(this._tm);
		this._tm = window.setTimeout(this.refresh.bind(this),10000);
		
	},
	
	q: function(ls){
		
		//this.resetMsg();
		$(this.mfrm).getElementsBySelector('.fromsend').each(function(e,i){ e.remove(); });
		$(ls).each(function(o,i){
				
				if($(this._lsm).member(o.id) !== true)
					this.addMsg(o);
			
			}.bind(this))
		
		Ax.getFrame().ism.statment = 'wait';
		Ax.getFrame().ism.disp();
		
	},
	
};



var AX_popFrm = Class.create();
AX_popFrm.prototype = {
		
	_bg: null,
	_frm: null,
	_cnt: null,
	_close: null,
	_title: null,
	_footer : null,
	
	width:550,
	height:350,
	ftime: 0.3,
	
	_zIndex:999,
	
	options : {
		afterFinnish : function(){ }
		},
	
	initialize: function()
		{
			this._build();
		},
	
	_build: function()
		{
			this._bg = document.createElement('div');
			this._bg.className = 'dhtml';
			this._bg.style.display = 'none';
			this._bg.style.zIndex = this._zIndex;
			
			this._frm = document.createElement('div');
			this._frm.className = 'dlayer';
			this._frm.style.width = this.width ? this.width+'px' : '';
			this._frm.style.height = this.height ? this.height+'px' : '';
			this._frm.style.zIndex = this._zIndex+1;
			
			this._title = document.createElement('div');
			this._title.className = 'dtitle';
			this._title.innerHTML = 'Dialog Box v3.1.201';
			
			this._close = document.createElement('a');
			this._close.className = 'closeDhtml';
			this._close.style.display = 'none';
			this._close.style.zIndex = this._zIndex+1;
			
			this._footer = document.createElement('div');
			this._footer.className = 'dfoot';

			
			this._cnt = document.createElement('div');
			this._cnt.className = 'dcnt';
			
			document.body.appendChild(this._bg);
			document.body.appendChild(this._frm);
			this._frm.appendChild(this._close);
			this._frm.appendChild(this._title);
			this._frm.appendChild(this._cnt);
			this._frm.appendChild(this._footer);
			
			AX_popFrm.prototype._zIndex += 2;
			
		},
	
	_center: function(e)
		{
			var height = e.offsetHeight;
			var width= e.offsetWidth;
			myParent=document.body;
			if (window.innerHeight) {
				pHeight = window.innerHeight;
				pWidth = window.innerWidth;
			} else { // IE
				pHeight = document.documentElement.clientHeight;
				pWidth = document.documentElement.clientWidth;
			}
			var sTop=myParent.scrollTop;
			var sLeft=myParent.scrollLeft;
			var posY=(pHeight/2)-(height/2)+sTop;
			var posX=(pWidth/2)-(width/2)+sLeft;
			e.style.top=posY+"px";
			e.style.left=posX+"px";
		},
	
	grow:function(w, h, onFinnish, growSpeed)
		{
			onFinnish = onFinnish ? onFinnish : function(){};
			
			if(growSpeed === false || growSpeed === 0)
				{
					$(this._frm).setStyle('width:'+w+'px; height:'+h+'px;');
					this._center(this._frm);
					onFinnish();
					return;
				}
				
			$(this._cnt).hide();
			$(this._footer).hide();
			var _ist = this;
			
			/*$(this._frm).setStyle({width:w+'px;', height:h+'px;'});
			Effect.Appear(_ist._cnt);
			return;*/
			
			//alert('start morph');
			$(this._frm).morph('width:'+w+'px; height:'+h+'px;', {
							duration:'0.2',
							afterFinish : function(){
								var ht = $(_ist._title).getHeight();
								$(_ist._cnt).setStyle('height:'+(h-ht)+'px;')
								Effect.Appear(_ist._cnt, {duration:'0.2'});
								Effect.BlindDown(_ist._footer,{duration:0.4});
								onFinnish();
							},
							afterUpdate: function()
							{
								_ist._center(_ist._frm);
							}});
		},
	
	setTitle : function(title)
		{
			this._title.innerHTML = title;
		},
		
	setFooter : function(c)
		{
			this._footer.innerHTML = '<div class="cnt">'+c+'</div>';
		},
	
	msg: function(txt)
		{
			this._cnt.innerHTML = '<div class="sp">' + txt + '</div>';
		},
	
	content: function( txt )
		{
			this._cnt.innerHTML = txt;
		},
	
	open: function()
		{
			this._center( this._frm );
			Effect.Appear(this._bg, {duration:this.ftime, to:'0.65' } );
		},
	
	close: function()
		{
			var _bg = this._bg;
			var _afterFinnish = this.options.afterFinnish;
			Effect.Fade(this._bg, {duration:this.ftime, afterFinish:function(e){ $(_bg).remove(); _afterFinnish(); } } );
			$(this._frm).remove();
		}
		
	
}
var MkWin = function(c, width, height, _options){
	

	var __options = _options || {};
	Ax.win(c,{name:name,title:__options.title,close:__options.close,drag:__options.drag,width:width,height:height,onLoad:(__options.onLoad?(typeof(__options.onLoad) === 'string' ? function(){ eval(__options.onLoad) } : __options.onLoad):null)});
			
}
var MkFrame = function(url,name,width,height,_options){
	
	var __options = _options || {};
	Ax.frm(url,{name:name,title:__options.title,close:__options.close,drag:__options.drag,width:width,height:height,onLoad:__options.onLoad});

}
var MkProgress = function(msg){
	
	Ax.progress(msg);

}

var MkAsk = function(content, yes, no, skip, ico, save)
{
	
	var __options = { skip : true || false, ico : ico || false, save : save || false };
	Ax.ask( content, yes, no, __options );
	return false;
	/*var o ='';
	o += '  <div align="center">';
	
	if(ico !== false) {
		
		if(ico == null) ico = 'normal/importantquest.gif';
		o += '<table width="100%"><tr>';
		o += '<td><img name="'+name+'" src="'+ICO_PATH+ico+'" hspace="10" /></td>';
		o += '<td><p style="font-size:13px; color:#333333;">'+content+'</p></td>';
		o += '</tr></table>';
	} 
	else
		o += '<p style="font-size:13px; color:#333333; margin:15px;">'+content+'</p>';
	
	if(yes != false)
		o +=  mkButton('yes',yes);
	if(no != false)
		o +=  mkButton('no',no);
	if(save != null)
		o +=  mkButton('save',save);
	if(skip != false)
		o += mkButton('annul','C_close();');
	
	
	o += '</div>';

	Ax.win(o,{close:false,width:300,height:150});
	return false;*/
	
}

var MkAlert = function(content, ico)
{
	
	var o ='';
	o += '  <div align="center" style="margin:15px;">';
	
	if(ico !== false) {
		
		if(ico == null) ico = 'normal/importantinfo.gif';
		o += '<table width="100%"><tr>';
		o += '<td><img name="'+name+'" src="'+ICO_PATH+ico+'" hspace="10" /></td>';
		o += '<td><p style="font-size:13px; color:#333333;">'+content+'</p></td>';
		o += '</tr></table>';
	} 
	else
		o += '<p style="font-size:13px; color:#333333;">'+content+'</p>';
	
	o += mkButton('ok','C_close();');
	o += '</div>';

	Ax.win(o,{close:false,width:300,height:150});
	return false;
	
}


var C_close = function(){
	Ax.closeWin();
}

var P_close = function(){
	Ax.closeWin();
}


var AX_editFormTab = function(id,i)
	{
		this.initialize(id,i);
		return this;
	}

AX_editFormTab.prototype = {

	id : null,
	/*
	 * ID d'instance
	 */
	_i : null,
	/*
	 * menu
	 */
	_m: null,
	/*
	 * Layer
	 */
	_l: null,
	/*
	 * Lignes
	 */
	_tabs: [],
		
	initialize: function(id, i)
		{
			this.id = id;
			this._i = i;
			this._tabs = new Array;
			this._m = $('btn'+id) || null;
			this._l = 	$(id) || null;
			this._l.hide();
			this._m.observe('click', function(){ window.phpkod.plugins.formLayer.switchTab(this._i); }.bind(this));
			
			$(id).getElementsBySelector('.line').each(function(o,i){ this._tabs.push( new AX_editFormLine(o,i) );  }.bind(this));
			
			Ax.onLoad( function(){
				Ax.trace('is loade d*******************');
				$$('#'+id+' .right.auto-width').each(function(o,i){ 
						var w = $($(o).getOffsetParent()).getWidth();
						// On enlève de la largeur le scroll et le layer de gauche
						$(o).setStyle({width : (w-245-20)+'px'});
					});
					
				$$('#'+id+' .right.auto-height').each(function(o,i){ 
						
						var h = Ax.getFrame().tab().getHeight();
						if($$('h1.h').length > 0)
							h -= 59;
	
						if($$('.CBODY .hmenu').length > 0)
							h -= 40;
						
						$(o).setStyle({height : (h-70)+'px', overflow:'auto'});
					});
				});
				
				
		},
	
	open : function()
		{
		
			Effect.Appear(this._l, {duration:0.5})
			this._m.addClassName('over');
		
		},
	
	close : function()
		{
			this._l.hide();
			this._m.removeClassName('over');
		}

}

var AX_editFormLine = function(l)
	{
		this.initialize(l);
		return this;
	}

AX_editFormLine.prototype = {

	/*
	 * Layer contenant la ligne
	 */
	_l: null,
	_h: null,
	_i:null,
	_ck:null,
	
	initialize: function(l)
		{
			this._l = $(l);
			this._h = $(l).getElementsBySelector('.help')[0] || null;
			this._i = 	$(l).getElementsBySelector('.inp')[0] || null;
			this._ck = 	$(l).getElementsBySelector('.activate')[0] || null;
			
			if(this._h)
				this._h.hide();

			if(this._ck)
				{
					this.switchActivate();
					var e = $(this._ck).childElements()[0];
					Event.observe(e, 'change', function(){
						this.switchActivate();
					}.bind(this));
						
				}
			
			if(this._h && this._i)
				{
					var e = $(this._i).childElements()[0];
					Event.observe( e, 'focus', function(){ 
							//alert('show help for input '+this._h.innerHTML);
							Effect.Appear(this._h, {duration:0.3}); 
							this._h.absolutize();
							//this._h.setStyle({top:this._l.getLayout().get('top')+'px;'});
							//this._h.show();
						}.bind(this) 
						);
					Event.observe( e, 'blur', function(){ 
							this._h.hide(); 
						}.bind(this) 
						);
				}
		
		},
	
	switchActivate: function()
		{
			
			if(this._ck)
				{
					var e = $(this._ck).childElements()[0];
					if(e.checked)
						{
							$(this._i).childElements()[0].disabled = '';
							$(this._i).childElements()[0].focus();
							$(this._l).removeClassName('disabled');
						}
					else
						{
							$(this._i).childElements()[0].disabled = 'disabled';						
							$(this._l).addClassName('disabled');
						}
				}
			
		}

}


/*
 * Classe de controle de la page d'accueil
 */

var AX_homeController = function(mods)
	{
		this.init(mods)
		return this;
	}

AX_homeController.prototype = 
	{
	
		/*
		 * LoadedModules instances
		 * Array
		 */
		_lmds : [],
		/*
		 * LoadedModules keys
		 * Array
		 */
		_lmdk : [],
		
		_layer : null,
		
		_cpos : 'rssTop',
		
		_csize : 'large',
		
		_toload : [],
		
		_sortable : null,
		
		_total: 0,
		_count: 0,
		
		_cel: null,
		
		init : function()
			{
				
				this._lmds = new Array;
				this._lmdk = new Array;
				this._toload = new Array;
				this._layer = $('rssMods');
				
			},
		
		loadModules: function(mods)
			{
				
				$('rssTop').innerHTML = '';
				
				var ms = mods || new Array;
				this._toload = ms;
				this._total = this._toload.length;
				this.loadNext();
					
			},
		
		loadNext : function()
			{
				
				if(this._toload.length < 1)
					return this.loadComplete();
					
				var _mc = this._toload[0];
				var _ic = new AX_smartModule(_mc, this._csize);
				this._lmds.push(_ic);
				this._lmdk.push(_mc);
				this._toload.shift();
				
			},
		
		loadComplete : function()
			{
				if(this._sortable===true)
					return;
					
				Position.includeScrollOffsets = true;
				Sortable.create( 'rssTop' , 
					{containment: ['rssTop','rssLeft','rssRight'],tag:'div', only:'mod',hoverclass:'newmod',constraint:false,dropOnEmpty:true,scroll:'MASTER_FRAME_0_BODY',scrollSpeed:5,handle:'ico',
					onUpdate:Ax._home.saveOrderer}
					);
				Sortable.create( 'rssLeft' , 
					{containment: ['rssTop','rssLeft','rssRight'],tag:'div', only:'mod',hoverclass:'newmod',constraint:false,dropOnEmpty:true,scroll:'MASTER_FRAME_0_BODY',scrollSpeed:5,handle:'ico',
					onUpdate:Ax._home.saveOrderer}
					);
				Sortable.create( 'rssRight' , 
					{containment: ['rssTop','rssLeft','rssRight'],tag:'div', only:'mod',hoverclass:'newmod',constraint:false,dropOnEmpty:true,scroll:'MASTER_FRAME_0_BODY',scrollSpeed:5,handle:'ico',
					onUpdate:Ax._home.saveOrderer}
					);
				this._sortable = true;
			},
		
		saveOrderer: function(e)
			{
				var ls = new Array;
				var tmp = $$('input[name|=mod[]]').each(function(o,i){ ls.push(o.value) });
				xajax_updateOrderMod(ls);
			},
		
		gm: function(k)
			{
				for(var i in this._lmdk)
					if(k == this._lmdk[i])
						return this._lmds[i]
				return null;
			},
		
		populate : function(o)
			{
				/*$('rssTop').appendChild( o );
				if(this._cpos == 'large')
					this._cpos = 'normal right';
				else if (this._cpos == 'normal left')
					this._cpos = 'normal right';
				else
					this.cpos = 'normal left';*/
				
				var toright = Math.ceil((this._total - 1) / 2);
				if(this._count === 0)
					{
						this._cpos = 'rssLeft';
						this._csize = 'large top';
						$('rssTop').appendChild( o );
					}
				else if(this._count <= toright)
					{
						this._cpos = 'rssLeft';
						this._csize = 'normal left';
						$('rssLeft').appendChild( o );
					}
				else
					{
						this._cpos = 'rssRight';
						this._csize = 'normal right';
						$('rssRight').appendChild( o );
					}
				this._count++;
			}
	
	}

/*
 * Class smartModule
 * Affichage du flux RSS d'un module pour un doimaine
 * Page d'accueil de l'app
 */

var AX_smartModule = function(n, s)
	{
		this.initialize(n, s);
		return this;
	}

AX_smartModule.prototype = 
	{
		
		_key : null,
		_layer : null,
		
		_layers : null,
		
		_cl: 0,
		_size : 'normal',
		
		initialize: function( moduleKey, size )
			{
				this._key = moduleKey;
				this._size = size || 'normal';
				this.buildHTML();
				this.loadLayers();
			},
		
		buildHTML : function()
			{
				
				var o = document.createElement('div')
				o.className="mod "+this._key+' '+this._size;
				o.innerHTML = '<h2>'+this._key+'</h2>';
				o.innerHTML += '<div class="load"><p><img src="'+apcphpkod.constantes.ICO_PATH+'normal/progressbar.gif" /></p><p>Chargement du module en cours...</p></div>';
				this._layer = o;
				Ax._home.populate(o);
				
			},
		
		reload: function()
			{
				this.loadLayer(this._cl,true);
			},
		
		loadLayers : function()
			{
				
				xajax__gl( this._key, '', this._size );
				
			},
		
		loadLayersResponse: function( r, l0, error )
			{
				this._layer.innerHTML = r;
				this._layers = new Array;
				this._layers.push(0);
				this.afterLoad();
				//this.loadLayersResponse(0, l0);
				//Ax._home.loadNext();
			},
		
		loadLayerError: function(l, error)
			{
				//Ax._home.loadNext();
				this._layer.getElementsBySelector('div.load')[0].innerHTML = '<div class="msg error">'+error+'</div>';
				//alert(error);
			},
		
		_mkfrm: function(o)
			{
				
			},
			
		_mkmenu: function(o)
			{
				
			},
		
		loadLayer : function( l, foceload )
			{
				if(this._layers)
					{
						$(this._layer).getElementsBySelector('.layer').each(function(o,i){ 
								
								if(i == l)
									{
										o.show();
									}
								else
									o.hide();
							
							 });
					}
					
				var f = $(this._layers).find(function(s){ return ((s == l) ? true : false); });
				if(f == undefined || foceload === true)
					{
						xajax__gl( this._key, l, this._size );
						Effect.Fade(this._layer, {to:0.3,duration:0.3});
					}
				
				this._cl = l;
				
			},
		
		loadLayerResponse : function( l, r )
			{
				
				var __k = this._key;
				this._layers.push(l);

				$(this._layer).getElementsBySelector('.layer').each(function(o,i){ 
						
						if(i == l)
							{
								o.innerHTML = r;
								o.show();
							}
						else
							o.hide();
					
					 });
				Effect.Appear(this._layer, {duration:0.3});
				this.afterLoad();
			},
		
		afterLoad : function()
			{
				var __k = this._key;
				switch(__k)
					{
						case 'News' :
							$(this._layer).getElementsBySelector('.layer div').each(function(o,i){ 
									$(o).getElementsBySelector('p').each(function(_o,_i){ $(_o).hide(); });
									$(o).observe('mouseenter', function(){ $(o).getElementsBySelector('p').each(function(_o,_i){ Effect.BlindDown(_o, {duration:0.3}); }); })
									$(o).observe('mouseleave', function(){ $(o).getElementsBySelector('p').each(function(_o,_i){ Effect.BlindUp(_o, {duration:0.3}); }); })
								});
							break;
					}

			}
	
	}

/*
 *
 * Config
 *
 *
 *
 */
var AX_MyConfig = function(){
	this.initialize();
	return this;
}

AX_MyConfig.prototype = 
	{
	
		
		initialize: function()
			{
			},
			
		home__check01 : function(){
			
			element1 = document.getElementById('useRssMod');
			element2 = document.getElementById('RssMods');
				if(element1.checked == true){
					element1.checked=false;
					element2.disabled = 'disabled';
				}
				else {
					element1.checked = true;
					element2.disabled=false;
				}
			
		},
		home__check02 : function(){
			
			element1 = document.getElementById('useRssMod');
			element2 = document.getElementById('RssMods');
				if(element1.checked == false){
					element2.disabled = 'disabled';
				}
				else {
					element2.disabled=false;
				}
			
		},
		home__check03 : function(){
			
			element1 = document.getElementById('useRappel');
			element2 = document.getElementById('RappelOften_false');
			element3 = document.getElementById('RappelOften_true');
				if(element1.checked == false){
					element2.disabled = 'disabled';
					element3.disabled = 'disabled';
				}
				else {
					element2.disabled=false;
					element3.disabled=false;
				}
			
		},
		update_StartOrderElements : function(element){
			
			var module = element.firstChild.getElementsByTagName('span')[0].innerHTML;
			var liste = document.getElementById('OrderLoadMods');
			var order = new Array();
			
			if (liste.hasChildNodes())
			// On vérifie d'abord si l'objet n'est pas vide, c.-à-d. s'il a des enfants
			{
			  var child = liste.childNodes;
			  for (var i = 0; i < child.length; i++) 
			  {
				order[i] = child[i].getElementsByTagName('span')[0].innerHTML;   
			  }
			}
			
			xajax__updateStartOrderElements(order);
			
			return true;
			
		},
		
		setSortable : function(id,onUpdatefunc){
		
			var _i = this;
		   Sortable.create(id,
			 {dropOnEmpty:true,constraint:false,tree:true,onUpdate:_i.update_StartOrderElements});
		   document.getElementById(id).className+=' Sortable';
		   
		},
		updateConf : function(elem,k){
			element = document.getElementById().value;
		},
		
		tickvalue : function(id){
			return document.getElementById(id).value;
		},
		tickcheck : function(id){
			return document.getElementById(id).checked;
		},
		
		My_updateRssMods : function(element){
			
			var array = new Array();
			
			for(var i=0; i < element.childNodes.length; i++){
				
				var e = element.childNodes[i].selected;
		
					array[ element.childNodes[i].value ] = e;
				
			}
			
			xajax__updateMyConf('RssMods',array);
			
		}
	
}

/*
 *
 *
 *
 *
 *
 *
 *	INITIALISATION DE L'APPLICATION
 *
 *
 *
 *
 *
 *
 */



var Ax = new AX_appController();

/*
New phpkod versionning
*/
window.phpkod = 
	{
		// L'objet script du head a utiliser pour les appels ajax cross-domain
		version : '0.1',
		
		
		
		GM : function(name)
			{
				if(!window.phpkod.modules[name])
					{
						alert('This JS Module componement does not exist for '+name);
						return null;
					}
				return window.phpkod.modules[name];
			}
	};
/*
/* Initialize Tools phpkod class
*/
window.phpkod.tools = 
	{
		
		checkEmail: function(email)
			{
				var place = email.indexOf("@",1);
				var point = email.indexOf(".",place+1);
				if ((place > -1)&&(email.length >2)&&(point > 1))
					{
						return true;
					}
				else
					{
						return false;
					}
			},
			
		checkTelNumber: function(tel)
			{
				var reg = new RegExp("[0-9\.]{10,16}","g");
				if(!reg.test(tel))
					return false;
				//if(tel.length < 10)
				//	return false;
				return true;
			},
		
		initFloatInput: function(o)
			{
				o.observe('keyup', this.floatInputCheck);
			},
			
		floatInputCheck: function(evt)
			{
				var e = evt | window.event;
				var o = evt.target.value;
				var _o = o;
				o = o.replace(/,/,'.');
				if(o !== _o)
					evt.target.value = o;
			}
		
	};
/*
/* Initialize Modules phpkod class
*/
window.phpkod.modules = {};
/*
/* Initialize Plugins phpkod class
*/
window.phpkod.plugins = {
	
		formLayer : {
			
			ctab : null,
			tabs : null,
			
			init: function()
				{
				
					this.tabs = new Array;
					
					$$('.formfrm').each(
						function(o,i){
							this.tabs.push( new AX_editFormTab($(o).getAttribute('id'), i) );
						}.bind(this)
						);
					
					$$('.floatInput').each( function(o,i){ o.observe('keyup', window.phpkod.tools.floatInputCheck); } )
					$$('.noke').each(function(o){ 
						o.observe('keydown', function(evt){  
								var e = evt || window.event;
								if(e.keyCode == 13)
									{
										Event.stop(e);
									}
							}); 
						});
					
					this.switchTab(0);

				},
			
			switchTab: function(tab)
				{
					if(this.ctab !== null)
						this.tabs[this.ctab].close();
					
					this.tabs[tab].open();
					this.ctab = tab;
				},
			
			sfields: function(gid)
				{
					var _l = $(gid);
					if(_l.style.display === 'none')
						{
							// ! $(element).show marche pas...
							$(gid).style.display = 'block';
							$('m'+gid).getElementsBySelector('img')[0].src = apcphpkod.constantes.ICO_PATH+'small/tabup.gif';
							$('m'+gid).getElementsBySelector('span')[0].innerHTML = 'Moins de champs...';
						}
					else
						{
							$(gid).hide();
							$('m'+gid).getElementsBySelector('img')[0].src = apcphpkod.constantes.ICO_PATH+'small/plus.png';
							$('m'+gid).getElementsBySelector('span')[0].innerHTML = 'Plus de champs...';
						}
				}

			
		},
		
		/**
		 *	Plugin tooltips pour scriptaculous
		 */
		ctools : null,
		tooltips : function($selector)
			{
				
				if(!phpkod.plugins.ctools)
					phpkod.plugins.ctools = new AX_ToolTips($selector);
					
				return phpkod.plugins.ctools;
			
			}
	
	};


var AX_ToolTips = function($selector)
	{
		this.initialize($selector);
		return this;
	}

AX_ToolTips.prototype = {
	
	cdisp : null,
	
	initialize : function($selector)
		{
			
			$sel = $selector || 'tooltip';
			$$('.'+$sel).each(function(o,i){
				$(o).observe('mouseover', function(e){ 
					var l = $(o).select('.tooltip-tip')[0];
					if(phpkod.plugins.tooltips().cdisp !== null)
						$(phpkod.plugins.tooltips().cdisp).hide();
					$(l).setStyle('position:absolute; display:block; opacity:0;');
					//alert(l);
					Effect.Appear( l, {duration:0.2} );
					phpkod.plugins.tooltips().cdisp = l;
					return false;
				 	
				 });
				$(o).observe('mouseout', function(e){ 
					var l = $(o).select('.tooltip-tip')[0];
					$(l).hide();
					phpkod.plugins.tooltips().cdisp = null;
					return false;
				 	
				 });
			});
			$$('.'+$sel+' .tooltip-tip').each(function(o,i){ $(o).hide(); })
			
		}
	
}




/*--------------------------------------------------------------------------------------------*/
/*--------------------------- Common.js ------------------------------------------------------*/
document.onkeypress = ManageEvent;
function ManageEvent(e){
	var myevent=window.Event?e:event;
	var ascii=window.Event?e.which:event.keyCode;
    var letter = String.fromCharCode(ascii);
	var IDS = apcphpkod.constantes.IDS;
	var PATH = apcphpkod.constantes.PATH;
	var LOGIN_PATH = apcphpkod.constantes.HTTP_LOGIN_PATH;
	if(myevent.ctrlKey == true){
	
		switch(letter){
		
			case 'k'	:	MkFrame(LOGIN_PATH + 'admin/MyConf/MyConf.php?IDS='+IDS,'MyConf',650,480); break;// elements de configuration
			case 'q'	:	MkFrame(LOGIN_PATH + 'admin/Search/index.php?IDS='+IDS,'MyConf',650,480); break;// elements de configuration
			case 'f'	:	parent.C_close(); break;// elements de configuration


		}
		
		return;
	
	}
	//alert(event.keyCode);
    //alert("Vous venez de frapper la lettre " + letter + "\ncode decimal de la touche : " + ascii )
}
function changesrc(id,src){
	document.getElementById(id).src = src;
}

/* Pour la foncton spanMenu();
*/
var old_sel = new Object;
old_sel.btn = '';
old_sel.action = '';
old_sel.mouseOver = '';
old_sel.mouseOut = '';
function spanMenu_select( id ){

	/* on verif si il y a un ancien vutton */
	if(old_sel.btn != null && old_sel.btn != ''){
	
		var o = document.getElementById( old_sel.btn );
		var _o= o.getElementsByTagName( 'a' )[0];;
		var oa = _o.attributes;
		if(oa != null){
			oa.onClick.value = old_sel.action;
			oa.onMouseover.value = old_sel.mouseOver;
			oa.onMouseout.value = old_sel.mouseOut;
			spanMenu_out( old_sel.btn );
		}
	}
	
	var d = document.getElementById( id );
	d.className = 'spanMenu selected';
	
	/* on efface les actions sur la presente */
	var _a = d.getElementsByTagName( 'a' )[0];
	old_sel.btn = id;
	old_sel.action = _a.attributes.onClick.value;
	old_sel.mouseOver = _a.attributes.onMouseover.value;
	old_sel.mouseOut = _a.attributes.onMouseout.value;
	_a.attributes.onClick.value = '';
	_a.attributes.onMouseover.value = '';
	_a.attributes.onMouseout.value = '';

}
function spanMenu_over( id ){

	var d = document.getElementById( id );
	d.className = 'spanMenu over';

}
function spanMenu_out( id ){

	var d = document.getElementById( id );
	d.className = 'spanMenu';

}
function btnclean( spry_id ){
	var div = document.getElementById(spry_id+'_jsMenu');
	var col = div.getElementsByTagName('span');
	for(i=0;i<col.length;i++){
		col[i].className = 'spanMenu';
	}


}
/*
Fonction pour affichier une dic et mettre ne cache la div actuelle.
les boutons doivent avoir le meme id que la layer + _btn en suffixe.
*/
function displayLayer( id , id_main_layer , id_spry ){
	
	// on clean les autres
	undisplayLayers( id_main_layer );

	if(id_spry != 'undefined'){
		//btnclean( id_spry );
	}
	
	/*if(c_layer != '' && c_layer != null){
		var elem = document.getElementById( c_layer );
		if(elem != null)
			elem.style.display = 'none';
	}*/
	if(typeof(id) == 'object'){
	
		for(i=0;i<id.length;i++){
			target = document.getElementById( id[i] );
			target.style.display = 'block';
		}
		
		var btn = document.getElementById( id[0] + '_btn' );
		if(btn != null){
			spanMenu_select( id[0] + '_btn' );
		}

	} else {
		target = document.getElementById( id );
		target.style.display = 'block';
		c_layer = id;
		var btn = document.getElementById( id + '_btn' );
		if(btn != null){
			spanMenu_select( id + '_btn' );
		}
	}
	// on met en exerg le boutton si il existe
	
}
/*
Fonction pour masquer toutes les div contenues dans le div prinvipal
*/
function undisplayLayers( id ){
	
	var main = document.getElementById( id );
	if(main == null)
		alert('Div manquante pour l\'id '+id);
	var divs = main.getElementsByTagName('div');
	for( i=0 ; i<divs.length ; i++ ){
		_c = divs[i];
		if(_c.className == 'jsFrame'){
			_c.style.display = 'none';
		}
	}
	
}

function updatefromUpload( file , upload_dir , name ){

	document.getElementById( 'INPUT_' + name ).value = file;

}

function MkButton( name , onclick , disabled , nodisable ){
	
	
	var ext = '.png';
	var HTTP_ADMIN_TPL_PATH = apcphpkod.constantes.HTTP_TPL_PATH+'admin/';
	
	if( disabled == true || onclick == '' )
		var o = '<img name="'+name+'" src="'+HTTP_ADMIN_TPL_PATH+'buttons/'+name+'_disabled'+ext+'" />';
	else{
		var o  = '';
		o += '<img name="'+name+'" src="'+HTTP_ADMIN_TPL_PATH+'buttons/'+name+ext+'"';
		o += ' onmouseover="javascript:this.src=\''+HTTP_ADMIN_TPL_PATH+'buttons/'+name+'_over'+ext+'\';"';
		o += ' onmouseout="javascript:this.src=\''+HTTP_ADMIN_TPL_PATH+'buttons/'+name+ext+'\';"';
		o += ' onclick="'+onclick;
		o += nodisable ? '' : ' desactivate(this);';
		o += '" />';
	}
	return o;
	
	
}
function sendCalEvent(Myevent,id,value){

	if(Myevent.keyCode == 13){
		MkProgress('Chargement du calendrier');
		xajax__callfromInPlace(id,value)
	}
	return false;
	
}

function switchFullScreen(){
}

/*
/* function selectAllCk
/* selectionne tous les checkbox d'une div donnée
*/
function select_all_checkbox(container_id){
	
	var container = $(container_id);
	var ck = container.getElementsByTagName('input');
	for(var i=0; i<ck.length; i++){
		
			k = ck[i];
			if(k.attributes.type.value == 'checkbox')
				k.checked = true;
		
		}
	
}
// Efface un plopmenu
function fadeplop( id, timeout )
	{
		
	}
// Efface tous les plopsmenu
function fadeAllPlop( timeout )
	{
		
	}

function setParentFullHeight(divId)
	{
		
		var topOffsetHeight = $(divId).parent.getHeight();
		$(divId).setAttribute('style','height:'+topOffsetHeight+'px;');

		
	}
