﻿function IsUsingIE() {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        return true;
    } else {
        return false;
    }
        
}

function ShowPleaseWait() {
    document.body.style.cursor = "wait";
    if (document.getElementById != null) {
        document.getElementById('pleasewaitScreen').style.visibility = 'visible';
        document.getElementById('pleasewaitScreen').style.zIndex = 15;
    } else {
        if (document.all) {
            document.all.pleasewaitScreen.style.visibility = 'visible';
            document.all.pleasewaitScreen.style.zIndex = 15;
        }
    }
}
function ShowGlossaryTerm(UseTerm) {
    openRadWindow('/savi/PopUps/Glossary.aspx?term=' + UseTerm, 'PopUpGlossary');
}
function HidePleaseWait() {
    document.body.style.cursor = "default";
    if (document.getElementById != null) {
        document.getElementById('pleasewaitScreen').style.visibility = 'hidden';
        document.getElementById('pleasewaitScreen').style.zIndex = 15;
    } else {
        if (document.all) {
            document.all.pleasewaitScreen.style.visibility = 'hidden';
            document.all.pleasewaitScreen.style.zIndex = 15;
        }
    }
}
function ChangePagePic(img_name, img_src) {
    document[img_name].src = img_src;
}
function ChangeImageBorder(img_src, border_style, no_border_style) {
    {
        var images = document.getElementsByTagName("IMG");
        var numOfImages = images.length;
        for (i = 0; i < numOfImages; i++) {
            if (images[i].src == img_src) {
                if (images[i].name != 'MyOwnIcon') {
                    images[i].style.border = border_style;
                }
            }
            else {
                images[i].style.border = no_border_style;
            }
        }
    }
    }
function ShowSAVIFeedBackSurvey() {
    //window.open('/savi/PopUps/ParticipateInSurvey.aspx', 'SAVI_Feedback');
}
function GreyOutArea(elm) {

    elm = document.getElementById(elm)

    _width = elm.offsetWidth
    _height = elm.offsetHeight
    _top = elm.offsetTop
    _left = elm.offsetLeft

    overlay = document.createElement("div")
    overlay.style.width = _width + "px"
    overlay.style.height = _height + "px"
    overlay.style.position = "absolute"
    overlay.style.background = "#dedede"
    overlay.style.top = _top + "px"
    overlay.style.left = _left + "px"

    overlay.style.filter = "alpha(opacity=50)"
    overlay.style.opacity = "0.5"
    overlay.style.mozOpacity = "0.5"

    document.getElementsByTagName("body")[0].appendChild(overlay)
}
function WidenComboBox(cbBox, AdjustWidth) {
    if (cbBox.style.width != AdjustWidth)
	{
	    cbBox.style.width = AdjustWidth;
	}
    //cbBox.style.zIndex = '1';
}
function replaceAll(txt, replace, with_this) {
    return txt.replace(new RegExp(replace, 'g'), with_this);
}
function GetIndexOf(TheArray, TheVal) {
    var j = -1;
    for (var i = 0; i < TheArray.length; i++) {
        if (TheArray[i] == TheVal) {
            j = i;
            return j;
        }
    }
    return j;
}
function TranslateBGLabel(FullLabel) {
    FullLabel = Mid(FullLabel, 5, FullLabel.length);
    var Set1;
    var Set2;
    var Set3;
    Set1 = Mid(FullLabel, 0, 4);
    Set2 = Mid(FullLabel, 4, 2);
    Set3 = Mid(FullLabel, 6, 1);
    return Set1 + '.' + Set2 + '.' + Set3;
}
function TranslateTRACTLabel(FullLabel) {
    FullLabel = Mid(FullLabel, 5, FullLabel.length);
    var Set1;
    var Set2;
    Set1 = Mid(FullLabel, 0, 4);
    Set2 = Mid(FullLabel, 4, 2);
    return Set1 + '.' + Set2;
}
function Mid(str, start, len) {
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
        iEnd = iLen;
    else
        iEnd = start + len;
    return String(str).substring(start, iEnd);
}
function changeClass(Elem, myClass) {
    var elem;
    if (document.getElementById) {
        elem = document.getElementById(Elem);
    } else if (document.all) {
        elem = document.all[Elem];
    }
    elem.className = myClass;
}
function InStr(strSearch, charSearchFor) {
    return strSearch.indexOf(charSearchFor)
}
function OnEnterKey(ButtonControl) {
    if (window.event.keyCode == 13) {
        ButtonControl.focus();
    }
}
function CheckAllCheckBoxes(CheckBoxList) {
    for (i = 0; i < CheckBoxList.length; i++)
        CheckBoxList[i].checked = true;
}
function UnCheckAllCheckBoxes(CheckBoxList) {
    for (i = 0; i < CheckBoxList.length; i++)
        CheckBoxList[i].checked = false;
}
function ChangeElementToPassword(e) {
    var input = document.getElementById(e);
    var input2 = input.cloneNode(false);
    input2.type = 'password';
    input.parentNode.replaceChild(input2, input);
    input2.focus();
    input2.focus();
    }
