// check of the date
function VerifyDate(form,T,DD,DF)
  {
	ERR = 0
	message = ""
	if (isNaN(DD) == true) {DD = "1950"}
	if (isNaN(DF) == true) {DF = "2020"}

	// delete of the first blank space
	i = 0
	while (i <= form.value.length - 1)
       {
		car = form.value.substring(i,i+1)
		if (car != " "){break}
		i = i + 1
       }
    form.value = form.value.substring(i,form.value.length)

	// format of the date
	if (form.value.length > 0)
		{
			i = 0; j = 1; nb = 0
			JJ = ""; MM = ""; AA = ""
			while (i <= form.value.length - 1)
			   {
				car = form.value.substring(i,i+1)
				if (car == "/" || car == "-" || car == "." )
					{
					 j = j + 1
					 nb = 0
					}
				else
				    {
				    if (car != " ")
						{
						 nb = nb + 1
						 if (j < 3 && nb == 3)
				 			{
							 j = j + 1
							 nb = 1
							}
						 if (j == 1) {JJ = JJ + car}
						 if (j == 2) {MM = MM + car}
						 if (j == 3) {AA = AA + car}
						}
				    }
				i = i + 1
			   }
			if(JJ.length == 1) {JJ = "0" + JJ}
			if(MM.length == 1) {MM = "0" + MM}
			if(AA.length == 2)
			   {
				if (AA > 30)
					{AA = "19" + AA}
				else
					{AA = "20" + AA}
			   }

			form.value = JJ + "/" + MM + "/" + AA
	        NUM = AA + MM + JJ

			// check of the validity of the date
			if (NUM.length != 8 || isNaN(NUM) == true || MM > "12")
				{ERR = 1}
			else
				{
				if (AA < DD)
				    {ERR = 1; message = " année inférieure à " + DD}
				else
					{
					if (AA > DF)
					    {ERR = 1; message = " année supérieure à " + DF}
					else
						{
						if (JJ > "30" && (MM == "04" || MM == "06" || MM == "09" || MM == "11"))
						    {ERR = 1}
						else
							{
							if (JJ > "31" && MM != "02")
							    {ERR = 1}
							}
						}
					}
				}
			if (ERR == 0 && MM == "02" )
				{
					VD = new Date()
 					VD.setDate(JJ)
 					VD.setMonth(MM -1) // in javascript the months go from 0 to 11
 					VD.setYear(AA)
 					//alert (VD)
 					JD = VD.getDate()
 				 	MD = VD.getMonth()+ 1
					if(JD.length == 1) {JD = "0" + JD}
					if(MD.length == 1) {MD = "0" + MD}
					//alert (JD + "/" + MD + "/" + AA)

					if(JD != JJ || MD != MM){ERR = 1}
				}
	}
	if (ERR == 0)
		{
			return true
		}
	else
		{
		alert("date erronée : " + form.value + message)
		return false
		}
  }


function MM_openBrWindow(theURL,winName,features,l,h) { //v2.0
 
 features=features + ",width="+l+",height="+h;
 if (screen.height) {
  var top = (screen.height-h)/2; 
  var left=(screen.width-l)/2;
  features=features+",top="+top+",left="+left;
 }
 window.open(theURL,winName,features );
 
}