<!DOCTYPE html>
<html>
<head>
    <title>Check domain</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <style type="text/css">
        body { margin: 0; }
        form {
            border: 1px solid #D1D1D1;
        }
        fieldset {
            border: 0px;
        }
        legend {
            padding-top: 15px;
        }
        p {
            margin: 0px;
        }
        textarea, select, input {
            border: 1px solid #D1D1D1;
            padding: 5px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            background-color: white;
        }
    </style>
</head>

<body>
<form method="post" action="" class="domainsearch" id="domain-checker">
    <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
    <fieldset>
        <p>
            <input type="text" id="dsearch" value="" name="sld" />
            {% set tlds = guest.servicedomain_tlds %}
            <select id="dsearch" name="tld">
                {% for tld in tlds %}
                <option value="{{ tld.tld }}" label="{{ tld.tld }}">{{ tld.tld }}</option>
                {% endfor %}
            </select>
        <button class="button large dsearch" type="submit"><span>Search</span></button>
        </p>
    </fieldset>
</form>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
    $(function() {
        $('#domain-checker').on('submit', function(event) {
            $.post("{{ constant('SYSTEM_URL') }}api/guest/servicedomain/check",
            $(this).serialize(),
            function(json) {
                if (json.error) {
                    alert(json.error.message);
                } else if (json.result) {
                    alert('Domain is available');
                } else {
                    alert('Domain is already registered');
                }
            }, 'json');

            return false;
        });
    });
</script>
</body>
</html>
