<!--

GlobalMsg = ''
Language = ''

/*************************************************************************************************
  BEGIN TRIM
*************************************************************************************************/
// LEFT
//====
function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ((i <= len) && (str.charAt(i) == " "))
			i++;

   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
} // end TrimLeft

// RIGHT
//=====

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ((i >= 0) && (str.charAt(i) == " "))
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
} // end TrimRight

function TrimString( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
} // end Trim


/*************************************************************************************************
  BEGIN CHECK DATE
*************************************************************************************************/
function _CF_onError(form_object, input_object, object_value, error_message)
    {
	//alert(error_message);
       	return false;	
    }



function _CF_hasValue(obj, obj_type)
    {
    if (obj_type == "TEXT" || obj_type == "PASSWORD")
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true; 
    	}
    else if (obj_type == "SELECT")
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj.options[i].selected)
			return true;
		}

       	return false;	
	}
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
	{

		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
	{

        for (i=0; i < obj.length; i++)
	    	{
		if (obj[i].checked)
			return true;
		}

       	return false;	
	}
	}



function _CF_checkeurodate(object_value)
    {
    //Returns true if value is a eurodate format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the dd/mm/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sDay = object_value.substring(0, isplit);
	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
		return false;

    sMonth = object_value.substring((sDay.length + 1), isplit);

	sYear = object_value.substring(isplit + 1);

	if (!_CF_checkinteger(sMonth)) //check month
		return false;
	else
	if (!_CF_checkrange(sMonth, 1, 12)) // check month
		return false;
	else
	if (!_CF_checkinteger(sYear)) //check year
		return false;
	else
	if (!_CF_checkrange(sYear, 0, null)) //check year
		return false;
	else
	if (!_CF_checkinteger(sDay)) //check day
		return false;
	else
	if (!_CF_checkday(sYear, sMonth, sDay)) //check day
		return false;
	else
		return true;
    }



function _CF_checkday(checkYear, checkMonth, checkDay)
    {

	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return _CF_checkrange(checkDay, 1, maxDay); //check day
    }



function _CF_checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	return _CF_checknumber(object_value);
    else
	return false;
    }



function _CF_numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
    }



function _CF_checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }



function _CF_checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!_CF_checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (_CF_numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }


function  CheckDate(ThisForm, ThisObject,TheLength)

    {
	var SameObject = TrimString(ThisObject.value)
	if (SameObject.length != TheLength)
		{
			return false
				}

    if  (!_CF_hasValue(ThisObject, "TEXT" )) 

        {

        if  (!_CF_onError(ThisForm, ThisObject, ThisObject.value, "Error in TestDate text."))

            {

            return false; 

            }

        }


    if  (!_CF_checkeurodate(ThisObject.value))

        {

        if  (!_CF_onError(ThisForm, ThisObject, ThisObject.value, "Error in TestDate text."))

            {

            return false; 

            }

        }


    return true;

    }

/*************************************************************************************************
  BEGIN CHECK SELECTED COMBO
*************************************************************************************************/

/*************************************************************************************************
  BEGIN CHECK SELECTED COMBO
*************************************************************************************************/
function CheckCombo (MyObject)
	{	if (MyObject[MyObject.selectedIndex].value == '')
			{	return (false)
					} else {
				return true
					}
	}


/*************************************************************************************************
  BEGIN CHECK INTEGER
*************************************************************************************************/

function CheckInteger(TheValue) {
	//Trim the value and assign it to var Number
	MyNumber = TrimString(TheValue)
	//Return false if the value is not a number
	if ( isNaN(TheValue) || (MyNumber.length==0) ) {
		return false;
			}	
	if ( parseFloat(TheValue) == parseInt(TheValue) ) {
		// Is Integer
		return true
		} else { // Not Integer
		return false
			}
    }

/*************************************************************************************************
  BEGIN CHECK MAXLENGTH TEXTAREA
*************************************************************************************************/
function CheckMLength (TheValue,MaxLength) {
	if (TheValue.length > MaxLength) {
		return false
		} else {
		return true
			}
 }

/*************************************************************************************************
  BEGIN CHECK EXACT LENGTH
*************************************************************************************************/
function CheckLength (TheValue,MaxLength) {
	//var SameValue
	//SameValue = TrimString(TheValue)
	if (TheValue.length == MaxLength) {
		return true
		} else {
		return false
			}
 }

/*************************************************************************************************
  BEGIN CHECK IF NUMBER
*************************************************************************************************/

function CheckIfNr (MyNumber) {
	if ( isNaN(MyNumber) ) { // Not a number
						 return false 
						} else { // Is a number
						return true
							}
}

/*************************************************************************************************
  BEGIN CHECK IF VALID EMAIL
*************************************************************************************************/

// Checks the E-MAIL field.
function isEmail(TheObject)
   {
  //Last 2 letters of the email adress
  TheDomSfx1 = TheObject.slice(TheObject.length-3,TheObject.length)
  //Last 3 letters of the email adress
  TheDomSfx2 = TheObject.slice(TheObject.length-4,TheObject.length)
  //Return false if the first letter of TheDomSfx1 is  not '.' AND if the first letter of TheDomSfx2 is  not '.' 
  if ( (TheDomSfx1.charAt(0) != '.') && (TheDomSfx2.charAt(0) != '.') )
	{	return false
			}
	
  TheObject.slice
   // Return false if e-mail field is blank.
   if (TheObject == "") 
	{	return false
			}
   // Return false if e-mail field does not contain a '@' and '.' .
   if (TheObject.indexOf ('@',0) == -1 || 
       TheObject.indexOf ('.',0) == -1)
      {	return false
			}
      return true
   }

/*************************************************************************************************
  BEGIN CHECK IF OPTION OR RADIO SELECTED
*************************************************************************************************/
function CheckGroup (MyGroup,NrOfElement) {
var Flag = false;
for (i=0;i<NrOfElement;i++)
	{
	if (MyGroup[i].checked==true)
		{
		Flag = true;
		}
	}
if (Flag==false) 
	{
	return false;
	} else {
	return true;
	}
}

/*************************************************************************************************
  BEGIN CALL THE RIGHT FUNCTION
*************************************************************************************************/
function CheckField ( Name, TheForm ,FieldObject, CheckType, Required, MaxLength )
	 {
		// Return false if the checked field is empty and required
		var MyObject
		var isLengthNull = false
		var msgRequired, msgDate, msgInt, msgString1a, msgString1b, msgString2a
		var msgString2b, msgNumber, msgEmail, msgSelect
		if (Language == 'en')
			{
			msgRequired = ' is required.\r' 
			msgDate = ' is not a valid date.\r'
			msgInt = ' is not a valid integer.\r' 
			msgString1a = ' can not contain more than '
			msgString1b = ' characters.\r' 
			msgString2 = ' must have a length of '
			msgNumber = ' is not a valid number.\r'
			msgEmail = ' is not a valid email address.\r'
			msgSelect = ' has to be selected.\r'
			} 
		if (Language == 'fr')
			{
			msgRequired = ' est requis.\r' 
			msgDate = ' n\'est pas une date valide.\r'
			msgInt = ' n\'est pas un entier.\r' 
			msgString1a = ' ne peut pas contenir plus de '
			msgString1b = ' charactères.\r' 
			msgString2 = ' doit avoir une longueur de '
			msgNumber = ' doit avoir 4 chiffres.\r'
			msgEmail = ' n\'est pas une adresse e-mail valide.\r'
			msgSelect = ' doit être sélectionné.\r'
			} 
		if (Language == 'nl')
			{
			msgRequired = ' is benodigd.\r' 
			msgDate = ' is geen juiste datum.\r'
			msgInt = ' is geen juiste integer. .\r' 
			msgString1a = ' kan niet meer dan  '
			msgString1b = ' karakters bevatten.\r' 
			msgString2 = ' moet een lengte hebben van '
			msgNumber = ' is geen geldig nummer.\r'
			msgEmail = ' is geen geldig E-mail adres.\r'
			msgSelect = ' moet geselecteerd worden.\r'
			} 


/**********************************************************************************************************************
 REQUIRED FIELDS
**********************************************************************************************************************/
				
		if (Required=='yes')
			{
			switch (CheckType) {	
					case 'date' : case 'integer' : case 'string' : case 'string2' : case 'number' : case 'email' :
						MyObject = TrimString(FieldObject.value)
						if (MyObject.length == 0) {
							isLengthNull = true
						}
						if ( (MyObject.length == 0)  ) {
			  				GlobalMsg = GlobalMsg + '\'' + Name  + '\'' + msgRequired ;
							return false;
						} 
					break;
					case 'select' :
						MyObject = TrimString(FieldObject[FieldObject.selectedIndex].value)
						if (MyObject == '') {
							isLengthNull = true;
							GlobalMsg = GlobalMsg  + '\''  +  Name  + '\'' + msgSelect  ;
							return false;
						}
					break;
					case 'group' :
						isLengthNull = true;
						if ( !CheckGroup (FieldObject,MaxLength) ) {
						GlobalMsg = GlobalMsg  + '\'' +  Name  + '\''  + msgRequired
							}
						return CheckGroup (FieldObject,MaxLength)
					break;
					} //End switch
			} // Enf if

/**********************************************************************************************************************
 CHECK SPECIAL VALUES
**********************************************************************************************************************/
			
		if (isLengthNull == false && MaxLength != -1) {
				switch (CheckType) {
					case 'date' :
						if ( !CheckDate(TheForm, FieldObject,MaxLength) ) {
							GlobalMsg = GlobalMsg  + '\'' +  Name  + '\'' + msgDate
							}
						return CheckDate(TheForm, FieldObject,MaxLength)
					break;
					case 'integer' :
						if ( !CheckInteger(FieldObject.value) ) {
						GlobalMsg = GlobalMsg + '\''  +  Name  + '\'' + msgInt
							}
						return CheckInteger(FieldObject.value)	
					break;
					case 'string' :
						if ( !CheckMLength(FieldObject.value, MaxLength) ) {
						GlobalMsg = GlobalMsg  + '\'' +  Name  + '\'' + msgString1a + MaxLength + msgString1b
							}
						return CheckMLength(FieldObject.value, MaxLength)
					break;
					case 'string2' :
						if ( !CheckLength(FieldObject.value, MaxLength) ) {
						GlobalMsg = GlobalMsg  + '\'' +  Name  + '\'' + msgString2 + MaxLength + '.\r'
							}
						return CheckLength(FieldObject.value, MaxLength)
					break; 
					case 'number' :
						if ( !CheckIfNr(FieldObject.value) ) {
						GlobalMsg = GlobalMsg  + '\'' +  Name  + '\'' + msgNumber
							}
						return CheckIfNr(FieldObject.value)
					break;
					case 'email' :
						if ( !isEmail(FieldObject.value) ) {
						GlobalMsg = GlobalMsg  + '\'' +  Name  + '\'' + msgEmail
							}
						return isEmail(FieldObject.value)
					break;


						}
			} // End If
	return true
	}

// -->

