<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><TMPL_VAR .doc.title></title>
<script src="js/page-leave-handler.js" type="text/javascript"></script>

<style>
    .mailHeader{
        background:#ccc;
    }

    .mailSubject{
    }

    .mailBody{
        white-space:pre; 
    }
    
    .done{
        background:#cfc;
    }
    
    table#events td:nth-of-type(1){
        width:15em;
    }

    table#events td:nth-of-type(2){
        width:60em;
    }
    
    td.action, input.action{
        width:5em;
    }
    
    form input{
        width:50em;
    }
    
    form textarea{
        width:50em;
        height:14em;
    }
</style>

<script>
    var region='<TMPL_VAR loc.region>';
    var event_id='<TMPL_VAR event_id>';
    var selectImageId='';
    <TMPL_IF .event_edited>
        $(document).ready(
            function(){
                if ($('div.error').length>0) return;
                if(comeFromCalendar()) getBack();
            }
        );
    </TMPL_IF>
    
    $(document).ready(
        function(){
            $("#forms form").submit(
                function( event ) {
                    event.preventDefault();
                    var $form = $( this );
                    var posting = $.post("notify-events.cgi", $form.serialize());    
                    posting.done(
                        function( data ) {
                            var content = $( data ).find( "#content" );
                            $('#result').html(content);
                            var formId=$form.attr('id');
                            $('#'+formId+" .mailHeader").addClass("done");
                        }
                    );
                }
            );
        }
    );
</script>

</head>
<body>
<div id="result" style="display:none"> </div>

<div id="forms">
<TMPL_LOOP events>
    <form id="event_<TMPL_VAR event_id>">
        <input type="hidden" name="project_id" value="<TMPL_VAR project_id>">
        <input type="hidden" name="studio_id" value="<TMPL_VAR studio_id>">
        <input type="hidden" name="series_id" value="<TMPL_VAR series_id>">
        <input type="hidden" name="event_id" value="<TMPL_VAR event_id>">
        <input type="hidden" name="action" value="send">

    <table id="events">
    <tr id="header_<TMPL_VAR event_id>" class="mailHeader">
        <td><b><TMPL_VAR start></b></td>
        <td><b><TMPL_VAR full_title></b> | <TMPL_IF live>live</TMPL_IF> <TMPL_IF preproduction>preproduction</TMPL_IF> <TMPL_IF playout>playout</TMPL_IF></td>

    <TMPL_IF noRecipient>
        <td></td>
    </tr>

    <tr>
        <td>Warning</td>
        <td><div class="error">no recipient configured at series!</div></td>
    </tr>

    <TMPL_ELSE>

        <td class="action"><input class="button" type="submit" name="action" value="send"></td>
    </tr>

    <TMPL_IF mail.Subject>
    <tr>
        <td>Subject</td>
        <td class="mailSubject"><input name="subject" value="<TMPL_VAR mail.Subject>"></td>
    </tr>
    </TMPL_IF>
    
    <TMPL_IF mail.To>
    <tr>
        <td>To</td>
        <td><input name="to" value="<TMPL_VAR mail.To>"></td>
    </tr>
    </TMPL_IF>

    <TMPL_IF mail.From>
    <tr>
        <td>From</td>
        <td><TMPL_VAR mail.From></td>
    </tr>
    </TMPL_IF>

    <TMPL_IF mail.Cc>
    <tr>
        <td>Cc</td>
        <td><input name="cc" value="<TMPL_VAR mail.Cc>"></td>
    </tr>
    </TMPL_IF>

    <TMPL_IF mail.Reply-To>
    <tr>
        <td>Reply-To</td>
        <td><TMPL_VAR mail.Reply-To></td>
    </tr>
    </TMPL_IF>

    <TMPL_IF mail.data>
    <tr>
        <td>Content</td>
        <td class="mailBody"><textarea name="content" ><TMPL_VAR mail.data></textarea></td>
    </tr>
    </TMPL_IF>

    </TMPL_IF>
</table>
</form>
</TMPL_LOOP>
</div>

</body>
</html>
