<script>
$(document).ready(function() {
    $("#shortUrlExpiryDate").datepicker({
        minDate: 0,
        dateFormat: 'dd-mm-yy'
    });
});

$("#longUrl").ready(function() {
    setDefaultPointer();
});

$("#additionalBox").ready(function() {
    setInitialAdditionalOptions();
});

/* pretty up the checkbox if JS is enabled */
$("#searchTermsB").ready(function() {
    var newHTML = "";
    newHTML += "<input name='agreeTerms' id='agreeTerms' value='<?php echo $_REQUEST['agreeTerms']; ?>' type='hidden'/>";
    newHTML += "<img id='agreeTermsCB' class='agreeTermsCB' src='<?php echo SITE_IMAGE_PATH; ?>/checkbox_off.png' width='24' height='20' onClick='clickCheckbox(); return false;'/>";
    $("#searchTermsB").html(newHTML);
    <?php
    if((int)$_REQUEST['agreeTerms'])
    {
        echo "clickCheckbox();";
    }
    ?>
});

function clickCheckbox()
{
    if($("#agreeTermsCB").attr("src") == "<?php echo SITE_IMAGE_PATH; ?>/checkbox_off.png")
    {
        $("#agreeTermsCB").attr("src", "<?php echo SITE_IMAGE_PATH; ?>/checkbox_on.png");
        $("#agreeTerms").val("1");
    }
    else
    {
        $("#agreeTermsCB").attr("src", "<?php echo SITE_IMAGE_PATH; ?>/checkbox_off.png");
        $("#agreeTerms").val("0");
    }
}

function showHideAdditionalOptions()
{
    var targetHeight = 145;
    var originalHeight = 39;

    if($("#additionalBox").css("height") == targetHeight+"px")
    {
        $("#additionalBox").animate({"height": originalHeight+"px"}, "slow");
        document.getElementById("additionalOptState").value = "0";
        document.getElementById("additionalImageIcon").src = "<?php echo SITE_IMAGE_PATH; ?>/downArrow.png";
    }
    else
    {
        document.getElementById("additionalOptState").value = "1";
        document.getElementById("additionalImageIcon").src = "<?php echo SITE_IMAGE_PATH; ?>/upArrow.png";
        $("#additionalBox").animate({"height": targetHeight+"px"}, "slow");
    }
}

function setInitialAdditionalOptions()
{
    <?php
        if((int)$_REQUEST['additionalOptState'] == 1)
        {
            $height = "145";
            ?>
            document.getElementById("additionalImageIcon").src = "<?php echo SITE_IMAGE_PATH; ?>/upArrow.png";
            <?php
        }
        else
        {
            $height = "39";
        }
    ?>
    $("#additionalBox").css("height", "<?php echo $height; ?>px");
}

/* calendar js */
var cal_obj2 = null;
var format = '<?php echo strlen(SITE_CONFIG_DATE_TIME_FORMAT_JS)?str_replace("/", "-", SITE_CONFIG_DATE_TIME_FORMAT_JS):"%d-%m-%Y %H:%i"; ?>';

// user defined onchange handler
function cal2_on_change(cal, object_code)
{
	if (object_code == 'day')
	{
		document.getElementById("shortUrlExpiryDate").value = cal.get_formatted_date(format);
		cal.hide();
		cal_obj2 = null;
	}
}
</script>

<link rel="stylesheet" href="<?php echo SITE_CSS_PATH; ?>/jsShare.css" type="text/css" charset="utf-8" />
<script src="<?php echo SITE_JS_PATH; ?>/jsShare.js" type="text/javascript"></script>
