//<!--
function IsDigit(event)
{
	// 8: Backspace 
	if (document.all)
		return (event.which == 8 || ((event.keyCode >= 48) && (event.keyCode <= 57)));
	else if (document.layers)
		return (event.which == 8 || ((event.which >= 48) && (event.which <= 57)));
	return true;
}

function CheckLength(theObject, caption, bRequired, minLength, maxLength) 
{
  if (Number(bRequired) && (theObject.value == ""))
  {
    alert("Veuillez entrer une valeur dans le domaine \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  }

  if (theObject.value.length < minLength)
  {
    alert("Veuillez écrire au moins " + minLength + " caractères dans le domaine de \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  }
  
  if (theObject.value.length > maxLength)
  {
    alert("Veuillez écrire tout au plus  " + maxLength + " caractères dans le domaine de \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  }
  
  return (true);
}

function CheckLetter(theObject, caption)
{
   
  return (true);
}

function CheckLetterDigit(theObject, caption)
{
  
  return (true);
}

function CheckDigit(theObject, caption)
{
  var checkOK = "1234567890";
  var checkStr = theObject.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Veuillez écrire seulement les chiffres dans le domaine \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  }
  
  return (true);
}

function CheckPhone(theObject, caption)
{
  var checkOK = "1234567890()-# ";
  var checkStr = theObject.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Veuillez écrire seulement les chiffres et '()-#' dans le domaine \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  }
  
  return (true);
}

function CheckEmail(theObject, caption)
{
  if (!isEmail(theObject.value))
  {
    alert("Veuillez écrire les caractères seulement de lettre et de chiffre dans le domaine \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  }
  
  return (true);
}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function CheckNumber(theObject, caption)
{
  var checkOK = "1234567890.";
  var checkStr = theObject.value;
  var allValid = true;
  var noPoint = 0;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
	  {
        if (ch == '.')
		  noPoint = noPoint + 1;
		break;
	  }
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Veuillez écrire seulement les chiffres dans le domaine \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  } 
  else if (noPoint > 1)
  {
    alert("Veuillez écrire seulement les chiffres dans le domaine \"" + caption + "\".");
    theObject.focus();
	theObject.select();
    return (false);
  }
  
  return (true);
}

function CheckRange(theObject, caption, lowerBound, upperBound)
{
  if (theObject.value > upperBound || theObject.value < lowerBound)
  {
  	alert("Veuillez écrire entre une valeur dans le domaine \"" + caption + "\"" + lowerBound + " et " + upperBound + ".");
    theObject.focus();
	theObject.select();
    return (false);
  }
  
  return (true);
}

function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)
{
   this[0] = m0;
   this[1] = m1;
   this[2] = m2;
   this[3] = m3;
   this[4] = m4;
   this[5] = m5;
   this[6] = m6;
   this[7] = m7;
   this[8] = m8;
   this[9] = m9;
   this[10] = m10;
   this[11] = m11;
}

function CheckDate(theObject, caption, yearObject, monthObject, dayObject)
{
	var year = getSelectedValue(yearObject);
	var month = getSelectedValue(monthObject);
	var day = getSelectedValue(dayObject);
    var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    // do the classic leap year calculation
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
    	monthDays[1] = 29;
	
	// check the day for the month
	if (monthDays[month-1] < day)
	{
	    alert("Veuillez choisir une date correcte dans le domaine \"" + caption + "\".");
	    theObject.focus();
	    return (false);
	}
	
	return (true);
}

function getSelectedValue(selectObject)	// for "Select"
{
	var selectedIndex = selectObject.selectedIndex;
	if (selectedIndex == -1)
		return ("");
	else
		return (selectObject.options[selectedIndex].value);
}

function SelectCheckbox(theForm, name, caption)
{
	var bSelected = 0;
	var ele=0;
	var length = theForm.elements.length;
	for (var i = 0; i < length; i++)	// loop over all the form elements
	{
		if (theForm.elements[i].name == name)	// find the checkbox by name
		{
			ele = i;
			if (theForm.elements[i].checked)
			{
				return (true);
			}
		}
	}
	
		alert("Veuillez choisir au moins un " + caption + ".");
		theForm.elements[ele].focus();
		return (false);
}

function CheckSelect(theObject, caption, bRequired)
{
	if (Number(bRequired) && (theObject.selectedIndex == -1))
	{
		alert("Veuillez choisir au moins un élément dans le domaine \"" + caption + "\".");
		theObject.focus();
		return (false);
	}
	return (true);
}

function GetRadioValue(radioObj)	// for "Radio"
{
	var i=0;
	if (radioObj.length)
	{
	  for (; i < radioObj.length; i++)
		if (radioObj[i].checked)
			return radioObj[i].value;
	}
	else
	{
		if (radioObj.checked)
			return radioObj.value;
	}
	
    return null;
}

function ArrayToList(theArray, separator)
{
	return theArray.join(separator);
/*
	var theList = "";
	for (i = 0; i < theArray.length; i++)
	{
		if (i > 0)
			theList = theList + separator;
		
		theList = theList + theArray[i];
	}
	
	return theList;
*/	
}

function SpliceArray(theArray, index, howMany)
{
	return theArray.slice(0, index).concat(theArray.slice(index+howMany));
}
//-->
