var oRECHCHP;

var loadedRech = false;

var largeurFenetreRech = 250;	
var topFenetreRech = 300;			
var leftFenetreRech = 200;	



var hauteurBarretitreRech = 13; 
var couleurHautRech = "#7392C6";	
var couleurBasRech = "#FFFFFF";

var texteBarretitreRech = "<b>Recherche</b>";
var policeBarretitreRech = "Arial";
var taillePoliceBarretitreRech = "12";
var couleurPoliceBarretitreRech = "#FFFFFF";

var policeCorpsRech = "Arial";
var taillePoliceCorpsRech = "12";
var couleurPoliceCorpsRech = "#000000";

var valueItemRech;
var ObjectValueRech;

var TypeSelectRech;
var STypeSelectRech;
var FieldSelectRech;
var ValueSelectRech;
var ovRech;

function clicDownRech(tab) {
	abscisse = abs-leftFenetreRech;
	ordonne = ord-topFenetreRech;
	clicRech=true;
}
function clicUpRech() {
		clicRech=false;
}
function fermerPopupRech() {
	oRECHCHP.style.visibility="hidden";
}




//---------------------------------------------------------

function typeFeedRech(){
	nRacinesvg = svgDoc.childNodes.item(0);
	nsvg = nRacinesvg.childNodes;
	for(i=0;i<nsvg.length;i++)
	{
		if(nsvg.item(i).nodeName == "g"){
			nTypesvg = nsvg.item(i);
			if(nTypesvg.firstChild.nodeName=="desc"){
				nLibTypesvg = nTypesvg.firstChild;
				TypeSelectRech.options[TypeSelectRech.options.length] = new Option(nLibTypesvg.firstChild.nodeValue, nsvg.item(i).getAttribute("id"));
			}			
		}			
	}
}

function sTypeFeedRech(){
	STypeSelectRech.options.length=0;
	nTypesvg = svgDoc.getElementById(TypeSelectRech.options[TypeSelectRech.selectedIndex].value);
	if(nTypesvg){
		for(i=0;i<nTypesvg.childNodes.length;i++){
			if(nTypesvg.childNodes.item(i).nodeName=="g"){
				nSTypesvg = nTypesvg.childNodes.item(i);
				if(nSTypesvg.firstChild.nodeName=="desc"){
					nLibSTypesvg = nSTypesvg.firstChild;
					STypeSelectRech.options[STypeSelectRech.options.length] = new Option(nLibSTypesvg.firstChild.nodeValue, nSTypesvg.getAttribute("id"));
				}
			}
		}
	}
	fieldFeedRech();
}

function fieldFeedRech(){
	FieldSelectRech.options.length=0;
	nSTypesvg = svgDoc.getElementById(STypeSelectRech.options[STypeSelectRech.selectedIndex].value);
	if(nSTypesvg){
		for(i=0;i<nSTypesvg.childNodes.length;i++){			
			if(nSTypesvg.childNodes.item(i).nodeName=="metadata"){
				nLibFieldsvg = nSTypesvg.childNodes.item(i);
				FieldSelectRech.options[FieldSelectRech.options.length] = new Option(nLibFieldsvg.firstChild.nodeValue, nLibFieldsvg.getAttribute("id"));
			}
		}
	}
	valueFeedRech();
}

function checkItem(itemValue){
	for(j=0;j<valueItem.length;j++){
		if(valueItem[j] == itemValue){
			return true;
		}
	}
	return false;
}

function valueFeedRech(){
	valueItemRech = new Array();	
	ObjectValueRech = new Array(Array(0xFFFFFFFF), Array(0xFFFFFFFF));
	ovRech = 0;
	
	FieldId = FieldSelectRech.options[FieldSelectRech.selectedIndex].value & 0xF0000;
	nSTypesvg = svgDoc.getElementById(STypeSelectRech.options[STypeSelectRech.selectedIndex].value);
	if(nSTypesvg){
		for(i=0;i<nSTypesvg.childNodes.length;i++){
			if(nSTypesvg.childNodes.item(i).nodeName=="g"){
				ObjectId = nSTypesvg.childNodes.item(i).getAttribute("id") & 0xFFF0FFFF;
				FieldObjectId = ObjectId + FieldId;
				nFieldsvg = svgDoc.getElementById(FieldObjectId);
				if(nFieldsvg){
					textValue="";
					if(nFieldsvg.firstChild){						
						ObjectValueRech[0][ovRech] = FieldObjectId;
						ObjectValueRech[1][ovRech] = nFieldsvg.firstChild.nodeValue;
						ovRech++;
					}								
				}
			}
		}
	}
}

function searchObjectRech(){
	var ofind=false;
	if(SearchTypeRech[0].checked){expression = "^" + ValueSelectRech.value + "$"}else{expression = ValueSelectRech.value}
	var re = new RegExp(expression);
	
	valueFeedRech();
	var HTMLcontent = "<table border='1' bordercolor='#000000' cellpadding='1' cellspacing='0'>";
	HTMLcontent+="<tr><td class='liste' align='center' valign='top'><b>Id<b></td>";
	nSTypesvg = svgDoc.getElementById(STypeSelectRech.options[STypeSelectRech.selectedIndex].value);
	if(nSTypesvg){
		for(i=0;i<nSTypesvg.childNodes.length;i++){			
			if(nSTypesvg.childNodes.item(i).nodeName=="metadata"){
				nLibFieldsvg = nSTypesvg.childNodes.item(i);
				HTMLcontent+="<td class='liste' align='center' valign='top'><b>"+nLibFieldsvg.firstChild.nodeValue+"</b></td>";				
			}
		}
	}
	HTMLcontent+="</tr>"
	for(i=0;i<ovRech;i++){					
		if(ObjectValueRech[1][i].search(re)!=-1){
			objectId = ObjectValueRech[0][i] & 0xFFF0FFFF;
			HTMLcontent+="<tr><td class='liste' align='center'><a href='#' onClick='blinkObject("+ objectId +")'>"+ ObjectValueRech[0][i] +"</a></td>";
			for(j=0;j<FieldSelectRech.options.length;j++){
				FieldId = FieldSelectRech.options[j].value;
				FieldObjectId = objectId + (FieldId & 0xF0000);
				nFieldsvg = svgDoc.getElementById(FieldObjectId);
				textValue="&nbsp;";
				if(nFieldsvg){if(nFieldsvg.firstChild)textValue=nFieldsvg.firstChild.nodeValue;}
				HTMLcontent+="<td class='liste' align='center' valign='top'>"+ textValue +"</td>";
			}
			HTMLcontent+="</tr>";if(j<FieldSelectRech.options.length) HTMLcontent+="<tr>";
			ofind=true;
		}
	}
	HTMLcontent+="</tr></table>";
	document.getElementById("content").innerHTML=HTMLcontent;
	showResult();
	if(!ofind)alert("Aucun objet trouvé");
}


//---------------------------------------------------------

function popup_rech(){
	if (document.getElementById) {
		document.write('<div id=BRECH STYLE="position:absolute;top:'+topFenetreRech+'px;left:'+leftFenetreRech+'px;visibility:hidden;filter:alpha(opacity=90)">')       
		document.write('<table width="'+largeurFenetreRech+'"  height="150" border="1" cellspacing="0" cellpadding="0" class="popup">')
		largeurFenetreRech -= hauteurBarretitreRech		
		document.write('<tr onmousedown="clicDownRech()" onmouseup="clicUpRech()">')
		document.write('<td bgcolor="'+couleurHautRech+'" class="titre" width="'+largeurFenetreRech+'" height="13" style="cursor: move"> ' + texteBarretitreRech +'</td>')
		document.write('<td bgcolor="'+couleurHautRech+'" class="titre" width="13" height="13"><img src="fonctions/img/b_fermer.gif" width="13" height="13" onclick="fermerPopupRech()"></td>')
		document.write('</tr>')
		document.write('<tr valign="top">') 
		document.write('<td bgcolor="'+couleurBasVal+'" width="'+largeurFenetreVal+'" colspan="2" class="corps">')
		document.write('<FORM name=selectSearchRech>')
		document.write('<br><div align="center"><SELECT onchange="sTypeFeedRech()" name="myTypeSelectRech">')
		document.write('</SELECT><br><br>')
		document.write('<SELECT onchange="fieldFeedRech()" name="mySTypeSelectRech">')
		document.write('</SELECT><br><br>')
		document.write('<SELECT name="myFieldSelectRech">')
		document.write('</SELECT><br><br>')
		document.write('<input type="radio" name="myRadSearchType" value="equal" checked>Egal&nbsp;')
		document.write('<input type="radio" name="myRadSearchType" value="inside">Contient<br>')
		document.write('<input type="text" name="myValueSelectRech" size="20" maxlength="20"><br>')
		document.write('<br><input type="button" value="ok" onClick="searchObjectRech()"></div>')		
		document.write('</FORM>')
		document.write('</td>')
		document.write('</tr>')			
		document.write('</table>')
		document.write('</div>')		
		
	}
	TypeSelectRech = selectSearchRech.myTypeSelectRech;
	STypeSelectRech = selectSearchRech.mySTypeSelectRech;
	FieldSelectRech = selectSearchRech.myFieldSelectRech;
	ValueSelectRech = selectSearchRech.myValueSelectRech;
	SearchTypeRech = selectSearchRech.myRadSearchType;
	
	oRECHCHP = document.getElementById("BRECH");	
}


	
