function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function ouverturePopup(PageAOuvrir, PageName, Width, Height, scroll, statut, resize, MenuBar)
{
	var NewWindow, LeftPosition, TopPosition;

	if(!MenuBar) MenuBar = 'yes';
	if(!resize) resize = 'yes';
	if(!statut) statut = 'yes';
	if(!scroll) scroll = 'yes';
	if(!Width) Width = screen.availWidth;
	if(!Height) Height = screen.availHeight;
	if(!PageName) PageName = 'popupHPV';
	LeftPosition = (Width) ? (screen.availWidth - Width) / 2 : 0;
	TopPosition = (Height) ? (screen.availHeight - Height) / 2 : 0;
	NewWindow = window.open(PageAOuvrir, PageName, 'height=' + Height + 'px,width=' + Width + 'px,top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',status=' + statut + ',resizable=' + resize + ',menubar=' + MenuBar);
	NewWindow.focus();
	if(Width == screen.availWidth || Height == screen.availHeight)
	{
		if(document.all)
			NewWindow.resizeTo(screen.availWidth, screen.availHeight);
		else if(document.layers || document.getElementById)
		{
			NewWindow.outerHeight = screen.availHeight;
			NewWindow.outerWidth = screen.availWidth;
		}
	}
}

function ChooseDate(TheInput1, TheInput2, TheInput3)
{
	if(!TheInput2 || !TheInput3)
		ouverturePopup('Calender.asp?TheForm=' + TheInput1.form.name + '&TheInput1=' + TheInput1.name, 'popupHPVCalender', 202, 260);
	else
		ouverturePopup('Calender.asp?TheForm=' + TheInput1.form.name + '&TheInput1=' + TheInput1.name + '&TheInput2=' + TheInput2.name + '&TheInput3=' + TheInput3.name, 'popupHPVCalender', 202, 260);
}

function CheckMultiSelectStatus()
{
	var i, oneSelected = false;
	for(i=1; i<document.form1.Status.length; i++)
		if(document.form1.Status.options[i].selected)
			oneSelected = true;
	if(oneSelected)
		document.form1.Status.options[0].selected = false;
	else
		document.form1.Status.options[0].selected = true;
}

function VerifMaxTextarea(TheTextarea, MaxCaracter)
{
	if(TheTextarea.value.length >= MaxCaracter)
		return false;
	else
		return true;
}

function TrunkTextarea(TheTextarea, MaxCaracter)
{
	return TheTextarea.value.substr(0, MaxCaracter);
}

function IsInputFloat(TheInput, MsgErreur)
{
	if(!MsgErreur)
		MsgErreur = 'The value must be a valid number. (4.1524 or 4,1524)';
	if(isNaN(TheInput.value.replace(',', '.').replace(' ')) || TheInput.value.indexOf('e') != -1)
	{
		alert(MsgErreur);
		TheInput.focus();
		TheInput.select();
		return false;
	}
	return true;
}

function IsInputInt(TheInput, MsgErreur)
{
	if(!MsgErreur)
		MsgErreur = 'The value must be a valid integr. (1254)';
	if(isNaN(TheInput.value.replace(' ')) || TheInput.value.indexOf(',') != -1 || TheInput.value.indexOf('.') != -1 || TheInput.value.indexOf('e') != -1)
	{
		alert(MsgErreur);
		TheInput.focus();
		TheInput.select();
		return true;
	}
	return false;
}

function IsInputEmpty(TheValue, MsgErreur)
{
	if(!MsgErreur)
		MsgErreur = 'You can\'t enter empty value here.';
	if (TheValue.type == 'select-one')
	{
		if (TheValue[TheValue.selectedIndex].value == '' || TheValue[TheValue.selectedIndex].value == 'null' || TheValue[TheValue.selectedIndex].value == 'NULL')
		{
			alert(MsgErreur);
			TheValue.focus();
			return true;
		}
	}
	else
	{
		if (TheValue.value == '')
		{
			alert(MsgErreur);
			if (TheValue.type != 'hidden')
				TheValue.focus();
			return true;
		}
	}
	return false;
}

function IsEmailValid(TheEmail, MsgErreur)
	{
	var i;
	
	// On commence par tester la longueur de la chaine saisie 
	//  ainsi que la présence et la position des caractères obligatoires
	if(!MsgErreur)
		MsgErreur = 'The e-mail inserted is not valid.';
	var EmailIsValid = true;
	var AtSym = TheEmail.value.indexOf('@');
	var Period = TheEmail.value.lastIndexOf('.');
	var Space = TheEmail.value.indexOf(' ');
	var Length = TheEmail.value.length - 1;
	
	if((AtSym < 1) || (Period <= AtSym + 1) || (Period == Length ) || (Space != -1))
		{
		alert(MsgErreur);
		TheEmail.focus();
		TheEmail.select();
		EmailIsValid = false;
		}
	else
		{
		// On s'assure que tous les autres caractères sont permis (lettres, chiffres, "_")
		
		// On retire le "@" et les "." qui sont présents
		var ls_StringToSearch = TheEmail.value.replace("@", "")
		ls_StringToSearch = ls_StringToSearch.replace(".", "")
		// On parcoure la chaine
		lb_valide = true;
		for (i = 0; i < ls_StringToSearch.length; i++)
			{
			// On applique la fonction escape, qui converti les caractères spéciaux en "%XX"
			ls_Char = escape(ls_StringToSearch.charAt(i));
			if (ls_Char.indexOf("%") != -1)
				{
				// On est en présence d'un caractère illégal
				lb_valide = false;
				}
			else
				{
				// Il reste à tester les signes mathématiques (* / +) qui ne sont pas
				//  pris en compte par la fonction escape
				switch (ls_Char)
					{
					case "/":
					case "*":
					case "+":
						lb_valide = false;
						break;
					}
				}
			}

		if (!(lb_valide))
			{
			alert(MsgErreur);
			TheEmail.focus();
			TheEmail.select();
			EmailIsValid = false;
			}
		}
	
	return EmailIsValid;
	}

function IsPasswordsValid(passwd1, passwd2, MsgErreur)
{
	if(!MsgErreur)
		MsgErreur = 'The new password and the new password confirmation are not the same.';
	if (passwd1.value != passwd2.value)
	{
		alert(MsgErreur);
		passwd1.focus();
		passwd1.select();
		return false;
	}
	return true;
}

function IsSepDateValid(TheDay, TheMonth, TheYear, MsgErreur)
{	//teste les dates saisies dans plusieurs input
	if(!MsgErreur)
		MsgErreur = 'The date is invalid.';

	if (IsInputEmpty(TheDay, MsgErreur)) return false;
	if (IsInputEmpty(TheMonth, MsgErreur)) return false;
	if (IsInputEmpty(TheYear, MsgErreur)) return false;
	if (TheYear.length == 2)
	{
		if (TheYear.value < 50)
			TheYear.value = '20' + TheYear.value;
		else
			TheYear.value = '19' + TheYear.value;
	}
	
	//Tests standards
	if (!VerifDate(TheDay.value, TheMonth.value, TheYear.value))
	{
		alert(MsgErreur);
		if (TheDay.type != 'hidden')
			TheDay.focus();
		return false;
	}
	
	return true;
}

function IsDateValid(TheDate, MsgErreur)
{	//teste les dates saisies dans un seul input
	
	if(!MsgErreur)
		MsgErreur = 'The date is invalide. (JJ/MM/YYYY).';

	var DateIsValid = true;

	if(TheDate.value.length != 10)
		DateIsValid = false;

	//Separation des sections de la date dans différentes variables
	var Day_date = TheDate.value.substring(0, 2);
	var FirstSlash = TheDate.value.substring(2, 3);
	var Month_date = TheDate.value.substring(3, 5);
	var SecondSlash = TheDate.value.substring(5, 6);
	var Year_date = TheDate.value.substring(6, 10);
	
	//test sur les slash
	if(FirstSlash != '/')
		DateIsValid = false;
	if(SecondSlash != '/')
		DateIsValid = false;

	//Tests standards
	if (!VerifDate(Day_date,Month_date,Year_date))
		DateIsValid = false;
	
	//message
	if(!DateIsValid)
	{
		alert(MsgErreur);
		TheDate.focus();
		TheDate.select();
	}
	return DateIsValid;
}

function VerifDate(Day_date,Month_date,Year_date) {

	var DateIsValid = true;
	//Test standard sur le jour, le mois et l'année
	
	if(Day_date < 1 || Day_date > 31 || isNaN(Day_date))
		{
		DateIsValid = false;
		}
	
	if(Month_date < 1 || Month_date > 12 || isNaN(Month_date))
		{
		DateIsValid = false;
		}
	
	if(Year_date < 0 || Year_date > 9999 || isNaN(Year_date))
		{
		DateIsValid = false;
		}
	
	//Test les mois qui n'ont pas 31 jours
	if(Month_date == 4 || Month_date == 6 || Month_date == 9 || Month_date == 11)
		if(Day_date == 31)
			{
			alert("pas 31 jours");
			DateIsValid = false;
			}
			
	//Test sur le mois de février pour les années bisextiles
	if(Month_date == 2)
	{
		if(isNaN(parseInt(Year_date / 4)))
			{alert("mois de février");
			DateIsValid = false;}
		if(Day_date > 29)
			{alert("mois de février");
			DateIsValid = false;}
		if(Day_date == 29 && ((Year_date / 4) != parseInt(Year_date / 4)))
			{alert("mois de février");
			DateIsValid = false;}
	}
	return DateIsValid;
}

