var msg='';
var yPos;
var xPos;

secteurs= new Array();
secteurs_id= new Array();

var wilayas= new Array();
var wilayas_id= new Array();

fonctions= new Array();
fonctions_id= new Array();

niveaux= new Array();
niveaux_id= new Array();

recruteurs= new Array();
recruteurs_id= new Array();

cmp='';


// verifier l'etat d'une check box
function checkBoxState(box){
	return box;
}


function checkAll(field)
{	
	p=eval(cmp);
	x=cmp+'_id';		
	fi=cmp+'_h';
	for (i = 0; i < field.length; i++){
			if (!field[i].checked){ 
				field[i].checked = true ;
				 p.push(field[i].title);
				 eval(x).push(field[i].value);
			}
		}


	document.getElementById(cmp).value =  p;
	document.getElementById(fi).value='';
	document.getElementById(fi).value=eval(x);
	//alert(document.getElementById(fi).value);
	
	
}

// lors des cliques sur les check box
function fct (checked,id,title){
	tab=eval(cmp);
	x=cmp+'_id';
	f=cmp+'_h';
	h=f.toString();
	if (checkBoxState(checked)){
		tab.push(title);
		eval(x).push(id);
		document.getElementById(cmp).value = tab;
		document.getElementById(h).value=eval(x);
	}else if (!checkBoxState(checked)){
		found=tab.indexOf(title);
		found_id=eval(x).indexOf(id);
		if (found != -1) {
			tab.splice(found,1);
			eval(x).splice(found_id,1);
			document.getElementById(cmp).value = tab;
			document.getElementById(h).value='';
			document.getElementById(h).value=eval(x);
		}
	};	
}

function test(param,etat){

	items=document.myform1.boxes.length;

	if (etat){
		for (i=0;i<items;i++){
			if (document.myform1.boxes[i].alt==param && document.myform1.boxes[i].checked==false ){
				document.myform1.boxes[i].checked=true;
				fct(document.myform1.boxes[i].checked,document.myform1.boxes[i].value, document.myform1.boxes[i].title);
			}
		}
	}else{
		for (i=0;i<items;i++){
			if (document.myform1.boxes[i].alt==param && document.myform1.boxes[i].checked==true){
				document.myform1.boxes[i].checked=false;
				fct(document.myform1.boxes[i].checked,document.myform1.boxes[i].value, document.myform1.boxes[i].title);
			}
		}
	}
}

function checkSelected(){
	//alert(cmp+'_id');
	x=cmp+'_id';
	a=eval(x).length;
	if (a>0){
		for (i = 0; i < a; i++)
		{ 
			document.getElementById(eval(x)[i]).checked=true
		}
	}
}




function showEvent(date){
	var haut=200;
	var Gauche=(screen.width-800)/2;
		yPos=haut;
		xPos=Gauche;
  cmp=date;
  var url = 'include/ajax.php';
  var parametres = 'field=' + date ;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: parametres,
				onLoading:waitMsg2,
				onComplete: remplirCommentaires
			}
		);
}
function showEvent2(date,e){
//var haut=(screen.height-100)/2;
var haut=533;
var Gauche=(screen.width-800)/2;
		yPos=haut;
		xPos=Gauche;


  cmp=date;
  var url = 'admin/include/ajax.php';
  var parametres = 'field=' + date ;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: parametres,
				onLoading:waitMsg,
				onComplete: remplirCommentaires
			}
		);
}

function remplirCommentaires(reponse){
		msg=reponse.responseText;
        $('res').style.visibility="visible";
        $('res').style.top=yPos+"px";
        $('res').style.left=xPos+"px";	
		$('res').style.height="auto";
		$('res').innerHTML=msg;
		checkSelected();
}

function checkbxs(etat){
	a=document.getElementById('list').length;
	if (etat){
		for (i=1;i<a;i++){
			document.list[i].checked=true;
	}
	} else{
	for (i=1;i<a;i++){
		document.list[i].checked=false;
	}
	}
}

function close_panel(){
$('res').style.visibility="hidden";
}


function uncheckAll(field,param){
	p=eval(cmp);
	x=cmp+'_id';		
	fi=cmp+'_h';
	for (i = 0; i < field.length; i++){
			if (field[i].checked){ 
				field[i].checked = false ;
				 p.shift(i);
				 eval(x).shift(i);
				 
			}
		}

	document.getElementById(cmp).value ='';
	document.getElementById(fi).value='';

}

// Page Navigator 
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
var page_courante=1;
var nb_pages=1;
function pagePrecedente() {
   if (page_courante==1) {
      alert("Vous êtes déjà sur la première page !");
   } else {
      affichePage(page_courante-1);
   }
}
function pageSuivante() {
   if (page_courante==nbpages) {
      alert("Vous êtes déjà sur la dernière page !");
   } else {
      affichePage(page_courante+1);
   }
}
function affichePage (page){
   document.getElementById("page"+page_courante).style.display = "none";
   document.getElementById("lienpage"+page_courante).style.fontWeight = "normal";
   document.getElementById("page"+page).style.display = "block";
   document.getElementById("lienpage"+page).style.fontWeight = "bold";
   page_courante=page;

}

function OuvrirPop(url,nom,haut,Gauche,largeur,hauteur,options) {
ouvpop=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function fenetreCent(url,nom,largeur,hauteur,options) {
var haut=(screen.height-hauteur)/2;
var Gauche=(screen.width-largeur)/2;
fencent=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
}

function manageSelection(action,id,ids){
  var url = 'admin/include/ckies.php';
  var parametres = 'select=' + action+'&id='+id+'&ids='+ids ;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: parametres,
				//onLoading:waitMsg,
				onComplete: updateLink
			}
		);
}


function updateLink(reponse){

		msg=reponse.responseText.split('|');
		$('newlink').innerHTML=msg[0];
		window.opener.document.getElementById('selections').innerHTML=msg[1];
}
function manageSelection2(action,id){
  var url = 'admin/include/ckies.php';
  var parametres = 'select=' + action+'&id='+id ;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: parametres,
				//onLoading:waitMsg,
				onComplete: updateLink2
			}
		);
}


function updateLink2(reponse){
		msg=reponse.responseText;
		$('selections').innerHTML=msg;
}
function waitMsg(a){
	var haut=533;
	var Gauche=(screen.width-800)/2;
	if (a.readyState!=4){			
        $('res').style.visibility="visible";
		$('res').style.top=haut+"px";
   		$('res').style.left=Gauche+"px";
  
		$('res').innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" height="200" ><tr><td align="center" valign="middle"><img id="loadImg"   src="images/loader.gif" width="16" height="16" ></td></tr></table>';
	}

}
function waitMsg2(a){
	var haut=200;
	var Gauche=(screen.width-800)/2;
	if (a.readyState!=4){			
        $('res').style.visibility="visible";
		$('res').style.top=haut+"px";
   		$('res').style.left=Gauche+"px";
  
		$('res').innerHTML='<table width="100%" border="0" cellspacing="0" cellpadding="0" height="200" ><tr><td align="center" valign="middle"><img id="loadImg"   src="images/loader.gif" width="16" height="16" ></td></tr></table>';
	}

}