/*************************************
*   Librairie de fonctions de base
// @datecreation : 06/10/2004
// @auteur       : J.Charoin - Webcentric
*************************************/

// fonction d'initiation générale
function init() {
	
}

function exit() {

}

// fonction de spécification d'objet
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;
}

// fonction de validation de formulaire
/*
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)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+= '- '+nm+' doit contenir une adresse e-mail valide.\n';
      } else if (test!= 'R') {
        if (isNaN(val)) errors+= '- '+nm+' doit contenir un nombre.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+= '- '+nm+' doit contenir un nombre compris entre '+min+' et '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' est obligatoire.\n'; }
  } if (errors) alert('Les erreurs suivantes sont apparues :\n'+errors);
  document.MM_returnValue = (errors == '');
}
*/

// fonction de validation de formulaire améliorer
function MM_validateForm()
	{
	//v5.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)
    	{
    	affich=args[i+1];
    	nm=val.name;
    	if ((val=val.value)!="")
    		{
      	if (test.indexOf('isEmail')!=-1)
      		{
      		p=val.indexOf('@');
        	if (p<1 || p==(val.length-1)) errors+= '- '+affich+' (doit contenir une adresse e-mail valide).\n';
      		}
      	else if (test!= 'R')
      		{
        	if (isNaN(val)) errors+= '- '+affich+' doit contenir un nombre.\n';
        	if (test.indexOf('inRange') != -1)
        		{
        		p=test.indexOf(':');
          	min=test.substring(8,p); max=test.substring(p+1);
          	if (val<min || max<val) errors+= '- '+affich+' doit contenir un nombre compris entre '+min+' et '+max+'.\n';
    				}
    			}
    		}
    	else if (test.charAt(0) == 'R') errors += '- '+affich+'.\n';
    	}
    }
    
	  var Compt = 0;
		var Deb = errors.indexOf('\n');
		while (Deb != -1)
			{
		  Compt++;
		  Deb = errors.indexOf('\n',++Deb);
			}
   if (errors)
   	{
   	if (Compt>1)
   		{
   	  alert('Les champs suivants sont obligatoires :\n'+errors);
   	  }
   	else
   		{
   	  alert('Le champ suivant est obligatoire :\n'+errors);  		
   		}   	
   	}
  document.MM_returnValue = (errors == '');
	}

// fonction d'ouverture de nouvelle fenêtre de navigateur
function WBC_openWindow(url,title,width,height,menus,tools,location,scrolling,resize) {
	optionsVar = "width="+width+",height="+height+",menubar="+menus+",toolbar="+tools+",location="+location+",scrollbars="+scrolling+",resizable="+resize;
	window.open(url,title,optionsVar);
}

// OPEN A NEW BROWSER WINDOW
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_openCenteredBrWindow(theURL,winName,width,height,features) { //v2.0
  LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-height)/2 : 0;
  myFeatures = "top="+TopPosition+",left="+LeftPosition+",width="+width+",height="+height+","+features;
  MM_openBrWindow(theURL,winName,myFeatures);
}

// fonction de redirection avec confirmation
function WBC_confirm(msg,url) { //v1.0
	if (confirm(msg)) {
		self.location = url;
	}
}

function WBC_confirm_double(msg,msg2,url)
	{ //v1.0
	if (confirm(msg))
		{
		if (confirm(msg2))
			{	
			self.location = url;
			}
		}
	}

// fonction d'impression
function WBC_print() { //v1.0
	self.print();
}

// fonction de suppression d'images
function WBC_deletePicture(name,url) {
	msg = "Êtes-vous sûr de vouloir effacer cet image ?";
	if (confirm(msg)) {
		document[name].src = url;
		document[name].width=40;
		document[name].height=40;
	}
}

// fonction de cochage/décochage de checkbox
function WBC_check(field,val) {
	for (i = 0; i < field.length; i++) field[i].checked = val ;
}

// Affiche la date
function getTime()
{       
	var now = new Date();
	var day = now.getDay();
	var date = now.getDate();
	var month = now.getMonth() +1;
	var year = now.getYear();
	var minutes = now.getMinutes();
	var divider = "h";
	var jour = "";
	var mois = "";
	if (year < 1900)		year = year + 1900;
	if (minutes<10)		divider = "h0";
	if (day == 0)		jour = "Dimanche";
	if (day == 1)		jour = "Lundi";
	if (day == 2)		jour = "Mardi";
	if (day == 3)		jour = "Mercredi";
	if (day == 4)		jour = "Jeudi";
	if (day == 5)		jour = "Vendredi";
	if (day == 6)		jour = "Samedi";
	if (month == 1)		mois = "janvier";
	if (month == 2)		mois = "f&eacute;vrier";
	if (month == 3)		mois = "mars";
	if (month == 4)		mois = "avril";
	if (month == 5)		mois = "mai";
	if (month == 6)		mois = "juin";
	if (month == 7)		mois = "juillet";
	if (month == 8)		mois = "ao&ucirc;t";
	if (month == 9)		mois = "septembre";
	if (month == 10)		mois = "octobre";
	if (month == 11)		mois = "novembre";
	if (month == 12)		mois = "d&eacute;cembre";
	return( jour + "  " + date + " " + mois   + " " + year + " \n\r " + now.getHours() + divider + minutes  );
}
