// JavaScript Document
function zoom(idzoom,e,sens,w,t) {
	var posx = 0;
	var posy = 0;
	if (!w) var w = 200;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}

	with (document.getElementById(idzoom).style) {
		display='block';
		left = posx - ((sens == 'g') ? w-70 : 0);
		top = parseInt(posy) + (t);
	}
}

function hidezoom(idzoom) {
	with (document.getElementById(idzoom).style) {
		display='none';
	}
}

var _dateFormatee = "";
function ctrlDate(val) { 
	var dureeMois = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
	var tmpString = "";
	var tmpChar = "";
	var tmpDate = "";
	var dateDuJour = new Date();
	var tmpAnnee = 0;
	var flagOk = 0;
	var tmpJJ = "";
	var tmpMM = "";
	var tmpAAAA = "";
	var nbJoursMois = 0;
	var testJJ = 0;
	var testMM = 0;

	//--> On recupere l'annee
	tmpAnnee = dateDuJour.getYear();
	if ( tmpAnnee < 2000 )
		tmpAnnee+=1900;	
	//--> La  date est vide...
	if ( val.length == 0 )
		return -1;

	for ( i=0; i < val.length ; i++ ) {
		tmpChar = val.substr(i,1);
		if ( isNaN(tmpChar) == false ) {
			tmpString = tmpString +  tmpChar;
		}
		else
		{
			flagOk++; // Il y a des separateurs dans la date
			if ( tmpString == "" )
				return -2; // Format de date incorrect...
			if ( tmpString.length > 2 )
				return -2; // Format de date incorrect...
			if ( tmpString.length == 1 )
				tmpString = "0" + tmpString;
			
			tmpDate = tmpDate + tmpString;
			tmpString = "";
		}
	}
	switch ( flagOk ) {
		case 0 :
			if ( tmpString.length < 6 || tmpString.length == 7 || tmpString.length > 8 )
				return -2; // Format de date incorrect...
			if ( tmpString.length == 6 )
				tmpString = tmpString.substring(0,4) + "20" + tmpString.substring(4,6);
		break;
		case 1 :
			if ( tmpString == "" )
				return -2; // Format de date incorrect...
			if ( tmpString.length > 2 )
				return -2; // Format de date incorrect...
			if ( tmpString.length == 1 )
				tmpString = "0" + tmpString;
			tmpDate = tmpDate + tmpString;
			tmpString=tmpAnnee;
		break;
		case 2 :
			if ( tmpString.length > 4 )
				return -2; // On jette car au 2 caracteres pour un année
			switch( tmpString.length ) {
				case 0 : tmpString=tmpAnnee; break;
				case 1 : tmpString = "200" + tmpString; break;
				case 2 : tmpString = "20" + tmpString; break;
				case 3 : tmpString = "2" + tmpString; break;
			}
		break;
	}

	tmpDate = tmpDate + tmpString;
	//--> A partir de la on a dans tmpDate une date de la forme JJMMAAAA

	//--> On contrôle
	tmpJJ = tmpDate.substring(0,2);
	if ( tmpJJ.indexOf("0") == 0 )
		testJJ = parseInt(tmpJJ.substr(1,1));
	else
		testJJ = parseInt(tmpJJ);

	if ( testJJ < 1 || testJJ > 31 )
		return -2; 
	tmpMM = tmpDate.substring(2,4);

	if ( tmpMM.indexOf("0") == 0 )
		testMM = parseInt(tmpMM.substr(1,1));
	else
		testMM = parseInt(tmpMM);

	if ( testMM < 1 || testMM > 12 )
		return -2; 

	tmpAAAA = tmpDate.substring(4,8);

	if ( testMM != 2 ) {
		nbJoursMois = dureeMois[testMM];
	}
	else
	{
		tmpAnnee = parseInt(tmpAAAA);
		if ( (tmpAnnee %4 == 0 && tmpAnnee %100 != 0) || tmpAnnee % 400 == 0 )
			nbJoursMois = 29;
		else
			nbJoursMois = 28;
	}

	if ( testJJ > nbJoursMois )
		return -2; 
	_dateFormatee = tmpJJ + "/" + tmpMM + "/" + tmpAAAA ;
	return 0;
}

function AAAAMMJJ(val)
{
	var ch = "";
	ch = val.substring(6,10) + val.substring(3,5) + val.substring(0,2);
	return parseInt(ch);
}
function onChange_datedeb() {
	test=ctrlDate(document.form0.datedeb.value);

	switch(test) {
		case -1  :
		return true;
		break;
		case -2  :
		alert("Attention : date incorrecte...");
		document.form0.datedeb.focus();
		return false;
		break;
		default :
		document.form0.datedeb.value=_dateFormatee;
		break;
	}
}

function onChange_datefin() {
	test=ctrlDate(document.form0.datefin.value);
	switch(test) {
		case -1  : 
		return true;
		break;
		case -2  :
		alert("Attention : date incorrecte...");
		document.form0.datefin.focus();
		return false;
		break;
		default :
		document.form0.datefin.value=_dateFormatee;
		break;
	}
}

function validateActu() { 
	if (document.form0.titre.value=="") {
	alert("Veuillez saisir le titre");
	document.form0.titre.focus();
	return false;
	}
	if (document.form0.titreuk.value=="") {
	alert("Veuillez saisir le titre en anglais");
	document.form0.titreuk.focus();
	return false;
	}
	if (document.form0.comment.value=="") {
	alert("Veuillez compléter le corps de l'actualité");
	document.form0.comment.focus();
	return false;
	}
	if (document.form0.commentuk.value=="") {
	alert("Veuillez compléter le corps de l'actualité en anglais");
	document.form0.commentuk.focus();
	return false;
	}

	txtImage=document.form0.photo.value;
	txtImage = txtImage.toLowerCase();
	if (txtImage!="") {
	if (txtImage.indexOf(".gif")<3 && txtImage.indexOf(".jpg")<3) { 
	alert("Le fichier image doit être en gif ou jpg");
	document.form0.photo.focus();
	return false;
	}

	test=ctrlDate(document.form0.datedeb.value);
	switch(test) {
		case -1  :
		alert("Veuillez saisir la date de début...");
		document.form0.datedeb.focus();
		return false;
		break;
		case -2  :
		alert("Attention : date incorrecte...");
		document.form0.datedeb.focus();
		return false;
		break;
		default :
		document.form0.datedeb.value=_dateFormatee;
		break;
	}

	test=ctrlDate(document.form0.datefin.value);
	switch(test) {
		case -1  :
		alert("Veuillez saisir la date de fin...");
		document.form0.datefin.focus();
		return false;
		break;
		case -2  :
		alert("Attention : date incorrecte...");
		document.form0.datefin.focus();
		return false;
		break;
		default :
		document.form0.datefin.value=_dateFormatee;
		break;
	}

	if ( AAAAMMJJ(document.form0.datedeb.value) > AAAAMMJJ(document.form0.datefin.value) ) {
		alert("Attention la date de début est supérieure à la date de fin");
		document.form0.datedeb.focus();
		return false;
	}

	return true;
}



function Valid_Date(val) { 
	if (val.length !=10) {
		 alert("Date Non Vraisemblable!  tapez la date sous ce format: ex: 23/12/2006");
		 return false;
	    } 
	  else
	  {
		 if ((nbrentier(val.substring(0,2)))   //test sur les caractères saisis
		        &&(nbrentier(val.substring(3,5)))
		        &&(nbrentier(val.substring(6,8)))
		        &&	(val.substring(2,3)=="/")
		        && (val.substring(5,6)=="/"))		  
			{
			   if ((val.substring(0,2)<="31")   // Inverser 31 et 12 pour le format anglais
			       &&(val.substring(3,5)<="12"))
				{ return true; }   // la date est correcte la fonction n'affiche rien
			   else
				{
				alert("Date Non Vraisemblable!  tapez la date sous ce format: ex: 01/12/2006")
				 return false;
				}
			}
		}				
	}
}

function validateContact() { 
	if (document.formcontact.Nom.value=="") {
	alert("Veuillez saisir votre nom, SVP");
	document.formcontact.Nom.focus();
	return false;
	}
	if (document.formcontact.Email.value=="") {
	alert("Veuillez saisir votre email, SVP");
	document.formcontact.Email.focus();
	return false;
	}
	if (document.formcontact.Question.value=="") {
	alert("Veuillez formuler votre question, SVP");
	document.formcontact.Question.focus();
	return false;
	}
	return true;
}
