$(document).ready(function() {
    Whl.UA.initData();

    $('#tester-submit').click(function(event) {         
        event.preventDefault();
        if (Validate()) {
            $('#formSubmit').submit();
        }     
    });
    
    $('#uxAboutUA').change(function(){
        if($('#uxAboutUA :selected').val()== 7){            
            $('#lblOther').css('display','block');
            $('#otherUA').css('display','block');
            $('#brOtherUAInvalid').css('display', 'block');
            $('#brOtherUA').css('display', 'block');            
        }
        else {
            $('#lblOther').css('display','none');
            $('#otherUA').css('display','none');
            $('#brOtherUAInvalid').css('display', 'none');
            $('#brOtherUA').css('display', 'none');
            $('#otherUAInvalid').html('');
        }
    });  
    $('#showHint').dialog({title: 'Help', bgiframe: false, autoOpen: false, height: 'auto', width: 300,
        buttons: {
            Close: function(){
                $('#showHint').dialog('close');
            }}
    });
    $(".showHintPass").click(function(){
        $("#showHint").show().dialog('open');
    });
});

function Validate(){
//    var flag=true;
    var fields = [];
    fields.push(['fname',   {blank:'Please enter the first name.'}]);
    fields.push(['lname',   {blank:'Please enter the last name.'}]);
    fields.push(['email',   {blank:'Please enter the email.', email:'Please enter the valid email.'}]);
    fields.push(['pass',    {blank:'Please enter the password.'}]);
    fields.push(['stnum',   {blank:'Please enter the street number & name.'}]);
    fields.push(['suburb',  {blank:'Please enter the suburb/city.'}]);
    fields.push(['uxNation',{blank:'Please choose the country.'}]);
    fields.push(['uxAboutUA',{blank:'Please choose the option.'}]);
    fields.push(['birthDayDD', ValidateDOB, 'Please select your date of birth.']);
    fields.push(['uxValidate', {blank:'Please type the right number.'}]);
    if($('#uxAboutUA :selected').val()== 7)
        fields.push(['otherUA', {blank:'Please enter the content.'}]);
    return Whl.validate(fields);    
} 
function ValidateDOB(){
	return(Date.toDate($('#birthDayDD').val()+' '+$('#birthDayMM').val()+' '+$('#birthDayYY').val())!=0);
}