/************************************************/
/*						*/
/*		Fichier javascript		*/
/*						*/
/************************************************/

/************************************************/
/*	    Fonctions d'initialisation		*/
/************************************************/

/* pour le fichier ListeGroupe.html */

function RechercherGroupes(Provenance)
{
 	/* Changement de navigation !
	   Provenance = 1 : Réservation rapide
	   Provenance = 2 : Gèrer votre compte */
 	if (Provenance == 1)
 	{
 	   /*Mise à jour du bouton retour */
 	   document.forms[0].Retour.value = LienRetour;
 	   top.window.document.title = SelectGrp1 + SelectGrp2;
  	}
 	else
 	   top.window.document.title = TitreGererGroupe + TitreGererGroupe2;

	top.frames[0].ModificationResa = "";
        top.frames[0].IdResaModif = 0;
 	top.frames[0].IdCmdeModif = 0;
 	top.frames[0].NumLayer	  = 0;
	/* Recuperation des valeurs de IdSession, IdClient et CodeLangue dans le Formulaire */
	document.forms[0].IdSession.value = top.frames[0].IdSession;
	document.forms[0].IdClient.value = top.frames[0].IdClient;
	document.forms[0].CLangue.value = top.frames[0].CodeLangue;
	/*MAJ du bouton nouveau groupe*/
	document.forms[0].NveauGrp.value = NveauGrpBtn;
	
	if (Provenance == 2)
	{
	/* Initialisation à blanc des variables de reservation et commande */
	   top.frames[0].DateResa    ="";
	   top.frames[0].HeureResa   ="";
	   top.frames[0].IdRestaurant="";
	   top.frames[0].Restaurant  ="";
	   top.frames[0].IdZoneGeo   ="";
	   top.frames[0].IdPrestation="";
  	}
	top.frames[0].NumCommande =0;
	top.frames[0].TotalComNet =0;
				
	/* Recherche des groupes */
	document.forms[0].target="groupes";
	document.forms[0].submit();
}


/* pour le fichier valider.html */

function initTimer(modifMP, modifClient, Client, MP, Session)
{
 	document.title = TitreValider;
 	
	setTimeout("ferm("+modifMP+","+modifClient+","+Client+",'"+MP+"',"+Session+");",2000);
}

function RetourEcran()
{
  /* reinitialisation de la date avec celle choisie au depart */
  top.frames[0].DateResa = top.frames[0].DateResaSav;
  /* Remise à 0 de l'heure en cas de retour à la partie Creation */
  if (top.frames[0].NumLayer == 0)
      top.frames[0].HeureResa = '00:00:00';

  if (top.frames[0].IdResaModif != 0)
  window.document.location=top.frames[0].url+"ModifResa&Arguments=-N"+top.frames[0].IdResaModif+",-N"+top.frames[0].IdSession+",-A"+top.frames[0].CodeLangue;
  else
  window.document.location=top.frames[0].url+"ChoixHeure&Arguments=-N"+top.frames[0].IdSession+",-N"+top.frames[0].IdPrestation+",-A"+top.frames[0].HeureResa+",-L"+top.frames[0].ModificationResa+",-N"+top.frames[0].IdResaModif+",-N"+top.frames[0].NumLayer + ",-A" + top.frames[0].CodeLangue;
}

function InitAffGrp(NbStop)
{
/*appelle par Listegroupe.html*/
   top.frames[0].RetourListeGroupe = "False";
   top.frames[0].RetourModif = "False";
   for(var i=1;i<=NbStop ;i++)
   {
	  eval('document.forms[0].ChoixGroupe'+i+'.value ="'+BtnChxGrp+'"');
   }
}

function InitAffGrp2(NbStop,NbStop2)
{
/* si appelle par Gerergroupes.html*/
   for(var i=1;i<=NbStop ;i++)
   {
	  eval('document.forms[0].Modifier'+i+'.value ="'+BtnModif+'"');
	  eval('document.forms[0].Supprimer'+i+'.value ="'+BtnSupp+'"');
   }
   for(var i=1;i<=NbStop2 ;i++)
   {
   	  eval('document.forms[0].Reserver'+i+'.value ="'+BtnReser+'"');
   }
   StopCons = NbStop2 - NbStop;
   for(var i=1;i<=StopCons ;i++)
   {
      	  eval('document.forms[0].Consulter'+i+'.value ="'+BtnCons+'"');
   }
}

function InitPlanning()
{
 	parent.document.getElementById('num3').style.display = '';
        parent.document.getElementById('fleche2').style.display = '';
}

function initListeResa()
{

	top.window.document.title = TitreResaGrp +' '+ TitreResaGrp2;
	/* Initialisation des infos client */
	top.frames[0].NumLayer	  = 0;
	top.frames[0].ModificationResa = "";
 	top.frames[0].IdResaModif = 0;
 	top.frames[0].IdCmdeModif = 0;
 	document.forms[0].CreateResa.value = LienCreat;
 	document.forms[0].Retour.value = LienRetour;
 	document.forms[0].IdSession.value    = top.frames[0].IdSession;
	document.forms[0].IdClient.value     = top.frames[0].IdClient;
	
 	document.forms[0].GroupeSelect.value = top.frames[0].GroupeSelect;
 	document.forms[0].CLangue.value	     = top.frames[0].CodeLangue;
 	
	top.frames[0].DateResa = "";
	top.frames[0].IdRestaurant = 0;
	top.frames[0].Restaurant = "";
	top.frames[0].IdZoneGeo=0;
	top.frames[0].IdPrestation=0;
		
	/* Recherche des resa*/
	document.forms[0].target="resa";
	document.forms[0].submit();
}

function InitValider()
{
 	 document.title = TitreValider;
 	 document.forms[0].BtnValid.value = valider;
}
/************************************************/
/*	    Fonctions de navigation		*/
/************************************************/

/* pour le fichier .html */

/*fonction appellee lors de la saisie du MP et du login */
function ListeGroupe()
{
	 window.document.location="/Magic94Scripts/mgrqispi94.dll?appname=Tourismev9&prgname=ConfirmLogin&Arguments=-N"+document.forms[0].CodeClient.value+",-A"+document.forms[0].MotPasse.value+",-N"+document.forms[0].IdSession.value+",-A"+document.forms[0].CLangue.value;
}

/* utilisee uniquement pour l'accès à la fiche clients */
function ouvrir(prog, num, IdClient, IdSession)
{
  window.open("/Magic94Scripts/mgrqispi94.dll?appname=Tourismev9&prgname="+prog+"&Arguments=-N" + num + ",-N" + IdClient + ",-N" + IdSession + ",-A" + document.forms[0].CLangue.value,'FicheClient','channelmode=no,toolbar=no,location=no,menubar=no,Left=150,top=10,width=500,height=700');
}


function ConditionVente(Langue)
{
 	 window.open("/html/ConditionVente"+Langue+".html",'ConditionVente','channelmode=no,toolbar=no,location=no,menubar=no,scrollbars=yes,Left=150,top=20,width=710,height=600');
}

function InfoLegale(Langue)
{
 	 window.open("/html/InfoLegal"+Langue+".html",'InfoLegal','channelmode=no,toolbar=no,location=no,menubar=no,scrollbars=no,Left=250,top=100,width=400,height=200');
}


/* pour le fichier AffichPlanning.html */

function ChangeDate(signe)
{
/*
	top.frames[0].DateResa = document.forms[0].DateResa.value;
	
	window.open(top.frames[0].url+'ListeRestoPlanning&Arguments=-A'+top.frames[0].Restaurant+',-N'+top.frames[0].IdZoneGeo+',-N'+top.frames[0].IdPrestation+',-A'+top.frames[0].DateResa+',-N'+top.frames[0].GroupeSelect+',-N'+top.frames[0].IdSession,'ListeResto','channelmode=no,toolbar=no,location=no,menubar=no,scrollbars=yes,Left=150,top=100,width=500,height=500');*/

top.frames[0].IdRestoChoisi=0;
top.frames[0].RestoChoisi="";
window.document.location=top.frames[0].url+"ChangeDate&Arguments=-A"+top.frames[0].DateResa+",-A"+signe+",-N"+top.frames[0].IdSession;
}


function AnnulationCom()
{
 if (top.frames[0].ModifGroupe == "True")
	alert(AlertModifGroupe);
 else
 {
    if (confirm(ConfirmAnnule) )
       window.document.location=top.frames[0].url+"AnnuleCmdeMenu&Arguments=-N"+document.forms[0].NumCommande.value+",-N" + top.frames[0].IdClient+",-N" + top.frames[0].IdSession + ",-N" + top.frames[0].OngletInit;
 }	
}


/* pour le fichier ListeGroupes.html */

function ListeReservation (IdGroupe, NomGroupe, NbResa, NbPers)
{
	parent.document.forms[0].GroupeSelect.value = IdGroupe;
	top.frames[0].GroupeSelect 		    = IdGroupe;
	top.frames[0].NomGroupeSelect		    = NomGroupe;
	top.frames[0].TailleGroupeSelect 	    = NbPers;
	/* si le groupe n'a pas de resa associe, on dirige le client tout de suite vers la creation de resa */
	if (NbResa >0)
	{
	   top.frames[0].RetourListeGroupe = "False";
	   top.frames[0].RetourModif = "False";
	   parent.window.document.location="/html/ListeReservationGroupe.html";
        }
 	else
	{
	   top.frames[0].RetourListeGroupe = "True";
	   top.frames[0].RetourModif = "False";
 	   parent.window.document.location=top.frames[0].url+'CreationResaRapide&Arguments=-N'+ top.frames[0].IdSession + ',-A' + top.frames[0].CodeLangue+',-Lfalse,-Ltrue,-Lfalse,-N'+IdGroupe;
	}
}

/* pour le fichier ListeReservationGroupe.html */

function ResaCreation()
{
        top.frames[0].RetourModif = "False";
	top.frames[0].RetourListeGroupe = "False";
//	window.document.location=top.frames[0].url+"CreationResa&Arguments=-N"+ top.frames[0].IdSession + ",-A" + top.frames[0].CodeLangue+",-L"+top.frames[0].RetourModif +",-N0"+",-L"+top.frames[0].RetourListeGroupe;
	window.document.location=top.frames[0].url+'CreationResaRapide&Arguments=-N'+ top.frames[0].IdSession + ',-A' + top.frames[0].CodeLangue+',-Lfalse,-Ltrue,-Lfalse,-N'+top.frames[0].GroupeSelect;
}

function AffListeGroupe()
{
 //   window.document.location=top.frames[0].url+"AffListeGroupe&Arguments=-N"+top.frames[0].IdClient+",-N"+top.frames[0].IdSession;
    window.document.location='/html/GererGroupe.html';
}


/* pour le fichier PLanning.html */

function ChoixHeure(heure, NbCreneau,PositionActuelle)
{
 	if (top.frames[0].ModificationResa == 'True')
 	{
 	   ModificationPlanning(heure);
 	}
 	else
	{
	chaine = document.forms[0].Dispo.value;
	FinBoucle = Math.max(chaine.lastIndexOf("0"),chaine.lastIndexOf("1")) + 1;
	
 	if (top.frames[0].GroupeSelect != 0)
 	{
 	 /* un groupe a été selectionné avant le planning */
  	   erreur = false;

 	   if ((PositionActuelle + NbCreneau-1) < FinBoucle)
 	      FinBoucle = (PositionActuelle + NbCreneau-1);
   	
           if ((FinBoucle - PositionActuelle +1) < NbCreneau)
   	      alert(ErreurManqueCreneau);
           else
	   {
   	       for (i=PositionActuelle-1;i<=FinBoucle-1;i++)
	       {
	     	if (chaine.charAt(i) == '0')
	     	   erreur = true;
      	       }
    		if(erreur)
    		   alert(ErreurManqueCreneau);
                else
	        {
    	      	 top.frames[0].IdRestaurant = top.frames[0].IdRestoChoisi;
	     	 top.frames[0].Restaurant   = top.frames[0].RestoChoisi;
    	     	 top.frames[0].IdRestoChoisi = 0;
    	     	 top.frames[0].RestoChoisi   ="";
     	         top.frames[0].HeureResa     = heure;
     	         
     	         parent.document.location=top.frames[0].url+"ChoixHeure&Arguments=-N"+top.frames[0].IdSession+",-N"+top.frames[0].IdPrestation+",-A"+heure+",-L"+top.frames[0].ModificationResa+",-N"+top.frames[0].IdResaModif+",-N"+top.frames[0].NumLayer + ",-A" + top.frames[0].CodeLangue;
	        }
	    }
	 }
	 else
	 {
	     /*résa rapide : on doit maintenant selectionner un groupe*/
	     /* on va calculer ici la taille max (TailleMax) du groupe que le client pourra selectionner */
	     TailleMax = 0;
	     cpt = PositionActuelle-1;
	     while( chaine.charAt(cpt)!= '0' && cpt < FinBoucle)
	     {
	  	TailleMax += parseInt(document.getElementById('CapaQuartHeure').value,10);
  	  	cpt++;
	     }
	     /* met à jour les variables globales */
	     top.frames[0].TailleMaxGrp = TailleMax;
	     top.frames[0].IdRestaurant = top.frames[0].IdRestoChoisi;
	     top.frames[0].Restaurant   = top.frames[0].RestoChoisi;
    	     top.frames[0].IdRestoChoisi = 0;
    	     top.frames[0].RestoChoisi   ="";
	     top.frames[0].HeureResa     = heure;
	     /* on appelle ensuite SelectGrp.html */
	     parent.document.location="/html/SelectGrp.html";
	 }
	 }
 }

function MAJInfoDyn(Heure, PositionActuelle)
{
 	if (top.frames[0].GroupeSelect == 0)
 	{
		/* Onglet Réservation rapide : le groupe n'a pas encore été selectionné */
 		document.getElementById('MouseOverHour').value = Heure;
 		document.getElementById('MouseOverNumber').value = PositionActuelle;
 		/* le curseur est sur un créneau horaire : on affiche les infos de taille max pour le groupe*/
 		LoadInfoDyn();
        }
        else
        {
            	/* Onglet Gerer votre compte : le groupe a été selectionné, on colore le(s) créneau(x) en fonction de la position du curseur de la souris */
            	/* Fin représente le nombre de créneaux a colorer.
		   Math.round(x) retourne l'entier le plus proche du résultat, ce qui permet de prendre en compte le fait que si le groupe fait x,5 créneaux, il faudra en fait x+1 créneaux*/
    		Fin = Math.round(top.frames[0].TailleGroupeSelect/parseInt(document.getElementById('CapaQuartHeure').value,10));
		if (Fin == 0)
		   Fin = 1;
		Fin = Fin + PositionActuelle - 1;
            	/* erreur vaut true s'il y a un créneau indisponible parmi les X créneaux nécessaires */
            	erreur = false;
            	chaine = document.forms[0].Dispo.value;
            	/*Si on déborde du planning, on ne fait rien */
            	if (Fin <= (Math.max(chaine.lastIndexOf("0"),chaine.lastIndexOf("1")) + 1))
            	{
 	   	       for (i=PositionActuelle-1;i<=Fin-1;i++)
		       {
	     	    	    if (chaine.charAt(i) == '0')
	     	       	       erreur = true;
      	               }
      	               if (erreur == false)
      	               {
            	       	  for(var i=PositionActuelle;i<=Fin ;i++)
 	  	 	  	eval("document.getElementById('"+ i +"').style.background ='#FFCCCC'");
		       }
  	 	}
        }
}

function LoadInfoDyn()
{
 	   if(parent.document.getElementById('AffPrestation').selectedIndex != '4')
 	   {
	       chaine = document.forms[0].Dispo.value;
	       FinBoucle = Math.max(chaine.lastIndexOf("0"),chaine.lastIndexOf("1")) + 1;
	       /*Calcule taille max pour la position actuelle du curseur sur le planning*/
	       TailleMax = 0;
	       cpt = eval("parseInt(document.getElementById('MouseOverNumber').value,10) - 1");
	       while( chaine.charAt(cpt)!= '0' && cpt < FinBoucle)
	       {
	  	      TailleMax += parseInt(document.getElementById('CapaQuartHeure').value,10);
  	  	      cpt++;
               }
	       /*Met à jour le bouton transparent dans planning.html pour affichage dynamique */
	       document.getElementById('InfoDyn').value = CapaciteAcc1 + document.getElementById('MouseOverHour').value +', \n'+ CapaciteAcc2 + TailleMax +NbPers;
	   }
}

function UnloadInfoDyn(PositionActuelle)
{
 	if (top.frames[0].GroupeSelect == 0)
 	{
  	        document.getElementById('MouseOverHour').value = '';
 	  	document.getElementById('MouseOverNumber').value = '';
 	   	/*désaffiche les infos*/
 	   	document.getElementById('InfoDyn').value = '';
 	}
	else
        {
	        Fin = Math.round(top.frames[0].TailleGroupeSelect/parseInt(document.getElementById('CapaQuartHeure').value,10));
            	if (Fin == 0)
		   Fin = 1;
		Fin = Fin + PositionActuelle - 1;
            	erreur = false;
            	chaine = document.forms[0].Dispo.value;
            	/*Si on déborde du planning, on ne fait rien */
            	if (Fin <= (Math.max(chaine.lastIndexOf("0"),chaine.lastIndexOf("1")) + 1))
            	{
 	   	       for (i=PositionActuelle-1;i<=Fin-1;i++)
		       {
	     	    	    if (chaine.charAt(i) == '0')
	     	       	       erreur = true;
      	               }
      	               if (erreur == false)
      	               {
            	       	  for(var i=PositionActuelle;i<=Fin ;i++)
 	  	 	  	eval("document.getElementById('"+ i +"').style.background ='#D2E987'");
	               }
  	 	}
 	}

}

/* pour le fichier reservationCreation.html */


function ListeResa()
{
	window.document.location="/html/ListeReservationGroupe.html";
}


/* pour le fichier valider.html */

function ferm(modifMP, modifClient, Client, MP, Session)
{
	if (modifMP)
	{ 
	   opener.parent.document.location="/Magic94Scripts/mgrqispi94.dll?appname=Tourismev9&prgname=ConfirmLogin&Arguments=-N"+Client+",-A"+ MP +",-N"+ Session;
	}
	if (modifClient)
	{
  	   opener.top.location.reload();
	}
	close();
}


function ModifCompoGroupe(GroupeMini, TrancheChauffeur, PresenceChauffeur)
{
 	document.forms[0].IdSession.value = top.frames[0].IdSession;
	if(document.forms[0].NbrePers.value=='' || document.forms[0].NbrePers.value < GroupeMini )
		alert(NbPersOblig + GroupeMini + Personne);
	else
	{
	    bool = false;
	    somme = 0;
	    for (i=1;i<=document.forms[0].CompteurFin.value;i++)
	    {
	     somme += parseInt(eval('document.forms[0].text'+i+'.value'),10);
	     if(eval('document.forms[0].text'+i+'.value')!= '')
               bool = true;
            }
    	    if(document.forms[0].NbrePers.value=='' && bool==false)
		alert(RensDetailGroupe);
	    else
	    if(parseInt(document.forms[0].NbrePers.value,10) != somme)
		alert(ErreurTotalGroupe);	
            else
            {
            if (PresenceChauffeur=='True')
            {
	       if(parseInt(eval(document.forms[0].text3.value,10)) > (parseInt(document.forms[0].NbrePers.value,10) / TrancheChauffeur))
	          alert(ErreurNbChauffeur)
     	       else
     	       {
     	          document.forms[0].target="_parent";
            	  document.forms[0].submit();
               }
	    }
     	    else
     	       {
     	          document.forms[0].target="_parent";
            	  document.forms[0].submit();
               }
	    }
    	}
}


function NewGrp(Provenance)
{
 	/*Complément de navigation :
	  ajout d'un paramètre supplémentaire
	  pour gerer correctement le retour de cet écran :
	  Provenance = 1 : Réserver rapidement
	  Provenance = 2 : Gèrer votre compte */
    	window.open(top.frames[0].url+'AppNveauGroupe&Arguments=-N'+ top.frames[0].IdClient +',-N'+top.frames[0].IdSession+',-Lfalse,-N0,-N'+Provenance , 'MainFrame', '');
}


function RemiseZero(Iframe)
{
 	 window.open('/html/bleu.html',Iframe,'');
}

function AideMenu()
{
 	 window.open('/html/AideMenu.html','Aide','');
}

function RetourPhaseInit()
{
 	 if (top.frames[0].OngletInit == 1)
 	  	 window.open(top.frames[0].url+'CreationResaRapide&Arguments=-N'+ top.frames[0].IdSession + ',-A' + top.frames[0].CodeLangue+',-Ltrue', 'MainFrame', '');
 	 else
	 if(top.frames[0].OngletInit == 3)	
 	         window.open('/html/GererGroupe.html', 'MainFrame', '');			
 	  	 
}

function ModificationPlanning(heure)
{
	    	parent.window.document.location=top.frames[0].url+"ModifPla&Arguments=-N"+top.frames[0].IdResaModif+",-A"+parent.document.forms[0].AffDateResa.value + ",-A" + parent.document.forms[0].Resto.value + ",-A" + heure + ",-N" + parent.document.forms[0].AffPrestation.value + ",-N" + top.frames[0].IdSession;		
}

function RetourChoixProduit()
{
 	 document.location=top.frames[0].url+"ChoixHeure&Arguments=-N"+top.frames[0].IdSession+",-N"+top.frames[0].IdPrestation+",-A"+top.frames[0].HeureResa +",-L"+top.frames[0].ModificationResa+",-N"+top.frames[0].IdResaModif+",-N"+top.frames[0].NumLayer + ",-A" + top.frames[0].CodeLangue;
}

function Load_Entree_Plan(Resto)
{
window.open("/magic94scripts/mgrqispi94.dll?appname=Tourismev9&prgname=Entree_Plan&Arguments=-A"+Resto,'', 'channelmode=no,toolbar=no,location=no,menubar=no,scrollbars=no,Left=150,top=100,width=700,height=580');
}
/************************************************/
/*	    Fonctions de verification		*/
/************************************************/

/* pour le fichier FicheClients.html */

function verif_email()
{
	var varp=document.forms[0].Mail.value;
	if (varp.indexOf("@")==-1)
	{
		alert(TestAt);
		return false;
	}
	if (varp.indexOf(".")==-1)
	{
		alert(TestPoint);
		return false;
	}

	if ((varp.indexOf(" ")!=-1)||(varp.indexOf(";")!=-1)||
	(varp.indexOf(",")!=-1)||
	(varp.indexOf("&")!=-1)||(varp.indexOf("é")!=-1)||
	(varp.indexOf("è")!=-1)||
	(varp.indexOf("¨")!=-1)||(varp.indexOf(";")!=-1)||
	(varp.indexOf("ç")!=-1)||
	(varp.indexOf("|")!=-1)||(varp.indexOf("°")!=-1)||
	(varp.indexOf("à")!=-1)||
	(varp.indexOf("¤")!=-1)||(varp.indexOf("ê")!=-1)||
	(varp.indexOf("%")!=-1)||
	(varp.indexOf("?")!=-1)||(varp.indexOf("!")!=-1)||
	(varp.indexOf("§")!=-1)||
	(varp.indexOf(":")!=-1)||(varp.indexOf("/")!=-1)||
	(varp.indexOf("²")!=-1)||
	(varp.indexOf("{")!=-1)||(varp.indexOf("}")!=-1)||
	(varp.indexOf("(")!=-1)||
	(varp.indexOf("[")!=-1)||(varp.indexOf("]")!=-1)||
	(varp.indexOf(")")!=-1)||
	(varp.indexOf("`")!=-1)||(varp.indexOf("=")!=-1)||
	(varp.indexOf("+")!=-1)||
	(varp.indexOf("<")!=-1)||(varp.indexOf(">")!=-1)||
	(varp.indexOf("~")!=-1)||
	(varp.indexOf("\\")!=-1)||(varp.indexOf("#")!=-1)||
	(varp.indexOf("'")!=-1)||
	(varp.indexOf("\"")!=-1)||(varp.indexOf("*")!=-1)||
	(varp.indexOf("^")!=-1))
	{
		alert(TestCaract);
		return false;
	}
	var indexa = varp.indexOf("@");
	var lindexa = varp.lastIndexOf("@");
	if (indexa != lindexa)
	{
		alert(TestunAt);
		return false;
	}
	var lindexp = varp.lastIndexOf("."); 
	if(lindexp < indexa)
	{
		alert(TestDomaine);
		return false
	}
	var longadr = varp.length;
	lastindex = longadr-1;
	if(lindexp == lastindex)
	{
		alert(TestExtension);
		return false;
	}
}


/* pour le fichier reservationCreation.html */
function isDateValid(chaineDate) {

   var ladate = (chaineDate).split("/");

   if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2]))) return false

   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]))

   var annee = unedate.getYear()
   if ((Math.abs(annee)+"").length < 4) annee = annee + 1900

   return ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])))
}

function ValidDateResa()
{

	if ((typeof DateJour) == 'undefined')
	{
		// on ne cree cette instance de l'objet Date qu'une seule fois
		DateJour = new Date();
	}

	chaine = document.forms[0].AffDateResa.value;

	Jour = chaine.substring(0,2);
	Mois = chaine.substring(3,5) - 1;
	Annee = chaine.substring(6,10);
	
	    if ((typeof Datetmp) == 'undefined')
	    {
		// on ne cree cette instance de l'objet Date qu'une seule fois
		Datetmp = new Date();
	    }
	    //Mise a jour de Datetmp
	    Datetmp.setDate(Jour);
	    Datetmp.setMonth(Mois);
	    Datetmp.setFullYear(Annee);

	    Diff = Datetmp.getTime() - DateJour.getTime();

	    if( Diff == 0 || Diff< 0)
		return false;
	    else
		return true;
}

/* pour le fichier ReservationCreation.html */
function RetourModif()
{
window.document.location=top.frames[0].url+"ModifResa&Arguments=-N"+top.frames[0].IdResaModif+",-N"+top.frames[0].IdSession+",-A"+top.frames[0].CodeLangue;
}



/* pour plusieurs fichiers */ 

function masqueSaisieChaineNum(obj, masque) {
  var ch = obj.value
  var tmp = ""
  var j = 0
  ch.toString()
  
  if (window.event.keyCode != 37 && window.event.keyCode != 39 && window.event.type != "keydown" && window.event.keyCode != 8 && window.event.keyCode != 46) {
    if (window.event.type == "keyup") {
      for (i=0; i<ch.length; i++) {
        if (!isNaN(ch.charAt(i)) && ch.charAt(i) != " ") { tmp += ch.charAt(i) }
      }
  
      ch = ""
  
      for (i=0; i<masque.length; i++) {
        if (masque.charAt(i)  == "0") { 
          if (tmp.charAt(j) != "" ) {
            ch += tmp.charAt(j)
            j++
          }
          else { ch += " " }
        }
        else { ch += masque.charAt(i) }
      }
    }
  
    obj.value = ch
  }
}

function SuppGrp(NumeroGroupe)
{
    if(confirm(SupprimerGrp))
 	parent.document.location=top.frames[0].url+"DeleteGrp&Arguments=-N" + NumeroGroupe;		
 	
}

function ModifGrp(NumeroGroupe)
{
 	 parent.document.location=top.frames[0].url+"AppNveauGroupe&Arguments=-N"+ top.frames[0].IdClient +",-N"+top.frames[0].IdSession+ ",-Ltrue,-N" + NumeroGroupe;
}

function VerifTailleGrp (Taille, IdGroupe, NomGroupe)
{
 	if (Taille > top.frames[0].TailleMaxGrp)
 	   alert(ErreurGroupe);
	else
	{
	   top.frames[0].GroupeSelect=IdGroupe;
	   top.frames[0].NomGroupeSelect=NomGroupe;
	   parent.document.location=top.frames[0].url+"ChoixHeure&Arguments=-N"+top.frames[0].IdSession+",-N"+top.frames[0].IdPrestation+",-A"+top.frames[0].HeureResa +",-L"+top.frames[0].ModificationResa+",-N"+top.frames[0].IdResaModif+",-N"+top.frames[0].NumLayer + ",-A" + top.frames[0].CodeLangue;
	}
}

/************************************************/
/*    Fonctions de selection dans une liste	*/
/************************************************/

function testresa(BlockEntree,BlockSortie)
{
	if (top.frames[0].IdPrestation != document.forms[0].AffPrestation.options[document.forms[0].AffPrestation.selectedIndex].value
		|| top.frames[0].DateResa != document.forms[0].AffDateResa.value
		|| top.frames[0].Restaurant != document.forms[0].AffRestaurant.value)
		return true;
	else
	{
	    	ToggleBlock(BlockEntree,BlockSortie);
		return false;
	}
}
function ToggleBlock(blk1,blk2)
{
    	document.getElementById(blk1).style.display = 'none';
 	document.getElementById(blk2).style.display = '';
}

function Menu()
{
        ToggleBlock('block1','block2');
	top.frames[0].HeureResa = document.forms[0].HeureResa.value;
	window.document.location=top.frames[0].url+"GestMenus&Arguments=-N"+top.frames[0].IdClient+",-N"+top.frames[0].GroupeSelect+",-N"+top.frames[0].NumCommande+",-N"+top.frames[0].IdPrestation+",-N"+top.frames[0].IdSession+",-L"+top.frames[0].ModificationResa+",-N"+top.frames[0].IdResaModif+",-A"+top.frames[0].CodeLangue+",-N" + top.frames[0].IdCmdeModif + ",-LTrue";
}

function CommandeTickets()
{
        ToggleBlock('block1','block2');
        top.frames[0].HeureResa = document.forms[0].HeureResa.value;		
	window.document.location=top.frames[0].url+"AppAchatTickets&Arguments=-N"+top.frames[0].IdClient+",-N"+top.frames[0].IdSession+',-L'+top.frames[0].ModificationResa+',-N'+top.frames[0].IdCmdeModif+',-Ltrue';

}

function RecapResa(Produit)
{
	ToggleBlock('block1','block2');
	document.forms[0].Produit.value = Produit;
	document.forms[0].submit();
}

/************************************************/
/*	    Coloriage des cellules		*/
/************************************************/
function ColorieCells(debut, fin, color)
{
 	 for(var i=debut;i<=fin ;i++)
 	  	 eval("document.getElementById('td"+ i +"').style.background =color");
}
/************************************************/
/*	    Calcul automatique			*/
/************************************************/
function AutoTotal()
{
 	NbCat = parseInt(document.forms[0].CatTotal.value,10);
	/*Calcul le total du groupe à créer */
	TotalGroupe = 0;
	for(cpt=1;cpt<=NbCat;cpt++)
	{
	  if(eval('document.forms[0].CAT'+cpt+'.value') != '')
	  	TotalGroupe +=eval('parseInt(document.forms[0].CAT'+cpt+'.value,10)');
	}	
  	 document.forms[0].NbrePers.value = TotalGroupe; 	
}
function AutoTotalModif()
{	
	 /* Fonction utilise lors de la modification d'un groupe dans une resa
	    ModifGroupe.html */
	 Total = 0;
	 
	 for(var i=1;i<=document.getElementById("TabGroupe").rows.length-5 ;i++)
 	{
		if (eval('document.forms[0].text'+i+'.value') != '')
			{
	  	  Total = Total + eval('parseInt(document.forms[0].text'+i+'.value,10)');
			}
	}
	
 	document.forms[0].NbrePers.value = Total;
}
function Incremente(lib,ModifResa)
{
 	 if(eval('document.forms[0].'+lib+'.value')== '')
	   Val= 1;
	else
	   Val = eval('parseInt(document.forms[0].'+lib+'.value,10)+1');
	   
 	 eval('document.forms[0].'+lib+'.value = '+Val);
 	 if (ModifResa == 'False')
 	    AutoTotal();
	 else
	    AutoTotalModif();
}
function Decremente(lib,ModifResa)
{
 	 if(eval('document.forms[0].'+lib+'.value')== ''||eval('document.forms[0].'+lib+'.value')== '0')
	   Val= 0;
	else
	   Val = eval('parseInt(document.forms[0].'+lib+'.value,10)-1');
	
 	 eval('document.forms[0].'+lib+'.value = '+Val);
 	 if (ModifResa == 'False')
 	    AutoTotal();
	 else
	    AutoTotalModif();
}
/************************************************/
/*	    Calendrier perpetuel		*/
/************************************************/


function MyGetDate(champs) {
IE = !(document.all?0:1);
NS = !IE;
dest = champs;
if (IE) {
// Taille du calendrier
  larg = 250; 
  Long = 188;
  posX = event.screenX; posY = event.screenY;
  if (posX+larg > screen.width) posX = screen.width - larg;
  if (posY+Long > screen.height) posY = screen.height - Long;
  eval("maFen = window.open('','FenDate','top='+posY+',left='+posX+',width="+larg+",height="+Long+",toolbar=no, location=no, directories=no, status=no, scrollbars=no, resizable=no');");
  maFen.focus();
  dessine();
  }
}

function dessine() {
txt = '<html><head><title>Choisissez une date.</title>\n';
txt += '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n';
txt += '<script>\n';
txt += 'var now = new Date();\nIE = !(document.all?0:1);\nNS = !IE;\n';
/* Gestion multilangue du calendrier */
if(top.frames[0].CodeLangue == 'FRA')
  txt += 'months = new Array(\'Janvier\',\'Fevrier\',\'Mars\',\'Avril\',\'Mai\',\'Juin\',\'Juillet\',\'Août\',\'Septembre\',\'Octobre\',\'Novembre\',\'Decembre\');\n';
else
if(top.frames[0].CodeLangue == 'ANG')
  txt += 'months = new Array(\'January\',\'February\',\'March\',\'April\',\'May\',\'June\',\'July\',\'August\',\'September\',\'October\',\'November\',\'December\');\n';
else
if(top.frames[0].CodeLangue == 'ESP')
  txt += 'months = new Array(\'Enero\',\'Febrero\',\'Marzo\',\'Abril\',\'Mayo\',\'Junio\',\'Julio\',\'Agosto\',\'Septiembre\',\'Octubre\',\'Noviembre\',\'Diciembre\');\n';
else
if(top.frames[0].CodeLangue == 'ITA')
  txt += 'months = new Array(\'Gennaio\',\'Febbraio\',\'Marzo\',\'Aprile\',\'Maggio\',\'Giugno\',\'Luglio\',\'Agosto\',\'Settembre\',\'Ottobre\',\'Novembre\',\'Dicembre\');\n';

txt += 'mois = now.getMonth();\nan = now.getFullYear();\njour = now.getDate();\nvide = "...";\n \n';

// Affectation des dates aux boutons
txt += 'function init() {\n';
txt += 'document.calendar.curMonth.value = months[mois] + " " + an;\n';
txt += 'document.calendar.curMonth.readOnly = true;\n';
txt += 'now.setMonth(mois);\n';
txt += 'now.setYear(an);\n';
txt += 'now.setDate(1);\n';
txt += 'for (i=0;i<now.getDay();i++) { eval("document.calendar.b"+0+i+".value = \' " + vide + " \' ;"); }\n';
txt += 'for (i=now.getDay();i<7;i++) {\n';
txt += '	    jour = "0"+now.getDate();\n';
txt += '		eval("document.calendar.b"+0+i+".value = \' "+jour+" \';");\n';
txt += '		now.setDate(now.getDate()+1);\n';
txt += '		}\n';
txt += 'for (j=1;j<6;j++) {\n';
txt += '	for (i=0;i<7;i++) {\n';
txt += '		if (jour==vide || now.getDate() < jour) { jour = vide; } else { jour = now.getDate(); }\n';
txt += '		if (jour < 10) { jour = "0"+jour; }\n';
txt += '		eval("document.calendar.b"+j+i+".value = \' "+jour+" \' ;");\n';
txt += '		now.setDate(now.getDate()+1);\n';
txt += '		}\n';
txt += '	}\n';
txt += '}\n\n';

// Mois suivant
txt += 'function next() {\n';
txt += 'if (mois == 11) { mois = 0; an = an + 1; } else { mois += 1; }\n';
txt += 'init();\n';
txt += '}\n\n';

// Mois precedent
txt += 'function prev() {\n';
txt += 'if (mois == 0) { mois = 11; an -= 1; } else { mois -= 1; }\n';
txt += 'init();\n';
txt += '}\n\n';

// 
txt += 'function lz(valeur) { if (valeur < 10) return("0"+valeur); else return(valeur); }\n\n';

// retour et fermeture du calendrier
txt += 'function done(but) {\n';
txt += 'txt = but.value.substr(1,2);\n';
txt += 'if (txt == vide.substr(1,2)) return;\n';

/*
   Si on veut l'annee sur 2 digits, ajouter ligne suivante :
   txt += 'an = an+""; an = an.substr(2,2);'; // Y2K compliant :o) comme ils disent là-bas.
*/

txt += 'txt = txt+"/"+lz(mois+1)+"/"+an;\n';
txt += 'opener.document.' + dest.form.name + '.' + dest.name + '.value = txt;\n';
txt += 'window.close();\n';
txt += '}\n';

txt += '</script>\n</head>\n<style>\n';
txt += 'td { font-weight: bold; text-align: center; }\n';

// Couleur des boutons
txt += 'input { cursor: hand; font-weight: bold; font_size: 6pt; text-align: center; color: #FE7236; background-color: white; BORDER-STYLE: none; BACKGROUND-IMAGE: url("/html/images/calendrier/element.gif"); background-repeat:no-repeat; background-position:center}\n';

// Texte
txt += 'td { font-size: 14px; }\n';

// Couleurs de fond de table et de document
txt +='</style>\n';
txt += '<body leftmargin="0" topmargin="0"; onLoad="init();" >\n';
//background="/html/images/fond_calendrier.gif"
txt += '<form name="calendar">\n';
txt += '<table border="0" cellspacing="2" cellpadding="0"  align=center>\n';
/* Affichage du mois */
txt += '<tr><td>\n';
txt += '<input type="button" style="WIDTH: 28px;color: #FFFFFF;BACKGROUND-IMAGE: url(/html/images/calendrier/element_back.gif);" name="bk" value="   " onclick="prev()"></div></td><td colspan=5>\n';
txt += '<input type="text" style="color: #FE4D01;BACKGROUND-IMAGE:none;FONT-FAMILY: Tahoma, sans-serif;" name="curMonth" size="20">\n';
txt += '</td><td><input style="WIDTH: 28px;color: #FFFFFF;BACKGROUND-IMAGE: url(/html/images/calendrier/element_next.gif);" type="button" name="bk" value="   " onclick="next()">\n</td></tr>';

/* Affichage des libéllés des jours en multi langue */
if(top.frames[0].CodeLangue == 'FRA')
   txt += '<tr style="color: #FE4D01;FONT-FAMILY: Tahoma, sans-serif;"><td>Dim</td><td>Lun</td><td>Mar</td><td>Mer</td><td>Jeu</td><td>Ven</td><td>Sam</td></tr>\n';
else
if(top.frames[0].CodeLangue == 'ANG')
   txt += '<tr style="color: #FE4D01;FONT-FAMILY: Tahoma, sans-serif;"><td>Sun</td><td>Mon</td><td>Tue</td><td>Wen</td><td>Thu</td><td>Fri</td><td>Sat</td></tr>\n';
else
if(top.frames[0].CodeLangue == 'ESP')
   txt += '<tr style="color: #FE4D01;FONT-FAMILY: Tahoma, sans-serif;"><td>Dom</td><td>Lun</td><td>Mar</td><td>Mie</td><td>Jue</td><td>Vie</td><td>Sab</td></tr>\n';
else
if(top.frames[0].CodeLangue == 'ITA')
   txt += '<tr style="color: #FE4D01;FONT-FAMILY: Tahoma, sans-serif;"><td>Dom</td><td>Lun</td><td>Mar</td><td>Mer</td><td>Gio</td><td>Ven</td><td>Sab</td></tr>\n';

// Creation des boutons
for (i=0;i<6;i++) {
  txt += '<tr>\n';
  for (j=0;j<7;j++) {
	txt += '<td><input type="button" style="WIDTH: 28px;" name="b'+i+j+'" onclick="done(this)"></td>\n';
    }
  txt += '</tr>\n';
  } 

txt += '</table></form></body>\n';

// Creation de la page
txt += '<script>\n';
txt += 'init();\n';
txt += '</script></html>\n';
maFen.document.write(txt);
}


