<!DOCTYPE html>
<html>
<head>
    <title>Login</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;
        }
        label {
            width: 100px;
            display: block;
            float: left;
        }
        p {
            margin-top: 0px;
        }
        textarea, select, input {
            border: 1px solid #D1D1D1;
            padding: 5px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            background-color: white;
            width: 240px;
        }
    </style>
</head>

<body>
    <form method="post" action="" id="public-ticket-create">
        <fieldset>
            <p>
                <label>{% trans 'Name' %}: </label>
                <input type="text" name="name" value="{{request.name}}" required="required">
            </p>

            <p>
                <label>{% trans 'Email' %}: </label>
                <input type="email" name="email" value="{{request.email}}" required="required">
            </p>

            <p>
                <label>{% trans 'Subject' %}: </label>
                <input type="text" name="subject" value="{{request.subject}}" required="required">
            </p>

            <p>
                <label>{% trans 'Message' %}: </label>
                <textarea name="message" cols="5" rows="5" required="required">{{request.message}}</textarea>
            </p>

            {% if guest.system_param({"key":"captcha_enabled"}) %}

            {% set publickey = guest.system_param({"key":"captcha_recaptcha_publickey"}) %}
            {% set server = "http://www.google.com/recaptcha/api" %}
            <script type="text/javascript">
                var RecaptchaOptions = {
                theme : 'custom',
                custom_theme_widget: 'recaptcha_widget'
             };
            </script>

             <div id="recaptcha_widget" style="display:none">

               <div id="recaptcha_image"></div>
               <div class="recaptcha_only_if_incorrect_sol" style="color:red">{% trans 'Incorrect please try again' %}</div>

               <p>
                   <label>{% trans 'Enter the words above' %}</label>
                   <br/>
                   <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" style="width: 245px"/>
                    <a class="bb-button" href="javascript:Recaptcha.reload()" style="float: right"><span class="dark-icon i-reload"></span></a>
               </p>
             </div>

            <script type="text/javascript" src="{{ server }}/challenge?k={{ publickey }}"></script>

            <noscript>
                <iframe src="{{ server }}/noscript?k={{ publickey }}" height="300" width="500" frameborder="0"></iframe><br/>
                <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
                <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/>
            </noscript>

            {% endif %}

            <input class="bb-button bb-button-submit" type="submit" value="{% trans 'Send' %}" style="width: auto;"/>

        </fieldset>

        <input type="hidden" name="anti-spam" value="1" id="anti-spam" required="required"/>
    </form>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
    $('#anti-spam').remove();

    $('#public-ticket-create').bind('submit',function(event){
        $.post('{{ constant('BB_URL') }}bb-api/rest.php/guest/support/ticket_create',
        $(this).serialize(),
        function(json) {
            if(json.error) {
                alert(json.error.message);
            } else {
                parent.window.location = '{{ 'contact-us/conversation'|link }}' + '/' + json.result;
            }
        }, 'json');
        return false;
    });
});
</script>
</body>
</html>