﻿var isIE6 = (navigator.appVersion.indexOf("MSIE 6.") != -1 && navigator.userAgent.indexOf("Opera") == -1) ? true : false;

// Get an element's computed value.
function getStyle(oElm, strCssRule) {
    var strValue = "";
    if (document.defaultView && document.defaultView.getComputedStyle) {
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    }
    else if (oElm.currentStyle) {
        try {
            strCssRule = strCssRule.replace(/\-(\w)/g, function(strMatch, p1) {
                return p1.toUpperCase();
            });
            strValue = oElm.currentStyle[strCssRule];
        }
        catch (e) {
            // Used to prevent an error in IE 5.0
        }
    }
    return strValue;
}

// Get an ASP.NET element based off it's server ID
// This comes in handy when a control is nested in a user control
// And is prefixed with ASP.NET's hirarchial structure naming.
// Note, only works on 'normal' controls like text boxes
function GetControl(controlName) {
    var elem = document.forms[0].elements;
    var elementID = "";

    for (var i = 0; i < elem.length; i++) {
        elementID = elem[i].id;

        //alert(elementID);

        if (elementID.length >= controlName.length) {
            if (elementID.substr(elementID.length - controlName.length, elementID.length) == controlName) {
                return document.getElementById(elementID);
            }
        }
    }
}

function disableSelection(target) {
    if (typeof target.onselectstart != "undefined") //IE route
        target.onselectstart = function() { return false }
    else if (typeof target.style.MozUserSelect != "undefined") //Firefox route
        target.style.MozUserSelect = "none";
    else //All other route (ie: Opera)
        target.onmousedown = function() { return false }
    //target.style.cursor = "default";
}

// Show or hide specified element based on IsVisible boolean value
function ToggleDisplay(ElementName, IsVisible) {
    document.getElementById(ElementName).style.display = IsVisible ? "block" : "none";
}

// Show or hide specified element based on IsVisible boolean value
function ToggleVisibility(ElementName, IsVisible) {
    document.getElementById(ElementName).style.visibility = IsVisible ? "visible" : "hidden";

    if (isIE6) {
        document.getElementById(ElementName).style.display = IsVisible ? "block" : "none";
    }
    else {
        document.getElementById(ElementName).style.display = IsVisible ? "" : "none";
    }
}