/**
*   author: fabrice antinoro
*   date :  03/11/2005
*   description : process to validate form   
**/

/*
*   Validate a listbox object
*/

function validateListBox( listBox ){
    var boolValidate = false;
    if( listBox != null ){
        if( listBox.value != '0' ){
            boolValidate = true;
        }
    }
    return boolValidate;
}

function validatePhone( phoneInput ){
    var phone = "" ;
    var boolValidate = false;
    if( phoneInput != null ){
        phone = phoneInput.value;
    }
    
    if( phone != "" ){
      try{
            if( phone.match("^[0-9]{10,12}$") ){
                boolValidate = true;
            }
      }catch(arg){}
    }
    return boolValidate;
}

function submit( form ){
    if( mainValidateForm( form ) ){
            form.submit();
        }    
}

function mainValidateForm( theForm ){
    var boolValidate = false;
    boolSex = validateListBox( theForm.sex );
    boolAge = validateListBox( theForm.age );
 boolCountry = validateListBox( theForm.country );
    boolInterest = validateListBox( theForm.interest );
    boolNumber =  validatePhone( theForm.phoneNumber );
    var errMessage = "";
    if( !boolSex ){
        errMessage = "The sex is invalid.\n";    
    }
    if( !boolAge ){
        errMessage += "The age is invalid.\n";
    }
    if( !boolInterest ){
        errMessage += "The interest is invalid.\n";
    }
 if( !boolCountry ){
        errMessage += "The country is invalid.\n";
    }
    if( !boolNumber ){
        errMessage += "The phone number is invalid.\n";
    }
    boolValidate = (boolSex && boolAge && boolInterest && boolNumber && boolCountry );
    if( !boolValidate ){alert( errMessage );}
    return boolValidate;
}
