(function($) {
    $(document).ready(function() {
        var $txtZipCode = $('#txtZipCode');
        var $txtEmailAddress = $('#txtEmailAddress');
        var $btnNextStep = $('#btnNextStep');
        var $btnFinish = $('#btnFinish');
        var $welcomeStep1 = $('#welcomeStep1');
        var $welcomeStep2 = $('#welcomeStep2');
        $txtZipCode.focus();

        var verify_zip = function(value) {
            var ptrn_zip = /^[0-9]{5}$/;
            if (!(ptrn_zip.test(value))) {
                $('#txtZipError').css('visibility', 'visible');
                return (false);
            } else {
                return (true);
            }
        }

        var verify_email = function(value) {
            var ptrn_email = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
            if (!(ptrn_email.test(value)) && value != 'Optional' && value != '') {
                $('#txtEmailError').css('visibility', 'visible');
                $txtEmailAddress.focus();
                return (false);
            } else {
                return (true);
            }
        };

        $btnNextStep.click(function() {
            var zip = $txtZipCode.val();
            if (verify_zip(zip) == true) {
                $('#welcomeStep1 :input').attr("readonly", true);
                $btnNextStep.unbind('click');
                $welcomeStep1.animate({
                    opacity: 0.00,
                    left: '-=140',
                    top: '+=12'
                }, 1000, function() {
                    $welcomeStep1.css('z-index', 1);
                    $welcomeStep2.animate({
                        opacity: 1.0,
                        left: '-=140',
                        top: '-=12'
                    }, function() {
                        $welcomeStep2.css('z-index', 99);
                        $('#welcomeStep2 :input').attr("disabled", false);
                    });
                });
            }
        });

        $txtEmailAddress.click(function() {
            $(this).val('');
            $(this).unbind('click');
            $(this).addClass('txtEmailRegisterNormal');
        });

        $btnFinish.click(function() {
            var email = $('#txtEmailAddress').val();
            if (verify_email(email)) {
                return true;
            } else {
                return false;
            }
        });

    });
})(jQuery);
