//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
//	Affichage Dynamique du Moteur de Recherche Fooding
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
//	(C) Wilfrid Pommarat / Juin 2006
//
//	http://www.wilfrid.fr/
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

var TCatBar = new Array(new Array(44,"After bars"), new Array(39,"Alcools et vins fins"), new Array(37,"Bars à bière"), new Array(34,"Bars à cocktails"), new Array(36,"Bars à histoires"), new Array(40,"Bars à stilettos"), new Array(43,"Restricted bars"), new Array(35,"Sound bars"));
var TCatResto = new Array(new Array(3,"Bistrots et néo-bistrots"), new Array(30,"Cafés"), new Array(31,"Dînettes, snacks"), new Array(17,"Feeling"), new Array(7,"Miniprix"), new Array(18,"Monde"), new Array(28,"Salons de thé"), new Array(5,"Terroirs, fruits de mer..."), new Array(23,"Trop bon"), new Array(4,"Vin sur vin"), new Array(6,"Voir et se faire voir"));
var TServices = new Array(new Array(3,"Antidépresseur"), new Array(24,"Brunch"), new Array(20,"ça Flambe !"), new Array(22,"Calme"), new Array(23,"des Pipoles !"), new Array(21,"Faim de nuit"), new Array(25,"Ouvert le Dimanche"), new Array(4,"Terrasse"));
var TPrix = new Array(new Array(1,"moins de 15 &euro;"), new Array(2,"de 16 &agrave; 35 &euro;"), new Array(3,"de 36 &agrave; 50 &euro;"), new Array(4,"plus de 51 &euro;"));
var TDepartements = new Array(new Array("75","75 Paris"), new Array("","------------"), new Array("01","01 Ain"), new Array("02","02 Aisne"), new Array("03","03 Allier"), new Array("04","04 Alpes de Haute Provence"), new Array("05","05 Hautes-Alpes"), new Array("06","06 Alpes Maritimes"), new Array("07","07 Ardèche"), new Array("08","08 Ardennes"), new Array("09","09 Ariège"), new Array("10","10 Aube"), new Array("11","11 Aude"), new Array("12","12 Aveyron"), new Array("13","13 Bouches du Rhone"), new Array("14","14 Calvados"), new Array("15","15 Cantal"), new Array("16","16 Charente"), new Array("17","17 Charente Maritime"), new Array("18","18 Cher"), new Array("19","19 Corrèze"), new Array("20","20 Corse"), new Array("21","21 Cote d'Or"), new Array("22","22 Cotes d'Armor"), new Array("23","23 Creuse"), new Array("24","24 Dordogne"), new Array("25","25 Doubs"), new Array("26","26 Drome"),new Array("27","27 Eure"),new Array("28","28 Eure-et-Loir"), new Array("29","29 Finistère"), new Array("30","30 Gard"), new Array("31","31 Haute Garonne"), new Array("32","32 Gers"), new Array("33","33 Gironde"), new Array("34","34 Hérault"), new Array("35","35 Ille et Vilaine"),new Array("36","36 Indre"), new Array("37","37 Indre et Loire"), new Array("38","38 Isère"), new Array("39","39 Jura"), new Array("40","40 Landes"), new Array("41","41 Loir et Cher"), new Array("42","42 Loire"), new Array("43","43 Haute Loire"), new Array("44","44 Loire Atlantique"), new Array("45","45 Loiret"), new Array("46","46 Lot"), new Array("47","47 Lot et Garonne"), new Array("48","48 Lozère"), new Array("49","49 Maine et Loire"), new Array("50","50 Manche"), new Array("51","51 Marne"),new Array("52","52 Haute-Marne"), new Array("53","53 Mayenne"), new Array("54","54 Meurthe et Moselle"), new Array("55","55 Meuse"), new Array("56","56 Morbihan"), new Array("57","57 Moselle"), new Array("58","58 Nièvre"), new Array("59","59 Nord"), new Array("60","60 Oise"), new Array("61","61 Orne"), new Array("62","62 Pas de Calais"), new Array("63","63 Puy de Dôme"), new Array("64","64 Pyrénées Atlantique"), new Array("65","65 Hautes Pyrénées"), new Array("66","66 Pyrénées Orientales"), new Array("67","67 Bas Rhin"), new Array("68","68 Haut Rhin"), new Array("69","69 Rhône"), new Array("70","70 Haute-Saône"), new Array("71","71 Saône et Loire"), new Array("72","72 Sarthe"), new Array("73","73 Savoie"), new Array("74","74 Haute-Savoie"), new Array("75","75 Paris"), new Array("76","76 Seine Maritime"), new Array("77","77 Seine et Marne"), new Array("78","78 Yvelines"),new Array("79","79 Deux-Sèvres"), new Array("80","80 Somme"), new Array("81","81 Tarn"), new Array("82","82 Tarn et Garonne"), new Array("83","83 Var"), new Array("84","84 Vaucluse"), new Array("85","85 Vendée"), new Array("86","86 Vienne"), new Array("87","87 Haute Vienne"), new Array("88","88 Vosges"), new Array("89","89 Yonne"), new Array("90","90 Territoire de Belfort"), new Array("91","91 Essonne"), new Array("92","92 Hauts-de-Seine"), new Array("93","93 Seine-Saint-Denis"), new Array("94","94 Val-de-Marne"), new Array("95","95 Val-d'Oise") );

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

/*
var Avance = false;
var Charge = false;
var Titre = false;
var Guide = true;

var FlashDpt = "";
var FlashArr = "";
*/

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

var Longevite=6;

var ChercheBar=false;
var NomCP="", NumCat=0, NumService=0, NumPrix=0, NumDepartement=0;

var ChaineNomCP = "";

var ChaineResto = " nom, ville ou code postal";
var ChaineBar = " nom ou code postal à Paris";

var ChaineCategorie = "toutes les catégories";

PlaceMoteur();

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function ChangeMenu(MenuCrt, TabSource)
{
	var NbOption = TabSource.length + 2;
		
	MenuCrt.length = NbOption;
		 
  for (var i=0; i<NbOption-2; i++) 
		MenuCrt.options[i+2] = new Option(TabSource[i][1], TabSource[i][0]);
    
  MenuCrt.selectedIndex=0;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function ChoixBar()
{
	if (!ChercheBar)
	{
		//ChangeMenu(document.Formulaire.Categorie, TCatBar);
		
		document.getElementById("CategoriesBar").style.display = "";

		document.getElementById("Departements").style.display = "none";
		document.Formulaire.Departement.selectedIndex=0;
		
		RefreshNomCP(ChaineBar);
		
		if (Avance)
		{
			document.getElementById("CategoriesResto").style.visibility = "hidden";
			document.getElementById("Prix").style.visibility = "hidden";
			document.getElementById("Services").style.visibility = "hidden";
			
			document.Formulaire.CategorieResto.selectedIndex=0;
			document.Formulaire.Prix.selectedIndex=0;
			document.Formulaire.Service.selectedIndex=0;
		}	
		
		ChercheBar = true;
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function ChoixResto()
{
	if (ChercheBar)
	{
		document.getElementById("CategoriesBar").style.display = "none";
		document.Formulaire.CategorieBar.selectedIndex=0;
		
		document.getElementById("Departements").style.display = "";

		//ChangeMenu(document.Formulaire.Categorie, TCatResto);

		RefreshNomCP(ChaineResto);

		if (Avance)
		{
			document.getElementById("CategoriesResto").style.visibility = "visible";
			document.getElementById("Prix").style.visibility = "visible";
			document.getElementById("Services").style.visibility = "visible";
		}	

		ChercheBar = false;
	}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function RefreshNomCP(NewChNomCP)
{
	if (document.Formulaire.NomCodePostal.value==ChaineNomCP)
		document.Formulaire.NomCodePostal.value = NewChNomCP;
		
	ChaineNomCP	= NewChNomCP;
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function ValSelect(Elmt)
{
	return (Elmt.options[Elmt.selectedIndex].value);
}	

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function Trim(Chaine) 
{
  while (Chaine.substring(0,1) == ' ') 
    Chaine = Chaine.substring(1,Chaine.length);

  while (Chaine.substring(Chaine.length-1,Chaine.length) == ' ') 
    Chaine = Chaine.substring(0,Chaine.length-1);

  return Chaine;
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlaceMoteur()
{
	if (Charge && CookieOn())
	{
		ChercheBar = (GetCookieVal("ChercheBar")=="true");
		
		NomCP = GetCookieVal("NomCP");

		if (ChercheBar)
			NumCat = GetCookieVal("NumCat");
		else
		{	
			if (FlashDpt!="")
			{
				NumDepartement = FlashDpt;
				SetCookie("NumDepartement", NumDepartement, Longevite);
				
				NomCP = "";
				NumCat = NumService = NumPrix = 0;
			}
			else 
				if (FlashArr!="")
				{
					NomCP = FlashArr;
					SetCookie("NomCP", NomCP, Longevite);
					
					NumDepartement = NumCat = NumService = NumPrix = 0;
				}
				else
					NumDepartement = GetCookieVal("NumDepartement");
	
			if (Avance)
			{
				NumCat = GetCookieVal("NumCat");
				NumPrix = GetCookieVal("NumPrix");
				NumService = GetCookieVal("NumService");
			}	
		}	
	}
	
	Moteur = "<TABLE Height='" + (Avance?(Guide?190:166):67) + "' CellSpacing='0' CellPadding='" + (Guide?1:0) + "' Border='0'>" +
					 "<FORM Action='recherche.htm' Method='Post' Name='Formulaire' OnSubmit='return ValideRecherche();'>";
							 
	if (Titre)
	{
		if (Avance)
			Moteur += "<TR><TD ColSPan='2'><IMG Src='Img/Rech_Avancee.gif' Width='196' Height='18'/></TD></TR>"
		else
			Moteur += "<TR><TD ColSPan='2'><IMG Src='Img/Rech_Rapide.gif' Width='196' Height='14'/></TD></TR>"
	}	
	
	ChaineNomCP = (ChercheBar?ChaineBar:ChaineResto);
							 
	Moteur += PlaceLieu(ChercheBar) + PlaceNomCP(NomCP) +
						"<TR><TD>" + PlaceDepartement(NumDepartement) + PlaceCategorie(true, NumCat) + "</TD>" +
						"<TD Align='Right'><INPUT Type='Image' Src='Img/" + (Guide?"Bt_OK_B":"Bt_OK") + ".gif' Align='AbsMiddle' Title='Lancer la recherche !' " +
						"Width='22' Height='22' Border='0' Value='OK' Name='OK'></TD></TR>";
	
	if (Avance)
		Moteur += "<TR><TD>" + PlaceCategorie(false, NumCat) + "</TD><TD RowSpan='2'>" + BtReset() + "</TD></TR>" + 
							"<TR><TD>" + PlacePrix(NumPrix) + "</TD></TR><TR><TD>" + PlaceService(NumService) + "</TD><TD>" + BtRechAvancee() + "</TD></TR>";

	Moteur += "</FORM></TABLE>";

	document.write (Moteur);
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function BtRechAvancee()
{
	var Retour="";
	
	if (!Guide)
		Retour = "<A HRef='guide.htm' Title='Recherche à la carte'><IMG Src='Img/Bt_Zoom.gif' Align='AbsMiddle' Alt='Recherche à la carte' Width='22' Height='22' Border='0'></A>";
	else
		Retour = "&nbsp;";
	
	return(Retour);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function EffaceRecherche()
{
	if (confirm('Souhaitez-vous effacer les critères de recherche ?'))
		with (document.Formulaire)
		{
			NomCodePostal.value = ChaineNomCP;
		
			if (ChercheBar)
				CategorieBar.selectedIndex=0;
			else
			{	
				Departement.selectedIndex=0;
				
				if (Avance)
				{
					CategorieResto.selectedIndex=0;
					Prix.selectedIndex=0;
					Service.selectedIndex=0;
				}
			}
		}
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function BtReset()
{
	var Retour;

	if (!Guide)
		Retour = "<A onClick='EffaceRecherche();' HRef='#'><IMG Src='Img/Bt_Reset.gif' Align='AbsMiddle' Alt='Effacer les critères de recherche' Width='22' Height='22' Border='0'></A>";
	else
		Retour = "&nbsp;";
	
	return(Retour);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlaceLieu(CrtChercheBar)
{
	var Retour;
	
	//Retour = "<TR><TD ColSPan='2' Class='CadreMoteur'><TABLE CellSpacing='0' CellPadding='0' Border='0'><TR>" +
	//				 "<TD><INPUT Type='Radio' Id=Bar Name='Lieu' OnClick='ChoixBar();' " + (CrtChercheBar?"Checked ":"") + "Value='bar' /></TD><TD Class='CadreMoteur'><LABEL For=Bar>&nbsp;Boire&nbsp;</LABEL>&nbsp;&nbsp;</TD>" +
	//				 "<TD><INPUT Type='Radio' Id=Resto Name='Lieu' OnClick='ChoixResto();' " + (!CrtChercheBar?"Checked ":"") + "Value='restaurant' /></TD><TD Class='CadreMoteur'><LABEL For=Resto>&nbsp;Manger</LABEL></TD>" +
	//				 "</TR></TABLE></TD></TR>";
	Retour = "<TR><TD ColSPan='2' Class='CadreMoteur'>&nbsp;<INPUT Type='hidden' Id=Resto Name='Lieu' Value='restaurant' /></TD></TR>";
					 
	return(Retour);
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlaceNomCP(CrtNomCP)
{
	var Retour;

	Retour = "<TR><TD ColSPan='2'><INPUT Name='NomCodePostal' Size='30' MaxLength='30' Class='NomCP' " +
					 "Value='" + (CrtNomCP!=""?CrtNomCP:ChaineNomCP) + "' onFocus=\"if (this.value==ChaineNomCP) {this.value=''}\" " + 
					 "onBlur=\"if (Trim(this.value)=='') {this.value=ChaineNomCP}\" /><BR><IMG Src='Img/P.gif' Width='1' Height='2'></TD></TR>";

	return(Retour);
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlacePrix(CrtPrix)
{
	var Retour;

	Retour = "<DIV ID='Prix'" + (ChercheBar?" Style='visibility:hidden'":"") + ">" + PlaceMenu("tous les prix", "Prix", TPrix, CrtPrix) + "</DIV>";

	return(Retour);
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlaceService(CrtService)
{
	var Retour;

	Retour = "<DIV ID='Services'" + (ChercheBar?" Style='visibility:hidden'":"") + ">" + 
					 PlaceMenu("services indifférents", "Service", TServices, CrtService) + "</DIV>";

	return(Retour);
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlaceDepartement(CrtDepartement)
{
	var Retour;

	Retour = "<DIV ID='Departements'" + (ChercheBar?" Style='display:none'":"") + ">" + PlaceMenu("tous les départements", "Departement", TDepartements, CrtDepartement) + "</DIV>";

	return(Retour);
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlaceCategorie(CatBar, CrtCategorie)
{
	var Retour;

	Retour = "<DIV ID='Categories" + (CatBar?"Bar":"Resto") + "'" + (CatBar?(ChercheBar?"":" Style='display:none'"):(ChercheBar?" Style='visibility:hidden'":"")) + ">" + 
					 PlaceMenu(ChaineCategorie, "Categorie"+(CatBar?"Bar":"Resto"), (CatBar?TCatBar:TCatResto), CrtCategorie) + "</DIV>";

	return(Retour);
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function PlaceMenu(Intitule, Label, Tablo, Choix)
{
	var Menu, i;
	
	//alert(Label);
	
	Menu = "<SELECT Name='" + Label + "' Class='Saisie'><OPTION Value=''>" + Intitule + "<OPTION Value=''>------------";
	
	for(i=0;(i<Tablo.length);i++)
		Menu += "<OPTION " + ((Choix==Tablo[i][0] && Tablo[i][0]!="")?"SELECTED Class='Critere' ":"") + "Value='" + Tablo[i][0] + "'>" + Tablo[i][1];
		
	Menu += "</SELECT>";
	
	return(Menu + "<BR>");
}		

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

function ValideRecherche()
{
	var Valide;

	with (document.Formulaire)
	{
		ChercheBar = ((Lieu[0])?(Lieu[0].checked):false);  // JP : Avoid null
		
		NomCP = Trim(NomCodePostal.value);
		
		NonValide = (NomCP==Trim(ChaineNomCP) || NomCP.length == 0);

		if (ChercheBar)
		{
			NumCat = ValSelect(CategorieBar);

			NonValide = (NonValide && (NumCat==""));
		}
		else
		{
			NumDepartement = ValSelect(Departement);

			NonValide = (NonValide && (NumDepartement=="")); 

			if (Avance)
			{
				NumCat = ValSelect(CategorieResto);
				NumPrix = ValSelect(Prix);
				NumService = ValSelect(Service);
		
				NonValide = (NonValide && (NumCat=="") && (NumPrix=="") && (NumService=="")); 
			}
		}
		
		if (NonValide)
		{
			alert("Veuillez choisir un critère de recherche...");
			
			if (ChercheBar)
				CategorieBar.focus();
			else	
				Departement.focus();
			
			return(false);
		}
		
		if (NomCP==Trim(ChaineNomCP))
		{
			NomCP="";
			NomCodePostal.value="";
		}	
	}	
	
	SetCookie("ChercheBar", ChercheBar, Longevite);

	SetCookie("NomCP", NomCP, Longevite);
	
	if (ChercheBar)
		SetCookie("NumCat", NumCat, Longevite);
	else
	{	
		SetCookie("NumDepartement", NumDepartement, Longevite);
	
		if (Avance)
		{
			SetCookie("NumCat", NumCat, Longevite);
			SetCookie("NumPrix", NumPrix, Longevite);
			SetCookie("NumService", NumService, Longevite);
		}	
	}	
	
	return (true);
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
