$(document).ready(function(){ 
    
    $("#login-process").ajaxStart(function(){
        $(this).show();
        $("#frmData").hide();
    });

    $("#login-process").ajaxComplete(function(){
        $(this).hide();
    });
    
    $("#aspnetForm").validate();
    
     $("input").bind("focus click keypress", function () {
         $(".message").html('');
    });

    
    $("#aspnetForm").submit(function() {       
        if($("#aspnetForm").valid())
        {
            $.ajax({
                type: "POST",
                url: "/Views/Franchise/SignUp.aspx",
                data: "name=" + $('.name').val() + "&email=" + $('.email').val() + "&contact_number=" + $('.contact_number').val() + "&state_area=" + $('.state_area').val() + "&how_hear=" + $('.how_hear :selected').val(),
                dataType: "html",
                timeout: 50000,
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    //console.log("Status: " + textStatus + " \nError Thrown: " + errorThrown);
                },
                success: function(data) {
                   
                   if($.trim(data) == "True") // true mean haserror
                   {
                        $("#responseMsg").html("<div id=\"join-thanks\" class=\"fail\">You are already subscribed to MYO Franchise Opportunities</p></div>");
                        
                        setTimeout(
                             "$('#responseMsg').fadeOut(); $('#frmData').fadeIn();"
                            , 5000
                        );
                       
                   }
                   else
                   {
                        $("#responseMsg").html("<div id=\"join-thanks\"><h3 class=\"thankyou\">Thanks</h3><p>Thanks for signing up to hear more about MYO franchise opportunities!<br />To confirm this subscription, please check your inbox and click on the link in the email we&rsquo;ve just sent you.</p></div>");
                   }
                }
            });
        }
        return false;
    });
});