//------------------------- AJAX ---------------------//
onloads.push( registerAjaxStuff);
//enregistrement des elements AJAX
function registerAjaxStuff(){
	ajaxEngine.registerRequest('diplomeAjax','http://www.lci-europe.com/page/ajout_diplome.php');
	ajaxEngine.registerRequest('deldiplomeAjax','http://www.lci-europe.com/page/suppr_diplome.php');
	ajaxEngine.registerRequest('compAjax','http://www.lci-europe.com/page/competences.php');
	ajaxEngine.registerAjaxElement('list_diplomes');
	ajaxEngine.registerAjaxElement('diplomes');
	ajaxEngine.registerAjaxElement('nameList1');
	ajaxEngine.registerAjaxElement('hidden1');
	ajaxEngine.registerRequest('sessionAjax','http://www.lci-europe.com/page/ajax_session.php');
	ajaxEngine.registerAjaxElement('status');
}

//fonction getinfo recupère le formulaire et enregistre les variables de session
function getinfo(){

	params=Form.serialize(document.forms.frmcandidature);
	ajaxEngine.sendRequest('sessionAjax',{method: 'post', parameters: params});
	//setTimeout("registerDraggables(document.getElementById('hidden1').innerHTML)",500);
}

// recupère la valeur passée dans Competences et affiche dans la selectbox les differentes
// competences depuis la base de donnée
function getcompfam(){

	for(var i=0; i< document.forms.frmcandidature.frmcompetences.options.length;i++){
		if(document.forms.frmcandidature.frmcompetences.options[i].selected){
				var comp=document.forms.frmcandidature.frmcompetences.options[i].value;
		}
	}

	ajaxEngine.sendRequest('compAjax',"comp_fam="+comp);
	//setTimeout("registerDraggables(document.getElementById('hidden1').innerHTML)",500);
}

// recupère la valeur passé dans diplome et domaine du diplome er l'enregistre dans la session
function getdiplomes(){

	for(var i=0; i< document.forms.frmcandidature.frmdiplome.options.length;i++){
		if(document.forms.frmcandidature.frmdiplome.options[i].selected){
				var dip=document.forms.frmcandidature.frmdiplome.options[i].value;
		}
	}

for(var i=0; i< document.forms.frmcandidature.frmdomaine.options.length;i++){
		if(document.forms.frmcandidature.frmdomaine.options[i].selected){
				var domaine=document.forms.frmcandidature.frmdomaine.options[i].value;
		}
	}
//alert('diplome:'+dip+' domaine:'+domaine);
	ajaxEngine.sendRequest('diplomeAjax',"diplome="+dip, "domaine="+domaine);
	setTimeout("Rico.Corner.round('list_diplomes')",500);

}

// efface de la session le diplome
function deldiplomes(dip,domaine){
	ajaxEngine.sendRequest('deldiplomeAjax',"diplome="+dip, "domaine="+domaine);
	setTimeout("Rico.Corner.round('list_diplomes')",500);
}

//------------------- FIN AJAX -----------------------------

function scrollerjusqua(what){
	//var elt = document.getElementById(id);
	//if (elt != null) elt.scrollIntoView();
	document.getElementById(what).style.left="100px"//scrollIntoView();
}
function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\//g,'\\\/');
	str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
return str;
}

// fonction qui efface du tableau used la valeur passé en parametre
function effaceme(valeur,tab){
	var i=0;
	while(i < tab.length){
		if(tab[i]==valeur){
			tab.splice(i,1);
		}else{
			i++;
		}
	}
	//alert("toto");
	//if(tab==used) document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value.replace(/valeur/,"");
	//alert(document.forms['frmcandidature'].compac.value);

	return tab;
	}

// fonction qui test si dans le tableau passé en paramètres la valeur y figure
function contient(tab,valeur){
	var tabstr= tab.toString();
	valeur=valeur.toString();
	if(tabstr == '') return false;

	//var reg=new RegExp("(\\\+)", "g");
	valeur=valeur.replace(/\+/g,'\\\+');
	//alert(valeur);
	var reg= new RegExp(valeur, 'g');

var bon= reg.test(tabstr);

return bon;

}

// fonction qui ajoute avec un double click
function add_dbl_click(tab,valeur){
	var names = valeur.split(",");
			if(contient(tab,names)==false){
				tab.push(names);
				//les competences
				if(tab==used){
					document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value+"¤"+valeur;
					document.getElementById('dropZone2').innerHTML+="<div><span id=\""+valeur+"\" ondblclick=\"effaceme(this.id,used);this.style.display='none';document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value.replace(/"+ addslashes(valeur)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + valeur + "]</span></div>";
				}
				//les secteurs d'activité
				if(tab==used4){
					document.forms['frmcandidature'].frmsecteurs.value+="#"+valeur;
					document.getElementById('dropZone4').innerHTML+="<div><span id=\""+valeur+"\" ondblclick=\"effaceme(this.id,used);this.style.display='none';document.forms['frmcandidature'].frmsecteurs.value=document.forms['frmcandidature'].frmsecteurs.value.replace(/"+ addslashes(valeur)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + valeur + "]</span></div>";
				}
				//les services
				if(tab==used5){
					document.forms['frmcandidature'].frmservices.value+="#"+valeur;
					document.getElementById('dropZone5').innerHTML+="<div><span id=\""+valeur+"\" ondblclick=\"effaceme(this.id,used5);this.style.display='none';document.forms['frmcandidature'].frmservices.value=document.forms['frmcandidature'].frmservices.value.replace(/"+ addslashes(valeur)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + valeur + "]</span></div>";
				}
				//les fonctions
				if(tab==used6){
					document.forms['frmcandidature'].frmfonctions.value+="#"+valeur;
					document.getElementById('dropZone6').innerHTML+="<div><span id=\""+valeur+"\" ondblclick=\"effaceme(this.id,used6);this.style.display='none';document.forms['frmcandidature'].frmfonctions.value=document.forms['frmcandidature'].frmfonctions.value.replace(/"+ addslashes(valeur)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + valeur + "]</span></div>";
				}
				//les regions - mobilité
				if(tab==used2){
					document.forms['frmcandidature'].mobilite.value+="#"+valeur;
					document.getElementById('dropZone').innerHTML+="<div><span id=\""+valeur+"\" ondblclick=\"effaceme(this.id,used2);this.style.display='none';document.forms['frmcandidature'].mobilite.value=document.forms['frmcandidature'].mobilite.value.replace(/"+ addslashes(valeur)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + valeur + "]</span></div>";
				}
			}

}
function desactiveTD(){
	document.getElementById('nameList2').innerHTML='<center><img src="img/progress.gif" align="center" /></center>';
	for(var i=0; i<document.getElementById('tdregion').getElementsByTagName('a').length; i++){
		document.getElementById('tdregion').getElementsByTagName('a')[i].className='moblink';
	}
}
function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}
//------------competences----------------
var names = new Array();
used= new Array();
function writeNameSpans2() {
		for(var i=0;i< names.length; i++)
										document.write("<span id='c"+i+"' class='nameSpan' style='border:1px solid #ffffee;display:block;cursor:pointer;' alt='double-click to add' title='double-click to add' ondblclick='add_dbl_click(used,"+names[i]+")'>"+names[i]+"</span>");
}

function createDraggables2(){
	//	for(var i=0;i< names.length; i++)	dndMgr.registerDraggable(new CustomDraggable($('c'+i),names[i]));
}

//Secteurs d'activités
var names4 = ["-Aeronautics",
"----Aeronautics",
"----Space",
"-Automobile",
"----Automobile",
"----Industrial vehicles",
"-Banking & Finance",
"----Finance",
"----Information Technology",
"----Insurance",
"----Investment banking",
"----Retail banking",
"-Public Works & Urban Planning",
"----Building industry",
"----Civil engineering",
"----Construction",
"----Construction materials",
"----Public Works",
"----Real estate",
"-Defense & Naval",
"----Defense",
"----Shipbuilding",
"-Energy & Environment",
"----Energy",
"----Environment",
"----Nuclear",
"----Production of electricity",
"----Water",
"-Railroads",
"-Industry",
"----Electric and electromechanic equipment",
"----Electronics",
"----General mechanical engineering",
"----Industrial machines & equipment",
"----Luxury items, sports items",
"----Measurement",
"----Metallurgy",
"----Optics",
"----Robotics",
"----Textiles, Clothing, Leather",
"----Transport",
"----Wood, paper",
"-Process industry",
"----Ceramics and glass",
"----Chemistry",
"----Food industry",
"----Metallurgy",
"----Petrochemical and offshore",
"----Pharmacy and Cosmetics",
"----Plastics processing",
"-NICT",
"----Electronics",
"----Information Technology",
"----Telecom",
"-Commercial sector",
"----Accounting firm",
"----Arts, Hobbies, Sports",
"----Associations",
"----Commercial agencies",
"----Consultancy",
"----Education",
"----Health & Safety",
"----Health and medical",
"----Home",
"----Hotel, restaurant and tourism management",
"----Human resources",
"----Legal",
"----Mail handling",
"----Maintenance and upkeep",
"----Management companies",
"----Management facilities",
"----Marketing",
"----Multimedia Communication",
"----Packaging Handling and Logistics",
"----Public utilities",
"----Publishing sector",
"----Recruitment",
"----Social and humanitarian",
"----Temporary work",
"----Trade, shops, other",
"----Transport"];

used4= new Array();
function writeNameSpans4() {
		for(var i=0;i< names4.length; i++)
										document.write("<span id=\"e"+i+"\" class=\"nameSpan\" style=\"border:1px solid #ffffee;display:block;cursor:pointer;\" alt=\"double-click to add\" title=\"double-click to add\" ondblclick=\"add_dbl_click(used4,'"+addslashes(names4[i])+"')\">"+names4[i]+"</span>");
}

function createDraggables4(){
		//for(var i=0;i< names4.length; i++)	dndMgr.registerDraggable(new CustomDraggable4($('e'+i),names4[i]));
}

//Services
var names5 = [" Communication/advertising/PR",
" Consultancy",
" Education",
" Engineering/restoration/building sites",
" General management",
" Human resources",
" IT/telecom",
" Industrialization/methods",
" Interpreting",
" Legal",
" Localization",
" Logistics/stocks/transport",
" Maintenance/upkeep/after-sales service",
" Management/accounting/finance",
" Marketing",
" Medical services",
" Production/production management",
" Project management",
" Proofreading",
" Purchasing/Procurement",
" Quality control",
" Reception/mail handling/toilet facilities",
" Research (R&D)",
" Secretary/assistant",
" Technical documentation",
" Testing and certification",
" Trade/sales/distribution",
" Translation",
" Other"];

used5= new Array();
function writeNameSpans5() {
		for(var i=0;i< names5.length; i++)
										document.write("<span id='f"+i+"' class='nameSpan' style='border:1px solid #ffffee;display:block;cursor:pointer;' alt='double-click to add' title='double-click to add' ondblclick=\"add_dbl_click(used5,'"+addslashes(names5[i])+"')\">"+names5[i]+"</span>");
}

function createDraggables5(){
	//	for(var i=0;i< names5.length; i++)	dndMgr.registerDraggable(new CustomDraggable5($('f'+i),names5[i]));
}

//Fonctions
var names6 = [".Accountant",
".Accounts manager",
".Activity pilot",
".Administrator",
".Agent",
".Analyst",
".Auditor",
".Chief accountant",
".Consultant",
".Desk officer",
".Economist",
".Editor",
".Engineer",
".Group Supervisor",
".Head of department",
".Linguist",
".Localization specialist",
".Management auditor",
".Manager",
".Operator",
".Programmer",
".Project manager",
".Proofreader",
".Public accountant",
".Research assistant",
".Researcher",
".Secretary",
".System/network administrator",
".Technician",
".Terminologist",
".Trader",
".Training agent",
".Translator"];

used6= new Array();
function writeNameSpans6() {
		for(var i=0;i< names6.length; i++)
										document.write("<span id='g"+i+"' class='nameSpan' style='border:1px solid #ffffee;display:block;cursor:pointer;' alt='double-click to add' title='double-click to add' ondblclick=\"add_dbl_click(used6,'"+addslashes(names6[i])+"')\">"+names6[i]+"</span>");
}

function createDraggables6(){
	//	for(var i=0;i< names6.length; i++)	dndMgr.registerDraggable(new CustomDraggable6($('g'+i),names6[i]));
}

// fonction qui enregistre les elements draggables à partir d'une chaine
function registerDraggables(chaine){
	var CustomDraggable2 = Class.create();
	CustomDraggable2.removeOnDrop = false;
	CustomDraggable2.revereNamesOnDrop = false;

	CustomDraggable2.prototype = (new Rico.Draggable()).extend( {

		   initialize: function( htmlElement, name ) {
		      this.type        = 'Custom';
		      this.htmlElement = $(htmlElement);
		      this.name        = name;
		   },

		   select: function() {
		      	this.selected = true;
		      var el = this.htmlElement;

		      // show the item selected.....
		      el.style.color           = "#ffffff";
		      el.style.backgroundColor = "#08246b";
		      el.style.border          = "1px solid blue";
		   },

		   deselect: function() {
		      this.selected = false;
		      var el = this.htmlElement;
		      el.style.color           = "#2b2b2b";
		      el.style.backgroundColor = "transparent";
		      el.style.border = "1px solid #ffffee";
		   },

		   startDrag: function() {
		      var el = this.htmlElement;
		   },

		   cancelDrag: function() {
		      var el = this.htmlElement;
		   },

		   endDrag: function() {
		      var el = this.htmlElement;
		      //this.log("endDrag: [" + this.name +"]");
		      if ( CustomDraggable2.removeOnDrop )
		         this.htmlElement.style.display = 'none';

		   },

		   getSingleObjectDragGUI: function() {
		      var el = this.htmlElement;
					var div = document.createElement("div");
		      div.className = 'customDraggable';
		      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
		      new Insertion.Top( div, this.name );
					return div;
		   },

		   getMultiObjectDragGUI: function( draggables ) {
		      var el = this.htmlElement;
					var names = "";
		      for ( var i = 0 ; i < draggables.length ; i++ ) {
		          names += draggables[i].name;

		         if ( i != (draggables.length - 1) )
		            names += ",<br/>";
		      }

		      var div = document.createElement("div");
		      div.className = 'customDraggable';
		      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
		      new Insertion.Top( div, names );
		      return div;
		   },

		   getDroppedGUI: function() {
		      var el = this.htmlElement;
					var div = document.createElement("div");
		      var names = this.name.split(",");
					if(contient(used,names)==false){
						used.push(names);
						if(el.id.slice(0,1)=="c"){
								document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value+"¤"+this.name;
						}else if(el.id.slice(0,1)=="d"){
								document.forms['frmcandidature'].metiers.value=document.forms['frmcandidature'].metiers.value+"¤"+this.name;
						}
						if ( CustomDraggable2.revereNamesOnDrop )
							new Insertion.Top( div, "<span id=\""+this.name+"\" ondblclick=\"effaceme(this.id,used);this.style.display='none';document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value.replace(/"+ addslashes(this.name)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + this.name + "]</span>" );
						else{
							new Insertion.Top( div, "<span id=\""+this.name+"\" ondblclick=\"effaceme(this.id,used);this.style.display='none';document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value.replace(/"+ addslashes(this.name)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + this.name + "]</span>" );


							}
					}else{
						new Insertion.Top( div, "" );
					}
						return div;
		   },

		   toString: function() {
		      return this.name;
		   }

	} );


	var names=chaine.split("¤");
	for(var i=0;i< names.length; i++)	dndMgr.registerDraggable(new CustomDraggable2($('c'+i),names[i]));

}

//customdraggable pour les competences
var CustomDraggable = Class.create();
CustomDraggable.removeOnDrop = false;
CustomDraggable.revereNamesOnDrop = false;

CustomDraggable.prototype = (new Rico.Draggable()).extend( {

   initialize: function( htmlElement, name ) {
      this.type        = 'Custom';
      this.htmlElement = $(htmlElement);
      this.name        = name;

   },

   select: function() {
      this.selected = true;
      var el = this.htmlElement;

      // show the item selected.....
      el.style.color           = "#ffffff";
      el.style.backgroundColor = "#08246b";
      el.style.border          = "1px solid blue";
   },

   deselect: function() {
      this.selected = false;
      var el = this.htmlElement;
      el.style.color           = "#2b2b2b";
      el.style.backgroundColor = "transparent";
      el.style.border = "1px solid #ffffee";
   },

   startDrag: function() {
      var el = this.htmlElement;
   },

   cancelDrag: function() {
      var el = this.htmlElement;
  },

   endDrag: function() {
      var el = this.htmlElement;
      if ( CustomDraggable.removeOnDrop )
         this.htmlElement.style.display = 'none';

   },

   getSingleObjectDragGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, this.name );
			return div;
   },

   getMultiObjectDragGUI: function( draggables ) {
      var el = this.htmlElement;
		  var names = "";
      for ( var i = 0 ; i < draggables.length ; i++ ) {
          names += draggables[i].name;

         if ( i != (draggables.length - 1) )
            names += ",<br/>";
      }

      var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, names );
      return div;
   },

   getDroppedGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      var names = this.name.split(",");
			if(contient(used,names)==false){
				used.push(names);
				document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value+"¤"+this.name;
				if ( CustomDraggable.revereNamesOnDrop )
					new Insertion.Top( div, "<span ondblclick='effaceme(names[0],used);this.style.display=\"none\"' class='nameSpan'>[" + names[1].substring(1) + " " + names[0]+ "]</span>" );
				else{
					new Insertion.Top( div, "<span id=\""+this.name+"\" ondblclick=\"effaceme(this.id,used);this.style.display='none';document.forms['frmcandidature'].compac.value=document.forms['frmcandidature'].compac.value.replace(/"+ addslashes(this.name)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + this.name + "]</span>" );
				}
			}else{
				new Insertion.Top( div, "" );
			}
				return div;
   },

   toString: function() {
      return this.name;
   }

} );

//customdraggable pour les secteurs d'activités
var CustomDraggable4 = Class.create();
CustomDraggable4.removeOnDrop = false;
CustomDraggable4.revereNamesOnDrop = false;

CustomDraggable4.prototype = (new Rico.Draggable()).extend( {

   initialize: function( htmlElement, name ) {
      this.type        = 'Custom';
      this.htmlElement = $(htmlElement);
      this.name        = name;

   },

   select: function() {
      this.selected = true;
      var el = this.htmlElement;

      // show the item selected.....
      el.style.color           = "#ffffff";
      el.style.backgroundColor = "#08246b";
      el.style.border          = "1px solid blue";
   },

   deselect: function() {
      this.selected = false;
      var el = this.htmlElement;
      el.style.color           = "#2b2b2b";
      el.style.backgroundColor = "transparent";
      el.style.border = "1px solid #ffffee";
   },

   startDrag: function() {
      var el = this.htmlElement;
   },

   cancelDrag: function() {
      var el = this.htmlElement;
  },

   endDrag: function() {
      var el = this.htmlElement;
      if ( CustomDraggable4.removeOnDrop )
         this.htmlElement.style.display = 'none';

   },

   getSingleObjectDragGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, this.name );
			return div;
   },

   getMultiObjectDragGUI: function( draggables ) {
      var el = this.htmlElement;
		  var names = "";
      for ( var i = 0 ; i < draggables.length ; i++ ) {
          names += draggables[i].name;

         if ( i != (draggables.length - 1) )
            names += ",<br/>";
      }

      var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, names );
      return div;
   },

   getDroppedGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      var names = this.name.split(",");
			if(contient(used4,names[0])==false){
				used4.push(names[0]);
				document.forms['frmcandidature'].frmsecteurs.value=document.forms['frmcandidature'].frmsecteurs.value+"#"+this.name;
				if ( CustomDraggable4.revereNamesOnDrop )
					new Insertion.Top( div, "<span ondblclick='effaceme(names[0],used4);this.style.display=\"none\"' class='nameSpan'>[" + names[1].substring(1) + " " + names[0]+ "]</span>" );
				else{
					new Insertion.Top( div, "<span id=\""+this.name+"\" ondblclick=\"effaceme(this.id,used4);this.style.display='none';document.forms['frmcandidature'].frmsecteurs.value=document.forms['frmcandidature'].frmsecteurs.value.replace(/"+ addslashes(this.name)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + this.name + "]</span>" );
				}
			}else{
				new Insertion.Top( div, "" );
			}
				return div;
   },

   toString: function() {
      return this.name;
   }

} );

//customdraggable pour les services
var CustomDraggable5 = Class.create();
CustomDraggable5.removeOnDrop = false;
CustomDraggable5.revereNamesOnDrop = false;

CustomDraggable5.prototype = (new Rico.Draggable()).extend( {

   initialize: function( htmlElement, name ) {
      this.type        = 'Custom';
      this.htmlElement = $(htmlElement);
      this.name        = name;

   },

   select: function() {
      this.selected = true;
      var el = this.htmlElement;

      // show the item selected.....
      el.style.color           = "#ffffff";
      el.style.backgroundColor = "#08246b";
      el.style.border          = "1px solid blue";
   },

   deselect: function() {
      this.selected = false;
      var el = this.htmlElement;
      el.style.color           = "#2b2b2b";
      el.style.backgroundColor = "transparent";
      el.style.border = "1px solid #ffffee";
   },

   startDrag: function() {
      var el = this.htmlElement;
   },

   cancelDrag: function() {
      var el = this.htmlElement;
  },

   endDrag: function() {
      var el = this.htmlElement;
      if ( CustomDraggable5.removeOnDrop )
         this.htmlElement.style.display = 'none';

   },

   getSingleObjectDragGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, this.name );
			return div;
   },

   getMultiObjectDragGUI: function( draggables ) {
      var el = this.htmlElement;
		  var names = "";
      for ( var i = 0 ; i < draggables.length ; i++ ) {
          names += draggables[i].name;

         if ( i != (draggables.length - 1) )
            names += ",<br/>";
      }

      var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, names );
      return div;
   },

   getDroppedGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      var names = this.name.split(",");
			if(contient(used5,names[0])==false){
				used5.push(names[0]);
				document.forms['frmcandidature'].frmservices.value=document.forms['frmcandidature'].frmservices.value+"#"+this.name;
				if ( CustomDraggable5.revereNamesOnDrop )
					new Insertion.Top( div, "<span ondblclick='effaceme(names[0],used5);this.style.display=\"none\"' class='nameSpan'>[" + names[1].substring(1) + " " + names[0]+ "]</span>" );
				else{
					new Insertion.Top( div, "<span id=\""+this.name+"\" ondblclick=\"effaceme(this.id,used5);this.style.display='none';document.forms['frmcandidature'].frmservices.value=document.forms['frmcandidature'].frmservices.value.replace(/"+ addslashes(this.name)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + this.name + "]</span>" );
				}
			}else{
				new Insertion.Top( div, "" );
			}
				return div;
   },

   toString: function() {
      return this.name;
   }

} );

//customdraggable pour les services
var CustomDraggable6 = Class.create();
CustomDraggable6.removeOnDrop = false;
CustomDraggable6.revereNamesOnDrop = false;

CustomDraggable6.prototype = (new Rico.Draggable()).extend( {

   initialize: function( htmlElement, name ) {
      this.type        = 'Custom';
      this.htmlElement = $(htmlElement);
      this.name        = name;

   },

   select: function() {
      this.selected = true;
      var el = this.htmlElement;

      // show the item selected.....
      el.style.color           = "#ffffff";
      el.style.backgroundColor = "#08246b";
      el.style.border          = "1px solid blue";
   },

   deselect: function() {
      this.selected = false;
      var el = this.htmlElement;
      el.style.color           = "#2b2b2b";
      el.style.backgroundColor = "transparent";
      el.style.border = "1px solid #ffffee";
   },

   startDrag: function() {
      var el = this.htmlElement;
   },

   cancelDrag: function() {
      var el = this.htmlElement;
  },

   endDrag: function() {
      var el = this.htmlElement;
      if ( CustomDraggable6.removeOnDrop )
         this.htmlElement.style.display = 'none';

   },

   getSingleObjectDragGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, this.name );
			return div;
   },

   getMultiObjectDragGUI: function( draggables ) {
      var el = this.htmlElement;
		  var names = "";
      for ( var i = 0 ; i < draggables.length ; i++ ) {
          names += draggables[i].name;

         if ( i != (draggables.length - 1) )
            names += ",<br/>";
      }

      var div = document.createElement("div");
      div.className = 'customDraggable';
      div.style.width = (this.htmlElement.offsetWidth - 10) + "px";
      new Insertion.Top( div, names );
      return div;
   },

   getDroppedGUI: function() {
      var el = this.htmlElement;
		  var div = document.createElement("div");
      var names = this.name.split(",");
			//alert("titi");
			if(contient(used6,names[0])==false){
				used6.push(names[0]);
				//alert("toto");
				document.forms['frmcandidature'].frmfonctions.value=document.forms['frmcandidature'].frmfonctions.value+"#"+this.name;
				if ( CustomDraggable6.revereNamesOnDrop )
					new Insertion.Top( div, "<span ondblclick='effaceme(names[0],used6);this.style.display=\"none\"' class='nameSpan'>[" + names[1].substring(1) + " " + names[0]+ "]</span>" );
				else{
					new Insertion.Top( div, "<span id=\""+this.name+"\" ondblclick=\"effaceme(this.id,used6);this.style.display='none';document.forms['frmcandidature'].frmfonctions.value=document.forms['frmcandidature'].frmfonctions.value.replace(/"+ addslashes(this.name)+"/,'');\" class='nameSpan' alt='double-click to delete' title='double-click to delete' style='cursor:pointer'>[" + this.name + "]</span>" );
				}
			}else{
				new Insertion.Top( div, "" );
			}
				return div;
   },

   toString: function() {
      return this.name;
   }

} );

var CustomDropzone = Class.create();

CustomDropzone.prototype = (new Rico.Dropzone()).extend( {

   initialize: function( htmlElement, header, acceptRange ) {
      this.htmlElement  = $(htmlElement);
      this.header       = $(header);
      this.absoluteRect = null;
      this.from = acceptRange[0];
      this.to   = acceptRange[1];
      this.acceptedObjects = [];

      this.offset = navigator.userAgent.toLowerCase().indexOf("msie") >= 0 ? 0 : 1;
   },

   activate: function() {
      new Rico.Effect.FadeTo( this.htmlElement, .4, 250, 4 );
   },

   deactivate: function() {
      new Rico.Effect.FadeTo( this.htmlElement, 1, 250, 4 );
   },

   showHover: function() {
      if ( this.showingHover )
         return;
      this.header.style.color = "#000000";
      new Rico.Effect.FadeTo( this.htmlElement, .7, 250, 4 );
      this.showingHover = true;
   },

   hideHover: function() {
      if ( !this.showingHover )
         return;
      this.header.style.color = "#5b5b5b";
      new Rico.Effect.FadeTo( this.htmlElement, .4, 250, 4 );
      this.showingHover = false;
   },

   accept: function(draggableObjects) {

      n = draggableObjects.length;
      for ( var i = 0 ; i < n ; i++ )
         this._insertSorted(draggableObjects[i]);
   },

   canAccept: function(draggableObjects) {
      for ( var i = 0 ; i < draggableObjects.length ; i++ ) {
         if ( draggableObjects[i].type != "Custom" )
            return false;
         var firstChar = draggableObjects[i].name.substring(0,1).toLowerCase();
         if ( firstChar < this.from || firstChar > this.to )
            return false;
	     //if(contient(used6,draggableObjects[i].name)==true || contient(used5,draggableObjects[i].name)==true || contient(used4,draggableObjects[i].name)==true)
		  //	return false;
	  }


      return true;
   },

   // -----------------------------------------------------------
   // implementation specific methods... not part of the
   // draggable contract
   // -----------------------------------------------------------

   _insertSorted: function( aDraggable ) {
      var theGUI = aDraggable.getDroppedGUI();
      var thisName = aDraggable.name;
      var position = this._getInsertPosition(aDraggable);
      if ( position == "append" )
         this.htmlElement.appendChild(theGUI);
      else
         this.htmlElement.insertBefore( theGUI, this.htmlElement.childNodes[position+this.offset]  );
      this.acceptedObjects[ this.acceptedObjects.length ] = aDraggable.name;
      //this.acceptedObjects.sort();
   },

   _getInsertPosition: function(aDraggable) {
      for( var i = 0 ; i < this.acceptedObjects.length ; i++ )
         if ( aDraggable.name < this.acceptedObjects[i] ) {
            return i;
         }
       return "append";
   }

} );

