function togglePostcode() {
    if ($F(f['uxCountry']) == "AU") {
        $(f['uxPostCode']).enable();
    } else {
        $(f['uxPostCode']).disable();
    }
}

function progressPhoneNumberEntry() {
    if ($F(f['uxPhoneNumberAreaCode']).length == 2) {
        $(f['uxPhoneNumber']).focus();
    }
}

function selectSex(self, other) {
    var passengersLeft = getTotalPassengers() - parseInt(self.options[self.selectedIndex].value);
    
    
    if (!setSelectedValue(other.id, passengersLeft)) {
        other.selectedIndex = other.options.length - 1;
    }
}

function getTotalPassengers() {
    return (totalMaleFemalePassengers);
}

// VALIDATION

function validatePostCodeRequired(source, args) {
    var postCode = $F(f['uxPostCode']).strip();

    if ($F(f['uxCountry']) == "AU" && postCode.length == 0) {
        args.IsValid = false
    } else {
        args.IsValid = true
    }
}

function validatePostCode(source, args) {
    var postCode = $F(f['uxPostCode']).strip();
    var regEx    = /^([0-9]{4})$/;

    if ($F(f['uxCountry']) == "AU") {
        args.IsValid = regEx.test(postCode);
    } else {
        args.IsValid = true
   }
}

function validatePhoneNumber(source, args) {
    var phoneNumber      = $F(f['uxPhoneNumberAreaCode']) + $F(f['uxPhoneNumber']);
    var cleanPhoneNumber = phoneNumber.replace(/[^\d]/g, "");  
    args.IsValid = (cleanPhoneNumber.length == 10)
}

function validateEmail(source, args) {
    var regEx = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    args.IsValid = regEx.test($F(f['uxEmail1']))
}

function validateEmailMatch(source, args) {
    args.IsValid = ($F(f['uxEmail1']).toLowerCase() == $F(f['uxEmail2']).toLowerCase());
}

function validatePinNumber(source, args) {
    var regEx = /^([0-9]{4})$/;
    args.IsValid = regEx.test($F(f['uxPinNumber1']))
}

function validatePinNumberMatch(source, args) {
    args.IsValid = ($F(f['uxPinNumber1']).toLowerCase() == $F(f['uxPinNumber2']).toLowerCase());
}

function validatePassengerSex(source, args) {
    args.IsValid = (parseInt($F(f['uxPassengerSexMale'])) + parseInt($F(f['uxPassengerSexFemale'])) == getTotalPassengers());
}
