﻿// ------------------------ help clicked therefore show help ----------------------------- //
function Show(id) {
    if (!document.getElementsByTagName) return

    closeExisting(id);

    var div = document.getElementById(id);
    if (div.style.display == 'block') {
        div.style.display = 'none'
    }
    else {
        div.style.display = 'block';
    }
}

function closeExisting(id) {
    var allDivs = document.getElementsByTagName("div");
    var len = allDivs.length;

    for (var x = 0; x < len; x++) {
        var singleDiv = allDivs[x];
        if (singleDiv.className == 'Help' && singleDiv.style.display == 'block' && singleDiv.id != id) {
            singleDiv.style.display = 'none';
        }
    }
}
// ----------------------------------------------------------------------------- //

function Hover(control, className) {
    if (control.className) {
        control.className = className;
    }
}

// ----------------------------- hide help --------------------------------- //
function Hide(id) {
    if (document.getElementById) {
        document.getElementById(id).style.display = 'none'
    }
}

// ----------------------------------------------------------------------------- //

// --------------------- borders for text type inputs ------------------------------ //
function AttachBorderAndSelect(id) {
    var obj0 = document.getElementById(id)

    obj0.onfocus = function() {
        this.style.border = "1px solid #f00";
        this.select();
    }

    obj0.onblur = function() {
        this.style.border = "1px solid #c1c1c1"
        if (this.value == "") {
            this.value = this.defaultValue
        }
        this.value = this.value
    }
}
// ----------------------------------------------------------------------------- //

// -------------------------- borders for radio and checkboxes ------------------------- //
function AttachBorderToRadio(id) {
    var obj0 = document.getElementById(id)
    obj0.onfocus = function() {
        this.style.border = "1px solid #f00"
    }
    obj0.onblur = function() {
        this.style.border = "1px solid #fff"
    }
}
// ----------------------------------------------------------------------------- //
function AttachBorderToSelectList(id) {
    var obj0 = document.getElementById(id)
    obj0.onfocus = function() {
        this.parentNode.style.border = "1px solid #f00"
    }
    obj0.onblur = function() {
        this.parentNode.style.border = "1px solid #fff"
    }
}
// ------------------------------ border for submit buttons --------------------------- //
function AttachBorderToButton(id) {
    var obj0 = document.getElementById(id)
    obj0.onfocus = function() {
        this.style.border = "1px solid #f00"
    }
    obj0.onblur = function() {
        this.style.border = "1px solid #c1c1c1"
    }
}
// ----------------------------------------------------------------------------- //

function ClearTextbox(control, message) {
    if (control.value == message)
        control.value = "";
}

function RestoreTextbox(control, message) {
    if (control.value == "")
        control.value = message;
}

function FocusIn(id) {
    var text = document.getElementById(id);
    text.focus();
}

function ToggleCheckboxes(cbID, offset, total, uncheckAllButThisOne) {
    if (uncheckAllButThisOne) {
        for (var i = 0; i < total; i++) {
            var cb = document.getElementById(cbID + '_' + i);
            if (cb && offset != i) cb.checked = false;
        }
    }
    else {
        var cb = document.getElementById(cbID + '_' + offset);
        if (cb) cb.checked = false;
    }
}
