$(function()
{
    $(".toggleblock .trigger").click(function(event)
    {
        event.preventDefault();
        $(this).parents(".toggleblock:first").find(".hidden").slideToggle();
        $(this).parents(".toggleblock:first").find(".shown").slideToggle();
    });
    
    $(".formsubmit").click(function(event)
    {
        event.preventDefault();
        $(this).parents("form:first").submit();
    });
    
    $("a.coupon").click(function(event)
    {
        event.preventDefault();
        
        var width = 740;
        var height = 560;
        var top = (screen.width - width) / 2;
        var left = (screen.height - height) / 2;
        
        popup = window.open(this.href, 'coupons', 'toolbar=yes,location=yes,directories=no,menubar=yes,scrollbars=yes,width='+width+',height='+height+',resizable=no,top='+top+',left='+left);    
        popup.focus();
    });
    
    if ($(".datepicker").size() > 0)
    {
        $(".datepicker").datepick({ dateFormat: 'yy-mm-dd', showAnim: 'fadeIn' });
    }
});

function initDatePickerRange(first, second, min, max)
{
    $(function()
    {
        if (min != null) { $(first).datepick('option', 'minDate', min); }
        if (max != null) { $(second).datepick('option', 'maxDate', max); }
        
        $(first).datepick('option', 'maxDate', $(second).val());
        $(second).datepick('option', 'minDate', $(first).val());
        
        $(first).datepick('option', 'onSelect', function(string) { $(second).datepick('option', 'minDate', $(first).val()); });
        $(second).datepick('option', 'onSelect', function(string) { $(first).datepick('option', 'maxDate', $(second).val()); });
    });
}