﻿var radComboBoxItemCollection = '';
var strSelectValue = "-- Select Value --";
var SplitItem = "~#~";
var SplitValueText = "~;~";

function ShowOpenToolPart(cliendId)
{
    MSOTlPn_ShowToolPane2('Edit', cliendId);
}

function OnCheckAll(controlID, TotalCount, allValue)
{
    try
    {
        var oAllCheckBox = document.getElementById(controlID + "c0_chkAllItem");
        if (oAllCheckBox != null)
        {
            for (var i = 0; i < TotalCount; i++)
            {
                var oTempCheckBox = document.getElementById(controlID + "c0_chklistValues_" + i);
                if (oTempCheckBox != null)
                {
                    oTempCheckBox.checked = oAllCheckBox.checked;
                }
            }
            setMainListBox(controlID, TotalCount, allValue);
        }
    } catch (ex)
    {
    }
}

function OnCheckAny(controlID, TotalCount, allValue)
{
    try
    {
        var oAllCheckBox = document.getElementById(controlID + "c0_chkAllItem");
        if (oAllCheckBox != null)
        {
            var bAllChecked = true;
            for (var i = 0; i < TotalCount; i++)
            {
                var oTempCheckBox = document.getElementById(controlID + "c0_chklistValues_" + i);
                if (oTempCheckBox != null)
                {
                    if (oAllCheckBox.checked == true &&
		                oTempCheckBox.checked == false)
                    {
                        oAllCheckBox.checked = false;
                    }
                    if (oTempCheckBox.checked == false)
                    {
                        bAllChecked = false;
                    }
                }
            }
            if (bAllChecked == true)
            {
                oAllCheckBox.checked = true;
                OnCheckAll(controlID, TotalCount, allValue);
                return true;
            }
            setMainListBox(controlID, TotalCount, allValue);
        }
    } catch (ex)
    {
    }
}

function setMainListBox(controlID, TotalCount, allValue)
{
    try
    {
        radComboBoxItemCollection = allValue;
        var oAllCheckBox = document.getElementById(controlID + "c0_chkAllItem");
        var oCmdList = document.getElementById(controlID + "Input");

        var hqTemp = "";
        for (var i = 0; i < TotalCount; i++)
        {
            var oTempCheckBox = document.getElementById(controlID + "c0_chklistValues_" + i);

            if (oTempCheckBox.checked == true)
            {
                hqTemp += GetAllValue(allValue, i) + ";";
            }
        }

        if (oCmdList != null)
        {
            if (hqTemp != "")
            {
                var result = hqTemp.substr(0, hqTemp.length - 1);
                oCmdList.value = result;
            } else
            {
                RemoveAll(oCmdList);
                oCmdList.value = strSelectValue;
            }
        }
    }
    catch (ex)
    {
    }
}

function GetAllValue(allValue, index)
{
    try
    {
        //var allItems = allValue.split("#");
        //var allItems = Split(allValue, "~#~", index);
        //var item = allItems[index];
        var item = Split(allValue, SplitItem, index);
        //var textValue = item.split(";");
        var text = '';
        var value = '';

        //if (textValue.Length > 1)
        if (item.indexOf(SplitValueText) > 0)
        {
            //            text = textValue[0];
            //            value = textValue[1];
            text = Split(item, SplitValueText, 0);
            value = Split(item, SplitValueText, 1);
        }
        else
        {
            //            text = textValue[0];
            //            value = textValue[0];
            text = Split(item, SplitValueText, 0);
            value = Split(item, SplitValueText, 0);
        }
        return text;
    }
    catch (ex)
    {
        return "";
    }
}

function Split(str, separator, index)
{
    var temp = str;
    try
    {
        var indexSeparator = temp.indexOf(separator)
        var indexValue = 0;
        while (indexSeparator > 0)
        {
            if (indexValue == index)
            {
                return temp.substring(0, indexSeparator);
            }
            temp = temp.substring(indexSeparator + separator.length);
            indexSeparator = temp.indexOf(separator);
            indexValue++;
            if (indexValue > 1000)
            {
                break;
            }
        }
        if (indexValue == index)
        {
            return temp;
        }
    }
    catch (ex)
    {
        alert(ex);
    }
    return temp;
}

function RemoveAll(ListBoxId)
{
    ListBoxId.value = "";
}

function ClearAllCheck(controlID, TotalCount, allValue)
{
    try
    {
        var oAllCheckBox = document.getElementById(controlID + "c0_chkAllItem");
        if (oAllCheckBox != null)
        {
            oAllCheckBox.checked = false;
            OnCheckAll(controlID, TotalCount, allValue);
            setMainListBox(controlID, TotalCount, allValue);
        }
    } catch (ex)
    {
    }
}

function SetSelectValue(strValue)
{
    strSelectValue = strValue;
}

function SetSplitItem(strValue)
{
    SplitItem = strValue;
}

function SetSplitValueText(strValue)
{
    SplitValueText = strValue;
}


//-------------------------------------------------AutoCompleteTextBox----------------------------------------------------------------------------------------------

function DisplayErrors(message)
{
    alert(message);
}

function actb(obj, ca)
{
    /* ---- Public Variables ---- */
    this.actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
    this.actb_lim = 4;    // Number of elements autocomplete can show (-1: no limit)
    this.actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
    this.actb_mouse = true; // Enable Mouse Support
    this.actb_delimiter = new Array(';', ',');  // Delimiter for multiple autocomplete. Set it to empty array for single autocomplete
    this.actb_startcheck = 1; // Show widget only after this number of characters is typed in.
    /* ---- Public Variables ---- */

    /* --- Styles --- */
    this.actb_cssClass = 'ms-searchform';
    this.actb_bgColor = '#FFFFFF';
    this.actb_textColor = '#000000';
    this.actb_hColor = 'highlight';
    this.actb_hText = 'White';
    this.actb_fFamily = 'Verdana';
    this.actb_fSize = '11px';
    this.actb_hStyle = 'text-decoration:underline;font-weight="bold";color:white';
    this.widthofPanel = '300px';
    /* --- Styles --- */

    /* ---- Private Variables ---- */
    var actb_delimwords = new Array();
    var actb_cdelimword = 0;
    var actb_delimchar = new Array();
    var actb_display = false;
    var actb_pos = 0;
    var actb_total = 0;
    var actb_curr = null;
    var actb_container = null;
    var actb_rangeu = 0;
    var actb_ranged = 0;
    var actb_bool = new Array();
    var actb_pre = 0;
    var actb_toid;
    var actb_tomake = false;
    var actb_getpre = "";
    var actb_mouse_on_list = 1;
    var actb_kwcount = 0;
    var actb_caretmove = false;
    var containerAD = null;
    this.actb_keywords = new Array();

    /* ---- Private Variables---- */

    this.actb_keywords = ca;

    var actb_self = this;

    actb_curr = obj;

    addEvent(actb_curr, "focus", actb_setup);

    function actb_setup()
    {
        addEvent(document, "keydown", actb_checkkey);
        addEvent(actb_curr, "blur", actb_clear);
        addEvent(document, "keypress", actb_keypress);
    }

    function actb_clear(evt)
    {
        if (!evt) evt = event;
        removeEvent(document, "keydown", actb_checkkey);
        removeEvent(actb_curr, "blur", actb_clear);
        removeEvent(document, "keypress", actb_keypress);
        actb_removedisp();
    }

    function actb_parse(n)
    {
        if (actb_self.actb_delimiter.length > 0)
        {
            var t = actb_delimwords[actb_cdelimword].trim().addslashes();
            var plen = actb_delimwords[actb_cdelimword].trim().length;
        } else
        {
            var t = actb_curr.value.addslashes();
            var plen = actb_curr.value.length;
        }
        var tobuild = '';
        var i;

        if (actb_self.actb_firstText)
        {
            var re = new RegExp("^" + t, "i");
        } else
        {
            var re = new RegExp(t, "i");
        }
        var p = n.search(re);

        for (i = 0; i < p; i++)
        {
            tobuild += n.substr(i, 1);
        }
        tobuild += "<font style='" + (actb_self.actb_hStyle) + "'><span style='background-color: highlight'>";
        for (i = p; i < plen + p; i++)
        {
            tobuild += n.substr(i, 1);
        }
        tobuild += "</span></font>";
        for (i = plen + p; i < n.length; i++)
        {
            tobuild += n.substr(i, 1);
        }
        return tobuild;
    }

    function actb_generate()
    {
        if (document.getElementById('tat_table')) { actb_display = false; document.body.removeChild(document.getElementById('tat_table')); }
        if (actb_kwcount == 0)
        {
            actb_display = false;
            return;
        }
        a = document.createElement('table');
        a.className = actb_curr.actb_cssClass;

        a.cellSpacing = '1px';
        a.cellPadding = '1px';
        a.style.borderStyle = 'solid';
        a.style.borderWidth = 'thin 1px';
        a.style.borderTopWidth = '0px';
        a.style.borderLeftColor = 'Silver';
        a.style.borderRightColor = 'Silver';
        a.style.borderBottomColor = 'Silver';
        a.style.borderCollapse = 'collapse';
        a.style.position = 'absolute';
        a.style.width = this.widthofPanel;

        scrollTop = 0;
        try
        {
            //scrollTop = document.getElementById('MSOZoneCell_WebPartWPQ1').childNodes[0].scrollTop;
        }
        catch (exasdf)
        {

        }

        a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight - scrollTop) + 4 + "px";

        a.style.left = curLeft(actb_curr) + "px";
        a.style.backgroundColor = actb_self.actb_bgColor;
        a.id = 'tat_table';


        document.body.appendChild(a);
        var i;
        var first = true;
        var j = 1;
        if (actb_self.actb_mouse)
        {
            a.onmouseout = actb_table_unfocus;
            a.onmouseover = actb_table_focus;
        }
        var counter = 0;
        for (i = 0; i < actb_self.actb_keywords.length; i++)
        {
            if (actb_bool[i])
            {
                counter++;
                r = a.insertRow(-1);


                r.style.color = actb_self.actb_hText;

                r.className = this.actb_cssClass;
                if (first && !actb_tomake)
                {

                    r.style.backgroundColor = actb_self.actb_hColor;
                    first = false;
                    actb_pos = counter;
                } else if (actb_pre == i)
                {
                    r.style.backgroundColor = actb_self.actb_hColor;
                    first = false;
                    actb_pos = counter;
                } else
                {
                    r.style.backgroundColor = actb_self.actb_bgColor;
                }
                r.id = 'tat_tr' + (j);
                c = r.insertCell(-1);
                c.style.color = actb_self.actb_textColor;
                c.style.fontFamily = actb_self.actb_fFamily;
                c.style.fontSize = actb_self.actb_fSize;
                c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
                c.id = 'tat_td' + (j);
                c.setAttribute('pos', j);
                if (actb_self.actb_mouse)
                {
                    c.style.cursor = 'pointer';
                    c.onclick = actb_mouseclick;
                    c.onmouseover = actb_table_highlight;
                }
                j++;
            }
            if (j - 1 == actb_self.actb_lim && j < actb_total)
            {
                r = a.insertRow(-1);
                r.style.backgroundColor = actb_self.actb_bgColor;
                r.style.textOverflow = 'ellipsis';
                c = r.insertCell(-1);
                c.style.color = actb_self.actb_textColor;
                c.style.fontFamily = 'arial narrow';
                c.style.fontSize = actb_self.actb_fSize;
                c.align = 'center';
                replaceHTML(c, '\\/');
                if (actb_self.actb_mouse)
                {
                    c.style.cursor = 'pointer';
                    c.onclick = actb_mouse_down;
                }
                break;
            }
        }
        actb_rangeu = 1;
        actb_ranged = j - 1;
        actb_display = true;
        if (actb_pos <= 0) actb_pos = 1;

    }

    function actb_remake()
    {
        document.body.removeChild(document.getElementById('tat_table'));
        a = document.createElement('table');
        a.cellSpacing = '1px';
        a.cellPadding = '1px';
        a.className = actb_curr.actb_cssClass;
        a.style.borderStyle = 'solid';
        a.style.borderWidth = 'thin 1px';
        a.style.borderTopWidth = '0px';
        a.style.borderLeftColor = 'Silver';
        a.style.borderRightColor = 'Silver';
        a.style.borderBottomColor = 'Silver';
        a.style.borderCollapse = 'collapse';

        a.style.position = 'absolute';
        a.style.width = this.widthofPanel;

        scrollTop = 0;
        try
        {
            //scrollTop = document.getElementById('MSOZoneCell_WebPartWPQ1').childNodes[0].scrollTop;
        }
        catch (exasdf)
        {

        }
        a.style.top = eval(curTop(actb_curr) + actb_curr.offsetHeight - scrollTop) + "px";

        a.style.left = curLeft(actb_curr) + "px";
        a.style.backgroundColor = actb_self.actb_bgColor;
        a.id = 'tat_table';
        if (actb_self.actb_mouse)
        {
            a.onmouseout = actb_table_unfocus;
            a.onmouseover = actb_table_focus;
        }

        document.body.appendChild(a);
        var i;
        var first = true;
        var j = 1;
        if (actb_rangeu > 1)
        {
            r = a.insertRow(-1);
            r.style.backgroundColor = actb_self.actb_bgColor;


            c = r.insertCell(-1);
            c.style.color = actb_self.actb_textColor;
            c.style.fontFamily = 'arial narrow';
            c.style.fontSize = actb_self.actb_fSize;
            c.align = 'center';
            replaceHTML(c, '/\\');
            if (actb_self.actb_mouse)
            {
                c.style.cursor = 'pointer';
                c.onclick = actb_mouse_up;
            }
        }
        for (i = 0; i < actb_self.actb_keywords.length; i++)
        {
            if (actb_bool[i])
            {
                if (j >= actb_rangeu && j <= actb_ranged)
                {
                    r = a.insertRow(-1);
                    r.style.backgroundColor = actb_self.actb_bgColor;



                    r.id = 'tat_tr' + (j);
                    c = r.insertCell(-1);
                    c.style.color = actb_self.actb_textColor;
                    c.style.fontFamily = actb_self.actb_fFamily;
                    c.style.fontSize = actb_self.actb_fSize;
                    c.innerHTML = actb_parse(actb_self.actb_keywords[i]);
                    c.id = 'tat_td' + (j);
                    c.setAttribute('pos', j);
                    if (actb_self.actb_mouse)
                    {
                        c.style.cursor = 'pointer';
                        c.onclick = actb_mouseclick;
                        c.onmouseover = actb_table_highlight;
                    }
                    j++;
                } else
                {
                    j++;
                }
            }
            if (j > actb_ranged) break;
        }
        if (j - 1 < actb_total)
        {
            r = a.insertRow(-1);
            r.style.backgroundColor = actb_self.actb_bgColor;
            r.style.textOverflow = 'ellipsis';
            c = r.insertCell(-1);
            c.style.color = actb_self.actb_textColor;
            c.style.fontFamily = 'arial narrow';
            c.style.fontSize = actb_self.actb_fSize;
            c.align = 'center';
            replaceHTML(c, '\\/');
            if (actb_self.actb_mouse)
            {
                c.style.cursor = 'pointer';
                c.onclick = actb_mouse_down;
            }
        }
    }

    function actb_goup()
    {
        if (!actb_display) return;
        if (actb_pos == 1) return;
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
        actb_pos--;
        if (actb_pos < actb_rangeu) actb_moveup();
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
        document.getElementById('tat_tr' + actb_pos).style.color = actb_self.actb_hText;
        if (actb_toid) clearTimeout(actb_toid);
        if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() { actb_mouse_on_list = 0; actb_removedisp(); }, actb_self.actb_timeOut);
    }

    function actb_godown()
    {
        if (!actb_display) return;
        if (actb_pos == actb_total) return;
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
        actb_pos++;
        if (actb_pos > actb_ranged) actb_movedown();
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
        document.getElementById('tat_tr' + actb_pos).style.color = actb_self.actb_hText;
        if (actb_toid) clearTimeout(actb_toid);
        if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() { actb_mouse_on_list = 0; actb_removedisp(); }, actb_self.actb_timeOut);
    }

    function actb_movedown()
    {
        actb_rangeu++;
        actb_ranged++;
        actb_remake();
    }

    function actb_moveup()
    {
        actb_rangeu--;
        actb_ranged--;
        actb_remake();
    }

    /* Mouse */
    function actb_mouse_down()
    {
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
        actb_pos++;
        actb_movedown();
        document.getElementById('tat_tr' + actb_pos).style.color = actb_self.actb_hText;
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
        actb_curr.focus();
        actb_mouse_on_list = 0;
        if (actb_toid) clearTimeout(actb_toid);
        if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() { actb_mouse_on_list = 0; actb_removedisp(); }, actb_self.actb_timeOut);
    }

    function actb_mouse_up(evt)
    {
        if (!evt) evt = event;
        if (evt.stopPropagation)
        {
            evt.stopPropagation();
        } else
        {
            evt.cancelBubble = true;
        }
        document.getElementById('tat_tr' + actb_pos).style.color = actb_self.actb_hText;
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
        actb_pos--;
        actb_moveup();
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
        actb_curr.focus();
        actb_mouse_on_list = 0;
        if (actb_toid) clearTimeout(actb_toid);
        if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() { actb_mouse_on_list = 0; actb_removedisp(); }, actb_self.actb_timeOut);
    }

    function actb_mouseclick(evt)
    {
        if (!evt) evt = event;
        if (!actb_display) return;
        actb_mouse_on_list = 0;
        actb_pos = this.getAttribute('pos');
        actb_penter();
    }

    function actb_table_focus()
    {
        actb_mouse_on_list = 1;
    }

    function actb_table_unfocus()
    {
        actb_mouse_on_list = 0;
        if (actb_toid) clearTimeout(actb_toid);
        if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() { actb_mouse_on_list = 0; actb_removedisp(); }, actb_self.actb_timeOut);
    }

    function actb_table_highlight()
    {
        actb_mouse_on_list = 1;
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_bgColor;
        actb_pos = this.getAttribute('pos');
        while (actb_pos < actb_rangeu) actb_moveup();
        while (actb_pos > actb_ranged) actb_movedown();
        document.getElementById('tat_tr' + actb_pos).style.backgroundColor = actb_self.actb_hColor;
        document.getElementById('tat_tr' + actb_pos).style.color = actb_self.actb_hText;
        if (actb_toid) clearTimeout(actb_toid);
        if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() { actb_mouse_on_list = 0; actb_removedisp(); }, actb_self.actb_timeOut);
    }
    /* ---- */

    function actb_insertword(a)
    {
        if (actb_self.actb_delimiter.length > 0)
        {
            str = '';
            l = 0;
            for (i = 0; i < actb_delimwords.length; i++)
            {
                if (actb_cdelimword == i)
                {
                    prespace = postspace = '';
                    gotbreak = false;
                    for (j = 0; j < actb_delimwords[i].length; ++j)
                    {
                        if (actb_delimwords[i].charAt(j) != ' ')
                        {
                            gotbreak = true;
                            break;
                        }
                        prespace += ' ';
                    }
                    for (j = actb_delimwords[i].length - 1; j >= 0; --j)
                    {
                        if (actb_delimwords[i].charAt(j) != ' ') break;
                        postspace += ' ';
                    }
                    str += prespace;
                    str += a;
                    l = str.length;
                    if (gotbreak) str += postspace;
                } else
                {
                    str += actb_delimwords[i];
                }
                if (i != actb_delimwords.length - 1)
                {
                    str += actb_delimchar[i];
                }
            }
            actb_curr.value = str;
            setCaret(actb_curr, l);
        } else
        {
            actb_curr.value = a;
        }
        actb_mouse_on_list = 0;
        actb_removedisp();
    }
    function actb_penter()
    {
        if (!actb_display) return;
        actb_display = false;
        var word = '';
        var c = 0;
        for (var i = 0; i <= actb_self.actb_keywords.length; i++)
        {
            if (actb_bool[i]) c++;
            if (c == actb_pos)
            {
                word = actb_self.actb_keywords[i];
                break;
            }
        }
        actb_insertword(word);
        l = getCaretStart(actb_curr);
    }
    function actb_removedisp()
    {
        if (actb_mouse_on_list == 0)
        {
            actb_display = 0;
            if (document.getElementById('tat_table')) { document.body.removeChild(document.getElementById('tat_table')); }
            if (actb_toid) clearTimeout(actb_toid);
        }
    }
    function actb_keypress(e)
    {
        if (actb_caretmove) stopEvent(e);
        return !actb_caretmove;
    }
    function actb_checkkey(evt)
    {
        //for eatch control
        actb_keywords = ca;

        if (!evt) evt = event;
        a = evt.keyCode;
        caret_pos_start = getCaretStart(actb_curr);
        actb_caretmove = 0;
        switch (a)
        {
            case 38:
                actb_goup();
                actb_caretmove = 1;
                return false;
                break;
            case 40:
                actb_godown();
                actb_caretmove = 1;
                return false;
                break;
            case 13: case 9:
                if (actb_display)
                {
                    actb_caretmove = 1;
                    actb_penter();
                    return false;
                } else
                {
                    return true;
                }
                break;
            default:
                setTimeout(function() { actb_tocomplete(a) }, 50);
                break;
        }
    }

    function actb_tocomplete(kc)
    {
        if (kc == 38 || kc == 40 || kc == 13) return;
        var i;
        if (actb_display)
        {
            var word = 0;
            var c = 0;
            for (var i = 0; i <= actb_self.actb_keywords.length; i++)
            {
                if (actb_bool[i]) c++;
                if (c == actb_pos)
                {
                    word = i;
                    break;
                }
            }
            actb_pre = word;
        } else { actb_pre = -1 };

        if (actb_curr.value == '')
        {
            actb_mouse_on_list = 0;
            actb_removedisp();
            return;
        }
        if (actb_self.actb_delimiter.length > 0)
        {
            caret_pos_start = getCaretStart(actb_curr);
            caret_pos_end = getCaretEnd(actb_curr);

            delim_split = '';
            for (i = 0; i < actb_self.actb_delimiter.length; i++)
            {
                delim_split += actb_self.actb_delimiter[i];
            }
            delim_split = delim_split.addslashes();
            delim_split_rx = new RegExp("([" + delim_split + "])");
            c = 0;
            actb_delimwords = new Array();
            actb_delimwords[0] = '';
            for (i = 0, j = actb_curr.value.length; i < actb_curr.value.length; i++, j--)
            {
                if (actb_curr.value.substr(i, j).search(delim_split_rx) == 0)
                {
                    ma = actb_curr.value.substr(i, j).match(delim_split_rx);
                    actb_delimchar[c] = ma[1];
                    c++;
                    actb_delimwords[c] = '';
                } else
                {
                    actb_delimwords[c] += actb_curr.value.charAt(i);
                }
            }

            var l = 0;
            actb_cdelimword = -1;
            for (i = 0; i < actb_delimwords.length; i++)
            {
                if (caret_pos_end >= l && caret_pos_end <= l + actb_delimwords[i].length)
                {
                    actb_cdelimword = i;
                }
                l += actb_delimwords[i].length + 1;
            }
            var ot = actb_delimwords[actb_cdelimword].trim();
            var t = actb_delimwords[actb_cdelimword].addslashes().trim();
        } else
        {
            var ot = actb_curr.value;
            var t = actb_curr.value.addslashes();
        }
        if (ot.length == 0)
        {
            actb_mouse_on_list = 0;
            actb_removedisp();
        }
        if (ot.length < actb_self.actb_startcheck) return this;
        if (actb_self.actb_firstText)
        {
            var re = new RegExp("^" + t, "i");
        } else
        {
            var re = new RegExp(t, "i");
        }

        actb_total = 0;
        actb_tomake = false;
        actb_kwcount = 0;
        for (i = 0; i < actb_self.actb_keywords.length; i++)
        {
            actb_bool[i] = false;
            if (re.test(actb_self.actb_keywords[i]))
            {
                actb_total++;
                actb_bool[i] = true;
                actb_kwcount++;
                if (actb_pre == i) actb_tomake = true;
            }
        }

        if (actb_toid) clearTimeout(actb_toid);
        if (actb_self.actb_timeOut > 0) actb_toid = setTimeout(function() { actb_mouse_on_list = 0; actb_removedisp(); }, actb_self.actb_timeOut);
        actb_generate();
    }
    return this;
}

/* Event Functions */

// Add an event to the obj given
// event_name refers to the event trigger, without the "on", like click or mouseover
// func_name refers to the function callback when event is triggered
function addEvent(obj, event_name, func_name)
{
    if (obj.attachEvent)
    {
        obj.attachEvent("on" + event_name, func_name);
    } else if (obj.addEventListener)
    {
        obj.addEventListener(event_name, func_name, true);
    } else
    {
        obj["on" + event_name] = func_name;
    }
}

// Removes an event from the object
function removeEvent(obj, event_name, func_name)
{
    if (obj.detachEvent)
    {
        obj.detachEvent("on" + event_name, func_name);
    } else if (obj.removeEventListener)
    {
        obj.removeEventListener(event_name, func_name, true);
    } else
    {
        obj["on" + event_name] = null;
    }
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt)
{
    evt || window.event;
    if (evt.stopPropagation)
    {
        evt.stopPropagation();
        evt.preventDefault();
    } else if (typeof evt.cancelBubble != "undefined")
    {
        evt.cancelBubble = true;
        evt.returnValue = false;
    }
    return false;
}

// Get the obj that starts the event
function getElement(evt)
{
    if (window.event)
    {
        return window.event.srcElement;
    } else
    {
        return evt.currentTarget;
    }
}
// Get the obj that triggers off the event
function getTargetElement(evt)
{
    if (window.event)
    {
        return window.event.srcElement;
    } else
    {
        return evt.target;
    }
}
// For IE only, stops the obj from being selected
function stopSelect(obj)
{
    if (typeof obj.onselectstart != 'undefined')
    {
        addEvent(obj, "selectstart", function() { return false; });
    }
}

/*    Caret Functions     */

// Get the end position of the caret in the object. Note that the obj needs to be in focus first
function getCaretEnd(obj)
{
    if (typeof obj.selectionEnd != "undefined")
    {
        return obj.selectionEnd;
    } else if (document.selection && document.selection.createRange)
    {
        var M = document.selection.createRange();
        try
        {
            var Lp = M.duplicate();
            Lp.moveToElementText(obj);
        } catch (e)
        {
            var Lp = obj.createTextRange();
        }
        Lp.setEndPoint("EndToEnd", M);
        var rb = Lp.text.length;
        if (rb > obj.value.length)
        {
            return -1;
        }
        return rb;
    }
}
// Get the start position of the caret in the object
function getCaretStart(obj)
{
    if (typeof obj.selectionStart != "undefined")
    {
        return obj.selectionStart;
    } else if (document.selection && document.selection.createRange)
    {
        var M = document.selection.createRange();
        try
        {
            var Lp = M.duplicate();
            Lp.moveToElementText(obj);
        } catch (e)
        {
            var Lp = obj.createTextRange();
        }
        Lp.setEndPoint("EndToStart", M);
        var rb = Lp.text.length;
        if (rb > obj.value.length)
        {
            return -1;
        }
        return rb;
    }
}
// sets the caret position to l in the object
function setCaret(obj, l)
{
    obj.focus();
    if (obj.setSelectionRange)
    {
        obj.setSelectionRange(l, l);
    } else if (obj.createTextRange)
    {
        m = obj.createTextRange();
        m.moveStart('character', l);
        m.collapse();
        m.select();
    }
}
// sets the caret selection from s to e in the object
function setSelection(obj, s, e)
{
    obj.focus();
    if (obj.setSelectionRange)
    {
        obj.setSelectionRange(s, e);
    } else if (obj.createTextRange)
    {
        m = obj.createTextRange();
        m.moveStart('character', s);
        m.moveEnd('character', e);
        m.select();
    }
}

/*    Escape function   */
String.prototype.addslashes = function()
{
    return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function()
{
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
/* --- Escape --- */

/* Offset position from top of the screen */
function curTop(obj)
{
    toreturn = 0;
    while (obj)
    {
        toreturn += obj.offsetTop;
        obj = obj.offsetParent;
    }

    return toreturn;
}
function curLeft(obj)
{
    toreturn = 0;
    while (obj)
    {
        toreturn += obj.offsetLeft;
        obj = obj.offsetParent;
    }
    return toreturn;
}
/* ------ End of Offset function ------- */

/* Types Function */

// is a given input a number?
function isNumber(a)
{
    return typeof a == 'number' && isFinite(a);
}

/* Object Functions */

function replaceHTML(obj, text)
{
    while (el = obj.childNodes[0])
    {
        obj.removeChild(el);
    };
    obj.appendChild(document.createTextNode(text));
}

function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}

function Bamboo_Encode(s){
	if (typeof encodeURIComponent == "function") {
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		return encodeURIComponent(s);
	} else {
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		return encodeURIComponentNew(s);
	}
}

function Bamboo_AddEvent(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		alert("Bamboo_AddEvent could not add event!");
	}
}

function Bamboo_GetXMLHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		if (window.Bamboo_XMLHttpRequestProgID) {
			return new ActiveXObject(window.Bamboo_XMLHttpRequestProgID);
		} else {
			var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
			for (var i = 0; i < progIDs.length; ++i) {
				var progID = progIDs[i];
				try {
					var x = new ActiveXObject(progID);
					window.Bamboo_XMLHttpRequestProgID = progID;
					return x;
				} catch (e) {
				}
			}
		}
	}
	return null;
}

function Bamboo_CallBack(url, target, id, method, args, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
	if (window.Bamboo_PreCallBack) {
		var preCallBackResult = Bamboo_PreCallBack();
		if (!(typeof preCallBackResult == "undefined" || preCallBackResult)) {
			if (window.Bamboo_CallBackCancelled) {
				Bamboo_CallBackCancelled();
			}
			return null;
		}
	}
	var x = Bamboo_GetXMLHttpRequest();
	var result = null;
	if (!x) {
		result = { "value": null, "error": "NOXMLHTTP" };
		Bamboo_DebugError(result.error);
		if (window.Bamboo_Error) {
			Bamboo_Error(result);
		}
		if (clientCallBack) {
			clientCallBack(result, clientCallBackArg);
		}
		return result;
	}
	x.open("POST", url ? url : Bamboo_DefaultURL, clientCallBack ? true : false);
	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
	x.setRequestHeader("Accept-Encoding", "gzip, deflate");
	if (clientCallBack) {
		x.onreadystatechange = function() {
			if (x.readyState != 4) {
				return;
			}
			Bamboo_DebugResponseText(x.responseText);
			result = Bamboo_GetResult(x);
			if (result.error) {
				Bamboo_DebugError(result.error);
				if (window.Bamboo_Error) {
					Bamboo_Error(result);
				}
			}
			if (updatePageAfterCallBack) {
				Bamboo_UpdatePage(result);
			}
			Bamboo_EvalClientSideScript(result);
			clientCallBack(result, clientCallBackArg);
			x = null;
			if (window.Bamboo_PostCallBack) {
				Bamboo_PostCallBack();
			}
		}
	}
    var encodedData = "";
    if (target == "Page") {
        encodedData += "&Bamboo_PageMethod=" + method;
    } else if (target == "MasterPage") {
        encodedData += "&Bamboo_MasterPageMethod=" + method;
    } else if (target == "Control") {
        encodedData += "&Bamboo_ControlID=" + id.split(":").join("_");
        encodedData += "&Bamboo_ControlMethod=" + method;
    }
	if (args) {
		for (var argsIndex = 0; argsIndex < args.length; ++argsIndex) {
			if (args[argsIndex] instanceof Array) {
				for (var i = 0; i < args[argsIndex].length; ++i) {
					encodedData += "&Bamboo_CallBackArgument" + argsIndex + "=" + Bamboo_Encode(args[argsIndex][i]);
				}
			} else {
				encodedData += "&Bamboo_CallBackArgument" + argsIndex + "=" + Bamboo_Encode(args[argsIndex]);
			}
		}
	}
	if (updatePageAfterCallBack) {
		encodedData += "&Bamboo_UpdatePage=true";
	}
	if (includeControlValuesWithCallBack) {
		var form = document.getElementById(Bamboo_FormID);
		if (form != null) {
			for (var elementIndex = 0; elementIndex < form.length; ++elementIndex) {
				var element = form.elements[elementIndex];
				if (element.name) {
					var elementValue = null;
					if (element.nodeName.toUpperCase() == "INPUT") {
						var inputType = element.getAttribute("type").toUpperCase();
						if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
							elementValue = element.value;
						} else if (inputType == "CHECKBOX" || inputType == "RADIO") {
							if (element.checked) {
								elementValue = element.value;
							}
						}
					} else if (element.nodeName.toUpperCase() == "SELECT") {
						if (element.multiple) {
							elementValue = [];
							for (var i = 0; i < element.length; ++i) {
								if (element.options[i].selected) {
									elementValue.push(element.options[i].value);
								}
							}
						} else if (element.length == 0) {
						    elementValue = null;
						} else {
							elementValue = element.value;
						}
					} else if (element.nodeName.toUpperCase() == "TEXTAREA") {
						elementValue = element.value;
					}
					if (elementValue instanceof Array) {
						for (var i = 0; i < elementValue.length; ++i) {
							encodedData += "&" + element.name + "=" + Bamboo_Encode(elementValue[i]);
						}
					} else if (elementValue != null) {
						encodedData += "&" + element.name + "=" + Bamboo_Encode(elementValue);
					}
				}
			}
			// ASP.NET 1.1 won't fire any events if neither of the following
			// two parameters are not in the request so make sure they're
			// always in the request.
			if (typeof form.__VIEWSTATE == "undefined") {
				encodedData += "&__VIEWSTATE=";
			}
			if (typeof form.__EVENTTARGET == "undefined") {
				encodedData += "&__EVENTTARGET=";
			}
		}
	}
	Bamboo_DebugRequestText(encodedData.split("&").join("\n&"));
	x.send(encodedData);
	if (!clientCallBack) {
		Bamboo_DebugResponseText(x.responseText);
		result = Bamboo_GetResult(x);
		if (result.error) {
			Bamboo_DebugError(result.error);
			if (window.Bamboo_Error) {
				Bamboo_Error(result);
			}
		}
		if (updatePageAfterCallBack) {
			Bamboo_UpdatePage(result);
		}
		Bamboo_EvalClientSideScript(result);
		if (window.Bamboo_PostCallBack) {
			Bamboo_PostCallBack();
		}
	}
	return result;
}

function Bamboo_GetResult(x) {
	var result = { "value": null, "error": null };
	var responseText = x.responseText;
	try {
		result = eval("(" + responseText + ")");
	} catch (e) {
		if (responseText.length == 0) {
			result.error = "NORESPONSE";
		} else {
			result.error = "BADRESPONSE";
			result.responseText = responseText;
		}
	}
	return result;
}

function Bamboo_SetHiddenInputValue(form, name, value) {
    var input = null;
    if (form[name]) {
        input = form[name];
    } else {
        input = document.createElement("input");
        input.setAttribute("name", name);
        input.setAttribute("type", "hidden");
    }
    input.setAttribute("value", value);
    var parentElement = input.parentElement ? input.parentElement : input.parentNode;
    if (parentElement == null) {
        form.appendChild(input);
        form[name] = input;
    }
}

function Bamboo_RemoveHiddenInput(form, name) {
    var input = form[name];
    var parentElement = input.parentElement ? input.parentElement : input.parentNode;
    if (input && parentElement == form) {
        form[name] = null;
        form.removeChild(input);
    }
}

function Bamboo_FireEvent(eventTarget, eventArgument, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
	var form = document.getElementById(Bamboo_FormID);
	Bamboo_SetHiddenInputValue(form, "__EVENTTARGET", eventTarget);
	Bamboo_SetHiddenInputValue(form, "__EVENTARGUMENT", eventArgument);
	Bamboo_CallBack(null, null, null, null, null, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack);
	form.__EVENTTARGET.value = "";
	form.__EVENTARGUMENT.value = "";
}

function Bamboo_UpdatePage(result) {
	var form = document.getElementById(Bamboo_FormID);
	if (result.viewState) {
		Bamboo_SetHiddenInputValue(form, "__VIEWSTATE", result.viewState);
	}
	if (result.viewStateEncrypted) {
		Bamboo_SetHiddenInputValue(form, "__VIEWSTATEENCRYPTED", result.viewStateEncrypted);
	}
	if (result.eventValidation) {
		Bamboo_SetHiddenInputValue(form, "__EVENTVALIDATION", result.eventValidation);
	}
	if (result.controls) {
		for (var controlID in result.controls) {
			var containerID = "Bamboo_" + controlID.split("$").join("_") + "__";
			var control = document.getElementById(containerID);
			if (control) {
				control.innerHTML = result.controls[controlID];
				if (result.controls[controlID] == "") {
					control.style.display = "none";
				} else {
					control.style.display = "block";
				}
			}
		}
	}
	if (result.pagescript) {
	    Bamboo_LoadPageScript(result, 0);
	}
}

// Load each script in order and wait for each one to load before proceeding
function Bamboo_LoadPageScript(result, index) {
    if (index < result.pagescript.length) {
		try {
		    var script = document.createElement('script');
		    script.type = 'text/javascript';
		    if (result.pagescript[index].indexOf('src=') == 0) {
		        script.src = result.pagescript[index].substring(4);
		    } else {
		        if (script.canHaveChildren ) {
		            script.appendChild(document.createTextNode(result.pagescript[index]));
		        } else {
		            script.text = result.pagescript[index];
		        }
		    }
	        document.getElementsByTagName('head')[0].appendChild(script);
	        if (typeof script.readyState != "undefined") {
	            script.onreadystatechange = function() {
	                if (script.readyState != "complete" && script.readyState != "loaded") {
	                    return;
	                } else {
	                    Bamboo_LoadPageScript(result, index + 1);
	                }
	            }
	        } else {
                Bamboo_LoadPageScript(result, index + 1);
	        }
		} catch (e) {
		    Bamboo_DebugError("Error adding page script to head. " + e.name + ": " + e.message);
		}
	}
}

function Bamboo_EvalClientSideScript(result) {
	if (result.script) {
		for (var i = 0; i < result.script.length; ++i) {
			try {
				eval(result.script[i]);
			} catch (e) {
				alert("Error evaluating client-side script!\n\nScript: " + result.script[i] + "\n\nException: " + e);
			}
		}
	}
}

function Bamboo_DebugRequestText(text) {
}

function Bamboo_DebugResponseText(text) {
}

function Bamboo_DebugError(text) {
}

//Fix for bug #1429412, "Reponse callback returns previous response after file push".
//see http://sourceforge.net/tracker/index.php?func=detail&aid=1429412&group_id=151897&atid=782464
function Bamboo_Clear__EVENTTARGET() {
	var form = document.getElementById(Bamboo_FormID);
	Bamboo_SetHiddenInputValue(form, "__EVENTTARGET", "");
}

function Bamboo_InvokePageMethod(methodName, args, clientCallBack, clientCallBackArg) {
	Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "Page", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
}

function Bamboo_InvokeMasterPageMethod(methodName, args, clientCallBack, clientCallBackArg) {
	Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "MasterPage", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
}

function Bamboo_InvokeControlMethod(id, methodName, args, clientCallBack, clientCallBackArg) {
	Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "Control", id, methodName, args, clientCallBack, clientCallBackArg, true, true);
}

function Bamboo_PreProcessCallBack(
    control,
    e,
    eventTarget,
    causesValidation, 
    validationGroup, 
    imageUrlDuringCallBack, 
    textDuringCallBack, 
    enabledDuringCallBack,
    preCallBackFunction,
    callBackCancelledFunction,
    preProcessOut
) {
	preProcessOut.Enabled = !control.disabled;
	var preCallBackResult = true;
	if (preCallBackFunction) {
		preCallBackResult = preCallBackFunction(control);
	}
	if (typeof preCallBackResult == "undefined" || preCallBackResult) {
		var valid = true;
		if (causesValidation && typeof Page_ClientValidate == "function") {
			valid = Page_ClientValidate(validationGroup);
		}
		if (valid) {
			var inputType = control.getAttribute("type");
			inputType = (inputType == null) ? '' : inputType.toUpperCase();
			if (inputType == "IMAGE" && e != null) {
                var form = document.getElementById(Bamboo_FormID);
                if (e.offsetX) {
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".x", e.offsetX);
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".y", e.offsetY);
                } else {
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".x", e.clientX - control.offsetLeft + 1);
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".y", e.clientY - control.offsetTop + 1);
                }
			}
			preProcessOut.OriginalText = control.innerHTML;
			if (imageUrlDuringCallBack || textDuringCallBack) {
			    if (control.nodeName.toUpperCase() == "INPUT") {
			        if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
			            preProcessOut.OriginalText = GetLabelText(control.id);
			            SetLabelText(control.id, textDuringCallBack);
			        } else if (inputType == "IMAGE") {
			            if (imageUrlDuringCallBack) {
			                preProcessOut.OriginalText = control.src;
			                control.src = imageUrlDuringCallBack;
			            } else {
			                preProcessOut.ParentElement = control.parentElement ? control.parentElement : control.parentNode;
			                if (preProcessOut.ParentElement) {
			                    preProcessOut.OriginalText = preProcessOut.ParentElement.innerHTML;
			                    preProcessOut.ParentElement.innerHTML = textDuringCallBack;
			                }
			            }
			        } else if (inputType == "SUBMIT") {
			            preProcessOut.OriginalText = control.value;
			            control.value = textDuringCallBack;
			        }
			    } else if (control.nodeName.toUpperCase() == "SELECT") {
			        preProcessOut.OriginalText = GetLabelText(control.id);
			        SetLabelText(control.id, textDuringCallBack);
			    } else {
				    control.innerHTML = textDuringCallBack;
				}
			}
			control.disabled = (typeof enabledDuringCallBack == "undefined") ? false : !enabledDuringCallBack;
			return true;
        } else {
            return false;
        }
	} else {
	    if (callBackCancelledFunction) {
		    callBackCancelledFunction(control);
		}
		return false;
	}
}

function Bamboo_PreProcessCallBackOut() {
    // Fields
    this.ParentElement = null;
    this.OriginalText = '';
    this.Enabled = true;
}

function Bamboo_PostProcessCallBack(
    result, 
    control,
    eventTarget, 
    clientCallBack, 
    clientCallBackArg, 
    imageUrlDuringCallBack, 
    textDuringCallBack, 
    postCallBackFunction, 
    preProcessOut
) {
    if (postCallBackFunction) {
        postCallBackFunction(control);
    }
	control.disabled = !preProcessOut.Enabled;
    var inputType = control.getAttribute("type");
    inputType = (inputType == null) ? '' : inputType.toUpperCase();
	if (inputType == "IMAGE") {
	    var form = document.getElementById(Bamboo_FormID);
        Bamboo_RemoveHiddenInput(form, eventTarget + ".x");
        Bamboo_RemoveHiddenInput(form, eventTarget + ".y");
	}
	if (imageUrlDuringCallBack || textDuringCallBack) {
	    if (control.nodeName.toUpperCase() == "INPUT") {
	        if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
	            SetLabelText(control.id, preProcessOut.OriginalText);
	        } else if (inputType == "IMAGE") {
	            if (imageUrlDuringCallBack) {
	                control.src = preProcessOut.OriginalText;
	            } else {
	                preProcessOut.ParentElement.innerHTML = preProcessOut.OriginalText;
	            }
	        } else if (inputType == "SUBMIT") {
	            control.value = preProcessOut.OriginalText;
	        }
	    } else if (control.nodeName.toUpperCase() == "SELECT") {
	        SetLabelText(control.id, preProcessOut.OriginalText);
	    } else {
	        control.innerHTML = preProcessOut.OriginalText;
	    }
	}
	if (clientCallBack) {
	    clientCallBack(result, clientCallBackArg);
	}
}

function Bamboo_FireCallBackEvent(
	control,
	e,
	eventTarget,
	eventArgument,
	causesValidation,
	validationGroup,
	imageUrlDuringCallBack,
	textDuringCallBack,
	enabledDuringCallBack,
	preCallBackFunction,
	postCallBackFunction,
	callBackCancelledFunction,
	includeControlValuesWithCallBack,
	updatePageAfterCallBack
) {
	var preProcessOut = new Bamboo_PreProcessCallBackOut();
	var preProcessResult = Bamboo_PreProcessCallBack(
	    control, 
	    e, 
	    eventTarget,
	    causesValidation, 
	    validationGroup, 
	    imageUrlDuringCallBack, 
	    textDuringCallBack, 
	    enabledDuringCallBack, 
	    preCallBackFunction, 
	    callBackCancelledFunction, 
	    preProcessOut
	);
    if (preProcessResult) {
	    Bamboo_FireEvent(
		    eventTarget,
		    eventArgument,
		    function(result) {
                Bamboo_PostProcessCallBack(
                    result, 
                    control, 
                    eventTarget,
                    null, 
                    null, 
                    imageUrlDuringCallBack, 
                    textDuringCallBack, 
                    postCallBackFunction, 
                    preProcessOut
                );
		    },
		    null,
		    includeControlValuesWithCallBack,
		    updatePageAfterCallBack
	    );
    }
}

function BambooListControl_OnClick(
    e,
	causesValidation,
	validationGroup,
	textDuringCallBack,
	enabledDuringCallBack,
	preCallBackFunction,
	postCallBackFunction,
	callBackCancelledFunction,
	includeControlValuesWithCallBack,
	updatePageAfterCallBack
) {
	var target = e.target || e.srcElement;
	if (target.nodeName.toUpperCase() == "LABEL" && target.htmlFor != '')
	    return;
	var eventTarget = target.id.split("_").join("$");
	Bamboo_FireCallBackEvent(
	    target, 
	    e,
	    eventTarget, 
	    '', 
	    causesValidation, 
	    validationGroup, 
	    '',
	    textDuringCallBack, 
	    enabledDuringCallBack, 
	    preCallBackFunction, 
	    postCallBackFunction, 
	    callBackCancelledFunction, 
	    true, 
	    true
	);
}

function GetLabelText(id) {
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
        if (labels[i].htmlFor == id) {
            return labels[i].innerHTML;
        }
    }
    return null;
}

function SetLabelText(id, text) {
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
        if (labels[i].htmlFor == id) {
            labels[i].innerHTML = text;
            return;
        }
    }
}

function Bamboo_SetCursor()
{
	document.body.style.cursor="wait";	
}
function Bamboo_RemoveCursor()
{
	document.body.style.cursor = "auto";	
}
var idElementParents = "";
var idElement = "";

function Bamboo_SetImage_SiteCreation(idElementParent,idElementChild,urlImage) {

idElementParents = idElementParent;
idElement = idElementChild;

var strTable = "<table BORDER='0px' cellspacing='0' cellpadding='0' style='width: 100%; height:20%; margin:0;'>";
    strTable +="<tr valign='middle'>";
    strTable +="<td class='ms-WPHeader' align='center' height='18px'>";
 strTable +="<b>Please Wait</b></td>";
 strTable +="</tr>";
 strTable +="<tr valign='middle' height='20'>";
 strTable +="<td align='center' >Contacting Server.....</td>";
 strTable +="</tr>";
 strTable +="<tr valign='top'>";
 strTable +="<td align='center'>";
 strTable +="<img src='"+urlImage+"/wait.gif'></img></td></tr></table>";
 var elementChild = document.createElement("DIV");
 elementChild.id = idElementChild;
 elementChild.style.zIndex = "999";
 elementChild.innerHTML = strTable;
 var ElementParent = document.getElementById(idElementParent); 
 //var ElementParent = document.getElementById(currentWP+"_GridCol");
 //elementChild.setAttribute("class","ms-main");
 //elementChild.style.left=0;
 //elementChild.style.top=0;
 elementChild.style.position = 'absolute';
 elementChild.style.backgroundColor= '#ffffff';
 elementChild.style.width = ElementParent.offsetWidth;
 elementChild.style.height = ElementParent.offsetHeight; 
 ElementParent.appendChild(elementChild);
 }
  
function Bamboo_RemoveImage_SiteCreation() {

if(idElement == "" | idElementParents == "") return;
 var elementChild = document.getElementById(idElement);
 if(elementChild != null)
 {
  var ElementParent = document.getElementById(idElementParents);
  ElementParent.removeChild(elementChild);  
 }
}

//end Ajax

function CheckNumberOnPage(validatorID, messageError)
{
	try
	{	    	
		var num = document.getElementById(validatorID).value;
		if (isNaN(num))
		{
		    alert(messageError);
		    document.getElementById(validatorID).focus();
		    document.getElementById(validatorID).select();
		}
		else
		{
		    if (num < 0)
		    {
		        alert(messageError);
		    }
		}
	}
	catch(ex)
	{
	    document.getElementById(validatorID).focus();
	}
}

function CustomeEntityEditorHandleCheckNameResult(result, ctx)
{
    EntityEditorClearWaitCursor(ctx);
    CustomeEntityEditorCallback(result, ctx);
}

function CustomeEntityEditorCallback(result, ctx, preventAutoPostBack)
{
    if (document.getElementById(ctx) == null)
        return;
    var editor = document.getElementById(ctx);
    var errorControl = document.getElementById(getSubControlID(ctx, 'errorLabel'));
    var xmlDoc;
    if (document.implementation && document.implementation.createDocument)
    {
        xmlDoc = (new DOMParser()).parseFromString(result, "text/xml");
    }
    else
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(result);
    }
    var entities = xmlDoc.documentElement;
    var separator = entities.getAttribute("Separator");
    if (separator == null)
    {
        separator = String.fromCharCode(0);
    }
    var append = entities.getAttribute("Append");
    var maxHeight = entities.getAttribute("MaxHeight");
    g_maxheight[ctx] = maxHeight;
    var spanData = "";
    var downlevelData = "";
    if (append == "False")
    {
        errorControl.innerHTML = STSHtmlEncode(entities.getAttribute("Error"));
        errorControl.style.color = "red";
    }
    for (x = 0; x < entities.childNodes.length; x++)
    {
        var entity = entities.childNodes[x];
        spanData += ConvertEntityToSpan(ctx, entity);
        if (x == 0 &&
			editor.getAttribute(g_EntityEditorShowEntityDisplayTextInTextBox) == "1")
        {
            downlevelData += entity.getAttribute("DisplayText");
            document.getElementById(getSubControlID(ctx, g_EntityEditorHiddenEntityKeyId)).value = entity.getAttribute("Key");
            document.getElementById(getSubControlID(ctx, g_EntityEditorHiddenEntityDisplayTextId)).value = entity.getAttribute("DisplayText");
        }
        else
        {
            downlevelData += entity.getAttribute("Key");
        }
        if (spanData != "" && x + 1 != entities.childNodes.length)
        {
            spanData += separator + " ";
            downlevelData += separator + " ";
        }
    }
    var uplevel = document.getElementById(getSubControlID(ctx, g_EntityEditorUpLevelId));
    var downlevel = document.getElementById(getSubControlID(ctx, g_EntityEditorDownLevelId));
    var shouldPostBack = (preventAutoPostBack == null || !preventAutoPostBack) && autoPostBackEnabled(uplevel);
    var shouldNotifyChange = (uplevel.innerHTML != spanData);
    if (append == "True" && uplevel.innerHTML != '')
    {
        uplevel.innerHTML += separator + " " + spanData;
        downlevel.value += separator + " " + downlevelData;
    }
    else
    {
        shouldPostBack = shouldPostBack && uplevel.innerHTML != spanData && spanData.indexOf('ms-entity-resolved') != -1;
        downlevel.value = downlevelData;
        uplevel.innerHTML = spanData;
    }
    if ((shouldNotifyChange) && (!shouldPostBack) && (downlevel.onvaluesetfrompicker))
    {
        if (typeof (downlevel.onvaluesetfrompicker) == 'function')
        {
            downlevel.onvaluesetfrompicker();
        }
        else
        {
            eval(downlevel.onvaluesetfrompicker);
        }
    }
    CustomeUpdateControlValue(ctx);
    PickerAdjustHeight(ctx, maxHeight);
    if (shouldPostBack) schedulePostBack();
    var cbScript = editor.getAttribute("EEAfterCallbackClientScript");
    if (cbScript != null && cbScript != "")
    {
        if (preventAutoPostBack == undefined || preventAutoPostBack == false)
        {
            var timeoutScript = cbScript + "('" + STSScriptEncode(ctx) + "', '" + STSScriptEncode(result) + "')";
            setTimeout(timeoutScript, 500);
        }
    }
}

function CustomeUpdateControlValue(editorClientID)
{
    if (document.getElementById(editorClientID) == null)
        return;
    var uplevel = document.getElementById(getSubControlID(editorClientID, g_EntityEditorUpLevelId));
    var editor = document.getElementById(editorClientID);
    editor.value = ((uplevel.innerHTML != '') ? 'true' : '')
    CustomeCheckOk(editorClientID);
}

function CustomeCheckOk(editorClientID)
{
    var editor = document.getElementById(editorClientID);
    if (editor == null)
        return;
    var allowEmpty = false;
    if (editor.getAttribute('allowEmpty') == '1')
        allowEmpty = true;
    var uplevel = document.getElementById(getSubControlID(editorClientID, g_EntityEditorUpLevelId));
    if (uplevel.innerHTML != '')
    {
        var temp = uplevel.innerHTML;
        temp = temp.replace('class=ms-entity-resolved', 'class=ms-entity-resolved-custome');
        temp = temp.replace('class=ms-entity-unresolved', 'class=ms-entity-unresolved-custome');
        uplevel.innerHTML = temp;
        if (self.enableOK != null)
            enableOK();
    }
    else
    {
        if (self.disableOK != null && !allowEmpty)
            disableOK();
    }
}

function CheckOk(editorClientID)
{
    var editor = document.getElementById(editorClientID);
    if (editor == null)
        return;
    var allowEmpty = false;
    var isBlackSingleLevel = false;
    if (editor.getAttribute('allowEmpty') == '1')
    {
        allowEmpty = true;
    }
    if (editor.getAttribute('isBlackSingleLevel') != null)
    {
        if (editor.getAttribute('isBlackSingleLevel') == 'true')
        {
            isBlackSingleLevel = true;
        }
    }
    var uplevel = document.getElementById(getSubControlID(editorClientID, g_EntityEditorUpLevelId));
    if (uplevel.innerHTML != '')
    {
        if (isBlackSingleLevel)
        {
            var temp = uplevel.innerHTML;
            var isCustomeOk = false;
			if (temp.indexOf('ms-custome-entity-resolved') > 0)
			{
				isCustomeOk = true;
			}
			if (!isCustomeOk)
			{
			    for (var i = 0; i < 100; i++)
			    {
			        temp = temp.replace('class=ms-entity-resolved', 'class=ms-custome-entity-resolved');
			        temp = temp.replace('class=ms-entity-unresolved', 'class=ms-custome-entity-unresolved');
			    }
			    uplevel.innerHTML = temp;
			}
        }
        if (self.enableOK != null)
            enableOK();
    }
    else
    {
        if (self.disableOK != null && !allowEmpty)
            disableOK();
    }
}
