if (/msie/i.test (navigator.userAgent))
{
   document.nativeGetElementById = document.getElementById;
   document.getElementById = function(id)
   {
	   // Get element using native method
	   var elem = document.nativeGetElementById(id);
	   if (elem)
	   {
		   // If id match, return element
		   if (elem.attributes['id'].value == id)
		   {
			   return elem;
		   }
		   // Otherwise look for the right one
		   else
		   {
			   for (var i = 1; i < document.all[id].length; i++)
			   {
				   if (document.all[id][i].attributes['id'].value == id)
				   {
					   return document.all[id][i];
				   }
			   }
		   }
	   }
	   return null;
   }
}


function connectAs(site)
{
	site.submit();
}

/* 
	* Role : Change the image of the lock in rights gestion's page
	* Input : no input
	* Output : no output
	* Date : 24/12/2007
*/
function swapIt()
{
	swapImg=document.getElementById("cadenas");
	if (swapImg.src == cadenas_open.src) swapImg.src=cadenas_close.src;
	else swapImg.src=cadenas_open.src;
}

/* 
	* Role : Lock or unlock each radiobutton of the rights gestion form in the rights gestion's page
	* Input : no input
	* Output : no output
	* Date : 24/12/2007
*/
function changeLockStatus()
{
	swapIt();
	for ( var i = 0 ; i < document.rights_page.elements.length; i++ )
	{
		var elm = document.rights_page.elements[i];
		if ( elm.type == "radio" )
		{
			if (elm.disabled == false) elm.disabled = true;
			else elm.disabled = false;
		}
	}
	if (document.rights_page.Submit.disabled == false){
		document.rights_page.Submit.disabled = true;
		document.getElementById('btn_save_change').style.display = "none";
		document.getElementById('btn_save_change_off').style.display = "block";
		document.cadenas.src="images/picto_cadenas_close.gif"; 
	}else{
		document.rights_page.Submit.disabled = false;
		document.getElementById("btn_save_change").style.display = "block";
		document.getElementById("btn_save_change_off").style.display = "none";
		document.cadenas.src ="images/picto_cadenas_open.gif"; 
	}
}





/* 
	* Role : Calls the peopleUpdateStar.php script to star or unstar specified elements in the people list
	* Input : fig (HTML image) -> the star image to change
			  id (int) -> the id of the people to star or unstar
	* Output : no output
	* Date : 24/12/2007
*/
function StarUnstar(fig, id)
{
	el = document.people_form.elements['h'+fig];
	if (document[fig].src==starOn.src)
	{
		document[fig].src = starOff.src;
		el.value = "0";
		document[fig].title = 'Add to My Favorites';
	}
	else
	{
		document[fig].src = starOn.src;
		el.value = "1";
		document[fig].title = 'Remove from My Favorites';
	}
	xmlhttp.open("GET", "php/peopleUpdateStar.php?id="+id+"&starred="+el.value,true);
	xmlhttp.send(null);
}


/* 
	* Role : Called while page is loading, initialize star images in the people list view page
	* Input : srcStarOn (string) -> the path of starred image
			  srcStarOff (string) -> the path of unstarred image
	* Output : no output
	* Date : 24/12/2007
*/
function initialisation(srcStarOn, srcStarOff)
{
	starOn = new Image(16,15); 
	starOn.src = srcStarOn;
	starOff = new Image(16,15); 
	starOff.src = srcStarOff;
}

/* 
	* Role : Opens the popup who presents the page to add a relationship history line to a people
	* Input : id (int) -> the people id
		   type (char) -> the type of ops object concerned
	* Output : no output
	* Date : 24/12/2007
*/
function addRelationshipHistory(id,type,site_id) 
{
				var width = 750;
				var height = 450;
				var top = 10;
				var left = 10;
				popUpWindow('index.php?go=pages/rhNew.php&popup=1&id=' + id + '&site_id=' + site_id + '&entity_type=' + type,top,left,width,height);
	/*popup = open ('index.php?go=pages/rhNew.php&popup=1&id=' + id + "&entity_type=" + type, 'popup', 
				   'width=646,height=400,scrollbars=1, resizable=no, status=yes');*/
}
/* 
	* Role : Opens the popup who presents the page to add a degree to a people
	* Input : id (int) -> the people id
		   type (char) -> the type of ops object concerned
	* Output : no output
	* Date : 24/12/2007
*/
function addDegree(id,site) 
{
				var width = 750;
				var height = 450;
				var top = 10;
				var left = 10;
				//popUpWindow('index.php?go=pages/degreeNew.php&popup=1&id=' + id + '&site_id=' + site_id,top,left,width,height);
				popUpWindow('index.php?go=pages/degreeNew.php&popup=1&id=' + id + '&site=' + site,top,left,width,height);
}
/* 
	* Role : Opens the popup who presents the page to modify a degree to a people
	* Input : id (int) -> the people id
		   type (char) -> the type of ops object concerned
	* Output : no output
	* Date : 24/12/2007
*/
function modifyDegree(id,id_degree,site_id) 
{
				var width = 750;
				var height = 450;
				var top = 10;
				var left = 10;
				popUpWindow('index.php?go=pages/degreeNew.php&popup=1&id=' + id + '&id_degree=' + id_degree,top,left,width,height);
}
/* 
	* Role : Opens the popup who presents the page to add a consultant to a group
	* Input : id (int) -> the group id
		   type (char) -> the type of ops object concerned
	* Output : no output
	* Date : 24/12/2007
*/
function addConsultant(group) 
{
				var width = 750;
				var height = 450;
				var top = 10;
				var left = 10;
				popUpWindow('index.php?go=pages/consultantNew.php&popup=1&group=' + group,top,left,width,height);
}

/* 
	* Role : Opens the popup who presents the page to forward a people
	* Input : id (int) -> the people id
		   type (char) -> the type of ops object concerned
	* Output : no output
	* Date : 24/12/2007
*/
function forwardPeople(id_people,site_id,people_id) 
{
				var width = 750;
				var height = 450;
				var top = 10;
				var left = 10;
				popUpWindow('index.php?go=pages/peopleForward.php&popup=1&id_people=' + id_people + '&site_id=' + site_id + '&people_id=' + people_id,top,left,width,height)
	/*popup = open ('index.php?go=pages/rhNew.php&popup=1&id=' + id + "&entity_type=" + type, 'popup', 
				   'width=646,height=400,scrollbars=1, resizable=no, status=yes');*/
}
/* 
	* Role : Relode the current page to view all the files of a network
	* Input : id (int) -> the site id
		   type (char) -> the type of ops object concerned
	* Output : no output
	* Date : 24/12/2007
function exportFiles() 
{
	var id_site = document.exportSite.site.value;
	document.location.href = 'index.php?go=pages/export.php&site=' + id_site;
}
*/
function exportFiles() 
{
	var id_site = document.exportSite.site.value;
	document.location.href = 'index.php?go=pages/documents.php&site=' + id_site;
}

/* 
	* Role : rules the redirections on the people modification page
			 this scripts gives the right parameters to deploy the right block on this page (for example, to deploy the organization selection list)
	* Input : elmt (string) -> the name of the block to deploy
			  parent (string) -> the value to give to the parent form element
			  modify (bool) -> is it an adding or a modification on the people modification page ?
	* Output : no output
	* Date : 24/01/2008
*/
function go_modify_people(elmt, parent, modify, module)
{
	if (!parent || parent === undefined) parent = '0';
	switch (elmt)
	{
		case 'go' :
			document.modify_people.action = "index.php?go=pages/peopleSearchExecute.php#" + modify;
			break;
		case 'current_employer' :
			if (document.forms[0].elements['txt_current_employer'].value.length < 2)
			{
				alert ('Please fill in the restriction search');
				return;
			}
			document.modify_people.modify.value = elmt;
			document.modify_people.parent.value = parent;
			document.modify_people.divYpos.value = document.getElementById("current_employer_div").scrollTop;
			document.modify_people.action = "index.php?go=pages/peopleModify_" + module + ".php";
			break;
		case 'last_institution' :
			if (document.forms[0].elements['txt_last_institution'].value.length < 2)
			{
				alert ('Please fill in the restriction search');
				return;
			}
			document.modify_people.modify.value = elmt;
			document.modify_people.parent.value = parent;
			document.modify_people.divYpos.value = document.getElementById("last_institution_div").scrollTop;
			document.modify_people.action = "index.php?go=pages/peopleModify_" + module + ".php";
			break;
		case 'former_employer' :
			if (document.forms[0].elements['txt_former_employers'].value.length < 2)
			{
				alert ('Please fill in the restriction search');
				return;
			}
			document.modify_people.modify.value = elmt;
			document.modify_people.action = "index.php?go=pages/peopleModify_" + module + ".php#" + elmt;
			break;
		default :
			document.modify_people.modify.value = elmt;
			document.modify_people.action = "index.php?go=pages/peopleModify_" + module + ".php#" + elmt;
			break;
	}
	document.modify_people.submit();
}

/* 
	* Role : rules the redirections on the degree modification page
			 this scripts gives the right parameters to deploy the right block on this page (for example, to deploy the organization selection list)
	* Input : elmt (string) -> the name of the block to deploy
			  parent (string) -> the value to give to the parent form element
			  modify (bool) -> is it an adding or a modification on the people modification page ?
	* Output : no output
	* Date : 24/01/2008
*/

function go_modify_degree(elmt, parent, modify)
{
	if (!parent || parent === undefined) parent = '0';
	switch (elmt)
	{
		case 'last_institution' :
			if (document.forms[0].elements['txt_last_institution'].value.length < 2)
			{
				alert ('Please fill in the restriction search');
				return;
			}
			document.modify_people.modify.value = elmt;
			document.modify_people.parent.value = parent;
			document.modify_people.divYpos.value = document.getElementById("last_institution_div").scrollTop;
			document.modify_people.action = "index.php?go=pages/degreeNew.php";
			break;
		default :
			document.modify_people.modify.value = elmt;
			document.modify_people.action = "index.php?go=pages/degreeNew.php#" + elmt;
			break;
	}
	document.modify_people.submit();
}

/* 
	* Role : rules the redirections on the organizations modification page
			 this scripts gives the right parameters to deploy the right block on this page (for example, to deploy the parent organization selection list)
	* Input : elmt (string) -> the name of the block to deploy
			  parent (string) -> the value to give to the parent form element
	* Output : no output
	* Date : 24/01/2008
*/
function go_modify_organization(elmt, parent)
{
	if (!parent || parent === undefined) parent='0';
	switch (elmt)
	{
		case 'go' :
			document.modify_organization.action = "index.php?go=pages/organizationSearchExecute.php";
			break;
		case 'parent' :
			if (document.forms[0].elements['txt_parent'].value.length < 2)
			{
				alert ('Please fill in the restriction search');
				return;
			}
			document.modify_organization.modify.value = elmt;
			document.modify_organization.action = "index.php?go=pages/organizationModify_basic.php";
			break;
		default :
			document.modify_organization.modify.value = elmt;
			document.modify_organization.action = "index.php?go=pages/organizationModify_basic.php";
			break;
	}
	document.modify_organization.submit();
}

function go_modify_assignment(elmt, parent, module)
{
	if (!parent || parent===undefined) parent='0';
	switch (elmt)
	{
		case 'go' :
			document.modify_assignment.action = "index.php?go=pages/peopleSearchExecute.php";
			break;
		case 'organization' :
			if (document.forms[0].elements['txt_organization'].value.length < 2)
			{
				alert ('Please fill in the restriction search');
				return;
			}
			document.modify_assignment.modify.value = elmt;
			document.modify_assignment.parent.value = parent;
			document.modify_assignment.divYpos.value = document.getElementById("organization_div").scrollTop;
			document.modify_assignment.action = "index.php?go=pages/assignmentModify_"+module+".php";
			break;
		default :
			document.modify_assignment.modify.value = elmt;
			document.modify_assignment.action = "index.php?go=pages/assignmentModify_"+module+".php#"+elmt;
			break;
	}
	document.modify_assignment.submit();
}

function go_modify_site()
{
	document.modifySite.action = "index.php?go=pages/siteModify.php#";
	document.modifySite.submit();
}

function go_import_people()
{
	document.import_people.action = "index.php?go=pages/adminImportPeople.php#";
	document.import_people.submit();
}


/* 
	* Role : submit the people modification form
	* Input : flag (bool) -> shall we validate and redirect to the update page ?
		   ancre (string) -> new anchor's name'
	* Output : no output
	* Date : 24/01/2008
*/
function submitFormFiles(flag,type)
{
	//alert(flag+' - '+ type);	
	if (flag) {
		if(type == 'A') document.modify_assignment.action = "php/filesUpdate.php";
		if(type == 'O') document.modify_organization.action = "php/filesUpdate.php";
		if(type == 'P') document.modify_people.action = "php/filesUpdate.php";
	}
	if(type == 'A') document.modify_assignment.submit();
	if(type == 'O') document.modify_organization.submit();
	if(type == 'P') document.modify_people.submit();
}

/* 
	* Role : submit the people modification form
	* Input : flag (bool) -> shall we validate and redirect to the update page ?
		   ancre (string) -> new anchor's name'
	* Output : no output
	* Date : 24/01/2008
*/
function submitFormPeople(flag, ancre)
{
	if (flag) document.modify_people.action = "php/peopleUpdate.php";
	document.modify_people.ancre.value = ancre;
	document.modify_people.submit();
}
/* 
	* Role : submit the people modification form
	* Input : flag (bool) -> shall we validate and redirect to the update page ?
		   ancre (string) -> new anchor's name'
	* Output : no output
	* Date : 24/01/2008
*/
function submitFormPeopleAssignments(flag)
{
	if (flag) document.assignments_people_form.action = "php/peopleAssignmentsInsert.php";
	if (flag == 3) flag = 0;
	document.assignments_people_form.type.value = flag;
	document.assignments_people_form.submit();
}

/* 
	* Role : submit the organizations modification form
	* Input : flag (bool) -> shall we validate and redirect to the update page ?
			  ancre (string) -> new anchor's name'
	* Output : no output
	* Date : 24/01/2008
*/
function submitFormOrganization(flag)
{
	if (flag) document.modify_organization.action = "php/organizationUpdate.php";
	document.modify_organization.submit();
}

/* 
	* Role : submit the groups modification form
	* Input : flag (bool) -> shall we validate and redirect to the update page ?
			  ancre (string) -> new anchor's name'
	* Output : no output
	* Date : 24/01/2008
*/
function submitFormGroups(flag)
{
	if (flag) document.modify_group.action = "php/groupUpdate.php";
	document.modify_group.submit();
}

/* 
	* Role : submit the sources modification form
	* Input : flag (bool) -> shall we validate and redirect to the update page ?
			  ancre (string) -> new anchor's name'
	* Output : no output
	* Date : 24/01/2008
*/
function submitFormSources(flag)
{
	if (flag) document.modify_organization.action = "php/sourceUpdate.php";
	document.modify_organization.submit();
}

function submitFormPeopleMerge(flag)
{
	if (flag) document.merge_people.action = "php/peopleMergeExecute.php";
	document.merge_people.submit();
}

function submitFormSourceMerge(flag)
{
	if (flag) document.merge_source.action = "php/sourceMergeExecute.php";
	document.merge_source.submit();
}

function submitFormPracticeMerge(flag)
{
	if (flag) document.merge_practice.action = "php/practiceMergeExecute.php";
	document.merge_practice.submit();
}
function submitFormOrganizationMerge(flag)
{
	if (flag) document.merge_organization.action = "php/organizationMergeExecute.php";
	document.merge_organization.submit();
}

function submitFormAssignment(flag)
{
	if (flag) document.modify_assignment.action = "php/assignmentUpdate.php";
	document.modify_assignment.submit();
}

function submitFormAssignmentsAdvancedSearch()
{
	document.advanced_search.action = "pages/assignmentsSearch.php";
	document.advanced_search.submit();
}


function submitFormSite(flag)
{
	if (flag) {
		document.modifySite.action = "php/siteNoSearchUpdate.php";
	}
	document.modifySite.submit();
}

function deleteFiles(id_files, id, type) 
{
	//alert(id_files+" - "+id+" - "+type);
	document.location.href = "php/filesDelete.php?id_files="+id_files+"&id="+id+"&type="+type;
}
function deletePeopleDoc(docType, id_people) 
{
	/* Send the AJAX request */
	xmlhttp = getXmlHttp();
	xmlhttp.open("GET", "php/peopleDocumentDelete.php?id_people="+id_people+"&docType="+docType, true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4 && xmlhttp.responseText) 
		{
			alert(xmlhttp.responseText);
			window.location.reload();
		}
	}
	xmlhttp.send(null);
}

function delete_doc_assignment(doc)
{
	document.modify_assignment.delfile.value = doc;
	submitForm(0);
}

function deleteOrganizationDoc(docType, id_organization) 
{
	/* Send the AJAX request */
	xmlhttp = getXmlHttp();
	xmlhttp.open("GET", "php/organizationDocumentDelete.php?id_organization="+id_organization+"&docType="+docType, true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4 && xmlhttp.responseText) 
		{
			alert(xmlhttp.responseText);
			window.location.reload();
		}
	}
	xmlhttp.send(null);
}
function deleteSiteDoc(docType, id_site) 
{
	/* Send the AJAX request */
	xmlhttp = getXmlHttp();
	xmlhttp.open("GET", "php/siteDocumentDelete.php?id_site="+id_site+"&docType="+docType, true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4 && xmlhttp.responseText) 
		{
			alert(xmlhttp.responseText);
			window.location.reload();
		}
	}
	xmlhttp.send(null);
}
function deleteNoSearchOrganization(id_site, id_organization) 
{
	/* Send the AJAX request */
	xmlhttp = getXmlHttp();
	xmlhttp.open("GET", "php/siteNoSearchDelete.php?id_site="+id_site+"&id_organization="+id_organization, true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4 && xmlhttp.responseText) 
		{
			alert(xmlhttp.responseText);
			window.location.href='index.php?go=pages/siteModify.php&id='+id_site;
		}
	}
	xmlhttp.send(null);
}
function deleteInvoiceDoc(id_invoice) 
{
	/* Send the AJAX request */
	xmlhttp = getXmlHttp();
	xmlhttp.open("GET", "php/invoiceDocumentDelete.php?id_invoice="+id_invoice, true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4 && xmlhttp.responseText) 
		{
			alert(xmlhttp.responseText);
			window.location.reload();
		}
	}
	xmlhttp.send(null);
}
function setSelect(formelem) 
{
	origine = popup.document.forms[0].elements[formelem];
	dest = window.document.forms[0].elements[formelem];
	for(var x=0; x < origine.options.length; x++)
	{
		  label = origine.options[x].text;
		  value = origine.options[x].value;
		  dest.options[x] = new Option(label, value);
		  dest.length = x+1;
	}
}

function swapIt(swapImgId, what)
{
	swapImg=document.getElementById('img'+swapImgId);
	switch (what)
	{
		case 'onClick':
			visibilite(swapImgId);
			if (swapImg.src == img_down_on.src) swapImg.src=img_right_on.src;
			else swapImg.src=img_down_on.src;
			break;
		case 'onMouseOut':		
			if (swapImg.src == img_down_on.src) swapImg.src=img_down_off.src;
			else swapImg.src=img_right_off.src;
			break;
		case 'onMouseIn':
			if (swapImg.src == img_down_off.src) swapImg.src=img_down_on.src;
			else swapImg.src=img_right_on.src;
	}
}

function submitOnEnter(type, field, evt, elmt,module) 
{
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if (keyCode != 13) return true;
	else 
	{
		if(type == 'people') go_modify_people(elmt,'','',module);
		if(type == 'degree') go_modify_degree(elmt,'','');
		else if(type == 'organization') go_modify_organization(elmt,'','',module);
		return false;
	}
}

function submitOnEnterAssignment (field, evt, elmt) 
{
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if (keyCode != 13) return true;
	else 
	{
		go_modify_assignment(elmt);
		return false;
	}
}

/* 
	* Role : in the people modification form, disable dob fields if ayb field is filled, and contrary
	* Input : no input
	* Output : no output
	* Date : 24/02/2008
*/
function alternateDobAyb()
{
	var ayb = document.getElementById("ayb");
	var dob_dd = document.getElementById("dob_dd");
	var dob_mm = document.getElementById("dob_mm");
	var dob_yy = document.getElementById("dob_yy");
	
	if(ayb && dob_dd && dob_mm && dob_yy)
	{
		if(dob_dd.value == 0 && dob_mm.value == 0 && (dob_yy.value == "" || dob_yy.value == "0000") && ayb.value != "")
		{
			ayb.disabled = false;
			dob_dd.disabled = true;
			dob_mm.disabled = true;
			dob_yy.disabled = true;
		}
		else if((dob_dd.value != 0 ||dob_mm.value != 0 || dob_yy.value != "") && ayb.value == "") 
		{
			ayb.disabled = true;
			dob_dd.disabled = false;
			dob_mm.disabled = false;
			dob_yy.disabled = false;
		}
		else
		{
			ayb.disabled = false;
			dob_dd.disabled = false;
			dob_mm.disabled = false;
			dob_yy.disabled = false;
		}
	}
}


/* 
	* Role : launch the script to delete a relationship history line
	* Input : idHistoryLine (int) -> the concerned history line id
	* Output : no output
	* Date : 27/02/2008
*/
function deleteRelationshipHistoryLine(idHistoryLine)
{
	if(confirmation('delete'))
	{
		if(idHistoryLine)
		{
			xmlhttp = getXmlHttp();
			xmlhttp.open("GET", "php/rhDelete.php?id="+idHistoryLine, true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4) 
				{
					window.location.reload();
				}
			}
			xmlhttp.send(null);
		}
		else alert("Error ! Bad id.");
	}
}

/* 
	* Role : launch the script to delete a degree line
	* Input : idDegreeLine (int) -> the concerned degree line id
	* Output : no output
	* Date : 27/02/2008
*/
function deleteDegree(idDegreeLine)
{
	if(confirmation('delete'))
	{
		if(idDegreeLine)
		{
			xmlhttp = getXmlHttp();
			xmlhttp.open("GET", "php/degreeDelete.php?id="+idDegreeLine, true);
			xmlhttp.onreadystatechange=function() 
			{
				if (xmlhttp.readyState==4) 
				{
					window.location.reload();
				}
			}
			xmlhttp.send(null);
		}
		else alert("Error ! Bad id.");
	}
}

/* 
	* Role : launch the script replace a word in people current_position
	* Input : no input
	* Output : no output
	* Date : 15/03/2008
*/
function replaceTextInCurrentPosition()
{
	var button = document.getElementById('cpreplacebutton');
	var needle = document.getElementById('needle').value;
	var replacement = document.getElementById('replacement').value;
	
	if(needle == "" && replacement == "") alert("Please fill fields with some text");
	else
	{
		button.value = "Please wait...";
		button.disabled = true;
		xmlhttp = getXmlHttp();
		xmlhttp.open("GET", "php/currentPositionReplacement.php?needle="+needle+"&replacement="+replacement, true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				button.disabled = false;
				button.value = "GO";
				alert(needle + " has been successfuly replaced by " + replacement + " in every people current position.");
			}
		}
		xmlhttp.send(null);
	}
}


/* 
	* Role : launch the script replace the words in people current_position
	* Input : no input
	* Output : no output
	* Date : 15/03/2008
*/
function replaceCurrentPosition()
{
	var please_wait = document.getElementById('please_wait');
	var replaceIt = document.getElementById('replaceIt');
	var needle = document.getElementById('currentPositionInput').value;
	var replacement = document.getElementById('positionInput').value;
	
	if(needle == "" && replacement == "") alert("Please fill fields with some text");
	else
	{
		please_wait.style.display = 'block';
		replaceIt.style.display = 'none';
		xmlhttp = getXmlHttp();
		xmlhttp.open("GET", "php/currentPositionReplacement.php?needle="+needle+"&replacement="+replacement, true);
		xmlhttp.onreadystatechange=function() 
		{
			if (xmlhttp.readyState==4) 
			{
				alert(needle + " has been successfuly replaced by " + replacement + " in every people current position.");
				please_wait.style.display = 'none';
				replaceIt.style.display = 'block';
			}
		}
		xmlhttp.send(null);
	}
}

/* 
	* Role : launch an autocompletion request
	* Input : elmt (string) -> the name of the element to auto complete
		    q (string) -> the value entered in the form element
	* Output : no output
	* Date : 24/03/2008
*/
function htmlentities(text) {
	text = text.replace(/&/g,'%26');
//	text = text.replace(/+/g,'%2B');
/*	text = text.replace(/</g, "&lt;");
	text = text.replace(/>/g, "&gt;"); */
	return text;
}


function sendRequest(elmt, q, exclude, suggest_only)
{
	document.getElementById(elmt+'Results').style.display='none';
	document.getElementById(elmt).value='';
	
	xmlhttp = getXmlHttp();
	xmlhttp.open('get', 'php/suggest.php?'+elmt+'='+htmlentities(q)+'&exclude='+(exclude)+'&suggest_only='+suggest_only);   
	xmlhttp.onreadystatechange = 
		function ()
		{
			if (xmlhttp.readyState == 4)
			{  
				var response = xmlhttp.responseText;
				if (response)
				{
					agent = navigator.userAgent.toLowerCase();

					document.getElementById(elmt+"Results").innerHTML = response;
					document.getElementById(elmt+'Results').style.display='block';
					if (agent.indexOf("msie") != -1)
					{
						intLeft = getOffsetLeft(document.getElementById(elmt+'Input'))+1;
						intHeight  = document.getElementById(elmt+'Input').offsetHeight;
						intTop  = getOffsetTop(document.getElementById(elmt+'Input')) + intHeight + 2;
						//intTop  = getOffsetTop(document.getElementById(elmt+'Input')) + 2;
					}
					else
					{
						intLeft = document.getElementById(elmt+'Input').offsetLeft+1;
						intHeight  = document.getElementById(elmt+'Input').offsetHeight;
						intTop  = document.getElementById(elmt+'Input').offsetTop + intHeight + 2;
						//intTop  = document.getElementById(elmt+'Input').offsetTop + 2;
					}
											
					document.getElementById(elmt+'Results').style.left = intLeft + 'px';
					document.getElementById(elmt+'Results').style.top = intTop + 'px';
					
				}
				else document.getElementById(elmt+'Results').s
			}
		}
	xmlhttp.send(null);
}   

function sendRequestPeople(elmt, q, exclude, suggest_only)
{
	if(q.length>2){
		document.getElementById(elmt+'Results').style.display='none';
		document.getElementById(elmt).value='';
		
		
		agent = navigator.userAgent.toLowerCase();
		document.getElementById(elmt+"Results").innerHTML = "<table class='suggestTable' width=100%><tr onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='suggestTable'\"><td>Searching</td></tr>\n</table>";
		document.getElementById(elmt+'Results').style.display='block';
		if (agent.indexOf("msie") != -1)
		{
			intLeft = getOffsetLeft(document.getElementById(elmt+'Input'))+1;
			intHeight  = document.getElementById(elmt+'Input').offsetHeight;
			intTop  = getOffsetTop(document.getElementById(elmt+'Input')) + intHeight + 2;
		}
		else
		{
			intLeft = document.getElementById(elmt+'Input').offsetLeft+1;
			intHeight  = document.getElementById(elmt+'Input').offsetHeight;
			intTop  = document.getElementById(elmt+'Input').offsetTop + intHeight + 2;
			//intTop  = document.getElementById(elmt+'Input').offsetTop + 2;
		}
								
		document.getElementById(elmt+'Results').style.left = intLeft + 'px';
		document.getElementById(elmt+'Results').style.top = intTop + 'px';
		
		xmlhttp = getXmlHttp();
		xmlhttp.open('get', 'php/suggest.php?'+elmt+'='+htmlentities(q)+'&exclude='+(exclude)+'&suggest_only='+suggest_only);   
		xmlhttp.onreadystatechange = 
			function ()
			{
				if (xmlhttp.readyState == 4)
				{  
					var response = xmlhttp.responseText;
					
					var elem = response.split('||');
					
					if(response){
						var text_retour = "<table class='suggestTable' width=100%>";
						var sous_elem = "";
						for(i=0;i<elem.length;i++)
						{
							sous_elem = elem[i].split('|');
							if(i!=20){
								text_retour += "<tr onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='suggestTable'\"><td><a href='javascript:;' onclick=\"updateInputsSumbit('keywords_people', '" + sous_elem[0] + "', '" + sous_elem[1] + "')\">" + sous_elem[2] + "</a></td></tr>";
							}else{
								text_retour += "<tr onMouseOver=\"this.className='highlight'\" onMouseOut=\"this.className='suggestTable'\"><td><a href='javascript:;' onclick=\"document.form1.submit()\">More results >>></a></td></tr>";
							}
						}
						
						text_retour += "</table>";
						
						response = text_retour;
					
						if (response)
						{
							agent = navigator.userAgent.toLowerCase();
							
							document.getElementById(elmt+"Results").innerHTML = response;
							document.getElementById(elmt+'Results').style.display='block';
							if (agent.indexOf("msie") != -1)
							{
								intLeft = getOffsetLeft(document.getElementById(elmt+'Input'))+1;
								intHeight  = document.getElementById(elmt+'Input').offsetHeight;
								intTop  = getOffsetTop(document.getElementById(elmt+'Input')) + intHeight + 2;
							}
							else
							{
								intLeft = document.getElementById(elmt+'Input').offsetLeft+1;
								intHeight  = document.getElementById(elmt+'Input').offsetHeight;
								intTop  = document.getElementById(elmt+'Input').offsetTop + intHeight + 2;
							}
													
							document.getElementById(elmt+'Results').style.left = intLeft + 'px';
							document.getElementById(elmt+'Results').style.top = intTop + 'px';
							
							
						}
						else
						{
							document.getElementById(elmt+'Results').s
							document.getElementById(elmt+'Results').style.display='none';
						}
					}
					else
					{
						document.getElementById(elmt+'Results').s
						document.getElementById(elmt+'Results').style.display='none';
					}
				}
			}
			
		xmlhttp.send(null);
	}
} 
/* 
	* Role : launch an autocompletion request for choosing consultant
	* Input : elmt (string) -> the name of the element to auto complete
		    q (string) -> the value entered in the form element
	* Output : no output
	* Date : 24/03/2008
*/
function sendRequestConsultant(elmt, q, group, groupSite)
{
	document.getElementById(elmt+'Results').style.display='none';
	document.getElementById(elmt).value='';
	
	xmlhttp = getXmlHttp();
	xmlhttp.open('get', 'php/suggest.php?'+elmt+'='+q+'&group='+group+'&groupSite='+groupSite);   
	xmlhttp.onreadystatechange = 
		function ()
		{
			if (xmlhttp.readyState == 4)
			{  
				var response = xmlhttp.responseText;
				if (response)
				{
					agent = navigator.userAgent.toLowerCase();

					document.getElementById(elmt+"Results").innerHTML = response;
					document.getElementById(elmt+'Results').style.display='block';
					if (agent.indexOf("msie") != -1)
					{
						intLeft = getOffsetLeft(document.getElementById(elmt+'Input'))+1;
						intHeight  = document.getElementById(elmt+'Input').offsetHeight;
						intTop  = getOffsetTop(document.getElementById(elmt+'Input')) + intHeight + 2;
						//intTop  = getOffsetTop(document.getElementById(elmt+'Input')) + 2;
					}
					else
					{
						intLeft = document.getElementById(elmt+'Input').offsetLeft+1;
						intHeight  = document.getElementById(elmt+'Input').offsetHeight;
						intTop  = document.getElementById(elmt+'Input').offsetTop + intHeight + 2;
						//intTop  = document.getElementById(elmt+'Input').offsetTop + 2;
					}
											
					document.getElementById(elmt+'Results').style.left = intLeft + 'px';
					document.getElementById(elmt+'Results').style.top = intTop + 'px';
					
				}
				else document.getElementById(elmt+'Results').s
			}
		}
	xmlhttp.send(null);
} 

/* 
	* Role : fill the concerned field with value selected by autocompletion system
	* Input : champ (string) -> the name of the field
		    id (string) -> the mysql id of the item
		    valeur (string) -> the text value of the item
	* Output : no output
	* Date : 24/03/2008
*/
function updateInputs(champ, id, valeur)
{
	document.getElementById(champ).value = id;
	document.getElementById(champ+'Input').value = valeur;
	//alert('value : '+document.getElementById(champ).value);
	document.getElementById(champ+'Results').style.display='none';
	if(champ == 'from_organization'){
		document.getElementById('into_organization').value = 0;
		document.getElementById('into_organizationInput').value = '';
		if(id == 0)
			document.getElementById('into_organizationInput').disabled = true;
		if(id != 0)
			document.getElementById('into_organizationInput').disabled = false;
	}
}

/* 
	* Role : fill the concerned field with value selected by autocompletion system And Submit the form
	* Input : champ (string) -> the name of the field
		    id (string) -> the mysql id of the item
		    valeur (string) -> the text value of the item
	* Output : no output
	* Date : 24/03/2008
*/
function updateInputsSumbit(champ, id, valeur)
{
	document.getElementById(champ).value = id;
	document.getElementById(champ+'Input').value = valeur;
	document.getElementById(champ+'Results').style.display='none';
	if(champ == 'from_organization'){
		document.getElementById('into_organization').value = 0;
		document.getElementById('into_organizationInput').value = '';
		if(id == 0)
			document.getElementById('into_organizationInput').disabled = true;
		if(id != 0)
			document.getElementById('into_organizationInput').disabled = false;
	}
	document.getElementById('form1').submit();
}

/* 
*/
function hide_suggest(elmt)
{
	document.getElementById('keywords_'+elmt+'Results').style.display='none';
}

/* 
	* Role : in people advanced search form, unlock subpractices field when practices field has a selected value
	* Input : practice (string) -> the practice selected
	* Output : no output
	* Date : 24/03/2008
*/
function activateSubpractice(practice)
{
	var subpracticesField = document.getElementById('theSubpractice');
	subpracticesField.options.length=0;
	try { subpracticesField.add(document.createElement('option'), 1); }
	catch(e) { subpracticesField.add(document.createElement('option'), null); }

	xmlhttp = getXmlHttp();
	xmlhttp.open('get', 'php/getSubpractices.php?practice='+practice);  
	xmlhttp.onreadystatechange = 
		function ()
		{
			if (xmlhttp.readyState == 4)
			{  
				var response = xmlhttp.responseXML;
				if (response)
				{
					var subpractices = response.getElementsByTagName('subpractice');
					for (var i=0; i < subpractices.length; ++i) 
					{
						var subpracticeElement = document.createElement('option');
						subpracticeElement.value = subpractices[i].getElementsByTagName('id_subpractice')[0].firstChild.data;
						subpracticeElement.text = subpractices[i].getElementsByTagName('title')[0].firstChild.data;
						try { 
							subpracticesField.add(subpracticeElement, 1);
						}
						catch(e) { 
							subpracticesField.add(subpracticeElement, null);
						}
					}
				}
			}
		}
	xmlhttp.send(null);
}

/* 
	* Role : in people advanced search form, unlock and fill countries field when regional_location field has a selected value
	* Input : regionalLocation (string) -> the regional location selected
	* Output : no output
	* Date : 24/03/2008
*/
function activateCountry(regionalLocation)
{
	var countriesField = document.getElementById('theCountry');
	countriesField.options.length=0;
	try { countriesField.add(document.createElement('option'), 1); }
	catch(e) { countriesField.add(document.createElement('option'), null); }

	xmlhttp = getXmlHttp();
	xmlhttp.open('get', 'php/getCountries.php?regionalLocation='+regionalLocation);  
	xmlhttp.onreadystatechange = 
		function ()
		{
			if (xmlhttp.readyState == 4)
			{  
				var response = xmlhttp.responseXML;
				if (response)
				{
					var countries = response.getElementsByTagName('country');
					for (var i=0; i < countries.length; ++i) 
					{
						var countryElement = document.createElement('option');
						countryElement.value = countries[i].getElementsByTagName('id_country')[0].firstChild.data;
						countryElement.text = countries[i].getElementsByTagName('name')[0].firstChild.data;
						try { 
							countriesField.add(countryElement, 1);
						}
						catch(e) { 
							countriesField.add(countryElement, null);
						}
					}
				}
			}
		}
	xmlhttp.send(null);
}

/* 
	* Role : in peaople advanced search form, reload the page with the specified redirection
	* Input : elmt (string) -> the redirection instruction
	* Output : no output
	* Date : 21/03/2011
*/
function go_search_people(elmt)
{
	switch (elmt)
	{
		case 'go' :
			document.advanced_search.action = "index.php?go=pages/peopleOpen.php";
			break;
		default :
			document.advanced_search.search.value = elmt;
			break;
	}
	document.advanced_search.submit();
}

/* 
	* Role : in assignments advanced search form, reload the page with the specified redirection
	* Input : elmt (string) -> the redirection instruction
	* Output : no output
	* Date : 19/04/2008
*/
function go_search_assignment(elmt)
{
	switch (elmt)
	{
		case 'save' :
			document.advanced_search.action = "index.php?go=people/assignments_research_new.php";
			break;
		case 'go' :
			document.advanced_search.action = "index.php?go=pages/assignmentsOpen.php";
			break;
		default :
			document.advanced_search.search.value = elmt;
			break;
	}
	document.advanced_search.submit();
}

function displayPeopleAdvancedOptions(theCheckbox)
{
	if(theCheckbox.checked == 0) document.getElementById("peopleAdvancedOptions").style['visibility'] = "hidden";
	else document.getElementById("peopleAdvancedOptions").style['visibility'] = "visible";
}
/* 
	* Role : submit the import people form
	* Input : flag (bool) -> shall we validate and redirect to the import page ?
	* Output : no output
	* Date : 17/12/2008
*/
function submitFormImportPeople(flag)
{
	if (flag) document.import_people.action = "php/adminImportPeopleExecute.php";
	document.import_people.submit();
}
/* 
	* Role : submit the import organizations form
	* Input : flag (bool) -> shall we validate and redirect to the import page ?
	* Output : no output
	* Date : 17/12/2008
*/
function submitFormImportOrganizations(flag)
{
	if (flag) document.import_organizations.action = "php/adminImportOrganizationsExecute.php";
	document.import_organizations.submit();
}
