$(document).ready(function() {

    /**
     * Validate contact us form
     *
     * @author const
     */
    $("#contactUsSubmit").click(function()
    {
        var firstName = $("#first_name").val().replace(/(^\s+)|(\s+$)/g, "");
        if (firstName == "") {
            alert('Please enter your First Name');
            return false;
        }

        var lastName = $("#last_name").val().replace(/(^\s+)|(\s+$)/g, "");
        if (lastName == "") {
            alert('Please enter your Last Name');
            return false;
        }

        var membershipType = $("#00N70000001ygmz").val();
        if (membershipType == "") {
            alert('Please choose a Membership Type');
            return false;
        }

        var company = $("#company").val().replace(/(^\s+)|(\s+$)/g, "");
        if (company== "") {
            alert('Please enter your Company Name');
            return false;
        }

        var url = $('#URL').val().replace(/(^\s+)|(\s+$)/g, "");
        if (url == '') {
            alert('Please enter your website');
            return false;
        }

        var phone = $("#phone").val().replace(/(^\s+)|(\s+$)/g, "");
        if (phone == "") {
            alert('Please enter your Phone Number');
            return false;
        }
        if (!phone.match(/^[\d\-\+\ ]+$/i)) {
            alert('Your Phone Number is incorrect');
            return false;
        }

        var email = $("#email").val().replace(/(^\s+)|(\s+$)/g, "");
        if (email == "") {
            alert('Please enter your Email');
            return false;
        }
        if (!email.match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/i)) {
            alert('Your Email is incorrect');
            return false;
        }

        var country = $('#country').val();
        if (country == '') {
            alert('Please select a country');
            return false;
        }

        var city = $('#city').val().replace(/(^\s+)|(\s+$)/g, "");
        if (city == '') {
            alert('Please enter your city');
            return false;
        }
        if (!city.match(/^[\w \-]+$/i)) {
            alert('Your city is incorrect');
            return false;
        }

        var state = $('#state').val();
        if (country == 'US' && state == '') {
            alert('Please choose your state');
            return false;
        }

        var zipcode = $('#zip').val().replace(/(^\s+)|(\s+$)/g, "");
        if (zipcode == '') {
            alert('Please enter your zipcode');
            return false;
        }
        if (!zipcode.match(/^[A-Z0-9]+$/)) {
            alert('Your zipcode is incorrect');
            return false;
        }

        var description = $('#description').val().replace(/(^\s+)|(\s+$)/g, "");
        if (description == '') {
            alert('Please enter a description');
            return false;
        }

        return true;
    });

    $("#country").change(function()
    {
        if ($(this).val() == "US" || $(this).val() == "United States") {
            $("#state").val('');
            $("#state").removeAttr("disabled");
        } else {
            $("#state").val('NONUS');
            $("#state").attr("disabled", "disabled");
        }
    });
});
