﻿/***************************\
* Greybox Related Functions *
\***************************/
var GB_ROOT_DIR = '/js/greybox/';
var curID = '';

function CloseGB()
{
    GB_hide();
}

function CloseGBandPost()
{
    GB_hide();

    // based on which button was clicked
    if (curID == '')
        alert('Unknown error. Please try again.');
    else
        causePostback(curID);
}

function causePostback(id)
{
    eval(unescape(document.getElementById(id).href));
}
/*******************************\
* End Greybox Related Functions *
\*******************************/

/****************************\
* Calendar Related Functions *
\****************************/
function createDatePicker(id)
{
    $('#' + id).css('margin-right', '3px');
    $('#' + id).datepicker(
            {
                showOn: 'button',
                buttonImage: '/images/calendar/calendar.jpg',
                buttonImageOnly: true,
                changeMonth: true,
                changeYear: true,
                showButtonPanel: true,
                currentText: 'Go To Today',
                closeText: 'Close',
                yearRange: '-1:+10',
                onSelect: function(dateText) {
                    document.all ?
                      $(this).get(0).fireEvent("onchange")
                : $(this).change();
                }
            });
}

function createDatePickers()
{
    $('.date').css('margin-right', '3px');
    $('.date').datepicker(
    {
        showOn: 'button',
        buttonImage: '/images/calendar/calendar.jpg',
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        currentText: 'Go To Today',
        closeText: 'Close',
        yearRange: '-1:+10',
		onSelect: function(dateText) {
			document.all ? $(this).get(0).fireEvent("onchange") : $(this).change();
		}
    });
}
/********************************\
* End Calendar Related Functions *
\********************************/



// custom show/hide function to show images inpage... so they do not take up as much space
function imgMouseOver(id)
{
    // used in the function below
    var iImgHeight = 100;

    $(document).ready(function()
    {
        // make sure we even need to do anything with the image (it could be small enough that it will be "sized up")
        if ($('#' + id).attr('width') > iImgHeight)
        {

            // save the width of the image
            $('#' + id).data('width', ($('#' + id).attr('width') < 650) ? $('#' + id).attr('width') : 650);

            // set the mouseover action to display full size
            $('#' + id).click(
                    function(e)
                    {
                        // set the Animation boolean
                        if (!$('#' + id).data('bAnimate'))
                        {
                            $('#' + id).data('bAnimate', true);
                            $('#' + id).animate({ width: $('#' + id).data('width') }, 500);
                        }
                    });

            // set the mouseout action to shrink to 100px
            $('#' + id).mouseleave(
			        function()
			        {
			            $('#' + id).animate({ width: iImgHeight + 'px' }, 500, 'linear', function()
			            {
			                $('#' + id).data('bAnimate', false);
			            });
			        });

            // init image to 100px, add hand cursor, and make relative
            $('#' + id).css({ 'position': 'absolute', 'cursor': 'hand', 'cursor': 'pointer', 'width': '100px', 'top': '0', 'left': '0', 'z-index': '900' });

            // make the image parent a relative positioned element and put a place holder under the image with the same height and width
            $('#' + id).parent().css('position', 'relative');
            $('#' + id).before('<div style="position:relative;width:100px;height:' + $('#' + id).height() + 'px;">&nbsp;</div>');
        }
    });
}  

// Select/Deselect All Checkboxes
// container: jquery selector of item wrapping checkboxes
// checked: true/false to select/deselect all
function selectAll(container, checked)
{
    $("'" + container + " input:checkbox'").each(function() {
        this.checked = checked;
    });
    return false;
}

// Alternate Rows on tr tags (used in maintenance system)
function altRows() 
{
    $(".formDisplay").each(function(index)
    {
        trToStripe = $("> tbody > tr:not('.header'):not('.ignore'):visible", $(this));
        trToStripe.filter(":even").removeClass("altRow");
        trToStripe.filter(":odd").addClass("altRow");
    });
}

function addCategoryImg() {
    var oCatImg = $('#content').find('.headImgWrap img').remove();
    if (oCatImg.length != 0) {
        $('#mainImg .slide').remove();
        $("#mainImg").append('<div class="slide"><img src="' + oCatImg.attr('src') + '" /> </div>');
    }
    return false;
}
$(function () {
    addCategoryImg();
});
