1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
function dateExpire()
{
var date = new Date;
var dtExpiration = new Date;
date.setTime(date.getTime() + 3600 * 1000);
dtExpiration.setTime(dtExpiration.getTime() + 365 * 24 * 3600 * 1000);
return dtExpiration;
}
/***************************************************/
function checkCookies()
{
if(document.cookie.length == 0)
{
window.open("formulaire.html");
}else{
actualCookie(); //Appele une fct.
}
}
/***************************************************/
function setFormulaire(objForm)
{
var msgAlert = "";
var title = objForm.chListe.value;
var prenom = objForm.chPrenom.value;
var nom = objForm.chNom.value;
var email = objForm.chMail.value;
var condition = objForm.chCondition.value;
if(objForm.chListe.value == ""){
msgAlert += "Veuillez indetifier votre titre.\n";
}
if(objForm.chPrenom.value == ""){
objForm.chPrenom.style.backgroundColor = "#F00";
msgAlert += "Veuillez encoder votre prenom.\n";
}
if(objForm.chNom.value == ""){
objForm.chNom.style.backgroundColor = "#F00";
msgAlert += "Veuillez encoder votre nom.\n";
}
if(objForm.chMail.value == ""){
objForm.chMail.style.backgroundColor = "#F00";
msgAlert += "Veuillez encoder votre email.\n";
}
else{
var txtMail = objForm.chMail.value;
var regMail = new RegExp("^[0-9a-z._-]+@{1}[0-9a-z.-]{2,}[.]{1}[a-z]{2,5}$", "i");
if(regMail.test(txtMail) == false){
msgAlert += "Votre email n\'est pas valide.\n";
}
}
if(!objForm.chCondition.checked){
msgAlert += "Veuillez accepter le condition.\n";
}
if(msgAlert == ""){
setCookie(title, prenom, nom, email, condition, objForm); //Appele d'une fct.
return(true);
}
else{
alert(msgAlert);
}
return(false);
}
/***************************************************/
function setCookie(title, prenom, nom, email, condition, objForm){
var nameCookieTitre = "titre";
var nameCookiePre = "prenom";
var nameCookieNom = "nom";
var nameCookieMail = "mail";
var nameCookieCtrct = "condition";
var valTitre = title;
var valPrenom = prenom;
var valNom = nom;
var valMail = email;
var valContract = condition;
var dtexpires = dateExpire(); //Appele fct.
document.cookie = nameCookieTitre + "=" + escape(valTitre) + ((dtexpires==null) ? "" : ("; expires="+dtexpires.toGMTString()));
document.cookie = nameCookiePre + "=" + escape(valPrenom) + ((dtexpires==null) ? "" : ("; expires="+dtexpires.toGMTString()));
document.cookie = nameCookieNom + "=" + escape(valNom) + ((dtexpires==null) ? "" : ("; expires="+dtexpires.toGMTString()));
document.cookie = nameCookieMail + "=" + escape(valMail) + ((dtexpires==null) ? "" : ("; expires="+dtexpires.toGMTString()));
document.cookie = nameCookieCtrct + "=" + escape(valContract) + ((dtexpires==null) ? "" : ("; expires="+dtexpires.toGMTString()));
window.open("page_1.html");
}
/***************************************************/
function getCookie(){
var nameCookiePre = "prenom";
var regCookies = new RegExp("(; )","g");
var cookies = document.cookie.split(regCookies);
for(var i=0; i<cookies.length; i++){
var regInfo = new RegExp("=","g");
var infos = cookies[i].split(regInfo);
if(infos[0] == nameCookiePre){
return unescape(infos[1]);
}
}
}
/***************************************************/
function actualCookie()
{
var tArrays = new Array();
contenu = document.cookie;
var listeCookies = contenu.split("; ");
nombre = listeCookies.length;
for(compteur=0;compteur<nombre;compteur++)
{
monCookie = listeCookies[compteur].split("=");
tArrays[compteur] = unescape(monCookie[1]);
}
var title = tArrays[0];
var prenom = tArrays[1];
var nom = tArrays[2];
var email = tArrays[3];
var condition = tArrays[4];
setCookie(title, prenom, nom, email, condition); //Appele une fct.
}
/***************************************************/
function getMotPolitesse(){
var ladate = new Date();
var h = ladate.getHours();
var prenom = getCookie();
if(h>18){
return document.write("Bonsoir " + prenom);
}else{
return document.write("Bonjour " + prenom);
}
}
/***************************************************/
function addFormulaire()
{
var tArrays = new Array();
contenu = document.cookie;
var listeCookies = contenu.split("; ");
nombre = listeCookies.length;
for(compteur=0;compteur<nombre;compteur++)
{
monCookie = listeCookies[compteur].split("=");
tArrays[compteur] = unescape(monCookie[1]);
}
var valTitre = tArrays[0];
var valPrenom = tArrays[1];
var valNom = tArrays[2];
var valMail = tArrays[3];
var valContract = tArrays[4];
var nameCookieTitre = "titre";
var nameCookiePre = "prenom";
var nameCookieNom = "nom";
var nameCookieMail = "mail";
var nameCookieCtrct = "condition";
var hWindow = window.open("formulaire.html");
hWindow.document.forms["formUser"].elements["chListe"].value = valTitre;
hWindow.document.forms["formUser"].elements["chPrenom"].value = valPrenom;
hWindow.document.formUser.chNom.value = valNom;
hWindow.document.formUser.chMail.value = valMail;
hWindow.document.formUser.chCondition.checked = valContract;
} |
Partager