var moz = (document.implementation && document.implementation.createDocument); 
var ie = (window.ActiveXObject); 
var xmlHTTP;

var myWaitingWindow;
function ShowWait(FileName) {
	//afficher fenetre attente
	Height = 222;
	Width  = 433;
	
	var X=(screen.height-Height)/2;
	var Y=(screen.width-Width)/2;
	if (navigator.appName == 'Netscape') {
		Parameters="menubar=no,resizable=no,screenX=" + X + ",screenY=" + Y;
		Parameters = Parameters + ",innerHeight=" + Height + ",innerWidth=" + Width;
	} else {
		Parameters ="menubar=no,resizable=no,left="+ X +",top="+ Y +",scrollbars=no";
		Parameters = "height=" + Height + ",width=" + Width + ",left=" + X + ",top=" + Y;
	}
	myWaitingWindow=window.open(FileName, "Attente",Parameters);
}

function ShowCalculTarifWait() {
	ShowWait("attente.htm");
}

function closeWaitingWindow() {
	if (myWaitingWindow != null) {
		myWaitingWindow.close();
	}
}

// fonction des boutons Roll Over --------------------------------------
<!--
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_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_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];}
}
//-->

// fonction des Calques --------------------------------------
function MM_showHide(z) { 
  t=document.getElementById('t'+z);
  t.style.display="none"
  }

function swapDiv(n) {
	t=eval("document.all.t"+n);if (t.style.display=="none")
	{t.style.display="block";} else {t.style.display="none";}
}

function MM_swapMenu(n){
	t=document.getElementById('t'+n);
	if (t.style.display=="none"){t.style.display="block";}
	else{t.style.display="none";}
}

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 pat() {
	setTimeout("MM_showHide(2)",8800);
}

//--- OLD AJAX_PROVIDER.JS ---------------------
function AJAX_ComboBox(Sel, Tagname, URL)
{ 
    var xhr = null;
    if(window.XMLHttpRequest)
     xhr = new XMLHttpRequest(); 
    else if (window.ActiveXObject)
     xhr  = new ActiveXObject('Microsoft.XMLHTTP'); 
     xhr.onreadystatechange = function()
    { 
         if(xhr.readyState == 4)
         {
              if(xhr.status == 200)
		{
		 var xml = xhr.responseXML.getElementsByTagName(Tagname);
		 for (x=Sel.length-1; x>=0; x--)   	{Sel.options[x] = null;}
				
		 Sel[Sel.length] = new Option('------------------------------');
		 
		 for (x=0; x<=xml.length-1; x++) 	{ Sel[Sel.length] = new Option(xml[x].getAttribute(Tagname));} 
		}
              else
		{
		 for (x=Sel.length-1; x>=0; x--)   	{Sel.options[x] = null;}
		 Sel[Sel.length] = new Option('------------------------------');
		}
         }
    };

   xhr.open("GET", URL,  true);
   xhr.send(null);
} 

function AJAX_Input(Sel, Tagname, URL)
{ 
    var xhr = null;
    if(window.XMLHttpRequest)
     xhr = new XMLHttpRequest(); 
    else if (window.ActiveXObject)
     xhr  = new ActiveXObject('Microsoft.XMLHTTP'); 
     xhr.onreadystatechange = function()
    { 
         if(xhr.readyState == 4)
         {
              	if(xhr.status == 200)
		{
			var xml = xhr.responseXML.getElementsByTagName(Tagname);
			if (xml.length > 0)
			Sel.value =  xml[0].getAttribute(Tagname);
			
		}
              	else
		{
			Sel.value = ''
		}
         }
    }

   xhr.open("GET", URL,  true);
   xhr.send(null);
} 

function ReinitialiseSelectedComboBox(sel)
{
	for (x=sel.length-1; x>=0; x--)   	{sel.options[x] = null;}
	sel[sel.length] = new Option('------------------------------');
}

function AJAX_ComboBoxModel(make,model,version,type,TagName, pURL)
{
pURL = pURL + make.options[make.selectedIndex].innerHTML;
ReinitialiseSelectedComboBox(version);
ReinitialiseSelectedComboBox(type);
AJAX_ComboBox(model, TagName, pURL);
}

function AJAX_ComboBoxVersion(make,model,version,type,TagName, pURL1,pURL2)
{
pURL1 = pURL1 + make.options[make.selectedIndex].innerHTML + pURL2 + model.options[model.selectedIndex].innerHTML
ReinitialiseSelectedComboBox(type);
AJAX_ComboBox(version, TagName, pURL1);
}

function AJAX_ComboBoxType(make,model,version,type,TagnameType,pURL1,pURL2,pURL3)
{
var VersionCh = version.options[version.selectedIndex].innerHTML
pURL1 = pURL1 + make.options[make.selectedIndex].innerHTML + pURL2 + model.options[model.selectedIndex].innerHTML + pURL3 + VersionCh
AJAX_ComboBox(Type, TagnameType, pURL1);
}

function AJAX_InputCostNew(make,model,version,Type,ValeurNeuve,PuissanceReelle,PuissanceFiscale,TagnameValeurNeuve,TagnamePuissanceReelle,TagnamePuissanceFiscale,pURL1,pURL2,pURL3,pURL4)
{
pURL1 = pURL1 + make.options[make.selectedIndex].innerHTML + pURL2 + model.options[model.selectedIndex].innerHTML + pURL3 + version.options[version.selectedIndex].innerHTML + pURL4 + Type.options[Type.selectedIndex].innerHTML
AJAX_Input(ValeurNeuve,TagnameValeurNeuve,pURL1)
AJAX_Input(PuissanceReelle,TagnamePuissanceReelle,pURL1)
AJAX_Input(PuissanceFiscale,TagnamePuissanceFiscale,pURL1)
}

function AJAX_ComboBoxCity(Sel, Tagname, URL)
{
	if (URL.length != 5)
	{
		var xhr = null;
		if(window.XMLHttpRequest)
			xhr = new XMLHttpRequest(); 
		else if (window.ActiveXObject)
			xhr  = new ActiveXObject('Microsoft.XMLHTTP'); 
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4)
			{
				if(xhr.status == 200)
				{
					var xml = xhr.responseXML.getElementsByTagName(Tagname);
					for (x=Sel.length-1; x>=0; x--)   	
						Sel.options[x] = null;
						
					Sel[Sel.length] = new Option('---------------');
				 
					for (x=0; x<=xml.length-1; x++) 	
						Sel[Sel.length] = new Option(xml[x].getAttribute(Tagname));
					
					if (xml.length > 0)	
						Sel.selectedIndex = 1;
				}
				else
				{
					for (x=Sel.length-1; x>=0; x--)   	
						Sel.options[x] = null;
	
					Sel[Sel.length] = new Option('---------------');
				}
			}
		};
	
	   xhr.open("GET", URL,  true);
	   xhr.send(null);
   }
} 

function AJAX_ComboBoxAndSelectFirstElement(Sel, Tagname, URL)
{
	if (URL.length != 5)
	{
		var xhr = null;
		if(window.XMLHttpRequest)
			xhr = new XMLHttpRequest(); 
		else if (window.ActiveXObject)
			xhr  = new ActiveXObject('Microsoft.XMLHTTP'); 
		xhr.onreadystatechange = function()
		{
			if(xhr.readyState == 4)
			{
				if(xhr.status == 200)
				{
					var xml = xhr.responseXML.getElementsByTagName(Tagname);
					for (x=Sel.length-1; x>=0; x--)   	
						Sel.options[x] = null;
						
					Sel[Sel.length] = new Option('---------------');
				 
					for (x=0; x<=xml.length-1; x++) 	
						Sel[Sel.length] = new Option(xml[x].getAttribute(Tagname));
					
					if (xml.length == 1)	
						Sel.selectedIndex = 1;
				}
				else
				{
					for (x=Sel.length-1; x>=0; x--)	
						Sel.options[x] = null;
	
					Sel[Sel.length] = new Option('---------------');
				}
			}
		};
	
	   xhr.open("GET", URL,  true);
	   xhr.send(null);
   }
} 

//----------------- UTILS.JS -----------------------
var moz = (document.implementation && document.implementation.createDocument); 
var ie = (window.ActiveXObject); 

var INTEGERS = "0123456789";
var REALS = "0123456789.,";
var CHARS    = "aàbcçdeéèëfghiïîjklmnopqrstuüùvwxyz -"; 
var LOGIN = "abcdefghijklmnopqrstuvwxyz0123456789-._"
var LETTERS = "abcdefghijklmnopqrstuvwxyz ";
var SEPAR   = "-.";
var PONCT   = ",;:/()[]\"'@=+-_?!$*£%&~";
var NET	    = "@&-.=";
var VIRG	= ",.";

//////////////////////////////////////   Styles   //////////////////////////////////////
function InitRadioAndCheckBox()
{
	var form = window.document.forms[0];
	for(x=0; x<form.elements.length; x++) 
	{
		if ((form.elements[x].type=="checkbox") || (form.elements[x].type=="radio")) 
		{ 	
			// Style : Disable la bordure:
			form.elements[x].style.borderWidth = "0px";
			form.elements[x].style.backgroundColor="white";
			form.elements[x].style.width= "20px";
			form.elements[x].style.textalign= "center";
			form.elements[x].style.verticalAlign = "middle";		
		}
	}
}
 
function InitStyle(elm)
{
	elm.className = "items";
}

function SetStyleErr(elm)
{
	elm.className = "items-error";
}

function ApplyStyleInitialisation()
{
	var nodes = document.getElementsByTagName("input");
	for (var i=0; i<nodes.length; i++) 
	{
		//if (nodes[i].getAttribute("type") == "text" || nodes[i].getAttribute("type") == "password" || nodes[i].getAttribute("type") == "file")
		if (nodes[i].getAttribute("type") != "checkbox" && nodes[i].getAttribute("type") != "radio")
		{
			InitStyle(nodes[i]);
		}
	}
	
	nodes = document.getElementsByTagName("select");
	for (var i=0; i<nodes.length; i++) 
	{
		InitStyle(nodes[i]);
	}
}

function CheckRequierdElement(form) {
	var res = false;
	for (var i=0; i<form.elements.length; i++) 
	{
		if (form.elements[i].getAttribute("type") == "text" && form.elements[i].getAttribute("required") == "true")
		{
			if (form.elements[i].value == "")
			{
				SetStyleErr(form.elements[i]);
				res = true;
			}
			else
				InitStyle(form.elements[i]);
		}
	}
	//nodes = document.getElementsByTagName("select");
	//if (nodes)
	//for (var i=0; i<nodes.length; i++) 
	for (var j=0; j<form.elements.length; j++) 
	{
		if (form.elements[j].options)
		{
			if (form.elements[j].getAttribute("required") == "true")
			{
				if (form.elements[j].options.length != 0)
				{
					var elmVal = form.elements[j].options[form.elements[j].selectedIndex].text;
					if (elmVal.indexOf('---') != -1 || elmVal == "")
					{
						SetStyleErr(form.elements[j]);
						res = true;
					}
					else
						InitStyle(form.elements[j]);
				}
				else
				{
					SetStyleErr(form.elements[j]);
					res = true;
				}
			}
		}
	}
	return res;
}


function ModifyBGColor(id, newColor)
{
	var mElement = document.getElementById(id);
	mElement.style.backgroundColor = newColor;
}
function ModifyTextColor(id, newColor)
{
	var mElement = document.getElementById(id);
	mElement.style.color = newColor;
}
function ModifyBoxSize(id, newWidth, newHeight)
{
	var mElement = document.getElementById(id);
	mElement.style.width = newWidth;
	mElement.style.height = newheight;
}
function ModifyBoxPosition(id, newLeft, newTop)
{
	var mElement = document.getElementById(id);
	mElement.style.left = newLeft;
	mElement.style.top = newTop;
}

////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////   Fonctions utiles communes   //////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////

function Display(id, div)
{
	if (document.getElementById(id).selectedIndex == 0)
		document.getElementById(div).style.display = "block";
	else
		document.getElementById(div).style.display = "none";
	
}

function DisplayHide(id)
{
	if (document.getElementById(id).style.display == "none")
		document.getElementById(id).style.display = "block";
	else
		document.getElementById(id).style.display = "none";
}

function swapMenu(n)
{
	window.focus();
	d=eval("document.all.d"+n);

	if (d.style.display=="none")
		{
			d.style.display="block";
		}
	else
		{
			d.style.display="none";
		}
}

function GoBack()
{
	if (moz)
	{
		if (location.href.indexOf('moto_page3.gsp') != -1)
		{
			var nbr = parseInt(document.getElementById('NbrRetour').value);
			nbr = -(2*nbr + 1);
			if (location.href.charAt(location.href.length - 1) == "#")
				nbr -= 1;
			//alert(nbr)
			location.href = "javascript:window.history.go("+nbr+")";

		}
		else
		{
			if (location.href.charAt(location.href.length - 1) != "#")
				location.href = "javascript:window.history.go(-1)";
			else
				location.href = "javascript:window.history.go(-2)";
		}
	}
	else
	{
		if (location.href.indexOf('moto_page3.gsp') != -1)
		{
			var nbr = parseInt(document.getElementById('NbrRetour').value);
			nbr = -(nbr + 1);
			location.href = "javascript:window.history.go("+nbr+")";
		}
		else
			location.href = "javascript:window.history.go(-1)";
	}
}

function openWindow(obj, url)
{
	/*if (moz) GoBack();*/
	window.open(url);
}

function CallGSPMethod(ValueName) {
	window.document.GENERIC_FORM.Opération.value = ValueName;
	window.document.GENERIC_FORM.submit();
}

function sleep(millis) 
{
	var date = new Date();
	var curDate = null;
	
	do { curDate = new Date(); } 
	while(curDate-date < millis);
}
 
 function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	setCookie(name,"",-1);
}

function checkEmail(emailAddr) {
	// Cette fonction vérifie la bon format d'une adresse e-mail.
	// Comme :
	// user@domain.com ou user.perso@domain.com
	
	var i;
	
	// Recherche de @
	i = emailAddr.indexOf("@");
	if (i == -1) {
		return false;
	}
	
	// Séparation du nom de l'utilisateur et du nom de domaine.
	var username = emailAddr.substring(0, i);
	var domain = emailAddr.substring(i + 1, emailAddr.length)

	// Recherche des espaces au début du nom de l'utilisateur.
	i = 0;
	while ((username.substring(i, i + 1) == " ") && (i < username.length)) {
		i++;
	}
	// Les enlève s'il en trouve.
	if (i > 0) {
		username = username.substring(i, username.length);
	}

	// Recherche d'espaces à la fin du nom de domaine.
	i = domain.length - 1;
	while ((domain.substring(i, i + 1) == " ") && (i >= 0)) {
		i--;
	}
	// Les enlève s'il en trouve.
	if (i < (domain.length - 1)) {
		domain = domain.substring(0, i + 1);
	}

	// Vérifie que le nom de l'utilisateur et du domaine ne soit pas vide.
	if ((username == "") || (domain == "")) {
		return false;
	}
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de l'utilisateur.
	var ch;
	for (i = 0; i < username.length; i++) {
		ch = (username.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= "a") && (ch <= "z")) || 
			((ch >= "0") && (ch <= "9")) ||
			(ch == "_") || (ch == "-") || (ch == "."))) {
				return false;
		}
	}
	
	// Vérifie s'il n'y a pas de caractères interdits dans le nom de domaine
	for (i = 0; i < domain.length; i++) {
		ch = (domain.substring(i, i + 1)).toLowerCase();
		if (!(((ch >= "a") && (ch <= "z")) || 
			((ch >= "0") && (ch <= "9")) ||
			(ch == "_") || (ch == "-") || (ch == "."))) {
				return false;
		}
	}

	// Ajouter ci-dessous de nouveaux noms de domaine.
	// Voir tous les noms de domaine sur http://www.toulouse-renaissance.net/c_outils/c-nom-domaine.htm
	//
	var aSuffix = new Array("com","net","int","aero","biz","museum","name","info","coop","pro","eu","edu","org","gov","mil","bj","dz","de","ad","be","ca","bf","bi","cm","cf","cg","cd","ci","dj","fr","ga","gp","gf","lu","mg","ml","ma","mq","mr","mc","nc","pf","re","pm","sn","ch","td","tf","tn");
	var bFoundSuffix = false;
	i = 0;
	while (i < aSuffix.length) {
		if (("." + aSuffix[i]) == domain.substring(domain.length - aSuffix[i].length - 1, domain.length)) {
			return true;
		}
		i++;
	}
	// Si le nom de domaine est inconnu  : return false
	return false;
	
}

function AllCharsOfAreIn(String1, String2) {
	for(i = 0 ; i < String1.length ; i++) {
		if(String2.indexOf(String1.charAt(i)) == -1) {
			return false;
		}
	}
	return true;
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber;
}

function IsDateValide(date) { //------------- Szou 18-06-08  retourne si la date est valide 
	d = new Date();
	var tab = date.split("/");
	var DayItem = tab[0];//date.substr(0,2);
	var MonthItem = tab[1];//date.substr(3,2);
	var YearItem = tab[2];//date.substr(6,4);		
	// Définition du dernier jour de février
	// Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
	var fev;
	if (YearItem%4 == 0 && YearItem%100 !=0 || YearItem%400 == 0) 
		fev = 29;
	else
		fev = 28;

	// Nombre de jours pour chaque mois
	var nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
	if(date.length == 10) {
		// Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
		return ( MonthItem >= 1 && MonthItem <=12 && DayItem >= 1 && DayItem <= nbJours[MonthItem-1] ); 
	}
	return false;
}

function IsDateAfterStrict(date_from, date_to) {
	if( date_from.getYear() > date_to.getYear() )  {
	
		return true ;
	} else if( date_from.getYear() == date_to.getYear() ) {
	
		if( date_from.getMonth() > date_to.getMonth() ) {
	
			return true;
		} else if( date_from.getMonth() == date_to.getMonth() )  {
	
			if( date_from.getDate() > date_to.getDate() ){
				return true;
			} 
		}
	}
	return false;
}
function IsDateAfter(date_from, date_to) {
	if( date_from.getFullYear() > date_to.getFullYear() )  {
		return true ;
	} else if( date_from.getFullYear() == date_to.getFullYear() ) {
		if( date_from.getMonth() > date_to.getMonth() ) {
			return true;
		} else if( date_from.getMonth() == date_to.getMonth() )  {		
			if( date_from.getDate() >= date_to.getDate() ){	
				return true;
			} 
		}
	}
	return false;
}

function IsDateBeforeStrict(date_from, date_to) {
	if( date_from.getFullYear() < date_to.getFullYear() )  {
		return true ;
	} else if( date_from.getFullYear() == date_to.getFullYear() ) {
		if( date_from.getMonth() < date_to.getMonth() ) {
			return true;
		} else if( date_from.getMonth() == date_to.getMonth() )  {
			if( date_from.getDate() < date_to.getDate() ){
                             return true;
			} 
		}
	}
	return false;
}

function IsDateBefore(date_from, date_to) {
	if( date_from.getFullYear() < date_to.getFullYear() )  {
		return true ;
	} else if( date_from.getFullYear() == date_to.getFullYear() ) {
		if( date_from.getMonth() < date_to.getMonth() ) {
			return true;
		} else if( date_from.getMonth() == date_to.getMonth() )  {
			if( date_from.getDate() <= date_to.getDate() ){
                             return true;
			} 
		}
	}
	return false;
}

function DateFromBeforeDateToByYear(date_from, date_to, diff) {
	var tab = date_from.split("/");
	var DayFromItem = tab[0];//date_from.substr(0,2);
	var MonthFromItem = tab[1];//date_from.substr(3,2);
	var YearFromItem = tab[2];//date_from.substr(6,4);
	date_from = new Date(YearFromItem, MonthFromItem-1, DayFromItem);
	
	var tab2 = date_to.split("/");
	var DayToItem = tab2[0];//date_to.substr(0,2);
	var MonthToItem = tab2[1];//date_to.substr(3,2);
	var YearToItem = tab2[2];//date_to.substr(6,4);
	date_to = new Date(YearToItem, MonthToItem-1, DayToItem);
	
	year = date_to.getFullYear() - diff;
	if( date_from.getFullYear() > year )  {
		return false ;
	} else if( date_from.getFullYear() == year ) {
		if( date_from.getMonth() > date_to.getMonth() ) {
			return false;
		} else if( date_from.getMonth() == date_to.getMonth() )  {
			if( date_from.getDate() > date_to.getDate() ){
                             return false;
			} 
		}
	}
	return true;
}

function CheckName(theName) {
	if(theName.length > 0) {
		return AllCharsOfAreIn(theName.toLowerCase(), CHARS);
	} else {
		return false;
	}
}

function CheckTelephone(theNumber) {
	if(theNumber.length > 0) 
		if(theNumber.length == 10) 
			return AllCharsOfAreIn(theNumber, INTEGERS);
		else
			return false;
	else
		return false;
}

function CheckPostalCode(theNumber) {
	if(theNumber.length != 5) {
		return false;
	}
	return AllCharsOfAreIn(theNumber, INTEGERS);
}

function trim (myString) 
{ 
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}

//--------------------- DateFormat.js ------------------------------------
function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return true; }
	}
	else 
	{
		if ((intYear % 4) == 0) { return true; }
}
	return false;
}

function dateValid(objName) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
// var err = 0;
var strMonthArray = new Array(12);

	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";

//strDate = datefield.value;
	strDate = objName;
	if (strDate.length < 1) 
	{
	return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false) 
	{
		if (strDate.length>5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
//Adjustment for short years entered
	if (strYear.length == 2) 
	{
		strYear = '20' + strYear;
	}
	strTemp = strDay;
	strDay = strMonth;
	strMonth = strTemp;
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
			intMonth = i+1;
			strMonth = strMonthArray[i];
			i = 12;
			}
		}
		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return false;
	}
	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;
				return false;
			}
		}
	else 
		{
			if (intday > 28) 
			{
				err = 10;
				return false;
			}
		}
	}
	return true;
}

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType,idError) {
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/"; 
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
	if(navigator.appName == "Netscape") 
	{
		if (navigator.appVersion < "5") 
		{
			isNav4 = true;
			isNav5 = false;
		}
	else
		if (navigator.appVersion > "4") 
		{
			isNav4 = false;
			isNav5 = true;
		}
	}
	else 
	{
		isIE4 = true;
	}
	vDateType = dateType;

//Enter a tilde sign for the first number and you can check the variable information.
	if (vDateValue == "~") 
	{
		alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
		vDateName.value = "";
		vDateName.focus();
		return true;
	}
var whichCode = (window.Event) ? e.which : e.keyCode;
// Check to see if a seperator is already present.
// bypass the date if a seperator is present and the length greater than 8
	if (vDateValue.length > 8 && isNav4) 
	{
		if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
			return true;
	}
//Eliminate all the ASCII codes that are not valid
var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
	if (alphaCheck.indexOf(vDateValue) >= 1) 
	{
		if (isNav4) 
		{
			vDateName.value = "";
			vDateName.focus();
			vDateName.select();
			return false;
		}
	else 
		{
			vDateName.value = vDateName.value.substr(0, (vDateValue.length-1));
			return false;
		}
	}
	if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
		return false;
	else 
	{
		//Create numeric string values for 0123456789/
		//The codes provided include both keyboard and keypad values
		var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
		if (strCheck.indexOf(whichCode) != -1) 
		{
			if (isNav4) 
			{
				if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) 
				{
					alert("1 Invalid Date\nPlease Re-Enter");
					vDateName.value = "";
					vDateName.focus();
					vDateName.select();
					return false;
				}		
				if (vDateValue.length == 6 && dateCheck) 
				{
					var mDay = vDateName.value.substr(2,2);
					var mMonth = vDateName.value.substr(0,2);
					var mYear = vDateName.value.substr(4,4)
					/*
					//Turn a two digit year into a 4 digit year
					if (mYear.length == 2 && vYearType == 4) 
					{
						var mToday = new Date();
						//If the year is greater than 30 years from now use 19, otherwise use 20
						var checkYear = mToday.getFullYear() + 30; 
						var mCheckYear = '20' + mYear;
						if (mCheckYear >= checkYear)
						mYear = '19' + mYear;
						else
						mYear = '20' + mYear;
					}*/
					var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
					if (!dateValid(vDateValueCheck)) 
					{
						DisplayError(idError);
						vDateType = vDateTypeTemp;
						vDateName.focus();
						return true;
					}
					else
					{
						EraseError(idError)
					}
					return true;
				}		
				else 
				{
					// Reformat the date for validation and set date type to a 1
					if (vDateValue.length >= 8  && dateCheck) 
					{
						/*if (vDateType == 1) // mmddyyyy
						{
							var mDay = vDateName.value.substr(2,2);
							var mMonth = vDateName.value.substr(0,2);
							var mYear = vDateName.value.substr(4,4)
							vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
						}
						if (vDateType == 2) // yyyymmdd
						{
							var mYear = vDateName.value.substr(0,4)
							var mMonth = vDateName.value.substr(4,2);
							var mDay = vDateName.value.substr(6,2);
							vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
						}*/
						if (vDateType == 3) // ddmmyyyy
						{
						var mMonth = vDateName.value.substr(2,2);
						var mDay = vDateName.value.substr(0,2);
						var mYear = vDateName.value.substr(4,4)
						vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
						}
						//Create a temporary variable for storing the DateType and change
						//the DateType to a 1 for validation.
						var vDateTypeTemp = vDateType;
						vDateType = 1;
						var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
						if (!dateValid(vDateValueCheck)) 
						{
							DisplayError(idError);
							vDateType = vDateTypeTemp;
							vDateName.focus();
							return true;
						}
						else
						{
							EraseError(idError)
						}
						vDateType = vDateTypeTemp;
						return true;
					}
					else 
					{
						if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) 
						{
							alert("4 Invalid Date\nPlease Re-Enter");
							vDateName.value = "";
							vDateName.focus();
							vDateName.select();
							return false;
						}
					}
				}
			}
			else // Non isNav Check
			{
				
				/*
				if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) 
				{
					alert("5 Invalid Date\nPlease Re-Enter");
					vDateName.value = "";
					vDateName.focus();
					return true;
				}				
				*/
				// Reformat date to format that can be validated. mm/dd/yyyy
				if (vDateValue.length >= 8 && dateCheck) 
				{
					// Additional date formats can be entered here and parsed out to
					// a valid date format that the validation routine will recognize.
					/*if (vDateType == 1) // mm/dd/yyyy
					{
						var mMonth = vDateName.value.substr(0,2);
						var mDay = vDateName.value.substr(3,2);
						var mYear = vDateName.value.substr(6,4)
					}
					if (vDateType == 2) // yyyy/mm/dd
					{
						var mYear = vDateName.value.substr(0,4)
						var mMonth = vDateName.value.substr(5,2);
						var mDay = vDateName.value.substr(8,2);
					}*/
					if (vDateType == 3) // dd/mm/yyyy
					{
						var mDay = vDateName.value.substr(0,2);
						var mMonth = vDateName.value.substr(3,2);
						var mYear = vDateName.value.substr(6,4)
					}
					if (vYearLength == 4) 
					{
						if (mYear.length < 4) 
						{
						alert("6 Invalid Date\nPlease Re-Enter");
						vDateName.value = "";
						vDateName.focus();
						return true;
						}
					}
					// Create temp. variable for storing the current vDateType
					var vDateTypeTemp = vDateType;
					// Change vDateType to a 1 for standard date format for validation
					// Type will be changed back when validation is completed.
					vDateType = 1;
					// Store reformatted date to new variable for validation.
					var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
					if (mYear.length == 2 && vYearType == 4 && dateCheck) 
					{
						/*
						//Turn a two digit year into a 4 digit year
						var mToday = new Date();
						//If the year is greater than 30 years from now use 19, otherwise use 20
						var checkYear = mToday.getFullYear() + 30; 
						var mCheckYear = '20' + mYear;
						if (mCheckYear >= checkYear)
							mYear = '19' + mYear;
						else
							mYear = '20' + mYear;
						*/
						vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
						// Store the new value back to the field.  This function will
						// not work with date type of 2 since the year is entered first.
						if (vDateTypeTemp == 1) // mm/dd/yyyy
						vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
						if (vDateTypeTemp == 3) // dd/mm/yyyy
						vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
					} 
					
						if (!dateValid(vDateValueCheck)) 
						{
							DisplayError(idError);
							vDateType = vDateTypeTemp;
							vDateName.focus();
							return true;
						}
						else
						{
							EraseError(idError)
						}
						vDateType = vDateTypeTemp;
						return true;
				}
				else 
				{
					/*if (vDateType == 1) 
					{
						if (vDateValue.length == 2) 
						{
							vDateName.value = vDateValue+strSeperator;
						}
						if (vDateValue.length == 5) 
						{
							vDateName.value = vDateValue+strSeperator;
						}
					}
					if (vDateType == 2) 
					{
						if (vDateValue.length == 4) 
						{
							vDateName.value = vDateValue+strSeperator;
						}	
						if (vDateValue.length == 7) 
						{
							vDateName.value = vDateValue+strSeperator;
						}
					} */
					if (vDateType == 3) 
					{
						if (vDateValue.length == 2) 
						{
							vDateName.value = vDateValue+strSeperator;
						}
						if (vDateValue.length == 5) 	
						{
							vDateName.value = vDateValue+strSeperator;
						}
					}
					return true;
				}
			}
			if (vDateValue.length == 10&& dateCheck) 
			{
				if (!dateValid(vDateName)) 
				{
					DisplayError(idError);
					vDateType = vDateTypeTemp;
					vDateName.focus();
					return true;
				}
				else
				{
					EraseError(idError)
				}
			}
			return false;
		}
		else 
		{
			// If the value is not in the string return the string minus the last
			// key entered.
			if (isNav4) 
			{
				vDateName.value = "";
				vDateName.focus();
				vDateName.select();
				return false;
			}
		}
	}
}

function DisplayError(idError)
{
	var element = document.getElementById(idError)
	if (element != undefined)
	  	element.innerHTML = '* Date invalide';
}

function EraseError(idError)
{
	var element = document.getElementById(idError)
	if (element != undefined)
		element.innerHTML = '';
}

function FormatDateOnBlurEvent(vDateName)
{
	var mDay = vDateName.value.substr(0,2);
	var mMonth = vDateName.value.substr(3,2);
	var mYear = vDateName.value.substr(6,4);
	var strSeperator = vDateName.value.substr(2,1);
	if (mYear.length == 2)
	{			
		var mToday = new Date();
		//If the year is greater than 30 years from now use 19, otherwise use 20
		var checkYear = mToday.getFullYear() + 30; 
		var mCheckYear = '20' + mYear;
		if (mCheckYear >= checkYear)
			mYear = '19' + mYear;
		else
			mYear = '20' + mYear;
	}
	vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
}
/* ------------------------ ROLL ------------------------ */
var a
 a= new Array();
 a[0]=new Image;
 a[0].src="../img/scoot-assurance-banner-votre-devis-50cc.gif";
 a[1]=new Image;
 a[1].src="../img/scoot-assurance-banner-votre-devis-50cc-on.gif";
 a[2]=new Image;
 a[2].src="../img/scoot-assurance-banner-votre-devis-plus50cc.gif";
 a[3]=new Image;
 a[3].src="../img/scoot-assurance-banner-votre-devis-plus50cc-on.gif";
 a[4]=new Image;
 a[4].src="../img/scoot-assurance-center-50cc-votre-devis.jpg";
 a[5]=new Image;
 a[5].src="../img/scoot-assurance-center-50cc-votre-devis-on.jpg";
 a[6]=new Image;
 a[6].src="../img/scoot-assurance-center-50ccplus-votre-devis.jpg";
 a[7]=new Image;
 a[7].src="../img/scoot-assurance-center-50ccplus-votre-devis-on.jpg";
 //----------------- ROLL du menu
 a[8]=new Image;
 a[8].src="../img/scoot-btn-toutsur-off.gif";
 a[9]=new Image;
 a[9].src="../img/scoot-btn-toutsur.gif";
 a[10]=new Image;
 a[10].src="../img/scoot-btn-nouschoisir-off.gif";
 a[11]=new Image;
 a[11].src="../img/scoot-btn-nouschoisir.gif";
 a[12]=new Image;
 a[12].src="../img/scoot-btn-actu-off.gif";
 a[13]=new Image;
 a[13].src="../img/scoot-btn-actu.gif";
 a[14]=new Image;
 a[14].src="../img/scoot-btn-quisommes-off.gif";
 a[15]=new Image;
 a[15].src="../img/scoot-btn-quisommes.gif";
 a[16]=new Image;
 a[16].src="../img/scoot-btn-sinistre-off.gif";
 a[17]=new Image;
 a[17].src="../img/scoot-btn-sinistre.gif";
 a[18]=new Image;
 a[18].src="../img/scoot-btn-suite.jpg";
 a[19]=new Image;
 a[19].src="../img/scoot-btn-suite-on.jpg";
 
 a[20]=new Image;
 a[20].src="../img/scoot-btn-back.jpg";
 a[21]=new Image;
 a[21].src="../img/scoot-btn-back-on.jpg";
 a[22]=new Image;
 a[22].src="../img/scoot-btn-modifier.gif";
 a[23]=new Image;
 a[23].src="../img/scoot-btn-modifier-on.gif";
 a[24]=new Image;
 a[24].src="../img/scoot-btn-editer-devis-off.gif";
 a[25]=new Image;
 a[25].src="../img/scoot-btn-editer-devis.gif";
 
function AddEventsToImages() {
            if (document.images['img0'])
			{document.images['img0'].onmouseover = function() { roll('img0',1); }
            document.images['img0'].onmouseout = function() { roll('img0',0); }
			}			
			if (document.images['img1'])
			{document.images['img1'].onmouseover = function() { roll('img1',3); }
            document.images['img1'].onmouseout = function() { roll('img1',2); }
			}
			 if (document.images['VotreDev50cc'])
			{document.images['VotreDev50cc'].onmouseover = function() { roll('VotreDev50cc',5); }
            document.images['VotreDev50cc'].onmouseout = function() { roll('VotreDev50cc',4); }
			}			
			if (document.images['VotreDev50ccplus'])
			{document.images['VotreDev50ccplus'].onmouseover = function() { roll('VotreDev50ccplus',7); }
            document.images['VotreDev50ccplus'].onmouseout = function() { roll('VotreDev50ccplus',6); }
			}
			//---- Menu
			if (document.images['img2'])
			{document.images['img2'].onmouseover = function() { roll('img2',9); }
            document.images['img2'].onmouseout = function() { roll('img2',8); }
			}			
			if (document.images['img3'])
			{document.images['img3'].onmouseover = function() { roll('img3',11); }
            document.images['img3'].onmouseout = function() { roll('img3',10); }
			}
			if (document.images['img4'])
			{document.images['img4'].onmouseover = function() { roll('img4',13); }
            document.images['img4'].onmouseout = function() { roll('img4',12); }
			}			
			if (document.images['img5'])
			{document.images['img5'].onmouseover = function() { roll('img5',15); }
            document.images['img5'].onmouseout = function() { roll('img5',14); }
			}
			if (document.images['img6'])
			{document.images['img6'].onmouseover = function() { roll('img6',17); }
            document.images['img6'].onmouseout = function() { roll('img6',16); }
			}
			if (document.images['btSuite'])
			{document.images['btSuite'].onmouseover = function() { roll('btSuite',19); }
            document.images['btSuite'].onmouseout = function() { roll('btSuite',18); }
			}
			if (document.images['btBack'])
			{document.images['btBack'].onmouseover = function() { roll('btBack',21); }
            document.images['btBack'].onmouseout = function() { roll('btBack',20); }
			}
			if (document.images['btMaj'])
			{document.images['btMaj'].onmouseover = function() { roll('btMaj',23); }
            document.images['btMaj'].onmouseout = function() { roll('btMaj',22); }
			}
			if (document.images['editerdevis'])
			{document.images['editerdevis'].onmouseover = function() { roll('editerdevis',25); }
            document.images['editerdevis'].onmouseout = function() { roll('editerdevis',24); }
			}
}

function roll(img,nb) {
   //eval("document.images[img].src=a["+nb+"].src");
   eval("img.src=a["+nb+"].src");
}

function DisplayItem(n1,n2,x)
{
	var d;
	for (i=n1; i<=n2; i++)
	{
		d = eval("document.getElementById('t'+i)");
		if (i == x)
		{
			if (d.style.display=="block")
				d.style.display="none";
			else
				d.style.display="block";
		}
		else
			d.style.display="none";
	}
}

/////////  AJAX

function initialiseAnHttpRequest(url)
{
	if (moz)    { xmlHTTP = new XMLHttpRequest();}
   	else if (ie) { xmlHTTP = new ActiveXObject('Microsoft.XMLHTTP');}		
	if (xmlHTTP!=null)
 	{
		//Mode synchrone
		xmlHTTP.onreadystatechange=state_Change;
		xmlHTTP.open("GET",url,false);
		//Mode asynchrone
		xmlHTTP.send(null);
  	}
	else
  	{
  		alert("Your browser does not support XMLHTTP.");
  	}
	
}

function state_Change()
{
	if (xmlHTTP.readyState==4)
  	{
		if (xmlHTTP.status==200)
    		{
    			// ...some code here...
    		}
 	 	else
    		{
    			alert("Problem retrieving XML data. Status's code is ="+xmlHTTP.status)
    		}
  	}
	
}

//------------ Gérer le passage de la var 'name' avec le GSP
function SetSession(name, val)
{
	initialiseAnHttpRequest('/infos/SetSession.asp?name='+name+'&value='+val);	
}

function GetSession(name)
{
	url = '/infos/GetSession.asp?name='+name; 
   	initialiseAnHttpRequest(url);
	var xml;
	var node;

	var res = "";
	if (ie)
	{
		xml = xmlHTTP.responseXML;
		var docXML= xmlHTTP.responseXML.documentElement;
		res = xml.childNodes(1).getAttribute('value');
	}
	else if (moz)
	{
		xml = xmlHTTP.responseXML;
		var docXML= xmlHTTP.responseXML.documentElement;

		res = docXML.textContent;
	}
	return res;
}

// ajouter le code offre dans les liens dirigeant vers les DEVIS
function AppendCodeOffreToHREF()
{
	var codeoffre = GetSession('codeoffre');
	//alert(document.getElementsByTagName("HrefVotreDevis").length)
	if (codeoffre != '')
	{
		var nodes = document.getElementsByTagName("a");
		for (var i=0; i<nodes.length; i++) 
		{
			if (nodes[i].getAttribute("name") == "HrefVotreDevis")
			{
				nodes[i].href += "&CODE_OFFRE=" + codeoffre;
			}
		}
	}
}