function areYouSure()
{
    return confirm(webtext['are_you_sure']);
}

function objectExists(objName)
{
    var obj = document.getElementById(objName);
    return (obj != null);

}

function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return a === null;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
}

function invertCheckbox(cbxName)
{
    var cbx = document.getElementById(cbxName);
    cbx.checked = !cbx.checked;
}

/**
 * JS vardump version
 */
var MAX_DUMP_DEPTH = 10;
function dumpObj(obj, name, indent, depth)
{
    if (depth > MAX_DUMP_DEPTH) {
        return indent + name + ": <Maximum Depth Reached>\n";
    }
    if (typeof obj == "object") {
        var child = null;
        var output = indent + name + "\n";
        indent += "\t";
        for (var item in obj)
        {
            try {
                child = obj[item];
            } catch (e) {
                child = "<Unable to Evaluate>";
            }
            if (typeof child == "object") {
                output += dumpObj(child, item, indent, depth + 1);
            } else {
                output += indent + item + ": " + child + "\n";
            }
        }
        return output;
    } else {
        return obj;
    }
}

/**
 * Return the current value (or selected value) of the
 * input field... The field can be of type radio, select,
 * input or textarea. Return null if value is not found.
 */
function getInputValue(inputObj)
{
    if (inputObj.type == 'select-one') {  // select box
        return inputObj.options[inputObj.selectedIndex].value;
    }
    else if (inputObj.length) {  // radio buttons
        return getRadioValue(inputObj);
    }
    else {
        return inputObj.value;
    }
    return null;
}

/**
 * Return the selected value from a group of radio
 * buttons. 'radioObj' should be a radio button object.
 */
function getRadioValue(radioObj)
{
    for (var i = 0; i < radioObj.length; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return null;
}

/*function getRadioValue(radio)
{
alert(typeof radio.constructor);
    if (!isObject(radio)) {
        return radio.value;
    }
alert('2');
    for (i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            return radio[i].value;
        }
    }
    return null;
}*/

function isInteger(str)
{
    if (str.length == 0) {
        return false;
    }
    var checkOK = '0123456789';
    var allNum = true;
    for (i = 0;  i < str.length;  i++) {
        ch = str.charAt(i);
        for (j = 0; j < checkOK.length; j++) {
            if (ch == checkOK.charAt(j)) {
                break;
            }
        }
        if (j == checkOK.length) {
            allNum = false;
            break;
        }
    }
    return allNum;
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{ // design & code by 3SIGN  http://www.3sign.be
   var obj = document.layers ? document.layers[szDivID] :
   document.getElementById ?  document.getElementById(szDivID).style :
   document.all[szDivID].style;
   obj.visibility = document.layers ? (iState ? "show" : "hide") :
   (iState ? "visible" : "hidden");
}

function loadingDialog(bEnabled)
{
  var dtObj=document.getElementById("loadingTextBox");
  if(dtObj!=null){document.body.removeChild(dtObj);}
  var dfObj=document.getElementById("loadingFumeBox");
  if(dfObj!=null){document.body.removeChild(dfObj);}
  if(bEnabled){
    dfObj=document.createElement("DIV");
    dfObj.setAttribute("id","loadingFumeBox");
    var pageH=(document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
    dfObj.setAttribute("style","position:absolute;left:0;top:0px;width:100%;height:"+pageH+"px;border:0;background:#000000;opacity:.3;filter:alpha(opacity=30);z-index:100;");
    document.body.appendChild(dfObj);
    dtObj=document.createElement("DIV");
    dtObj.setAttribute("id","loadingTextBox");
    var top=(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
    top+=Math.round(window.innerHeight/2)-12;
    dtObj.setAttribute("style","position:absolute;left:40%;right:40%;top:"+top+"px;text-align:center;border:1px solid #000000;-moz-border-radius:10px;background:#EEEEEE;font-family:Arial,Verdana,sans-serif;font-size:18px;font-weight:bold;text-transform:capitalize;font-variant:small-caps;color:#000000;opacity:.9;filter:alpha(opacity=90);z-index:101;");
    var tObj=document.createTextNode("Loading...");
    dtObj.appendChild(tObj);
    document.body.appendChild(dtObj);
  }
}

function Popup(url, w, h)
{
    x = ((screen.availWidth / 2) - (w / 2));
    y = ((screen.availHeight / 2) - (h / 2));
    var myWin = null;
    uploadPopup = window.open ('', 'myPopup', 'menubar=no,scrollbars=yes,resizable=no,status=no,width=' + w + ',height=' + h + ',screenX=0,screenY=0,top=' + y + ',left=' + x);
    uploadPopup.focus();
    if (uploadPopup != null) {
        if (uploadPopup.opener == null) {
            uploadPopup.opener = self;
        }
        uploadPopup.location.href = url;
    }
}

function checkMail(email)
{
    var x = email;
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(x)) {
        return true;
    } else {
        return false;
    };
}

// 1 visible, 0 hidden
function setVisibility(szDivID, iState)
{
    var obj = document.layers ? document.layers[szDivID]
                              : document.getElementById ? document.getElementById(szDivID).style
                                                        : document.all[szDivID].style;
    if (obj != null) {
        var oldState = document.layers ? (obj.visibility == "show")
                                       : (obj.visibility == "visible");
        if (oldState != iState) {
            obj.visibility = document.layers ? (iState ? "show"    : "hide")
                                             : (iState ? "visible" : "hidden");
            obj.display = (iState ? "block" : "none");
            return true;
        }
    }
    return false;
}

// 1 visible, 0 hidden
function toggleVisibility(szDivID)
{
    var obj = document.layers ? document.layers[szDivID]
                              : document.getElementById ? document.getElementById(szDivID).style
                                                        : document.all[szDivID].style;
    var current = ((obj.visibility == 'show') || (obj.visibility == 'visible'));
    obj.visibility = document.layers ? (!current ? "show"    : "hide")
                                     : (!current ? "visible" : "hidden");
    obj.display = (!current ? "block" : "none");
}

// sets the text of an object
function setText(szDivID, text)
{
    var obj = document.layers ? document.layers[szDivID]
                              : document.getElementById ? document.getElementById(szDivID)
                                                     : document.all[szDivID];
    obj.innerHTML = text;
}

function setScrollPosition(x, y)
{
    window.scrollTo(x, y);
}

function Viewport()
{
    this.windowX = window.innerWidth;
    this.windowY = window.innerHeight;
    this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
    this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
    this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
    this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;

    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

