<div id="primary_header">
    <h1><?php print $this->translate('Mass Mail')?></h1>
</div>

<div id="Flash" class="flash_notice"></div>

<div id="back_button" style="float:right; margin-right:30px; margin-top:20px; margin-bottom:0px;">
    <a href="#">
        <span class="stronglastword"><?php echo $this->translate('Back to Options') ?></span>
    </a>
</div>

<form id="massmailComposeMessage">
    <input type="hidden" name="sendToAll" value="<?php echo $this->requestParams['sendToAll'] ?>" />
    <input type="hidden" name="sendToAllSubadmins" value="<?php echo $this->requestParams['sendToAllSubadmins'] ?>" />
    <input type="hidden" name="account_o" value="<?php echo @$this->requestParams['account_o'] ?>" />
    <input type="hidden" name="Account" value="<?php echo @$this->requestParams['Account'] ?>" />
    <input type="hidden" name="Ugroup" value="<?php echo @$this->requestParams['Ugroup'] ?>" />
    <input type="hidden" name="domain" value="<?php echo @$this->requestParams['domain'] ?>" />

    <div id="message_wrapper">
        <div class="message reply expanded">
            <div class="message_outer">
                <div class="message_inner">
                    <div class="composedetails">
                        <div class="details">
                            <h3 class="collapse">
                                <div class="leftcompose"></div>
                                <div class="rightcompose" style="height:25px; color:black;">
                                    Matched users for mass mail message: <?php echo $this->matchedUserCount ?> <a href="#" id="clickToView">(click to view list)</a>
                                </div>
                                <div class="leftcompose"><strong><?php print $this->translate('Subject')?>:</strong></div>
                                <div class="rightcompose">
                                    <div id="form_subject" class="focus_subject mass_mail">
                                        <input id="emailSubject" class="subject default" type="text" name="emailSubject" modified="false" value="<?php echo addslashes($this->translate('No Subject')) ?>" />
                                    </div>
                                </div>
                            </h3>
                        </div>
                        <div class="massmailBody">
                            <textarea name="emailBodyHtml" id="massmailMessageBody" class="rte-zone" height="150" style="display:none"></textarea>
                        </div>
                        <div id="massmailSend" class="buttonGeneric" style="margin:10px 0 0 20px;">
                            <span class="stronglastword"><?php print $this->translate('Send Mass mail')?></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.spellchecker.js"></script>
<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.rte.js"></script>
<script type="text/javascript" language="JavaScript">

    $(document).ready( function()
    {
        var tabId = '#Mass_Mail';
        perform_service_common_binds(tabId);
        $('#emailSubject', tabId).bind('focus', function()
        {
            if( $(this).attr('modified') == 'false' )
                $(this).attr('modified', 'true').attr('value', '').removeClass('default')

        })

        // Send email hooks
        $('#massmailSend', tabId).bind('click', function()
        {

            if( $(this).hasClass('disabled') )
                return false

            $('.sendEmail', tabId).disableActionSimpler();

            // Get the HTML message
            var html = $('.rte-zone', tabId).rte_html()
            $("#massmailMessageBody", tabId).attr('value', html)
            $.php('<?php echo $this->moduleBaseUrl ?>/services/massmailsend', $('#massmailComposeMessage', tabId).serializeArray() )
            return false

        })

        //who knows y this works below and y it doesn't work without it
        setTimeout("$('.rte-zone', '#Mass_Mail').rte({ content_css_url: '<?php echo $this->siteBaseUrl ?>css/webmail.css', media_url: '<?php echo $this->siteBaseUrl ?>images/rte-light/' })", 0)

        $('#back_button', tabId).bind('click', function()
        {
            $(tabId).load('<?php echo $this->moduleBaseUrl ?>/services/massmail', $('#massmailComposeMessage', tabId).serializeArray() )
        })

        $('#clickToView', tabId).bind('click', function()
        {

            listPopup = window.open( '', "Mass Mail List", "menubar=0,location=0,height=700,width=700" )
            $listPopup = $( listPopup.document.body )
            $.ajax({
                type: "POST",
                url: '<?php echo $this->moduleBaseUrl ?>/services/massmailviewlist',
                data: $('#massmailComposeMessage', tabId).serializeArray(),
                success: function(response)
                {
                    $listPopup.html( response )
                }
            })
            return false

        })
    })

</script>