var PanelReSize =
{
    /* This is used to resize panels to be the same height as their neighbours */
    height: 0,
    init: function() {
        /* what page are we on? */
        if ($('#homeContent')) {
            PanelReSize.homePage();
        }
    },
    homePage: function() {
        if ($('.panelWrapper').children().height() > 0) {
            PanelReSize.setHeight($('.panelWrapper').children());
            return true;
        }
    },
    setHeight: function(matchedSet) {
        $(matchedSet).each(function() {
            if ($(this).outerHeight() > PanelReSize.height) {
                PanelReSize.height = $(this).outerHeight();
            }
        });
        $(matchedSet).each(function() {
            var difference = $(this).outerHeight() - $(this).height();
            var newHeight = PanelReSize.height - difference;
            $(this).height(newHeight);
        });
        //console.log(PanelReSize.height);
        PanelReSize.height = 0;
    }
}

var Pie =
{
    remove: function() {
        $('.css3Pie').removeClass('css3Pie'); // CSS3PIE compatability issue work around
    },
    add: function() {
        $('.rounded').addClass('css3Pie'); // CSS3PIE compatability issue work around
    }
}

var CheckZoom =
{
    init: function() {
        var b = document.body.getBoundingClientRect();
        var newZoom = (b.right - b.left) / document.body.clientWidth;
        if (newZoom != 1) {
            Pie.remove();
            $('div').unbind('resize');
        }
    }
}


$(document).ready(function() {
    if ($.browser.msie) {
        PanelReSize.init();
        Pie.add();

        window.onbeforeprint = Pie.remove;
        window.onafterprint = Pie.add;
        if ($.browser.version.substr(0, 1) == 7) {
            /* Fix for IE7 && CSS3Pie zoom bug */
            CheckZoom.init();
            $('div').bind('resize', function() {
                CheckZoom.init();
            });
        }
    }
});

function SubmitOnEnter(submitButtonId) {
    var submitButton = document.getElementById(submitButtonId);

    var keycode;

    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else
        return true;

    if (keycode == 13) {
        submitButton.click();
        return false;
    }
    else
        return true;
}

