var username;
var password;
var title;
var firstname;
var surname;
var phone;
var fax;
var confirmpassword;

function ValidateRegisterForm(){
    var errorMessageReg;
    var passwordError = "";
    errorMessageReg = "The following fields are required: <br />";
    username = $("div.msgboxcontent input[name$='username']").val();
    password = $("div.msgboxcontent input[name$='password']").val();
    title = $("div.msgboxcontent select[name$='title']").val();
    firstname = $("div.msgboxcontent input[name$='firstname']").val();
    surname = $("div.msgboxcontent input[name$='surname']").val();
    phone = $("div.msgboxcontent input[name$='phone']").val();
    fax = $("div.msgboxcontent input[name$='fax']").val();
    confirmpassword = $("div.msgboxcontent input[name='confirmpassword']").val();

    var valid = true;
    
    if(password != confirmpassword){
        passwordError = "Error! Passwords do not match";
        valid = false;
    }
    
    if(username.length <=  0){
        errorMessageReg = errorMessageReg + ' email';
        valid = false;
    }
    if(password.length <=  0){
        errorMessageReg = errorMessageReg + '<br /> password';
        valid = false;
    }
    if(firstname.length <=  0){
        errorMessageReg = errorMessageReg + '<br /> first name';
        valid = false;
    }
    if(surname.length <=  0){
        errorMessageReg = errorMessageReg + '<br /> surname';
        valid = false;
    }
    if(phone.length <=  0){
        errorMessageReg = errorMessageReg + '<br /> phone';
        valid = false;
    }
    if(passwordError.length > 0){
        errorMessageReg = passwordError;
    }
    
    if(!valid){
        $('div#registerresult').show()
        $('div#registerresult').html('<div id="registererror">'+errorMessageReg+'<br /><br /></div>');
    }
    
    return valid;
    
}
