// determine browser
isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;

// select named object
function selectObjectById(objectId) {
    if (isIE)
        return eval('document.all.' + objectId);
    else if (isNN)
        return document.getElementById(objectId);
    else
        return eval('document.' + objectId);
}

// show specified object
function showObjectById(objectId) {
    if (isIE||isNN)
        selectObjectById(objectId).style.visibility="visible";
    else if (isN4)
        selectObjectById(objectId).visibility="show";
}

// hide specified object
function hideObjectById(objectId) {
    if (isIE||isNN)
        selectObjectById(objectId).style.visibility="hidden";
    else if (isN4)
        selectObjectById(objectId).visibility="hide";
}

// selected item support
function setSelcted(optionList, selectedValue) {
    setSelctedValue(optionList, selectedValue.value);
}

// selected item support
function setSelctedValue(optionList, selectedValue) {
    for(var i=0; i<optionList.options.length; i++)
        if (optionList.options[i].value == selectedValue)
            optionList.options[i].selected = true;
}

// selected item support
function setSelctedText(optionList, selectedText) {
    setSelctedTextValue(optionList, selectedText.value);
}

// selected item support
function setSelctedTextValue(optionList, selectedText) {
    for(var i=0; i<optionList.options.length; i++)
        if (optionList.options[i].text == selectedText)
            optionList.options[i].selected = true;
}

// selected item support
function getSelctedValue(optionList, selectedValue) {
    if (optionList.selectedIndex < 0)
        selectedValue.value = '';
    else
        selectedValue.value =
                optionList.options[optionList.selectedIndex].value;
}

// selected item support
function getSelctedText(optionList, selectedText) {
    if (optionList.selectedIndex < 0)
        selectedText.value = '';
    else
        selectedText.value =
                optionList.options[optionList.selectedIndex].text;
}

function addOption(optionList, optionValue, optionText) {
    var newOption = document.createElement('option');
    newOption.text = optionText;
    newOption.value = optionValue;
    try {
      optionList.add(newOption, optionList.options[0]); // standards compliant; doesn't work in IE
    }
    catch(ex) {
      optionList.add(newOption, 0); // IE only
    }
}

// traslate JS text to HTML text
function toHtmlText(jsText) {
    var htmlText = jsText.replace(/</gi, '&lt;');
    htmlText = htmlText.replace(/>/gi, '&gt;');
    htmlText = htmlText.replace(/\r\n/gi, '<br>');
    htmlText = htmlText.replace(/\n/gi, '<br>');
    htmlText = htmlText.replace(/\\n/gi, '<br>');
    htmlText = htmlText.replace(/\r/gi, ' ');
    htmlText = htmlText.replace(/\f/gi, ' ');
    htmlText = htmlText.replace(/  /gi, '&nbsp;&nbsp;');
    return htmlText;
}

// selected item support
function toJavaScriptText(htmlText) {
    var jsText = htmlText;
    jsText.replace(/&lt;/gi, '<');
    jsText.replace(/&gt;/gi, '>');
    jsText.replace(/<br>/gi, '\\r\\n');
    jsText.replace(/&nbsp;&nbsp;/gi, '  ');
    return jsText;
}