var nodeForm		= null;
var nodeType		= null;
var nodeTypeLabel	= null;
var nodeCategorie	= null; 
var nodeCategorieLabel	= null; 
var nodePrix		= null;
var nodePrixLabel	= null;
var nodeVille		= null;
var nodeVilleLabel	= null;
var nodeMotCleLabel	= null;
var nodeMotCle		= null;
var nodeAucuneAnnonce	= null;
var nodeRechercheAnnonce= null;
var nodeBoutonLabel	= null;
var nodeInitialiserLabel= null;
var itemAucuneAnnonce	= null;
var itemDefautAnnonce	= null;
var nodeIframe		= null;
var colorDefaut		= null;
function	initVars()
{
	nodeForm		= document.getElementById('rechercheForm');
	nodeType		= document.getElementById('type');
	nodeTypeLabel		= document.getElementById('typeLabel');
	nodeCategorie		= document.getElementById('categorie');
	nodeCategorieLabel	= document.getElementById('categorieLabel');
	nodePrix		= document.getElementById('prix');
	nodePrixLabel		= document.getElementById('prixLabel');
	nodeVille		= document.getElementById('ville');
	nodeVilleLabel		= document.getElementById('villeLabel');
	nodeMotCle		= document.getElementById('motcle');
	nodeMotCleLabel		= document.getElementById('motcleLabel');
	nodeAucuneAnnonce	= document.getElementById('aucuneAnnonce');
	nodeRechercheAnnonce	= document.getElementById('rechercheAnnonce');
	nodeBoutonLabel		= document.getElementById('boutonLabel');
	nodeInitialiserLabel	= document.getElementById('initialiserLabel');
	itemAucuneAnnonce	= new Option("----------------","0");
	itemDefautAnnonce	= new Option("-- Choisissez --","0");
	nodeIframe		= window.frames['ifr'];
	colorDefaut		= "#005f9d";
	colorGrey		= "#ccddcc";
}
function	alerte(nodeLabel)
{
	nodeLabel.style.color	= '#FF0000';
	nodeLabel.innerHTML	= nodeLabel.innerHTML+'*';
}
function	lectureSeule(nodeLabel, nodeField)
{
	nodeLabel.style.color	= colorGrey;
	nodeField.style.color	= colorGrey;
	supprimerOption(nodeField);
	nodeField.readOnly	= true;
}
function	ajouterOption(nodeField, item)
{
	if (nodeField.type == 'select-one' && item.length>0)
	{
		supprimerOption(nodeField);
		for (i=0; i<item.length; i++)
			nodeField.options[i+1] = item[i];
	}
}
function	supprimerOption(nodeField, defautOption)
{
        if (nodeField.type=="select-one")
        {
		if (nodeField.options.length > 1)
		{
			for(i=nodeField.options.length-1; i>0; i--)
					nodeField.remove(i);
		}
	}
}
function	estLectureSeule(nodeLabel)
{
	rtn = false;
	if (nodeLabel.style.color == colorGrey)
		rtn = true;
	return rtn;
}
function	lecture(nodeLabel, nodeField)
{
	nodeLabel.style.color	= colorDefaut;
	nodeField.style.color	= colorDefaut;
	nodeField.readOnly	= false;
	supprimerOption(nodeField);
}
function	initForms(categorie, prix, ville)
{
	nodeAucuneAnnonce.style.display		= 'none';
	nodeRechercheAnnonce.style.display	= 'none';
	nodeInitialiserLabel.style.display	= 'none';
	nodeBoutonLabel.style.display		= 'block';
	lecture(nodeMotCleLabel, nodeMotCle);
	if (categorie)	lecture(nodeCategorieLabel, nodeCategorie);
	if (prix)	lecture(nodePrixLabel, nodePrix);
	if (ville)	lecture(nodeVilleLabel, nodeVille);
}
function	newCategorie()
{
	initForms(true,true,true);
	var type	= nodeType[nodeType.selectedIndex].value;
	if (parseInt(type) > 0)	nodeIframe.location.href = "/ajax/chargerCategorie.php?RUB_N_RUBRIQUEPARENT="+type;
}
function	newPrix()
{
	initForms(false,true,true);
	var categorie	= nodeCategorie[nodeCategorie.selectedIndex].value;
	if (parseInt(categorie) > 0)	nodeIframe.location.href = "/ajax/chargerPrix.php?RUB_N_RUBRIQUEPARENT="+categorie;
}
function	newVille()
{
	initForms(false,false,true);
	var categorie			= nodeCategorie[nodeCategorie.selectedIndex].value;
	var prix			= nodePrix[nodePrix.selectedIndex].value;
	if (parseInt(prix)>0)		nodeIframe.location.href = "/ajax/chargerVille.php?RUB_L_RUBRIQUE="+prix;
	else if (parseInt(categorie)>0)	nodeIframe.location.href = "/ajax/chargerVille.php?RUB_L_RUBRIQUE="+categorie;
}
function	rechercher()
{
	var type	= nodeType[nodeType.selectedIndex].value;
	var categorie	= nodeCategorie[nodeCategorie.selectedIndex].value;
	var prix	= nodePrix[nodePrix.selectedIndex].value;
	var ville	= nodeVille[nodeVille.selectedIndex].value;
	var r		= nodeForm.elements['r'];
	var nar		= nodeForm.elements['nar'];
	var zg		= nodeForm.elements['zg'];
	var kw		= nodeForm.elements['kw'];
	if (kw.value=='mot clé')
		kw.value	= "";
	kw.value = kw.value.replace(/^\s+/g,'').replace(/\s+$/g,'');
	if (parseInt(type) > 0)
	{
		r.value	= parseInt(type);
		if (parseInt(prix)>0)		nar.value	= parseInt(prix);
		else if (parseInt(categorie)>0)	nar.value	= parseInt(categorie);
		else				nar.value	= parseInt(type);
		if (parseInt(ville)>0)		zg.value	= parseInt(ville);
		nodeForm.submit();
	}
	else if (kw.value != '')
		nodeForm.submit();
	else
		nodeRechercheAnnonce.style.display = 'block';
}
