	/* CAST FUNCTIONS */

	//Fonction permattant de formater une date AAAAMMJJ en JJ/MM/AAAA :
	function StrToDate(in_date)
		{
			 year = in_date.substr(0,4);
			 month = in_date.substr(4,2);
			 day = in_date.substr(6,2);
			 return day+"/"+month+"/"+year;
		}


	/* FRAME FUNCTIONS */

	function frame_refresh(in_target)
		{
		eval("top.main."+in_target+".location = top.main." + in_target + ".location;");
		}

	function frame_update(in_target, in_location)
		{
		//alert (in_location);
		//alert(in_target+".location = " + in_location + ";");
		window.open(in_location,in_target);
		}


	/* POPUP FUNCTIONS */


	function help_open(in_str)
		{
			window.open("/project/help.asp?keyword="+in_str,"help","Width=400px; Height=200px; status=no; border=none; help=no; titlebar=no,scrollbars=no");
		}

	function popup_open2(in_url, in_x, in_y, in_title, in_ico)
		{

			str_url = in_url.replace("&","|");
			str_url = str_url.replace("?","*");
			str_url = str_url.replace("'","´");
			str_url = "/lib/popup2.asp?x=" + in_x + "&y=" + in_y + "&ico=" + in_ico + "&title=" + in_title + "&url=" + str_url;
			//alert (str_url);
			window.open(str_url,"_blank","fullscreen=1;status=0; border=none;help=0;titlebar=0;scrollbars=0;modal=yes");
		}


	function popup_open(in_url, in_x, in_y, in_title, in_ico)
		{
			str_url = in_url.replace("&","|");
			str_url = str_url.replace("?","||");
			str_url = str_url.replace("'","´");
			str_url = "/lib/popup.asp?x=" + in_x + "&y=" + in_y + "&ico=" + in_ico + "&title=" + in_title + "&url=" + str_url;
			str_poshori = (screen.width - in_x)/2;
			str_posvert = (screen.height - in_y)/2;
			str_option = "status=0,width=" + in_x + ",height=" + in_y + ",top=" + str_posvert + ",left=" + str_poshori + ",titlebar=0,scrollbars=0;"


			//alert (str_option);
			window.open(str_url,"_blank",str_option);
		}

	function popupscroll_open(in_url, in_x, in_y, in_title, in_ico)
		{
			str_url = in_url.replace("&","|");
			str_url = str_url.replace("?","||");
			str_url = str_url.replace("'","´");
			str_url = "/lib/popup.asp?x=" + in_x + "&y=" + in_y + "&ico=" + in_ico + "&title=" + in_title + "&url=" + str_url;
			str_poshori = (screen.width - in_x)/2;
			str_posvert = (screen.height - in_y)/2;
			str_option = "scrollbars=yes;status=no;width=" + in_x + ";height=" + in_y + ";top=" + str_posvert + ";left=" + str_poshori + ";titlebar=0;"

			//alert (str_option);
			window.open(str_url,"_blank",str_option);
		}

	//Fonction fermant la fenêtre parente :
	function popup_close()
		{
			parent.close();
		}

	//Fonction ouvrant une fenêtre d'aperçu avant impression :
     function printPreview(in_url)
		 {
			window.open('/lib/print_preview.asp?url='+ in_url ,'_blank','fullscreen=1;');
		 }
	/* FORM FUNCTIONS  */

	// Fonction permettant de cocher ou de décocher toutes les checkbox d'un formulaire :
	function CheckAll(in_obj)
				{
				in_form = in_obj.form;
				if(in_obj.checked == true)
					{
					cpt = 0;
					while(in_form.elements[cpt] != null)
						{
						if(in_form.elements[cpt].type == "checkbox")
							{
							in_form.elements[cpt].checked=true;
							}
						cpt = cpt + 1;
						}
					}
				else
					{
					cpt = 0;
					while(in_form.elements[cpt] != null)
						{
						if(in_form.elements[cpt].type == "checkbox")
							{
							in_form.elements[cpt].checked=false;
							}
						cpt = cpt + 1;
						}
					}
				}


	//Fonction permettant de comparer deux dates (true: date1 <= date2 ; false: date1 > date2) :

	function CompareDate(in_date1,in_date2) // IN : JJ/MM/AAAA, OUT : BOOLEAN
		{
			date1 = new String();
			date2 = new String();

			date1 = in_date1;
			date2 = in_date2;


			day1 = date1.substr(0,2) - 0;
			month1 = date1.substr(3,2) - 0;
			year1 = date1.substr(6,4) - 0;

			day2 = date2.substr(0,2) - 0;
			month2 = date2.substr(3,2) - 0;
			year2 = date2.substr(6,4) - 0 ;

			if(day1 < 10)
				{
				day1 = "0" + day1;
				}

			if(month1 < 10)
				{
				month1 = "0" + month1;
				}

			if(day2 < 10)
				{
				day2 = "0" + day2;
				}

			if(month2 < 10)
				{
				month2 = "0" + month2;
				}


			date1 = year1 + "-" + month1 + "-" + day1;
			date2 = year2 + "-" + month2 + "-" + day2;

			//alert(date1);
			//alert(date2);

			if(date1 <= date2)
				{
				return true;
				}
			else
				{
				return false;
				}
		}


// Fonction permettant de vérifier si une date est valide :

	function isDate (day,month,year)
		{
			var today = new Date();
			year = ((!year) ? today.getYear():year);
			month = ((!month) ? today.getMonth():month-1);
			if (!day) return false
			var test = new Date(year,month,day);
			if ( (test.getYear() == year) &&
				 (month == test.getMonth()) &&
				 (day == test.getDate()) )
				return true;
			else
				return false
		}




// Fonction permettant d'addition un nombre à une date :

	function dateAdd(in_date,in_nber,in_mode)
		{

		date2Sum = new Date();
		date2Sum = in_date;


		//in_nber = in_nber.replace(',','.');
		//alert(in_nber);
		if (in_nber < 0)
			{
			in_nber = in_nber * (-1);
			}
		in_nber = parseFloat(in_nber) + parseFloat(0.4);
		//alert(in_nber);
		in_nber = Math.round(in_nber);
		//alert(in_nber);

		dayOfDate2Sum = date2Sum.substr(0,2) - 0;
		monthOfDate2Sum = date2Sum.substr(3,2) - 0;
		yearOfDate2Sum = date2Sum.substr(6,4) - 0;

		switch (in_mode)
			{
				case "d" :
					dayOfDate2Sum = dayOfDate2Sum  + parseFloat(in_nber);
					if(!isDate(dayOfDate2Sum,monthOfDate2Sum,yearOfDate2Sum))
						{
						//alert("1. " + dayOfDate2Sum + "/" + monthOfDate2Sum + "/" +  yearOfDate2Sum);
						dayOfDate2Sum = 1;
						monthOfDate2Sum = monthOfDate2Sum + 1 - 0.0;
						if(!isDate(dayOfDate2Sum,monthOfDate2Sum,yearOfDate2Sum))
							{
							//alert("2. " + dayOfDate2Sum + "/" + monthOfDate2Sum + "/" +  yearOfDate2Sum);
							monthOfDate2Sum = 1;
							yearOfDate2Sum = yearOfDate2Sum + 1 - 0.0;
							}
						}
				break;
			}

		if(dayOfDate2Sum < 10)
			{
				dayOfDate2Sum = '0' + dayOfDate2Sum ;
			}
		if(monthOfDate2Sum < 10)
			{
				monthOfDate2Sum = '0' + monthOfDate2Sum ;
			}

		//alert("3. " + dayOfDate2Sum + "/" + monthOfDate2Sum + "/" +  yearOfDate2Sum);
		return dayOfDate2Sum + "/" + monthOfDate2Sum + "/" +  yearOfDate2Sum;
		}

	function reverseStr(in_str)
		{
		text = "";
		for (i = 0; i <= in_str.length; i++)
			{
			text = in_str.substring(i, i+1) + text;
			}
		return text;
		}


	function trim(in_str)
		{
		if (in_str != "")
			{

			while('' + in_str.charAt(0)==' ')
				{
				in_str = in_str.substring(1,in_str.length);
				}

			in_strrev = reverseStr(in_str);

			while('' + in_strrev.charAt(0)==' ')
				{
				in_strrev = in_str.substring(1,in_strrev.length);
				}
			return reverseStr(in_strrev);
			}
		else
			{
			return "";
			}
		}

function checkEmail(in_value)
	{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(in_value))
		{
		return true;
		}
	else
		{
		return false;
		}
	}

	function increaseField(in_obj,in_maxlength)
		{
		var obj_increase;
		obj_increase = parseFloat(in_obj.value) + 1;

		if(typeof(in_maxlength) == "undefined")
			{
			in_maxlength = 2;
			}

		if(isNaN(in_obj.value) || (obj_increase.toString()).length > in_maxlength)
			{
			in_obj.value = 0;
			}
		else
			{
			in_obj.value = obj_increase;
			}
		in_obj.focus();
		}

	function decreaseField(in_obj)
		{
		if(isNaN(in_obj.value))
			{
			in_obj.value = 0;
			}
		else
			{
			if(parseFloat(in_obj.value) - 1 < 0)
				{
				in_obj.value = 0;
				}
			else
				{
				in_obj.value = parseFloat(in_obj.value) - 1;
				}
			}
		in_obj.focus();
		}
	// Fonction qui permet de supprimer une liste déroulante passée en paramètre :
	function DeleteCombo(in_obj)
		{

		combo_length = in_obj.length-1;

		for(cpt=combo_length;cpt>=0;cpt--)
			{
			in_obj[cpt] = null;
			}
		in_obj.length=0;
		}

	function checkForm()
		{
		if (trim(document.getElementById('nom').value)=="")
			{
			alert("Le nom est obligatoire !");
			document.getElementById('nom').focus();
			return false;
			}

		if (trim(document.getElementById('email').value)=="")
			{
			alert("L'adresse e-mail est obligatoire !");
			document.getElementById('email').focus();
			return false;
			}
		else
			{
			if (!checkEmail(document.getElementById('email').value))
				{
				alert("L'adresse e-mail n'est pas valide !");
				document.getElementById('email').focus();
				return false;
				}
			}

		if (document.getElementById('period').value=="")
			{
			alert("La période est obligatoire !");
			return false;
			}

		if (document.getElementById('nombre').value=="")
			{
			alert("Le nombre d'enfant est obligatoire !");
			return false;
			}

		return true;
	}

	function checkForm2(in_number)
		{
		var error_txt = "";
		var i_txt;
		var i = 1;

		while(i<=in_number)
			{
			i_txt = new String(i);

			if(trim(document.getElementById('enfant_nom_' + i_txt + '').value)=="")
				{
				error_txt = error_txt + "Le nom de l'enfant " + i_txt + " est obligatoire !\n";
				}
			if(trim(document.getElementById('enfant_prenom_' + i_txt + '').value)=="")
				{
				error_txt = error_txt + "Le prénom de l'enfant " + i_txt + " est obligatoire !\n";
				}
			if(trim(document.getElementById('enfant_date_' + i_txt + '').value)=="")
				{
				error_txt = error_txt + "La date de naissance de l'enfant " + i_txt + " est obligatoire !\n";
				}
			i++;
			}

		if(error_txt != "")
			{
			alert(error_txt);
			return false;
			}

		return true;
	}

	function setFocus(in_fieldid)
		{
		document.getElementById(in_fieldid).focus();
		}
