var bool2 = false;
var currentField = "textarea";
var selectionSeparator = "--$$$$--";
var tripleIDSeparator = "~~$$$$~~";
var allChecked = true;
var prems=true;


function disableInput(form,fieldName,val){
	var fieldToHandle = fieldName
	var liste = null; 
	 for (var j=0; j<form.getElementsByTagName("select").length; j++ ) {
		liste = form.getElementsByTagName("select")[j];
		if (liste.name == "field")
			for ( var k=0; k<liste.options.length; k++)
				if (liste.options[k].value == fieldToHandle)
					if(val == "true"){
						liste.options[k].setAttribute('disabled',"disabled");
						liste.options[k].disabled = "disabled";
						}
					else{
						liste.options[k].removeAttribute('disabled');
						liste.options[k].disabled = null;
						}
	}
}	

function removeField (fieldName){  
	form=getFieldId('frm');
	disableInput(form,fieldName,"false");
   	var tmp = "field"+fieldName;
    var tmp1 ="value"+fieldName;
    var tmp2 = "button"+fieldName;
	var tmp4="list"+fieldName;
	
	
	getFieldId(tmp).style.display="none";
	getFieldId(tmp1).style.display="none";
	getFieldId(tmp1).setAttribute("value","");
	getFieldId(tmp1).value="";
	getFieldId(tmp2).style.display="none";
	if(getFieldId(tmp4))
	getFieldId(tmp4).style.display="none";
}

function getField (fieldName) {
form=getFieldId('frm')
  if (!document.all)
    return form[fieldName];

  else  // IE has a bug not adding dynamically created field 
        // as named properties so we loop through the elements array 
    for (var e = 0; e < form.elements.length; e++)
      if (form.elements[e].name == fieldName)
        return form.elements[e];
  return null;
} 

function getFieldId (id) {
	 if (document.getElementById)
    {
        // this is the way the standards work
        var obj = document.getElementById(id);
    }
    else if (document.all)
    {
        // this is the way old msie versions work
        var obj = document.all[id];
    }
    else if (document.layers)
    {
        // this is the way nn4 works
        var obj = document.layers[id];
    }
    return obj
} 

function showHideListButton(paf){
//reinit values for suggest tool
CACHED = [];
sel_id = -1;

var change = getFieldId("fieldList");
var val = change.options[change.selectedIndex].value;

	elt=getFieldId('sugImg');
	if (val != "taxonName" && val!= "genus" && val != "family" && val!= "country" && val!="higherTaxon" && val!="commonName"){
		elt.style.backgroundColor = "#ccc";
		onOff = 'OFF'	
		document.getElementById("searchresults").style.display = "none";
	}
	else {elt.style.backgroundColor = "transparent"; onOff = "ON";}
	
	title= elt.title.split(":")[0]+":"+onOff;
	elt.title=title;
	elt.setAttribute('title',title);
		

	if(val == "institutionId" || val == "collectionId" || val =="family" || val =="country"){
		getFieldId("dragDropList").disabled="none";
		getFieldId("dragDropList").removeAttribute('disabled');
		getFieldId("dragDropList").style.color="#000";
	}
	else{
		getFieldId("dragDropList").disabled="disabled";
		getFieldId("dragDropList").setAttribute('disabled',"disabled");
		getFieldId("dragDropList").style.color="#ccc";
	}
	if(val.search("date") != -1){
		getFieldId("dateHelpInfo").disabled="none";
		getFieldId("dateHelpInfo").removeAttribute('disabled');}
	else{
		getFieldId("dateHelpInfo").disabled="disabled";
		getFieldId("dateHelpInfo").setAttribute('disabled',"disabled");}
}    
   
function displayList(){
	currentField = "textarea"
	var fieldName = getField("field");
	fieldName = fieldName.value;
	var page;
	if (fieldName == "institutionId" || fieldName == "collectionId"  )
		display = true;
	else
		display = false;
	if (display)
		window.open('/toto/search/units/popup/openPopup/'+fieldName,'List', 'resizable=yes, scrollbars=yes, toolbar=no, status=no, width=300, height=300, center');
	}

function displayDateHelp(text){
  if(bool2==false && getFieldId('fieldList').value.indexOf('date') != -1) {
  document.getElementById("dateHelpInfoText").style.visibility="visible"; 
  document.getElementById("dateHelpInfoText").innerHTML = text; 
  bool2=true;
  }
}

function cache2(){
document.getElementById("dateHelpInfoText").style.visibility="hidden"; 
bool2 = false;
}



function enableRecordBasis(){
	var checkbx = getFieldId("record_basis_flag");
	var records = getFieldId("record_basis");
	if ( ! checkbx.checked){
		records.setAttribute('disabled',"disabled");
		records.disabled = "disabled";
	}
	else{
		records.removeAttribute('disabled');
		records.disabled = null;
	}
}




function refineQuery(box,tosee){//box=page en cours
if (box=="commonName")box="commonBox";
if (box.indexOf('Box')==-1) box=box+"Box";

var liste = document.getElementsByName(box);
//  alert(box);
	var selection =[];
	var s = 0;
	for (var k=0; k<liste.length;k++){
		if (liste[k].checked){
			val = liste[k].value
			if (val.indexOf('<b>') != -1)
				val = (val.split('<b>'))[0]
			val = val.split("/");
	        val = val.join("%2F");
	        val = val.split(",");
	        val = val.join("%2C");
	        val = val.split("(");
	        val = val.join("~$par$~");
	        val = val.split(")");
	        val = val.join("~$parf$~");
			selection[s] = val;
			s ++;
		}
	}
	var form = getFieldId("form");
	var boxField = getFieldId("box");
	boxField.setAttribute('value',box);
    boxField.value=box;	

	boxField = getFieldId("tosee");
	boxField.setAttribute('value',tosee);
    boxField.value=tosee;	
   
	form.action="/toto/search/units/preview/refineQuery/";
	selectionStr = selection.join(selectionSeparator);
	var fieldName = getFieldId("listStr");
	fieldName.setAttribute('value',selectionStr);
    fieldName.value=selectionStr;	

	
	
	if (s > 0 && liste.length>s)
		form.submit();
	else{
		var boxField = getFieldId("box");
		boxField.setAttribute('value',tosee);
    	boxField.value=tosee;
		form.action="/toto/search/units/preview/see/";
			form.submit();
	}
// 	else
// 	alert("Check at least one box");
}

function searchForMatch(box){
	var liste = document.getElementsByName(box);
	var s = 0;
	var formu = getFieldId("form");
	for (var k=0; k<liste.length;k++){
		if (liste[k].checked){
		s++;
		}
		if (s>0) break;
}
	if (s > 0)
		{displayLoadingGif();
		formu.submit();}
	else
		alert("Check at least one box");
}


function searchNames(box){
	var liste = document.getElementsByName(box);
	var selection =[];
	var s = 0;
	for (var k=0; k<liste.length;k++){
		if (liste[k].checked){
			val = liste[k].value
			if (val.indexOf('<b>') != -1)
				val = (val.split('<b>'))[0]
			val = val.split("/");
	        val = val.join("%2F");
	        val = val.split(",");
	        val = val.join("%2C");
	        val = val.split("(");
	        val = val.join("~$par$~");
	        val = val.split(")");
	        val = val.join("~$parf$~");
			selection[s] = val;
			s ++;
		}
	}
    
    var form = getFieldId("form");
	var boxField = getFieldId("box");
	boxField.setAttribute('value',box);
    boxField.value=box;	
    
	form.action="/toto/search/units/syncon/search/"
	selectionStr = selection.join(selectionSeparator);
	var fieldName = getFieldId("listStr");
	fieldName.setAttribute('value',selectionStr);
   fieldName.value=selectionStr;	
	
	if (s > 0)
		form.submit();
	else
	alert("Check at least one box");
}

function searchNamesConcept(){
	var liste = document.getElementsByTagName('input');
	var selection =[];
	var notselection=[];
	var s = 0;var n=0;
	for (var k=0; k<liste.length;k++){
		if (liste[k].checked && liste[k].name.indexOf('rel_') ==-1 && liste[k].name.indexOf('refBox') ==-1 && liste[k].type =="checkbox"){
			val = liste[k].value
			if (val.indexOf('<b>') != -1)
				val = (val.split('<b>'))[0]
			val = val.split("/");
	        val = val.join("%2F");
	        val = val.split(",");
	        val = val.join("%2C");
	        val = val.split("(");
	        val = val.join("~$par$~");
	        val = val.split(")");
	        val = val.join("~$parf$~");
			selection[s] = val;
			s ++;
		}else{
			if (!liste[k].checked && liste[k].name.indexOf('rel_') ==-1 && liste[k].name.indexOf('refBox') ==-1 && liste[k].type =="checkbox"){
			val = liste[k].value
			if (val.indexOf('<b>') != -1)
				val = (val.split('<b>'))[0]
				val = val.split("/");
				val = val.join("%2F");
				val = val.split(",");
				val = val.join("%2C");
				val = val.split("(");
		        val = val.join("~$par$~");
		        val = val.split(")");
		        val = val.join("~$parf$~");
			notselection[n] = val;
			n ++;
		}}
	}
    
    var form = getFieldId("form");
	var boxField = getFieldId("box");
	boxField.setAttribute('value','taxonBox');
    boxField.value='taxonBox';	
    
	form.action="/toto/search/units/syncon/search/"
	selectionStr = selection.join(selectionSeparator);
	var fieldName = getFieldId("listStr");
	fieldName.setAttribute('value',selectionStr);
   	fieldName.value=selectionStr;	

	notselectionStr = notselection.join(selectionSeparator);
	var notfieldName = getFieldId("withoutlistStr");
	notfieldName.setAttribute('value',notselectionStr);
   	notfieldName.value=notselectionStr;	
	
	if (s > 0)
		form.submit();
	else
	alert("Check at least one box");
}


function seeResult(box){
if (box=="commonName")box="commonBox";
if (box.indexOf('Box')==-1) box=box+"Box";
	var liste = document.getElementsByName(box);
	var selection =[];
	var s = 0;
	for (var k=0; k<liste.length;k++){
		if (liste[k].checked){
			val = liste[k].value
			if (val.indexOf('<b>') != -1)
				val = (val.split('<b>'))[0]
			val = val.split("/");
	        val = val.join("%2F");
	        val = val.split(",");
	        val = val.join("%2C");
	        val = val.split("(");
	        val = val.join("~$par$~");
	        val = val.split(")");
	        val = val.join("~$parf$~");
			selection[s] = val;
			s ++;
		}
	}
    
    var form = getFieldId("form");
	var boxField = getFieldId("box");
	boxField.setAttribute('value',box);
    boxField.value=box;	
    
	form.action="/toto/search/units/preview/seeResult/"
	selectionStr = selection.join(selectionSeparator);
	var fieldName = getFieldId("listStr");
	fieldName.setAttribute('value',selectionStr);
   fieldName.value=selectionStr;	
	
	if (s > 0)
		form.submit();
	else
	alert("Check at least one box");
}



function encode(liste){
        liste = liste.split("/");
        liste = liste.join("%2F");
        liste = liste.split(",");
        liste = liste.join("%2C");
        liste = liste.split("(");
	    liste = liste.join("~$par$~");
	    liste = liste.split(")");
	    liste = liste.join("~$parf$~");
        return liste;
}



function getDetails(unitID,collectionID,institutionID,resourceKey,biorecordKey){

         while (collectionID.match("  ")){
                collectionID = collectionID.replace("  "," ");
        }
        while (institutionID.match("  ")){
        	institutionID = institutionID.replace("  "," ");
        }
        collectionID = encode(collectionID);
        institutionID = encode(institutionID);
        unitID = encode(unitID);
        
		if (collectionID == " "|| collectionID == "")
        	collectionID = null;
        if (institutionID == " "|| institutionID =="")
            institutionID = null;
	
	
	var display = document.getElementsByName('display');
	var portal = "displaysynth";
	for (var k=0; k<display.length;k++){
		if (display[k].checked) portal=display[k].id;
	}
	if (portal == 'displaysynth'){
	collectionField = getFieldId('collectionID');
	institutionField = getFieldId('institutionID');	
	unitIDField = getFieldId('unitID');
	resourceField = getFieldId('resourceKey');
	posField = getFieldId('pos');

	collectionField.setAttribute('value',collectionID);	
	collectionField.value=collectionID;
	
	institutionField.setAttribute('value',institutionID);	
	institutionField=institutionID;
	
	unitIDField.setAttribute('value',unitID);
	unitIDField.value=unitID;

	resourceField.setAttribute('value',resourceKey);
	resourceField.value=resourceKey;
	
	if (biorecordKey != null && biorecordKey !=''){
	try{
		bioField=getFieldId('bioKey');
		bioField.setAttribute('value',biorecordKey);
		bioField.value=biorecordKey;
	}
	catch(e){
		getFieldId('detailsFrm').innerHTML+='<input type="hidden" id="bioKey" name="bioKey" value="'+biorecordKey+'"/>';}
	}
	getFieldId('detailsFrm').submit()
	}
	else{	
		getFieldId('detailsFrmGBIF').action=getFieldId('toto').innerHTML+biorecordKey
		getFieldId('detailsFrmGBIF').submit()
	}	
}

function checkAllConcept(box,tocheck){
if (box == 'taxonBox'){
try{
var boxes = document.getElementsByTagName('input');

	if (tocheck){
		//check everything
		for (var k=0; k<boxes.length;k++){
			if (boxes[k].type=="checkbox"){
			boxes[k].setAttribute('checked',"checked");
			boxes[k].checked = true;
			}
			
		}
		allChecked = true
	}
	else{
	//uncheck everything
		for (var k=0; k<boxes.length;k++){
			if (boxes[k].type=="checkbox"){
			boxes[k].removeAttribute('checked');
			boxes[k].checked = false;
			}
			
		}
		allChecked = false
	}
}catch(e){}
}
else{
try{
	var boxes = document.getElementsByTagName('input');
	references = Array()
	i=0;
	for (var k=0; k<boxes.length;k++){
			if (boxes[k].name.search('refBox') !=-1){
				if (boxes[k].checked== false){
					references[i]=(boxes[k].name.split('_')[1]);
					i++;
				}
			}
			
		}

	if (tocheck){
		//check everything
		for (var k=0; k<boxes.length;k++){
		ok=true
			if (boxes[k].name.search(box) !=-1){
				for (var i=0; i<references.length;i++){
					if (boxes[k].name.search(references[i]) !=-1)
						ok=false;
				}
			
			if (ok == true){
			boxes[k].setAttribute('checked',"checked");
			boxes[k].checked = true;}
			}
		}
			
		
		allChecked = true
	}
	else{
	//uncheck everything
		for (var k=0; k<boxes.length;k++){
			ok=true
			if (boxes[k].name.search(box) !=-1){
				for (var i=0; i<references.length;i++){
					if (boxes[k].name.search(references[i].split('_')[1]) !=-1)
						ok=false;
				}
			
			if (ok == true){
			boxes[k].removeAttribute('checked');
			boxes[k].checked = false;}
			}
			
		}
		allChecked = false
	}
}
catch(e){}
}

}

function checkReference(box,tocheck){
try{
	var boxes = document.getElementsByTagName('input');	
	if (tocheck){
		//check everything
		for (var k=0; k<boxes.length;k++){
			if (boxes[k].name.search(box) !=-1){
			boxes[k].setAttribute('checked',"checked");
			boxes[k].checked = true;}
			
		}
		allChecked = true
	}
	else{
	//uncheck everything
		for (var k=0; k<boxes.length;k++){
			if (boxes[k].name.search(box) !=-1){
			boxes[k].removeAttribute('checked');
			boxes[k].checked = false;}
			
		}
		allChecked = false
	}
}
catch(e){}

}

function checkAll(box){
if (box == "avaBox"){
if (allChecked && prems) {allChecked=false; prems =false;}
else if (!allChecked && prems) {allChecked=true; prems = false;}
}
	var boxes = document.getElementsByName(box);
	if (! allChecked){
		//check everything
		for (var k=0; k<boxes.length;k++){
			boxes[k].setAttribute('checked',"checked");
			boxes[k].checked = true;
			
		}
		allChecked = true
	}
	else{
	//uncheck everything
		for (var k=0; k<boxes.length;k++){
			boxes[k].removeAttribute('checked');
			boxes[k].checked = false;
			
		}
		allChecked = false
	}
}

function getFormatedSelection(){
//unitID,collectionID,institutionID,resourceKey
	var liste = document.getElementsByName('avaBox');
	var corb = [];
	var corbU =[];
	var i =0;
	var m =0;
	for (var k=0; k<liste.length;k++){
		value = liste[k].value.slice(0,(liste[k].value).length);
		value = value.split(tripleIDSeparator);
			collectionID = value[1];
        while (collectionID.match("  ")){
                collectionID = collectionID.replace("  "," ");
        }
        collectionID = encode(collectionID);
		if (collectionID == " " || collectionID == "")
        	collectionID = null;
        institutionID = value[2]
        while (institutionID.match("  ")){
        	institutionID = institutionID.replace("  "," ");
        }
        institutionID = encode(institutionID);
		if (institutionID == " " || institutionID =="")
        	institutionID = null;
		resourceKey = value[3];
		if (resourceKey == "")
				resourceKey = null;
			unitID = value[0];
	    unitID = encode(unitID);
		name = value[4];
		
		biorecordKey = value[5];
        while (biorecordKey.match("  ")){
                biorecordKey = biorecordKey.replace("  "," ");
        }
        biorecordKey = encode(biorecordKey);
		if (biorecordKey == " " || biorecordKey == "")
        	biorecordKey = null;
		
		if (liste[k].checked){		
		corb[i] = unitID+tripleIDSeparator+collectionID+tripleIDSeparator+institutionID+tripleIDSeparator+resourceKey+tripleIDSeparator+name+tripleIDSeparator+biorecordKey
		i ++;
		}
		else{
		corbU[m] = unitID+tripleIDSeparator+collectionID+tripleIDSeparator+institutionID+tripleIDSeparator+resourceKey+tripleIDSeparator+name+tripleIDSeparator+biorecordKey
		m ++;
		}
	}
	checkStr = corb.join(selectionSeparator);
	uncheckStr = corbU.join(selectionSeparator);
	if (checkStr.length==0)
	return ["empty","empty"];
	else
	return [checkStr,uncheckStr];
}



function getListDetails(form){	
	corbs = getFormatedSelection();
	corbStr = corbs[0]
	corbUstr= corbs[1]
	if (corbStr=="empty") return alert("Check at least one box");
// 		displayLoadingGif();
		var fieldName = getFieldId("corbStr");
	    fieldName.setAttribute('value',corbStr);
		fieldName.value=corbStr;	
		
		var fieldName = getFieldId("corbUstr");
	    fieldName.setAttribute('value',corbUstr);
		fieldName.value=corbUstr;			
		
		form.submit()   

}

function sortBy(col,top){
 corbs = getFormatedSelection();
 	corbSortStr = corbs[0]
 	corbSortUstr= corbs[1]
	
	var form=getFieldId('sortPageWithBoxes');


	var fieldName = getFieldId("corbSortStr");
    fieldName.setAttribute('value',corbSortStr);
	fieldName.value=corbSortStr;	
	
	var fieldName = getFieldId("corbSortUstr");
    fieldName.setAttribute('value',corbSortUstr);
	fieldName.value=corbSortUstr;
	
 	var fieldName = getFieldId("col");
     fieldName.setAttribute('value',col);
 	fieldName.value=col;
 	
 	var fieldName = getFieldId("top");
     fieldName.setAttribute('value',top);
 	fieldName.value=top;			
 	
 	form.submit()   
 }



function setCurrentPageWithBoxes(page){
var liste = document.getElementsByName('avaBox');
	var corb = [];
	var corbU= []
	var i = 0;
	var m = 0;
	for (var k=0; k<liste.length;k++){
		if (liste[k].checked){
			corb[i]=liste[k].value
			i++;
		}
		else{
		corbU[m]=liste[k].value
			m++;		
		}
	}
	checkStr = corb.join(selectionSeparator);
	uncheckStr = corbU.join(selectionSeparator);
	
	var fieldName = getFieldId("checkedBoxes");
	    fieldName.setAttribute('value',checkStr);
		fieldName.value=checkStr;
		
	var fieldName = getFieldId("uncheckedBoxes");
	    fieldName.setAttribute('value',uncheckStr);
		fieldName.value=uncheckStr;
		
	var fieldName = getFieldId("cpage");
	    fieldName.setAttribute('value',page);
		fieldName.value=page;

	var form = getFieldId("currentPageWithBoxes");
	form.submit()   ;
	
}



function expandCollapseList(ulID){
	var elt = getFieldId(ulID);
	if (elt.style.display == 'block'){
		elt.style.display="none";
	}
	else{
		elt.style.display="block";
	}
}

function dlListDetails(form){
	corbs = getFormatedSelection();
	corbStr = corbs[0]
	corbUstr= corbs[1]
	if (corbStr=="empty") return alert("Check at least one box");

		var fieldName = getFieldId("corbStrDL");
	    fieldName.setAttribute('value',corbStr);
		fieldName.value=corbStr;
		
		var fieldName = getFieldId("corbUstrDL");
	    fieldName.setAttribute('value',corbUstr);
		fieldName.value=corbUstr;	
		form.submit()   

}


function displayLoadingGif(){
	var imageDiv = getFieldId("loading");
	var image = getFieldId("loadingGif");

	if (imageDiv.style.display=="block"){
		document.getElementById("loading").style.display="none";
		var content = getFieldId( 'loading' ).innerHTML
		document.getElementById("page").style.backgroundImage = "url(/toto/static/images/bg.jpg)";
		}
	else{
	    document.getElementById('loading').style.display ="block";
	    var content = getFieldId( 'loading' ).innerHTML
		document.getElementById("page").style.backgroundImage = "url(/toto/static/images/bgbg.jpg)";
		}
	getFieldId( 'loading' ).innerHTML= content;
		
}

function seeSelectionMap(form){
	corbs = getFormatedSelection();
	corbStr = corbs[0]
	corbUstr= corbs[1]
	if (corbStr=="empty") return alert("Check at least one box");

		var fieldName = getFieldId("corbMap");
	    fieldName.setAttribute('value',corbStr);
		fieldName.value=corbStr;	
		
		var fieldName = getFieldId("corbUmap");
	    fieldName.setAttribute('value',corbUstr);
		fieldName.value=corbUstr;	
		form.submit()   

}

function seeRecordBasis(){
document.getElementById("recordBasis").style.display="block"; 
window.location.href='/toto/search/units/preview/seeRecordBasis'
}


function surveille(touche){
  if (document.title.indexOf("advanced") != -1){
    if(touche==13){
    	var textarea = getFieldId('textarea');
    	if (textarea.value != "" && getFieldId('fieldList').value != ""){
    		addField('frm');
    	}
    }
  }
}


function enableSuggestion(){
elt=getFieldId('sugImg');
if (elt.style.backgroundColor.indexOf('204') == -1 && elt.style.backgroundColor.indexOf('ccc') == -1){
	elt.style.backgroundColor = "#ccc";
	onOff = 'OFF'	
	document.getElementById("searchresults").style.display = "none";
	if (document.getElementById("genusName") != null) document.getElementById("genusName").setAttribute("autocomplete","on");
	else document.getElementById("textarea").setAttribute("autocomplete","on");
	}
else {elt.style.backgroundColor = "transparent"; onOff = "ON";
	if (document.getElementById("genusName") != null) document.getElementById("genusName").setAttribute("autocomplete","off");
	else document.getElementById("textarea").setAttribute("autocomplete","off");}

title= elt.title.split(":")[0]+":"+onOff;
elt.title=title;
elt.setAttribute('title',title);
}

function dlAllFromCache(nbResults){
Check = confirm("It can take a while and the size of the file can reach several Mb .\n Do you want to go further?");
if(Check == true) window.location.href='/toto/search/units/preview/dlAllFromCache';
}

function makeVisible(){	
	root=getFieldId('frm');
	var children = root.getElementsByTagName('input'); 							
	var len = children.length;
	for(var node = 0; node< len; node++){							
		children[node].style.display = "inline";
	}
	children = root.getElementsByTagName('img'); 							
	len = children.length;
	for(var node = 0; node< len; node++){							
		children[node].style.display = "inline";
	}
}

function displayBiocaseOptions(){
elt = getFieldId('biocaseOption')
getFieldId('biocaseOption').style.display='block';
}

function hideBiocaseOptions(){
getFieldId('biocaseOption').style.display='none';
}

function expColl(elt){
	
	var count = 0;
	var toCollapse = [];
	var wrapper = elt.parentNode;
	if (wrapper.tagName !='DIV') wrapper=wrapper.parentNode;
	var child1 = wrapper.firstChild;
	while(child1){	
		if(child1.tagName == 'UL'){
			if (child1.style.display != 'none')
			child1.style.display='none';
			else
			child1.style.display='block';	
			
		}
		else{
			try{
				var child2 = child1.firstChild;
if(child2.tagName == 'IMG' ){
			url=child1.innerHTML
			if (url.indexOf('relations.png') !=-1)url = url.replace("relations.png","relationsF.png")
			else url=url.replace("relationsF.png","relations.png")
			child1.innerHTML=url;
		}
}
				catch(e){}}
 		child1 = child1.nextSibling;
}}
function checkNames(nom,luim){
if (luim.checked == true) tocheck=true;
else tocheck=false;

var boxes = document.getElementsByTagName('input');	
	if (tocheck){
		//check everything
		for (var k=0; k<boxes.length;k++){
			if (boxes[k].value.search(nom) !=-1){
			boxes[k].setAttribute('checked',"checked");
			boxes[k].checked = true;}
		}
		}
	else{
	for (var k=0; k<boxes.length;k++){
			if (boxes[k].value.search(nom) !=-1){
			boxes[k].removeAttribute('checked');
			boxes[k].checked = false;}
		}
}

}