<?php
/* setup includes */
require_once('includes/master.inc.php');

/* setup page */
define("PAGE_NAME", t("delayed_redirect_page_name"));
define("PAGE_DESCRIPTION", t("delayed_redirect_meta_description"));
define("PAGE_KEYWORDS", t("delayed_redirect_meta_keywords"));

/* we expect to receive a param on this page, it not, throw an error */
$shortUrlObj = shortUrl::loadByID($u);

require_once('_header.php');
?>

<script>
    <!--
    var milisec = 0;
    var seconds = <?php echo (int) SITE_CONFIG_REDIRECT_DELAY_SECONDS; ?>;

    function display()
    { 
        if (milisec<=0)
        {
            milisec	= 9;
            seconds	-= 1;
        }
        if (seconds<=-1)
        {
            milisec = 0;
            seconds += 1;
        } 
        else
        {
            milisec -= 1;
        }
        if(seconds == 0)
        {
            document.getElementById("countDownTimer").innerHTML = "redirecting";
            window.location = "<?php echo $shortUrlObj->fullUrl; ?>";

        }
        else
        {
            document.getElementById("countDownTimer").innerHTML = seconds+" second";
            if(seconds != 1)
            {
                document.getElementById("countDownTimer").innerHTML += "s";
            }
            setTimeout("display()", 100);
        }
    }

    $(document).ready(function() {
        document.getElementById("countDownTimer").innerHTML = '30';
        display();
    });
    -->
</script>

<!-- top ads -->
<div class="metaRedirectWrapperTopAds">
<?php echo SITE_CONFIG_ADVERT_DELAYED_REDIRECT_TOP; ?>
</div>

<div class="metaRedirectWrapper">
    <div class="metaRedirect">
        <strong><?php echo t("redirecting_to"); ?></strong><br/>
<?php echo $shortUrlObj->getFormattedLongUrl(50); ?><br/>
        <img src="<?php echo SITE_IMAGE_PATH; ?>/pleaseWait.gif" alt="<?php echo t("please_wait"); ?>" width="50" height="50" style="padding: 8px;"/><br/>
		(<span id="countDownTimer"><!-- --></span>)
    </div>
</div>

<!-- bottom ads -->
<div class="metaRedirectWrapperBottomAds">
<?php echo SITE_CONFIG_ADVERT_DELAYED_REDIRECT_BOTTOM; ?>
</div>

<?php
require_once('_footer.php');
?>