		function _AddToList(vList, vText, vValue)		{			var tmp = "";
					vList.length = vList.length + 1;			vList.options[vList.length - 1].text = vText;
			vList.options[vList.length - 1].value = vValue;
			
			vList.selectedIndex = vList.length - 1;						ChangeIMG(vList);		}


		function DeleteFromList(vList)		{
			if (vList.length > 0) 			{				var tmp = vList.selectedIndex;
			
				vList.remove(vList.selectedIndex);
				if (tmp == 0)
				{
					vList.selectedIndex = 0;				}
				else
				{
					vList.selectedIndex = tmp - 1;				};
			};
		}

		function Trim(s) 
		{
			return s.replace(/(^\s+)|(\s+$)/g, "");
		}


		//	Entree:
		//		_Date : Le nom de l'objet ex: document.MyForm.txtDate
		//		_Flag : 1 si date obligatoire, 0 sinon
		//		_Msg  : le message a affiché
		//	Sortie:
		//		true  : si valide
		//		false : si non valide
		function CheckDate(_Date, _Flag, _Msg)
		{
			var err = true;
			
			tmp = Trim(_Date.value);
			
			if ((tmp != '') || (tmp == '' && _Flag == true))
			{
				if (tmp.length > 10) {err = false;};
				if (tmp.length < 8) {err = false;};

				var TabDate = new Array(0,0,0);
				if ((tmp.indexOf("-")!=-1) || (tmp.indexOf("/")!=-1))
				{
					if (tmp.indexOf("-")!=-1)
						{TabDate = tmp.split("-");}
					else 
						{TabDate = tmp.split("/");};
				};

				_Day   = TabDate[1];	// Day
				_Month = TabDate[0];	// Month
				_Year  = TabDate[2];	// Year

				if (_Day < 1 || _Day > 31) {err = false;};
				if (_Month < 1 || _Month > 12) {err = false;};
				if (_Year < 1900) {err = false;};
			
				if (_Month==4 || _Month==6 || _Month==9 || _Month==11) 
				{
					if (_Day == 31) {err = false;};
				}
			
				if (_Month==2)
				{
					var BisYear=parseInt(_Year/4);
					if (isNaN(BisYear)) {err = false;};
					if (_Day > 29) {err = false;};
					if (_Day==29 && ((_Year/4) != parseInt(_Year/4))) {err = false;};
				}
			
				if (err == false) 
				{
					//alert('"' + tmp + '" ' + _Msg);
					alert(_Msg);
					_Date.focus();
					_Date.select();
				}
			}
			return err;
		}


		//	Entree:
		//		elt : Le nom de l'objet ex: document.MyForm.txtPic
		//		msg : le message a affiché
		//	Sortie:
		//		true  : if not empty
		//		false : if empty
		function CheckEmpty(elt, msg)
		{
			Flag = true
			tmp = Trim(elt.value);
			if (tmp == "") 
			{
				alert(msg);
				elt.focus();
				elt.select();
				Flag = false;
			};
			return Flag;
		}


		//	Entree:
		//		elt		 : Le nom de l'objet ex: document.MyForm.txtPic
		//		required : 1 si obligatoire, 0 sinon
		//		msg		 : le message a affiché
		//	Sortie:
		//		true  : if not empty
		//		false : if empty
		function CheckNumber(elt, required, vLower, vUpper, msg) 
		{
			var Flag = true;
		
			tmp = Trim(elt.value);

			if ((required == 1) || (tmp != ''))
			{
				if ((isNaN(tmp) || tmp == '') || (tmp > vUpper || tmp < vLower))
				{
					alert(msg + " /  Range between: " + vLower + " and " + vUpper);
					elt.focus();
					elt.select();
					Flag = false;
				} 
				else 
				{
					Flag = true;
				};
			}
			return Flag;
		}


		//onKeyDown="javascript: LimitText(document.Default.txtaDesc, 1000, false);" onKeyUp="javascript: LimitText(document.Default.txtaDesc, 1000, false);"
		function LimitText(field, maxlimit, Display)
		{
			if (field.value.length > maxlimit) // if too long...trim it!
			{
				field.value = field.value.substring(0, maxlimit);
			}
			
			if (Display) 
			{
				Display.value = maxlimit - field.value.length;
			}
            //var lbl = document.getElementById("Label1");
            //var tb = document.getElementById("TextBox1");
            //var max = tb.getAttribute("maxlength");
            //if (tb.value.length > max) { tb.value = tb.value.substring(0, max); }
            //else { lbl.innerText = max - tb.value.length + " chars left"; }
		}
		


		//	Entree:
		//		C  : Le nom de l'objet ex: document.MyForm.txtPic
		//		DF : 1 Si date, 0 sinon
		//	Sortie:
		//		true  : if valid
		//		false : if invalid
		// ex: onKeyPress="javascript: return JustNB(event, 0);"
		function JustNB(C, DF)		{			var KC; //KeyCode

			if (document.all)
			{ 
				KC = C.keyCode;
			}
			else
			{
				KC = C.which;
			};


			if (DF == 1)
			{
				if ((KC < 48 || KC > 57) && (KC != 45) && (KC != 47) && (KC != 13))
				{
					return false;				};
			}
			else
			{
				if ((KC < 48 || KC > 57)  && (KC != 13))
				{
					return false;				};
			};
						return true;
		}
		
		
		//ex: OpenWindow('calendar.asp', 0, 0, 0, 0, 0, 1, 1, 420, 420)
		function OpenWindow(url, vTool, vLoc, vDir, vStatus, vMenu, vScroll, vResize, vWidth, vHeight)
		{
			var address		= url;				//Address
			var op_tool		= vTool;			//Toolbar
			var op_loc_box	= vLoc;				//Location
			var op_dir		= vDir;				//Directories
			var op_stat		= vStatus;			//Status
			var op_menu		= vMenu;			//Menubar
			var op_scroll	= vScroll;			//Scrollbar
			var op_resize	= vResize;			//Resizable
			var op_wid		= vWidth;			//Width
			var op_heigh	= vHeight;			//Height

			var option = "toolbar=" + op_tool + ",location=" + op_loc_box + ",directories=" 
			        + op_dir + ",status=" + op_stat + ",menubar=" + op_menu + ",scrollbars="  
			        + op_scroll + ",resizable="  + op_resize + ",width=" + op_wid + ",height=" 
			        + op_heigh;

			window.open(address, "vScreenName", option);
		}



		function CountCharacter(_Field, _Allowed)
		{
			var err = true;
			var tmp = _Field.value;
			if (tmp.length > _Allowed)
			{
				err = false;
				alert('le nombre de caractère permis est: ' + _Allowed);
				_Field.focus();
			}
			return err;
		}




		//ex: 
		function emailCheck (elt, Required, LG)
		{
			emailStr = elt.value;
			if ((emailStr != '') || (emailStr == '' && Required == 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. */
					if (LG==2) 
						alert("L'adresse e-mail ne peut contenir de caractères non valables et doit contenir '@' et '.'")
					else 
						alert("Email address seems incorrect (check @ and .'s)");
					elt.focus();
					elt.select();
					return false
				}
				var user=matchArray[1]
				var domain=matchArray[2]

				// See if "user" is valid 
				if (user.match(userPat)==null) {
				    // user is not valid
					if (LG==2) 
						alert("Nom d'utilisateur incorrect")
					else 
					    alert("The username doesn't seem to be valid.");
					elt.focus();
					elt.select();
				    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) 
					    {
							if (LG==2) 
								alert("Adresse IP incorrecte")
							else 
							    alert("Destination IP address is invalid!");
							elt.focus();
							elt.select();
							return false
					    }
					  }
				    return true
				}

				// Domain is symbolic name
				var domainArray=domain.match(domainPat)
				if (domainArray==null) 
				{
					if (LG==2) 
						alert("Nom du domaine incorrect")
					else 
						alert("The domain name doesn't seem to be valid.");
					elt.focus();
					elt.select();
				    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) 
				if (domArr[domArr.length-1].length<2) 
				{
				   // the address must end in a two letter or three letter word.
					if (LG==2) 
						alert("L’adresse e-mail doit se terminer par 2 lettres ou plus")
					else 
					   alert("The address must end with 2 letters or more");
				   elt.focus();
				   elt.select();
				   return false
				}

				// Make sure there's a host name preceding the domain.
				if (len<2) 
				{
					if (LG==2) 
						alert("L’adresse ne contient pas un nom de serveur")
					else 
					   alert("This address is missing a hostname!");
				   elt.focus();
				   elt.select();
				   return false
				}
			}
			
			// If we've gotten this far, everything's valid!
			return true;
		}



        function ShowHideDiv(obj) {
	        if (document.getElementById) 
	        {
		        if (document.all[obj].style.visibility == 'visible')
		        {
			        document.all[obj].style.visibility = 'hidden';
		        }
		        else
		        {
			        document.all[obj].style.visibility = 'visible';
		        }
	        }
	        else
	        {
		        if (document.all[obj].style.visibility == 'visible')
		        {
			        document.layers[obj].visibility = 'visible';
		        }
		        else
		        {
			        document.layers[obj].visibility = 'visible';
		        }
	        }

        }
        
        
        
        /*Left(string, length): Returns a specified number of characters from the left side of a string*/
        function Left(str, n)
        /***
                IN: str - the string we are LEFTing
                    n - the number of characters we want to return

                RETVAL: n characters from the left side of the string
        ***/
        {
                if (n <= 0)     // Invalid bound, return blank string
                        return "";
                else if (n > String(str).length)   // Invalid bound, return
                        return str;                // entire string
                else // Valid bound, return appropriate substring
                        return String(str).substring(0,n);
        }
