		function LTrim(str)
		/*
		        PURPOSE: Remove leading blanks from our string.
		        IN: str - the string we want to LTrim
		*/
		{
	        var whitespace = new String(" \t\n\r");

	        var s = new String(str);

	        if (whitespace.indexOf(s.charAt(0)) != -1) {
	            // We have a string with leading blank(s)...

	            var j=0, i = s.length;

	            // Iterate from the far left of string until we
	            // don't have any more whitespace...
	            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
	                j++;
	                
	            // Get the substring from the first non-whitespace
	            // character to the end of the string...
	            s = s.substring(j, i);
	        }
	        return s;
		}


		function RTrim(str)
		/*
		        PURPOSE: Remove trailing blanks from our string.
		        IN: str - the string we want to RTrim
		*/
		{
		    // We don't want to trip JUST spaces, but also tabs,
		    // line feeds, etc.  Add anything else you want to
		    // "trim" here in Whitespace
		    var whitespace = new String(" \t\n\r");

		    var s = new String(str);

		    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		        // We have a string with trailing blank(s)...

		        var i = s.length - 1;       // Get length of string

		        // Iterate from the far right of string until we
		        // don't have any more whitespace...
		        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		            i--;

		        // Get the substring from the front of the string to
		        // where the last non-whitespace character is...
		        s = s.substring(0, i+1);
		    }

		    return s;
		}


		function Trim(str)
		/*
		        PURPOSE: Remove trailing and leading blanks from our string.
		        IN: str - the string we want to Trim
		        RETVAL: A Trimmed string!
		*/
		{
		        return RTrim(LTrim(str));
		}


		//	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);
					_Date.focus();
					_Date.select();
				}
			}
			return err;
		}


		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;
		}



		function CheckEmpty(elt, msg)
		{
			Flag = true
			tmp = elt.value;
			if (Trim(tmp) == "") 
			{
				alert(msg);
				elt.focus();
				elt.select();
				Flag = false;
			};
			return Flag;
		}


		function TextCounter(field, maxlimit)
		{
			if (field.value.length > maxlimit) // if too long...trim it!
				field.value = field.value.substring(0, maxlimit);
		}


		function OpenWindow() 
		{
			var address		= "preview.asp";		//Address
			var op_tool		= 0;				//Toolbar
			var op_loc_box		= 0;				//Location
			var op_dir		= 0;				//Directories
			var op_stat		= 0;				//Status
			var op_menu		= 0;				//Menubar
			var op_scroll		= 1;				//Scrollbar
			var op_resize		= 1;				//Resizable
			var op_wid		= 620;				//Width
			var op_heigh		= 600;				//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, "NewWindow", option);
		}
