//DÈclaration des tableaux pour chaque liste box

Contacts=new Array(4);
Contacts[0]=new Array(25);
Contacts[1]=new Array(25);
Contacts[2]=new Array(25);
Contacts[3]=new Array(25);

Contacts[0][0]="0";
Contacts[0][1]="100000";
Contacts[0][2]="200000";
Contacts[0][3]="300000";
Contacts[0][4]="400000";
Contacts[0][5]="500000";
Contacts[0][6]="600000";
Contacts[0][7]="700000";
Contacts[0][8]="800000";
Contacts[0][9]="900000";
Contacts[0][10]="1000000";
Contacts[0][11]="1100000";
Contacts[0][12]="1200000";
Contacts[0][13]="1300000";
Contacts[0][14]="1400000";
Contacts[0][15]="1500000";
Contacts[0][16]="1600000";
Contacts[0][17]="1700000";
Contacts[0][18]="1800000";
Contacts[0][19]="1900000";
Contacts[0][20]="2000000";
Contacts[0][21]="2500000";
Contacts[0][22]="3000000";
Contacts[0][23]="3500000";
Contacts[0][24]="4000000";
Contacts[0][25]="4500000";
Contacts[0][26]="5000000";
Contacts[0][27]="10000000";
Contacts[0][28]="20000000";

Contacts[1][0]="0";
Contacts[1][1]="10000";
Contacts[1][2]="20000";
Contacts[1][3]="30000";
Contacts[1][4]="40000";
Contacts[1][5]="50000";
Contacts[1][6]="60000";
Contacts[1][7]="70000";
Contacts[1][8]="80000";
Contacts[1][9]="90000";
Contacts[1][10]="100000";
Contacts[1][11]="110000";
Contacts[1][12]="120000";
Contacts[1][13]="130000";
Contacts[1][14]="140000";
Contacts[1][15]="150000";
Contacts[1][16]="200000";
Contacts[1][17]="250000";
Contacts[1][18]="300000";
Contacts[1][19]="400000";
Contacts[1][20]="500000";
Contacts[1][21]="600000";
Contacts[1][22]="700000";
Contacts[1][23]="800000";
Contacts[1][24]="900000";
Contacts[1][25]="1000000";
Contacts[1][26]="2000000";
Contacts[1][27]="3000000";
Contacts[1][28]="4000000";

Contacts[2][0]="100000";
Contacts[2][1]="200000";
Contacts[2][2]="300000";
Contacts[2][3]="400000";
Contacts[2][4]="500000";
Contacts[2][5]="600000";
Contacts[2][6]="700000";
Contacts[2][7]="800000";
Contacts[2][8]="900000";
Contacts[2][9]="1000000";
Contacts[2][10]="1100000";
Contacts[2][11]="1200000";
Contacts[2][12]="1300000";
Contacts[2][13]="1400000";
Contacts[2][14]="1500000";
Contacts[2][15]="1600000";
Contacts[2][16]="1700000";
Contacts[2][17]="1800000";
Contacts[2][18]="1900000";
Contacts[2][19]="2000000";
Contacts[2][20]="2500000";
Contacts[2][21]="3000000";
Contacts[2][22]="3500000";
Contacts[2][23]="4000000";
Contacts[2][24]="4500000";
Contacts[2][25]="5000000";
Contacts[2][26]="10000000";
Contacts[2][27]="20000000";
Contacts[2][28]="0";

Contacts[3][0]="10000";
Contacts[3][1]="20000";
Contacts[3][2]="30000";
Contacts[3][3]="40000";
Contacts[3][4]="50000";
Contacts[3][5]="60000";
Contacts[3][6]="70000";
Contacts[3][7]="80000";
Contacts[3][8]="90000";
Contacts[3][9]="100000";
Contacts[3][10]="110000";
Contacts[3][11]="120000";
Contacts[3][12]="130000";
Contacts[3][13]="140000";
Contacts[3][14]="150000";
Contacts[3][15]="200000";
Contacts[3][16]="250000";
Contacts[3][17]="300000";
Contacts[3][18]="400000";
Contacts[3][19]="500000";
Contacts[3][20]="600000";
Contacts[3][21]="700000";
Contacts[3][22]="800000";
Contacts[3][23]="900000";
Contacts[3][24]="1000000";
Contacts[3][25]="2000000";
Contacts[3][26]="3000000";
Contacts[3][27]="4000000";
Contacts[3][28]="0";

Loyer=new Array(4);
Loyer[0]=new Array(13);
Loyer[1]=new Array(13);
Loyer[2]=new Array(13);
Loyer[3]=new Array(13);

Loyer[0][0]="0";
Loyer[0][1]="1000";
Loyer[0][2]="2000";
Loyer[0][3]="3000";
Loyer[0][4]="4000";
Loyer[0][5]="5000";
Loyer[0][6]="6000";
Loyer[0][7]="7000";
Loyer[0][8]="8000";
Loyer[0][9]="9000";
Loyer[0][10]="10000";
Loyer[0][11]="15000";
Loyer[0][12]="20000";

Loyer[1][0]="0";
Loyer[1][1]="200";
Loyer[1][2]="300";
Loyer[1][3]="400";
Loyer[1][4]="500";
Loyer[1][5]="600";
Loyer[1][6]="700";
Loyer[1][7]="800";
Loyer[1][8]="900";
Loyer[1][9]="1000";
Loyer[1][10]="2000";
Loyer[1][11]="5000";
Loyer[1][12]="10000";

Loyer[2][0]="1000";
Loyer[2][1]="2000";
Loyer[2][2]="3000";
Loyer[2][3]="4000";
Loyer[2][4]="5000";
Loyer[2][5]="6000";
Loyer[2][6]="7000";
Loyer[2][7]="8000";
Loyer[2][8]="9000";
Loyer[2][9]="10000";
Loyer[2][10]="15000";
Loyer[2][11]="20000";
Loyer[2][12]="0";

Loyer[3][0]="200";
Loyer[3][1]="300";
Loyer[3][2]="400";
Loyer[3][3]="500";
Loyer[3][4]="600";
Loyer[3][5]="700";
Loyer[3][6]="800";
Loyer[3][7]="900";
Loyer[3][8]="1000";
Loyer[3][9]="2000";
Loyer[3][10]="5000";
Loyer[3][11]="10000";
Loyer[3][12]="0";


function selection1(num)
{
   document.Form1.P1.selectedIndex=0;
   for(ctr=0;ctr<Contacts[num].length;ctr++)
   {
      num==0?document.Form1.P1.options[ctr]=new Option(format_prix(Contacts[num][ctr],'0','FF'),Contacts[num][ctr]):document.Form1.P1.options[ctr]=new Option(format_prix(Contacts[num][ctr],'0','euro'),Contacts[num][ctr]);
   }
   document.Form1.P1.length=Contacts[num].length;
   document.Form1.P1.selectedIndex=0;   
   document.Form1.P2.selectedIndex=0;
   for(ctr=0;ctr<Contacts[eval(parseInt(num)+2)].length;ctr++)
   {
      num==0?document.Form1.P2.options[ctr]=new Option(format_prix(Contacts[eval(parseInt(num)+2)][ctr],'0','FF'),Contacts[eval(parseInt(num)+2)][ctr]):document.Form1.P2.options[ctr]=new Option(format_prix(Contacts[eval(parseInt(num)+2)][ctr],'0','euro'),Contacts[eval(parseInt(num)+2)][ctr]);
   }
	document.Form1.P2.length=Contacts[eval(parseInt(num)+2)].length;
   document.Form1.P2.selectedIndex=28;	
}

function selection2(num)
{
   document.Form1.P1.selectedIndex=0;
   for(ctr=0;ctr<Loyer[num].length;ctr++)
   {
      num==0?document.Form1.P1.options[ctr]=new Option(format_prix(Loyer[num][ctr],'0','FF'),Loyer[num][ctr]):document.Form1.P1.options[ctr]=new Option(format_prix(Loyer[num][ctr],'0','euro'),Loyer[num][ctr]);
   }
   document.Form1.P1.length=Loyer[num].length;
   document.Form1.P1.selectedIndex=0;   
   document.Form1.P2.selectedIndex=0;
   for(ctr=0;ctr<Loyer[eval(parseInt(num)+2)].length;ctr++)
   {
      num==0?document.Form1.P2.options[ctr]=new Option(format_prix(Loyer[eval(parseInt(num)+2)][ctr],'0','FF'),Loyer[eval(parseInt(num)+2)][ctr]):document.Form1.P2.options[ctr]=new Option(format_prix(Loyer[eval(parseInt(num)+2)][ctr],'0','euro'),Loyer[eval(parseInt(num)+2)][ctr]);
   }
	document.Form1.P2.length=Loyer[eval(parseInt(num)+2)].length;
   document.Form1.P2.selectedIndex=12;	
}

function selection3(num)
{
    if(document.forms[0].elements['R'].type!="hidden"){
	var mc = document.forms[0].elements['R'];
	var mcl = mc[0];
	mc[0].checked?selection1(num):selection2(num);
    }else {
	selection1(num);
    }
}

function selectiont(num)
{
	var mc = document.forms[0].elements['D'];
	var mcl = mc[0];
	mc[0].checked?selection3(0):selection3(1);
}

function currencyPad(anynum,width,devise) {
if(!devise)devise='FF'
if(devise=='euro')devise='€'
anynum = "" + eval(anynum)
intnum=0
                if (anynum >= 1) {
                         intnum = parseInt(anynum)
                }    
                //isolate integer portion
                intstr = ""+intnum
                //add comma in thousands place.
                if (intnum >= 1000) {
                        intlen = intstr.length
                       temp1=parseInt(""+(intnum/1000))
                       temp2=intstr.substring(intlen-3,intlen)
                        intstr = temp1+" "+temp2
                }
                if (intnum >= 1000000) {
                        intlen = intstr.length
                        temp1=parseInt(""+(intnum/1000000))
                        temp2=intstr.substring(intlen-7,intlen)
                        intstr = temp1+" "+temp2        
                }
                decnum = Math.abs(parseFloat(anynum)-intnum) //isolate decimal portion
                decnum = decnum * 100 // multiply decimal portion by 100.
                decstr = "" + Math.abs(Math.round(decnum))
                while (decstr.length < 2) {
                        decstr="0"+decstr
                }
		/*retval = intstr + "," + decstr*/
		retval = intstr
                if (intnum < 0) {
                        retval=retval.substring(1,retval.length)
                        retval="("+retval+")"        
                }       
                retval = retval+devise
                while (retval.length < width){
                        retval=" "+retval
                }
                return retval
        }
function format_prix(prix,valeur_par_defaut,devise){
	if (parseInt(prix) == parseInt(valeur_par_defaut)) return "Indifférent"
	else return currencyPad(prix,0,devise)
}

function emailCheck (emailStr) {
if (Trim(emailStr)=="") return true;
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Une adresse email semble incorrecte")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("Une adresse email semble incorrecte")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("L'adresse IP semble incorrecte!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("Le nom de domaine semble incorrecte!")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("Le nom de domaine semble incorrecte!")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="Une adresse email semble incorrecte!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}


function RTrim(str){
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
   	var i = s.length - 1;       // Get length of string
   while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
   i--;
	s = s.substring(0, i+1);
	}
return s;
}

function LTrim(str){
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(0)) != -1) {
	var j=0, i = s.length;
	while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
		j++;
		s = s.substring(j, i);
   }
   return s;
}

function Trim(str){
return RTrim(LTrim(str));
}

