<?php
defined('_JEXEC') or die('Restricted access');
?>

<script type="text/javascript">
    Joomla.submitbutton = function(task)
    {
        if (task == 'cancel')
        {
            Joomla.submitform(task, document.getElementById('adminForm'));
        }
        if (task == 'apply' || task == 'save' || document.formvalidator.isValid(document.id('adminForm'))) {
            var aurl = document.getElementById('ad_url').value;
            var aimg = document.getElementById('ad_image').value;
            if (aurl != '' && aimg != '')
            {
                var Extension = aimg.substring(aimg.lastIndexOf('.') + 1).toLowerCase();
                if (Extension == "gif" || Extension == "png" || Extension == "jpeg" || Extension == "jpg") {
                    Joomla.submitform(task, document.getElementById('adminForm'));
                }
                else
                {
                    alert("png, jpg, jpeg, gif type of images only accepted!");
                    document.getElementById('ad_image').focus();
                }
            }
            else if (aimg == '')
            {
                document.getElementById('ad_image').focus();
                alert("You must provide advertisment's image!");
            }
            else if (aurl == '')
            {
                document.getElementById('ad_url').focus();
                alert("You must provide advertisment's URL!");
            }
        }
    }
</script>

<fieldset class="adminform">
    <legend>Add new Wishlogue Ad</legend>
    <form id="adminForm" action="index.php?option=com_wishlogue&layout=wishlogueadspace" method="POST" name="adminForm" enctype="multipart/form-data">
        Choose the image for advertisement:
        <input type="file" name="ad_image" id="ad_image" /><br><br>
        Enter the advertisement's URL:
        <input type="text" name="ad_url" id="ad_url"><br><br>
        Enter the Description:
		<textarea name="ad_description" id="ad_description"></textarea><br><br>
        Do you want to enable this ad?: &nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" name="ad_status" id="ad_status" value="1" checked>Yes  &nbsp;&nbsp;&nbsp;&nbsp;
        <input type="radio" name="ad_status" id="ad_status" value="0">No
        <input type="hidden" name="option" value="<?php echo JRequest::getVar('option', 'wishlogue'); ?>"/>
        <input type="hidden" name="optionvalue" value="<?php echo JRequest::getVar('option'); ?>"/>
        <input type="hidden" name="task" value="<?php echo JRequest::getVar('task'); ?>"/>
    </form>
</fieldset>