

var ActiveBrowser                       = new Browser();
var ActiveMenu                          = null;
var LastBorderId                        = null;
var LastBorderStyle                     = null;


function SetCookie(Name, Value, Days) {
    var e = '';
	if (Days) {
		var date = new Date();
		date.setTime(date.getTime() + (Days*24*60*60*1000));
		e = '; expires=' + date.toGMTString();
	}
	document.cookie = Name + '=' + escape(Value) + e;
}
function GetCookie(Name) {
	var n = Name + '=';
	var c = document.cookie.split(';');
	for(var i=0; i < c.length; i++) {
		var e = c[i];
		while (e.charAt(0) == ' ') e = e.substring(1, e.length);
		if (e.indexOf(n) == 0) return e.substring(n.length, e.length);
	}
	return null;
}
function RemoveCookie(Name) {
	SetCookie(name, ' ', -1);
}
function SetStr(Text, Search, Value) {
    //alert(Text + ', ' + Search + ', ' + Value);
    var counter = 0;
    var start = 0;
    var before = '';
    var after = '';
    while (Text.length) {
        start = Text.indexOf(Search, counter);
        if (start == -1) {
            break;
        } else {
            before = Text.substr(0, start);
            after = Text.substr(start + Search.length, Text.length);
            Text = before + Value + after;
            counter = before.length + Value.length;
        }
    }
    //alert('After Replace: ' + Text);
    return Text;
}
function GetStr(text, start, stop, def) {
    start   = start || '';
    stop    = stop  || '';
    def     = def   || '-';
    var k = -1;

    if ((start == '') && (stop == '')) {
        alert('CRITICAL: Neither start nor stop in GetStr for "' + text + '".');

    } else if (stop == '') {
        k = text.indexOf(start);
        if (k == -1) {
            if (def == '-') return '';
            return def; //'START no, END null';
        }
        return text.substr(k + start.length);

    } else if (start == '') {
        k = text.indexOf(stop);
        if (k == -1) {
            if (def == '-') return text;
            return def; // 'START null, END no';
        }
        return text.substr(0, k);

    } else {
        k = text.indexOf(start);
        if (k == -1) { // 'START no, END ?';
            if (def == '-') return '';
            return def;
        }
        //k = k + start.length;
        text = text.substr(k + start.length);
        //alert('NewText:' + text + ', Stop:' + stop + '.');

        k = text.indexOf(stop);
        if (k == -1) { // 'START yes, END no';
            if (def == '-') return text;
            return def;
        }
        return text.substr(0, k);
    }
}
function ExecPage(Cmd, Param1, Param2, Param3, Message) {
    Param1      = Param1    || 0;
    Param2      = Param2    || 0;
    Param3      = Param3    || 0;
    Message     = Message   || 0;
    //alert('ExecPage: Cmd=' + Cmd + ', Param1=' + Param1 + ', Param2=' + Param2 + ', Param3=' + Param3 + ', Message=' + Message);
    if (Message) if (window.confirm(Message) == false) return;
    Form1.Cmd.value = Cmd;
    Form1.Param1.value = Param1;
    Form1.Param2.value = Param2;
    Form1.Param3.value = Param3;
    Form1.submit();
}
function ExecForm(Cmd, Param1, Param2, Param3, Message) {
    Param1      = Param1    || 0;
    Param2      = Param2    || 0;
    Param3      = Param3    || 0;
    Message     = Message   || 0;
    //alert('ExecForm: Cmd=' + Cmd + ', Param1=' + Param1 + ', Param2=' + Param2 + ', Param3=' + Param3 + ', Message=' + Message);
    if (Message) if (window.confirm(Message) == false) return;
    Form1.Cmd.value              = Cmd;
    Form1.Param1.value           = Param1;
    Form1.Param2.value           = Param2;
    Form1.Param3.value           = Param3;
    Form1.submit();
}
function ExecTable(Cmd, Param1, Param2, Param3, Message, Selected, SelectedNames) {
    //alert('ExecTableTool: Cmd=' + Cmd + ', Param1=' + Param1 + ', Param2=' + Param2);
    //alert(TableSearchOptions.value);
    //return;
    Param1          = Param1            || 0;
    Param2          = Param2            || 0;
    Param3          = Param3            || 0;
    Message         = Message           || 0;
    SelectedNames   = SelectedNames     || 'CheckList[]';
    //alert('ExecTable: Cmd=' + Cmd + ', Param1=' + Param1 + ', Param2=' + Param2 + ', Param3=' + Param3 + ', Selected=' + Selected);
    //return;
    if (Selected > 0) {
        var Items = document.getElementsByName(SelectedNames); //'CheckList[]'
        var Len = Items.length;
        var Total = 0;
    	for (i=0; i < Len; i++) {
    		if (Items[i].checked == true) Total++;
    	}
        if (Selected == 1) {
            if (Total == 0) {
                alert('Please, select an item first.');
                return false;
            } else if (Total > 1) {
                alert('Please, select only one item first.');
                return false;
            }
        } else if (Total == 0) {
            alert('Please, select some items first.');
            return false;
        }
        if (Message) Message = Message.replace('[Total]', Total);
    }
    if (Message) if (!confirm(Message)) return;
    FormExecTable.Cmd.value             = Cmd;
    FormExecTable.Param1.value          = Param1;
    FormExecTable.Param2.value          = Param2;
    FormExecTable.Param3.value          = Param3;
    FormExecTable.submit();
}
function ShowStatus(Text) {
    if (Text) {
        window.status = Text;
    } else {
        window.status = window.defaultStatus;
    }
    return true ;
}
function ShowTab(names, key, focus) {
    var c = document.getElementsByTagName('DIV');
    var i;
    for (i = 0; i < c.length; i++) {
        if (c[i].name == names) {
            var e = c[i];
            var d = document.getElementById(e.id + 'Top');
            if (e.id == ('form-tab' + key)) {
                e.style.display = 'block';
                if (!HasClassName(d, 'form-pane-active')) d.className += ' form-pane-active';
            } else {
                e.style.display = 'none';
                if (HasClassName(d, 'form-pane-active')) RemoveClassName(d, 'form-pane-active');
            }
        }
    }
    if (!focus) return;
    if (focus == 'Description') return;
    var e = document.getElementById(focus);
    if (!e) return;
    if (e.disabled) return;
    switch (e.tagName) {
    case 'INPUT':
        e.focus();
        if (e.type == 'text') e.select();
        break;
    case 'TEXTAREA':
        //
        break;
    default:
        e.focus();
        break;
    }
}
function OpenWindow(Page, Width, Height) {
    var a = 'scrollbars=yes,menubar=no,height=450,width=600,resizable=yes,toolbar=no,location=no,status=no';
    var w = window.open(Page, '', a);
}
function SetTextEnable(target, value) {
    var e = document.getElementById(target);
    if (value) {
        e.disabled = false;
        e.style.backgroundColor = '#fff';
        e.focus();
    } else {
        e.disabled = true;
        e.style.backgroundColor = '#ddd';
    }
    return;
}
function ClearFormSearch(e, text, color1, color2) {
    if (e.value == text) {
        e.value = '';
        e.style.color = color1;
    } else if (e.value == '') {
        e.value = text;
        e.style.color = color2;
    }
    return false;
}
function SetImage(Form, Name, Target){
    var e = document.forms[Form].elements[Name];
    if (e.value > '') {
        document.images[Target].src = 'file://' + e.value;
    }
}
function OnFileChange(Target, Path) {
    var t = document.getElementById(Target);
    t.value = GetFileName(Path);
}
function GetFileName(Path) {
    var s = new String(Path);
    var p = s.replace(/\\/g, '/').split('/');
    i = p.length-1;
    return p[i];
}
function OnUploadChange(Folder, File, Target) {
    //alert(Folder);
    var e1 = document.getElementById(Folder);
    var e2 = document.getElementById(File);
    var e3 = document.getElementById(Target);
    var p = e1.options[e1.selectedIndex].value;
    //if (!p) p = '/';
    //p = '/' + p;
    e3.innerText = p + e2.value;
}
function ClearImage(Name) {
    //alert(Name);
    var e = document.getElementById(Name);
    var p = document.getElementById(Name + 'Preview');
    e.value = '';
    p.src = '/Inc/Images/Pixel.gif';
    //alert(e.value);
}
function ShowDiv(DivId, Element, Effect, TextShow, TextHide) {
    var d = document.getElementById(DivId);
    //var e = document.getElementById(El);
    if (d.style.display == 'none') {
        d.style.display = 'block';
        if (Element) SetElementProp(Element, Effect, TextHide);
    } else {
        d.style.display = 'none';
        if (Element) SetElementProp(Element, Effect, TextShow);
    }
    return false;
}
function SetElementProp(Element, Prop, Value) {
    switch (Prop) {
    case 'Class':
        Element.className = Value;
        break;
    case 'Text':
        Element.innerText = Value;
        break;
    }
}

function ExpandDiv(Id, ImageId, ImageShow, ImageHide) {
    //alert(Id);
    //return;
    var d = document.getElementById(Id);
    var e = document.getElementById(ImageId);
    if (d.style.display == 'none') {
        d.style.display = 'block';
        if (e) e.src = ImageHide;
    } else {
        d.style.display = 'none';
        if (e) e.src = ImageShow;
    }
    return false;
}

function OnTableCheck(Id, ClassId, ClassRow, ClassSel) {
    ClassId     = ClassId   || 0;
    ClassRow    = ClassRow  || 0;
    ClassSel    = ClassSel  || 0;

    //alert(Id + ', ' + ClassId + ', ' + ClassRow + ', ' + ClassSel);
    //return;

    var Check = document.getElementById('CheckAll');
    var Items = document.getElementsByName('CheckList[]');
    var Len = Items.length;
    var Total = 0;
    var All = false;

    if (Id == 0) {
        for (i=0; i < Len; i++) {
            var Id = Items[i].id;
            Id = Id.replace('TableGridRowCheck', '');
            //alert(Id);
			Items[i].checked = Check.checked;
            if (ClassId) {
                //alert(ClassId);
                var r = document.getElementById(ClassId + Id);
                if (Check.checked) {
                    if (!HasClassName(r, ClassSel)) r.className += ' ' + ClassSel;
                } else {
                    if (HasClassName(r, ClassSel)) RemoveClassName(r, ClassSel);
                }
            }
        }
    } else {
        All = true;
		for (i=0; i < Len; i++ ) {
			if (Items[i].checked) continue;
            All = false;
			break;
		}
        Check.checked = All;
        if (ClassId) {
            var r = document.getElementById(ClassId);
            //alert(r.className);
            var e = ClassId.replace('TableGridRow', 'TableGridRowCheck');
            var c = document.getElementById(e);
            if (c.checked) {
                if (!HasClassName(r, ClassSel)) r.className += ' ' + ClassSel;
            } else {
                if (HasClassName(r, ClassSel)) RemoveClassName(r, ClassSel);
            }
        }
	}

	for (i=0; i < Len; i++) {
		if (Items[i].checked == true) {
    		Total++;
        }
	}
}




















function Browser() {
    var u, s, i;
    this.IsExplorer                     = false;
    this.IsOpera                        = false;
    this.IsNetscape                     = false;
    this.Version                        = null;
    u = navigator.userAgent;
    s = "Opera";
    if ((i = u.indexOf(s)) >= 0) {
        this.IsOpera = true;
        this.Version = parseFloat(u.substr(i + s.length));
        return;
    }
    s = "Netscape6/";
    if ((i = u.indexOf(s)) >= 0) {
        this.IsNetscape = true;
        this.Version = parseFloat(u.substr(i + s.length));
        return;
    }
    // Treat any other "Gecko" ActiveBrowser as Netscape 6.1.
    s = "Gecko";
    if ((i = u.indexOf(s)) >= 0) {
        this.IsNetscape = true;
        this.Version = 6.1;
        return;
    }

    s = "MSIE";
    if ((i = u.indexOf(s))) {
        this.IsExplorer = true;
        this.Version = parseFloat(u.substr(i + s.length));
        return;
    }
}
function OnMenuButtonClick(event, id) {
    var button;
    // Get the target button element.
    if (ActiveBrowser.IsExplorer)
        button = window.event.srcElement;
    else
        button = event.currentTarget;
    // Blur focus from the link to remove that annoying outline.
    button.blur();
    // Associate the named menu to this button if not already done.
    // Additionally, initialize menu display.

    if (button.menu == null) {
        if (id) {
            button.menu = document.getElementById(id);
            if (button.menu.isInitialized == null) StartMenuPopup(button.menu);
        }
    }
    // [MODIFIED] Added for activate/deactivate on mouseover.
    // Set mouseout event handler for the button, if not already done.
    if (button.onmouseout == null) button.onmouseout = OnMenuMouseOut;
    // Exit if this button is the currently active one.
    if (button == ActiveMenu) return false;
    // [END MODIFIED]
    // Reset the currently active button, if any.
    if (ActiveMenu != null) SetMenuButtonNormal(ActiveMenu);
    // Activate this button, unless it was the currently active one.
    if (button != ActiveMenu) {
        SetMenuButtonActive(button);
        ActiveMenu = button;
    }
    else
        ActiveMenu = null;
    return false;
}

function OnMenuButtonOver(event, id) {
    //alert(id);
    //return;

    var button;
    // [MODIFIED] Added for activate/deactivate on mouseover.
    // Activates this button's menu if no other is currently active.
    if (ActiveMenu == null) {
        OnMenuButtonClick(event, id);
        return;
    }
    // [END MODIFIED]
    // Find the target button element.
    if (ActiveBrowser.IsExplorer)
        button = window.event.srcElement;
    else
        button = event.currentTarget;
    // If any other button menu is active, make this one active instead.
    if (ActiveMenu != null && ActiveMenu != button) OnMenuButtonClick(event, id);
}

function SetMenuButtonActive(button) {
    var x, y;
    // Update the button's style class to make it look like it's
    // depressed.
    button.className += " MenuButtonActive";
    // [MODIFIED] Added for activate/deactivate on mouseover.
    // Set mouseout event handler for the button, if not already done.
    if (button.onmouseout == null) button.onmouseout = OnMenuMouseOut;
    if (button.menu.onmouseout == null) button.menu.onmouseout = OnMenuMouseOut;
    // [END MODIFIED]
    // Position the associated drop down menu under the button and
    // show it.
    x = GetPageOffsetLeft(button);
    y = GetPageOffsetTop(button) + button.offsetHeight;
    // For IE, adjust position.
    if (ActiveBrowser.IsExplorer) {
        x += button.offsetParent.clientLeft - 2;
        y += button.offsetParent.clientTop - 1;
    }

    button.menu.style.left = x + "px";
    button.menu.style.top  = y + "px";
    button.menu.style.visibility = "visible";

  // For IE; size, position and show the menu's IFRAME as well.

    if (button.menu.iframeEl != null) {
        button.menu.iframeEl.style.left = button.menu.style.left;
        button.menu.iframeEl.style.top  = button.menu.style.top;
        button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
        button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
        button.menu.iframeEl.style.display = "";
    }
}

function SetMenuButtonNormal(button) {
    // Restore the button's style class.
    RemoveClassName(button, "MenuButtonActive");
    // Hide the button's menu, first closing any sub menus.
    if (button.menu != null) {
        CloseMenuPopup(button.menu);
        button.menu.style.visibility = "hidden";
        // For IE, hide menu's IFRAME as well.

    if (button.menu.iframeEl != null)
        button.menu.iframeEl.style.display = "none";
    }
}

function OnMenuPopupOver(event) {
    var menu;
    // Find the target menu element.
    if (ActiveBrowser.IsExplorer)
        menu = GetContainerWith(window.event.srcElement, "DIV", "MenuPopup");
    else
        menu = event.currentTarget;
    // Close any active sub menu.
    if (menu.activeItem != null) CloseMenuPopup(menu);
}

function OnMenuItemOver(event, id) {
    //alert(id);
    //return;
    var item, menu, x, y;
    // Find the target item element and its parent menu element.
    if (ActiveBrowser.IsExplorer)
        item = GetContainerWith(window.event.srcElement, "A", "MenuItem");
    else
        item = event.currentTarget;

    menu = GetContainerWith(item, "DIV", "MenuPopup");
    // Close any active sub menu and mark this one as active.
    if (menu.activeItem != null) CloseMenuPopup(menu);
    menu.activeItem = item;
    // Highlight the item element.
    item.className += " MenuItemActive";
    // Initialize the sub menu, if not already done.
    if (item.subMenu == null) {
        item.subMenu = document.getElementById(id);
        if (item.subMenu.isInitialized == null) StartMenuPopup(item.subMenu);
    }
    // [MODIFIED] Added for activate/deactivate on mouseover.
    // Set mouseout event handler for the sub menu, if not already done.
    if (item.subMenu.onmouseout == null)
        item.subMenu.onmouseout = OnMenuMouseOut;
    // [END MODIFIED]
    // Get position for submenu based on the menu item.
    x = GetPageOffsetLeft(item) + item.offsetWidth;
    y = GetPageOffsetTop(item);
    // Adjust position to fit in view.
    var maxX, maxY;
    if (ActiveBrowser.IsExplorer) {
        maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) + (document.documentElement.clientWidth  != 0 ? document.documentElement.clientWidth  : document.body.clientWidth);
        maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop)   + (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
    }
    if (ActiveBrowser.IsOpera) {
        maxX = document.documentElement.scrollLeft + window.innerWidth;
        maxY = document.documentElement.scrollTop  + window.innerHeight;
    }
    if (ActiveBrowser.IsNetscape) {
        maxX = window.scrollX + window.innerWidth;
        maxY = window.scrollY + window.innerHeight;
    }
    maxX -= item.subMenu.offsetWidth;
    maxY -= item.subMenu.offsetHeight;
    if (x > maxX) x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth + (menu.offsetWidth - item.offsetWidth));
    y = Math.max(0, Math.min(y, maxY));
    //x = x + 2;
    y = y - 1;
    // Position and show the sub menu.
    item.subMenu.style.left       = x + "px";
    item.subMenu.style.top        = y + "px";
    item.subMenu.style.visibility = "visible";
    // For IE; size, position and display the menu's IFRAME as well.
    if (item.subMenu.iframeEl != null) {
        item.subMenu.iframeEl.style.left    = item.subMenu.style.left;
        item.subMenu.iframeEl.style.top     = item.subMenu.style.top;
        item.subMenu.iframeEl.style.width   = item.subMenu.offsetWidth  + "px";
        item.subMenu.iframeEl.style.height  = item.subMenu.offsetHeight + "px";
        item.subMenu.iframeEl.style.display = "";
    }
    // Stop the event from bubbling.
    if (ActiveBrowser.IsExplorer)
        window.event.cancelBubble = true;
    else
        event.stopPropagation();
}

function CloseMenuPopup(menu) {
    if (menu == null || menu.activeItem == null) return;
    // Recursively close any sub menus.
    if (menu.activeItem.subMenu != null) {
        CloseMenuPopup(menu.activeItem.subMenu);
        menu.activeItem.subMenu.style.visibility = "hidden";
        // For IE, hide the sub menu's IFRAME as well.
        if (menu.activeItem.subMenu.iframeEl != null)
            menu.activeItem.subMenu.iframeEl.style.display = "none";
        menu.activeItem.subMenu = null;
    }
    // Deactivate the active menu item.
    RemoveClassName(menu.activeItem, "MenuItemActive");
    menu.activeItem = null;
}

// [MODIFIED] Added for activate/deactivate on mouseover. Handler for mouseout
// event on buttons and menus.

function OnMenuMouseOut(event) {
    var e;
  // If there is no active button, exit.
    if (ActiveMenu == null) return;
    // Find the element the mouse is moving to.
    if (ActiveBrowser.IsExplorer)
        e = window.event.toElement;
    else if (event.relatedTarget != null)
        e = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);
    // If the element is not part of a menu, reset the active button.
    if (GetContainerWith(e, "DIV", "MenuPopup") == null) {
        SetMenuButtonNormal(ActiveMenu);
        ActiveMenu = null;
    }
}

// [END MODIFIED]
function StartMenuPopup(menu) {
    var itemList, spanList;
    var textEl, arrowEl;
    var itemWidth;
    var w, dw;
    var i, j;
    // For IE, replace arrow characters.
    if (ActiveBrowser.IsExplorer) {
        menu.style.lineHeight = "2.5ex";
        spanList = menu.getElementsByTagName("SPAN");
        for (i = 0; i < spanList.length; i++)
            if (HasClassName(spanList[i], "MenuItemArrow")) {
                spanList[i].style.fontFamily = "Webdings";
                spanList[i].firstChild.nodeValue = "4";
        }
    }
    // Find the width of a menu item.
    itemList = menu.getElementsByTagName("A");
    if (itemList.length > 0)
        itemWidth = itemList[0].offsetWidth;
    else
        return;
    // For items with arrows, add padding to item text to make the
    // arrows flush right.

    // alert(itemWidth);
    for (i = 0; i < itemList.length; i++) {
        spanList = itemList[i].getElementsByTagName("SPAN");
        textEl  = null;
        arrowEl = null;
        for (j = 0; j < spanList.length; j++) {
            if (HasClassName(spanList[j], "MenuItemText"))  textEl  = spanList[j];
            if (HasClassName(spanList[j], "MenuItemArrow")) arrowEl = spanList[j];
        }
        if (textEl != null && arrowEl != null) {
            textEl.style.paddingRight = (itemWidth - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
            // For Opera, remove the negative right margin to fix a display bug.
            if (ActiveBrowser.IsOpera) arrowEl.style.marginRight = "0px";
        }
    }
    // Fix IE hover problem by setting an explicit width on first item of
    // the menu.
    if (ActiveBrowser.IsExplorer) {
        w = itemList[0].offsetWidth;
        itemList[0].style.width = w + "px";
        dw = itemList[0].offsetWidth - w;
        w -= dw;
        itemList[0].style.width = w + "px";
    }
    // Fix the IE display problem (SELECT elements and other windowed controls
    // overlaying the menu) by adding an IFRAME under the menu.
    if (ActiveBrowser.IsExplorer) {
        var iframeEl = document.createElement("IFRAME");
        iframeEl.frameBorder = 0;
        iframeEl.src = "javascript:;";
        iframeEl.style.display = "none";
        iframeEl.style.position = "absolute";
        iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
        menu.iframeEl = menu.parentNode.insertBefore(iframeEl, menu);
    }
    // Mark menu as initialized.
    menu.isInitialized = true;
}

function GetContainerWith(node, tagName, className) {
    // Starting with the given node, find the nearest containing element
    // with the specified tag name and style class.
    while (node != null) {
        if (node.tagName != null && node.tagName == tagName && HasClassName(node, className)) return node;
        node = node.parentNode;
    }
    return node;
}

function GetPageOffsetLeft(e) {
    var x;
    // Return the x coordinate of an element relative to the page.
    x = e.offsetLeft;
    if (e.offsetParent != null) x += GetPageOffsetLeft(e.offsetParent);
    return x;
}

function GetPageOffsetTop(e) {
    var y;
    // Return the x coordinate of an element relative to the page.
    y = e.offsetTop;
    if (e.offsetParent != null) y += GetPageOffsetTop(e.offsetParent);
    return y;
}

function HasClassName(e, name) {
    var i, list;
    list = e.className.split(' ');
    for (i = 0; i < list.length; i++) {
        if (list[i] == name) return true;
    }
    //alert('dgfdg');
    return false;
}
function RemoveClassName(e, name) {
    var i, curList, newList;
    if (e.className == null) return;
    newList = new Array();
    curList = e.className.split(' ');
    for (i = 0; i < curList.length; i++)
        if (curList[i] != name) newList.push(curList[i]);
    e.className = newList.join(' ');
}

function SetPageTheme(Option, Value){
	var links = document.getElementsByTagName("link");
	var found = null;
	var next = null;
    var i;
	//for(i = 0; (link = links[i]); i++) {
	for(i = 0; i < links.length; i++) {
        link = links[i];
        var s = link.getAttribute("rel");
        if (s == 'stylesheet') {
            s = link.getAttribute("title");
            if (s == 'System.Themes.' + Option) {
                s = link.getAttribute("href");
                link.setAttribute("href", 'Themes.' + Option + '.' + Value + '.css');
                break;
            }
        } else {
            alert('New Link Type: "' + s + '".');
        }
	}
}
function SetBorder(Id) {
    if (LastBorderId) {
        var e = document.getElementById(LastBorderId);
        e.style.border = LastBorderStyle;
        //e.width = e.width + 8;
    }
    var e = document.getElementById(Id);
    LastBorderId = Id;
    LastBorderStyle = e.style.border;
    //alert(e.style.border);
    e.style.border = '4px dashed #c00';
    //e.width = e.width - 8;
}
function ShowByClass(name, inc) {
    //alert(name);
    inc = inc || 0;
    //return;
    var c = GetElementsByClass('TR', name, inc);
    //alert(c.length);
    if (c.length) {
        var i;
        var d;
        d = (c[0].style.display == 'none') ? 'block' : 'none';
        for (i = 0; i < c.length; i++) {
            c[i].style.display = d;
        }
    }
    return (d == 'none' ? 1 : 0);
}
function GetElementsByClass(tag, name, inc) {
    inc = inc || 0;
    //alert(tag);
    var r = new Array();
    var j = 0;
    var c = document.getElementsByTagName(tag);
    for (i = 0; i < c.length; i++) {
        if (inc == 0) {
            if (c[i].className == name) {
                r[j] = c[i];
                j++;
            }
        } else {
            if (HasClassName(c[i], name)) {
                //alert(name + ': ' + c[i].className);
                r[j] = c[i];
                j++;
            }
        }
    }
    return r;
}
function $() {
	var c = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var e = arguments[i];
		if (typeof e == 'string') e = document.getElementById(e);
		if (arguments.length == 1) return e;
		c.push(e);
	}
	return c;
}
function $$() {
    var elements = new Array();
	for (var i=0,len=arguments.length;i<len;i++) {
        var element = arguments[i];
        alert(element);
		if (typeof element == 'string') {
			var matched = document.getElementById(element);
			if (matched) {
				elements.push(matched);
			} else {
				var allels = (document.all) ? document.all : document.getElementsByTagName('*');
				var regexp = new RegExp('(^| )'+element+'( |$)');
				for (var i=0,len=allels.length;i<len;i++) if (regexp.test(allels[i].className)) elements.push(allels[i]);
			}
			if (!elements.length) elements = document.getElementsByTagName(element);
			if (!elements.length) {
				elements = new Array();
				var allels = (document.all) ? document.all : document.getElementsByTagName('*');
				for (var i=0,len=allels.length;i<len;i++) if (allels[i].getAttribute(element)) elements.push(allels[i]);
			}
			if (!elements.length) {
				var allels = (document.all) ? document.all : document.getElementsByTagName('*');
				for (var i=0,len=allels.length;i<len;i++) if (allels[i].attributes) for (var j=0,lenn=allels[i].attributes.length;j<lenn;j++) if (allels[i].attributes[j].specified) if (allels[i].attributes[j].nodeValue == element) elements.push(allels[i]);
			}
		} else {
			elements.push(element);
		}
	}
	if (elements.length == 1) {
		return elements[0];
	} else {
		return elements;
	}
}
function getElementsByClassName(node, classname) {
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
function EnableSelect(Id, Active, IndexActive, IndexInactive) {
    IndexActive     = IndexActive   || 1;
    IndexInactive   = IndexInactive || 0;
    var e = document.getElementById(Id);
    if (Active) {
        //e.disabled = false;
        //e.selectedIndex = IndexActive;
        e.style.backgroundColor = 'window';
    } else {
        //e.disabled = true;
        e.selectedIndex = IndexInactive;
        //e.style.backgroundColor = 'buttonface';
    }
}
function SetEnabled(Val) {
    //alert(Val);
    for (var i=1, len = arguments.length; i < len; ++i) {
        var e = document.getElementById(arguments[i]);
        e.disabled = Val;
    };
}