var listmodules= new Array();
var wordsearch="";
var currentcampaign=0;
var currentmodule;
var timerportalrefresh;
var timerportalrefreshcampaign;
var timerusersportalrefresh;
var idrecord_over;
var idobj_over;
var idmod_over;
var timerdisplayresult;
var eventcour;
var statesearch;
var optx;
var opty;
var optw;
var opth;
var old_idobject="";
var old_idrecord="";
var old_idmodule="";
var cur_idobject;
var cur_idrecord;
var cur_idmodule;
var cur_idworkspace;
var typefavorite;

function modifyViewTicket(type) {
    var elem=document.getElementById("contentdesktopticket");
    if (type==0) {
        elem.style.display="none";
        elem.style.visibility="hidden";
    }
    else {
        elem.style.display="block";
        elem.style.visibility="visible";
    }
}

function searchUserWorkflow() {
	clearTimeout(timerdisplayresult);
	timerdisplayresult = setTimeout("searchUserWorkflowExec()", 200);
}

function searchUserWorkflowExec() {
	var nomsearch=document.getElementById("dims_workflow_userfilter").value;
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=workflow_search_users&dims_workflow_userfilter='+nomsearch,'',"div_workflow_search_result");
}

function searchUserShare() {
	clearTimeout(timerdisplayresult);
	timerdisplayresult = setTimeout("searchUserShareExec()", 200);
}

function searchUserShareExec() {
	var nomsearch=document.getElementById("dims_shares_userfilter").value;
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=shares_search_users&dims_shares_userfilter='+nomsearch,'',"div_shares_search_result");
}

function switchModuleDisplay(idmodule) {
	var elem=dims_getelem("content"+idmodule);
	var elemtmp;
	var desktopdetail=dims_getelem("desktop_detail_content");
	var desktopright=dims_getelem("desktop_right_content");
	
	for(i=0;i<listmodules.length;i++) {
		opttxt=dims_getelem("modresult"+listmodules[i]);
		opttxt.className="modresult";
		
		if (listmodules[i]!=idmodule) {
			elemtmp=dims_getelem("content"+listmodules[i]);
			elemtmp.style.display="none";
			elemtmp.style.visibility="hidden";
		}
	}
	
	if (elem!=null) {
		if (elem.style.display=="block") {
			elem.style.display="none";
			elem.style.visibility="hidden";
			dims_xmlhttprequest('admin.php','dims_op=reset_currentobject');
			
			desktopdetail.style.visibility="hidden";
			desktopdetail.style.display="none";
			desktopright.style.visibility="visible";
			desktopright.style.display="block";			
		}
		else {
			elem.style.display="block";
			elem.style.visibility="visible";
			opttxt=dims_getelem("modresult"+idmodule);
			opttxt.className="modresultvert";
		}
	}
}

function displayNewServices(event, idService) {
	dims_showpopup('',220,event,'click','dims_popup',0,0);
	dims_xmlhttprequest_todiv('admin.php','action=add_service&id_service='+idService,'','dims_popup');
}

function displayOptions(event,idworkspace,idmodule,idobject,idrecord) {
	if (cur_idobject!=-1 && (cur_idobject!=idobject || cur_idworkspace!=idworkspace || cur_idmodule != idmodule || cur_idrecord != idrecord)) {
		cur_idobject=idobject;
		cur_idworkspace=idworkspace;
		cur_idmodule = idmodule;
		cur_idrecord = idrecord;
		dims_showpopup('',160,event,'click','dims_popup',0,0);
		dims_xmlhttprequest_todiv('admin.php','dims_op=displayObjectOptions&idworkspace='+idworkspace+'&idrecord='+idrecord+'&idobject='+idobject+'&idmodule='+idmodule,'','dims_popup');
	}
}
function initDisplayOptions(opt) {
	if (opt==0) {
		cur_idobject=-1;
		// timer to avoid display just after close window
		timerusersportalrefresh = setTimeout("initDisplayOptions(1)", 300);
	}
	else {
		cur_idobject=0;
		clearTimeout(timerusersportalrefresh);
	}
}

function displayOptionsRefresh(idworkspace,idmodule,idobject,idrecord) {
	dims_xmlhttprequest_todiv('admin.php','dims_op=displayObjectOptions&idworkspace='+idworkspace+'&idrecord='+idrecord+'&idobject='+idobject+'&idmodule='+idmodule,'','dims_popup');
}

function changeListProjectDisplay(state) {
	dims_xmlhttprequest('admin.php','dims_op=change_projectlist&state='+state);
}
function viewDesktopDetail(id,type) {
	var desktopdetail=dims_getelem("desktop_detail_content");
	var desktopright=dims_getelem("desktop_right_content");

	if (id==1) {
		desktopdetail.innerHTML="";
		desktopdetail.style.visibility="visible";
		desktopdetail.style.display="block";
		desktopright.style.visibility="hidden";
		desktopright.style.display="none";
	}
	else {
		desktopdetail.style.visibility="hidden";
		desktopdetail.style.display="none";
		desktopright.style.visibility="visible";
		desktopright.style.display="block";
		//if (type==0) timerportalrefresh = setTimeout("searchRecursiveNewsTimer()", 250);
		//else timerportalrefresh = setTimeout("searchRecursiveFavoritesTimer()", 250);
	}
}

function searchRecursiveNewsTimer() {
	clearTimeout(timerportalrefresh);
	searchRecursiveNews();
}

function searchRecursiveFavoritesTimer() {
	clearTimeout(timerportalrefresh);
	searchRecursiveFavorites(typefavorite);
}

function viewPropertiesObject(idobject,idrecord,idmodule,activePreview) {
	cur_idobject=idobject;
	cur_idrecord=idrecord;
	cur_idmodule=idmodule;
	if (activePreview==null) activePreview=1;
	var elem;
	// update img et ligne
	if (old_idmodule!="" && old_idrecord!="" && old_idobject!="") {
		elem=dims_getelem("obj_"+old_idobject+"_"+old_idrecord+"_"+old_idmodule);
		if (elem!=null) elem.style.backgroundColor="";
		
		elem=dims_getelem("img_"+old_idobject+"_"+old_idrecord+"_"+old_idmodule);
		if (elem!=null) elem.src="./img/arrow-right.gif";
	}
	
	elem=dims_getelem("obj_"+idobject+"_"+idrecord+"_"+idmodule);
	if (elem!=null) elem.style.backgroundColor="#FFFFEE";
	elem=dims_getelem("img_"+idobject+"_"+idrecord+"_"+idmodule);
	if (elem!=null) elem.src="./img/arrow-blue-right.gif";
	
	old_idobject=idobject;
	old_idrecord=idrecord;
	old_idmodule=idmodule;

	var desktopdetail=dims_getelem("desktop_detail_content");
	desktopdetail.style.visibility="visible";
	desktopdetail.style.display="block";
	
	var desktopright=dims_getelem("desktop_right_content");
	if (desktopright!=null) {
		desktopright.style.visibility="hidden";
		desktopright.style.display="none";
	}	
	
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=object_properties&idrecord='+idrecord+'&idobject='+idobject+'&idmodule='+idmodule,execviewPropertiesObject,activePreview);
}

function execviewPropertiesObject(result,activePreview) {
	
	dims_getelem("desktop_detail_content").innerHTML=result;
	var bottomAccordion = new accordion('vertical_container');
	
	var verticalAccordions = $$('.accordion_toggle');
	verticalAccordions.each(function(accordion){
		$(accordion.next(0)).setStyle({height: '0px'});
	});
	bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
	
	if (activePreview) {
		// on lance la previsualisation du document
		dims_getelem("desktop_detail_object_content").innerHTML="<table width=\"100%\" height=\"400\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
		dims_xmlhttprequest_todiv('admin.php','dims_op=object_detail_properties','',"desktop_detail_object_content");
	}
}

function viewPropertiesTicket(idticket,idobject,idrecord,idmodule) {
	// update ticket status
	dims_xmlhttprequest('admin.php','op=ticket_open&ticket_id='+idticket);
	
	var desktopdetail=dims_getelem("desktop_detail_content");
	var desktopright=dims_getelem("desktop_right_content");
	
	desktopdetail.style.visibility="visible";
	desktopdetail.style.display="block";
	
	if (desktopright!=null) {
		desktopright.style.visibility="hidden";
		desktopright.style.display="none";
	}
	
	if (idobject>0 && idrecord>0 && idmodule>0) {
		dims_xmlhttprequest_tofunction('admin-light.php','dims_op=ticket_properties&idticket='+idticket,execviewPropertiesTicket,idticket);
	}
	else
		dims_xmlhttprequest_tofunction('admin-light.php','dims_op=ticket_properties&idticket='+idticket,execviewPropertiesTicketLight,idticket);
}

function execviewPropertiesTicket(result,idticket) {
	ticketsRefresh();
	dims_getelem("desktop_detail_content").innerHTML=result;
	var bottomAccordion = new accordion('vertical_container');
	
	var verticalAccordions = $$('.accordion_toggle');
	verticalAccordions.each(function(accordion){
		$(accordion.next(0)).setStyle({height: '0px'});
	});
	bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
	
	// on lance la previsualisation du document
	var elem=dims_getelem("desktop_detail_object_content");
	if (elem!=null) elem.innerHTML="<table width=\"100%\" height=\"400\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
	dims_xmlhttprequest_todiv('admin.php','dims_op=object_detail_properties','',"desktop_detail_object_content");
}

function closeObject() {
	viewDesktopDetail(0);
	dims_xmlhttprequest('admin-light.php','dims_op=object_close');
}

function execCloseObject() {
	window.location.reload();
}

function eraseTickets() {
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=eraseticket',updateTickets);
}

function eraseTicketsSent(){
        dims_xmlhttprequest_tofunction('admin-light.php','dims_op=eraseticketsent',updateTickets);
}

function deleteSelTickets(nb) {
	var lst="";
	for (i = 0; i < nb; i++) {
		if (document.getElementById("selticket"+i).checked) {
			if (lst=="") lst=document.getElementById("selticket"+i).value;
			else lst+=","+document.getElementById("selticket"+i).value;
		}
	}
	if (lst!="") dims_xmlhttprequest_tofunction('admin-light.php','dims_op=deleteselticket&lst='+lst,updateTickets);
}

function deleteSelSentTickets(nb) {
	var lst="";
	for (i = 0; i < nb; i++) {
		if (document.getElementById("selticket"+i).checked) {
			if (lst=="") lst=document.getElementById("selticket"+i).value;
			else lst+=","+document.getElementById("selticket"+i).value;
		}
	}
	if (lst!="") dims_xmlhttprequest_tofunction('admin-light.php','dims_op=deleteselsentticket&lst='+lst,updateTickets);
}

function deleteSelSentTicketOpen(id){
        if(confirm('?tes-vous certain de vouloir supprimer ce ticket ?') && (id != "")){
            dims_xmlhttprequest_tofunction('admin-light.php','dims_op=deleteselsentticket&lst='+lst,updateTickets);
        }
}

function updateTickets() {
	ticketsRefresh();
}

function execviewPropertiesTicketLight(result) {
	ticketsRefresh();
	dims_getelem("desktop_detail_content").innerHTML=result;
	var bottomAccordion = new accordion('vertical_container');
	
	var verticalAccordions = $$('.accordion_toggle');
	verticalAccordions.each(function(accordion){
		$(accordion.next(0)).setStyle({height: '0px'});
	});
	bottomAccordion.activate($$('#vertical_container .accordion_toggle')[0]);
}

function searchUserPlanning() {
	clearTimeout(timerdisplayresult);
	timerdisplayresult = setTimeout("searchUserPlanningExec()", 300);
}

function searchUserPlanningExec() {
	var nomsearch=document.getElementById("nomsearchplanning").value;
	dims_xmlhttprequest_todiv('admin.php','op=search_contact_planning&nomsearch='+nomsearch,'',"lst_planninguser");
}

function updateUserFromSelectedPlanning(op,id_user) {
	dims_xmlhttprequest_tofunction('admin-light.php','op='+op+"&id_user="+id_user,refresh_planning);
}

function ticketOpenResponse(idticket) {
	timerusersportalrefresh = setTimeout("execOpenResponse("+idticket+")", 500);
}

function execOpenResponse(idticket) {
	clearTimeout(timerdisplayresult);
	dims_xmlhttprequest_todiv('admin.php','op=ticket_replyto&ticket_id='+idticket,'',"ticket_response_"+idticket);
}

function ticketOpenResponses(idticket) {
	timerusersportalrefresh = setTimeout("execOpenResponses("+idticket+")", 500);
}

function execOpenResponses(idticket) {
	clearTimeout(timerdisplayresult);
	dims_xmlhttprequest_todiv('admin.php','op=ticket_open_responses&ticket_id='+idticket,'',"ticket_responses_"+idticket);
}

function ticketsRefresh(page) {
	if (page==null) dims_xmlhttprequest_todiv('admin-light.php','dims_op=tickets_refresh','','contentdesktopticket');
	else dims_xmlhttprequest_todiv('admin-light.php','dims_op=tickets_refresh&page='+page,'','contentdesktopticket');
}

function checkAllTickets(nbfiles) {
	for (i = 0; i < nbfiles; i++)
		document.getElementById("selticket"+i).checked = true;
}

function uncheckAllTickets(nbfiles) {
	for (i = 0; i < nbfiles; i++)
		document.getElementById("selticket"+i).checked = false;
}

function refreshDesktopPage(mod,op,page) {
	//dims_xmlhttprequest_todiv('admin-light.php','dims_op='+op+'&moduleid='+mod+'&page='+page,'||','ressearch'+mod,'content'+mod);
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op='+op+'&moduleid='+mod+'&page='+page,refreshDesktopPageSuite,mod);
}

function refreshDesktopPageSuite(result,mod) {
if (result!=null) tabxmlvalue=result.split("||");
	var elem=dims_getelem('ressearch'+mod);
	var elemcontent=dims_getelem('content'+mod);
	
	if (elem!=null) elem.innerHTML= "<a href=\"javascript:void(0);\" onclick=\"javascript:switchModuleDisplay("+mod+");\">"+tabxmlvalue[0]+"</a>";
	if (elemcontent!=null) elemcontent.innerHTML= tabxmlvalue[1];
}

function refreshFavorites(idfav,iduser,idmodule,idworkspace,idobject,idrecord,value,iduserfrom,divcontent,activemode,mustreload) {
	if (activemode==1) {
		dims_xmlhttprequest_todiv('admin-light.php','dims_op=updatefavoriteobject&idfav='+idfav+'&iduserfrom='+iduserfrom+'&iduser='+iduser+'&idmodule='+idmodule+'&idworkspace='+idworkspace+'&idobject='+idobject+'&idrecord='+idrecord+'&value='+value,'',divcontent);
	}
	else {
		dims_xmlhttprequest('admin-light.php','dims_op=updatefavoriteobject&idfav='+idfav+'&iduserfrom='+iduserfrom+'&iduser='+iduser+'&idmodule='+idmodule+'&idworkspace='+idworkspace+'&idobject='+idobject+'&idrecord='+idrecord+'&value='+value+'&passivemode=1');
		if (mustreload==null) mustreload=false;
		if (mustreload) window.location.reload();
	}
}

function refreshDesktop(type,action,op,divcontent) {
	dims_xmlhttprequest_todiv('admin.php','dims_op=refreshdesktop&type='+type+'&action='+action+'&op='+op,'',divcontent);
}

function refreshTimerDesktop(type,action,op,divcontent) {
	timerusersportalrefresh = setTimeout("execrefreshDesktop('"+type+"','"+action+"','"+op+"','"+divcontent+"')", 30000);
}

function execrefreshDesktop(type,action,op,divcontent) {
	clearTimeout(timerusersportalrefresh);
	dims_xmlhttprequest_todiv('admin.php','dims_op=refreshdesktop&type='+type+'&action='+action+'&op='+op,'',divcontent);
	refreshTimerDesktop(type,action,op,divcontent);
}

function switchOption(event,cmd,id) {
	var opttxt=dims_getelem("optionstext"+id);
	var optcmd=dims_getelem("optionscmd"+id);

	for(i=0;i<listmodules.length;i++) {
		opttxt=dims_getelem("optionstext"+listmodules[i]);
		optcmd=dims_getelem("optionscmd"+listmodules[i]);
		opttxt.style.visibility="visible";
		opttxt.style.display="block";
		optcmd.style.visibility="hidden";
		optcmd.style.display="none";
	}
	var opttxt=dims_getelem("optionstext"+id);
	var optcmd=dims_getelem("optionscmd"+id);

	opttxt.style.visibility="hidden";
	opttxt.style.display="none";
	optcmd.style.visibility="visible";
	optcmd.style.display="block";
}

function displayModuleInformation(event,idmodule) {
	eventcour=event;
	dims_showpopup('',400,eventcour);
	dims_xmlhttprequest_todiv('admin.php','dims_op=displaymodinfo&idmodule='+idmodule,'','dims_popup');
}

function displayMapWorkspaces(event) {
	var eventcour=event;
	var dims_popup=document.getElementById('dims_popup');
	var x=200;
	var y=50;

	dims_popup.style.visibility='visible';
	dims_popup.style.display='block';
	dims_popup.style.position="absolute";

	if( window.innerWidth) {
		dims_popup.style.width=(window.innerWidth *4)/ 5+"px";
		x = (window.innerWidth / 2) - (dims_popup.offsetWidth / 2);
  		y = 60; //(window.offsetHeight / 2) - (dims_popup.offsetHeight / 2);
	}
  	else {
  		dims_popup.style.width=(document.body.offsetWidth *4)/ 5+"px";
		dims_popup.style.height=60; //(document.body.offsetHeight *4)/ 5+"px";
		x = (document.body.offsetWidth / 2) - (dims_popup.offsetWidth / 2);
  		//y = (document.body.offsetHeight / 2) - (dims_popup.offsetHeight / 2);
  		y = 60;
  	}

  	dims_popup.style.top = y+"px";
  	dims_popup.style.left = x+"px";
  	dims_popup.style.display = "block";

	dims_xmlhttprequest_todiv('admin.php','dims_op=view_workspace','','dims_popup');

}

function dislayResultOverTimer(event,idmodule,idobject,idrecord) {
	eventcour=event;
	dims_showpopup('',400,eventcour);
	dims_xmlhttprequest_todiv('admin.php','dims_op=displaysearchresult&idmodule='+idmodule+'&idobject='+idobject+'&idrecord='+idrecord,'','dims_popup');
}

function dislayContentOverTimer(event,idmodule,idobject,idrecord) {
	eventcour=event;
	dims_showpopup('',600,eventcour,'click',"dims_popup2");
	dims_xmlhttprequest_todiv('admin.php','dims_op=displaycontent&moduleid='+idmodule+'&idobject='+idobject+'&idrecord='+idrecord,'','dims_popup2');
}

function displaySharesModules(event,idobject,idrecord,idmodule) {
	dims_showpopup('',400,event);
	dims_xmlhttprequest_todiv('admin.php','dims_op=shares_viewmodule&idmodule='+idmodule+'&idobject='+idobject+'&idrecord='+idrecord,'','dims_popup');
}

function saveSharesModules(idobject,idrecord,idmodule) {
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=shares_savemodule&idmodule='+idmodule+'&idobject='+idobject+'&idrecord='+idrecord,saveSharesModulesSuite,idrecord);
}

function saveSharesModulesSuite(result,idmodule) {
	dims_getelem('dims_popup').style.visibility='hidden';
	refreshSharesModules(idmodule);
}

function refreshSharesModules(idmodule) {
	dims_xmlhttprequest_todiv('admin.php','dims_op=shares_refreshmodule&idmodule='+idmodule,'||','adminmod_'+idmodule,'adminviewmod_'+idmodule);
}

function displayDomainInfo(event,typeaccess,iddomain) {
	dims_showpopup('',460,event,'click');
	dims_xmlhttprequest_todiv('admin.php','dims_op=domains_viewdomain&iddomain='+iddomain+'&typeaccess='+typeaccess,'','dims_popup');
}

function displayTemplateInfo(event,idworkspace) {
	dims_showpopup('',400,event,'click');
	dims_xmlhttprequest_todiv('admin.php','dims_op=templates_view&idworkspace='+idworkspace,'','dims_popup');
}

function dislayResultOver(idmodule,idobject,idrecord) {
	dims_showpopup('',400,eventcour,'click');
	dims_xmlhttprequest_todiv('admin.php','dims_op=displaysearchresult&idmodule='+idmodule+'&idobject='+idobject+'&idrecord='+idrecord,'','dims_popup');
}

function undodisplayResult() {
	clearTimeout(timerdisplayresult);
}

function switchsearch() {
	var elem=dims_getelem('block_search');
	var state=0;

	if (elem!=null) {
		if(elem.style.display!='block') {
			elem.style.display='block';
			elem.style.visibility='visible';
			dims_getelem('wordsearch').focus();
			state=1;
		}
		else {
			elem.style.display='none';
			elem.style.visibility='hidden';
			state=0;
		}
		dims_xmlhttprequest('admin.php','dims_op=active_search&state='+state);

		//if (state==0) searchNews();
		//else searchEmpty();
	}
	//else {
	//	document.location="admin.php?dims_mainmenu=0&dims_desktop=portal&displaysearch=1";
	//}
}

function changetagsearch() {
	var elem=dims_getelem('checktagsearch');
	var state=0;

	if (elem!=null) {
		if(elem.checked) state=1;
		else {
			dims_getelem('resulttags').innerHTML="";
			state=0;
		}
		dims_getelem('wordsearch').focus();
		dims_xmlhttprequest('admin.php','dims_op=checktagsearch&state='+state);
	}

}

/******************************************************************************************************/
/*      Function clipboard                                                                            */
/******************************************************************************************************/
var currentselection="";
var elemselection;
var elemsrc;

function detectSelectedText(event) {
	/*
	if (document.selection!=null && document.selection.createRange().text)
		sel = document.selection.createRange().text;
	else if (window.getSelection())
		sel = window.getSelection();

	event= (!event) ? window.event : event;
	// on peut détecter le type de champ si c'est un input ou textarea
	var src= (event) ? event.target : event.srcElement;

	if((src.tagName=="INPUT" && src.type=="text") || src.type=="textarea") {
		elemsrc=src;
		elemselection=src;

	}

	if (sel != "") {
		// on appelle la barre de proposition de copie
		if (currentselection!=sel) {
			currentselection=""+sel;
			dims_showpopup('',90,event,'click','dims_clipboard');
			dims_xmlhttprequest_todiv('admin.php','dims_op=clipboard_showcmd','','dims_clipboard');
		}

	}
	else {
		if((src.tagName=="INPUT" && src.type=="text") || src.type=="textarea") {

			dims_showpopup('',90,event,'click','dims_clipboard',0,-55);
			dims_xmlhttprequest_todiv('admin.php','dims_op=clipboard_showcmdget','','dims_clipboard');
		}
	}
	*/
}

function clipboard_getallSuite(result) {
	if((elemsrc.tagName=="INPUT" && elemsrc.type=="text") || elemsrc.type=="textarea") {
		elemselection.value=result;
	}
	dims_hidepopup('dims_clipboard');
	elemselection.focus();
}

function clipboard_copy(event) {
	if (document.selection!=null && document.selection.createRange().text)
		sel = document.selection.createRange().text;
	else if (window.getSelection())
		sel = window.getSelection();

	if (sel != "") {
		dims_xmlhttprequest('admin.php','dims_op=clipboard_add&paste='+window.getSelection());
		dims_hidepopup('dims_clipboard');
		//dims_showpopup('',400,event,'click','dims_clipboard');
		//dims_xmlhttprequest_todiv('admin.php','dims_op=clipboard_show','','dims_clipboard');
	}
	else
		alert("Aucune selection !");
}

function clipboard_copyto(id_element) {
	var elem = dims_getelem(id_element);
	elem.select();
}

function clipboard_get(element) {
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=clipboard_pasteall',clipboard_getallSuite);
}

function clipboard_delete(id) {
	dims_xmlhttprequest_todiv('admin.php','dims_op=clipboard_delete&id='+id, '' ,'dims_clipboard');
}

function dims_show_clipboard(event) {
	dims_showpopup('',400,event,'click','dims_clipboard');
	dims_xmlhttprequest_todiv('admin.php','dims_op=clipboard_show','','dims_clipboard');
}

function zoomOuputBlock(mod) {
	var contentzoom=$("zoomContent");
	contentzoom.innerHTML="";
	contentzoom.style.visibility="hidden";
	contentzoom.style.display="none";

	var elem = $("dimsminimize");
	elem.style.display="none";
	elem.style.visibility="hidden";

	elem = $("dimsblock");
	elem.style.display="block";
	elem.style.visibility="visible";
}

function zoomBlock(mod) {
	var elem = $("dimsblock");
	elem.style.display="none";
	elem.style.visibility="hidden";

	elem = $("dimsminimize");
	elem.style.display="block";
	elem.style.visibility="visible";

	viewActiveZoom(mod);
}


function viewActiveZoom(mod) {
	var contentzoom=$("zoomContent");

	contentzoom.style.visibility="visible";
	contentzoom.style.display="block";
	var elem=$("block-"+mod);
	var ch=elem.innerHTML;
	ch=ch.replace("content"+mod,"zoomcontent"+mod);
	ch=ch.replace("moduleContent0","moduleContentZoom");
	ch=ch.replace("moduleContent1","moduleContentZoom");
	ch=ch.replace("closestate","closestatehide");
	ch=ch.replace("zoomBlock","zoomOuputBlock");
	ch=ch.replace("zoom.png","zoomouput.png");

	contentzoom.innerHTML=ch.replace("search_explorer_main","search_explorer_mainzoom");
}

function updateValidate(mod,refresh) {
    if (refresh==null) refresh=false;
	//var elem=$("ressearch"+mod);
	//elem.innerHTML="<font class=\"fontgray\">-</font>";
    if (refresh)
        dims_xmlhttprequest_tofunction('admin-light.php',"dims_op=updatevalidate&moduleid="+mod,updateValidateSuite);
	else
        dims_xmlhttprequest("admin-light.php","dims_op=updatevalidate&moduleid="+mod);
}

function updateValidateSuite() {
    document.location.reload();
}

function updateAllValidate() {
	dims_xmlhttprequest("admin-light.php","dims_op=updateallvalidate");
}

function updateState(mod,state) {
	elemstate=$('state'+mod);
	var elemdiv=$("content"+mod);
	var elemimg=$("bkimg"+mod);
	var h=0;

	var src="";

	if (elemstate.innerHTML=="0") {
		h="165px";
		state=1;
		elemstate.innerHTML="1";
		src="./img/minimize.gif";

		if (statesearch=="search") {
			searchWordSuite("",mod);
		}
		else {
			dims_xmlhttprequest_todiv('admin-light.php','dims_op=searchnews&moduleid='+mod,'||','ressearch'+mod,'content'+mod);
		}
	}
	else {
		h="0px";
		state=0;
		elemstate.innerHTML="0";
		src="./img/maximize.gif";
	}

	dims_xmlhttprequest("admin-light.php","dims_op=updatestate&module="+mod+"&state="+state);
	elemdiv.style.height=h;
	elemimg.src=src;
}

function addTags(event,data) {
 	dims_showpopup('',350, event);
	timerportalrefresh = setTimeout("execaddTags('"+data+"')", 100);
}

function execaddTags(data) {
	clearTimeout(timerportalrefresh);
	dims_xmlhttprequest_todiv("admin-light.php",data,'',"dims_popup");
}

function useCampaign(campaignid) {
	currentcampaign=campaignid;
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=useCampaign&campaignid='+campaignid,useCampaignSuite);
}

function useCampaignSuite(result) {
	//dims_getelem('dims_getelem('resultselectedwords').innerHTML=result;').innerHTML=result;
	searchWordSuite("",0);
}

function addCampaign(event) {
 	dims_showpopup('Campaign',300, event);
	timerportalrefresh = setTimeout("execCampaign()", 100);
}

function execCampaign() {
	clearTimeout(timerportalrefresh);
	dims_xmlhttprequest_todiv("admin-light.php",'dims_op=add_campain','',"dims_popup");
}

function dims_init_refresh_campaign() {
	timerportalrefreshcampaign = setTimeout("execRefreshCampaign()", 120000);
}

function execRefreshCampaign() {
	clearTimeout(timerportalrefreshcampaign);
	dims_xmlhttprequest_todiv("admin-light.php",'dims_op=execRefreshCampaign','||',"infocampaign","listcampaign");
	dims_init_refresh_campaign();
}

function deleteCampaign(val) {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=deleteCampaign&campaignid='+val,'||',"infocampaign","listcampaign");
}

function updateCampaign(val) {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=updateCampaign&campaignid='+val,'||',"infocampaign","listcampaign");
}

function updateOperator(key,val) {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=word_updateoperatorsearch&wordid='+key+"&val="+val,'','resultselectedwords');
}

function addParenthese() {
	var elemdiv;
	var d1=0;
	var d2=0;
	var f1=0;
	var f2=0;
	var begin="";
	var last="";

	if (document.getSelection) sel = document.getSelection();
	else if (document.selection) sel = document.selection.createRange().text;

	if (sel.length>0) {
		// on supprime les parenthses ( et )
		sel=sel.replace(/[(]/g,"");
		sel=sel.replace(/[)]/g,"");
		sel=sel.replace(/&nbsp;/g,"");

		// recuperation du premier et dernier mot
		d1=sel.indexOf(" & ");
		d2=sel.indexOf(" U ");
		f1=sel.lastIndexOf(" & ");
		f2=sel.lastIndexOf(" U ");
		if ((d1>0 || d2>0) && (f1>0 || f2>0)) {
			// extraction du premier et dernier mots
			if (d1>0 && d2>0) {
				if (d1<d2) begin=sel.substring(0,d1);
				else begin=sel.substring(0,d2);
			}
			else {
				if (d1>0) begin=sel.substring(0,d1);
				else begin=sel.substring(0,d2);
			}

			if (f1>0 && f2>0) {
				if (f1>f2) last=sel.substring(f1+3,sel.length);
				else last=sel.substring(f2+3,sel.length);
			}
			else {
				if (f1>0) last=sel.substring(f1+3,sel.length);
				else last=sel.substring(f2+3,sel.length);
			}

			if (begin.length>0 && last.length>0)
				dims_xmlhttprequest_todiv('admin-light.php','dims_op=word_addparenthese&begin='+begin+'&last='+last,'','resultselectedwords');
		}
	}
	else alert("Vous devez slectionner au moins deux mots cles");
}

function addSelectedWord(word) {
	issearching=true;
	if (document.getElementById("imgsearch")!=null) {
		if (ancienimgsearch=="") ancienimgsearch=document.getElementById("imgsearch").src;
		document.getElementById("imgsearch").src="./img/loading.gif";
	}
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=word_addsearch&word='+word,addSelectedWordSuite,word);
}

function addSelectedWordSuite(result,word) {
	dims_getelem('resultselectedwords').innerHTML=result;
	/* on appelle la mise en cache de la sélection*/
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=word_addsearchcache&word='+word,addSelectedWordEnd);
}

function addSelectedWordEnd(result) {
	issearching=false;
	if (ancienimgsearch!="") document.getElementById("imgsearch").src=ancienimgsearch;
	document.getElementById("wordsearch").focus();
	searchWord();
}

function deleteSelectedWord(wordid) {
	/* hide dims_popup*/
	dims_getelem('dims_popup').style.visibility='hidden';
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=word_deletesearch&wordid='+wordid,'','resultselectedwords');
}

function refreshSelectedWord() {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=word_refreshselectedword','','resultselectedwords');
}

function deleteSelected() {
	/* hide dims_popup*/
	dims_getelem('dims_popup').style.visibility='hidden';
	currentcampaign=0;
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=word_deleteselected','','resultselectedwords');
	searchEmpty();
}

function addSelectedTag(tag) {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=tag_addsearch&tag='+tag,'','resultselectedtags');
}

function deleteSelectedTag(tagid) {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=tag_deletesearch&tagid='+tagid,'','resultselectedtags');
}

function refreshSelectedTag() {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=tag_refreshselectedtag','','resultselectedtags');
}

function deleteSelectedTags() {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=tag_deleteselected','','resultselectedtags');
}

function searchNews() {
	var elemdiv;

	for(i=0;i<listmodules.length;i++) {
		elemdiv=document.getElementById('state'+listmodules[i]);
		if (elemdiv.innerHTML=="1")
			document.getElementById('content'+listmodules[i]).innerHTML="<table width=\"99%\" height=\"99%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
	}

	for(i=0;i<listmodules.length;i++) {
		elemdiv=document.getElementById('state'+listmodules[i]);
		if (elemdiv.innerHTML=="1")
			dims_xmlhttprequest_todiv('admin-light.php','dims_op=searchnews&moduleid='+listmodules[i],'||','ressearch'+listmodules[i],'content'+listmodules[i]);
	}
	statesearch="searchnews";
}

function searchRecursiveNews() {
	i=0;
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=searchnews&moduleid='+listmodules[i],searchRecursiveNewsSuite,i);
	statesearch="searchnews";
}

function searchRecursiveNewsSuite(result,i) {
	if (result!=null) tabxmlvalue=result.split("||");
	var elem=dims_getelem('ressearch'+listmodules[i]);
	var elemcontent=dims_getelem('content'+listmodules[i]);
	
	if (elem!=null) elem.innerHTML= "<a href=\"javascript:void(0);\" onclick=\"javascript:switchModuleDisplay("+listmodules[i]+");\">"+tabxmlvalue[0]+"</a>";
	if (elemcontent!=null) elemcontent.innerHTML= tabxmlvalue[1];
	
	i++;
	
	if (i<listmodules.length) {
		/*elem=dims_getelem('ressearch'+listmodules[i]);
		elemcontent=dims_getelem('content'+listmodules[i]);
		if (elem!=null) elem.innerHTML="<img src=\"./img/loading.gif\" alt=\"\">";
		if (elemcontent!=null) elemcontent.innerHTML="<table width=\"100%\" height=\"100%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
		*/
		dims_xmlhttprequest_tofunction('admin-light.php','dims_op=searchnews&moduleid='+listmodules[i],searchRecursiveNewsSuite,i);
	}
}

function searchRecursiveFavorites(type) {
	i=0;
	typefavorite=type;
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=searchfavorites&type='+typefavorite+'&moduleid='+listmodules[i],searchRecursiveFavoritesSuite,i);
	statesearch="searchnfavorites";
}

function searchRecursiveFavoritesSuite(result,i) {
	tabxmlvalue=result.split("||");
	var elem=dims_getelem('ressearch'+listmodules[i]);
	var elemcontent=dims_getelem('content'+listmodules[i]);
	
	if (elem!=null) elem.innerHTML= "<a href=\"javascript:void(0);\" onclick=\"javascript:switchModuleDisplay("+listmodules[i]+");\">"+tabxmlvalue[0]+"</a>";
	if (elemcontent!=null) elemcontent.innerHTML= tabxmlvalue[1];
		
	i++;
	if (i<listmodules.length) {
		elem=dims_getelem('ressearch'+listmodules[i]);
		elemcontent=dims_getelem('content'+listmodules[i]);
		if (elem!=null) elem.innerHTML="<img src=\"./img/loading.gif\" alt=\"\">";
		if (elemcontent!=null) elemcontent.innerHTML="<table width=\"100%\" height=\"100%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
		
		dims_xmlhttprequest_tofunction('admin-light.php','dims_op=searchfavorites&type='+typefavorite+'&moduleid='+listmodules[i],searchRecursiveFavoritesSuite,i);
	}
}

function refreshAgenda(moduleid,month,year) {
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=searchnews&moduleid='+moduleid+'&agenda_month_block='+month+'&agenda_year_block='+year,'||','ressearch'+moduleid,'content'+moduleid);
}

function searchEmpty() {

	var elemdiv;

	for(i=0;i<listmodules.length;i++) {
		elemdiv=document.getElementById('state'+listmodules[i]);
		if (elemdiv.innerHTML=="1") {
			document.getElementById('content'+listmodules[i]).innerHTML="";
		}
	}
	arraysearch = new Array();
	document.getElementById("wordsearch").focus();
}

function searchUniqueWord(idmodule) {
	word=document.getElementById("wordsearch").value;
	document.getElementById('content'+idmodule).innerHTML="<table width=\"100%\" height=\"100%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
	dims_xmlhttprequest_todiv('admin-light.php','dims_op=searchunique&moduleid='+idmodule+'&word='+word,'||','ressearch'+idmodule,'content'+idmodule);
}

function searchWordtmp() {
	i=0;
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=search&moduleid='+listmodules[i]+'&word='+wordsearch,searchSuite,i);
}

function searchSuite(result,i) {
	dims_getelem('content'+listmodules[i]).innerHTML=result;
	i++;
	if (i<listmodules.length) {
		document.getElementById('content'+listmodules[i]).innerHTML="<table width=\"100%\" height=\"100%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
		dims_xmlhttprequest_tofunction('admin-light.php','dims_op=search&moduleid='+listmodules[i]+'&word='+wordsearch,searchSuite,i);
	}
	else document.getElementById("wordsearch").focus();
}

function searchWord() {
	/* test for unique search or not */
	//listmod=document.getElementById('listemodulesearch');
	//selectedelement=listmod.selectedIndex;
	moduleid=0;
	res="";
for(i=0;i<listmodules.length;i++) {
	res=res+listmodules[i]+" ";
}

	/*if (selectedelement==0 || currentcampaign>0) {
		for(i=0;i<listmodules.length;i++) {
		document.getElementById('content'+listmodules[i]).innerHTML="<table width=\"100%\" height=\"100%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
		}*/

	/*}
	else {
		moduleid=listmod.options[selectedelement].value;
		document.getElementById('content'+moduleid).innerHTML="<table width=\"100%\" height=\"100%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
	}*/
	/*init de mouseover sur l'objet */
	idrecord_over=0;
	idobj_over=0;
	idmod_over=0;
	isearch=0;
	statesearch="search";
	/* preparation et chargement des éléments en mémoire */
	dims_xmlhttprequest_tofunction('admin-light.php','dims_op=executesearch',searchWordSuite);
}


function searchRecursiveWordSuite(result,isearch) {
	tabxmlvalue=result.split("||");
	dims_getelem('ressearch'+listmodules[isearch]).innerHTML= "<a href=\"javascript:void(0);\" onclick=\"javascript:switchModuleDisplay("+listmodules[isearch]+");\">"+tabxmlvalue[0]+"</a>";
	dims_getelem('content'+listmodules[isearch]).innerHTML= tabxmlvalue[1];
		
	isearch++;
	if (isearch<listmodules.length) {
		document.getElementById('ressearch'+listmodules[isearch]).innerHTML="<img src=\"./img/loading.gif\" alt=\"\">";
		document.getElementById('content'+listmodules[isearch]).innerHTML="<table width=\"100%\" height=\"100%\"><tr><td valign=\"center\" align=\"center\"><img src=\"./img/loading.gif\" alt=\"\"></td></tr></table>";
		
		dims_xmlhttprequest_tofunction('admin-light.php','dims_op=search&moduleid='+listmodules[isearch],searchRecursiveWordSuite,isearch);
	}
}

function searchWordSuite(result) {
	isearch=0;
	if (listmodules[isearch]!=null) {
		dims_xmlhttprequest_tofunction('admin-light.php','dims_op=search&moduleid='+listmodules[isearch],searchRecursiveWordSuite,isearch);
	}
	else { 
		/*recherche unique */
		sm=dims_getelem('dims_searchmenu');
		sm.style.visibility="visible";
		sm.style.display="block";
		dims_xmlhttprequest_todiv('admin-light.php','dims_op=search','||','dims_ressearch','dims_searchcontent');
	}
/*
	if (moduleid==0 && currentcampaign<0) {
		listmod=document.getElementById('listemodulesearch');
		selectedelement=listmod.selectedIndex;
		moduleid=listmod.options[selectedelement].value;
	}

	if (moduleid>0 ) {
		dims_xmlhttprequest_todiv('admin-light.php','dims_op=search&moduleid='+moduleid+"&campaignid="+currentcampaign,'||','ressearch'+moduleid,'content'+moduleid);
	}
	else {
		for(i=0;i<listmodules.length;i++) {
			dims_xmlhttprequest_todiv('admin-light.php','dims_op=search&moduleid='+listmodules[i]+"&campaignid="+currentcampaign,'||','ressearch'+listmodules[i],'content'+listmodules[i]);
		}

		if (currentcampaign>0)
		dims_xmlhttprequest_todiv("admin-light.php","dims_op=execRefreshCacheCampaign&campaignid="+currentcampaign,"","resultselectedwords");
	}

	document.getElementById("wordsearch").focus();
*/
}

function prepareWord() {
	document.getElementById("wordsearch").focus();
	document.getElementById("wordsearch").select();
}

var word_timer;
var word_search;
var word_deb;
var lastword;
var word_results = new Array();
var tag_results = new Array();

var arraysearch = new Array();
var word_new_array = new Array();
var tag_last_array = new Array();
var tag_new_array = new Array();

var word_lastedit = '';
var word_modified = -1
var issearching=false;
var ancienimgsearch ="";
var nbelemcourant=0;
var nbelemtmp=0;
function dims_word_init() {
	dims_getelem('wordsearch').onkeyup = dims_word_keyup;
	dims_getelem('wordsearch').onkeypress = dims_word_keypress;
}

function dims_word_init_semanticsearch() {
	dims_xmlhttprequest("admin-light.php","dims_op=init_semanticsearch");
}

function dims_word_search() {

	if (!issearching) {
		clearTimeout(word_timer);
		word_search = dims_getelem('wordsearch').value;
		word_timer = setTimeout("dims_word_searchtimeout()", 600);
	}
}

function dims_word_searchtimeout() {
	issearching=true;

	word_search=word_search.replace('(','');
	word_search=word_search.replace(')','');
	word_search=word_search.replace('AND','');
	word_search=word_search.replace('OR','');
	list_words = word_search.split(' ');

	if (list_words.length>0) {
		nbelemcourant=list_words.length;
		dims_word_searchlastword(list_words[list_words.length-1]);
	}
	else {
		dims_getelem('resultwords').innerHTML ="";
		dims_getelem('resulttags').innerHTML = "";
		issearching=false;
	}

}

function dims_word_searchrecursword(result,ind) {
	if (ind<list_words.length) {
		word=list_words[ind];
		arraysearch[arraysearch.length]=word;

		// recursive call for analyse next word
		if (ind==list_words.length-1)
			dims_word_searchlastword(list_words[ind]);
		else
			dims_xmlhttprequest_tofunction('index-light.php','dims_op=word_addsearchcache&word='+word,dims_word_searchrecursword,ind+1);
	}
}

function dims_word_searchlastword(ch) {
	if (ch.length>=2) {
		issearching=true;
		if (document.getElementById("imgsearch")!=null) {
			if (ancienimgsearch=="") ancienimgsearch=document.getElementById("imgsearch").src;
			document.getElementById("imgsearch").src="./img/loading.gif";
		}

		dims_xmlhttprequest_tofunction('index-light.php','dims_op=word_presearch&word='+word_search,dims_word_display);
		if (document.getElementById("checktagsearch").checked)
			dims_xmlhttprequest_tofunction('index-light.php','dims_op=tag_presearch&word='+ch,dims_tag_search_display);
	}
	else {
		issearching=false;
		word_search="";
	}
}

function dims_word_display(result,ticket) {
	if (result != '') {
		debch="";
		if (word_deb!="") debch="\""+word_deb;

		word_results = new Array();
		var nbwords=0;

		splited_result = result.split('|');
		tagstoprint = '';

		for (i=0;i<splited_result.length;i++) {

			if (i==0) {
				// on compte le nbre d'elements
				nbelemtmp=splited_result[i].split(' ').length;
			}
			//if (word_deb!="") detail=debch+" "+splited_result[i]+"\"";
			detail = splited_result[i];
			nbwords=detail.split(' ').length;

			if (tagstoprint != '') tagstoprint += ' ';
			if (nbwords==1) detailtext=detail;
			else detailtext="\""+detail+"\"";

			tagstoprint += '<a href="javascript:addSelectedWord(\''+detail+'\');prepareWord();">'+detailtext+'</a>&nbsp;|&nbsp; ';
			word_results[i] = detail;
		}

		dims_getelem('resultwords').innerHTML = tagstoprint;
	}
	else {
		dims_getelem('resultwords').innerHTML = '';
		//word_results = new Array();
	}
	issearching=false;

	if (ancienimgsearch!="") document.getElementById("imgsearch").src=ancienimgsearch;

	dims_getelem('wordsearch').selectionStart=dims_getelem('wordsearch').value.length;
	dims_getelem('wordsearch').selectionEnd=dims_getelem('wordsearch').value.length;
	// test si on a pas ecrit qq chose en attendant
	if (dims_getelem('wordsearch').value!=word_search) dims_word_search();

}

function dims_tag_search_display(result,ticket) {
	if (result != '') {
		tag_results = new Array();

		splited_result = result.split('|');
		tagstoprint = '';

		for (i=0;i<splited_result.length;i++) {
			detail = splited_result[i];
			if (tagstoprint != '') tagstoprint += ' ';
			if (i==0) tagstoprint += '<b>';
			tagstoprint += '<a href="javascript:addSelectedTag(\''+detail+'\');prepareWord();">'+detail+'</a>&nbsp;|&nbsp; ';
			if (i==0) tagstoprint += '</b>';
			tag_results[i] = detail;
		}
		dims_getelem('resulttags').innerHTML = tagstoprint;
	}
	else {
		dims_getelem('resulttags').innerHTML = '';
		tags_results = new Array();
	}
}

function dims_word_prevent(e) {
	if (window.event) window.event.returnValue = false;
	else e.preventDefault();
}

function dims_word_keypress(e) {
	e=e||window.event;
	src = (e.srcElement) ? e.srcElement : e.target;

	switch(e.keyCode) {

		case 38: case 40:
			//prevent(e);
		break;
		case 9:
			dims_word_prevent(e);
		break;
		case 13:
			dims_word_prevent(e);
		break;

		default:
			word_lastedit = dims_getelem(src.id).value;
		break;
	}
}

function dims_word_keyup(e) {
	e=e||window.event;
	src = (e.srcElement) ? e.srcElement : e.target; // get source field

	switch(e.keyCode) {
		case 8:
			if (dims_getelem('wordsearch').value.length==0) {
				dims_getelem('wordsearch').value="";
				dims_getelem('resultwords').innerHTML="";
				dims_getelem('resulttags').innerHTML="";
				word_results = new Array();
			}
			else dims_word_search();
			break;

		case 13:
			//dims_word_complete();
			//dims_word_prevent(e);
			//searchWord();

			word=dims_getelem('wordsearch').value;

			if (word.length>0) {
				addSelectedWord(word);
				dims_getelem('wordsearch').value="";
				dims_getelem('resultwords').innerHTML="";
				dims_getelem('resulttags').innerHTML="";
				word_results = new Array();
			}
		break;
		case 35: //end
		case 36: //home
			dims_word_prevent(e);
			break;
		case 39: //right
		case 37: //left
		case 38 : //up
		case 40: //down
			if (word_results.length>0) {
				dims_word_prevent(e);
				dims_getelem('wordsearch').selectionStart=dims_getelem('wordsearch').value.length;
				dims_getelem('wordsearch').selectionEnd=dims_getelem('wordsearch').value.length;
				// verify if result so turn up
				var savefirstvalue="";
				if (e.keyCode==38 || e.keyCode==37) {
					for(i=0;i<word_results.length;i++) {
						if (i==0) savefirstvalue=word_results[i];
						word_results[i]=word_results[i+1];
					}
					word_results[i-1]=savefirstvalue;
				}
				else {
					for(i=(word_results.length-2);i>=0;i--) {
						if (i==(word_results.length-2)) savefirstvalue=word_results[i+1];
						word_results[i+1]=word_results[i];
					}
					word_results[0]=savefirstvalue;
				}
				var nbwords=dims_getelem('wordsearch').value.split(' ').length;

				tagstoprint = '';

				for (i=0;i<word_results.length;i++) {
					detail = word_results[i];

					if (tagstoprint != '') tagstoprint += ' ';
					if (nbwords==1) detailtext=detail;
					else detailtext="\""+detail+"\"";

					tagstoprint += '<a href="javascript:addSelectedWord(\''+detail+'\');prepareWord();">'+detailtext+'</a>&nbsp;|&nbsp; ';
				}
				dims_getelem('resultwords').innerHTML = tagstoprint;
			}
			break;
		case 9:
		case 32: //space
			dims_word_prevent(e);

			if (word_results.length==0) dims_word_prevent(e);
			else {
				// on regarde le mot courant
				// on split le tableau et ensuite on prend le dernier en cours
				var word_search = dims_getelem('wordsearch').value;
				// premier test si dernier caractère saisi est un espace

				var list_wordstmp = word_search.split(' ');

				if (list_wordstmp.length>0) {
					// on a bien un mot tapé : on regarde si on a des éléments dans la liste
					if (word_results.length>=1) {
						/*
						var trouve=false;
						wordsearch=list_words[list_words.length-2];

						for(i=0;i<word_results.length;i++) {

							if (wordsearch==word_results[i]) {
								trouve=true;
							}
						}

						if (!trouve) {
						nbelemcourant==nbelemtmp ||
						*/

						if ( e.keyCode==9) {
							// recupération de la proposition de mot
							word=word_results[0];

							// on ajoute le nouveau mot ds la liste courant
							arraysearch[arraysearch.length]=word;
							dims_getelem('wordsearch').value=word+" ";

							dims_getelem('resultwords').innerHTML="";
							dims_getelem('resulttags').innerHTML="";

							issearching=true;
							if (document.getElementById("imgsearch")!=null) {
								if (ancienimgsearch=="") ancienimgsearch=document.getElementById("imgsearch").src;
								document.getElementById("imgsearch").src="./img/loading.gif";
							}
							dims_xmlhttprequest_tofunction('index-light.php','dims_op=word_presearch&word='+word+"%20",dims_word_display);
						}
						//}
					}

				}
			}
			break;
		case 8:
		default:
			if (lastword!=dims_getelem('wordsearch').value) dims_word_search();

		break;
	}
}

function dims_word_keyupunique(e)
{
	e=e||window.event;
	src = (e.srcElement) ? e.srcElement : e.target; // get source field

	switch(e.keyCode)
	{
		case 38: case 40:
			prevent(e);
		break
		case 9:
			//dims_word_complete();
			//dims_word_prevent(e);
		break
		case 13:
			//dims_word_complete();
			dims_word_prevent(e);
			// on recupere le numro de module
			var ch=src.id;
			idmodule=ch.substring(10,ch.length);
			searchUniqueWord(idmodule);
		break;
	}
}


function dims_word_complete(idword)
{
	/*
	if (!(idword>=0)) idword = 0;

	if (word_results[idword])
	{
		word_new_array[word_modified] = word_results[idword];

		taglist = '';
		for (i=0;i<word_new_array.length;i++)
		{
			if (taglist != '') taglist += ' ';
			taglist += word_new_array[i]
		}

		dims_getelem('wordsearch').value = taglist.replace('/(^\s*)|(\s*$)/g','')+" ";
		//dims_getelem('resultwords').innerHTML = '';
	}

	word_results = new Array();
	*/
}

// accordion.js v2.0
//
// Copyright (c) 2007 stickmanlabs
// Author: Kevin P Miller | http://www.stickmanlabs.com
//
// Accordion is freely distributable under the terms of an MIT-style license.
if (typeof Effect == 'undefined')
	throw("accordion.js requires including script.aculo.us' effects.js library!");

var accordion = Class.create();
accordion.prototype = {

	//
	//  Setup the Variables
	//
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	AlreadyActivated: [], //Added by Trey
	//
	//  Initialize the accordions
	//
	initialize: function(container, options) {
	  if (!$(container)) {
	    throw(container+" doesn't exist!");
	    return false;
	  }

		this.options = Object.extend({
			resizeSpeed : 8,
			classNames : {
				toggle : 'accordion_toggle',
				toggleActive : 'accordion_toggle_active',
				content : 'accordion_content'
			},
			defaultSize : {
				height : null,
				width : null
			},
			direction : 'vertical',
			onEvent : 'click',
			onActivate: null, //Added by Trey:  CallBack Function called when Tab is activated, sends elemet.
			RepeatActivate: {} //Added by Trey
		}, options || {});

		this.duration = ((11-this.options.resizeSpeed)*0.15);
		this.AlreadyActivated =[]; //Added by Trey
		var accordions = $$('#'+container+' .'+this.options.classNames.toggle);
		accordions.each(function(accordion) {
			Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
			if (this.options.onEvent == 'click') {
			  accordion.onclick = function() {return false;};
			}

			if (this.options.direction == 'horizontal') {
				var options = {width: '0px'};
			} else {
				var options = {height: '0px'};
			}
			//options.merge({display: 'none'});
			Object.extend(options, {display: 'none'});

			this.currentAccordion = $(accordion.next(0)).setStyle(options);
		}.bind(this));
	},

	//
	//  Activate an accordion
	//
	activate : function(accordion) {
		if (this.animating) {
			return false;
		}

		this.effects = [];

		this.currentAccordion = $(accordion.next(0));
		this.currentAccordion.setStyle({
			display: 'block'
		});

		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);

		if (this.options.direction == 'horizontal') {
			this.scaling = {
				scaleX: true,
				scaleY: false
			};
		} else {
			this.scaling = {
				scaleX: false,
				scaleY: true
			};
		}

		if (this.currentAccordion == this.showAccordion) {
		  this.deactivate();
		} else {

//This was added by Trey Aughenbaugh
//Allows calling a function before activating a new Menu
		var bolCall = true;
		var elementid = $(this.currentAccordion).id
		var AA = this.AlreadyActivated.indexOf(elementid);
		var RA = this.options.RepeatActivate[elementid];
		if (RA != undefined)
		{
			if ( AA != -1 )
			{
				if ( RA != undefined )
				bolCall = RA;
			}
			else
			{
				this.AlreadyActivated.push(elementid);
			}
		}

		if (this.options.onActivate && bolCall)
			this.options.onActivate(this.currentAccordion) ;

//My Code Updates End Here.......................Orig Call Below.
  		  this._handleAccordion();
		}
	},
	//
	// Deactivate an active accordion
	//
	deactivate : function() {
		var options = {
		  duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end',
				scope: 'accordionAnimation'
			},
			scaleMode: {
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			},
			afterFinish: function() {
				this.showAccordion.setStyle({
					height: '0px',
					display: 'none'
				});
				this.showAccordion = null;
				this.animating = false;
			}.bind(this)
		};
    //options.merge(this.scaling);
	Object.extend(options, this.scaling);

    this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);

		new Effect.Scale(this.showAccordion, 0, options);
	},

  //
  // Handle the open/close actions of the accordion
  //
	_handleAccordion : function() {
		var options = {
			sync: true,
			scaleFrom: 0,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			scaleMode: {
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			}
		};
		//options.merge(this.scaling);
		Object.extend(options, this.scaling);

		this.effects.push(
			new Effect.Scale(this.currentAccordion, 100, options)
		);

		if (this.showAccordion) {
			this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);

			options = {
				sync: true,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal
			};
			//options.merge(this.scaling);
			Object.extend(options, this.scaling);

			this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options)
			);
		}

    new Effect.Parallel(this.effects, {
			duration: this.duration,
			queue: {
				position: 'end',
				scope: 'accordionAnimation'
			},
			beforeStart: function() {
				this.animating = true;
			}.bind(this),
			afterFinish: function() {
				if (this.showAccordion) {
					this.showAccordion.setStyle({
						display: 'none'
					});
				}
				$(this.currentAccordion).setStyle({
				  height: 'auto'
				});
				this.showAccordion = this.currentAccordion;
				this.animating = false;
			}.bind(this)
		});
	}
}
	
var DimsPortal = Class.create();
DimsPortal.prototype = {
	initialize: function (options) {

    	this.setOptions(options);

    	var sortables = $$('div.'+this.options.column);

    	sortables.each(function (sortable) {
     	try {

      		Sortable.create(sortable, {
		        containment: sortables,
		        constraint: false,
		        tag: 'div',
				ghosting:false,
		        only: this.options.block,
		        dropOnEmpty: true,
		        handle: this.options.handle,
		        hoverclass: this.options.hoverclass,onChange:function (contain) { this.elemfrom=contain.id;}.bind(this),
				onUpdate: function (container) {
			        if (!this.options.saveurl) {return;}

				  	idcolumn=container.id.substring(12,container.id.length);

				  	var url = this.options.saveurl;
			        var postBody = "col"+idcolumn+ '=';

					blocks = container.select( this.options.block);
			        postBody += blocks.pluck('id').join(',');

					if (idcolumn==1) this.urldata=postBody;
					else this.urldata+="&"+postBody;

					if (idcolumn==(sortables.length)) {
						while (this.urldata!=this.urldata.replace('block-','')){this.urldata=this.urldata.replace('block-','');};
						dims_xmlhttprequest_todiv("index-light.php","dims_op=refresh_blockportal&"+this.urldata,'',"debugblock");
					}
		        }.bind(this)
	      	});
	      }
	      catch (e) {}
	    }.bind(this));

    var blocks = $$('div.'+this.options.block);

    blocks.each(
		function (block) {
        	var content = block.select( this.options.content);
            var toggle = block.select( this.options.toggle);

			Event.observe(toggle, 'click', function (e) { Effect.toggle(content, 'Slide'); },false);
        }.bind(this)

    );

    //Event.observe(this.options.blocklistlink, 'click', this.displayBlockList.bindAsEventListener(this), false);

    //new Draggable(this.options.blocklist, {handle: this.options.blocklisthandle});

  },

  displayBlockList: function (e) {
    Effect.toggle(this.options.blocklist);
    Event.stop(e);
  },

  setOptions: function (options) {
    this.options = {
      dims: 'dims',
      column: 'dims-column',
      block: 'block',
      content: 'content',
      handle: 'handle',
      hoverclass: 'block-hover',
      toggle: 'block-toggle',
      blocklist: 'dims-column-block-list',
      blocklistlink: 'dims-block-list-link',
      blocklisthandle: 'block-list-handle',
	  elemfrom:'',
	  urldata:"",
      saveurl: ''
    }
    Object.extend(this.options, options || {});

  },

  applySettings: function (settings) {
	for (var container in settings) {
      settings[container].each(function (block) { $(container).appendChild($(block));});
    }

  }
}

