var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var NS6 = (document.getElementById && !document.all) ? true : false;

/*	Ce script permet d'associer des effets de style compatibles avec IE	*/
var whNavOk=false;

if(navigator.appName.indexOf("Netscape") !=-1 && navigator.appVersion.substring(0,1)>=5)
	whNavOk=true;
	
if(navigator.appName.indexOf("Microsoft")!=-1)
	whNavOk=true;

/*	Capture du mouvement souris			*/
var mouse_x = 0;
var mouse_y = 0;

document.onmousemove = mouseMove
if (NS4) 
	document.captureEvents(Event.MOUSEMOVE)
/*	----------------------------------- */

function mouseMove(e)
{
	if (NS4 || NS6) 
	{
		mouse_x=e.pageX; 
		mouse_y=e.pageY;
	}
	if (IE4) 
		{
		mouse_x=event.x; 
		mouse_y=event.y;
		}
	if (IE5) 
		{

	 		mouse_x=event.x+ document.body.scrollLeft; 
			mouse_y=event.y+document.body.scrollTop;
		}
	mouse_x=mouse_x-25;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion,10)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
		
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
  	if (v=='show')
		{
		hideElement("SELECT");
			if(NS4) 
				obj.left=1; 
		}
	else
		showElement("SELECT");
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

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 moins(txtQte,btn)
{
	var txtQuantite
	if (typeof(btn.form.btnMoins.length)=="undefined")
	{
		txtQuantite=txtQte
	}
	else
	{
		for (i=0;i<btn.form.btnMoins.length; i++)
		{
			if (btn==btn.form.btnMoins[i])
			{
				txtQuantite=txtQte[i]
			}
		}
	}
	var quantite
	quantite=parseInt(txtQuantite.value,10);
	if (isNaN(quantite)) quantite = 0
	if (quantite>0) quantite = quantite - 1
	txtQuantite.value=quantite
	return false;
}

function plus(txtQte,btn)
{
	var txtQuantite
	if (typeof(btn.form.btnPlus.length)=="undefined")
	{
		txtQuantite=txtQte
	}
	else
	{
		for (i=0;i<btn.form.btnPlus.length; i++)
		{
			if (btn==btn.form.btnPlus[i])
			{
				txtQuantite=txtQte[i]
			}
		}
	}
	var quantite
	quantite=parseInt(txtQuantite.value,10)
	if (isNaN(quantite)) quantite = 0
	quantite = quantite + 1
	txtQuantite.value=quantite
	return false;
}


function CalculTotalQuantite(whForm,whObjectName,whValue)
{
	var whTotal=0;
	if(typeof(whForm.quantite.length)=="undefined") {
		if(whForm.quantite.value!="")	{
			whTotal=parseInt(whForm.quantite.value,10);
		}
	}
	else
		{
		for(i=0;i<=whForm.quantite.length-1;i++)
			{
				if (isNaN(parseInt(whForm.quantite[i].value,10))==false) 
					whTotal+=parseInt(whForm.quantite[i].value,10); 
				else
					whForm.quantite[i].value=0;
				
				if(whNavOk==true)	{
				if(whForm.quantite[i].value==0)
					whForm.quantite[i].style.borderColor=std_borderColor;
				else
					whForm.quantite[i].style.borderColor='#FF0000';	}
			}
		}
	
	//if(typeof(whForm.quantitetotal)!="undefined")
	//	whForm.quantitetotal.value=whTotal;
	if (whObjectName!="")
	{
		if(whTotal==0) whTotal="";
		whValue=whValue.replace('%1',whTotal);
		eval("whForm."+whObjectName+".value=whValue");
	}
	return whTotal;
}

function ResetQuantite(whForm,whObjectName,whValue)
{
	if(typeof(whForm.quantite.length)=="undefined")
		{
		if(parseInt(whForm.quantite.value,10)!=0)
			whForm.quantite.value=0;	
		}
	else
		{
		for(i=0;i<=whForm.quantite.length-1;i++)
			{
				if(whNavOk==true)	
				{
					whForm.quantite[i].style.borderColor=std_borderColor;
					if(parseInt(whForm.quantite[i].value,10)!=0)
						whForm.quantite[i].value=0;
				}
			}
		}
	if (whObjectName!="")
			eval("whForm."+whObjectName+".value=whValue");
}

function hideElement(elmID)
{
	if (IE4 || IE5) {
		for (i = 0; i < document.all.tags(elmID).length; i++)
		{
			obj = document.all.tags(elmID)[i];
			obj.style.visibility = "hidden";
		}
	}
}

function showElement(elmID)
{
	if (IE4 || IE5) {
		for (i = 0; i < document.all.tags(elmID).length; i++)
		{
			obj = document.all.tags(elmID)[i];
			obj.style.visibility = "";
		} 
	}
}

/*	SFRL - diagdirect | D. GIRE 2001	*/
var std_borderColor="#666666"	//	Bordure standard

function menu_lk_hover(whElement)
{
	var whStyle = whElement.style;
	var whHoverColor=(menu_lk_hover.arguments.length>1)?menu_lk_hover.arguments[1]:"#FFFFFF";
	
//	whStyle.cursor="hand";
	if(typeof(whElement.type)=='undefined')	
	{
		whStyle.borderColor=whHoverColor
		whStyle.borderTopColor=std_borderColor;
		whStyle.borderBottomColor=std_borderColor;
	}
	whStyle.backgroundColor=whHoverColor;
}

function menu_lk_out(whElement)
{
	var whStyle = whElement.style;
	whStyle.backgroundColor="";
	whStyle.cursor="";
	if(typeof(whElement.type)=='undefined')	
	{
		whStyle.borderColor="#EEEEEE";
	}
}

function DisplayPopup(theURL,winName,features) { 
  var wnd;
  wnd=window.open(theURL,winName,features);
  wnd.focus();
}

//Auteur=S.PREVOT;Date=20021107;
//Rem=Valide une date de type jj/mm/aaaa

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

var reason = '';

function isValidDate (myDate,sep) {
// checks if date passed is in valid dd/mm/yyyy format

    if (myDate.length == 10) {
        if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
            var date  = myDate.substring(0,2);
            var month = myDate.substring(3,5);
            var year  = myDate.substring(6,10);

            var test = new Date(year,month-1,date);

            if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
                reason = '';
                return true;
            }
            else {
                reason = "the date does not exist";
                return false;
            }
        }
        else {
            reason = "The separator of the date is invalid";
            return false;
        }
    }
    else {
        reason = "La length of the date is invalid";
        return false;
    }
}

//Rem=Determine si une date est au format dd/mm/yyyy
function verifDate(objForm) {
    //Rem=le champ qui contient la date a tester n'est pas vide
    if(objForm)
		{
		if (objForm.value != '') {
						//Rem=la date est valide
						//Act=on n'affiche pas le message de date valide
						if (isValidDate(objForm.value,'/')) {
							//document.write(objForm.value + ' = valid date<BR>');
						//Rem=la date est invalide pour la raison 'reason'
						//Act=on n'affiche pas le message de date invalide
						//Act=on met a blanc le champ qui contient la date a tester
							return true;
						}
						else {
							// //document.write(objForm.value + ' = ' + reason + '<BR>');
							// objForm.value = ''
							//Auteur=S.PREVOT;Date=20021224;Modif=affiche la raison pour laquelle la date n'est pas au bon format
							alert(reason+'.');
							return false;
						}
		}
		else {
			return true;
		}
	}
	else
	{
		return true;
	}
}

// Vérifie qu'une adresse email est valide
function verifEmail(sEmail) {
	var TypeCas=0;
	if(sEmail.length==0)
		TypeCas=1;
		
	if(sEmail.indexOf('@')==-1 || sEmail.indexOf('@.')!=-1 || sEmail.indexOf('.@')!=-1 || sEmail.indexOf('@,')!=-1 || sEmail.indexOf(',@')!=-1)
		TypeCas = 1;
		
	if(sEmail.indexOf('/')!=-1 || sEmail.indexOf('>')!=-1 || sEmail.indexOf('<')!=-1 || sEmail.indexOf(',')!=-1 || sEmail.indexOf('\\')!=-1 || sEmail.indexOf('|')!=-1 || sEmail.indexOf(' ')!=-1)
		TypeCas = 2;
	
	switch(TypeCas)
		{
		case 0:
			return true;
		case 1:
			alert('The field email is not valid !');
			return false;
			break;
		case 2:
			alert('To separate your emails, use a character \';\'');
			return false;
			break;
		}
}


//vérifie qu'un mot de passe est composé d'au moins 6 caractères, dont 2 chiffres et 4 lettres
function verifPassword(pwd) {
	var message = "The password must be composed of at least 6 characters, including 4 letters and 2 digits";
	var i;
	var nbLettres=0;
	var nbChiffres=0;
	if (pwd.length<6) {
		alert(message+" too short");
		return false;
	}
	else {
		for (i=0;i<pwd.length;i++) {
			if (isNaN(pwd.substr(i,1))) {
				nbLettres++;
			}
			else {
				nbChiffres++;
			}
		}
	}
	if ((nbChiffres>=2) && (nbLettres>=4)) {
		return true;
	}
	else {
		alert(message+" nb figures="+nbChiffres+" nb letters="+nbLettres);
		return false;
	}
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

//vérifie le jeu de caractère
var listeCaractere1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789- ";
var listeCaractere2 = listeCaractere1 + "éèêëàâäùüûïîç,()='+:?!\"%&*<>";
var listeCaractere3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
function verifCaractere(text,listeCarAutorise) {
	var i;
	for (i=0;i<text.length;i++) {
		if (listeCarAutorise.indexOf(text.substr(i,1))==-1) {
			return false;
		}
	}
	return true;
}