﻿
//function Left(str, n){
//	if (n <= 0)
//	    return "";
//	else if (n > String(str).length)
//	    return str;
//	else
//	    return String(str).substring(0,n);
//}
//function Right(str, n){
//    if (n <= 0)
//       return "";
//    else if (n > String(str).length)
//       return str;
//    else {
//       var iLen = String(str).length;
//       return String(str).substring(iLen, iLen - n);
//    }
//}


/////////////////////////////////////////////////
// empêche un élément 'DISABLED' d'une liste 'SELECT' d'être sélectionné (BUG IE)
/////////////////////////////////////////////////

function preventSelectDisabled(oSelect) {
	var isOptionDisabled = oSelect.options[oSelect.selectedIndex].disabled;
          if(isOptionDisabled) {
              oSelect.selectedIndex = oSelect.defaultSelectedIndex;
              return false;
          }
          //else oSelect.defaultSelectedIndex = oSelect.selectedIndex;
          return true;
}



/////////////////////////////////////////////////
// fait clignoter un élément (compatible tous navigateurs)
/////////////////////////////////////////////////

function blinkIt() {
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
   }
 }
}
setInterval('blinkIt()',500);


/////////////////////////////////////////////////
// affiche un élément s'il est caché, le cache s'il est visible
/////////////////////////////////////////////////


function toggle_display(elmt){
if (getObject(elmt).style.display=="none")
	{
	show(elmt);
	}
	else
	{
	hide(elmt);
	}
}





/////////////////////////////////////////////////
// idem fonction right en Vb
/////////////////////////////////////////////////

function Right(str, n)
{
  if (n <= 0) 
  {
    return "";
  }
  else if (n > String(str).length) 
  {
    return str; 
  }
  else 
  { 
    var iLen = String(str).length;
    return String(str).substring(iLen, iLen - n);
  }
}


/////////////////////////////////////////////////
// récupérer les variables passées dans l'url comme en asp
/////////////////////////////////////////////////

function RObj(ea){var LS="";var QS=new Object();var un="undefined";var x=null;var f="function";var n="number";var r="string";var e1="ERROR:Index out of range in\r\nRequest.QueryString";var e2="ERROR:Wrong number of arguments or invalid property assignment\r\nRequest.QueryString";var e3="ERROR:Object doesn't support this property or method\r\nRequest.QueryString.Key";function Err(arg){if(ea){alert("Request Object:\r\n"+arg)}};function URID(t){var d="";if(t){for(var i=0;i<t.length;++i){var c=t.charAt(i);d+=(c=="+"?" ":c)}};return unescape(d)};function OL(o){var l=0;for(var i in o){if(typeof o[i]!=f){l++}};return l};function AK(key){var auk=true;for(var u in QS){if(typeof QS[u]!=f&&u.toString().toLowerCase()==key.toLowerCase()){auk=false;return u}}if(auk){QS[key]=new Object();QS[key].toString=function(){return TS(QS[key])};QS[key].Count=function(){return OL(QS[key])};QS[key].Count.toString=function(){return OL(QS[key]).toString()};QS[key].Item=function(e){if(typeof e==un){return QS[key]}else {if(typeof e==n){var a=QS[key][Math.ceil(e)];if(typeof a==un){Err(e1+"(\""+key+"\").Item("+e+")")};return a}else {Err("ERROR:Expecting numeric input in\r\nRequest.QueryString(\""+key+"\").Item(\""+e+"\")")}}};QS[key].Item.toString=function(e){if(typeof e==un){return QS[key].toString()}else {var a=QS[key][e];if(typeof a==un){Err(e1+"(\""+key+"\").Item("+e+")")};return a.toString()}};QS[key].Key=function(e){var t=typeof e;if(t==r){var a=QS[key][e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e3+"("+(e?e:"")+")")}};QS[key].Key.toString=function(){return x}};return key};function AVTK(key,val){if(key!=""){var key=AK(key);var l=OL(QS[key]);QS[key][l+1]=val}};function TS(o){var s="";for(var i in o){var ty=typeof o[i];if(ty=="object"){s+=TS(o[i])}else if(ty!=f){s+=o[i]+", "}};var l=s.length;if(l>1){return(s.substring(0,l-2))}return(s==""?x:s)};function KM(k,o){var k=k.toLowerCase();for(var u in o){if(typeof o[u]!=f&&u.toString().toLowerCase()==k){return u}}}if(window.location&&window.location.search){LS=window.location.search;var l=LS.length;if(l>0){LS=LS.substring(1,l);var preAmpAt=0;var ampAt=-1;var eqAt=-1;var k=0;var skip=false;for(var i=0;i<l;++i){var c=LS.charAt(i);if(LS.charAt(preAmpAt)=="="||(preAmpAt==0&&i==0&&c=="=")){skip=true}if(c=="="&&eqAt==-1&&!skip){eqAt=i}if(c=="&"&&ampAt==-1){if(eqAt!=-1){ampAt=i}if(skip){preAmpAt=i+1};skip=false}if(ampAt>eqAt){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,ampAt)));preAmpAt=ampAt+1;eqAt=ampAt=-1;++k}}if(LS.charAt(preAmpAt)!="="&&(preAmpAt!=0||i!=0||c!="=")){if(preAmpAt!=l){if(eqAt!=-1){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,l)))}else if(preAmpAt!=l-1){AVTK(URID(LS.substring(preAmpAt,l)),"")}}if(l==1){AVTK(LS.substring(0,1),"")}}}};var TC=OL(QS);if(!TC){TC=0};QS.toString=function(){return LS.toString()};QS.Count=function(){return(TC?TC:0)};QS.Count.toString=function(){return(TC?TC.toString():"0")};QS.Item=function(e){if(typeof e==un){return LS}else {if(typeof e==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return QS[i]}};Err(e1+"().Item("+e+")")}else {return QS[KM(e,QS)]}};return x};QS.Item.toString=function(){return LS.toString()};QS.Key=function(e){var t=typeof e;if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return i}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e2+"().Key("+(e?e:"")+")")};Err(e1+"().Item("+e+")")};QS.Key.toString=function(){Err(e2+"().Key")};this.QueryString=function(k){if(typeof k==un){return QS}else {var k=KM(k,QS);if(typeof QS[k]==un){t=new Object();t.Count=function(){return 0};t.Count.toString=function(){return "0"};t.toString=function(){return x};t.Item=function(e){return x};t.Item.toString=function(){return x};t.Key=function(e){Err(e3+"("+(e?e:"")+")")};t.Key.toString=function(){return x};return t}if(typeof k==n){return QS.Item(k)}else {return QS[k]}}};this.QueryString.toString=function(){return LS.toString()};this.QueryString.Count=function(){return(TC?TC:0)};this.QueryString.Count.toString=function(){return(TC?TC.toString():"0")};this.QueryString.Item=function(e){if(typeof e==un){return LS.toString()}else {if(typeof e==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]!=f&&++c==e){return QS[i]}};Err(e1+".Item("+e+")")}else {return QS[KM(e,QS)]}}if(typeof e==n){Err(e1+".Item("+e+")")};return x};this.QueryString.Item.toString=function(){return LS.toString()};this.QueryString.Key=function(e){var t=typeof e;if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof QS[i]=="object"&&(++c==e)){return i}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof a!=un&&a&&a.toString()?e:"")}else {Err(e2+".Key("+(e?e:"")+")")};Err(e1+".Item("+e+")")};this.QueryString.Key.toString=function(){Err(e2+".Key")};this.Version=1.3;this.Author="Andrew Urquhart (www.andrewu.co.uk)"};var Request=new RObj(false);


/////////////////////////////////////////////////
// recupérer les variables de l'url
/////////////////////////////////////////////////

  var qs = location.search.substring(1);
  var nv = qs.split('&');
  var url = new Object();
  for(i = 0; i < nv.length; i++)
  {
    eq = nv[i].indexOf('=');
    url[nv[i].substring(0,eq).toLowerCase()] = unescape(nv[i].substring(eq + 1));
  }

/////////////////////////////////////////////////
// convertir un chiffre au format devise
/////////////////////////////////////////////////


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+' '+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + ',' + cents);
}


//////////////////////////////////////////////////////
// remplacer une chaine de caractères par une autre
//////////////////////////////////////////////////////

function ereg_replace(tx,rg,ch)
{
var regEx = new RegExp(rg,"g")
return tx.replace(regEx,ch)
}


/////////////////////////////////////////////////
// convertir des euros en francs
/////////////////////////////////////////////////

function franc(id,euro)
{
var resultat=getObject(id+'FR');


if (euro && euro !=0)
	{
	
	euro=ereg_replace(euro,",",".")
		
	if (isNaN(euro))
		{
		alert ("Veuillez ne saisir que des chiffres."); 
		champ=getObject(id);
		champ.value="";
		euro=0;
		}
	francs =  Math.round(100*parseFloat(euro)*6.55957)/100;
	resultat.innerHTML ="&nbsp;soit "+formatCurrency(francs)+" F";
	}	
else	
	{
	resultat.innerHTML = "";
	}
}




////////////////////////////////////
// faire clignoter une case à cocher / a terminer
////////////////////////////////////
var compteur=0
function blinkcheckbox(checkbox) 
{
compteur++;
getObject(checkbox).checked=!(getObject(checkbox).checked);
if (compteur>=20) 
	{
	clearInterval(0);
	getObject(checkbox).checked=false;
	}
}


/////////////////////////////////
// Browser Detect  v2.1.6
/////////////////////////////////

// documentation: http://www.dithered.com/javascript/browser_detect/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)

function detect_browser() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new detect_browser();


/////////////////////////////
// fonctions pour listboxes
/////////////////////////////

//  selects an option by its value
function selectByValue(selectbox, value) {for (i = 0; i < selectbox.options.length; i++)if (selectbox.options[i].value.toLowerCase() == value.toLowerCase()){selectbox.options[i].selected=true;return;}return;} 

//  unselects an option by its value
function unselectByValue(selectbox, value) {for (i = 0; i < selectbox.options.length; i++)if (selectbox.options[i].value.toLowerCase() == value.toLowerCase()){selectbox.options[i].selected=false;return;}return;} 

//  selects all options
function selectAll(combo)
{for (var i=0;i<combo.options.length;i++){combo.options[i].selected=true;}}

//  unselects all options
function unselectAll(combo)
{for (var i=0;i<combo.options.length;i++){combo.options[i].selected=false;}}



function MoveUp(combo_name)
{
	var combo=document.getElementById(combo_name);
	i=combo.selectedIndex;
	if (i>0)
	{
		swap(combo,i,i-1);
		combo.options[i-1].selected=true;
		combo.options[i].selected=false;
	}
}

function MoveDown(combo_name)
{
	var combo=document.getElementById(combo_name);
	i=combo.selectedIndex;

	if (i<combo.length-1 && i>-1)
	{
		swap(combo,i+1,i);
		combo.options[i+1].selected=true;
		combo.options[i].selected=false;
	}
}

//this function is used to swap between elements
function swap(combo,index1, index2)
{
	var savedValue=combo.options[index1].value;
	var savedText=combo.options[index1].text;

	combo.options[index1].value=combo.options[index2].value;
	combo.options[index1].text=combo.options[index2].text;

	combo.options[index2].value=savedValue;
	combo.options[index2].text=savedText;
}

function MoveToTop(combo_name)
{
	var combo=document.getElementById(combo_name);
	i=combo.selectedIndex;
	
	for (;i>0;i--)
	{
		swap(combo,i,i-1);
		combo.options[i-1].selected=true;
		combo.options[i].selected=false;
	}
}

function MoveToBottom(combo_name)
{
	var combo=document.getElementById(combo_name);
	i=combo.selectedIndex;
	
	if (i>-1)
	{
		for (;i<combo.length-1;i++)
		{
			swap(combo,i+1,i);
			combo.options[i+1].selected=true;
			combo.options[i].selected=false;
		}
	}
}

//moves options from one selection box (combo box) to another
//removes the all selected options from one combo box and adds them to the second combo box
function MoveElements(FromComboName,ToComboName)
{
	var FromCombo=document.getElementById(FromComboName);
	var ToCombo=document.getElementById(ToComboName);

	var to_remove_counter=0; //number of options that were removed (num selected options)

	//move selected options to right select box (to)
	for (var i=0;i<FromCombo.options.length;i++)
	{
		if (FromCombo.options[i].selected==true)
		{
			var addtext=FromCombo.options[i].text;
			var addvalue=FromCombo.options[i].value;
			ToCombo.options[ToCombo.options.length]=new Option(addtext,addvalue);
			FromCombo.options[i].selected=false;
			++to_remove_counter;
		}
		else
		{
			FromCombo.options[i-to_remove_counter].selected=false;
			FromCombo.options[i-to_remove_counter].text=FromCombo.options[i].text;
			FromCombo.options[i-to_remove_counter].value=FromCombo.options[i].value;
		}
	}

	//now cleanup the last remaining options 
	var numToLeave=FromCombo.options.length-to_remove_counter;
	for (i=FromCombo.options.length-1;i>=numToLeave;i--) 
	{ 
		FromCombo.options[i]=null;
	}
}

function toggleSelectAll(combo_name)
{
	
	var select_all_link=document.getElementById('select_all_link');
	var combo=document.getElementById(combo_name);//get the select

	var to_select=true;
	var select_link_new_caption;//the new "Select All" link caption will be here
	if (select_all_link.unselectAll==true)//this is a new attribute that is dynamically added
	{
		//we now want to select all options
		to_select=false;
		select_all_link.unselectAll=false;
		select_link_new_caption="Select All";//set the new caption
	}
	else
	{
		//we now want to unselect all options
		select_all_link.unselectAll=true;
		select_link_new_caption="Unselect All";//set the new caption
	}

	select_all_link.innerText=select_link_new_caption;//change the caption of the select all link
	SelectAll(combo,to_select);
}




//  utility function to determine if a select object has an options array
function hasOptions(obj){if(obj!=null && obj.options!=null){return true;}return false;}

//  sortSelect(select_object)
//  Pass this function a SELECT object and the options will be sorted by their text (display) values
function sortSelect(obj){var o = new Array();if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;}if(o.length==0){return;}o = o.sort(
function(a,b){if((a.text+"") <(b.text+"")){return -1;}if((a.text+"") >(b.text+"")){return 1;}return 0;});for(var i=0;i<o.length;i++){obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);}}


//  moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//  onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
function moveSelectedOptions(from,to){if(arguments.length>3){var regex = arguments[3];if(regex != ""){unSelectMatchingOptions(from,regex);}}if(!hasOptions(from)){return;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(!hasOptions(to)){var index = 0;}else{var index=to.options.length;}to.options[index] = new Option( o.text, o.value, false, false);}}for(var i=(from.options.length-1);i>=0;i--){var o = from.options[i];if(o.selected){from.options[i] = null;}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(from);sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}


//  copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  this function copies options between select boxes instead of moving items. Duplicates in the target list are not allowed.
function copySelectedOptions(from,to){var options = new Object();if(hasOptions(to)){for(var i=0;i<to.options.length;i++){options[to.options[i].value] = to.options[i].text;}}if(!hasOptions(from)){return;}for(var i=0;i<from.options.length;i++){var o = from.options[i];if(o.selected){if(options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text){if(!hasOptions(to)){var index = 0;}else{var index=to.options.length;}to.options[index] = new Option( o.text, o.value, false, false);}}}if((arguments.length<3) ||(arguments[2]==true)){sortSelect(to);}from.selectedIndex = -1;to.selectedIndex = -1;}


//  moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  move all options from one select box to another.
function moveAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){moveSelectedOptions(from,to);}else if(arguments.length==3){moveSelectedOptions(from,to,arguments[2]);}else if(arguments.length==4){moveSelectedOptions(from,to,arguments[2],arguments[3]);}}


//  copyAllOptions(select_object,select_object[,autosort(true/false)])
//  copy all options from one select box to another, instead of removing items. Duplicates in the target list are not allowed.
function copyAllOptions(from,to){selectAllOptions(from);if(arguments.length==2){copySelectedOptions(from,to);}else if(arguments.length==3){copySelectedOptions(from,to,arguments[2]);}}


//  swapOptions(select_object,option1,option2)
//  swap positions of two options in a select list
function swapOptions(obj,i,j){var o = obj.options;var i_selected = o[i].selected;var j_selected = o[j].selected;var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);o[i] = temp2;o[j] = temp;o[i].selected = j_selected;o[j].selected = i_selected;}


//  moveOptionUp(select_object)
//  move selected option in a select list up one
function moveOptionUp(obj){if(!hasOptions(obj)){return;}for(i=0;i<obj.options.length;i++){if(obj.options[i].selected){if(i != 0 && !obj.options[i-1].selected){swapOptions(obj,i,i-1);obj.options[i-1].selected = true;}}}}


//  moveOptionDown(select_object)
//  move selected option in a select list down one
function moveOptionDown(obj){if(!hasOptions(obj)){return;}for(i=obj.options.length-1;i>=0;i--){if(obj.options[i].selected){if(i !=(obj.options.length-1) && ! obj.options[i+1].selected){swapOptions(obj,i,i+1);obj.options[i+1].selected = true;}}}}


//  removeSelectedOptions(select_object)
//  remove all selected options from a list
function removeSelectedOptions(from){if(!hasOptions(from)){return;}for(var i=(from.options.length-1);i>=0;i--){var o=from.options[i];if(o.selected){from.options[i] = null;}}from.selectedIndex = -1;}


//  removeAllOptions(select_object)
//  remove all options from a list
function removeAllOptions(from){if(!hasOptions(from)){return;}for(var i=(from.options.length-1);i>=0;i--){from.options[i] = null;}from.selectedIndex = -1;}


//  addOption(select_object,display_text,value,selected)
//  add an option to a list
function addOption(obj,text,value,selected){if(obj!=null && obj.options!=null){obj.options[obj.options.length] = new Option(text, value, false, selected);}}


////////////////////////////////////////////////
// changement de la couleur de fond des champs 
////////////////////////////////////////////////

function aff_bg(champ)
{
champ.style.backgroundColor='#e6ffe5';
}


////////////////////////////////////////////////
// affichage d'une bulle contextuelle
////////////////////////////////////////////////


// SHOW MENU
function showTipBox(layerName,imgName){
 img = getImage(imgName);
 TipBoxTop = getImagePageTop(img)+4; // TIP BOX TOP POSITION
 TipBoxLeft =  getImagePageLeft(img)-147; // TIP BOX LEFT POSITION
if (NS4 || IE4) {
 if (timeOn != null) {
 clearTimeout(timeOn)
 hideLayer(onLayer)
 }
 if (NS4 || IE4) {
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerVis+'"');
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top="'+TipBoxTop+'"');
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left="'+TipBoxLeft+'"');
 } 
 onLayer = layerName
 }
}

 window.onerror = null;
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
 var menuActive = 0
 var menuOn = 0
 var onLayer
 var timeOn = null // LAYER SWITCHING CODE
if (NS4 || IE4) {
 if (navigator.appName == "Netscape"){
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
layerVis="show";
layerHid="hide";
 }else
{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
layerVis="visible";
layerHid="hidden";
 }
}// HIDE MENU
function hideLayer(layerName){
 if (menuActive == 0) {
 if (NS4 || IE4) {
 eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerHid+'"');
 }
 }
}// TIMER FOR TIP BOX MOUSE OUT
function linkTimer() {
 timeOn = setTimeout("btnOut()",0)
}// MOUSE OUT
function btnOut(layerName) {
 if (menuActive == 0) {
 hideLayer(onLayer)
 }
}// GET IMAGE 
function getImage(name) {
  if (NS4) {
    return findImage(name, document);
  }
  if (IE4)
    return eval('document.all.' + name);
  return null;
}

function findImage(name, doc) {
  var i, img;
  for (i = 0; i < doc.images.length; i++)
    if (doc.images[i].name == name)
      return doc.images[i];
  for (i = 0; i < doc.layers.length; i++)
    if ((img = findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  return null;
}

function getImagePageLeft(img) {
  var x, obj;
  if (NS4) {
    if (img.container != null)
      return img.container.pageX + img.x;
    else
      return img.x;
  }
  if (IE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}

function getImagePageTop(img) {
  var y, obj;
  if (NS4) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (IE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}


////////////////////////////////////////////////
// dreamweaver popup
////////////////////////////////////////////////


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

////////////////////////////////////////////////
// detection et redirection suivant navigateur
////////////////////////////////////////////////

function browser_redirect(url_ie,url_ns)
{
browserName=navigator.appName; 

  if ((browserName=="Netscape") ||  (browserName=="Microsoft Internet Explorer"))
  {     
    if (browserName=="Netscape")
        version="NS";
     else
         version="IE";
     }
  else
      version="OTHER"; 

if ((version=="NS") || (version=="IE"))
{
 if (version=="NS")  
 /* NS URL */ 
   window.location=url_ns;
 else
 /* IE URL */
   window.location=url_ie;
}
else
 /* OTHER URL */
     window.location=url_ns;
}


////////////////////////////////////////////////////
// contrôle si un champ ne contient que des chiffres
////////////////////////////////////////////////////

function ereg_replace(tx,rg,ch)
{
var regEx = new RegExp(rg,"g")
return tx.replace(regEx,ch)
}

function test_num(id)
{
valeur=ereg_replace(getObject(id).value,",",".")

if (isNaN(valeur))
	{
	alert ("Veuillez entrer uniquement des chiffres."); 
	getObject(id).value="";
	}
}


///////////////////////////////////////////////////////////////
// contrôle si 3 champs JJ MM AAAA forment une date valide
///////////////////////////////////////////////////////////////

// Declaring valid date character, minimum year and maximum year

var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function validateDate(jour,mois,annee,anneeMin,anneeMax){
	checkedDate=getObject(jour).value+'/'+getObject(mois).value+'/'+getObject(annee).value

	if (isDate(checkedDate)==false){
		getObject(jour).focus()
		return false
	}
    return true
 }




///////////////////////////////////////////////////////////////
// contrôle si un champ contient une date au format jj/mm/aaaa
///////////////////////////////////////////////////////////////


function checkDate (field)
{
	var checkstr = "0123456789";
	var DateValue = field;
	var DateTemp = "";
	var seperator = "/";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;
	err = 0;
	for (i = 0; i < DateValue.length; i++)
	{
		if (checkstr.indexOf(DateValue.substr(i,1)) >= 0)
		{
			DateTemp = DateTemp + DateValue.substr(i,1);
		}
	}
	DateValue = DateTemp;
	if (DateValue.length != 8)
	{
	err=1;
	}
	year = DateValue.substr(4,4);
	if (year == 0)
	{
	err=1;
	}
	month = DateValue.substr(2,2);
	if ((month < 1) || (month > 12))
	{
	err=1;
	}
	day = DateValue.substr(0,2);
	if (day < 1)
	{
	err=1;
	}
	if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0))
	{
	leap=1;
	}
	if ((month == 2) && (leap == 1) && (day > 29))
	{
	err=1;
	}
	if ((month == 2) && (leap != 1) && (day > 28))
	{
	err=1;
	}
	if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12")))
	{
	err=1;
	}
	if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11")))
	{
	err=1;
	}
	if ( ( field.length == 0 ) )
	{
	err=1;
	}
	if (err == 0)
	{
	return true;
	}
	else
	{
	return false;
	}
}



/////////////////////////////////////////////////////////////
// contrôle si un champ contient une adresse e-mail correcte
/////////////////////////////////////////////////////////////


function checkEmail ( emailStr )
{ 
	var checkTLD=0;
	var knownDomsPat=/ ^(com|fr|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		alert("Veuillez indiquer une adresse e-mail valide.");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
			alert("Veuillez indiquer une adresse e-mail valide.\nLe nom d'utilisateur contient des caractères invalides.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			alert("Veuillez indiquer une adresse e-mail valide.\nLe nom de domaine contient des caractères invalides.");
			return false;
		}
	}
	if (user.match(userPat)==null)
	{
		alert("Veuillez indiquer une adresse e-mail valide.\nLe nom d'utilisateur est invalide.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray>255)
			{
				alert("Veuillez indiquer une adresse e-mail valide.\nL'adresse IP est invalide.");
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
			alert("Veuillez indiquer une adresse e-mail valide.\nLe nom de domaine est invalide.");
			return false;
		}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
	{
		alert("Veuillez indiquer une adresse e-mail valide.\nL'extension du domaine est invalide");
		return false;
	}
	if (len<2)
	{
		alert("Veuillez indiquer une adresse e-mail valide.\nVeuillez indiquer une extension au domaine valide: ex .com.");
		return false;
	}
	return true;
}



//////////////////////////////////////////////////
// contrôle si l'objet en question est un tableau
//////////////////////////////////////////////////

function isArray(elementInQuestion) {
if (elementInQuestion.length) {
return true;
} else {
return false;
}
}





///////////////////////////////////////////////
// contrôle de la visibilité d'un élément
///////////////////////////////////////////////

function hide( ElementName )
{
	ElementObject = getObject ( ElementName );
	ElementObject.style.display = "none";
}

if (!browser.isIE)	{
	function show( ElementName ){ElementObject = getObject ( ElementName );ElementObject.style.display = "";}
	}
	else
	{
	function show( ElementName ){ElementObject = getObject ( ElementName );ElementObject.style.display = "";}
	}

function getObject(ID) {
     return document.getElementById(ID);
}
 
function getObject2 (objectName) {
	return document.getElementsByName(objectName);
}



////////////////////////////////////////////////////////////
// contrôle de l'affichage des champs dans les formulaires
////////////////////////////////////////////////////////////


function displayMineur(action)
{
if (action.value=="non")
 {
 hide('ligne_sexe');
 hide('ligne_nationalite');
 hide('ligne_communeNaiss');
 hide('ligne_adresse');
 hide('ligne_cp');
 hide('ligne_commune');
 hide('ligne_nomRepresentant');
 hide('ligne_prenomRepresentant');
 }
else
 {
 show('ligne_sexe');
 show('ligne_nationalite');
 show('ligne_communeNaiss');
 show('ligne_adresse');
 show('ligne_cp');
 show('ligne_commune');
 show('ligne_nomRepresentant');
 show('ligne_prenomRepresentant');
 }
}


function displayMineurMozaic(action)
{
if (action.value=="non")
 {
 hide('ligne_adresse');
 hide('ligne_commune');
 hide('ligne_cp');
 hide('ligne_nomRepresentant');
 hide('ligne_prenomRepresentant');
 }
else
 {
 show('ligne_adresse');
 show('ligne_commune');
 show('ligne_cp');
 show('ligne_nomRepresentant');
 show('ligne_prenomRepresentant');
 }
}



function displayAssures(action)
{
if (action.value == "Famille" )
 {
 show('ligne_assures');
 show('ligne_sepAssures');
 }
else
 {
 hide('ligne_assures');
 hide('ligne_sepAssures');
 }
}


function displayInterdit(action)
{
if (action.value != "Maestro" && action.value != "Visa")
 {
 show('ligne_interdit');
 }
else
 {
 hide('ligne_interdit');
  }
}

function displayChainageCode(action)
{
if (action.value.length!=30)
 {
 hide('ligne_chainageCode');
 hide('ligne_separation');
 }
else
 {
 show('ligne_chainageCode');
 show('ligne_separation');
 }
}

function displayCompteNormal(action)
{
if (action.value != "Maestro" && action.value != "Visa")
 {
 show('ligne_compteNormal');
 show('ligne_sep_compteNormal');
 show('ligne_topo_compteNormal');
 }
else
 {
 hide('ligne_compteNormal');
 hide('ligne_sep_compteNormal');
 hide('ligne_topo_compteNormal');
 }
}

function displayOptionsOptimum(action)
{
if (action.value.length > 30)
 {
 show('ligne_plafondOptimum');
 show('ligne_montantOptimum');
 show('ligne_livretOptimum');
 show('ligne_dateOptimum');
 show('ligne_plafondOptimum2');
 show('ligne_montantOptimum2');
 show('ligne_livretOptimum2');
 show('ligne_dateOptimum2');
 }
else
 {
 hide('ligne_plafondOptimum');
 hide('ligne_montantOptimum');
 hide('ligne_livretOptimum');
 hide('ligne_dateOptimum');
 hide('ligne_plafondOptimum2');
 hide('ligne_montantOptimum2');
 hide('ligne_livretOptimum2');
 hide('ligne_dateOptimum2');
 }
}


///////////////////////////////////////////////
// vérification de champs
///////////////////////////////////////////////


function verif_selectVide(nom,message)
{
 if (ok)
 {
  if (!getObject(nom).value) {alert(message);getObject(nom).focus();ok=0;}
 }
}

function verif_champVide(nom,message)
{
 if (ok)
 {
  if (!getObject(nom).value) {alert(message);getObject(nom).focus();ok=0;}
 }
} 

function verif_numCompte(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 11) {alert(message);getObject(nom).focus();ok=0;}
 }
} 


function verif_numCompteNouveau(nom,ancienNom,messageVide,messageIdem)
{
 if (ok)
 {
  if (getObject(nom).value.length < 11) {alert(messageVide);getObject(nom).focus();ok=0;}
  if (getObject(nom).value==getObject(ancienNom).value) {alert(messageIdem);getObject(nom).value="";getObject(nom).focus();ok=0;}
 }
} 



function verif_numSecu(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 15) {alert(message);getObject(nom).focus();ok=0;}
 }
} 

function verif_numCarte(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 8) {alert(message);getObject(nom).focus();ok=0;}
 }
} 

function verif_numPret(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 9) {alert(message);getObject(nom).focus();ok=0;}
 }
} 


function verif_telephone(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 8) {alert(message);getObject(nom).focus();ok=0;}
 }
}

function verif_typeMine(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 8) {alert(message);getObject(nom).focus();ok=0;}
 }
}

function verif_immatriculation(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 6) {alert(message);getObject(nom).focus();ok=0;}
 }
}

function verif_mobile(nom,message)
{
 if (ok)
 {
  if (getObject(nom).value.length < 10) {alert(message);getObject(nom).focus();ok=0;}
 }
}


function verif_radioVide(nom,message)
{
 if (ok)
 {
 objet=getObject2(nom);
 if (!objet[0].checked && !objet[1].checked) {alert(message);ok=0;}
 }
}

function verif_checkVide(nom,message)
{
 if (ok)
 {
 kkk=0;
 objet=getObject2(nom);
 
 if (objet[0]) { // if the button group is an array (one button is not an array)
 
    for (var i=0; i<objet.length; i++) 
      {
        if (objet[i].checked)
		  {
          kkk=1;
          }
      }
 }
 else
 {
 if (objet.checked) { kkk=1; }
 } 
  
  
  if (kkk==0){alert(message);getObject(nom).focus();ok=0;}
  
 }
}



