<!--

/*============================*/
// InstantASP Common 
/*============================*/

// Browser Sniff

var iasp_UserAgent = navigator.userAgent.toLowerCase();
var iasp_BrowserVer = navigator.appVersion
var iasp_Opera = (iasp_UserAgent.indexOf('opera') != -1);
var iasp_Opera8 = ((iasp_UserAgent.indexOf('opera 8') != -1 || iasp_UserAgent.indexOf('opera/8') != -1) ? 1 : 0);
var iasp_NS4 = (document.layers) ? true : false;
var iasp_IE4 = (document.all && !document.getElementById) ? true : false;
var iasp_IE5 = (document.all && document.getElementById) ? true : false;
var iasp_IsIE = (iasp_IE4 || iasp_IE5) ? true : false;
var iasp_NS6 = (!document.all && document.getElementById) ? true : false;
var iasp_FireFox = (iasp_UserAgent.indexOf("firefox/") != -1);
var iasp_Chrome = (iasp_UserAgent.indexOf("chrome/") != -1);

// simple menu control

var iasp_MenusActive = false; 
var iasp_MenuItems = new Array(); 
var iasp_MenuLeft = 0;
var iasp_MenuRight = 0;
var iasp_MenuTop = 0;
var iasp_MenuBottom = 0;
var currentSize = null;
var iasp_ModalActive = false;

// add simple menu events

addEvent(window, 'load', function(e) {
    iasp_TrackResize();
}
);

addEvent(document, 'click', function(e) {
    iasp_HideAllMenusOnClick(e);
}
);

// code to resolve resize event fire bug when using .appendChild within IE
// why? Because the <body> element was resized to accomodate the newly added <div> (menu) tag, and 
// IE fails to make any distinction between the window (or viewport) and the <body> element resizing
function iasp_Resized() {
    currentSize = iasp_GetViewPortSize();
    if (currentSize != null) {
        if (currentSize[0] != g_prevSize[0] || currentSize[1] != g_prevSize[1]) {
            g_prevSize = currentSize;
            iasp_HideAllMenus();
        }
    }
}

// track page resizing
function iasp_TrackResize() {
    g_prevSize = iasp_GetViewPortSize();
    if (g_prevSize != null) {
        setInterval(iasp_Resized, 25);
    }
}

// Open Menu on MouseOver Event
function iasp_OpnMnuMO(CallerID, displayID, Width, height, model) {

    if (height == null) { height = ""; }
    if (iasp_MenusActive) { iasp_OpnMnu(CallerID, displayID, Width, height, model); }
}

// Open Menu on MouseClick Event
function iasp_OpnMnu(CallerID, displayID, Width, Height, model) {

    // is menu active
    if (iasp_ModalActive) { return; }
    
    // setup local variables
    if (Height == null) { Height = ""; }    
    var Caller = iasp_FindControl(CallerID);
    var mnuDivID = displayID + "_smMenu";

    // determine if we can create elements dynamically
    if (!document.createElement) { return false; }

    // hide all other menus
    iasp_HideAllMenus();
    
    // set local flah
    iasp_MenusActive = true;

    // is this a mobal menu?
    if (model) {

        // modal menu disable body
        iasp_disableBody("default");
        iasp_ModalActive = true;

    } else {

        // check to see if item is already within active menu array if so just quit and return false
        for (count = 0; count < iasp_MenuItems.length; count++) {
            if (iasp_MenuItems[count] == mnuDivID) {
                return false;
            }
        }

        // hide any menus that maybe open	
        iasp_MenuItems[iasp_MenuItems.length] = mnuDivID;

    }

    // create the div layer container for this menu
    iasp_CreateLayer(displayID, mnuDivID, Width, Height);

    // get object references to div layer and div_layer that called this function
    var div_layer = iasp_FindControl(mnuDivID);

    // set default offset for div layer from the caller div
    var offsetTopDefault = Caller.offsetHeight + 4;

    // position div layer relative to the opening link  
    var intTop = iasp_GetOffsetTop(Caller) + offsetTopDefault;
    var intLeft = iasp_GetOffsetLeft(Caller);

    // set position of controls
    div_layer.style.top = intTop + "px";
    div_layer.style.left = intLeft + "px";

    //  calculate left and top positions of current div layer
    if (iasp_IE4 || iasp_IE5 || iasp_Opera) {
        iasp_MenuLeft = div_layer.style.posLeft;
        iasp_MenuTop = div_layer.style.posTop - offsetTopDefault;
    } else if (iasp_NS6) {
        iasp_MenuLeft = iasp_StyleWidthToInt(div_layer.style.left);
        iasp_MenuTop = iasp_StyleWidthToInt(div_layer.style.top);
    }

    // calculate right and bottom positions of current div layer
    iasp_MenuRight = parseInt(iasp_MenuLeft) + parseInt(mnu_extent.x);
    iasp_MenuBottom = parseInt(iasp_MenuTop) + parseInt(mnu_extent.y);

    // attempt to keep menu on screen			
    if (iasp_IE4 || iasp_IE5 || iasp_Opera || iasp_NS6) {
        win_width = document.body.clientWidth;
        if (iasp_MenuRight > win_width) {
            div_layer.style.left = win_width - parseInt(mnu_extent.x) - 12 + "px";
        }

        win_height = document.body.clientHeight;
        if (win_height > 0) {
            if ((iasp_MenuTop + parseInt(mnu_extent.y)) > win_height) {
                div_layer.style.top = win_height - (parseInt(mnu_extent.y) - 12) + "px";
            }
        }

    }

    // show menu	 
    div_layer.style.display = '';

}

// Create div to hold menu
function iasp_CreateLayer(displayID, DivLayer, mnu_width, mnu_height) {

    // get dic to display from client
    var displayDiv = iasp_FindControl(displayID);

    // create div layer container to holder table
    var elemDiv = null;
    elemDiv = document.createElement('span');
    elemDiv.id = DivLayer;
    elemDiv.style.position = 'absolute';
    elemDiv.style.top = '-1000px'; /* tweak for opera */
    elemDiv.style.left = '-1000px'; /* tweak for opera */
    elemDiv.style.overflow = 'hidden';
    elemDiv.style.zindex = 10;
    elemDiv.style.width = mnu_width;
    elemDiv.className = "sm_Container"

    if (displayDiv != null) {
        elemDiv.appendChild(displayDiv);
        if (displayDiv.className != null && displayDiv.className != "") { 
            elemDiv.className = displayDiv.className; 
        }
        elemDiv.innerHTML = displayDiv.innerHTML;
    } else {
        elemDiv.innerHTML = "No client side div menu found!";
    }

    if (iasp_IsIE) {
        elemDiv.style.filter = 'progid:DXImageTransform.Microsoft.Shadow(color="#888888", Direction=120, Strength=3) alpha(Opacity=100)';
    }

    // add elements to document        
    document.body.appendChild(elemDiv);        

    // get height now content has been added
    var height;
    if ((iasp_IE4 || iasp_IE5) || iasp_NS6)
    { height = elemDiv.offsetHeight; }
    else if (iasp_NS4)
    { height = elemDiv.clip.height; }

    // contents exceed height setup overflow
    if (mnu_height != "") {
        mnu_height = iasp_StyleWidthToInt(mnu_height)
        if (height > mnu_height) {
            elemDiv.style.height = mnu_height + "px";
            elemDiv.style.overflowX = 'hidden';
            elemDiv.style.overflowY = 'scroll';
            height = mnu_height
        }
    }

    mnu_extent = {
        x: mnu_width,
        y: height
    };

}

// Hide all menus on click event of document
function iasp_HideAllMenusOnClick(event) {

    // hide any possible tooltip
    iasp_hideToolTip();

    // are menus active
    if (iasp_MenusActive) {

        var el = null;
        // find the element that was clicked
        if (iasp_IE4 || iasp_IE5 || iasp_Opera) {
        
            el = window.event.srcElement;

        } else {
        
            // resolve issue with links not working in FF
            if (event.target != null) {
                if (event.target.tagName.toLowerCase() == "a") { return; }
            }
            if (event.target.parentNode != null) {
                if (event.target.parentNode.tagName.toLowerCase() == "a") { return; }
            }
            el = (event.target.tagName ? event.target : event.target.parentNode);
        }

        // did we find a parent div layer
        var container = iasp_GetContainer(el, "SPAN")

        if (container != null) {
            if (container.id.indexOf("_smMenu") == -1) {
                // hide all menus
                iasp_HideAllMenus();
            }
        } else {
            // hide all menus
            iasp_HideAllMenus();
        }
    }
}

// Hide all active menus 

function iasp_HideAllMenus() {
    // hide any possible simply meny control
    if (iasp_MenusActive) {
        for (count = 0; count < iasp_MenuItems.length; count++) {
            var div_layer = iasp_FindControl(iasp_MenuItems[count]);
            if (div_layer != null) {
                div_layer.style.display = 'none';
                iasp_MenuItems[count] = '';
                iasp_MenusActive = false;
            }
        }
    }
}

// LinkBar Control

function iasp_LinkBarToggle(nodeID, clientID, csstd, csstdsel, csstdchild, csstabline, csstabhl, csstablinesel) {

    // unique node id
    var uniqueid = nodeID + clientID;

    // get menu objects
    var lbtdchild = iasp_FindControl("lbtdchild_" + clientID);
    var lbchildmenulayer = iasp_FindControl("lbchildmenulayer_" + uniqueid);

    // reset styles
    iasp_LinkBarReset(clientID, csstd, csstdchild, csstabline, csstabhl);

    // update styles
    iasp_SwitchClass("lbtd_" + uniqueid, csstdsel);
    iasp_SwitchClass("lbtdchild_" + clientID, csstdchild);
    iasp_SwitchClass("lbtd1_" + uniqueid, csstabline);
    iasp_SwitchClass("lbtd2_" + uniqueid, csstabhl);
    iasp_SwitchClass("lbtd3_" + uniqueid, csstablinesel);
    iasp_SwitchClass("lbhtd1_" + uniqueid, csstabhl);
    iasp_SwitchClass("lbhtd2_" + uniqueid, csstabhl);
    iasp_SwitchClass("lbhtd3_" + uniqueid, csstablinesel);

    // populate host with menu
    if (lbchildmenulayer != null) {
        lbtdchild.innerHTML = lbchildmenulayer.innerHTML;
    }

}

// reset link bar tabs

function iasp_LinkBarReset(clientID, csstd, csstdchild, csstabline, csstabhl) {
    for (i = 1; i <= 10; i++) {
        var uniqueid = i + clientID
        iasp_SwitchClass("lbtd_" + uniqueid, csstd);
        iasp_SwitchClass("lbtdchild_" + clientID, csstdchild);
        iasp_SwitchClass("lbtd1_" + uniqueid, csstabline);
        iasp_SwitchClass("lbtd2_" + uniqueid, csstabline);
        iasp_SwitchClass("lbtd3_" + uniqueid, csstabline);
        iasp_SwitchClass("lbhtd1_" + uniqueid, csstabhl);
        iasp_SwitchClass("lbhtd2_" + uniqueid, csstabhl);
        iasp_SwitchClass("lbhtd3_" + uniqueid, csstabhl);
    }
}

// Hrrm tasty cookies

function iasp_UpdateCookie(objName, bolSave, strCookieName) {
    var ckColl = iasp_GetCookie(strCookieName);
    var arrLocTemp = new Array();
    if (ckColl != null) {
        arrColl = ckColl.split(",");
        for (i in arrColl) {
            if (arrColl[i] != objName && arrColl[i] != "") { arrLocTemp[arrLocTemp.length] = arrColl[i]; }
        }
    }
    if (bolSave) { arrLocTemp[arrLocTemp.length] = objName; }
    iasp_SetCookie(strCookieName, arrLocTemp.join(","));
}

function iasp_SetCookie(name, value) {
    expire = "expires=Wed, 1 Jan 2020 00:00:00 GMT;";
    document.cookie = name + "=" + value + "; path=/;" + expire;
}

function iasp_GetCookie(name) {
    ckName = name + "="; ckPos = document.cookie.indexOf(ckName);
    if (ckPos != -1) {
        ckStart = ckPos + ckName.length;
        ckEnd = document.cookie.indexOf(";", ckStart);
        if (ckEnd == -1) { ckEnd = document.cookie.length; }
        return unescape(document.cookie.substring(ckStart, ckEnd));
    }
    return null;
}

// toggle css class

function iasp_SwitchClass(objectname, classname) {
    var obj = iasp_FindControl(objectname);
    if (obj) { obj.className = classname; }
}

function iasp_SwitchTrCss(tr, classname) {
    if (tr != null) {
        var td = tr.getElementsByTagName("TD");
        for (var i = 0; i < td.length; i++) {
            
            td[i].className = classname;
        }
    }
}

function iasp_rowChecked(ckb, startcss) {

    if (ckb == null) {return;}
    var tr = iasp_GetContainer(ckb, "TR");
    if (tr == null) {return;}

    if (ckb.checked == true) {
        var td = tr.getElementsByTagName("TD");
        for (var i = 0; i < td.length; i++) {
            if ( td[i].className == "TableCell_Light") {
                td[i].className = "TableCell_Checked";
            }
        }
    } else {
        var td = tr.getElementsByTagName("TD");
        for (var i = 0; i < td.length; i++) {
            if ( td[i].className == "TableCell_Checked") {
                td[i].className = "TableCell_Light";
            }
            
        }
     
    }

}

// get top offset for object

function iasp_GetOffsetTop(objControl) {

    var top = objControl.offsetTop;
    var parent = objControl.offsetParent;
    while (parent != document.form) {
        top += parent.offsetTop;
        parent = parent.offsetParent;
    }
    return top;


}

// get left offset for object

function iasp_GetOffsetLeft(objControl) {

    var left = objControl.offsetLeft;
    var parent = objControl.offsetParent;
    while (parent != document.form) {
        left += parent.offsetLeft;
        parent = parent.offsetParent;
    }
    return left;

}

// get the height of an object.

function iasp_GetObjHeight(obj) {
    var height = 0;
    if (iasp_NS4) { var height = obj.clip.height; }
    else { var height = obj.offsetHeight; }
    return height;
}

// starting with the given node, find the nearest contained element             

function iasp_GetContainer(node, tagName) {

    while (node != null) {
        if (node.tagName != null && node.tagName == tagName)
            return node; node = node.parentNode;
    }
    return node;
}

// removes px and percentage markers from css style properties and returns an integer      

function iasp_StyleWidthToInt(strInput) {

    var strOutput = 0;
    if (strInput.toLowerCase().indexOf("px") >= 0) {
        strOutput = strInput.substr(0, strInput.toLowerCase().indexOf("px"));
    } else if (strInput.indexOf("%") >= 0) {
        strOutput = strInput.substr(0, strInput.indexOf("%"));
    }
    return parseInt(strOutput);
}

// removes any trialing anchor points within a string

function iasp_RemoveBookMark(strInput) {
    var uri = new String(strInput)
    var strOutput; var intPos = uri.indexOf('#');
    if (intPos > 0) { strOutput = uri.substring(0, intPos); }
    else { strOutput = uri; } return strOutput;
}

// removes any querystring from a string

function iasp_RemoveQueryString(strInput) {
    var uri = new String(strInput)
    var strOutput; var intPos = uri.indexOf('?');
    if (intPos > 0) { strOutput = uri.substring(0, intPos); }
    else { strOutput = uri; } return strOutput;
}

// get window size

function iasp_GetViewPortSize() {

    var size = [0, 0];
    if (typeof window.innerWidth != 'undefined') {
        size = [window.innerWidth, window.innerHeight];
    }
    else if (typeof document.documentElement != 'undefined' &&
             typeof document.documentElement.clientWidth != 'undefined' &&
             document.documentElement.clientWidth != 0) {
        size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
    }
    else {
    
        try
        {
            size = [document.getElementsByTagName('body')[0].clientWidth,
                  document.getElementsByTagName('body')[0].clientHeight];
        } catch (e) {
            return null;
         }
              
              
              
    }

    return size;

}

// ToolTip Control

var iasptooltip_offsetxpoint = 10;
var iasptooltip_offsetypoint = 10;
var iasptooltip_obj = null;
var iasptooltip_allowMove = true;
var iasptooltip_allowHide = true;
var iasptooltip_timeoutID;

/* get ibhect nidel */
function iasp_ieTrueBody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

/* enable tooltip */
function iasp_EnableTip(thetext, intWidth, intShowFor) {

    // init vars
    iasptooltip_allowMove = true;
    iasptooltip_allowHide = true;

    // clear timeout
    if (iasptooltip_timeoutID != null) { clearTimeout(iasptooltip_timeoutID); }

    // get tooltip layer
    iasptooltip_obj = iasp_FindControl('iasp_ToolTip');

    if (!iasptooltip_obj) { return false; }

    iasptooltip_obj.style.left = '-1000px'
    iasptooltip_obj.style.top = '-1000px'
    iasptooltip_obj.style.zindex = '9999999'
    
    if (iasp_NS6 || iasp_IE5) {
        if (typeof intWidth != "undefined") {
            iasptooltip_obj.style.width = intWidth + "px";
        }
        if (iasp_IE5) {
            iasptooltip_obj.style.filter = 'progid:DXImageTransform.Microsoft.Shadow(color="#888888", Direction=120, Strength=3) alpha(Opacity=100)';
        }

        // populate text
        iasp_populateToolTip(thetext);

        // show tooltip
        iasptooltip_obj.style.display = "block";
        iasp_PositionTip;

        // depends on InstantASPTransitions.js
        doFade(iasptooltip_obj, 25);

        // position tooltip
        document.onmousemove = iasp_PositionTip;

        // hide after x secs
        if (intShowFor > 0) {
            iasp_DisableTip(intShowFor)
        }

    }
}

/* populate tooltip text */
function iasp_populateToolTip(strText) {
    iasptooltip_obj.innerHTML = strText;
}

/* position tooltip */
function iasp_PositionTip(e) {

    if (iasptooltip_allowMove && iasptooltip_obj.style.display != "none") {

        var iasptooltip_curX = (iasp_NS6) ? e.pageX : event.x + iasp_ieTrueBody().scrollLeft;
        var iasptooltip_curY = (iasp_NS6) ? e.pageY : event.y + iasp_ieTrueBody().scrollTop;
        var iasptooltip_bottomedge = iasp_IE5 && !iasp_Opera ? iasp_ieTrueBody().clientHeight - event.clientY - iasptooltip_offsetypoint : window.innerHeight - e.clientY - iasptooltip_offsetypoint;
        var iasptooltip_rightedge = iasp_IE5 && !iasp_Opera ? iasp_ieTrueBody().clientWidth - event.clientX - iasptooltip_offsetxpoint : (window.innerWidth - e.clientX - iasptooltip_offsetxpoint);

        // set left
        if (iasptooltip_rightedge < iasptooltip_obj.offsetWidth) {
            iasptooltip_obj.style.left = iasp_IE5 ? iasp_ieTrueBody().scrollLeft + event.clientX - iasptooltip_obj.offsetWidth - 15 + "px" : window.pageXOffset + (e.clientX - iasptooltip_obj.offsetWidth - 15) + "px";
        }
        else {
            iasptooltip_obj.style.left = iasptooltip_curX + (iasptooltip_offsetxpoint) + "px";
        }

        // set top
        iasptooltip_obj.style.top = iasp_IE5 ? iasp_ieTrueBody().scrollTop + event.clientY + iasptooltip_offsetypoint + "px" : window.pageYOffset + e.clientY + iasptooltip_offsetypoint + "px";

        // don't move again
        iasptooltip_allowMove = false;

    }
}

function iasp_DisableTip(intDelay) {
    if (intDelay == null) { intDelay = 0; }
    if (iasptooltip_allowHide) {
        iasptooltip_timeoutID = setTimeout(iasp_hideToolTip, intDelay * 1000)
    }
}

function iasp_clearToolTipTimeout() {
    // clear timeout
    if (iasptooltip_timeoutID != null) { clearTimeout(iasptooltip_timeoutID); }
    iasp_showToolTip();
    iasptooltip_allowHide = false;
}

function iasp_showToolTip() {
    if (iasp_NS6 || iasp_IE5) {
        if (iasptooltip_obj != null) {
            iasptooltip_obj.style.display = "inline-block";
            iasptooltip_allowMove = false;
        }
    }
}

function iasp_hideToolTip() {
    if (iasp_NS6 || iasp_IE5) {
        if (iasptooltip_obj != null) {
            iasptooltip_obj.style.display = "none";
            iasptooltip_allowMove = true;
        }
    }
}

// dim background - use later for mozilla

function iasp_disableBody(cursor) {

    // set pointer to hourglass
    if (document.body != null) { document.body.style.cursor = cursor ? cursor : "wait"; }

    // init dimmer
    var div = null;
    var divid = "bgDimmer"
    if (iasp_FindControl(divid) != null) {
  
        div = iasp_FindControl(divid);
        
    } else {
    
        div = document.createElement("DIV");
        div.id = divid;
        div.className = "AjaxLoaderDimmer";
        div.innerHTML = "&nbsp;";
        div.style.left = "0px";
        
        if (iasp_IsIE) {
            div.style.filter = "alpha(opacity=50); moz-opacity:.50;"
        }

        // ensure layer scrolls with us
        addEvent(window, 'scroll', function(e) {
            if (document.body.scrollTop > 0) {
                div.style.top = document.body.scrollTop + "px";
            } else {
                div.style.top = document.documentElement.scrollTop + "px";
            }
        }
        );
        
        document.body.appendChild(div);
    }

    // setup div

    if (document.body.scrollTop > 0) {
        div.style.top = document.body.scrollTop + "px";
    } else {
        div.style.top = document.documentElement.scrollTop + "px";
    }
    div.style.display = "";
   

}

// enable bg again

function iasp_enableBody() {

    // get body
    var body = document.getElementsByTagName("body");

    // set pointer to default
    if (document.body != null) { document.body.style.cursor = 'default'; }

    // hide dimmer
    var dimmer = iasp_FindControl("bgDimmer");
    if (dimmer != null) {
        dimmer.style.display = "none";
    }

}

// disable object

function iasp_diableElem(el) {
    try {
        el.disabled = el.disabled ? false : true;
    }
    catch (e) { }

    if (el.childNodes && el.childNodes.length > 0) {
        for (var x = 0; x < el.childNodes.length; x++) {

            iasp_diableElem(el.childNodes[x]);

        }
    }
}

// find child control

function iasp_findChildByTag(el, tagName) {

    if (el.childNodes && el.childNodes.length > 0) {
        for (var x = 0; x < el.childNodes.length; x++) {
            if (el.tagName == tagName) {
                return el;
            } else {
                iasp_findChildByTag(el.childNodes[x]);
            }

        }
    }

    return null;

}

// find the submit button within a form

function iasp_findSubmit(doc) {

    var inputs = doc.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        var input = inputs[i];
        if (input.type.toLowerCase() == 'submit') {
            return input;
        };
    };

    return null;

}

function iasp_findUpload(doc) {

    var inputs = doc.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        var input = inputs[i];
        if (input.type.toLowerCase() == 'file') {
            return input;
        };
    };

    return null;

}

// ajax Loader

var iasp_bolLoadStarted = false;
var iasp_bolLoadEnded = false;
var iasp_LoaderDivId = 'iasp_LoaderDiv';

function iasp_AjaxExtensionsInitializeRequest(postBackElement) {

    // ensure method is only ran once
    if (!iasp_bolLoadStarted) {
    
        // diable bg
        iasp_disableBody();

        // show loader
        iasp_AddLoader();

        // update flags
        iasp_bolLoadStarted = true;
        iasp_bolLoadEnded = false;

    }
}

function iasp_AjaxExtensionsEndRequest(postBackElement) {

    // ensure method is only ran once
    if (!iasp_bolLoadEnded) {

        // enable background
        iasp_enableBody();

        // hide loader
        iasp_RemoveLoader();

        // update flags
        iasp_bolLoadEnded = true;
        iasp_bolLoadStarted = false;

    }
}

var iasp_LoaderDiv;
function iasp_AddLoader() {

    // calculate position
    var top = Math.round((document.documentElement.clientHeight / 2) + document.documentElement.scrollTop) + "px";
    var left = Math.round((document.documentElement.clientWidth / 2)) - 100 + "px";

    // build loader
    if (!iasp_LoaderDiv) { iasp_LoaderDiv = document.createElement('div'); }
    iasp_LoaderDiv.id = iasp_LoaderDivId;
    iasp_LoaderDiv.style.position = 'absolute';
    iasp_LoaderDiv.style.top = top;
    iasp_LoaderDiv.style.left = left;
    iasp_LoaderDiv.style.zindex = 999999;
    iasp_LoaderDiv.innerHTML = iasp_AjaxLoadingText;

    // add to document
    document.body.appendChild(iasp_LoaderDiv);
}

function iasp_RemoveLoader() {
    // hide loader
    var iasp_LoaderDiv = iasp_FindControl(iasp_LoaderDivId);
    if (iasp_LoaderDiv != null) {
        iasp_LoaderDiv.style.display = "";
        document.body.removeChild(iasp_LoaderDiv);
    }
}

// Json Proxy

instantaspjsonproxy = new Object();

function InstantASPJSONProxy(strJSON) {

    this.json = strJSON;
    this.jsonData = null; // store in internal array to avoid multiple json parsing

    if (instantaspjsonproxy[strJSON] != null) {
        return instantaspjsonproxy[strJSON];
    } else {
        instantaspjsonproxy[strJSON] = this;
    }
    return this;

}

InstantASPJSONProxy.prototype.getData = function() {

    if (this.jsonData == null) {
        this.jsonData = JSON.parse(this.json);
        if (!this.jsonData) { alert("Unable to parse JSON string!"); return; }
    }
    return this.jsonData;

}

InstantASPJSONProxy.prototype.objToArray = function(obj) {

    if (!obj) return new Array();
    if (!obj.length) { return new Array(obj); }
    return obj;

}

// treeview 

instantaspTree = new Object();
instantaspTreeIc = new Object();

function InstantASPTree(TreeID) {

    this.TreeID = TreeID;
    this.Options = new Options();
    this.Icons = new Icons();
    this.NodeList = new Object();
    this.ContextMenu = null;
    this.NodeContextMenu = new Object();
    this.TreeReference = "";
    this.RootNode = null;
    this.SelectedNode = null;
    this.Transition = null;
    this.EditId = null;
    this.NodeCount = 0;
    this.XmlHttp = null;

    if (instantaspTree[this.TreeID] != null) {
        return instantaspTree[this.TreeID];
    } else {
        instantaspTree[this.TreeID] = this;
    }
    return this;

}

function Icons(path) {
    if (path != undefined) {
        this.pnb = path + "Lines/TreeView_Plusnb.gif";
        this.pb = path + "Lines/TreeView_Plusb.gif";
        this.pr = path + "Lines/TreeView_Plusr.gif";
        this.mnb = path + "Lines/TreeView_Minusnb.gif";
        this.mb = path + "Lines/TreeView_Minusb.gif";
        this.mr = path + "Lines/TreeView_Minusr.gif";
        this.opf = path + "TreeView_FolderOpen.gif";
        this.clf = path + "TreeView_Folder.gif";
        this.chd = path + "TreeView_Leaf.gif";
        this.rot = path + "Lines/TreeView_Root.gif";
        this.lnb = path + "Lines/TreeView_LineAng.gif";
        this.lb = path + "Lines/TreeView_LineInts.gif";
        this.lin = path + "Lines/TreeView_Line.gif";
        this.bln = path + "Lines/TreeView_Blank.gif";
        this.spc = path + "Lines/TreeView_Spacer.gif";
        preloadIcon(this.pnb, this.pb, this.mnb, this.mb, this.opf, this.clf, this.chd, this.rot, this.lnb, this.lb, this.lin, this.bln);
        this.toString = function() { return "Standard Icons" };
        return this;
    }
}

function Options() {
    this.Target = "_self";
    this.Sort = "no";
    this.Icons = true;
    this.Check = false;
    this.Editable = false;
    this.SelectRow = false;
    this.EditKey = 113;
    this.EnableContext = true;
    this.OneExpand = false;
    this.OneClick = false;
    this.EnableCookie = false;    
    this.ShowRoot = true;
    this.LoadingText = "Loading...";
    this.ExpandedListTextBoxID = "";
    this.SelectedNodeTextBoxID = "";
    this.TabID = 0;
    this.LiveWriteCallBackURL = "";
    this.LiveDeleteCallBackURL = "";
    this.LiveMoveUpCallBackURL = "";
    this.LiveMoveDownCallBackURL = "";
    this.InputHiddenID = null;
    this.NodeEditURL = "";
    this.Expanded = false;
    return this;
}

function InstantASPTreeNode(NodeID, Text, NavigateURL, Icon, Expanded, Checked, CallBackURL, CategoryID) {
    this.NodeID = NodeID;
    this.ID = "";
    this.Text = Text;
    this.NavigateURL = (NavigateURL == null || NavigateURL == "") ? "javascript:void(0)" : NavigateURL;
    this.Icon = (Icon == null || Icon == "") ? null : Icon.split(",");
    this.Expanded = Expanded == null ? false : Expanded;
    this.Checked = (Checked ? Checked : false);
    this.CallBackURL = CallBackURL == "" ? null : CallBackURL;
    this.ContextMenu = null;
    this.cstStyle = "";
    if (this.Icon) { preloadIcon(this.Icon[0]); if (this.Icon.length > 1) { preloadIcon(this.Icon[1]); } }
    this.NextNode = null;
    this.PrevNode = null;
    this.FirstChild = null;
    this.LastChild = null;
    this.ParentNode = null;
    this.LoadingOnDemand = false;
    this.CategoryID = CategoryID == undefined ? 0 : CategoryID;
    this.equals = function(nd) { return (this.ID == nd.ID); };
    return this;
}

InstantASPTree.prototype.genIntTreeID = function(id) {
    return this.TreeID + id;
}

InstantASPTree.prototype.genOrgId = function(inTreeID) {
    return inTreeID.substr(this.TreeID.length);
}

InstantASPTree.prototype.compareNode = function(aN, bN) {
    return (aN.Text >= bN.Text);
}

InstantASPTree.prototype.add = function(id, prn, capt, url, ic, exp, chk, callbackurl, categoryid) {
    var nNd = new InstantASPTreeNode(((id == null || id == "") ? ("n_" + (++this.NodeCount)) : id), capt, url, ic, exp, chk, callbackurl, categoryid);
    nNd.ID = this.genIntTreeID(nNd.NodeID);
    if (this.NodeList[nNd.ID] != null) { return; }
    this.NodeList[nNd.ID] = nNd;
    if (this.RootNode == null) {
        this.RootNode = nNd
    } else {
        var pnd = this.NodeList[this.genIntTreeID(prn)];
        if (pnd != null) {
            nNd.ParentNode = pnd;
            if (pnd.LastChild == null) {
                pnd.FirstChild = nNd;
                pnd.LastChild = nNd
            } else {
                var t = pnd.FirstChild;
                if (this.Options.Sort != "no") {
                    do {
                        if (this.Options.Sort == "asc" ? this.compareNode(t, nNd) : this.compareNode(nNd, t)) { break; }
                        t = t.NextNode;
                    }
                    while (t != null);
                    if (t != null) {
                        if (t.PrevNode == null) {
                            t.PrevNode = nNd;
                            pnd.FirstChild = nNd
                        } else {
                            nNd.PrevNode = t.PrevNode;
                            t.PrevNode.NextNode = nNd;
                            t.PrevNode = nNd;
                        }
                        nNd.NextNode = t;
                    }
                }
                if (this.Options.Sort == "no" || t == null) {
                    nNd.PrevNode = pnd.LastChild;
                    pnd.LastChild.NextNode = nNd;
                    pnd.LastChild = nNd;
                }
            }
        }
    }
    return nNd
}

InstantASPTree.prototype.addBefore = function(id, sib, capt, url, ic, exp, chk, callbackurl) {
    var nd = this.getNodeById(sib);
    if (nd == null) { return; }
    var nNd = new InstantASPTreeNode(((id == null || id == "") ? ("int" + (++this.NodeCount)) : id), capt, url, ic, exp, chk, callbackurl);
    nNd.ID = this.genIntTreeID(nNd.NodeID);
    if (this.NodeList[nNd.ID] != null) { alert("Item with id " + id + " already exist"); return; }
    this.NodeList[nNd.ID] = nNd;
    nNd.ParentNode = nd.ParentNode;
    nNd.NextNode = nd;
    if (nd.PrevNode == null) {
        nd.PrevNode = nNd;
        nd.ParentNode.FirstChild = nNd;
    } else {
        nNd.PrevNode = nd.PrevNode; nd.PrevNode.NextNode = nNd; nd.PrevNode = nNd;
    }
    return nNd
}

InstantASPTree.prototype.addAfter = function(id, sib, capt, url, ic, exp, chk, callbackurl) {
    var nd = this.getNodeById(sib);
    if (nd == null) { return };
    var nNd = new InstantASPTreeNode(((id == null || id == "") ? ("int" + (++this.NodeCount)) : id), capt, url, ic, exp, chk, callbackurl);
    nNd.ID = this.genIntTreeID(nNd.NodeID);
    if (this.NodeList[nNd.ID] != null) { alert("Item with id " + id + " already exist"); return; }
    this.NodeList[nNd.ID] = nNd;
    nNd.ParentNode = nd.ParentNode;
    nNd.PrevNode = nd;
    if (nd.NextNode == null) { nd.NextNode = nNd; nd.ParentNode.LastChild = nNd }
    else { nNd.NextNode = nd.NextNode; nd.NextNode.PrevNode = nNd; nd.NextNode = nNd }
    return nNd
}

InstantASPTree.prototype.append = function(id, prn, capt, url, ic, exp, chk, callbackurl) {
    var nd = this.add(id, prn, capt, url, ic, exp, chk, callbackurl);
    this.reloadNode(prn);
    return nd
}

InstantASPTree.prototype.remove = function(id, reload) {
    var rNd = (id != null ? this.NodeList[this.genIntTreeID(id)] : this.SelectedNode);
    if (rNd != null) {
        if (this.RootNode.equals(rNd)) { this.RootNode = null; this.NodeList = new Object(); this.SelectedNode = null; return rNd };
        if (this.SelectedNode != null) { if (rNd.equals(this.SelectedNode)) { this.SelectedNode = null; } }
        var pr = rNd.ParentNode;
        if (pr.LastChild.equals(rNd)) { pr.LastChild = rNd.PrevNode; }
        if (pr.FirstChild.equals(rNd)) { pr.FirstChild = rNd.NextNode; }
        if (rNd.PrevNode != null) { rNd.PrevNode.NextNode = rNd.NextNode; }
        if (rNd.NextNode != null) { rNd.NextNode.PrevNode = rNd.PrevNode; }
        rNd.NextNode = null; rNd.PrevNode = null; rNd.ParentNode = null;
        var treeId = this.TreeID;
        this.loopTree(rNd, function(n) { instantaspTree[treeId].NodeList[n.ID] = null });
        if (reload == null || reload) { this.reloadNode(this.genOrgId(pr.ID)); }
    }
    return rNd;
}

InstantASPTree.prototype.removeChilds = function(id, reload) {
    var rNd = (id != null ? this.NodeList[this.genIntTreeID(id)] : this.SelectedNode);
    if (rNd != null) {
        while (rNd.FirstChild) { this.remove(rNd.FirstChild.NodeID, false); }
        if (reload == null || reload) { this.reloadNode(id); }
    }
}

InstantASPTree.prototype.removeLoading = function(id) {
    var rNd = (id != null ? this.NodeList[this.genIntTreeID(id)] : this.SelectedNode);
    if (rNd != null) {
        if (rNd.FirstChild != null) {
            if (rNd.FirstChild.Text == this.Options.LoadingText) { this.remove(rNd.FirstChild.NodeID, false); }
        }
    }
}

InstantASPTree.prototype.getSelNode = function() {
    return this.SelectedNode
}

InstantASPTree.prototype.genANode = function(sNd) {
    var ev = "";
    var st = "";
    var cm = "";
    var treeName = this.TreeReference + "instantaspTree." + this.TreeID;
    var ip = (sNd.NextNode != null ? this.Icons.lb : this.Icons.lnb);
    var sv = treeName + ".selectNode(\"" + sNd.ID + "\");";
    var cm = treeName + ".contextMenu(event, \"" + sNd.ID + "\");";
    var cn = treeName + ".checkNode(\"" + sNd.ID + "\");";
    if (sNd.FirstChild || sNd.CallBackURL != null) {
        ev = treeName + ".ParentNodeepareToggle(\"" + sNd.ID + "\");" + treeName + ".toggleNode(\"" + sNd.ID + "\");";
        st = (sNd.NavigateURL == "javascript:void(0)" ? treeName + ".selNToggle(\"" + sNd.ID + "\");" : "");
        ip = (sNd.NextNode != null ? (sNd.Expanded ? (!this.Options.ShowRoot && sNd.ParentNode.NodeID == 1 && !sNd.PrevNode ? this.Icons.mr : this.Icons.mb) : (!this.Options.ShowRoot && sNd.ParentNode.NodeID == 1 && !sNd.PrevNode ? this.Icons.pr : this.Icons.pb)) : (sNd.Expanded ? this.Icons.mnb : this.Icons.pnb));
    } else { sNd.Expanded = false; }

    var s = (sNd.ParentNode == null ? "" : "<img id=ip_" + sNd.ID + " src='" + ip + "' " + (sNd.FirstChild == null && sNd.CallBackURL == null ? "" : "onclick='" + ev + "'") + " class='tree' />");
    if (this.Options.Icons || sNd.equals(this.RootNode)) {
        var evl = "' onclick='" + (sNd.FirstChild && this.Options.OneClick ? st : sv) + " return " + treeName + ".treeOnClick(event);' oncontextmenu='return " + cm + "' ondblclick='" + st + " return " + treeName + ".treeOnDblClick(event)' onmouseover='" + treeName + ".treeOnMouseOver(event)' onmousemove='" + treeName + ".treeOnMouseMove(event)' onmouseout='" + treeName + ".treeOnMouseOut(event)' onmousedown='" + treeName + ".treeOnMouseDown(event)' onmouseUp='" + treeName + ".treeOnMouseUp(event)' />";
        s += ("<img id='ic_" + sNd.ID + "' class='" + (sNd.PrevNove ? "tree" : "treeroot") + "' src='" + this.toggleNodeImage(sNd) + evl);
    }

    s += (this.Options.Check ? "<input style='height:14px;margin-top:0px;margin-bottom:0px;padding:0px' type='checkbox' class='treeviewCheckbox' id=cb_" + sNd.ID + " " + (sNd.Checked ? "checked" : "") + " onclick='" + cn + treeName + ".treeOnCheck(\"" + sNd.NodeID + "\")'>" : "") + "<a target=\"" + this.Options.Target + "\" href=\"" + sNd.NavigateURL + "\" id='ac_" + sNd.ID + "' class='" + (sNd.FirstChild ? "prnnode" : "node") + "' onclick='" + (sNd.FirstChild && this.Options.OneClick ? st : sv) + " return " + treeName + ".treeOnClick(event);' oncontextmenu='return " + cm + "' ondblclick='" + st + " return " + treeName + ".treeOnDblClick(event)' onmouseover='" + treeName + ".treeOnMouseOver(event)' onmousemove='" + treeName + ".treeOnMouseMove(event)' onmouseout='" + treeName + ".treeOnMouseOut(event)' onmousedown='" + treeName + ".treeOnMouseDown(event)' onmouseup='" + treeName + ".treeOnMouseUp(event)'><span id='cstl_" + sNd.ID + "' " + (sNd.cstStyle != "" ? "class='" + sNd.cstStyle + "'" : "") + " >" + sNd.Text + "</span></a>";

    var n = sNd.ParentNode;
    while (n != null && !n.equals(this.RootNode)) {
        s = "<img src='" + (n.NextNode != null ? this.Icons.lin : this.Icons.bln) + "' class='tree' />" + s;
        n = n.ParentNode
    }
        
    if (sNd.ContextMenu && sNd.ContextMenu.mId && !this.NodeContextMenu[sNd.ContextMenu.mId])
    { s += sNd.ContextMenu.genMenu(); this.NodeContextMenu[sNd.ContextMenu.mId] = sNd.ContextMenu.mId }
    return s;

}

InstantASPTree.prototype.genNodes = function(sNd, incpar, wrt) {
    var s = "";
    if (!this.Options.ShowRoot && sNd.equals(this.RootNode)) { // root node is disabled
        s = "<div id='" + sNd.ID + "'></div><div id='ch_" + sNd.ID + "'>";
    }
    else {
        s = incpar ? ("<div id='" + sNd.ID + "' class='row'>" + this.genANode(sNd) + "</div><div style='display:" + (sNd.FirstChild && sNd.Expanded ? "inline" : "none") + "; visibility:" + (sNd.FirstChild && sNd.Expanded ? "visible" : "hidden") + ";' id='ch_" + sNd.ID + "'>") : "";
    }
    if (wrt) document.write(s);
    if (sNd.FirstChild != null) {
        var chNode = sNd.FirstChild;
        do {
            if (wrt) {
                this.genNodes(chNode, true, wrt);
            } else {
                s = s + this.genNodes(chNode, true, wrt);
            }
            chNode = chNode.NextNode;
        }
        while (chNode != null)
    }
    if (wrt) {
        if (incpar) document.write("</div>"); return "";
    } else {
        s = incpar ? (s + "</div>") : s; return s;
    }
}

InstantASPTree.prototype.genTree = function() {
    return this.genNodes(this.RootNode, true, false) + "<input id='ndedt" + this.TreeID + "' type='text' class='nodeedit' style='display:none;' value='' onblur='instantaspTree." + this.TreeID + ".liveNodeWrite()'>" + (this.ContextMenu ? this.ContextMenu.genMenu() : "") + (!iasp_FindControl("ddGesture") ? "<div id='ddGesture' style='display:none;' class='ddGesture'></div>" : "");
}

InstantASPTree.prototype.render = function(plc) {

    if (this.Options.Check) {
        this.populateCheckedNodes();
    }

    if (plc && plc != "") {
        var p = iasp_FindControl(plc);
        if (p != null) {
            p.innerHTML = this.genTree();
        }
    } else {
        document.write("<div class='treeviewContainer'>");
        this.genNodes(this.RootNode, true, true);
        document.write("<input id='ndedt" + this.TreeID + "' type='text' class='nodeedit' style='display:none;' value='' onblur='instantaspTree." + this.TreeID + ".liveNodeWrite()' />" + (this.ContextMenu ? this.ContextMenu.genMenu() : "") + (!iasp_FindControl("ddGesture") ? "<div id='ddGesture' style='display:none;' class='ddGesture'></div>" : ""));
        document.write("</div>");
    }

    this.initEvent();

    if (this.Options.EnableCookie && this.getCookie) {
        var sid = this.getCookie(this.TreeID + "_selnd");
        if (sid && sid != "") { this.selectNodeById(sid); }
    }
    
}

InstantASPTree.prototype.initEvent = function() {
    var isIE = (navigator.userAgent.indexOf("MSIE") >= 0);
    var orgEvent = (isIE ? document.body.onkeydown : window.onkeydown);
    if (!orgEvent || orgEvent.toString().search(/orgEvent/gi) < 0) {
        var newEvent = function(e) {
            if (instantaspTree.selectedTree) { instantaspTree.selectedTree.liveNodePress(isIE ? event : e); }
            if (orgEvent) { return orgEvent(); }
        };
        if (isIE) { document.body.onkeydown = newEvent; }
        else { window.onkeydown = newEvent; }
    }
}

InstantASPTree.prototype.reloadNode = function(id) {
    var inTreeID = this.genIntTreeID(id);
    var s = this.genNodes(this.NodeList[inTreeID], false);
    var dvN = iasp_FindControl("ch_" + inTreeID);
    dvN.innerHTML = s;
    if (dvN.innerHTML == "") {
        dvN.style.display = "none";
        s = this.genANode(this.NodeList[inTreeID]);
        dvN = iasp_FindControl(inTreeID);
        dvN.innerHTML = s;
    }
    if (this.SelectedNode != null) {
        var sId = this.SelectedNode.ID;
        this.SelectedNode = null;
        this.selectNode(sId);
    }
}

InstantASPTree.prototype.selNToggle = function(id) {
    this.toggleNode(id);
    if (!this.SelectedNode || this.SelectedNode.ID != id) { this.selectNode(id); }
    if (this.EditId != null) { clearTimeout(this.EditId); this.EditId = null }
}

InstantASPTree.prototype.selectNode = function(id) {
 
    instantaspTree.selectedTree = this;
    if (this.Options.Editable) {
        if (this.SelectedNode != null && this.SelectedNode.ID != id) {
            if (this.EditId) { clearTimeout(this.EditId); this.EditId = null }
        }
        if (this.SelectedNode != null && this.SelectedNode.ID == id) {
            this.EditId = setTimeout("instantaspTree." + this.TreeID + ".liveNodeEdit('" + id + "')", 500);
        }
        if (iasp_FindControl("ndedt" + this.TreeID).style.display == "") {
            var edt = iasp_FindControl("ndedt" + this.TreeID);
            edt.style.display = "none";
            edt.disabled = true
        }
    }

    var ac = null; var ic = null; var sNd = null;
    sNd = this.SelectedNode;
    if (sNd != null) {
        if (this.Options.SelectedRow)
            iasp_FindControl(sNd.ID).className = "row";
        ac = iasp_FindControl("ac_" + sNd.ID);
        if (this.Options.Icons) {
            var ic = iasp_FindControl("ic_" + sNd.ID);
            if (ic) { ic.style.display = "none"; iasp_FindControl("ic_" + sNd.ID).style.display = "" }
        }
        if (ac) { ac.className = (sNd.FirstChild ? "prnnode" : "node"); }
    }

    sNd = this.NodeList[id];
    this.SelectedNode = sNd;
    if (this.Options.SelectRow)
        iasp_FindControl(id).className = "selrow";
    ac = iasp_FindControl("ac_" + id);
    if (this.Options.Icons) {
        var ic = iasp_FindControl("ic_" + id);
        if (ic) { iasp_FindControl("ic_" + id).style.display = "none"; ic.style.display = "" }
    }

    if (ac) { ac.className = (sNd.FirstChild ? "selprnnode" : "selnode"); }
    if (this.Options.EnableCookie && this.setCookie)
        this.setCookie(this.TreeID + "_selnd", sNd.NodeID);
}

InstantASPTree.prototype.selectNodeById = function(id) {

    var node = this.getNodeById(id);
    if (!node) { return };
    var tmp = node;
    while (tmp.ParentNode != null) { this.expandNode(tmp.NodeID); tmp = tmp.ParentNode }
    this.selectNode(node.ID);
}

InstantASPTree.prototype.isChild = function(c, p) {
    var nd = this.getNodeById(c);
    if (!nd) { return false };
    var tmp = nd.ParentNode;
    while (tmp != null) { if (tmp.NodeID == p) { return true; } tmp = tmp.ParentNode; }
    return false
}

InstantASPTree.prototype.hasChild = function(id) {
    var nd = this.getNodeById(id);
    return (nd.FirstChild != null);
}

InstantASPTree.prototype.expandNode = function(id) {
    var tmpTransition = null;
    var sNd = this.NodeList[this.genIntTreeID(id)];
    if (this.Transition != null) { tmpTransition = this.Transition; this.Transition = null; }
    if (!sNd.Expanded) { this.toggleNode(sNd.ID); }
    if (tmpTransition != null) { this.Transition = tmpTransition; };
}

InstantASPTree.prototype.collapseNode = function(id) {
    var sNd = this.NodeList[this.genIntTreeID(id)];
    if (this.Transition != null) { tmpTransition = this.Transition; this.Transition = null; }
    if (sNd.Expanded) { this.toggleNode(sNd.ID); }
    if (tmpTransition != null) { this.Transition = tmpTransition; };
}

InstantASPTree.prototype.ParentNodeepareToggle = function(id) {

    var sNd = this.SelectedNode;
    if (sNd == null) { this.selectNode(id); return; }
    if (sNd.ID == id) return;
    while (sNd != null && sNd.ID != id) { sNd = sNd.ParentNode; }
    if (sNd == null) { return; }
    if (sNd.ID == id) { this.selectNode(id); }

}

InstantASPTree.prototype.toggleNode = function(id) {

    var nd = iasp_FindControl("ch_" + id);
    var ip = iasp_FindControl("ip_" + id);
    var ic = iasp_FindControl("ic_" + id);
    
   var sNd = this.NodeList[id];
   if (sNd.Expanded) {
        sNd.Expanded = false;
        nd.style.height = '';
        if (this.Transition != null && this.Transition.CollapseSlide != 0) {
            this.Transition.CollapseDiv(nd);
        } else {
            nd.style.display = 'none';
            nd.style.visibility = 'hidden';
        }
        if (ip != null) {
            ip.src = (sNd.NextNode ? this.Icons.pb : this.Icons.pnb);
        }

        if (ic != null) { ic.src = this.toggleNodeImage(sNd); }
        this.treeOnCollapse(sNd.NodeID);
        this.treeOnResize(sNd.NodeID); 

    } else {

        if (this.Options.OneExpand && sNd.ParentNode) {
            var tNd = sNd.ParentNode.FirstChild;
            while (tNd) {
                if (tNd.id != id && tNd.Expanded) {
                    this.collapseNode(tNd.NodeID);
                }
                tNd = tNd.NextNode
            }
        }
        sNd.Expanded = true;
        nd.style.height = '';
        if (this.Transition != null && this.Transition.ExpandSlide != 0) {
            this.Transition.ExpandDiv(nd);
        } else {
            nd.style.display = 'block';
            nd.style.visibility = 'visible';
        }

        if (ip != null && (sNd.FirstChild != null || sNd.CallBackURL != null)) {
            ip.src = (sNd.NextNode ? this.Icons.mb : this.Icons.mnb);
        }
    
        if (ic != null) { ic.src = this.toggleNodeImage(sNd); }
        this.treeOnExpand(sNd.NodeID);
        this.treeOnResize(sNd.NodeID); 
    }
}

InstantASPTree.prototype.fetchContent = function(id) {
    var sNd = this.NodeList[id];
    if (sNd != null) {
        if (sNd.LoadingOnDemand) {
            return;
        } else {
            if (sNd.CallBackURL != null && sNd.FirstChild == null) { this.populatefetchedContent(id); }
        }
    }
}

InstantASPTree.prototype.populatefetchedContent = function(id) {
    
    var sNd = this.NodeList[id];
    var nd = iasp_FindControl("ch_" + id);
    var arrURL = sNd.CallBackURL.split("?");
    var tree = this; // can't use this within HttpHandler method

    tree.add(null, sNd.NodeID, this.Options.LoadingText, "", "", false, false, "");
    tree.reloadNode(sNd.NodeID);

    if (!this.XmlHttp) { this.XmlHttp = new iasp_XmlHttpRequest(); }
    var objXmlHttpHandler = function(obj) {
        sNd.LoadingOnDemand = true;
        if (obj.responseXML != null) {
            var items = obj.responseXML.getElementsByTagName("Node");
            if (items.length > 0) {
                tree.removeLoading(sNd.NodeID);
                for (var i = 0; i < items.length; i++) {
                    var nd = items[i];
                    var id = nd.getAttribute("NodeID") == null ? null : nd.getAttribute("NodeID");
                    var capt = nd.getAttribute("Text") == null ? "" : nd.getAttribute("Text");
                    if (capt == "") { capt = nd.getAttribute("TextNonLocalized"); }
                    var url = nd.getAttribute("NavigateURL") == null ? "" : nd.getAttribute("NavigateURL");
                    var icon = nd.getAttribute("ImageURL") == null ? "" : nd.getAttribute("ImageURL");
                    var expandedicon = nd.getAttribute("ExpandedImageUrl") == null ? "" : nd.getAttribute("ExpandedImageUrl");
                    if (icon != '') { expandedicon = ',' + expandedicon }
                    var expanded = nd.getAttribute("Expanded") == null ? false : nd.getAttribute("Expanded");
                    var categoryid = nd.getAttribute("ID") == null ? false : nd.getAttribute("ID");
                    var checked = nd.getAttribute("Checked") == null ? false : nd.getAttribute("Checked");
                    var callbackurl = nd.getAttribute("CallbackUrl") == null ? "" : nd.getAttribute("CallbackUrl");

                    // add node					
                    var nNd = tree.add(id, sNd.NodeID, capt, url, icon + expandedicon, expanded, checked, callbackurl, categoryid);
                    nNd.ParentNode = sNd;   
                      
                }

                tree.reloadNode(sNd.NodeID);
                sNd.LoadingOnDemand = false;
                tree.treeOnResize(sNd.NodeID); 
                    
            }
        } else {
            alert("Could not retreive data from " + sNd.CallBackURL + ", invalid response. Response received: " + obj.responseXML);
            sNd.LoadingOnDemand = false;
        }
    };

    this.XmlHttp.Connect(arrURL[0], "GET", arrURL[1], objXmlHttpHandler);
}

InstantASPTree.prototype.toggleNodeImage = function(sNd) {
    var isrc = (sNd.equals
   (this.RootNode) ? this.Icons.rot : sNd.FirstChild || sNd.CallBackURL != null ? (sNd.Expanded ? this.Icons.opf : this.Icons.clf) :
   (sNd.FirstChild ? this.Icons.opf : this.Icons.chd));

    if (sNd.Icon) { isrc = (sNd.Icon.length > 1 ? (sNd.Expanded ? sNd.Icon[1] : sNd.Icon[0]) : sNd.Icon[0]); }
    return isrc;
}

InstantASPTree.prototype.expandAll = function() {
    var treeId = this.TreeID;
    this.loopTree(this.RootNode, function(n) {
        if (n.FirstChild) {
            instantaspTree[treeId].expandNode(n.NodeID);
        }
    });
}

InstantASPTree.prototype.collapseAll = function(incPr) {
    var treeId = this.TreeID;
    this.loopTree(this.RootNode, function(n) {
        if (n.FirstChild && (!instantaspTree[treeId].RootNode.equals(n) || incPr)) {
            instantaspTree[treeId].collapseNode(n.NodeID);
        }
    });
}

InstantASPTree.prototype.checkNode = function(inTreeID) {
    var nd = iasp_FindControl("cb_" + inTreeID);
     var treeId = this.TreeID;
    var sNd = this.NodeList[inTreeID];
    sNd.Checked = nd.checked;
    this.populateHiddenField();
}

InstantASPTree.prototype.populateHiddenField = function() {

    if (this.Options.InputHiddenID == null) { return; }

    var txt = iasp_FindControl(this.Options.InputHiddenID);
    if (txt != null) {
        txt.value = '';
        this.loopTree(this.RootNode, function(n) {
            if (n.Checked) {
                txt.value += n.CategoryID + ",";
            }
        }
        );
    }
}

InstantASPTree.prototype.populateCheckedNodes = function() {

    if (this.Options.InputHiddenID == null) { return; }

    var txt = iasp_FindControl(this.Options.InputHiddenID);
    if (txt != null) {
        if (txt.value == "") { return; }
        var arrIds = txt.value.split(",");
        if (arrIds.length == 0) { alert("no"); }
        this.loopTree(this.RootNode, function(n) {
            n.Checked = false;
            for (var i = 0; i < arrIds.length; i++) {
                if (arrIds[i] == n.CategoryID) {
                    n.Checked = true;
                }
            }
        }
        );

    }
}

InstantASPTree.prototype.setNodeStyle = function(id, cls, rt) {
    var nd = this.getNodeById(id); nd.cstStyle = cls;
    if (rt) {
        var oNd = iasp_FindControl("cstl_" + nd.ID);
        if (oNd) { oNd.className = cls; }
    }
}

InstantASPTree.prototype.setNodeText = function(id, Text) {
    var inTreeID = this.genIntTreeID(id);
    var nd = iasp_FindControl("ac_" + inTreeID);
    var sNd = this.NodeList[inTreeID];
    nd.innerHTML = Text;
    sNd.Text = Text;
}

InstantASPTree.prototype.getNodeById = function(id) {
    return this.NodeList[this.genIntTreeID(id)];
}

InstantASPTree.prototype.setGlobalCtxMenu = function(ctx) {
    this.ContextMenu = ctx;
    ctx.container = this;
}

InstantASPTree.prototype.setGlobalTransition = function(transition) {
    this.Transition = transition;
    transition.Container = this;
}

InstantASPTree.prototype.setNodeCtxMenu = function(id, ctx) {
    var nd = this.NodeList[this.genIntTreeID(id)];
    nd.ContextMenu = ctx;
    if (ctx.mId) { ctx.container = this; }
}

InstantASPTree.prototype.contextMenu = function(ev, id) {
    if (!this.Options.EnableContext) { return false; }
    var sNd = this.NodeList[id];
    var ctx = null;
    if (sNd.ContextMenu && sNd.ContextMenu.mId) { ctx = sNd.ContextMenu; }
    else if (sNd.ContextMenu == "DEFAULT") { ctx = null; }
    else if (sNd.ContextMenu == "NONE") { return false; }
    else { ctx = this.ContextMenu; }
    if (!ctx) { return true; }
    this.selectNode(id);
    if (this.EditId) clearTimeout(this.EditId);

    ctx.showMenu(ev.clientX, ev.clientY);
    return false
}

InstantASPTree.prototype.loopTree = function(sNd, act) {
    act(sNd);
    if (sNd.FirstChild != null) {
        var chNode = sNd.FirstChild;
        do {
            this.loopTree(chNode, act);
            chNode = chNode.NextNode
        }
        while (chNode != null)
    }

}

InstantASPTree.prototype.liveNodeEditStart = function(id) {
    this.EditId = setTimeout("instantaspTree." + this.TreeID + ".liveNodeEdit('" + id + "')", 0)
}

InstantASPTree.prototype.liveNodeEdit = function(id) {
    if (this.EditId != null) {
        var edt = iasp_FindControl("ndedt" + this.TreeID);
        var ac = iasp_FindControl("ac_" + id);
        var sp = iasp_FindControl("cstl_" + id);
        var x = 0, y = 0, elm = ac;
        while (elm.tagName != "BODY") {
            x += elm.offsetLeft;
            y += elm.offsetTop; elm = elm.offsetParent
        };
        ac.style.display = "none";
        with (edt) {
            disabled = false;
            style.top = y + "px";
            style.left = x + "px";
            style.display = "";
            focus();
            value = sp.innerHTML;
            select();
        }
        this.EditId = null
    }
}

InstantASPTree.prototype.liveNodeWrite = function() {
    var edt = iasp_FindControl("ndedt" + this.TreeID);

    if (edt.style.display == "none") { return; }
    var node = iasp_FindControl("ac_" + this.SelectedNode.ID);
    var ac = iasp_FindControl("cstl_" + this.SelectedNode.ID);
    // do we have a new value 
    if (edt.value != "") {
        ac.innerHTML = edt.value;
        this.SelectedNode.Text = edt.value;
        this.treeOnNodeWrite(this)
        edt.style.display = "none";
        node.style.display = "";
        edt.disabled = true;


        // refresh parent node
        if (this.SelectedNode != null) {
            if (this.SelectedNode.ParentNode != null) {
                this.SelectedNode.ParentNode.Expanded = false;
                this.toggleNode(this.SelectedNode.ParentNode.ID)

            }
        }
    }

}

InstantASPTree.prototype.liveNodePress = function(e) {
    if (!this.Options.Editable) { return; }
    if (e.keyCode == 13) {
        this.liveNodeWrite();
    } else if (e.keyCode == 27) {
        var edt = iasp_FindControl("ndedt" + this.TreeID);
        edt.style.display = "none";
        edt.disabled = true
    } else if (e.keyCode == this.Options.EditKey) {
        this.EditId = setTimeout("instantaspTree." + this.TreeID + ".liveNodeEdit('" + this.SelectedNode.ID + "')", 10);
    }
}

InstantASPTree.prototype.setCookie = function(key, value, expire) {
    document.cookie = escape(key) + "=" + escape(value) + (expire ? "; expires=" + expire : "");
}

InstantASPTree.prototype.getCookie = function(key) {
    if (document.cookie) {
        var c = document.cookie.split(";")[0].split("=");
        if (unescape(c[0]) == key) { return unescape(c[1]); }
    }
    return ""
}

InstantASPTree.prototype.removeCookie = function() { this.setCookie(this.TreeID + "_selnd", "-1", "Fri, 31 Dec 1999 23:59:59 GMT;"); };
InstantASPTree.prototype.treeOnClick = function(e) { };
InstantASPTree.prototype.treeOnDblClick = function(e) { };
InstantASPTree.prototype.treeOnMouseOver = function(e) { };
InstantASPTree.prototype.treeOnMouseMove = function(e) { };
InstantASPTree.prototype.treeOnMouseOut = function(e) { };
InstantASPTree.prototype.treeOnMouseDown = function(e) { };
InstantASPTree.prototype.treeOnMouseUp = function(e) { };
InstantASPTree.prototype.treeOnCheck = function(id) { };
InstantASPTree.prototype.treeOnExpand = function(id) { };
InstantASPTree.prototype.treeOnResize = function(id) { };

InstantASPTree.prototype.treeOnCollapse = function(id) { };
InstantASPTree.prototype.treeOnNodeWrite = function(tree) { };


function preloadIcon() {
    var arg = preloadIcon.arguments;
    for (var i = 0; i < arg.length; i++) {
        if (!instantaspTreeIc[arg[i]]) { instantaspTreeIc[arg[i]] = new Image(); instantaspTreeIc[arg[i]].src = arg[i] }
    }
}


// common UI elements

instantaspcommonui = new Object();

function InstantASPCommonUI(strImgFolder) {

    // public properties
    this.imgFolder = strImgFolder;
    this._sfloat = null;

    if (document.all) {
        this._sfloat = "styleFloat"; //ie
    } else {
        this._sfloat = "cssFloat"; //ff
    }

    if (instantaspcommonui[strImgFolder] != null) {
        return instantaspcommonui[strImgFolder];
    } else {
        instantaspcommonui[strImgFolder] = this;
    }

    return this;

}

// build table cell

InstantASPCommonUI.prototype.buildTD = function(strClass, strWidth, strAlign, objControl, intColSpan) {

    var td = document.createElement("TD");
    if (strClass != null) { td.className = strClass; };
    if (strWidth != null) { td.style.width = strWidth; };
    if (strAlign != null) { td.align = strAlign; };
    if (intColSpan != null) { td.setAttribute('colSpan', intColSpan) };
    if (objControl != null) { td.appendChild(objControl); };
    return td;

}

// build select list

InstantASPCommonUI.prototype.buildSelect = function(strClass, strWidth, arrValues) {

    var objSelect = document.createElement("SELECT");
    if (strClass != null) {
        objSelect.className = strClass;
    } else {
        objSelect.className = "FormInputDropDown";
    }

    if (strWidth != null) {
        objSelect.style.width = strWidth;
    }

    if (arrValues != null) {

        for (i = 0; i < arrValues.length; i++) {

            var arrValue = arrValues[i];
            var objOption = document.createElement("OPTION");
            objOption.text = arrValue[1];
            objOption.value = arrValue[2];
            this.AddOptToSelect(objSelect, objOption);

        }

    } else {

        var objOption = document.createElement("OPTION");
        objOption.text = "No data";
        objOption.value = "0";
        this.AddOptToSelect(objSelect, objOption);

    }

    return objSelect;

}

// add option to select

InstantASPCommonUI.prototype.AddOptToSelect = function(select, option) {

    if (document.all && !window.opera) {
        select.add(option);
    } else {
        select.add(option, null);
    }

}

// search textbox

InstantASPCommonUI.prototype.buildSearchTxtBox = function(txtTextBox, butSubmit, butOptions) {
   
    var div1 = document.createElement("div");
    div1.className = "input_BG";

    var div2 = document.createElement("div");
    div2.className = "input_BGLeft";

    var div3 = document.createElement("div");
    div3.className = "input_BGContainer";

    var div4 = document.createElement("div");
    div4.className = "input_BGContainerBG";

    div1.appendChild(div2);
    div2.appendChild(div3);
    div3.appendChild(div4);

    // setup textbox

    var div5 = document.createElement("div");
    div5.className = "text-field";
    if (butOptions != null) {
        div5.style.width = "65%";
    }

    if (txtTextBox != null) {
    
        // catch enter button
        addEvent(txtTextBox, "keydown", function(e) {
            return catchKeyDown(butSubmit.id, e);
        }
        );


//        txtTextBox.onkeypress =  function() { 
//        var key; 
//        if (window.event) 
//        {key = window.event.keyCode;} 
//        else 
//        {key = e.which;} 
//        if (key == 13) 
//        {return false;} 
//        else 
//        {return true;}
//        
//        };
           
        
        

        div5.appendChild(txtTextBox);

    }

    // setup search button

    var div6 = document.createElement("div");
    div6.className = "button-field";


    if (butSubmit != null) {
        div6.appendChild(butSubmit);
    }

    // setup show forums button

    var div7 = null;
    if (butOptions != null) {
        div7 = this.buildSimpleMenuLink(butOptions);
        div7.className = "button-catfield";
    }


    // add search options to div

    div4.appendChild(div5);
    div4.appendChild(div6);

    if (div7 != null) { div4.appendChild(div7); }

    return div1;

}

InstantASPCommonUI.prototype.buildSimpleMenuLink = function(ctl) {

    var div = document.createElement("span");

    if (ctl != null) {
        div.setAttribute("id", ctl.id + "_smMenuContainer");
        div.appendChild(ctl);
    }

    return div;

}

// rounded tab le

InstantASPCommonUI.prototype.buildRoundedTable = function(title, div) {

    var strPadding = "12px";

    // build table

    var tbl = document.createElement("TABLE");
    tbl.style[this._sfloat] = "left";
    tbl.style.width = "100%";
    tbl.className = "rt_tbl"
    tbl.setAttribute("cellPadding", "0px")
    tbl.setAttribute("cellSpacing", "0px")

    var tBody = document.createElement("TBODY");

    tbl.appendChild(tBody);

    // ---------------- top row

    var row = document.createElement("TR");

    // top left 

    var img = document.createElement("IMG");
    img.src = this.imgFolder + "Common/RoundedTable/tbl_topleft.gif";
    img.style.display = "block";

    var td1 = this.buildTD("rt_Edge", null, null, img)
    row.appendChild(td1);

    // top

    var div1 = document.createElement("DIV");
    div1.className = "hLight"
    div1.appendChild(document.createTextNode(title));

    var td2 = this.buildTD("rt_Top", null, null, div1)
    row.appendChild(td2);

    // top right 

    var img = document.createElement("IMG");
    img.src = this.imgFolder + "Common/RoundedTable/tbl_topright.gif";
    img.style.display = "block";

    var td3 = this.buildTD("rt_Edge", null, null, img)
    row.appendChild(td3);

    tBody.appendChild(row);

    // ---------------- middle row

    var row = document.createElement("TR");

    // middle left 

    var td4 = this.buildTD("rt_Left", null, null, document.createElement("DIV"))
    row.appendChild(td4);

    // create container table

    var tblContent = document.createElement("TABLE");
    tblContent.style.width = "100%";
    tblContent.setAttribute("cellPadding", strPadding);
    tblContent.setAttribute("cellSpacing", "0px");

    var tBodyContent = document.createElement("TBODY");
    tblContent.appendChild(tBodyContent);

    var rowContent = document.createElement("TR");

    var tdContent = this.buildTD(null, null, null, div)
    rowContent.appendChild(tdContent);

    tBodyContent.appendChild(rowContent);

    var td5 = this.buildTD(null, null, null, tblContent)

    row.appendChild(td5);

    // middle right  

    var td6 = this.buildTD("rt_Right", null, null, document.createElement("DIV"))
    row.appendChild(td6);

    tBody.appendChild(row);

    // ---------------- bottom row

    var row = document.createElement("TR");

    // bottom left 

    var img = document.createElement("IMG");
    img.src = this.imgFolder + "Common/RoundedTable/tbl_bottomleft.gif";
    img.style.display = "block";

    var td7 = this.buildTD("rt_Edge", null, null, img)
    row.appendChild(td7);

    // bottom                          

    var td8 = this.buildTD("rt_Bottom", null, null, document.createElement("DIV"));
    row.appendChild(td8);

    // bottom right 

    var img = document.createElement("IMG");
    img.src = this.imgFolder + "Common/RoundedTable/tbl_bottomright.gif";
    img.style.display = "block";

    var td9 = this.buildTD("rt_Edge", null, null, img)
    row.appendChild(td9);

    tBody.appendChild(row);

    return tbl;

}

// sort order drop down list

InstantASPCommonUI.prototype.buildSortOrderDropDown = function() {

    var arr = new Array(2);
    for (i = 0; i < arr.length; i++) {
        arr[i] = new Array(2);
    }

    arr[0][1] = "in: DESC order";
    arr[0][2] = "1";
    arr[1][1] = "in: ASC order";
    arr[1][2] = "2";

    return this.buildSelect(null, null, arr);


}

// records per page drop down list

InstantASPCommonUI.prototype.buildRecordsPerPageDropDown = function() {

    var arr = new Array(4);
    for (i = 0; i < arr.length; i++) {
        arr[i] = new Array(2);
    }

    arr[0][1] = iasp_PageSize.replace("[0]","10");
    arr[0][2] = "10";
    arr[1][1] = iasp_PageSize.replace("[0]", "20");
    arr[1][2] = "20";
    arr[2][1] = iasp_PageSize.replace("[0]", "50");
    arr[2][2] = "50";
    arr[3][1] = iasp_PageSize.replace("[0]", "100");
    arr[3][2] = "100";

    return this.buildSelect(null, null, arr);

}


// search type drop down list

InstantASPCommonUI.prototype.buildSearchTypeDropDown = function() {

    var arr = new Array(3);
    for (i = 0; i < arr.length; i++) {
        arr[i] = new Array(2);
    }

    arr[0][1] = iasp_SearchUsing1;
    arr[0][2] = "1";
    arr[1][1] = iasp_SearchUsing2;
    arr[1][2] = "2";
    arr[2][1] = iasp_SearchUsing3;
    arr[2][2] = "3";

    return this.buildSelect(null, null, arr);

}

InstantASPCommonUI.prototype.setAttribute = function(node, attr, value) {

    if (value == null || node == null || attr == null) return;
    if (attr.toLowerCase() == "style") {
        this.setStyleAttribute(node, value);
    }
    else {
        node.setAttribute(attr, value);
    }

}

InstantASPCommonUI.prototype.setStyleAttribute = function(node, style) {

    if (style == null) return;
    var styles = style.split(";");
    var pos;
    for (var i = 0; i < styles.length; i++) {
        var attributes = styles[i].split(":");
        if (attributes.length == 2) {
            try {
                var attr = this.trim(attributes[0]);
                while ((pos = attr.search(/-/)) != -1) {
                    var strBefore = attr.substring(0, pos);
                    var strToUpperCase = attr.substring(pos + 1, pos + 2);
                    var strAfter = attr.substring(pos + 2, attr.length);
                    attr = strBefore + strToUpperCase.toUpperCase() + strAfter;
                }
                var value = this.trim(attributes[1]).toLowerCase();
                node.style[attr] = value;
            }
            catch (e) {
                alert(e);
            }
        }
    }
}

InstantASPCommonUI.prototype.trim = function(str) {
    return str.replace(/^\s*|\s*$/g, "");
}

// transitions

var fadetimer = false;
var timerloopback = 1;
var dtCurrentTime;

instantaspTransition = new Object();

function InstantASPTransition(transitionid) {
    this.TransitionID = transitionid;
    this.ExpandSlide = 0;
    this.ExpandSlideDuration = 200;
    this.ExpandTransition = 12;
    this.ExpandTransitionDuration = 175;
    this.CollapseSlide = 0;
    this.CollapseSlideDuration = 200;
    this.CollapseTransition = 12;
    this.CollapseTransitionDuration = 175;
    this.UseFade = false;
    this.FadeIncrement = 25;
    this.Container = null;
    if (instantaspTransition[this.TransitionID] != null) {
        return instantaspTransition[this.TransitionID];
    } else {
        instantaspTransition[this.TransitionID] = this;
    }
    return this;
}

InstantASPTransition.prototype.ExpandDiv = function(obj) {

    if (obj != null) {

        obj.style.overflow = 'hidden';
        obj.style.display = '';

        if (this.ExpandSlide > 0) {
            dtCurrentTime = (new Date()).getTime();
            ExpandDivSlide(iasp_GetObjHeight(obj), this.ExpandSlideDuration, this.ExpandSlide, obj.id);
        }

        if (this.ExpandTransition > 0) {
            obj.style.filter = InitializeFilter(this.ExpandTransition, this.ExpandTransitionDuration);
            if (obj.filters && obj.filters[0]) {
                obj.style.visibility = 'hidden';
                obj.filters[0].apply();
                obj.style.visibility = 'visible';
                obj.filters[0].play();
            }
        } else {
            obj.style.visibility = 'visible'
        }

        if (this.UseFade) { doFade(obj, this.FadeIncrement); }

    }

}

InstantASPTransition.prototype.CollapseDiv = function(obj) {

    if (obj != null) {

        obj.style.overflow = 'hidden';

        if (this.CollapseSlide > 0) {
            if (this.CollapseSlide > 0) {
                dtCurrentTime = (new Date()).getTime();
                CollapseDivSlide(iasp_GetObjHeight(obj), this.CollapseSlideDuration, this.CollapseSlide, obj.id);
            }
        } else {
            obj.style.display = 'none';
        }
    
        if (this.UseFade) { doFade(obj, this.FadeIncrement); }

    }

}

    function ExpandDivSlide(height, slideduration, slidetype, id) {
    var obj = iasp_FindControl(id);
    var slidetimer = (new Date()).getTime() - dtCurrentTime;
    var slideincrement = InitializeSlide(slidetimer, slideduration, slidetype);
    if (slideincrement == 1) {
        obj.style.height = height + 'px';
        obj.style.overflow = 'visible';
        obj.style.height = '';
        obj = null;
    } else {
        obj.style.height = Math.max(1, Math.floor(height * slideincrement)) + 'px';
        setTimeout('ExpandDivSlide(' + height + ',' + slideduration + ',' + slidetype + ',"' + id + '");', timerloopback);
    };
}

function CollapseDivSlide(height, slideduration, slidetype, id) {
    var obj = iasp_FindControl(id);
    var slidetimer = (new Date()).getTime() - dtCurrentTime;
    var slideincrement = InitializeSlide(slidetimer, slideduration, slidetype);
    if (slideincrement == 1) {
        obj.style.display = 'none'; obj = null;
    } else {
        obj.style.height = Math.ceil((1 - slideincrement) * height) + 'px';
        setTimeout('CollapseDivSlide(' + height + ',' + slideduration + ',' + slidetype + ',"' + id + '");', timerloopback);
    };
}

function InitializeFilter(transition, duration) {
    var s; if (iasp_BrowserVer < 5.5) {
        if (transition = 37) { transition = parseInt(23 * Math.random()); }
        s = "revealTrans(Transition=" + transition + ",Duration=" + (duration / 1000) + ");";
    } else {
        if (transition == 37) { transition = parseInt(36 * Math.random()); }
        s = "progid:DXImageTransform.Microsoft." + GetFilter(transition);
        s = s.replace(')', 'Duration=' + (duration / 1000) + ');');
    }
    return s;
}

function InitializeSlide(slidetimer, slideduration, slidetype) {
    if (slidetype == 0 || slidetimer >= slideduration) { return 1; };
    if (slidetype == 1) { slidetimer = slideduration - slidetimer; };
    var intMod = slidetimer / slideduration;
    var intReturn;
    switch (slidetype) {
        case 1: intReturn = 1 - Math.pow(1 / 300, intMod); break;
        case 2:
        case 3: intReturn = intMod; break;
    };
    if (slidetype == 1) { intReturn = 1 - intReturn; };
    return Math.min(Math.max(0, intReturn), 1);
};

function GetFilter(transition) {
    switch (transition) {
        case 0: return "Iris(irisStyle=SQUARE,motion=in,)";
        case 1: return "Iris(irisStyle=SQUARE,motion=out,)";
        case 2: return "Iris(irisStyle=CIRCLE,motion=in,)";
        case 3: return "Iris(irisStyle=CIRCLE,motion=out,)";
        case 4: return "Wipe(GradientSize=1.0,wipeStyle=1,motion=reverse,)";
        case 5: return "Wipe(GradientSize=1.0,wipeStyle=1,motion=forward,)";
        case 6: return "Wipe(GradientSize=1.0,wipeStyle=0,motion=forward,)";
        case 7: return "Wipe(GradientSize=1.0,wipeStyle=0,motion=reverse,)";
        case 8: return "Blinds(bands=8,direction=RIGHT,)";
        case 9: return "Blinds(bands=8,direction=DOWN,)";
        case 10: return "Checkerboard(squaresX=16,squaresY=16,direction=right,)";
        case 11: return "Checkerboard(squaresX=12,squaresY=12,direction=down,)";
        case 12: return "RandomDissolve()";
        case 13: return "Barn(orientation=vertical,motion=in,)";
        case 14: return "Barn(orientation=vertical,motion=out,)";
        case 15: return "Barn(orientation=horizontal,motion=in,)";
        case 16: return "Barn(orientation=horizontal,motion=out,)";
        case 17: return "Strips(Motion=leftdown,)";
        case 18: return "Strips(Motion=leftup,)";
        case 19: return "Strips(Motion=rightdown,)";
        case 20: return "Strips(Motion=rightup,)";
        case 21: return "RandomBars(orientation=horizontal,)";
        case 22: return "RandomBars(orientation=vertical,)";
        case 23: return "Fade(overlap=.5,)";
        case 24: return "Wheel(spokes=16,)";
        case 25: return "Slide(slideStyle=hide,bands=15,)";
        case 26: return "Slide(slideStyle=swap,bands=15,)";
        case 27: return "Inset()";
        case 28: return "Pixelate(MaxSquare=15,)";
        case 29: return "Stretch(stretchStyle=hide,)";
        case 30: return "Stretch(stretchStyle=spin,)";
        case 31: return "Iris(irisStyle=cross,motion=in,)";
        case 32: return "Iris(irisStyle=cross,motion=out,)";
        case 33: return "Iris(irisStyle=plus,motion=in,)";
        case 34: return "Iris(irisStyle=plus,motion=out,)";
        case 35: return "Iris(irisStyle=star,motion=in,)";
        case 36: return "Iris(irisStyle=star,motion=out,)";
    };
    return null;
}

function doFade(obj, fadeincrement) {
    if (obj.filters != null && obj.style.filter.indexOf("alpha") == -1) {
        obj.style.filter = "alpha(opacity=0); moz-opacity:0%;"
    }
    FadeIn(obj.id, 0, fadeincrement);
}

function FadeIn(id, opac, fadeincrement) {
    obj = iasp_FindControl(id);
    if (opac <= 100) {
        opac += fadeincrement;
        if (iasp_IE4 || iasp_IE5) { obj.filters.alpha.opacity = opac; }
        if (iasp_NS6) { obj.style.MozOpacity = opac / 100; }
        fadetimer = setTimeout("FadeIn('" + id + "', " + opac + "," + fadeincrement + ");", timerloopback);
    } else {
        clearTimeout(fadetimer)
    }
}

// Json Table

instantaspjsontable = new Object();

function InstantASPJSONTable(strTableID) {

    this.TableID = strTableID;
    this.jsonproxy = null;
    this.Host = null;
    this.commonUI = null;
    this.useCols = false;
    this.noOfCols = 1;
    this.loading = false;
    this.rightToLeft = false;
    
    if (instantaspjsontable[this.TableID] != null) {
        return instantaspjsontable[this.TableID];
    } else {
        instantaspjsontable[this.TableID] = this;
    }
    return this;

}

InstantASPJSONTable.prototype.initalize = function() {

    if (this.commonUI == null) { this.commonUI = new InstantASPCommonUI(); }

    // show loader whist we build the table
    this.showLoader();

    this.buildTable();

    this.hideLoader();

}

InstantASPJSONTable.prototype.buildTable = function() {

    // get table header
    var tHead = this.getTableHead();

    // rause bind data event to get data
    var data = this.BindData(this.Host);

    // add table row to header
    if (data != null) {
        if (this.OnHeaderRowAdd != null) {

            var row = this.addHeaderRow();
            var tempRow = null;

            if (tempRow != null) {
                tHead.appendChild(tempRow);
            } else {
                tHead.appendChild(row);
            }

        }
    }

    if (this.BindData != null) {

        if (this.useCols == false) {
            this.buildRowsFromData(data);
        } else {
            this.buildColsFromData(data);
        }

    }

    this.loading = false;

}

InstantASPJSONTable.prototype.buildRowsFromData = function(data) {

    var tBody = this.getTableBody();
    var rightToLeft = true;

    // build our data rows
    if (data != null) {

        for (var i = 0; i < data.length; i++) {
            if (typeof data[i].Seperator == 'undefined') {

                var row = this.addRow(data[i], i);
                var tempRow = null;

                if (tempRow != null) {
                    tBody.appendChild(tempRow);
                } else {
                    tBody.appendChild(row);
                }

            } else {
                if (this.OnSeperatorRowAdd != null) {
                    tBody.appendChild(this.addSeperatorRow(data[i]));
                }
            }
        }

    } else {

        tBody.appendChild(this.buildNoResults());

    }

}

InstantASPJSONTable.prototype.buildColsFromData = function(data) {

    var tBody = this.getTableBody();

    // build our data rows
    if (data != null) {

        for (var i = 0; i < data.length; i++) {
            if (i % this.noOfCols == 0) {
                var row = document.createElement("TR");
            }
            row.appendChild(this.addCol(data[i], i));
            if (i % this.noOfCols == this.noOfCols - 1) {
                tBody.appendChild(row)
            }
        }
        if (i % this.noOfCols != 0) {
            tBody.appendChild(row)
        }

    } else {
        tBody.appendChild(this.buildNoResults());
    }

}

InstantASPJSONTable.prototype.buildNoResults = function() {

    // get header columns
    var intColSpan = (this.getTableHead().getElementsByTagName("TD").length - 1);

    // cell css
    var strCssLight = "TableCell_Light";

    // create row
    var row = document.createElement("TR");

    // create label
    var span = document.createElement("SPAN");
    span.appendChild(document.createTextNode(iasp_NoResults));

    // create column
    var td = this.commonUI.buildTD(strCssLight, "100%", null, span, intColSpan)

    // add column to row
    row.appendChild(td);

    // update loading status
    this.loading = false;

    // return row
    return row;


}

InstantASPJSONTable.prototype.clearTable = function() {

    this.clearHeader();
    this.clearBody();

}

InstantASPJSONTable.prototype.clearHeader = function() {

    var tHead = this.getTableHead();
    var rows = tHead.getElementsByTagName("TR");

    // ensure we never remove the first row  
    for (i = rows.length - 1; i >= 1; i--) {
        tHead.removeChild(rows[i]);
    }

}

InstantASPJSONTable.prototype.clearBody = function() {

    var tBody = this.getTableBody();
    var rows = tBody.getElementsByTagName("TR");

    // ensure we never remove the first row
    for (i = rows.length - 1; i >= 1; i--) {
        tBody.removeChild(rows[i]);
    }

}

InstantASPJSONTable.prototype.showLoader = function() {

    var trLoader = this.getLoader();
    trLoader.style.display = '';
    
    // update loading status
    this.loading = true;
    
}

InstantASPJSONTable.prototype.hideLoader = function() {

    var trLoader = this.getLoader();
    trLoader.style.display = 'none';
    
    // update loading status
    this.loading = false;

}

InstantASPJSONTable.prototype.getTable = function() {
    return iasp_FindControl(this.TableID);
}

InstantASPJSONTable.prototype.getTableHead = function() {
    return this.getTable().getElementsByTagName("THEAD")[0];
}

InstantASPJSONTable.prototype.getTableBody = function() {
    return this.getTable().getElementsByTagName("TBODY")[0];
}

InstantASPJSONTable.prototype.getLoader = function() {
    return this.getTableBody().getElementsByTagName("TR")[0];
}

InstantASPJSONTable.prototype.addHeaderRow = function() {
    // raise event so we can build the table tow
    return this.OnHeaderRowAdd(this.Host);
}

InstantASPJSONTable.prototype.addRow = function(data, index) {
    // raise event so we can build the table tow
    return this.OnRowAdd(this.Host, data, index);
}

InstantASPJSONTable.prototype.addSeperatorRow = function(data) {
    // raise event so we can build the table tow
    return this.OnSeperatorRowAdd(this.Host, data);
}

InstantASPJSONTable.prototype.addCol = function(data, index) {
    // raise event so we can build the table tow
    return this.OnColAdd(this.Host, data, index);
}

InstantASPJSONTable.prototype.BindData = function(host) { };
InstantASPJSONTable.prototype.OnHeaderRowAdd = function() { };
InstantASPJSONTable.prototype.OnRowAdd = function(host, data, index) { };
InstantASPJSONTable.prototype.OnSeperatorRowAdd = null // function(host, data) { };
InstantASPJSONTable.prototype.OnColAdd = function(host, data, index) { };

/* ---------------*/
// helpers
/* ---------------*/

// Get a reference to an object on the client                   

function iasp_FindControl(strControlName) {
    if (strControlName == null || strControlName == "") {return null;}
    if (iasp_IE5 || iasp_NS6 || iasp_Opera || iasp_Opera8)
    { return document.getElementById(strControlName); }
    else if (iasp_IE4) { return document.all[strControlName]; }
    else if (iasp_NS4) { return document.layers[strControlName]; }

}

function InstantASP_FindControl(id) {
    return iasp_FindControl(id);
}


// XmlHttpRequest    

function iasp_XmlHttpRequest() {
    var XmlHttp, bComplete = false;
    try { XmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) {
        try { XmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) {
            try { XmlHttp = new XMLHttpRequest(); }
            catch (e) { XmlHttp = false; }
        }
    }
    if (!XmlHttp) return null;

    this.Connect = function(sURL, sMethod, sVars, oEvent) {
        if (!XmlHttp) return false;
        bComplete = false;
        sMethod = sMethod.toUpperCase();

        try {
            if (sMethod == "GET") {
                XmlHttp.open(sMethod, sURL + "?" + sVars, true);
                sVars = "";
            } else {
                XmlHttp.open(sMethod, sURL, true);
                XmlHttp.setRequestHeader("Method", "GET " + sURL + " HTTP/1.1");
                XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            }
            XmlHttp.onreadystatechange = function() {
                if (XmlHttp.readyState == 4 && XmlHttp.status == 200 && !bComplete) {
                    bComplete = true; oEvent(XmlHttp);
                }
            };
            XmlHttp.send(sVars);
        } catch (e) { return false; }
        return true;
    };
    return this;
}


function iasp_scrollToDiv(divid) {

    // scroll to div
    var div = iasp_FindControl(divid);
    if (div != null) {
        if (div.offsetTop > 16) {
            window.scroll(0, iasp_absOffset(div) - 16);
        } else {
            window.scroll(0, 0);
        }
    }
}

function iasp_absOffset(div) {
    return div.offsetParent && div.offsetTop + iasp_absOffset(div.offsetParent);
}


// expand / collapse a single panel bar

var iasp_transition = null;

function iasp_pbToggle(strTrId, strImgId, strSkin, strCkiePrefix, strCkieName, bolState, strExImg, strColImg, strGroupName) {

    objContent = iasp_FindControl(strTrId);
    objImage = iasp_FindControl(strImgId);

    if (iasp_transition == null) {
        iasp_transition = new InstantASPTransition;
        iasp_transition.UseFade = false;
        iasp_transition.ExpandSlide = 2;
        iasp_transition.CollapseSlide = 2;
        iasp_transition.ExpandTransition = -1;
        iasp_transition.CollapseTransition = -1;
    }


    if (objContent.style.display == "none") { // expand

        // should we collpase the rest of the group
        if (strGroupName != "") {
            iasp_PanelBarGroupToggle(strGroupName, strCkiePrefix, strCkieName, 0, strSkin);
        }

        // display controls
        if (objImage != null) { objImage.src = strSkin + strColImg; }

        if (iasp_transition != null) {
            objContent.style.height = '';
            iasp_transition.ExpandDiv(objContent);

        } else {
            objContent.style.display = "block";
        }

        // update cookie
        if (bolState) { iasp_UpdateCookie(strTrId, false, strCkiePrefix + strCkieName); }
        else { iasp_UpdateCookie(strTrId, true, strCkiePrefix + strCkieName); }

    } else { // collapse

        // hide controls
        if (objImage != null) { objImage.src = strSkin + strExImg; }

        if (iasp_transition != null) {
            objContent.style.height = '';
            iasp_transition.CollapseDiv(objContent);

        } else {
            if (objContent != null) { objContent.style.display = "none"; }
        }


        // update cookie
        if (bolState) { iasp_UpdateCookie(strTrId, true, strCkiePrefix + strCkieName); }
        else { iasp_UpdateCookie(strTrId, false, strCkiePrefix + strCkieName); }

    }
}

// expand / collapse a group of panel bars

function iasp_PanelBarGroupToggle(strGroupName, strCkiePrefix, strCkieName, bolState, strSkin, strExImg, strColImg) {

    if (iasp_IsIE || iasp_Opera || iasp_NS6) {

        if (iasp_transition == null) {
            iasp_transition = new InstantASPTransition;
            iasp_transition.UseFade = false;
            iasp_transition.ExpandTransition = -1;
            iasp_transition.CollapseTransition = -1;
        }


        // toggle all divs matching object name
        tr = document.getElementsByTagName("DIV");
        for (var i = 0; i < tr.length; i++) {
            if (tr[i].id.indexOf(strGroupName) >= 0) {
                if (bolState) {

                    if (iasp_transition != null) {
                        tr[i].style.height = '';
                        iasp_transition.ExpandDiv(tr[i]);
                    } else {
                        tr[i].style.display = "block";
                    }

                    if (strCkieName != "") {
                        iasp_UpdateCookie(tr[i].id, true, strCkiePrefix + strCkieName);
                    }

                } else {

                    tr[i].style.display = "none";

                    if (strCkieName != "") {
                        iasp_UpdateCookie(tr[i].id, false, strCkiePrefix + strCkieName);
                    }
                }

            }
        }

        // change all images matching object name
        input = document.getElementsByTagName("img");
        for (var i = 0; i < input.length; i++) {
            if (input[i].id.indexOf(strGroupName) >= 0) {
                if (bolState)
                { input[i].src = strSkin + "Images/Misc_Collapse.gif"; }
                else
                { input[i].src = strSkin + "Images/Misc_Expand.gif"; }
            }
        }
    }
}


// Retrieve text of an XML document element, including elements using namespaces

function iasp_GetElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && iasp_IE4 || iasp_IE5) {
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        result = parentElem.getElementsByTagName(local)[index];
    }

    if (result) {
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;
        }
    } else {
        return "";
    }
}

// encode a string for including within a URL      

function iasp_EncodeString(s) {
    if (!s) { return ''; }
    s = s.replace(/\+/g, '%2B');
    s = s.replace(/\"/g, '%22')
    s = s.replace(/\'/g, '\'')
    return encodeURI(s);
}

function iasp_EscapeXML(s) {
    if (!s) { return ''; }
    s = s.replace("&", '&amp;');
    s = s.replace("'", '&apos;');
    s = s.replace('"', '&quot;');
    s = s.replace(">", '&gt;');
    s = s.replace("<", '&lt;');
    return s;
}


function iasp_ToggleVisibility(strControlName) {
    var obj = iasp_FindControl(strControlName);

    if (obj != null) {
        if (obj.style.display == "none") {
            obj.style.display = "inline";
        } else {
            obj.style.display = "none";
        }
    }
}

function iasp_HideControl(strControlName) {
    var obj = iasp_FindControl(strControlName);
    if (obj != null) {
        obj.style.display = "none";
    }
}

function iasp_ShowControl(strControlName) {
    var obj = iasp_FindControl(strControlName);
    if (obj != null) {
        obj.style.display = "";
    }
}

function hasOptions(obj) {
    if (obj != null && obj.options != null) { return true; }
    return false;
}

function addTextBoxOption(from, to, inputhidden) {
    var value = from.value;
    var options = new Object();
    if (hasOptions(to)) {
        for (var i = 0; i < to.options.length; i++) {
            options[to.options[i].value] = to.options[i].text;
        }
    }
    if (value == "") { return; }
    if (value == null || value == "undefined" || options[value] != value) {
        if (!hasOptions(to)) { var index = 0; } else { var index = to.options.length; }
        to.options[index] = new Option(value, value, false, false);
    }
    populateValueField(to, inputhidden);
    from.value = "";
    to.selectedIndex = -1;
}

function addSelectedOptions(from, to, inputhidden) {
    var options = new Object();
    if (hasOptions(to)) {
        for (var i = 0; i < to.options.length; i++) {
            options[to.options[i].value] = to.options[i].text;
        }
    }
    if (!hasOptions(from)) { return; }
    for (var i = 0; i < from.options.length; i++) {
        var o = from.options[i];
        if (o.selected) {
            if (options[o.value] == null || options[o.value] == "undefined" || options[o.value] != o.text) {
                if (!hasOptions(to)) { var index = 0; } else { var index = to.options.length; }
                to.options[index] = new Option(o.text, o.value, false, false);
            }
        }
    }

    populateValueField(to, inputhidden);
    from.selectedIndex = -1;
    to.selectedIndex = -1;

}

function removeSelectedOptions(from, inputhidden) {
    if (!hasOptions(from)) { return; }
    if (from.type == "select-one") {
        from.options[from.selectedIndex] = null;
    }
    else {
        for (var i = (from.options.length - 1); i >= 0; i--) {
            var o = from.options[i];
            if (o.selected) {
                from.options[i] = null;
            }
        }
    }
    populateValueField(from, inputhidden);
    from.selectedIndex = -1;
}

function moveOptionUp(obj, inputhidden) {
    if (!hasOptions(obj)) { return; }
    for (i = 0; i < obj.options.length; i++) {
        if (obj.options[i].selected) {
            if (i != 0 && !obj.options[i - 1].selected) {
                swapOptions(obj, i, i - 1);
                obj.options[i - 1].selected = true;
            }
        }
    }
    populateValueField(obj, inputhidden);
}

function moveOptionDown(obj, inputhidden) {
    if (!hasOptions(obj)) { return; }
    for (i = obj.options.length - 1; i >= 0; i--) {
        if (obj.options[i].selected) {
            if (i != (obj.options.length - 1) && !obj.options[i + 1].selected) {
                swapOptions(obj, i, i + 1);
                obj.options[i + 1].selected = true;
            }
        }
    }
    populateValueField(obj, inputhidden);
}

function swapOptions(obj, i, j) {
    var o = obj.options;
    var i_selected = o[i].selected;
    var j_selected = o[j].selected;
    var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
    var temp2 = new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
    o[i] = temp2;
    o[j] = temp;
    o[i].selected = j_selected;
    o[j].selected = i_selected;
}

function populateValueField(obj, inputhidden) {

    if (!hasOptions(obj)) { return; }
    var strValues = "";
    for (i = 0; i < obj.options.length; i++) {
        strValues = strValues + obj.options[i].value + ",";
    }
    inputhidden.value = strValues;

}

function iasp_Bookmark(bmurl, bmtitle) {

    if (window.sidebar) {
        window.sidebar.addPanel(bmtitle, bmurl, "");
    } else if (document.all) {
        window.external.AddFavorite(bmurl, bmtitle);
    } else if (window.opera && window.print) {
        return true;

    }
}

// catch enter key for search forms
function catchKeyDown(butSubmitID, e) {

    var keyCode = getKeyCode(e);
    if (keyCode && keyCode == 13) {
        disableFormSubmit();    
        if (butSubmitID != null) {
            var but = iasp_FindControl(butSubmitID);
            if (but != null) {
                but.click();
            }
        }
        return false;
    } else {
        return true;
    }

}

// disable form submitting for mozilla based browsers

function disableFormSubmit() {
    var frm = document.forms[0];
    if (frm) {
        frm.onsubmit = function() { return false };
    }
}

// get keycode to catch carraige returns

function getKeyCode(e) {
    
    if  (iasp_IsIE) { 
       
        if (e != null) {
         return e.keyCode;
        } else {
            if (window.event) {
                return event.keyCode;
            } 
        }

    }
    else if (e.which) {
        return e.which;
    }
}

// global add event method

function addEvent(obj, evType, fn) {

    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return false;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}

// clear textbox default value and reset if nothing is entered

function clearTxt(txt, defaultVal, clear) {

    var strDefaultVal = "";
    if (defaultVal != null) { strDefaultVal = defaultVal; }
    if (!clear) { clear = false; }

    if (txt != null) {
        if (clear) {
            if (txt.value == strDefaultVal) {
                txt.value = "";
            }
        } else {
            if (txt.value == "") {
                txt.value = strDefaultVal;
            }
        }

    }

    return false;
}

function resetTextbox(txt, defaultVal) {

    var strDefaultVal = "";
    if (defaultVal != null) { strDefaultVal = defaultVal; }

}

// used only for user controls implementing IScriptControl interface

function refreshControl(controlID, pageIndex) {

    var pIndex = 1;
    if (pageIndex != null) {
        if (pageIndex != "" && IsNumeric(pageIndex)) {
            pIndex = pageIndex;
        } else {
            alert("You must provide a valid page number!");
            return;
        }
        iasp_HideAllMenus();
    }

    var ctl = $find(controlID);
    if (ctl != null) {
        ctl.fetchData(pIndex);
    }
}

// check to see if a string is numbers only

function IsNumeric(sText) {

    var ValidChars = "0123456789";
    var IsNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }

    return IsNumber;
}

// add commas to numbers

function formatNum(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}

// filter a string and return only numbers

function tidyInt(sInt) {

    var ValidChars = "0123456789";
    var news = "";
    var Char;

    if (sInt != null) {
        for (i = 0; i < sInt.length; i++) {
            Char = sInt.charAt(i);
            if (ValidChars.indexOf(Char) >= 0) {
                news += Char;
            }
        }
    }

    return news;
}

function checkAll(ckbId, checked) {

    var form = document.forms[0];

    for (var i = 0; i < form.length; i++) {
        var objCheckBox = form.elements[i];

        if (objCheckBox.type == 'checkbox' && objCheckBox.id.indexOf(ckbId) >= 0) {

            if (checked) {
                objCheckBox.checked = true;
            } else {
                objCheckBox.checked = false;
            }
        }
    }
}

// convert array to xml

function ObjToXml(obj, d) {

    d = (d) ? d : 0;
    var rString = "\n";
    var pad = "";

    for (var i = 0; i < d; i++) {
        pad += " ";
    }

    if (typeof obj == "object") {

        if (obj.constructor.toString().indexOf("Array") !== -1) {
            for (i = 0; i < obj.length; i++) {
                if (obj[i] != null && obj[i] != "") {
                    rString += pad + "<item>" + obj[i] + "</item>\n";
                }
            }
            rString = rString.substr(0, rString.length - 1);
        } else {

            for (i in obj) {
                if (obj[i] != null) {
                    var val = ObjToXml(obj[i], d + 1);
                    if (val == null) {
                        rString = "";
                    } else {
                        rString += ((rString === "\n") ? "" : "\n") + pad + "<" + i + ">" + val + ((typeof obj[i] === "object") ? "\n" + pad : "") + "</" + i + ">";
                    }
                }
            }
        }


    }
    else if (typeof obj == "string") {
        rString = iasp_EscapeXML(obj);
    }
    else if (typeof obj == "number") {
        rString = obj.toString();
    }
    else if (obj.toString) {
        rString = obj.toString();
    }
    else {
        return false;
    }

    return rString;

}

// convert JSON string to XML
function JsonToXml(json) {

    return eval("ObjToXml(" + json + ");");

}

function clickElement(elementid) {
    var e = iasp_FindControl(elementid);
    if (e != null) {

        if (document.createEvent) {
            var evObj = document.createEvent('MouseEvents');
            evObj.initEvent('click', true, true);
            e.dispatchEvent(evObj);
            alert('createEvent');
            return false;
        }
        else if (document.createEventObject) {
            e.fireEvent('onclick');
            alert('createEventObject');
            return false;
        }
        else {
            e.click();
            alert('click');
            return false;
        }

    }
}


// -------------------------------------------------------------------
// InstantKB.NET Specific JavaScript 
// -------------------------------------------------------------------

function ikb_SearchChecked(id) {


}


// preload images
function ikb_PreloadImages(CurrentSkin) {
	if (document.images)
	{
		arImageList = new Array ();
		var arImageSrc = new Array(CurrentSkin + "Images/Misc_Rating1.gif",
		CurrentSkin + "Images/Misc_Rating2.gif",
		CurrentSkin + "Images/Misc_Rating3.gif",
		CurrentSkin + "Images/Misc_Rating4.gif",
		CurrentSkin + "Images/Misc_Rating5.gif",
		CurrentSkin + "Images/Misc_AjaxLoading.gif");
		for (counter in arImageSrc) {
			arImageList[counter] = new Image();
			arImageList[counter].src = arImageSrc[counter];
		}
	}    
}

/* scipr to pick update enter key for simple menu search */
function ikb_SimpleSearchKeyPress(butid) {     
     
     try {
        if ((event.keyCode && event.keyCode == 13)) {
           iasp_FindControl(butid).click();
            return false;
         } else return true;
         
      } 
        catch (e) {};
             
}

/* enter we have search terms in simple menu site wide search in mainnavigation.ascx */
function ikb_SimpleSearchValidate(strKeywords) {


    if (strKeywords != "") {
        return true;
    
    } else {
        return false;
    }    
}

/* generic delete confirmation for admin pages */
function ikb_ConfirmDelete(listid, deleteenum) {

    // get drop down list
    var list = iasp_FindControl(listid);     
    if (list != null) {
        if (list.value == 0) {return false;}
        // is delete selected
        if (list.value == deleteenum)
        {   return confirm(ikb_strDeleteItemConfirmation);
        }
    }
    return true;

}



/* tab mass action button event */
function ikb_ViewTabsMassActionClick(listid, movetolistid, deleteenum, deletemoveenum) {

  // get drop down list
    var list = iasp_FindControl(listid);
    var movetolist = iasp_FindControl(movetolistid);     
    if (list != null && movetolist != null) {
        if (list.value == 0) {return false;}
        // is delete selected
        if (list.value == deleteenum)
        {   return confirm(ikb_strDeleteTabConfirmation);
        }
        else if (list.value == deletemoveenum)
            if (movetolist.value == 0) {alert(ikb_strNoNewTabSelected); return false;}
        {   return confirm(ikb_strDeleteTabMveConfirmation);
        }
    }
    return true;
}

/* show "move to tab" drop down list if you we choose to move centent when deleting tabs */
function ikb_ViewTabsMassActionSelectedIndexChanged(listid, movetolistid, deletemoveenum) {

 // get drop down list
    var list = iasp_FindControl(listid);  
    var movetolist = iasp_FindControl(movetolistid);  
    if (list != null && movetolist != null) {
          // is delete selected
        if (list.value == deletemoveenum)
        {  movetolist.style.display = '';
        }
        else {  
            movetolist.style.display = 'none';
        }
    }

}

/* ----------------------------------------------------------- */
// Article Options (Send Via Email, Social Bookmarks etc)
/* ----------------------------------------------------------- */

function ikb_SendArticleByEmail(strToEmail, strCallBackURL) {

    // check we have a email
    if (strToEmail == "") {
        alert(ikb_strEmailRequired); return;
    }

    // get url
    var arrURL = strCallBackURL.split("?");

    // setup xmlhttp
    if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
      var objXmlHttpHandler = function (obj) {
        if (obj.responseXML != null) {
            var items = obj.responseXML.getElementsByTagName("result");
            if (items.length>0) {
	            for (var i = 0; i<items.length;i++) {
		            var nd = items[i];
		            // get result
		            var identity = nd.getAttribute("identity")==null?0:nd.getAttribute("identity");
		            // end loader
		            iasp_AjaxExtensionsEndRequest();
		            // was everything ok
		            if (identity==0) {
		                alert(ikb_strSendProblem);
		            } else {
		                // hide menu
		                iasp_HideAllMenus();
		                // show alert
		                alert(ikb_strArticleSentSuccess);
		            }
	            }
            }
        }
      };
      
    // setup params
    var strParams = arrURL[1] + "&key=" + iasp_EncodeString(strToEmail);   
    // setup loader
    iasp_AjaxExtensionsInitializeRequest();
     // make request
    this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

}

/* ----------------------------------------------------------- */
// treeview context menu options
/* ----------------------------------------------------------- */

/* staff root category context menu */   
function ikb_rootNodeContextMenu(container, selNode, menuId, itemId) {

    if (container != null) {
  
        // get selected node
        var selNode =  container.getSelNode();
        
        if (selNode != null) {

            switch (itemId) {
                case "0": // add category
                    var selNodeID = selNode.NodeID;
                    container.ctx_liveAdd(selNodeID, ikb_strDefaultNodeText);
                    break;
                case "2": // expand
                    container.expandAll();
                    break;
                case "3": // collapse
                    container.collapseAll();
                    break;
            }
        }
    }
}                  

/* staff category context menu */       
function ikb_treeContextMenu(container, selNode, menuId, itemId) {

    if (container != null) {  
    
        // get selected node
        var selNode =  container.getSelNode();  
             
        if (selNode != null) {     
           
            switch (itemId) {
                case "0": // add category
                    var selNodeID = selNode.NodeID;
                    container.ctx_liveAdd(selNodeID, ikb_strDefaultNodeText);
                    break;
                case "1": // quick edit
                    container.liveNodeEditStart(selNode.ID);
                    break;
                case "2": // edit category detailed                                                   
                    if (selNode.NavigateURL.indexOf("javascript:") == -1) {
                        location = selNode.NavigateURL;
                    } else {
                     var uri = container.Options.NodeEditURL + 'StaffEditCategory' + selNode.CategoryID + '-' + container.Options.TabID + '.aspx';
                    location = uri;
                    }                  
                    break;
                case "4": // move up
                    // get orevious node
                    var dest = null; if (selNode.PrevNode != null) {dest = selNode.PrevNode;}
                    if (dest != null) {
                        // move node
                        container.moveChild(selNode, dest, 2)
                        // do callback
                        ikb_treeCallBack(container, selNode, container.Options.LiveMoveUpCallBackURL, "", "&id=" + selNode.CategoryID)
                    }
                    break;
                case "5": // move down
                    // get bext node  
                    var dest = null; if (selNode.NextNode != null) {dest = selNode.NextNode;}
                    if (dest != null) {
                        // move node
                        container.moveChild(selNode, dest, 3)
                        // do callback 
                        ikb_treeCallBack(container, selNode, container.Options.LiveMoveDownCallBackURL, "", "&id=" + selNode.CategoryID)
                    }
                    break;
                case "7": // delete 
                    // confirm delete
                    if (confirm(ikb_strDeleteCategory)) {
                        // do loader
                        iasp_AjaxExtensionsInitializeRequest();
                        // delete node
                        container.remove(); 
                        // do callback
                        ikb_treeCallBack(container, selNode, container.Options.LiveDeleteCallBackURL, ikb_strProblemDeletingCategory, "&id=" + selNode.CategoryID)
                    }     
                    break;
            } 
        }            
    }  
}

/* staff root troubleshooter context menu */   
function ikb_rootTroubleshooterNodeContextMenu(container, selNode, menuId, itemId) {

    if (container != null) {
  
        // get selected node
        var selNode =  container.getSelNode();
        
        if (selNode != null) {

            switch (itemId) {
                case "0": // add category
                    var selNodeID = selNode.NodeID;
                    container.ctx_liveAdd(selNodeID, ikb_strDefaultTroubleshooterNodeText);
                    break;
                case "2": // expand
                    container.expandAll();
                    break;
                case "3": // collapse
                    container.collapseAll();
                    break;
            }
        }
    }
}                  

/* staff troubleshooter context menu */       
function ikb_treeTroubleshooterContextMenu(container, selNode, menuId, itemId) {

    if (container != null) {  
    
        // get selected node
        var selNode =  container.getSelNode();  
             
        if (selNode != null) {     
           
            switch (itemId) {
                case "0": // add step
                    var selNodeID = selNode.NodeID;
                    container.ctx_liveAdd(selNodeID, ikb_strDefaultTroubleshooterNodeText);
                    break;
                case "1": // quick edit
                    container.liveNodeEditStart(selNode.ID);
                    break;                    
                case "2": // edut category detailed
                     if (selNode.NavigateURL.indexOf("javascript:") == -1) {
                        location = selNode.NavigateURL;
                    } else {
                    var loc = ""; loc = location.href;
                    var end = loc.indexOf("?");
                    var loc = loc.substring(0, end);
                    var uri = loc + "?StepID=" + selNode.CategoryID;
                    location = uri;
                    }          
                    break;
                case "4": // move up
                    // get orevious node
                    var dest = null; if (selNode.PrevNode != null) {dest = selNode.PrevNode;}
                    if (dest != null) {
                        // move node
                        container.moveChild(selNode, dest, 2)
                        // do callback
                        ikb_treeCallBack(container, selNode, container.Options.LiveMoveUpCallBackURL, "", "&id=" + selNode.CategoryID)
                    }
                    break;
                case "5": // move down
                    // get bext node  
                    var dest = null; if (selNode.NextNode != null) {dest = selNode.NextNode;}
                    if (dest != null) {
                        // move node
                        container.moveChild(selNode, dest, 3)
                        // do callback 
                        ikb_treeCallBack(container, selNode, container.Options.LiveMoveDownCallBackURL, "", "&id=" + selNode.CategoryID)
                    }
                    break;
                case "7": // delete 
                    // confirm delete step
                    if (confirm(ikb_strDeleteTroubleshooterStep)) {
                        // delete node
                        container.remove(); 
                        // do callback
                        ikb_treeCallBack(container, selNode, container.Options.LiveDeleteCallBackURL, ikb_strProblemDeletingCategory, "&id=" + selNode.CategoryID)
                    }     
                    break;
            } 
        }            
    }  
}

function ikb_treeLiveWrite(tree) {

    if (tree != null) {
    
        // get node
        var node = tree.SelectedNode;
         
        if (node != null) {

            // get url
            var arrURL = tree.Options.LiveWriteCallBackURL.split("?");

            // setup xmlhttp
            if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
              var objXmlHttpHandler = function (obj) {
                if (obj.responseXML != null) {
			        var items = obj.responseXML.getElementsByTagName("result");
			        if (items.length>0) {
				        for (var i = 0; i<items.length;i++) {
					        var nd = items[i];
					        // get result
					        var identity = nd.getAttribute("identity")==null?0:nd.getAttribute("identity");
					        // end loader
					        iasp_AjaxExtensionsEndRequest();
					        // was everything ok
					        if (identity==0) {
					            alert(ikb_strProblemSavingCategory);
					        } else {
					            tree.SelectedNode.CategoryID = identity;
					        }
				        }
			        }
		        }
              };

            var categoryID = 0;
            if (node.ParentNode != null) {
                categoryID = node.ParentNode.CategoryID;
            }
            // setup params
            var strParams = arrURL[1] + "&id=" + node.CategoryID + "&ParentID=" + categoryID + "&Key=" + iasp_EncodeString(node.Text);   
            // setup loader
            iasp_AjaxExtensionsInitializeRequest();
             // make request
            this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

        }
    }
}

function ikb_treeCallBack(tree, node, callbackURL, errMsg, params) {

 if (tree != null) {
    
        // do we have a specific node?
        if (node==null) {node = tree.SelectedNode;}
        
        if (node != null) {
            
            // get url
            var arrURL = callbackURL.split("?");

            // setup xmlhttp
            if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
              var objXmlHttpHandler = function (obj) {
                if (obj.responseXML != null) {
			        var items = obj.responseXML.getElementsByTagName("result");
			        if (items.length>0) {
				        for (var i = 0; i<items.length;i++) {
					        var nd = items[i];
					        // get result
					        var identity = nd.getAttribute("identity")==null?0:nd.getAttribute("identity");
					        // end loader
					        iasp_AjaxExtensionsEndRequest();
					        // was everything ok
					        if (identity==0) {alert(errMsg);}
				        }
			        }
		        }
              };
              
            // we need a category id to delete   
            if (node.CategoryID > 0) {
                // setup params
                var strParams = arrURL[1] + params
                // setup loader
                iasp_AjaxExtensionsInitializeRequest();                
                // make request
                this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 
            }
            
        }
    }
}

function ikb_toggleTree(tree) {
    if (tree.Options.Expanded) {
         tree.collapseAll();
         tree.Options.Expanded = false;
    } else {
         tree.expandAll();
         tree.Options.Expanded = true;
    }
}

/* ----------------------------------------------------------- */
// logout confirmation alert
/* ----------------------------------------------------------- */

function ikb_logOut() {

  // disable body
    iasp_disableBody();
    
	if (confirm(ikb_strLogoutAlertText)) {
	    return true;
    }
    else {
        // enable body if cancel
        iasp_enableBody();
        return false;
    }


}

/* ----------------------------------------------------------- */
// show ajax based glossary tooltip
/* ----------------------------------------------------------- */

function ikb_showGlossaryToopTip(intGlossaryTermID) {
    
    // tooltip width 
    var intWidth = 275;
    var intShowForSecs = 5;
    
    // get url
    var arrURL = strGlossaryToolTipCallBackURL.split("?");

    // setup xmlhttp
    if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
      var objXmlHttpHandler = function (obj) {
        if (obj.responseXML != null) {
            var items = obj.responseXML.getElementsByTagName("result");
            if (items.length>0) {
                for (var i = 0; i<items.length;i++) {
	                var nd = items[i];
	                // get result
	                var strValue = nd.getAttribute("value")==null?0:nd.getAttribute("value");	   
	                // was everything ok
	                if (strValue=="") {
	                    alert(ikb_strSendProblem);
	                    iasp_DisableTip();
	                } else {
	                    // update text
	                    iasp_populateToolTip(strValue);
	                }
                }
            }
        }
      };
      
    // setup params
    var strParams = arrURL[1] + "&id=" + intGlossaryTermID;   
    // show loading tooltip
    iasp_EnableTip(ikb_strPleaseWait, intWidth, intShowForSecs)
     // make request
    this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

}


/* ----------------------------------------------------------- */
// main navigation forum search
/* ----------------------------------------------------------- */

function kbSearch(txtID, defaultVal, installURL, pageURL) {

    // loop through inputs as we may have dynamically added the textbox ie. appendChild(txt)
    var t = null;
    var everything = document.getElementsByTagName('input'); 
    var everythinglength = everything.length;
     for(var i = 0;i<everythinglength;i++)     
     {       
       try {       
           if (everything[i].id == txtID) {
             t = everything[i];
           }
       } 
       catch(e) {  
            t = null;
       }
    } 
 
    if (t != null) {
        if (t.value != defaultVal) {
            if (t.value != "") { 
                if (installURL != null) { // SEO URLs enabled   
                    if (pageURL != null) {     
                        location = installURL + pageURL + "?Keywords=" + t.value;
                    } else {
                       location = installURL + "Search/?Keywords=" + t.value;
                    }
               } else {
                    if (pageURL != null) {     
                        location = pageURL + "?Keywords=" + t.value;
                    } else {
                        location = "Search.aspx?Keywords=" + t.value;
                    }
                }
                return;
            }
        }        
        if (installURL != null) { // SEO URLs enabled   
            if (pageURL != null) {     
                location = installURL + pageURL;
            } else {
                location = installURL + "/Search/";
            }
        } else {
          if (pageURL != null) {   
                location = pageURL;
            } else {
                location = "Search.aspx";
            }
        }
    }
    
 }   
 
  /* ----------------------------------------------------------- */
// method to add standard replies to the rich text box within the staff CP
/* ----------------------------------------------------------- */

function ikb_AddStandardReply(intReplyID, strRTBClientID, strCallBackURL) {

    var editor = $find(strRTBClientID); 
 
    // get url
    var arrURL = strCallBackURL.split("?");

    // setup xmlhttp
    if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
      var objXmlHttpHandler = function (obj) {
        if (obj.responseXML != null) {
            var items = obj.responseXML.getElementsByTagName("result");
            if (items.length>0) {
	            for (var i = 0; i<items.length;i++) {
		            var nd = items[i];
		            // get result
		            var text = nd.getAttribute("text")==null?"":nd.getAttribute("text");
		            // end loader
		            iasp_AjaxExtensionsEndRequest();
		            // was everything ok
		            if (text == "") {
		                alert(ikb_strAddStandardReplyProblem);
		            } else {
		       
                       editor.pasteHtml(text);
		            }
	            }
            }
        }
      };
      
    // setup params
    var strParams = arrURL[1] + "&ID=" + intReplyID;   
    // setup loader
    iasp_AjaxExtensionsInitializeRequest();
     // make request
    this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

}

 /* ----------------------------------------------------------- */
// method to add standard replies to the rich text box within the staff CP
/* ----------------------------------------------------------- */

var iaspls_timeoutID = "lsTimeout"
var lsDelay = 1;
var lsTimerStarted = false;
var lsPageSze = 5;
var lsLoader = false;

var lsTxt = null
var lsRTB = null;

// textbox change event
function ikb_lsTextSelChanged(txt, usetimeout) {
    lsTxt = txt;   
    lsPageSze = 5;
    lsLoader = false;
    if (txt.value != "" && lsTimerStarted == false) {
        if (usetimeout) {
            iaspls_timeoutID = setTimeout(ikb_lsKeyDown, lsDelay * 1000)
        } else {
            ikb_lsKeyDown();
        }
        lsTimerStarted = true;
    }
}

// rich textbox key down event
function ikb_lsEditorSelChanged(rtb, args) {
  
    if (rtb != null && lsTimerStarted == false) {
        addEvent(rtb.get_document(), 'keydown', function(e) {

            lsPageSze = 5;
            lsLoader = false;
            if (rtb.get_text() != "") {
                    lsRTB = rtb;
                    iaspls_timeoutID = setTimeout(ikb_lsKeyDown, lsDelay * 1000)
                    lsTimerStarted = true;
            }
          
        }
        );
    }
}

function ikb_lsKeyDown() {
  
    if (lsLoader == null) {lsLoader = false;}

    var strKeywords = ""
    if (lsTxt != null) {
        strKeywords = lsTxt.value;
    }
 
    if (lsRTB != null) {
          strKeywords =  strKeywords + " " + lsRTB.get_text()
    }

    if (ls != null) {
          
        var pnl = iasp_FindControl(ls.id);
        var pnlMore = iasp_FindControl(ls.more);
        var tr1 = iasp_FindControl(ls.tr1);
        var tr2 = iasp_FindControl(ls.tr2);

        // check for our settings array

        if (pnl != null && tr1 != null && tr2 != null) {
            
            if (strKeywords != "") {
                ikb_lsPopulate(lsPageSze, strKeywords, ls.callbackurl, pnl, pnlMore, tr1, tr2);
            } else {
                tr1.style.display = "none";
                tr2.style.display = "none";
                pnl.innerHTML = "";
                 if (iaspls_timeoutID != null) { clearTimeout(iaspls_timeoutID); }
            }
        }
    }
}

function ikb_lsMoreClick() {
    lsPageSze += 5;
    lsLoader = true;
    ikb_lsKeyDown(true);
}

function ikb_lsPopulate(pageSize, strKeywords, strCallBackURL, pnl, pnlMore, tr1, tr2) {

    // get url
    var arrURL = strCallBackURL.split("?");
    var intTotal = 0;

    // setup xmlhttp
    if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
      var objXmlHttpHandler = function (obj) {
        if (obj.responseXML != null) {
          var total = obj.responseXML.getElementsByTagName("total");  
            if (total.length>0) { 
                for (var i = 0; i<total.length;i++) {
                    var nd = total[i];	
                    intTotal = parseInt(nd.firstChild.nodeValue)
                }
            }
            var items = obj.responseXML.getElementsByTagName("result");          
            var s = "";
            if (items.length>0) {             
                s += "<h2>" + ikb_strLiveResultsHeader + "</h2>";         
	            for (var i = 0; i<items.length;i++) {
		            var nd = items[i];		       
		            var title = nd.getAttribute("title")==null?"":nd.getAttribute("title");
                    var rank =  nd.getAttribute("rank")==null?0:parseInt(nd.getAttribute("rank"));
		            var text = nd.getAttribute("text")==null?"":nd.getAttribute("text");
                    var navigateurl =  nd.getAttribute("navigateurl")==null?"":nd.getAttribute("navigateurl");
                    s += "<p><a href=\"" + navigateurl + "\" target=\"_blank\">" + title + "</a>";
                    if (rank > 0) {    
                        s += "<span class=\"SmallGrayText\">"; 
                        s += " " + ibk_Rank.replace("[0]", rank) 
                        s += "</span>";
                    }
                    s += "<br />";
                    s += text;
                    s += "</p>";
	            }
            }

            if (typeof s != 'undefined' && s != null) {
                if (s != "") {
                    tr1.style.display = "";
                    tr2.style.display = "";               
                    if (pageSize >= intTotal) {
                        pnlMore.style.display = "none";
                    } else {
                        pnlMore.style.display = "";
                    }
                    pnl.innerHTML = s;
                } else {
                    tr1.style.display = "none";
                    tr2.style.display = "none";
                    pnl.innerHTML = "";
                }
            } else {
                tr1.style.display = "none";
                tr2.style.display = "none";
                pnl.innerHTML = "";
            }
  
            // clear timeout we don't want to keep hitting the db
            if (iaspls_timeoutID != null) { clearTimeout(iaspls_timeoutID); }
            lsTimerStarted = false; 
            if (lsLoader) {iasp_AjaxExtensionsEndRequest();}

        }
      };
      
      if (lsLoader) {iasp_AjaxExtensionsInitializeRequest();}
      // setup params
      var strParams = arrURL[1] + "&Keywords=" + iasp_EncodeString(strKeywords) + "&PageSize=" + pageSize;   
      // make request
      this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

}

/* ----------------------------------------------------------- */
// helper for all r.a.d editor controls
/* ----------------------------------------------------------- */

function Editor_OnClientLoad(editor, args)  {  

   var toolbar = $get(editor.get_id() + "Top"); 
   
   var buttons = toolbar.getElementsByTagName("A");   
   for (var i=0; i< buttons.length; i++)  
   {  
      var a = buttons[i];  
      a.tabIndex = -1;  
      a.tabStop = false;  
   }   
} 

function doHelpSearch(searchURL, txt) {

    var txt = iasp_FindControl(txt);
 
    if (txt != null) {
        if (txt.value != "Enter Keywords..." && txt.value != "") {   
            location = searchURL + "?Keywords=" + iasp_EncodeString(txt.value);
        } else {
            txt.focus();
            txt.value = "";
        }
    }
    return false;

}

function ikb_updateSplitterCookie(sender) {
       var navigationPane = sender;                                       
       var w = navigationPane.get_width();  
       iasp_SetCookie('tocWidth',w);
       showSplitterTable(navigationPane.get_splitter());
} 
                                 
                                 
function showSplitterTable(splitter) {
             
          if($telerik.isIE)
		  {
		     splitter.getContainerElement().style.position = 'static';
		  } 
}     


/* ----------------------------------------------------------- */
// flag ticket
/* ----------------------------------------------------------- */

function ikb_FlagTicket(img, id, callbackurl) {
   
   if (img == null) {return;}
   
   if (img.src.toLowerCase().indexOf("flagoff.gif") >= 0) {
       ikb_FlagTicketCallBack(img, callbackurl, true, id)
   } else {
        ikb_FlagTicketCallBack(img, callbackurl, false, id)
   }


}

function ikb_FlagTicketCallBack(img, strCallBackURL, bolFlag, intTicketID) {

    // get url
    var arrURL = strCallBackURL.split("?");

    // setup xmlhttp
    if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
      var objXmlHttpHandler = function (obj) {
        if (obj.responseXML != null) {
            var items = obj.responseXML.getElementsByTagName("result");
           if (items.length>0) {
				for (var i = 0; i<items.length;i++) {
					var nd = items[i];
					// get result
					var identity = nd.getAttribute("identity")==null?0:nd.getAttribute("identity");
		    		// was everything ok
					if (identity==0) {
                        alert(errMsg);
                    } else {
                        
                        var tr = iasp_GetContainer(img, "TR")
                        if (tr == null) {return;}

                        if (bolFlag) { 
                            img.src = img.src.toLowerCase().replace("flagoff.gif","flagon.gif")
                            var td = tr.getElementsByTagName("TD");
                            for (var i = 0; i < td.length; i++) {
                            if (td[i].className == "TableCell_Light") {
                                td[i].className = "TableCell_Flagged";
                                }
                            }                  
                        } else {
                            img.src = img.src.toLowerCase().replace("flagon.gif","flagoff.gif")
                             var td = tr.getElementsByTagName("TD");
                            for (var i = 0; i < td.length; i++) {
                            if (td[i].className == "TableCell_Flagged") {
                                td[i].className = "TableCell_Light";
                                }
                            }       
                       
                        }


                    }
                    
                    // end loader
					iasp_AjaxExtensionsEndRequest();

				}
			}
        }
      };
      
    // setup params
    var intFlag = 0;
    if (bolFlag) {intFlag = 1;}
    var strParams = arrURL[1] + "&ID=" + intTicketID + "&Update=" + intFlag;   
    // setup loader
    iasp_AjaxExtensionsInitializeRequest();
     // make request
    this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

}


// update ticket status or priority
function ikb_UpdateTicket(intTicketID, intIdentity, strButID, strCallBackURL) {

    // get url
    var arrURL = strCallBackURL.split("?");

    // setup xmlhttp
    if (!this.XmlHttp) {this.XmlHttp = new iasp_XmlHttpRequest();}
      var objXmlHttpHandler = function (obj) {
        if (obj.responseXML != null) {
            var items = obj.responseXML.getElementsByTagName("result");
           if (items.length>0) {
				for (var i = 0; i<items.length;i++) {
					var nd = items[i];
					// get result
					var identity = nd.getAttribute("identity")==null?0:nd.getAttribute("identity");
		    		// was everything ok
					if (identity==0) {
                        alert(errMsg);
                    } else {
                       iasp_FindControl(strButID).click();
                    }                    
                    // end loader
					iasp_AjaxExtensionsEndRequest();

				}
			}
        }
      };


    var strParams = arrURL[1] + "&TicketID=" + intTicketID + "&ID=" + intIdentity;   
    // setup loader    
    iasp_AjaxExtensionsInitializeRequest();
     // make request
    this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

}


