/**
 * Function for submitting free trial forms
 * @author  Dimitar Velkov
 * @version 1.0
 */
$(document).ready(function(){
    $("#signUpButton").click(function(){        
        $(".error").html('&nbsp;');
        var hasError = false;
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

        var emailVal = $("#email").val();
        if(emailVal == '') {
            $("#emailError").html('*');
            hasError = true;
        } else if(!emailReg.test(emailVal)) {
            $("#emailError").html('*');
            hasError = true;
        }

        var websiteVal = $("#website").val();
        if(websiteVal == '') {
            $("#websiteError").html('*');
            hasError = true;
        }

        if(hasError == false) {
            $(this).hide();
            $("#buttonPlace").append('<img src="' + BASE_URL + '/images/ajax-loader.gif" alt="Loading" id="loading" />');

            $.ajax({
                url: BASE_URL + "index.php/ajax/submitFreeTrial",
                type: "POST",
                data: {email : emailVal, website : websiteVal},
                cache: false,
                success: function (html) {
                    if (html == 0) {
                        $("#placeHolder").html("<p id=\"thnTxt\">Thank you for subscribing to ActiveReception.</p>");
                    } else alert('Sorry, unexpected error. Please try again later.');
                }
            });
        }

        return false;
    });
});

