AdEase.contact = function() {
    AdEase.systemBusy();

    jQuery.ajax({
        'url': '/becomeclient/contact',
        'dataType': 'json',
        'data': jQuery('#contact-form').serialize(),
        'type': 'post',
        'success': function(res) {
            AdEase.systemFree();
            AdEase.msg(res.message);

            if (res.status) {
                setTimeout(function() {
                    AdEase.redirect('/index/contact');
                }, 2000);
            }
        }
    });
};

AdEase.register = function(internal) {
    AdEase.systemBusy();

    jQuery.ajax({
        'url': '/becomeclient',
        'dataType': 'html',
        'type': 'post',
        'success': function(res) {
            AdEase.systemFree();

            AdEase.openPopup({
                'title': 'Registration',
                'width': 410,
                'height': 500,
                'html': res + '<div style="padding: 10px 0 0 0; text-align: right;"><input type="button" id="popup-register" class="g-button" value="Register" /></div>',
                'afterOpen': function(popup) {

                    jQuery('#popup-register').click(function() {
                        jQuery.ajax({
                            type: "post",
                            url: "/becomeclient/try",
                            data: jQuery('#add-client-form').serialize() + '&' + encodeURIComponent("data[internal]") + '=' + internal,
                            dataType : 'json',
                            success: function(res) {

                                if (res.status) {
                                    popup.remove();
                                    AdEase.msg('Your information will be approved shortly and you will receive all nessesary information via email.');
                                } else {
                                    jQuery('#add-client-form .alert').hide();
                                    jQuery('#add-client-form .custom_error').html('');

                                    jQuery.each(res.data, function(key, value) {
                                        if (key == 'state' || key == 'country') {
                                            key += key + '-alert';
                                        }
                                        jQuery('#' + key).show();
                                        if (value != 'Required') {
                                            jQuery('#' + key + '_error').html(value);
                                        }
                                    });
                                }
                            }
                        });
                    });
                }
            });
        }
    });
};

AdEase.checkState = function() {
    if (jQuery('#country').val() == 'US') {
        jQuery('#state').hide().attr('name', 'undefined');
        jQuery('#state_ca').hide().attr('name', 'undefined');
        jQuery('#state_us').show().attr('name', 'data[state]');
    } else if (jQuery('#country').val() == 'CA') {
        jQuery('#state').hide().attr('name', 'undefined');
        jQuery('#state_us').hide().attr('name', 'undefined');
        jQuery('#state_ca').show().attr('name', 'data[state]');
    } else {
        jQuery('#state_ca').hide().attr('name', 'undefined');
        jQuery('#state_us').hide().attr('name', 'undefined');
        jQuery('#state').show().attr('name', 'data[state]');
    }
};

AdEase.faPresentation = function() {
    AdEase.frontLightBox({
        'html': '<embed width="100%" height="417px" src="/template/adease/presentation.swf" />',
        'title': 'Flyer Analyzer Presentation',
        'subtitle': '',
        'logo': 'fa'
    });
};
