﻿var blnBubble = false; //--- Tree bubble up

// Defense - No try, catch and final in library (sh...)
//--- Window
function refresh() {
    window.location = window.location;
}
function refreshParent() {
    parent.window.location = parent.window.location;
}
function refreshDelayed() {
    setTimeout('refresh()', 200);
}
function refreshDelayedParent() {
    setTimeout('refreshParent()', 200);
}
function redirect(strUrl, strKey) {
    if (!isNOE(strKey)) { strUrl = strUrl + '&pk0=' + getText(strKey); }
    if (!blnBubble) { window.location = strUrl.replace('&amp;', '&'); }
    blnBubble = true;
    setTimeout("blnBubble = false", 200);
}
function redirectCalendar(ddlYear, ddlMonth) {
    window.location = window.location.pathname + '?yr=' + ddlYear.value + '&mt=' + ddlMonth.value;
}
//--- Element
function elmNew(strType, strId, strValue) {
    var elmObj = document.createElement(strType);
    elmObj.setAttribute('id', strId);
    elmObj.setAttribute('value', strValue);
    return elmObj;
}
function getElement(elmObj, strPrefix) {
    //--- Ut 2008.10.06 *Dc*
    if (!elmObj) { return ''; } //--- Defense
    if (isNOE(getId(elmObj))) { return ''; } //--- Defense
    elmObj = document.getElementById(getId(elmObj).replace(getId(elmObj).substring(0, 3), strPrefix));
    if (elmObj) { return elmObj; } //--- Defense
}
//--- Id
function getId(elmObj) {
    //--- Ut 2008.10.06 *Dc*
    if (!elmObj) { return ''; } //--- Defense
    if (isNOE(elmObj.id)) { return ''; } //--- Defense
    if (!isNOE(elmObj.name)) { return elmObj.name; } //--- Rdo
    return elmObj.id;
}
//--- Value
function setRadio(strKey) {
    $('input:radio').attr('checked', false);
    document.getElementById(strKey).checked = true;
}
function setChecked(elmObj, strValue) {
    if (!elmObj) { return ''; } //--- Defense
    elmObj.value = strValue;
}
function getChecked(elmObj) {
    if (!elmObj) { return ''; } //--- Defense
    return elmObj.checked;
}
function setText(strKey, strValue) {
    setValue(document.getElementById(strKey), strValue);
}
function getText(strKey) {
    var elmObj = document.getElementById(strKey);
    if (!elmObj) { return ''; } //--- Defense
    if (isNOE(elmObj.value)) { return ''; } //--- Defense
    return elmObj.value;
}
function setValue(elmObj, strValue) {
    if (!elmObj) { return ''; } //--- Defense
    elmObj.value = strValue;
}
function getValue(elmObj) {
    if (!elmObj) { return ''; } //--- Defense
    if (isNOE(elmObj.value)) { return ''; } //--- Defense
    return elmObj.value;
}
function setInnerHTML(elmObj, strInnerHTML) {
    if (!elmObj) { return ''; } //--- Defense
    elmObj.innerHTML = strInnerHTML;
}
function getInnerHTML(elmObj) {
    if (!elmObj) { return ''; } //--- Defense
    if (isNOE(elmObj.innerHTML)) { return ''; } //--- Defense
    return elmObj.innerHTML;
}
function setSrc(elmObj, strSrc) {
    if (!elmObj) { return ''; } //--- Defense
    elmObj.src = strSrc;
}
function getSrc(elmObj) {
    if (!elmObj) { return ''; } //--- Defense
    return elmObj.src;
}
function setClassName(elmObj, strClassName) {
    if (!elmObj) { return ''; } //--- Defense
    elmObj.className = strClassName;
}
function getClassName(elmObj) {
    if (!elmObj) { return ''; } //--- Defense
    return elmObj.className;
}
function getNodeName(elmObj) {
    if (!elmObj) { return ''; } //--- Defense
    return elmObj.nodeName;
}
function getDisplay(elmObj) {
    if (elmObj.display) { return elmObj.display }
    if (elmObj.style.display) { return elmObj.style.display }
    if (elmObj.currentStyle.display) { return elmObj.currentStyle.display }
}
function setToogle(elmObj, strDisplay) {
    var strEvent = objTest.addEvent('setToogle(' + getId(elmObj) + ',' + strDisplay + ')');
    if (isNOE(strDisplay)) {
        if (getDisplay(elmObj) == 'block') {
            strDisplay = 'none';
        } else {
            strDisplay = 'block';
        }
    }
    elmObj.style.display = strDisplay
}
function resizeChild(strKey, strSrc, intPad) {
    try {
        var elmFrames = parent.document.getElementsByTagName('iframe');
        for (var intIdx = 0; intIdx < elmFrames.length; intIdx++) {
            if (elmFrames[intIdx].src.indexOf(strSrc) > -1) {
                document.getElementById(strKey).style.height = (elmFrames[intIdx].parentElement.style.height.replace('px', '') - intPad) + 'px';
                document.getElementById(strKey).style.width = (elmFrames[intIdx].parentElement.style.width.replace('px', '') - intPad) + 'px';
            }
        }
    } catch (err) {}
} 
//--- Date time
function Close(tdDate) {
    var strDate = '#' + tdDate.id.replace('td', 'div');
    $(strDate).dialog('close');
}
function addDays(datValue, days) {
    if (isNOE(strValue)) { return ''; } //--- Defense
    datValue.setTime(datValue.getTime() + (24 * 60 * 60 * 1000));
    return datValue
}
function checkTime(strValue) {
    if (isNOE(strValue)) { return '12:00 pm'; }
    return strValue;
}
function checkDate(strValue) {
    if (isNOE(strValue)) { return new Date().toMMDDYYYY(); }
    return strValue;
}
//--- String
function trim(strValue) {
    if (isNOE(strValue)) { return ''; } //--- Defense
    return replaceAll(strValue, /^\s+|\s+$/g, '');
}
function replaceAll(strValue, strOld, strNew) {
    if (isNOE(strValue)) { return ''; } //--- Defense
    return strValue.split(strOld).join(strNew);
    //return replaceAll(this, new RegExp('\\' + strOld, 'gi'), strNew);
}
//--- Glyph - try - return escape(strValue); return unescape(strValue);
function enGlyph(strValue) {
    if (isNOE(strValue)) { return ''; } //--- Defense
    strValue = replaceAll(strValue, '\t', '#009;');
    strValue = replaceAll(strValue, '\n', '#010;');
    strValue = replaceAll(strValue, '\r', '#013;');
    strValue = replaceAll(strValue, '"', '#034;');
    strValue = replaceAll(strValue, '&', '#038;');
    strValue = replaceAll(strValue, "'", '#039;');
    strValue = replaceAll(strValue, ',', '#044;');
    strValue = replaceAll(strValue, '<', '#060;');
    strValue = replaceAll(strValue, '=', '#061;');
    strValue = replaceAll(strValue, '>', '#062;');
    strValue = replaceAll(strValue, '?', '#063;');
    return replaceAll(strValue, '@', '#064;');
}
function deGlyph(strValue) {
    if (isNOE(strValue)) { return ''; } //--- Defense
    strValue = replaceAll(strValue, '#009;', '\t');
    strValue = replaceAll(strValue, '#010;', '\n');
    strValue = replaceAll(strValue, '#013;', '\r');
    strValue = replaceAll(strValue, '#034;', '"');
    strValue = replaceAll(strValue, '#038;', '&');
    strValue = replaceAll(strValue, '#039;', "'");
    strValue = replaceAll(strValue, '#044;', ',');
    strValue = replaceAll(strValue, '#060;', '<');
    strValue = replaceAll(strValue, '#061;', '=');
    strValue = replaceAll(strValue, '#062;', '>');
    strValue = replaceAll(strValue, '#063;', '?');
    strValue = replaceAll(strValue, '#064;', '@');
    strValue = replaceAll(strValue, '&amp;', '&');
    strValue = replaceAll(strValue, '&lt;', '<');
    strValue = replaceAll(strValue, '&gt;', '>');
    return replaceAll(strValue, '&nbsp;', ' ');
}
//--- Char
function isNOE(strValue) { 
    if (strValue == undefined) { return true; }
    if (strValue == '') { return true; }
    return false
}
function isNothing(strId) { 
    if (isNOE(strId)) { return true; }
    if (!document.getElementById(strId)) { return true; }
    return false
}
function isNumber(intCharCode, blnAlt, blnCtrl, blnShift) {
    return ((intCharCode >= 48 && intCharCode <= 57)
        && (!blnAlt && !blnCtrl && !blnShift))
}
function isAlpha(intCharCode, blnAlt, blnCtrl, blnShift) {
    return ((intCharCode >= 65 && intCharCode <= 90)
        || (intCharCode >= 97 && intCharCode <= 122)
        && (!blnAlt && !blnCtrl))
}
function isSpecial(intCharCode, blnAlt, blnCtrl, blnShift) {
    return ((intCharCode >= 33 && intCharCode <= 47)
        || (intCharCode >= 58 && intCharCode <= 64)
        || (intCharCode >= 91 && intCharCode <= 96)
        || (intCharCode >= 123 && intCharCode <= 126)
        && (!blnAlt && !blnCtrl))
}
function isChange(intCharCode, blnAlt, blnCtrl, blnShift) {
    return ((intCharCode == 8 || intCharCode == 9 //--- Backspace, tab
        || intCharCode == 13 || intCharCode == 127)
        && (!blnAlt && !blnCtrl && !blnShift))
}
function toUpper(intCharCode) {
    if (intCharCode >= 97 && intCharCode <= 122) { return intCharCode - 32; }
    return intCharCode;
}
function toLower(intCharCode) {
    if (intCharCode >= 65 && intCharCode <= 90) { return intCharCode + 32; }
    return intCharCode;
}
function getURLParam(strKey) {
    var aryQuery = window.location.href.split(strKey + "=");
    if (aryQuery.length > 0) {
        var intIdx = aryQuery[1].indexOf("?");
        if (intIdx < 0) { intIdx = aryQuery[1].length; }
        return unescape(aryQuery[1].substring(0, intIdx));
    }
}
function getCharCode(objEvent) {
    return (objEvent.charCode) ? objEvent.charCode : ((objEvent.keyCode) ? objEvent.keyCode : ((objEvent.which) ? objEvent.which : 0));
}
//--- Continue
function getContinue(blnCheck, strMessage) {
    var blnContinue = true;
    if (blnCheck) { blnContinue = confirm(strMessage); }
    return blnContinue;
}
//--- Style
function setStyle() {
}
function getStyle() {
}
//--- Get position
function getBodyHeight() {
    if (blnIe) {
        return document.getElementById('divFadDOS').offsetHeight; /* no ie7 document.body.offsetHeight; /* ie8 ff */
    } else {
        return document.getElementById('divFadDOS').offsetHeight; /* ff */
    }
}
function getBodyWidth() {
    if (blnIe) {
        return document.body.offsetWidth; /* ie8 ff */
    } else {
        return document.getElementById('divFadDOS').offsetWidth; /* ff */
    }
}
function getPosY(elmObj) {
    if (!elmObj) { return ''; }
    var intPosY = elmObj.offsetTop;
    elmParent = elmObj.parentNode;
    while (elmParent.offsetParent) {
        intPosY += elmParent.offsetTop;
        elmParent = elmParent.offsetParent;
    }
    return intPosY;
}
function getPosX(elmObj) {
    if (!elmObj) { return ''; }
    var intPosX = elmObj.offsetLeft;
    elmParent = elmObj.parentNode;
    while (elmParent.offsetParent) {
        intPosX += elmParent.offsetLeft;
        elmParent = elmParent.offsetParent;
    }
    return intPosX;
}
function setCenter(elmObj) {
    if (!elmObj) { return ''; }
    elmObj.style.top = Math.abs((((getBodyHeight() - elmObj.offsetHeight) / (getBodyHeight() / 100))) / 2) + '%'; // ff likes %
    elmObj.style.left = Math.abs((((getBodyWidth() - elmObj.offsetWidth) / (getBodyWidth() / 100))) / 2) + '%';
}
function getHeight(elmObj) {
    if (!elmObj) { return ''; }
    if (elmObj.parentNode.offsetHeight) { return elmObj.parentNode.offsetHeight; } //--- Defense
    if (elmObj.parentNode.clientHeight) { return elmObj.parentNode.clientHeight; } //--- Defense
}
function setTop(elmObj, strTop) {
    if (!elmObj) { return ''; }
    if (isNOE(strTop)) { strTop = '0' } //--- Defense
    if (blnIx) {
        elmObj.style.top = strTop + 'px' //--- (ie7)
    } else {
        elmObj.style.top = strTop + 'px'
    }
}
function setLeft(elmObj, strLeft) {
    if (!elmObj) { return ''; }
    elmObj.style.left = strLeft + 'px'
}

