// FUNCTIONS TO PROMPT USER:
//
// warnInvalidRadio (radio, s)           Notify user that contents of field radio are invalid.
// warnEmptyCombo (radio, s)			 Notify user that content of Combo is empty.

// FUNCTIONS TO INTERACTIVELY CHECK FIELD CONTENTS:
//
// isRadioButtonChecked ((radio, s)			Verify that radio is Checked.
// checkSelected (theField, s, emptyOK)		Check that Dropdownlist is Selected
// isCheckedBox (Checkbox, isChecked, s)	Check that Ckheckbox is Checked

//Constante 
var mFRCivility = "Please enter a civility.";
var mFRGoldenQ1 = "Please answer the first question.";
var mFRGoldenQ2 = "Please answer the second question.";

var iFRPhone = "This field must be a valid phone number. Please reenter it now.";
var iFRMobilePhone = "Le numero de telephone doit contenir 10 chiffre [exemple : 0101020304].  Veuillez le ressaisir svp.";
var iFRAge = "Please enter a valid age (Integer between 10 and 99).";
var iFRDate = "Date"

var sFREmail = "Email"
var sFRName = "Name";
var sFRFirstName = "First Name";
var sFRAddr = "Address"
var sFRCity = "City";
var sFRZip = "Zip Code";
var sFRCountry = "Country";
var sFRQuestion = "Question";
var sFRLangue = "Language";
var sFRBrand = "Brand";
var sFRModel = "Model";
var sFRSMSNumber = "Mobile";
var sFRIndex = "index"
var sFRClassement = "Ranking"

var cAgeMin = 10;
var cAgeMax = 99;

//Notify user that contents of field radio are invalid.
function warnInvalidRadio (radio, s){	
	radio[0].focus();
	alert(s);
	return false;
}

//idem warnempty mais sans le set focus qui fait erreur sous netscape
function warnEmptyCombo (theField, s)
{   //theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}

//Verify that radio is Checked.
function isRadioButtonChecked (radio, s){
	var rtn=false;
     for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { rtn=true; }
    }
    if (!rtn) 
       return warnInvalidRadio (radio, s);
    else return true;
}

//Verify that radio is Checked Whithout Prompt alert if false.
function isRadioButtonChecked_Ex (radio){
	var rtn=false;
     for (var i = 0; i < radio.length; i++)
    {   if (radio[i].checked) { rtn=true; }
    }
    if (!rtn) 
       return false;
    else return true;
}

// Get checked value from radio button.

function getRadioButtonValueEx (radio)
{   for (var i = 0; i < radio.length-1; i++)
    {   if (radio[i].checked){ break }
    }
    if (!radio[i].checked) {return false;}
    return radio[i].value
}


//Verify that CheckBox is Checked.
function isCheckedBox (Checkbox, isChecked, s){
	if(!isChecked)
		return warnInvalid(Checkbox, s)
	else return true;
}

// CheckIsTrue :  One of the checkbox must be checked.
function CheckIsTrue (checkbox, b, s) {
	if (!isTrue(b)) return warnInvalid(checkbox, s);
	return true;
}
function isTrue(b) {
	return b;
}

//Check that Dropdownlist is Selected.
function checkSelected (theField, s, emptyOK){   
	// Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkSelected.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (!isSelected(theField))) return true;
    if (!isSelected(theField)) 
       return warnEmptyCombo (theField, s);
    else return true;
}

//Verify that Dropdownlist is Selected.
function isSelected(theField){
sValue = new String(theField.options[theField.selectedIndex].value);
if (sValue=="0" || isEmpty(sValue)) return false;
else return true;
}

// checkIntegerInRange (TEXTFIELD theField, STRING s, INTEGER a, INTEGER b [, BOOLEAN emptyOK])
// 
// Check that string theField.value is an Integer in the specified Range.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkIntegerInRange (theField, s, a, b, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkIntegerInRange.arguments.length == 4) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isIntegerInRange(theField.value, a, b)) 
       return warnInvalid (theField, s);
    else return true;
}

// checkDateEx (yearField, monthField, dayField, STRING labelString [, OKtoOmitDay==false], [, BOOLEAN emptyOK])
//
// It's Same Function That checkDate but we Add parameter emptyOK
//
// Check that yearField.value, monthField.value, and dayField.value 
// form a valid date.
//
// If they don't, labelString (the name of the date, like "Birth Date")
// is displayed to tell the user which date field is invalid.
//
// If it is OK for the day field to be empty, set optional argument
// OKtoOmitDay to true.  It defaults to false.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkDateEx (yearField, monthField, dayField, labelString, OKtoOmitDay, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if ( (checkDateEx.arguments.length == 4) || (checkDateEx.arguments.length == 5) ) emptyOk = false;
    if (checkDateEx.arguments.length == 4) OKtoOmitDay = false;
    if ((emptyOK == true) && (isEmpty(yearField.value + monthField.value + dayField.value))) return true;
    if (!isYear(yearField.value)) return warnInvalid (yearField, iYear);
    if (!isMonth(monthField.value)) return warnInvalid (monthField, iMonth);
    if ( (OKtoOmitDay == true) && isEmpty(dayField.value) ) return true;
    else if (!isDay(dayField.value)) 
       return warnInvalid (dayField, iDay);
    if (isDate (yearField.value, monthField.value, dayField.value))
       return true;
    alert (iDatePrefix + labelString + iDateSuffix)
    return false
}

// checkFRPhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid French Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkFRPhone (theField, emptyOK)
{   if (checkFRPhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isUSPhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iFRPhone);
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = normalizedPhone//reformatFRPhone(normalizedPhone)
          return true;
       }
    }
}

// checkFRMobilePhone (TEXTFIELD theField [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is a valid FR Mobile Phone.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkFRMobilePhone (theField, emptyOK)
{   if (checkFRMobilePhone.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    else
    {  var normalizedPhone = stripCharsInBag(theField.value, phoneNumberDelimiters)
       if (!isFRMobilePhoneNumber(normalizedPhone, false)) 
          return warnInvalid (theField, iFRMobilePhone);
       else 
       {  // if you don't want to reformat as (123) 456-789, comment next line out
          theField.value = normalizedPhone //reformatFRPhone(normalizedPhone)
          return true;
       }
    }
}

//
function isFRMobilePhoneNumber (s)
{	if (isEmpty(s)) 
       if (isFRMobilePhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isFRMobilePhoneNumber.arguments[1] == true);
    return (isInteger(s) && s.length == digitsInUSPhoneNumber && s.substring(0,2)=="06")
}

// takes FRPhone, a string of 10 digits
// and reformats as 01 47 33 56 25
function reformatFRPhone (FRPhone)
{   return (reformat (FRPhone, "", 2, ".", 2, ".", 2, ".", 2, ".", 2))
}


/* FUNCTIONS TO INTERACTIVELY CHECK VARIOUS FIELDS. */

// checkInteger (TEXTFIELD theField, STRING s, [, BOOLEAN emptyOK==false])
//
// Check that string theField.value is not all whitespace.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function checkInteger (theField, s, emptyOK)
{   // Next line is needed on NN3 to avoid "undefined is not a number" error
    // in equality comparison below.
    if (checkInteger.arguments.length == 2) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isInteger(theField.value)) 
       return warnInvalid (theField, s);
    else return true;
}