﻿/**
 *  Hides or shows an item based on whether a checkbox is checked.
 *
 *  @param  field   Name of the field which is a checkox
 *  @param  div     The layer to hide or show.
 *  @param  delay   The time JQuery should use to show or hide.
 *  @author HSD (TF)
 **/
function displayOnChecked(field, div, delay) {
    if ($(field).is(':checked')) {
        //Use special function below to avoid IE Clear Typing issue
        $(div).fadeIn();
        //$(div).show(delay);
    }
    else {
        $(div).hide(delay);
    }
}
/**
*  Hides or shows an item based on whether a checkbox is UNchecked.
*
*  @param  field   Name of the field which is a checkox
*  @param  div     The layer to hide or show.
*  @param  delay   The time JQuery should use to show or hide.
*  @author HSD (TF)
**/
function displayOnUnChecked(field, div, delay) {
    if ($(field).is(':checked')) {
        $(div).hide(delay);
    }
    else {
        //Use special function below to avoid IE Clear Typing issue
        $(div).fadeIn();
        //$(div).show(delay);
    }
}


/**
*  Returns the value of a radio button thats selected (or undefined)
*
*  @param  field   Name of the field which is a radiobutton
*  @author HSD (TF)
**/
function getSelectedRadioButtonItem(field) {
    return $('input[name=' + field + ']:checked').val();
}

/**
*  Toggles PrintPreview status
*
*  @author HSD (TF)
**/
function togglePrintPreview() {
    var currCSS = document.getElementById('printCSS');
    var currCSS2 = document.getElementById('printCSS2');
    if (currCSS.media == 'all') {
        currCSS.media = 'print';
        currCSS2.media = 'print';
        $('#printPreview').hide();
    }
    else {
        currCSS.media = 'all';
        currCSS2.media = 'all';
        $('#printPreview').show();
    }
}

/**
*  Shows a print preview version of the current page by appending 
*  the PrintPreview querystring to the end of the URL.
*
*  @author HSD (TF)
**/
function showPrintPreview() {
    /*
    var url = window.location.href;
    var qs = window.location.search.substring(1);
    if (qs == "") url += "?"; else url += "&";
    url += "printpreview=true";
    var pp = window.open(url, "printpreview");
    */
}

jQuery.fn.fadeIn = function(speed, callback) {
    return this.animate({ opacity: 'show' }, speed, function() {
        if (jQuery.browser.msie)
            this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};

jQuery.fn.fadeOut = function(speed, callback) {
    return this.animate({ opacity: 'hide' }, speed, function() {
        if (jQuery.browser.msie)
            this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};

jQuery.fn.fadeTo = function(speed, to, callback) {
    return this.animate({ opacity: to }, speed, function() {
        if (to == 1 && jQuery.browser.msie)
            this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
}; 