// JScript File
    var state = 'hidden';
    
    function getItem(layer_ref)
    {
    
        if (document.getElementById) {
            return document.getElementById(layer_ref);
        }
        else if (document.all) { //IS IE 4 or 5 (or 6 beta)
            return eval( "document.all." + layer_ref);
        }
        else if (document.layers) { //IS NETSCAPE 4 or below
            return document.layers[layer_ref];
        }
    
    }
    
    function showhide(layer_ref, arg) 
    {
        if (arg == null){
            if (state == 'visible') {
                state = 'hidden';
            }
            else {
                state = 'visible';
            }
        }
        else if (arg == 'show') {state = 'visible';}
        else if (arg == 'hide') {state = 'hidden';}

        if (document.getElementById) {
            var maxwell_smart = document.getElementById(layer_ref);
            maxwell_smart.style.visibility = state;
        }
        else if (document.all) { //IS IE 4 or 5 (or 6 beta)
            eval( "document.all." + layer_ref + ".style.visibility = state");
        }
        else if (document.layers) { //IS NETSCAPE 4 or below
            document.layers[layer_ref].visibility = state;
        }
    }
    function display(layer_ref, arg) 
    {
        if (arg == null){
            state = getItem(layer_ref).style.display;
            if (state == 'block') {
                state = 'none';
            }
            else {
                state = 'block';
            }
        }
        else if (arg == 'show') {state = 'block';}
        else if (arg == 'hide') {state = 'none';}
        else if (arg === true) {state = 'block';}
        else if (arg === false) {state = 'none';}

        if (document.getElementById) {
            var maxwell_smart = document.getElementById(layer_ref);
            maxwell_smart.style.display = state;
        }
        else if (document.all) { //IS IE 4 or 5 (or 6 beta)
            eval( "document.all." + layer_ref + ".style.display = state");
        }
        else if (document.layers) { //IS NETSCAPE 4 or below
            document.layers[layer_ref].display = state;
        }
    }

    // sets the index v on listbox s
    function setSelectedIndex(s, v) {
        for ( var i = 0; i < s.options.length; i++ ) {
            if ( s.options[i].value == v ) {
                s.options[i].selected = true;
                return;
            }
        }
    }
    
    /* colors the specified item to have red letter color */
    function setFontToColor(layer_ref, color){
        if (color == '' || color == null || color == undefined) color = 'Red';
        getItem(layer_ref).style.color = color;
    }
    
    function disable(item, value){
        if (item === undefined || item === null){
            return;
        }
/*
//        if (item.disabled != undefined){
//            if (!item.neverDisable){
//                item.disabled = value;
//            }
//        }
*/
        if (item.tagName != undefined && 
            (item.tagName == 'BUTTON' 
            || item.tagName == 'INPUT'
            || item.tagName == 'OPTGROUP'
            || item.tagName == 'OPTION'
            || item.tagName == 'SELECT'
            || item.tagName == 'TEXTAREA')){
            if (!item.neverDisable){
                item.disabled = value;
            }
        }
        else {
            if (item.childNodes){
                var childNr;
                for(childNr = 0; childNr < item.childNodes.length; childNr++){
                    disable(item.childNodes[childNr], value);
                }
            }
        }
    }

    /*sets the text v on listbox s*/
    function setSelectedText(s, v) {
        for ( var i = 0; i < s.options.length; i++ ) {
            if ( s.options[i].text == v ) {
                s.options[i].selected = true;
                return;
            }
        }
    }
    
    function trim(str){
        return str.replace(/^\s+|\s+$/g, '');
    }
    

    
    function hideColumn(columnNum, tableHtmlId, value)
    {
        /*col_num = document.getElementById("column_numbder").value;*/
        col_num = columnNum;
        rows = document.getElementById(tableHtmlId).rows;
        for(i=0;i <rows.length;i++){
            if (value == "block" || value == "none") {
                rows[i].cells[col_num].style.display = value;
            } else {
                rows[i].cells[col_num].style.display = (rows[i].cells[col_num].style.display == "none") ? "block" : "none";
            }
        }
    }

    function myCustomCleanup(type, value) 
    {   
        if (type == "insert_to_editor") {
            value = HTMLDecode(value);
        }
        return value; 
    }
    
    function myCustomSaveContent(element_id, html, body) {
        return HTMLEncode(html); 
    }

    function HTMLEncode(text){
        var html = text;
        html= html.replace(/&/gi,"&amp;");
        html= html.replace(/</gi,"&lt;");
        html= html.replace(/>/gi,"&gt;");
        html= html.replace(/\""/gi,"&quot;");
        return html; 
    }

    function HTMLDecode(text){
        var value = text;
        value = value.replace(/&lt;/gi,"<");
        value = value.replace(/&gt;/gi,">");
        value = value.replace(/&quot;/gi,"\"");
        value = value.replace(/&amp;/gi,"&");
        return value;
    }

    /* Creates a popup window
     * -> text: the text to show in the popup
    */
    function showPopUp(text) {
        var popup = $j('<div></div>')
            .addClass('JSPopupBoxStyle')
            .width(document.documentElement.clientWidth)
            .height(document.documentElement.clientHeight)
            .css({ "position": "absolute" })
            .get(0);
        var popupContent = $j('<div></div>')
            .addClass('JSPopupBoxInnerStyle')
            .html(text)
            .appendTo(popup);
        var butt = $j('<input type="submit"></input>')
            .attr('value', 'Ok')
            .click(function() {
                popup.style.display = 'none';
                document.body.removeChild(popup);
            })
            .appendTo(popup);
        document.body.appendChild(popup);
    }
    
    


    function initTinyMCE(){
        if (tinyMCE){
            tinyMCE.init({
                /* General options */
                mode : "exact",
                theme : "advanced",
                encoding : "xml",
                plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                
                /* Theme options */
                theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
                theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
                theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
                theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,blockquote,pagebreak,|,insertfile,insertimage",
                theme_advanced_toolbar_location : "top",
                theme_advanced_toolbar_align : "left",
                theme_advanced_statusbar_location : "bottom",
                theme_advanced_resizing: true,
                entity_encoding: "raw",

                /* Example content CSS (should be your site CSS) */
                content_css : "css/example.css",

                /* Drop lists for link/image/media/template dialogs */
                template_external_list_url : "js/template_list.js",
                external_link_list_url : "js/link_list.js",
                external_image_list_url : "js/image_list.js",
                media_external_list_url : "js/media_list.js"
                
                /* for partial postback cleanup
                cleanup_callback : "myCustomCleanup",
                save_callback : "myCustomSaveContent", */

            });
        }
    } 
    
    Date.prototype.printTime = function (format){
        var result = ((this.getHours() < 10) ? '0' : '') + this.getHours() 
            + ':' + ((this.getMinutes() < 10) ? '0' : '') + this.getMinutes();
        if (format == 'hms')
            result += ':' + ((this.getSeconds() < 10) ? '0' : '') + this.getSeconds();
        return result;
    };


    /*    Session expiration functions!    */

    var SessionExpiryTime = new Date();

    function setSessionExpiryTime(milliseconds) {
        SessionExpiryTime = new Date(new Date().getTime() + milliseconds);
    }

    function showSessionExpiryAlert(warningtext, warninglength, timeouttext, isWarning) {
        var now = new Date();
        if (now >= SessionExpiryTime) {
            if (isWarning) {
                setSessionExpiryTime(warninglength);
                //alert(warningtext);
                var now2 = new Date();
                if (now2 >= SessionExpiryTime) {
                    //alert(timeouttext);
                } else {
                    window.setTimeout('showSessionExpiryAlert("' + warningtext + '", ' + warninglength + ', "' + timeouttext + '", false);', SessionExpiryTime.getTime() - now2.getTime());
                }
            }
            else {
                //alert(timeouttext);
            }
        } else {
            window.setTimeout('showSessionExpiryAlert("' + warningtext + '", ' + warninglength + ', "' + timeouttext + '", true);', SessionExpiryTime.getTime() - now.getTime());
        }
    }
    
    
    
