/**
 * dummy function um default-settings ueberschreiben zu koennen
 */
function doNothing() {
    ;
}
 

/**
 * Function to decode HTML entities. 
 */
function decodeHtml(s) {
    if (typeof s == "string") {
        return s.replace(/&#(\d+);/g, function (wholematch, parenmatch1) {
            return String.fromCharCode(+parenmatch1);
        });
    }
    return s;
}
/**
 * Function to decode HTML ampersand. 
 */
function decodeAmpersand(s) {
    if (typeof s == "string") {
        return s.replace(/&amp;/gim, "&");
    }
    return s;
}
/**
 * Function to add on load function to on load event.
 */
function addOnload(func) {
    if (window.onload) {
        var oldOnload = window.onload;
        window.onload = function (e) {
            oldOnload(e);
            func();
        };
    } else {
        window.onload = func;
    }
}
/**
 * Function to swap between normal and hover image source.
 */
function hover(imgObj) {markAllJobs();
    var index = imgObj.src.indexOf("_hover.");
    if (index > -1) {
        imgObj.src = imgObj.src.substring(0, index) + imgObj.src.substring(index + 6);
    }
    else {
        index = imgObj.src.indexOf(".");
        imgObj.src = imgObj.src.substring(0, index) + "_hover" + imgObj.src.substring(index);
    }
}
/**
 * Function to swap between normal and focus font color.
 * Used by Internet Explorer only to substitue the CSS pseudoclass :focus.
 */
function prepareElementsForFocus(tagName) {
    var inputs = document.getElementsByTagName(tagName);
    for (var i=0; i<inputs.length; i=i+1) {
        if (!(inputs[i].tagName=="INPUT" && 
            (inputs[i].type == "submit" || inputs[i].type == "reset" || inputs[i].type == "image"))) {
            inputs[i].onfocus = function (e) {
                if (this.style) {
                    this.style.color = "#000000";
                }
            };
            inputs[i].onblur = function (e) {
                if (this.style) {
                    this.style.color = "#999999";
                }
            };
            if (inputs[i].style) {
                inputs[i].style.color = "#999999";
            }
        }
    }
}
/**
 * Function to swap between normal and focus font color of input, select and textarea.
 */
function prepareForFocus() {
    prepareElementsForFocus("INPUT");
    prepareElementsForFocus("SELECT");
    prepareElementsForFocus("TEXTAREA");
}
// addOnload(prepareForFocus);


/**
 * Function to reset the portal form submit.
 */
function cleanSubmit(id) {
    var forms = document.getElementsByTagName("FORM");
    for (var i=0; i<forms.length; i=i+1) {
        if (forms[i].id == id) {
            if (window.adfpp_originalSubmit && window.adfpp_originalSubmit[i]) {
                document.forms[i].submit = window.adfpp_originalSubmit[i];
            }
            break;
        }
    }
}
/**
 * Function to remove the portal listeners.
 */
function cleanListener(obj) {
    if (obj.tagName == "FORM" && window.adfpp_formSub) {
        cleanListenerSwitch(obj, "submit", window.adfpp_formSub, true);
    }
    else if (obj.tagName == "A" && window.adfpp_linkSub) {
        cleanListenerSwitch(obj, "click", window.adfpp_linkSub, false);
    }
    else if (obj.tagName == "INPUT" && obj.type == "submit" && window.setSubName) {
        cleanListenerSwitch(obj, "click", window.setSubName, true);
    }
}
/*
 * Function to clean listeners upon browser.
 */
function cleanListenerSwitch(obj, meth, func, capt) {
    if (obj.removeEventListener) {  // Mozilla
        obj.removeEventListener(meth, func, capt);
    }
    else if (obj.detachEvent) {     // IE
        obj.detachEvent("on" + meth, func);
    }
}

function resetLabel(name) {
    document.getElementById(name).style.color='black';
 }

function moveScrollbar(name, value) {
    var actElem = document.getElementById(name);
    if ( actElem == null ) {
        return;
    }
    actElem.scrollTop = value; // vertical scrollbar offset from top
}
    
    

function toggleChilds(name, caller) {
    var actElem = document.getElementById(name);
    var callerValue = caller.checked;
    
    for (var i = 0; i < actElem.childNodes.length; i++) {
        var actChild = actElem.childNodes[i];
        if ( actChild.type != 'checkbox' ) {
            continue;
        }
        
        actChild.checked = callerValue;
    }
}

function on(name) {
    var actElem = document.getElementById(name);
    alert('on:name=' + name + '=' + actElem);
    if ( actElem != null ) {
        actElem.disabled = false;
//        actElem.style.visibility = 'visible';
    }
}

function off(name) {
    var actElem = document.getElementById(name);
    alert('off:name=' + name + '=' + actElem);
    if ( actElem != null ) {
        actElem.disabled = true;
//        actElem.style.visibility = 'hidden';
    }
}

function cbOff(name) {
    var actElem = document.getElementById(name);
    if ( actElem.type == 'checkbox' ) {
        actElem.checked = false;
    }
}

function onoff(name) {
    var actElem = document.getElementById(name);
    var aaa = actElem.style.visibility;
    if ( aaa == 'visible' ) {
      actElem.style.visibility = 'hidden';
    } else { 
      actElem.style.visibility = 'visible';
    }
}

function onoff(name, caller) {
    var actElem = document.getElementById(name);
    var actCaller = document.getElementById(caller);
    var aaa = actElem.style.visibility;
    if ( aaa == 'visible' ) {
      actElem.style.visibility = 'hidden';
    } else { 
      actElem.style.visibility = 'visible';
      //actCaller.style.visibility = 'hidden';
      if ( actCaller != null ) {
        actElem.style.zIndex = actCaller.style.zIndex+1;
      }
    }
}

function showElement(name) {
    var actElem = document.getElementById(name);
    if ( actElem != null ) {
      actElem.style.visibility = 'visible';
    }
}

function hideElement(name) {
    var actElem = document.getElementById(name);
    if ( actElem != null ) {
      actElem.style.visibility = 'hidden';
    }
}



