var PHPKOD_IMG_ACCEPT_SMALL_SRC = ICO_PATH + 'small/accept.png';
var PHPKOD_IMG_DENY_SMALL_SRC = ICO_PATH + 'small/deny.gif';
var AX_appController = Class.create();
AX_appController.prototype = {
	
	frames: null,
	
	options:{//set all the options here
	},
	
	initialize: function(options){
		this.frames = new AX_appFrameController();
	}
	
	
};
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
	
	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.maintab = this.tabs[0];
	
	},
	
	switchFs: function(){
		
		this.maintab.menu.style.display = 'none';
		this.topframe.style.display = 'none';
		this.tabframe.style.display = 'none';
	
	}

};
var AX_appTabController = Class.create();
AX_appTabController.prototype = {

	id: null,
	tab:null,
	top:null,
	menu:null,
	main:null,	
	
	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];
	},
	
	switchMenu: function(int){
		
		$(this.id+'_1_0').style.display = (int == 0) ? 'block' : 'none';
		$(this.id+'_1_1').style.display = (int == 1) ? 'block' : 'none';
		
	}

};
var Ax;
document.observe('dom:loaded', function () { 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'
	};
/*
/* 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;
			}
		
		
	};
/*
/* Initialize Modules phpkod class
*/
window.phpkod.modules = {};
/*
/* Initialize Plugins phpkod class
*/
window.phpkod.plugins = {};





/*--------------------------------------------------------------------------------------------*/
/*--------------------------- 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


		}
	
	}
	//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;');

		
	}
