//////////////////////////////////////////////////////////////////////////////////////////
//
//	Fichier		: identitemes.js
//      Permet la sauvegarde et la récupération d'une identité donnée dans un formulaire dans un cookie
//      Nécessite des fonctions codées dans cookie.js
//	Dernière mise à jour : 19/01/2001
//
//
//	Historique des mises à jour :
//
//      19/01/2001 : adaptation au formulaire a-et-a.com 
//
//      Exemple d'utilisation :
//// Fonction appelée au chargement de la page :
//p = new Usermes("", "", "", "", "", "", "", "", "", "", "", "");
//function initformnom()
//{
//  p.name = "Usermes";
//  p.constructor.name = "Usermes" ;
//  p = getUsermesFromCookie();
//  p.getIdentityToForm(document.forms[0]);
//  document.forms[0].Nom.select();
//  document.forms[0].Nom.focus();
//}
//
//// Fonction appelée à l'envoi du formulaire
//function validation(objet)
//{
//  if (val(objet)==true)
//	{
//	alert("Le formulaire est correct, vous pouvez l\'imprimer.");
//// 1er Cookie Netscape 4.7 et IE5
//	p.name = "Usermes";
//	p.constructor.name = "Usermes" ;
//      p.setIdentityFromForm(document.forms[0]);
//    	p.saveToCookie();
// 2eme Cookie pour compatibilité avec IE4
//    	p.name = "undefined";
//	p.constructor.name = "undefined" ;
//      p.setIdentityFromForm(document.forms[0]);
//    	p.saveToCookie();	
//	};   
//  return false;
//}	
//////////////////////////////////////////////////////////////////////////////////////////


//
// ************************************ Classe Usermes **************************************
//

// ---------------------------------------------------------------------------------------
// Nom		: Usermes(Titre, Nom, Prenom, Societe, Adresse, Code_postal, Ville, Etat, Pays, Email, Telephone, m1, m2, m3, m4, m5, m6, m7, m8, m9,m10, m11, m12, m13, m14, m15, m16, m17, m18, m19, m20, m21, m22)
// Classe	: Usermes
// Description	: Construit un nouvel objet de classe Usermes. C'est un utilisateur 
// 		  caractérisé par son nom, son prénom et son adresse e-mail
//		  - Cette fonction étant le constructeur de la classe, toute nouvelle
//		    propriété ou méthode devra etre ajoutée dans cette fonction
// Entrée	: Nom    - String - nom de l'utilisateur
//		  Prenom - String - prénom de l'utilisateur
//		  Email  - String - adresse e-mail de l'utilisateur

function Usermes(Titre, Nom, Prenom, Adresse, Code_postal, Ville, Etat, Pays, Email, Telephone, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19, m20, m21, m22) 
{
	// Propriétés
//alert("Usermes") ;
	this.Titre = Titre;
	this.Nom = Nom;
	this.Prenom = Prenom;
	this.Adresse = Adresse;
	this.Code_postal = Code_postal;
	this.Ville = Ville;
	this.Etat = Etat;
	this.Pays = Pays;
	this.Email = Email;
	this.Telephone = Telephone;
	// mesures à mémoriser	
	this.m1 = m1;
	this.m2 = m2;
	this.m3 = m3;
	this.m4 = m4;
	this.m5 = m5;
	this.m6 = m6;
	this.m7 = m7;
	this.m8 = m8;
	this.m9 = m9;
	this.m10 = m10;
	this.m11 = m11;
	this.m12 = m12;	
	this.m13 = m13;
	this.m14 = m14;
	this.m15 = m15;
	this.m16 = m16;
	this.m17 = m17;
	this.m18 = m18;
	this.m19 = m19;
	this.m20 = m20;
	this.m21 = m21;
	this.m22 = m22;
	// Méthodes
	this.saveToCookie        = saveToCookie;
	this.setIdentityFromForm = setIdentityFromForm;
	this.getIdentityToForm   = getIdentityToForm;
	this.identityIsValid     = identityIsValid;
}


// ---------------------------------------------------------------------------------------
// Nom		: saveToCookie()
// Classe	: Usermes
// Description	: Sauve les propriétés de l'objet dans le cookie "Usermes"
//		  - Le chemin est "/" car Usermes est un cookie "global", le domaine est le
//		    domaine courant (qui peut etre positionné par setCookieDomain()).
function saveToCookie() {
	var cookiePath = getCookiePath();	//  sauvegarder le path
	setCookiePath("/");
	setCookieFromObject(this);
	setCookiePath(cookiePath);		// restituer le path
}


// ---------------------------------------------------------------------------------------
// Nom		: setIdentityFromForm(form)
// Classe	: Usermes
// Description	: Recupère l'identité (nom, prénom, e-mail) d'un utilisateur à partir du
//		  formulaire spécifié.
//		  - Ce formulaire doit obligatoirement contenir des champs de type text
//		    nommés "Nom", "Titre" et "Email" car les données sont lues dans ces
//		    champs
//		  - De plus, ces trois champs ("Nom", "Titre" et "Email") doivent etre
//		    tous les trois non vide pour que l'objet les recupère.
// Entrée	: form - Form - Formulaire dans lequel sont lus Nom, Prenom et Email
// Retour	: Boolean :
//		  - true si les trois champs "Nom", "Titre" et "Email" sont tous non 
//		    vides (l'objet a alors gardé ces trois valeurs)
//		  - false si au moins un des trois champs "Nom", "Titre" et "Email" est
//		    vide (l'état de l'objet reste inchangé)
function setIdentityFromForm(form) 
{
	//if (form.Nom.value!="" && form.Titre.value!="" && form.Email.value!="") 
	//{
		this.Titre    = form.Titre.value;
		this.Nom    = form.Nom.value;
		this.Prenom = form.Prenom.value;
		
		this.Adresse = form.Adresse.value;
		this.Code_postal = form.Code_postal.value;
		this.Ville = form.Ville.value;
		this.Etat = form.Etat.value;
		this.Pays = form.Pays.value;
		this.Email  = form.Email.value;
		this.Telephone = form.Telephone.value;
		
	this.m1 = form.m1.value;
	this.m2 = form.m2.value;
	this.m3 = form.m3.value;
	this.m4 = form.m4.value;
	this.m5 = form.m5.value;
	this.m6 = form.m6.value;
	this.m7 = form.m7.value;
	this.m8 = form.m8.value;
	this.m9 = form.m9.value;
	this.m10 = form.m10.value;
	this.m11 = form.m11.value;
	this.m12 = form.m12.value;
	this.m13 = form.m13.value;
	this.m14 = form.m14.value;
	this.m15 = form.m15.value;
	this.m16 = form.m16.value;
	this.m17 = form.m17.value;
	this.m18 = form.m18.value;
	this.m19 = form.m19.value;
	this.m20 = form.m20.value;
	this.m21 = form.m21.value;
	this.m22 = form.m22.value;	
		return true;
	//} else
	//	return false;
}


// ---------------------------------------------------------------------------------------
// Nom		: getIdentityToForm(form)
// Classe	: Usermes
// Description	: Charge l'identité (nom, prénom, e-mail) d'un utilisateur dans le
//		  formulaire spécifié.
//		  - Ce formulaire doit obligatoirement contenir des champs de type text
//		    nommés "Nom", "Prenom" et "Email"
// Entrée	: form - Form - Formulaire dans lequel la méthode place le nom, le prénom
//			et l'e-mail respectivement dans les champs nommés "Nom", "Prenom"
//			et "Email"
function getIdentityToForm(form) 
{
	form.Titre.value    = this.Titre ;
	form.Nom.value    = this.Nom ;
	form.Prenom.value = this.Prenom ;
	
	form.Adresse.value = this.Adresse ;
	form.Code_postal.value = this.Code_postal ;
	form.Ville.value = this.Ville ;
	form.Etat.value = this.Etat;
	form.Pays.value = this.Pays ;
	form.Email.value  = this.Email ;
	form.Telephone.value  = this.Telephone ;
	
	form.m1.value = this.m1;
	form.m2.value = this.m2;
	form.m3.value = this.m3;
	form.m4.value = this.m4;
	form.m5.value = this.m5;
	form.m6.value = this.m6;
	form.m7.value = this.m7;
	form.m8.value = this.m8;
	form.m9.value = this.m9;
	form.m10.value = this.m10;
	form.m11.value = this.m11;
	form.m12.value = this.m12;
	form.m13.value = this.m13;
	form.m14.value = this.m14;
	form.m15.value = this.m15;
	form.m16.value = this.m16;
	form.m17.value = this.m17;
	form.m18.value = this.m18;
	form.m19.value = this.m19;
	form.m20.value = this.m20;
	form.m21.value = this.m21;
	form.m22.value = this.m22;
	
}


// ---------------------------------------------------------------------------------------
// Nom		: identityIsValid()
// Description	: Retourne true si l'identité {Nom, Prenom, Email} est correcte (c'est à
//		  dire si les trois données sont non vides) ou bien false sinon
// Retour	: Boolean - true si les trois propriétés Nom, Prenom et Email sont toutes 
//		  renseignées ou bien false sinon
function identityIsValid() {
	return (this.Nom!="" && this.Prenom!="" & this.Email!="");
}

//
// ********************************* Fonctions globales **********************************
//


// ---------------------------------------------------------------------------------------
// Nom		: getUsermesFromCookie()
// Description	: Renvoie un objet de classe Usermes dont les propriétés sont lues dans le
//		  cookie "Usermes".
//		  - Les propriétés lues dans le cookie sont placées de manière "brute"
//		    dans l'objet retourné, cela suppose que les valeurs du cookie sont
//		    intègres car aucune vérification n'est faite par cette fonction
//		  - Seules les propriétés lues sont positionnées : si l'objet possède des
//		    propriétés qui ne figurent pas dans le cookie alors les valeurs de 
//		    ces propriétés, pour l'objet retourné, restent à "undefined"
//		  - Les méthodes, si elles existent, sont définies
// Retour	: Usermes - objet de classe Usermes avec les propriétés positionnées aux valeurs
//			du cookie "Usermes", ou new Usermes("", "", "") si le cookie "Usermes" 
//			n'existe pas
function getUsermesFromCookie() {
	var aUsermes ;
//	var aUsermes = new Usermes("", "", "", "", "", "", "", "", "", "", "", "");
//	getCookieToObject(aUsermes);
	aUsermes = getCookieToObject("Usermes");
	
//alert(aUsermes.name) ;
if (aUsermes == null) { aUsermes = new Usermes("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "")};
aUsermes.name = "Usermes";
aUsermes.constructor.name = "Usermes";
// alert(aUsermes.name) ;
return  (aUsermes) ;

//      return ( (aUsermes == null) ? new Usermes("", "", "", "", "", "", "", "", "", "", "", "") : aUsermes );

}


//
//////////////////////////////////////////////////////////////////////////////////////////
// fin du fichier identitemes.js
//////////////////////////////////////////////////////////////////////////////////////////







