// JavaScript Document

/*
Fonction de traitement des balises pour la mise en forme de texte
*/

function storeCaret(text)
{ // voided
}

function AddText(startTag,defaultText,endTag,champ) 
{

 if (champ.createTextRange) 
 {
  var text;
  champ.focus(champ.caretPos);
  champ.caretPos = document.selection.createRange().duplicate();
  if(champ.caretPos.text.length>0)
  {
   champ.caretPos.text = startTag + champ.caretPos.text + endTag;
  }
  else
  {
   champ.caretPos.text = startTag+defaultText+endTag;
  }
 }
 else champ.value += startTag+defaultText+endTag;
}

function chcolor(color,champ)
{

 if (champ.createTextRange) 
 {
	Selection = document.selection.createRange().text;
 	champ.focus(champ.caretPos);
  champ.caretPos = document.selection.createRange().duplicate();
 if(champ.caretPos.text.length>0)
  {
   champ.caretPos.text = "[" + color + "]"+ champ.caretPos.text + "[/" + color + "]";
  }
  else
  {
   champ.caretPos.text = "[" + color + "] votre texte "+ Selection + "[/" + color + "]";
  }
}
else
champ.value += "[" + color + "]"+ Selection + "[/" + color + "]";
}

/*
Fonction d'activation/desactivation de zone texte


function disable_enable(zone_texte){
if (document.all || document.getElementById){
if (zone_texte.disabled==true) {
zone_texte.disabled=false
}
else {
zone_texte.disabled=true
zone_texte.value=''
}
}
}

function rempli_vide(){
if (document.f.cre_cook.value=='vide') {
document.f.cre_cook.value='creation'
}
else {
document.f.cre_cook.value='vide'
}
}

function selectionner()
{
document.form1.contenu.select();
}
*/
function limitcar(texte, nb, maxi) {
 if (texte.value.length > maxi)
   texte.value = texte.value.substring(0, maxi);
 else 
   nb.value = maxi - texte.value.length;
}
/*
function remplissage()
{

if(document.form1.idem.checked) {

var radio, radio1
radio = document.form1.titre
radio1 = document.form1.titre_livraison

for (var i=0; i<radio.length;i++) {
	if (radio[i].checked) {
		radio1[i].checked=true;
		}
    }

document.form1.prenom_livraison.value = document.form1.prenom.value;
document.form1.nom_livraison.value = document.form1.nom.value;
document.form1.societe_livraison.value = document.form1.societe.value;
document.form1.adresse_livraison.value = document.form1.adresse.value;
document.form1.code_postal_livraison.value = document.form1.code_postal.value;
document.form1.ville_livraison.value = document.form1.ville.value;
}

else {

document.form1.titre_livraison[0].checked=true;
document.form1.titre_livraison.value = "";
document.form1.prenom_livraison.value = "";
document.form1.nom_livraison.value = "";
document.form1.societe_livraison.value = "";
document.form1.adresse_livraison.value = "";
document.form1.code_postal_livraison.value = "";
document.form1.ville_livraison.value = "";
}

}

<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Format_Tel(NumTel){
  var Tel;
  var i = 0;
  while (i < NumTel.length-1)
    {
    if ((NumTel.charAt(i) == ".")||(NumTel.charAt(i) == ",")||(NumTel.charAt(i) == "/")||(NumTel.charAt(i) == "-")||(NumTel.charAt(i) == " "))
      {
      Tel = NumTel.substring(0,i) + NumTel.substring(i+1,NumTel.length);
          NumTel = Tel; 
      }
      else{
      i++;
      }
    }
  return (NumTel);
}

function nbjours_mois(mois,annee)
{
  
  if ((mois==1)||(mois==3)||
    (mois==5)||(mois==7)||
    (mois==8)||(mois==10)||
    (mois==12))
  {
  return(31);
  }
  else if ((mois==4)||(mois==6)||
    (mois==9)||(mois==11))
  {
  return(30);
  }
  else if ((mois==2)&&(annee % 4 ==0))
  {
  return(29);
  }
  else
  {
  return(28);
  }

}

function date_valide(x,y,z)
{
  if ((x <= 31)&&(nbjours_mois(y,z)==31))
  {
  //return("True");
  return("T");
  }
  else if ((x <= 29)&&(nbjours_mois(y,z)==29))
  {
  return("T");
  }  
  else if ((x<=28)&&(nbjours_mois(y,z)==28))
  {
  return("T");
  }  
  else if ((x<=30)&&(nbjours_mois(y,z)==30))
  {
  return("T");
  }  
  else
  {
  return("F");
  }
}
*/
function MM_validateForm() { //v4.0
  
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  
  for (i=0; i<(args.length-2); i+=3) 
  { 
  	test=args[i+2]; val=MM_findObj(args[i]);
    
	if (val) 
	{ 
		nm=val.name; 
		
		if ((val=val.value)!="") 
		{
			//S'il s'agit d'un email, on vérifie le format
			if (test.indexOf('isEmail')!=-1) 
			{ 
				p=val.indexOf('@');
				if (p<1 || p==(val.length-1)) errors+='- Le champs '+nm+' doit contenir une adresse email valide.\n';
			} 
	
			//on vérifie le format du lien
			if ((test.charAt(0) == 'U')||(test.charAt(1) == 'U')) 
			{
				if (val.substring(0,7)!='') 
				{	
					test_pt = val.indexOf('.');
					if (val.substring(0,7)!='http://' || test_pt<1) 
						errors += '- Le champs '+nm+' doit contenir un lien correct (http://).\n';
				}
			}

			//On vérifie le format de la date
			if (test.charAt(0) == 'D' || test.charAt(1) == 'D') 
			{
				var j,m,a;
				
				if (val.length != 10) 
					errors+='- Le champs '+nm+' doit contenir une date valide\n';
				else if ((isNaN(val.substring(0,2)))||(isNaN(val.substring(3,5)))||(isNaN(val.substring(6,10)))) 
					errors+='- Le champs '+nm+' doit contenir une date valide\n';
				else if ((val.substring(2,3)!="/")||(val.substring(5,6)!="/")) 
					errors+='- Le champs '+nm+' doit contenir une date valide\n';
				else if (date_valide(val.substring(0,2),val.substring(3,5),val.substring(6,10))=='F') 
					errors+='- Le champs '+nm+' doit contenir une date valide\n';
			}
											
			if (test == 'isNum') 
		  	{ 
		  		num = parseFloat(val);
			
				if (isNaN(val)) 
					errors+='- '+nm+' must contain a number.\n';
			
				if (test.indexOf('inRange') != -1) 
				{ 
					p=test.indexOf(':');
			 		min=test.substring(8,p); max=test.substring(p+1);
			  	
				if (num<min || max<num) 
					errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
				} 
		  	} 
		} 

		//S'il s'agit d'un champs obligatoire
		else if (test.charAt(0) == 'R' && document.getElementById(nm).value == '') 
			errors += '- Le champs '+nm+' est obligatoire.\n'; 

		//S'il s'agit d'un mot de passe
		if (test == 'MP' && nm == 'mot_de_passe') 
		{
			//Si on est sur le formulaire de modification d'un utilisateur
			if (document.getElementById('changer_mdp'))
			{
				if (document.getElementById('mot_de_passe').value == '' && document.getElementById('confirmation_mot_de_passe').value == '' && document.getElementById('changer_mdp').checked == false)
				{
					errors += '- Le champs mot_de_passe est obligatoire.\n';
					errors += '- Le champs confirmation_mot_de_passe est obligatoire.\n';
				}
				else if ((document.getElementById('mot_de_passe').value != document.getElementById('confirmation_mot_de_passe').value) && document.getElementById('changer_mdp').checked == false)
					errors += '- Les deux mots de passe ne coincident pas !';
			}
			//Si on est sur le formulaire d'ajout d'un utilisateur
			else
			{		
				if (document.getElementById('mot_de_passe').value == '' && document.getElementById('confirmation_mot_de_passe').value == '')
				{
					errors += '- Le champs mot_de_passe est obligatoire.\n';
					errors += '- Le champs confirmation_mot_de_passe est obligatoire.\n';
				}
				else if (document.getElementById('mot_de_passe').value != document.getElementById('confirmation_mot_de_passe').value)
					errors += '- Les deux mots de passe ne coincident pas !';
			}
		}
	}
  } 
  
  if (errors) alert('Erreur(s) rencontrée(s) :\n\n'+errors);
  	document.MM_returnValue = (errors == '');
}
//-->


<!--
/*
Fonction de fermeture d'un popup et raffraichissement de la fenetre mere

  function refresh(url){
  opener.location.href=url;
  self.close();
  };
//-->

function validbutton1(dd)
{
	window.open("calendrier/calendrier.asp?origine="+dd,"calendrier","width=215,height=170,top=120,left=120");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
*/

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
/*

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function afficheVignette(cheminVignette,cheminMaxi)
	{
	document.write('<A HREF="javascript:afficheMaxi(\''+cheminMaxi+'\')"><IMG SRC="'+cheminVignette+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="cliquez ici pour voir en grand"></A>');
	}
function afficheMaxi(chemin)
	{
	i1 = new Image;
	i1.src = chemin;
	html = '<HTML><HEAD><TITLE>CILAS</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+27,document.imageTest.height+150)"></CENTER></BODY></HTML>';
	popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0');
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close()
	};
	
var DateValue = ""
var DateInputID = ""
var ObjInput
function CalendarInput(oInput){
	ObjInput = oInput
	DateValue = oInput.value
	showModelessDialog("../fonctions/calendar.html",window,"status:no;dialogLeft:" + event.screenX + ";dialogTop:" + event.screenY + ";dialogWidth:181px;dialogHeight:220px;resizable:no;scroll:no");
}
function DateUpdate() {ObjInput.value = DateValue}

function resolution(d) { 
document.location=d+"?width="+screen.width+"&height="+screen.height; 
} 

function resolution2(d) { 
return (d+"?width="+screen.width+"&height="+screen.height); 
} 

//Fonction de validation de suppression des candidatures
function validation() {
var retour;
retour = window.confirm('Vous etes sur le point de supprimer toutes les candidatures apparaissant sur cette page ! ');
if (retour) document.vider_corbeille.submit();
}
*/

//Fonction d'activation/desactivation d'éléments
function activ() 
{
	var args=activ.arguments;
   
	for (i=0; i<(args.length); i++) 
	{
		if (document.getElementById(args[i]).disabled == true)
			document.getElementById(args[i]).disabled = false;
		else
			document.getElementById(args[i]).disabled = true;
	}
}

//Fonction pour griser ou non un texte
function grise()
{
	var args=grise.arguments;
   
	for (i=0; i<(args.length); i++) 
	{
		if (document.getElementById(args[i]).style.color == 'black')
			document.getElementById(args[i]).style.color = '#CCCCCC';
		else
			document.getElementById(args[i]).style.color = 'black';
	}
}


//Demande de confirmation avant suppression
function confirmation(nom_form, message)
{
	if(confirm('Si vous voulez supprimer définitivement ' + message + ', cliquez sur OK,\nsinon, cliquez sur annuler'))
		confirmation = document.getElementById(nom_form).submit();
}


//Demande de confirmation avant suppression
function confirmation_publication(nom_form, message)
{
	if(confirm(message))
		confirmation = document.getElementById(nom_form).submit();
}


//Demande de confirmation avant suppression
function confirm_suppr(page)
{
	if(confirm('Si vous voulez supprimer définitivement ce fichier, cliquez sur OK,\nsinon, cliquez sur annuler'))
		confirm_suppr = location.replace(page);
}


//Vérification de l'extension
function verif_extension()
{
	trouve = 0;
	
	//On récupère les arguments passés en paramètres
	var args=verif_extension.arguments;
	
	//On stocke l'extension recherchee passée en premier paramètre
	extension_recherchee = args[0];
	
	//On regarde si l'extension est autorisée
	for (i=1; i<(args.length); i++) 
	{
		if (args[i] == extension_recherchee)
			trouve = 1;
	}
	
	if (trouve == 0) alert('Le format de votre fichier n\'est pas autorisé !');
	
  	document.retour = (trouve == 1);
}

//Fcontion sur les touches pressées
function codeTouche(evenement)
{
        for (prop in evenement)
        {
                if(prop == 'which') return(evenement.which);
        }
        return(evenement.keyCode);
}

function scanTouche(evenement, expression)
{
        //var reCarValides = /\w/;
        var reCarValides = expression;

        var codeDecimal  = codeTouche(evenement);
        var car = String.fromCharCode(codeDecimal);
        var autorisation = reCarValides.test(car);

        return autorisation;
}

function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}

function afficheVignette(cheminVignette,cheminMaxi)
{
document.write('<A HREF="javascript:afficheMaxi(\''+cheminMaxi+'\')"><IMG SRC="'+cheminVignette+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="cliquez ici pour voir en grand"></A>');
}
	
function afficheMaxi(chemin)
	{
	i1 = new Image;
	i1.src = chemin;
	html = '<HTML><HEAD><TITLE>BSTCO</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+27,document.imageTest.height+60)"></CENTER></BODY></HTML>';
	popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=0');
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close()
	};
	
var DateValue = ""
var DateInputID = ""
var ObjInput