﻿$(document).ready(function() {
    $("#emailButton").click(function() {
        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        var hasError = false;
        var emailToVal = $("#emailsubscribtion").val();
        if (emailToVal == '') {
            $("#error").html('</br>Zapoměli jste napsat email.');
            hasError = true;
        } else if (!emailReg.test(emailToVal)) {
            $("#error").html('</br>Prosím zadejte platný email');
            hasError = true;
        }

        if (hasError == false) {
             $.ajax({
                type: 'POST',
                url: 'http://www.sahajayoga.cz/emailsubscription.php',
                dataType: 'json',
                data: {
                    emailsubscribtion: $("#emailsubscribtion").val()
                },
                success: function(data) {
                    if (data.error == false) {
                        $("#error").html('</br><span id="error" >Omllouváme se došlo k chybě. Zkuste jiný prohlížeč.</span>');
                    }
                    else
                    {
                        //$('#emailWaiting').html("Děkujeme za registraci");
						$("#error").html("Děkujeme za registraci");
                     
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) { }
            });
        }
    });
});

