/********************************************************************************************/
// Variables globales
/********************************************************************************************/
var sitear='http://www.renault-trucks.it';
var squarear='http://www.renault-trucks.it/cafecentral';
/********************************************************************************************/
// Aficher / cacher le loading
/********************************************************************************************/
function loading(targetid) {
var chaine=document.getElementById(targetid).className;
// Si en train de loader, cacher le loader
if (chaine.indexOf('loading')!=-1) {
var reg=new RegExp("(loading)", "gi");
document.getElementById(targetid).className = chaine.replace(reg,'');
}
// Sinon, afficher le loader
else {
document.getElementById(targetid).className=chaine+' loading';
}
}
/********************************************************************************************/
// AJAX permet de charcher le contenu d un fichier dans un
/********************************************************************************************/
function load(url, targetid) {
// Sans autre instruction, utiliser le jardin
if (!targetid) {var targetid='backyard';}
var myAjax = new Ajax.Updater(targetid, url, {method:'get', evalScripts:true, onLoading:function () {loading(targetid)}, onComplete:function () {loading(targetid)}});
// var myAjax = new Ajax.Updater(targetid, url, {method:'get', evalScripts:true});
}
/********************************************************************************************/
// Post comment
/********************************************************************************************/
function poston(objet, onobjet) {
// A la fin, on load quoi ?
loadthis=sitear+'/node.php?ajx=refresh&what=make_'+objet+onobjet;
// Notre formulaire et notre liste
form='form'+objet+'on'+onobjet;
list='listof'+objet+'on'+onobjet;
// Ce que je fais
// alert('je post '+form+' et rafraichis '+list);
// aller, on poste en ajax
post(form, sitear+'/node.php?pageclef=form', null, true, null, loadthis, list);
}
/********************************************************************************************/
// AJAX permet de envoyer un formulaire sans reloader une page
/********************************************************************************************/
// Poster un formulaire
function post(form, url, etat, asynchronous, gohere, loadthat, loadithere, dothat, dothatarg) {
// Quel formulaire on envoie ?
if (!form){form='main';}
// Si le formulaire existe
if (document.getElementById(form)) {
// Loading ?
if (loading) {
var complete = function(objet) {loading(loading);}
}
// Si AJAX trouve la page
var success = function(objet) {
// Voilà le retour
// alert('dont panic, just a test :'+objet.responseText);
// Se rendre à l'objet ?
if (gohere=='reach') {location.href=objet.responseText;}
// Si gohere de n'importe quelle url, y aller
else if (gohere || loadthat || dothat) {
// Voilà ce que je fais
// alert(loadthat+' here '+loadithere);
if (loadthat) {load(loadthat+'&alerteclef='+objet.responseText, loadithere);}
if (gohere) {location.href=gohere;}
if (dothat) {window[dothat](dothatarg);}
}
// Ou montrer le contenu retourné ?
else if (objet.responseText) {alert(objet.responseText);}
// Sous Café Central : Pumpitdown
pumpitdown();
}
// Si AJAX retourne un echec
var failure = function(objet) {
alert('Error ' + objet.status + ' : ' + objet.statusText);
}
// Special TinyMCE : sauvegarder le contenu
if (typeof(tinyMCE)!='undefined') {tinyMCE.triggerSave();}
// On récupère les valeurs des champs
var content = Form.serialize(form);
// On ajoute l'etat demandé
if (etat) {
var table=document.getElementById('table').value;
content=content+'&'+table+'_setetat='+etat;
}
// Doit-on atteindre l'objet à la fin ?
if (gohere=='reach') {
content=content+'&return=reach';
}
// On envoie là où le form le demande
if (!url) {var url=document.getElementById(form).action;}
// Asynchrone par defaut
if (!asynchronous) {var asynchronous=true;}
// Et voilà
var query = new Ajax.Request(
url, {
asynchronous:asynchronous,
evalScripts:true,
method:'post',
parameters:content,
onComplete:complete,
onSuccess:success,
onFailure:failure /*pas de virgule ici pour ie6*/
}
);
}
// Si le formulaire n'existe pas mais qu'on a un goto
else if (gohere) {location.href=gohere;}
}
/********************************************************************************************/
// Vérifier les formulaires
/********************************************************************************************/
// Quelques fonctions de vérification
function is_ko(fieldid) {
// Ssi le champ existe
if (field=document.getElementById(fieldid)) {
// Récupérer le type de champ
type=getfieldtype(fieldid);
// Et vérifier le champ en fonction du type
switch (type) {
// Checkboxes ?
case 'checkbox' :
// Boucler pour voir si au moins une est cochée
var ok=null;
i=0;
while (document.getElementById(fieldid+i)) {
if (document.getElementById(fieldid+i).checked === true ) {ok=true;}
i=i+1;
}
if (!ok) {return true;}
break;
// Email ?
case 'email' :
if (field.value.indexOf('@')<0 || field.value.indexOf('.')<0 || field.value==0) {return true;}
break;
// Capcha
case 'captcha' :
if (field.value!=captcha) {return true;}
break;
// Date ?
case 'date' :
// Boucler pour voir si les trois (jour, mois, année) sont remplis
var mydate = field.getElementsByTagName('select');
var ko=false;
var year = mydate[2].options[mydate[2].selectedIndex].value;
var month = mydate[1].options[mydate[1].selectedIndex].value;
var day = mydate[0].options[mydate[0].selectedIndex].value;
if (day == '00') {ko=true;}
if (month == '00') {ko=true;}
if (year == '0000') {ko=true;}
source_date = new Date(year,month-1,day);
//alert(source_date);
if(year != source_date.getFullYear()) { ko=true; }
if(month-1 != source_date.getMonth()) { ko=true; }
if(day != source_date.getDate()) { ko=true; }
//alert(ko);
if (ko) {return true;}
break;
// Password check
case 'password_check' :
// Trouver le nom du champs qui est vérifié
checkedfield=fieldid.replace('_check', '');
// Si le champs password qu'on vérifie est vide
if (document.getElementById(checkedfield).value==0) {return true;}
// Si le champs password qu'on vérifie est rempli, mais qu'ils ne sont pas identiques
else if (document.getElementById(checkedfield) && field.value!=document.getElementById(checkedfield).value) {return true;}
break;
// Password (Comme une chaine)
case 'password' :
// Pour les chaines et tout le reste
default:
// Pour les chaines avec taille limite (min ou max)
control=type.substr(0,3);
if (control=='min' || control=='max') {
// Limite ?
limit=type.substr(3);
if (control=='min' && field.value.lengthlimit) {return true;}
}
// Les autres chaines ne doivent pas être vides
else if (field.value==0 || (field.value==field.title && field.value.indexOf('flush')==-1)) {return true;}
break;
}
}
}
/********************************************************************************************/
// Récupérer le type d'un champ dans un formulaire standard Café Central
/********************************************************************************************/
function getfieldtype(fieldid) {
// SSI le li a la bonne id
if (document.getElementById(fieldid).parentNode) {
type=document.getElementById(fieldid).parentNode.className.replace('compulsory', '');
type=type.replace(' ', '');
return type;
}
}
/********************************************************************************************/
// Savoir si un champ est obligatoire ou pas
/********************************************************************************************/
function is_compulsory(fieldid) {
// SSI le li a la bonne id
if (document.getElementById(fieldid).parentNode) {
if (document.getElementById(fieldid).parentNode.className.indexOf('compulsory')!=-1) {return true;}
}
}
/********************************************************************************************/
// Fonction de vérification des formulaires (lit les lignes avec la class "compulsory")
var firstkofield=null;
/********************************************************************************************/
function check(formid) {
// SSi le form existe
if (document.getElementById(formid)) {
// Récupérer la liste des champs compulsory
FORMfields=document.getElementById(formid).getElementsByTagName("li");
// Construire le tableau des champs compulsory
COMPULSORYfield = new Array();
for (var i=0; i textarea.clientHeight && !window.opera) {textarea.rows += 1};
}
/********************************************************************************************/
// Changer une class
/********************************************************************************************/
function switchclass(id, newclass) {
var chaine=document.getElementById(id).className;
// Si la classe est déjà montée, l'enlever
if (chaine.indexOf(newclass)!=-1) {
chaine=document.getElementById(id).className=chaine.replace(newclass, '');
chaine=document.getElementById(id).className=chaine.replace(' '+newclass, '');
}
// Sinon, l'ajouter
else {document.getElementById(id).className = chaine+' '+newclass;}
}
/********************************************************************************************/
// Ne pas quitter la page avec un formulaire commencé...
/********************************************************************************************/
var THISform_modified=null;
var THISform_saved=null;
function confirmexit() {
if (THISform_modified && !THISform_saved) {return 'Si vous quittez ce formulaire, tous vos changements seront perdus.';}
}
/********************************************************************************************/
// Input Placeholder Text
/********************************************************************************************/
/* Project: Input Placeholder Text
Title: Automatic population of form fields with contents of title attributes
Created: 13 August 2005 by Jon Gibbins (aka dotjay)
Modified: 13 November 2006 by Jon Gibbins (aka dotjay)
Add the following classes to text inputs or textareas to get the desired behaviour:
auto-select : Will pre-populate the input with the title attribute and select the text when it receives focus.
auto-clear : Will pre-populate the input with the title attribute and clear the text when it receives focus.
populate : Will just populate the input with the title attribute.
Note: if auto-select and auto-clear are set, auto-select takes precedence.
*/
function populateforms() {
if (!document.getElementsByTagName) return true;
ourForms = document.getElementsByTagName('form');
// go through each form
var numForms = ourForms.length;
for (var i=0;i