/// <reference path="jquery.min.js"/> 

//NAV MOUSEOVERS
function show(hideID) {
    document.getElementById(hideID).className = "shown"
}

function hide(hideID) {
    document.getElementById(hideID).className = "hidden"
}

function tg(id) {
    if (document.getElementById) {
        if ((document.getElementById(id).style.display == 'none') || (document.getElementById(id).style.display
    == null) || (document.getElementById(id).style.display == '')) {
            document.getElementById(id).style.display
    = 'block';
        } else { document.getElementById(id).style.display = 'none'; }
    } else
        if (document.all) {
        if (document.all[id].style.display == 'none') {
            document.all[id].style.display
    = 'block';
        } else { document.all[id].style.display = 'none'; }
    }
}

// Method to modify DOM object innerText values that works for all browsers.
function SetInnerText(object, text) {
    if (object.textContent != null) object.textContent = text;
    else object.innerText = text;
}


/*
* Image preview script 
* powered by jQuery (http://www.jquery.com)
* 
*/

this.imagePreview = function () {
    /* CONFIG */
    // these 2 variable determine popup's distance from the cursor
    xOffset = 10;
    yOffset = 30;
    /* END CONFIG */

    $("a.preview[disabled!='disabled']").hover(function (e) {
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");
        $("#preview")
            .css("top", (e.pageY - xOffset) + "px")
            .css("left", (e.pageX + yOffset) + "px")
            .fadeIn("fast");
    },
    function () {
        this.title = this.t;
        $("#preview").remove();
    });
    $("a.preview[disabled!='disabled']").mousemove(function (e) {
        $("#preview")
            .css("top", (e.pageY - xOffset) + "px")
            .css("left", (e.pageX + yOffset) + "px");
    });
};


// starting the script on page load
$(document).ready(function () {
    imagePreview();
});


function ShowPanel(panelId) {
    var panel = $('#' + panelId);
    if (panel.length == 0) return;
    panel.show();
}

function HidePanel(panelId) {
    var panel = $('#' + panelId);
    if (panel.length == 0) return;
    panel.hide();
}

function IsRadioButtonChecked(buttonId) {
    var button = $('#' + buttonId);
    if (button.length == 0) return;
    return (button.is('input:checked'));
}

function DisableControls(selector) {
    var controls = $(selector);
    if (controls.length == 0) return;
    controls.attr('disabled', 'disabled');
}

function EnableControls(selector) {
    var controls = $(selector);
    if (controls.length == 0) return;
    controls.removeAttr('disabled');
}

function selectDropDownItemByIndex(dropDownId, index) {
    var dropDown = $('#' + dropDownId);
    if (dropDown.length == 0) return;
    dropDown.attr('selectedIndex', index);
}

function getDropDownSelectedValue(dropDownId) {
    var dropDown = $('#' + dropDownId);
    if (dropDown.length == 0) return '';

    return dropDown.val();
}

function getDropDownSelectedIndex(dropDownId) {
    var dropDown = $('#' + dropDownId);
    if (dropDown.length == 0) return -1;

    return dropDown[0].selectedIndex;
}


function EnableValidator(validatorId, enable) {
    var validator = $('#' + validatorId);
    if (validator.length == 0) return;
    ValidatorEnable(validator[0], enable);
    validator[0].isValid = true;
    ValidatorUpdateDisplay(validator[0]);
}

function ValidateValidator(validatorId) {
    var validator = $('#' + validatorId);
    if (validator.length == 0) return;

    ValidatorValidate(validator[0]);
}

function setLabelText(labelId, newText) {
    var label = $('#' + labelId);
    if (label.length == 0) return;
    
    label.text(newText);
}

function setBoldStyle(elementId) {
    var elem = $('#' + elementId);
    if (elem.length == 0) return;

    elem.css('font-weight', 'bold');
}

function removeBoldStyle(elementId) {
    var elem = $('#' + elementId);
    if (elem.length == 0) return;

    if (elem.css('font-weight') == 'bold') elem.css('font-weight', '');
}

function getRadioButtonListCheckedValue(radioButtonListId) {
    var checked_radio = $('#' + radioButtonListId + ' input:radio:checked');
    if (checked_radio.length == 0) return '';

    return checked_radio.val();
}

(function ($) {
    var cache = [];
    // Arguments are image paths relative to the current page.
    $.preLoadImages = function () {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)

