// Gestion des erreurs
// Annulation des messages d'erreur
function NoError() { return true; }
window.onerror=NoError;

function CookieExist(CookieName)
{
	cookieinfo = document.cookie;
	if (cookieinfo.indexOf(CookieName) == -1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function GetCookie(CookieName) {

	if ( CookieExist(CookieName) )
	{
		cookieinfo = document.cookie;
		d = cookieinfo.indexOf(CookieName) + CookieName.length + 1;
		f = cookieinfo.indexOf(";",d);
		if ( f == -1)
		{
			f = cookieinfo.length;
		}
		return (cookieinfo.substring(d,f));
	}
	else
	{
		return ("");
	}
}

function SetCookie(CookieName,CookieArgs,CookieExpire)
{
	document.cookie = CookieName + "=" + CookieArgs + ";expires=" + CookieExpire;
}

function SauveCookie()
{
	ParamCookie = "<P>" + document.Form1.PASSWORD.value + "</P>";
	ParamCookie = ParamCookie + "<NOM>" + document.Form1.NOM.value + "</NOM>";
	ParamCookie = ParamCookie + "<SOCIETE>" + document.Form1.SOCIETE.value + "</SOCIETE>";
	SetCookie("RDVF2001",ParamCookie,"Sunday, 31-Dec-01 00:00:00 GMT");
}

function AfficheCookie(CookieName)
{
	x = GetCookie(CookieName);

	tmpCookie1 = "<P>"; tmpCookieF1 = "</P>";
	tmpCookie2 = "<NOM>"; tmpCookieF2 = "</NOM>";
	tmpCookie3 = "<SOCIETE>"; tmpCookieF3 = "</SOCIETE>";
	tmpCookie4 = ""; tmpCookieF4 = "";
	tmpCookie5 = ""; tmpCookieF5 = "";

	if (x != "")
	{
		if (tmpCookie1!="") {document.Form1.PASSWORD.value = x.substring(x.indexOf(tmpCookie1)+tmpCookie1.length, x.indexOf(tmpCookieF1)); }
		if (tmpCookie2!="") {document.Form1.NOM.value = x.substring(x.indexOf(tmpCookie2)+tmpCookie2.length, x.indexOf(tmpCookieF2)); }
		if (tmpCookie3!="") {document.Form1.SOCIETE.value = x.substring(x.indexOf(tmpCookie3)+tmpCookie3.length, x.indexOf(tmpCookieF3)); }
		if (tmpCookie4!="") {document.Form1.SOCIETE.value = x.substring(x.indexOf(tmpCookie4)+tmpCookie4.length, x.indexOf(tmpCookieF4)); }
		if (tmpCookie5!="") {document.Form1.SOCIETE.value = x.substring(x.indexOf(tmpCookie5)+tmpCookie5.length, x.indexOf(tmpCookieF5)); }
	}
}

function Capitale(Texte)
{
	var tmpAlpha = "abcdefghijklmnopqrstuvwxyz";
	var tmpAlphaMaj = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	Texte = Texte.charAt(0).toUpperCase() + Texte.substring(1,255).toLowerCase();
	for (var t=0;t<26;t++)
	{
			while (Texte.indexOf(' '+tmpAlpha.charAt(t))>0)
		{
		  Texte = Texte.replace(' '+tmpAlpha.charAt(t), ' '+tmpAlphaMaj.charAt(t));
		}
	}
	return Texte
}

function TestMail(eMail)
{
	Mail = eMail.value;
	if ((Mail.indexOf("@") > 0) && (Mail.indexOf("@") < Mail.indexOf(".", Mail.indexOf("@"))))
	{ return true; }
	else
	{ alert("L'adresse mail n'est pas correcte !"); eMail.focus(); return false; }
}


function GetPicture(PictName,L,H)
{
	win = open(PictName ,'FicheClient','width=' + L + ',height=' + H + ',scrollbars=no,left=0,top=0,location=no,directories=no,status=no,menubar=no')
	win.blur();
	win.focus();
}

function GetPictures(PictName,L,H)
{
	win = open(PictName ,'PictName','width=' + L + ',height=' + H + ',scrollbars=yes,left=0,top=0,location=no,directories=no,status=no,menubar=no')
	win.blur();
	win.focus();
}

function GetPictureFull(PictName,Nom,L,H)
{
	win = open(PictName ,Nom ,'width=' + L + ',height=' + H + ',scrollbars=yes,left=0,top=0,location=yes,directories=no,status=no,menubar=yes')
	win.blur();
	win.focus();
}

function GetPicturesName(PictName,Nom,L,H)
{
	win = open(PictName ,Nom ,'width=' + L + ',height=' + H + ',scrollbars=yes,left=0,top=0,location=no,directories=no,status=no,menubar=no')
	win.blur();
	win.focus();
}


function MoveDate(nomChamp, mavaleur)
{
// La date doit être fournie au format JJ/MM/AA
	valeur = mavaleur.replace("-","/");
	valeur = valeur.replace("-","/");
	valeur = valeur.replace("Jan","1");
	valeur = valeur.replace("Fév","2");
	valeur = valeur.replace("Mar","3");
	valeur = valeur.replace("Avr","4");
	valeur = valeur.replace("Mai","5");
	valeur = valeur.replace("Jui","6");
	valeur = valeur.replace("Juil","7");
	valeur = valeur.replace("Aoû","8");
	valeur = valeur.replace("Sep","9");
	valeur = valeur.replace("Oct","10");
	valeur = valeur.replace("Nov","11");
	valeur = valeur.replace("Déc","12");

	if (valeur != "") {
		maDate= new Date(valeur);
		monJour = maDate.getDate();
		monMois = ""+(maDate.getMonth()+1);
		monAnnee = maDate.getYear();
		
		monMois = monMois.replace("12","Déc");
		monMois = monMois.replace("11","Nov");
		monMois = monMois.replace("10","Oct");
		monMois = monMois.replace("9","Sep");
		monMois = monMois.replace("8","Aoû");
		monMois = monMois.replace("7","Juil");
		monMois = monMois.replace("6","Jui");
		monMois = monMois.replace("5","Mai");
		monMois = monMois.replace("4","Avr");
		monMois = monMois.replace("3","Mar");
		monMois = monMois.replace("2","Fév");
		monMois = monMois.replace("1","Jan");

	} else {
		maDate= new Date();
		monJour = 0;
		monMois = 0;
		monAnnee = 0;
	}

	for (t=0;t<=document.Form1(nomChamp + "_J").length-1;t++)
	{
		if (monJour == document.Form1(nomChamp + "_J")[t].value)
		{
			document.Form1(nomChamp + "_J")[t].selected = true;
		}
	}

	for (t=0;t<=document.Form1(nomChamp + "_M").length-1;t++)
	{
		if (monMois == document.Form1(nomChamp + "_M")[t].value)
		{
			document.Form1(nomChamp + "_M")[t].selected = true;
		}
	}

	for (t=0;t<=document.Form1(nomChamp + "_A").length-1;t++)
	{
		if (monAnnee == document.Form1(nomChamp + "_A")[t].value)
		{
			document.Form1(nomChamp + "_A")[t].selected = true;
		}
	}

}

function calculDate(nomChamp)
{
	if (document.Form1(nomChamp + "_J").value == 0 || document.Form1(nomChamp + "_M").value == 0 || document.Form1(nomChamp + "_A").value == 0)
	{
		document.Form1(nomChamp).value = ""}
	else
	{
		//document.Form1(nomChamp).value = document.Form1(nomChamp + "_M").value + "-" + document.Form1(nomChamp + "_J").value + "-" + document.Form1(nomChamp + "_A").value;
		document.Form1(nomChamp).value = document.Form1(nomChamp + "_J").value + "-" + document.Form1(nomChamp + "_M").value + "-" + document.Form1(nomChamp + "_A").value;
	}
	
	
	//var ladate = (document.Form1(nomChamp).value).split("-");
	//var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
	//alert ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])));
	
}

function afficheDate(nomChamp, vide, valeur)
{
	if (valeur != "") {
		maDate= new Date(valeur);
		monJour = maDate.getDate();
		monMois = maDate.getMonth() + 1;
		monAnnee = maDate.getYear();
	} else {
		maDate= new Date();
		monJour = 0;
		monMois = 0;
		monAnnee = 0;
	}

	var monParam = '"' + nomChamp + '"';

// Dessin du JOUR
	maChaine = "<select onChange=javascript:calculDate(" + monParam + ") size='1' name=" + nomChamp + "_J style='font-family: Arial; font-size: 9px'>";

	if (vide == 1)
	{
		if (monJour == 0) 
		{
			maChaine = maChaine + "<option selected value=0> </option>" 
		}
		else 
		{
			maChaine = maChaine + "<option value=0> </option>";
		}
	}
	

	if (monJour == 1) {
		maChaine = maChaine + "<option selected value=1>1er</option>";
	}
	else {
		maChaine = maChaine + "<option value=1>1er</option>";
	}

	for (i=2;i<=31;i++)
	{
	var tmp = "";
	if (monJour == i) { tmp = "selected " }
	maChaine = maChaine + "<option " + tmp + "value='" + i + "'>" + i + "</option>";
	}
	maChaine = maChaine + "</select>&nbsp;";

// Dessin du MOIS

	maChaine = maChaine + "<select onChange=javascript:calculDate(" + monParam + ") size='1' name=" + nomChamp + "_M size=1 name=" + nomChamp + "_M style='font-family: Arial; font-size: 9px'>";

	if (vide == 1) {
		if (monMois == 0) {monSelect= " selected "; } else {monSelect=""; }
		maChaine = maChaine + "<option " + monSelect + " value=0> </option>";
	}

	if (monMois == 1) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Jan>Janvier</option>";
	if (monMois == 2) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Fév>Février</option>";
	if (monMois == 3) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Mar>Mars</option>";
	if (monMois == 4) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Avr>Avril</option>";
	if (monMois == 5) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Mai>Mai</option>";
	if (monMois == 6) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Jui>Juin</option>";
	if (monMois == 7) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Juil>Juillet</option>";
	if (monMois == 8) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Aoû>Août</option>";
	if (monMois == 9) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Sep>Septembre</option>";
	if (monMois == 10) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Oct>Octobre</option>";
	if (monMois == 11) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Nov>Novembre</option>";
	if (monMois == 12) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Déc>Décembre</option>";
	maChaine = maChaine + "</select>";

// Dessin de l'année
	maChaine = maChaine + "<select onChange=javascript:calculDate(" + monParam + ") size='1' name=" + nomChamp + "_A size=1 name=" + nomChamp + "_A style='font-family: Arial; font-size: 9px'>";

	if (vide == 1) {
		if (monAnnee == 0) {monSelect= " selected "; } else {monSelect=""; }
		maChaine = maChaine + "<option " + monSelect + " value=0> </option>";
	}

	for (i=2002;i<=2010;i++)
	{
		var tmp = "";

		if (monAnnee == i ) { tmp = "selected " }
		maChaine = maChaine + "<option " + tmp + "value='" + i + "'>" + i + "</option>";
	}

	maChaine = maChaine + "</select>";

	return maChaine
}









function calculDatePlage(nomChamp, pdebut, pfin)
{
	if (document.Form1(nomChamp + "_J").value == 0 || document.Form1(nomChamp + "_M").value == 0 || document.Form1(nomChamp + "_A").value == 0)
	{
		document.Form1(nomChamp).value = ""}
	else
	{
		document.Form1(nomChamp).value = document.Form1(nomChamp + "_M").value + "-" + document.Form1(nomChamp + "_J").value  + "-" + document.Form1(nomChamp + "_A").value;
	}
	
	//tmpdebut = new Date(pdebut);
	//maDatepdebut = tmpdebut.getDate()+"/"+tmpdebut.getMonth()+"/"+tmpdebut.getYear();
	//maDatepfin = pfin;
	//maDateNomChamp = document.Form1(nomChamp).value;
	
	//alert(maDatepdebut);
	
	//if (maDateNomChamp < maDatepdebut || maDateNomChamp > maDatepfin)
	//{
	//	alert("Hors de la plage de date autorisée !");
	//	document.Form1(nomChamp).value = "";
	//}
}



function afficheDatePlage(nomChamp, vide, valeur, pdebut, pfin)
{
	if (valeur != "") {
		maDate= new Date(valeur);
		monJour = maDate.getDate();
		monMois = maDate.getMonth() + 1;
		monAnnee = maDate.getYear();
	} else {
		maDate= new Date();
		monJour = 0;
		monMois = 0;
		monAnnee = 0;
	}

	monpdebut = new Date(pdebut);
	monpfin = new Date(pfin);

	var monParam = '"' + nomChamp + '"';
	monpdebut = '"' + monpdebut + '"';
	monpfin = '"' + monpfin + '"';

// Dessin du JOUR
	maChaine = "<select onChange=javascript:calculDatePlage(" + monParam + "," + monpdebut + "," + monpfin + ") size='1' name=" + nomChamp + "_J style='font-family: Arial; font-size: 9px'>";

	if (vide == 1) {
		if (monJour == 0) {maChaine = maChaine + "<option selected value=0> </option>" };
	}
	//else {
	//	maChaine = maChaine + "<option value=0> </option>";
	//}

	if (monJour == 1) {
		maChaine = maChaine + "<option selected value=1>1er</option>";
	}
	else {
		maChaine = maChaine + "<option value=1>1er</option>";
	}

	for (i=2;i<=31;i++)
	{
	var tmp = "";
	if (monJour == i) { tmp = "selected " }
	maChaine = maChaine + "<option " + tmp + "value='" + i + "'>" + i + "</option>";
	}
	maChaine = maChaine + "</select>&nbsp;";

// Dessin du MOIS

	maChaine = maChaine + "<select onChange=javascript:calculDatePlage(" + monParam + ") size='1' name=" + nomChamp + "_M size=1 name=" + nomChamp + "_M style='font-family: Arial; font-size: 9px'>";

	if (vide == 1) {
		if (monMois == 0) {monSelect= " selected "; } else {monSelect=""; }
		maChaine = maChaine + "<option " + monSelect + " value=0> </option>";
	}

	if (monMois == 1) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Jan>Janvier</option>";
	if (monMois == 2) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Fév>Février</option>";
	if (monMois == 3) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Mar>Mars</option>";
	if (monMois == 4) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Avr>Avril</option>";
	if (monMois == 5) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Mai>Mai</option>";
	if (monMois == 6) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Jui>Juin</option>";
	if (monMois == 7) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Juil>Juillet</option>";
	if (monMois == 8) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Aoû>Août</option>";
	if (monMois == 9) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Sep>Septembre</option>";
	if (monMois == 10) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Oct>Octobre</option>";
	if (monMois == 11) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Nov>Novembre</option>";
	if (monMois == 12) {monSelect= " selected "; } else {monSelect=""; }
	maChaine = maChaine + "<option " + monSelect + " value=Déc>Décembre</option>";
	maChaine = maChaine + "</select>";

// Dessin de l'année
	maChaine = maChaine + "<select onChange=javascript:calculDatePlage(" + monParam + ") size='1' name=" + nomChamp + "_A size=1 name=" + nomChamp + "_A style='font-family: Arial; font-size: 9px'>";

	if (vide == 1) {
		if (monAnnee == 0) {monSelect= " selected "; } else {monSelect=""; }
		maChaine = maChaine + "<option " + monSelect + " value=0> </option>";
	}

	for (i=2002;i<=2010;i++)
	{
		var tmp = "";

		if (monAnnee == i ) { tmp = "selected " }
		maChaine = maChaine + "<option " + tmp + "value='" + i + "'>" + i + "</option>";
	}

	maChaine = maChaine + "</select>";

	return maChaine
}


