//--------------------------------------------------------------------------
// isInteger : Le paramètre passé est-il un entier ?
//--------------------------------------------------------------------------
function isInteger(inputStr){
var oneChar=' ';for (var i=0;i<inputStr.length;i++){oneChar= inputStr.substring(i,i+1);if ((oneChar<'0'||oneChar>'9')){return false;}}return true;}

//--------------------------------------------------------------------------
// isVide : Le contenu(champ) du champ de formulaire(formName) est-il vide ?
// Si vide : Renvoie 'letitre' + FAUX, sinon renvoie 'VRAI'
//--------------------------------------------------------------------------
function isVide(formName, champ, letitre){
with(eval('document.' + formName)){str=eval(champ+'.value');if (str==''){alert(letitre);eval(champ).focus();return false;}}alert(str);return true;}

//--------------------------------------------------------------------------
// isCorrectText : Le contenu(champ) du champ de formulaire(formName) est-il vide ?
// ou est il rempli avec 3 caracteres identiques ?
// Renvoie 'letitre' + FAUX, sinon renvoie 'VRAI'
//--------------------------------------------------------------------------
function isCorrectText(formName, champ, letitre){
	with(eval('document.' + formName)){
		str=eval(champ+'.value');
		valid = true;
		switch(str.length) {
			case 0 :
				valid	= false;
				break;
			case 1 :
				valid	= false;
				break;
			case 2 :
				if (str.charAt(0)==str.charAt(1))
					valid	= false;
			case 3 :
				if (str.charAt(0)==str.charAt(1) && str.charAt(1)==str.charAt(2))
					valid	= false;
			default :
				if (str.charAt(0)==str.charAt(1) && str.charAt(1)==str.charAt(2))
					valid	= false;
		}
		if (valid)
			return true;
		else {
			alert(letitre);
			eval(champ).focus();
			return false;
		}
	}
}
//--------------------------------------------------------------------------
// verifDate : vérifie si la date est valable + si elle n'est pas inferieure à la date du jour.
// formName=Nom du formulaire, champ=Nom du champ, message=message affiché si erreur, suptoday= impose que la date soit supérieure à la date du jour
//--------------------------------------------------------------------------
function verifDate(formName, champ, message, suptoday){
var days;var dateJour=new Date();var jour=dateJour.getDate();var mois=dateJour.getMonth()+1;var annee=dateJour.getFullYear();var dateVal,tabdateVal;
with(eval('document.'+formName)){dateVal=eval(champ +'.value');}
if(dateVal.length==0){alert(message);return false;}tabdateVal=dateVal.split("/");
if(tabdateVal[0].length<1||tabdateVal[0].length>2){alert('erreur sur le jour');return false;}else{if(isInteger(tabdateVal[0])){if(tabdateVal[0]>31||isNaN(tabdateVal[0])||tabdateVal[0]<1){alert('erreur sur le jour');return false;}}else{alert(message);return false;}}
if(tabdateVal[1].length<1||tabdateVal[1].length>2){alert('erreur sur le mois');return false;}else{if(isInteger(tabdateVal[1])){if(tabdateVal[1]>12||isNaN(tabdateVal[1])||tabdateVal[1]<1){alert('erreur sur le mois');return false;}}else{alert(message);return false;}}
if(tabdateVal[2].length!=4){alert('erreur sur l\'année');return false;}else{if(isInteger(tabdateVal[2])){if(isNaN(tabdateVal[2])||tabdateVal[2]<1){alert('erreur sur l\'année');return false;}}else{alert(message);return false;}}
var LaDate=new Date(tabdateVal[2],tabdateVal[1]-1,tabdateVal[0],00,00,00,00);if (LaDate.getDate()!=tabdateVal[0]||LaDate.getMonth()+1!=tabdateVal[1]||LaDate.getFullYear()!=tabdateVal[2]){alert('Cette date n\'existe pas');return false;}
if (suptoday) {
	
	days=Math.floor((dateJour-LaDate)/86400000);
	if(days>0) {
		alert('Date inférieure à la date du jour !');
		with(eval('document.'+formName)){
			eval(champ).focus();
		}
		return false;
	}
}
return true;}

//--------------------------------------------------------------------------
// verifDate : vérifie si la date est valable.
// formName=Nom du formulaire, champ=Nom du champ, message=message affiché si erreur
//--------------------------------------------------------------------------
function verifDate2(formName, champ, message){
var days;var dateJour=new Date();var jour=dateJour.getDate();var mois=dateJour.getMonth()+1;var annee=dateJour.getFullYear();var dateVal,tabdateVal;
with(eval('document.'+formName)){dateVal=eval(champ +'.value');}
if(dateVal.length==0){alert(message);return false;}tabdateVal=dateVal.split("/");
if(tabdateVal[0].length<1||tabdateVal[0].length>2){alert('erreur sur le jour');return false;}else{if(isInteger(tabdateVal[0])){if(tabdateVal[0]>31||isNaN(tabdateVal[0])||tabdateVal[0]<1){alert('erreur sur le jour');return false;}}else{alert(message);return false;}}
if(tabdateVal[1].length<1||tabdateVal[1].length>2){alert('erreur sur le mois');return false;}else{if(isInteger(tabdateVal[1])){if(tabdateVal[1]>12||isNaN(tabdateVal[1])||tabdateVal[1]<1){alert('erreur sur le mois');return false;}}else{alert(message);return false;}}
if(tabdateVal[2].length!=4){alert('erreur sur l\'année');return false;}else{if(isInteger(tabdateVal[2])){if(tabdateVal[2]<annee||isNaN(tabdateVal[2])||tabdateVal[2]<1){alert('erreur sur l\'année');return false;}}else{alert(message);return false;}}
var LaDate=new Date(tabdateVal[2],tabdateVal[1]-1,tabdateVal[0],00,00,00,00);if (LaDate.getDate()!=tabdateVal[0]||LaDate.getMonth()+1!=tabdateVal[1]||LaDate.getFullYear()!=tabdateVal[2]){alert('Cette date n\'existe pas');return false;}
return true;}

//--------------------------------------------------------------------------
// CompareDate : compare deux dates afin de s'assurer que la 1ere n'est pas inférieure à la 2eme
//--------------------------------------------------------------------------
function compareDate(date1,date2) {
var tabdateVal1=date1.split("/");
var tabdateVal2=date2.split("/");
var date1MS=Date.UTC(tabdateVal1[2],tabdateVal1[1]-1,tabdateVal1[0]);
var date2MS=Date.UTC(tabdateVal2[2],tabdateVal2[1]-1,tabdateVal2[0]);	
if(date1MS>date2MS) return 0;if(date1MS==date2MS) return -1;return true;}

//--------------------------------------------------------------------------
//	Compte le nombre de caractères d'un textarea et arrète la saisie lorsqu'il est atteint.
//--------------------------------------------------------------------------
function CheckLen(formName,Target,Longueur,CPTName){	
var CharsLeft,StrLen=Target.value.length;
if(StrLen>Longueur){Target.value=Target.value.substring(0,Longueur);CharsLeft=Longueur;}
else{CharsLeft=StrLen;}
eval('document.'+formName+'.'+CPTName).value=CharsLeft;}

//--------------------------------------------------------------------------
//	Vérifie la validité du champ mail.
//--------------------------------------------------------------------------
function isEmail(formName, champ, letitre){
	with(eval('document.' + formName)){
		str=eval(champ+'.value');
		if ((str.length) < 2){
			alert(letitre);
			eval(champ).focus();
			return false;
		}
		if (str.indexOf ('@',0)==-1 || str.indexOf ('.',0)==-1){
			alert(letitre);
			eval(champ).focus();
			return false;
		}
		var oneChar=' ';
		for (var i=0; i<str.length; i++){
			oneChar= str.substring(i,i+1);
			if (oneChar==' '){
				alert(letitre);
				eval(champ).focus();
				return false;
			}
		}
		return true;
   }
}

function checkRadio(champ, message) {
	if (champ.length) {
		for (var i=0; i<champ.length; i++) {
			if (champ[i].checked) return true;
		}
	} else if (champ.checked) return true;
	alert(message);
	return false;
}

function validationClick (){
	if (!checkRadio(document.forms.form1.civilite,'You have to inform correctly the Title.')) return false;
	if (!isCorrectText('form1','nom','You have to inform correctly the \'Last name\'.')) return false;
	if (!isCorrectText('form1','societe','You have to inform correctly the \'Company\'.')) return false;
	if (!isCorrectText('form1','adresse','You have to inform correctly the \'Addresse\'.')) return false;
	if (!isCorrectText('form1','cp','You have to inform correctly the \'Postcode\'.')) return false;
	if (!isCorrectText('form1','ville','You have to inform correctly the \'Town/city\'.')) return false;
	if (!isCorrectText('form1','pays','You have to inform correctly the \'Country\'.')) return false;	
	if (!isCorrectText('form1','tel','You have to inform correctly the \'Telephone\'.')) return false;
	if (!isEmail('form1','email','You have to inform correctly the \'E-mail\'.')) return false;
	return true;
}

function validationClick2 (){
	if (!validationClick()) return false;
	if (!isCorrectText('form1','situation_geo','You have to inform correctly the Location.')) return false;
	if (!isCorrectText('form1','domaine_utilisation','You have to inform correctly the Site specifications.')) return false;
	if (!isCorrectText('form1','carac_technique','You have to inform correctly the Technical requirements.')) return false;
	return true;
}

function validationClick3(){
	if (!checkRadio(document.forms.form1.objet_demande,'You have to inform correctly your request.')) return false;
	if (!checkRadio(document.forms.form1.civilite,'You have to inform correctly the Title.')) return false;
	if (!isCorrectText('form1','nom','You have to inform correctly the \'Last name\'.')) return false;
	if (!isCorrectText('form1','societe','You have to inform correctly the \'Company\'.')) return false;
	if (!isCorrectText('form1','adresse','You have to inform correctly the \'Addresse\'.')) return false;
	if (!isCorrectText('form1','cp','You have to inform correctly the \'Postcode\'.')) return false;
	if (!isCorrectText('form1','ville','You have to inform correctly the \'Town/city\'.')) return false;
	if (!isCorrectText('form1','pays','You have to inform correctly the \'Country\'.')) return false;	
	if (!isCorrectText('form1','tel','You have to inform correctly the \'Telephone\'.')) return false;
	if (!isEmail('form1','email','You have to inform correctly the \'E-mail\'.')) return false;
	return true;
}