/*======================================================================*/
// © InstantASP Limited.
/*======================================================================*/

/*============================*/
// 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);

    // if the div has not already been added to the dom
    var elemDiv = null;
    if (iasp_FindControl(DivLayer) != null) {

        elemDiv = iasp_FindControl(DivLayer);

    } else {

        // create div layer container to holder table
        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);
            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; }
}


// 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) {

    alert(el.childNodes.length);
    if (el.childNodes && el.childNodes.length > 0) {
        for (var x = 0; x < el.childNodes.length; x++) {
            alert(el.type)
            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 != "") {
        iasp_FindControl(plc).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;
        if (this.Transition != null) {
            nd.style.height = '';
            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);
    } 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;
        if (this.Transition != null) {
            nd.style.height = '';
            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);
    }
}

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;
            }
        } 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 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.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 = 2;
    this.ExpandSlideDuration = 200;
    this.ExpandTransition = 12;
    this.ExpandTransitionDuration = 175;
    this.CollapseSlide = 2;
    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 (this.rightToLeft) {

                // add existing columns to array
                var cols = row.getElementsByTagName("TD");                  
                var colArray = new Array(cols.length - 1);
                for (var x = 0; x < cols.length; x++) {
                    colArray.push(cols[x]);
                }

                // rebuild row right to left
                tempRow = document.createElement("TR");                    
                for (var j = colArray.length - 1; j >= 0; j--) {
                    var td = colArray[j];          
                    if (typeof td == 'object') {
                        tempRow.appendChild(td);
                    }
                }

            }

            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 (this.rightToLeft) {

                    // add existing columns to array
                    var cols = row.getElementsByTagName("TD");                  
                    var colArray = new Array(cols.length - 1);
                    for (var x = 0; x < cols.length; x++) {
                        colArray.push(cols[x]);
                    }

                    // rebuild row right to left
                    tempRow = document.createElement("TR");                    
                    for (var j = colArray.length - 1; j >= 0; j--) {
                        var td = colArray[j];          
                        if (typeof td == 'object') {
                            tempRow.appendChild(td);
                        }
                    }

                }

                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) {
    var objReturn = null;
    if (iasp_IE5 || iasp_NS6 || iasp_Opera || iasp_Opera8)
    { objReturn = document.getElementById(strControlName); }
    else if (iasp_IE4) { objReturn = document.all[strControlName]; }
    else if (iasp_NS4) { objReturn = document.layers[strControlName]; }
    return objReturn;
}

// 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;
}


// 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.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) {
    
    disableFormSubmit();
    
    var keyCode = getKeyCode(e);
    if (keyCode && keyCode == 13) {
        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;
        }

    }
}

/*============================*/
// InstantForum.NET
/*============================*/

// forum UI Object

instantforumui = new Object();

function InstantForumUI(imgFolder) {
    
    // public properties
    this.imgFolder = imgFolder;
    this._ActiveUserCard = false;
    this._ActiveUserCards = new Array();
    
       if (this._commonUI == null) { this._commonUI = new InstantASPCommonUI(this.imgFolder) }

    if (instantforumui[imgFolder] != null) {
        return instantforumui[imgFolder];
    } else {
    instantforumui[imgFolder] = this;
    }

    return this;
    
}

// build topic sort by drop down

InstantForumUI.prototype.buildTopicsSortByDropDown = function(fulltextEnabled) {

    // drop down list values
    var arr = new Array(fulltextEnabled ? 10 : 9);
    for (i = 0; i < arr.length; i++) {
        arr[i] = new Array(2);
    }

    var i = 0;
    var prefix = if_SortByPrefix;
        
    if (fulltextEnabled) {
        arr[0][1] = prefix + if_TopicSortBy10;
        arr[0][2] = "TopicRank";
        i += 1
    }

    arr[0 + i][1] = prefix + if_TopicSortBy1;
    arr[0 + i][2] = "LastPosterdate";
    arr[1 + i][1] = prefix + if_TopicSortBy2;
    arr[1 + i][2] = "DateStamp";
    arr[2 + i][1] = prefix + if_TopicSortBy3;
    arr[2 + i][2] = "Title";
    arr[3 + i][1] = prefix + if_TopicSortBy4;
    arr[3 + i][2] = "Replies";
    arr[4 + i][1] = prefix + if_TopicSortBy5;
    arr[4 + i][2] = "Views";
    arr[5 + i][1] = prefix + if_TopicSortBy6;
    arr[5 + i][2] = "Rating";
    arr[6 + i][1] = prefix + if_TopicSortBy7;
    arr[6 + i][2] = "EditDateStamp";
    arr[7 + i][1] = prefix + if_TopicSortBy8;
    arr[7 + i][2] = "IsPinned";
    arr[8 + i][1] = prefix + if_TopicSortBy9;
    arr[8 + i][2] = "IsLocked";


    return this._commonUI.buildSelect(null, null, arr);
}

InstantForumUI.prototype.buildDateFilterDropDown = function() {

    // drop down list values
    var arr = new Array(14);
    for (i = 0; i < arr.length; i++) {
        arr[i] = new Array(2);
    }

    var prefix = "from:";
    arr[0][1] = prefix + iasp_DateFilter1;
    arr[0][2] = "1";
    arr[1][1] = prefix + iasp_DateFilter2;
    arr[1][2] = "2";
    arr[2][1] = prefix + iasp_DateFilter3;
    arr[2][2] = "3";
    arr[3][1] = prefix + iasp_DateFilter4;
    arr[3][2] = "4";
    arr[4][1] = prefix + iasp_DateFilter5;
    arr[4][2] = "5";
    arr[5][1] = prefix + iasp_DateFilter6;
    arr[5][2] = "6";
    arr[6][1] = prefix + iasp_DateFilter7;
    arr[6][2] = "7";
    arr[7][1] = prefix + iasp_DateFilter8;
    arr[7][2] = "8";
    arr[8][1] = prefix + iasp_DateFilter9;
    arr[8][2] = "9";
    arr[9][1] = prefix + iasp_DateFilter10;
    arr[9][2] = "10";
    arr[10][1] = prefix + iasp_DateFilter11;
    arr[10][2] = "11";
    arr[11][1] = prefix + iasp_DateFilter12;
    arr[11][2] = "12";
    arr[12][1] = prefix + iasp_DateFilter13;
    arr[12][2] = "13";
    arr[13][1] = iasp_DateFilter14;
    arr[13][2] = "14";
    
    return this._commonUI.buildSelect(null, null, arr);
}

// forum user card Object

instantforumusercard = new Object();

function InstantForumUserCard(element) {

    // public properties
    this._element = element;
    this._json = null;
    this._context = null;
    this._commonUI = null;
    this._forumUI = null;
    this.imgFolder = null;
    this.installURL = null;
    this._userLevel = null;
    this._sfloat = null;
    this._emailMembers = false;

    if (document.all) {
        this._sfloat = "styleFloat"; //ie
    } else {
        this._sfloat = "cssFloat"; //ff
    }

    if (instantforumusercard[element.id] != null) {
        return instantforumusercard[element.id];
    } else {
        instantforumusercard[element.id] = this;
    }

    return this;

}

InstantForumUserCard.prototype.initialize = function() {

    if (this._json != null) {
        this._context = new InstantForumContext(this._json);
        this._context.initialize();
    }

    if (this._context != null) {

        // set image folder
        this.imgFolder = this._context.CurrentSettings.InstallImageFolderURL
        this.installURL = this._context.CurrentSettings.InstallURL
        
        if (this._commonUI == null) {
            this._commonUI = new InstantASPCommonUI(this.imgFolder);
        }

        if (this._forumUI == null) {
            this._forumUI = new InstantForumUI(this.imgFolder) 
        }

        // set user level
        this._userLevel = new InstantForumUserLevel(this._json);
        this._userLevel.defaultNoOfBlocks = 10; //this.get_defaultNoOfBlocks();
        this._userLevel.imgFolder = this.imgFolder;
        this._userLevel.installURL = this.installURL;
        this._userLevel.initialize();

    }
    
}

InstantForumUserCard.prototype.showUserCard = function(userid, loc) {

    // add card to dom
    this.addUserCardToDom(userid, loc);

    var tooltip = iasp_FindControl("usercard_" + this._element.id + userid);
    var imgtooltip = iasp_FindControl("imgusercard_" + this._element.id + userid)
    var divtooltip = iasp_FindControl("divusercard_" + this._element.id + userid)
    
    if (tooltip != null && imgtooltip != null && divtooltip != null) {

        // hide all tooltips
        this.hideUserCard();

        // add to local array
        this._forumUI._ActiveUserCards[this._forumUI._ActiveUserCards.length] = tooltip.id;

        // setup offsets
        if (loc == 1) {
            x1 = -15;
            y1 = 214;
        }
        else if (loc == 2) {
            x1 = -20;
            y1 = 410;
        }
        else if (loc == 3) {
            x1 = 525;
            y1 = 214;
        }

        var element = this._element ? this._element : document.body;

        if (!iasp_IsIE) {
            addEvent(element, 'mouseover', function(e) {
                positionTip(e);
            }
            );
        } else {
            element.onmouseover = positionTip
        }

        var ctl = this;
        function positionTip(m) {

            if (ctl._forumUI._ActiveUserCard == true) { return; }

            if (iasp_IsIE) {

                var tmpX = event.clientX;
                var tmpY = event.clientY;
                tmpX = tmpX - x1;
                tmpY = tmpY - y1;

                if (!document.body.scrollTop) {

                    var iL = document.documentElement.scrollLeft;
                    var iV = document.documentElement.scrollTop;
                    tempX = tmpX + iL;
                    tempY = tmpY + iV;
                    tooltip.style.top = tempY + "px";
                    tooltip.style.left = tempX + "px";
                } else {
                    tooltip.style.top = tmpY + "px";
                    tooltip.style.left = tmpX + "px";
                }
            } else {
                var tmpX = m.pageX;
                var tmpY = m.pageY;
                tmpX = tmpX - x1;
                tmpY = tmpY - y1;
                tooltip.style.top = tmpY + "px";
                tooltip.style.left = tmpX + "px";
            }

        }

        // toggle visibility
        imgtooltip.style.display = "";
        tooltip.style.display = "block";
        divtooltip.style.display = "none";

        // create context to pass to onComplete, onError etc
        var arrUserContext = new Array();
        arrUserContext[0] = this;

        // get data & set async evetns
        var service = new InstantASP.InstantForum.UI.WebServices.Users();
        service.SelectUser(userid, true, this.onTooltipComplete, this.onTooltipError, arrUserContext);

    }

}

InstantForumUserCard.prototype.onTooltipComplete = function(returndata, userContext) {

    // GET CONTROL
    var ctl = userContext[0];

    // update tooltip status
    ctl._forumUI._ActiveUserCard = true;


    // get user collection
    var users = null;
    if (returndata != null && returndata != "") {
        users = new InstantForumUsers(returndata);
        users.initialize();
    }


    var user = null;
    if (users != null && users.UserCollection != null) {
        user = users.UserCollection[0];
    }

    // do we have a collection
    if (user != null) {
        ctl.buildUserCard(user);
    } else {

    }

}

InstantForumUserCard.prototype.onToolTipError = function(error) {

    //alert("Error");

}

InstantForumUserCard.prototype.buildUserCard = function(user) {

    // get tooltip
    var tooltip = iasp_FindControl("usercard_" + this._element.id + user.UserID)
    var imgtooltip = iasp_FindControl("imgusercard_" + this._element.id + user.UserID)
    var divtooltip = iasp_FindControl("divusercard_" + this._element.id + user.UserID)

    if (tooltip != null && imgtooltip != null && divtooltip != null) {

        // build user card
        var s = null;
        if (user != null) {
            s = this.buildUserCardText(user, this._userLevel, this._context);
        } else {
            s = "No user found";
        }
        
        // populate div
        divtooltip.innerHTML = s;

           
        // hide loader
        imgtooltip.style.display = "none";

        // show div
        divtooltip.style.display = "";

    }

}

InstantForumUserCard.prototype.addUserCardToDom = function(intUserId, intCardSector, strCss) {

    var imgFolder = this.imgFolder;

    // add tooltip layers for members

    if (intUserId > 0) {

        // create main tooltip div
        var tooltip = document.createElement("DIV");
        tooltip.id = "usercard_" + this._element.id + intUserId;
        tooltip.style.display = "none";

        if (intCardSector == 1) {
            tooltip.className = "bigtipleft";
        } else if (intCardSector == 2) {

        } else if (intCardSector == 3) {
            tooltip.className = "bigtipright";
        }

        // content div
        var div = document.createElement("DIV");
        div.id = "divusercard_" + this._element.id + intUserId;
        div.style[this._sfloat] = "left";
        div.style.width = "100%";
        div.style.display = "none";

        // add content cell to div
        tooltip.appendChild(div);

        // create loading image
        var imgLoading = document.createElement("IMG");
        imgLoading.id = "imgusercard_" + this._element.id + intUserId;
        imgLoading.src = imgFolder + "Misc_AjaxLoadingLarge.gif";
        imgLoading.className = "bigtiploading"

        // add loading image to tooltip div
        tooltip.appendChild(imgLoading);

        // add tooltip div to dom
        if (iasp_FindControl("usercard_" + this._element.id + intUserId) == null) {
            document.body.appendChild(tooltip);
        }

    }

}

InstantForumUserCard.prototype.buildPhotoWithCard = function(intUserId, hypPhoto, intCardSector, strCss) {

    //this.addUserCardToDom(intUserId, intCardSector);

    // create span to hold & style photo
    var imgDiv = document.createElement("DIV");
    imgDiv.id = "usercard_photo";
    imgDiv.className = !strCss ? "userPictureMedium" : strCss;

    // add image to span
    imgDiv.appendChild(hypPhoto)

    // return div
    return imgDiv;
        


}

InstantForumUserCard.prototype.hideUserCard = function() {

    if (this._forumUI._ActiveUserCards.length == -1) { return; }

    for (i = 0; i < this._forumUI._ActiveUserCards.length; i++) {
        if (this._forumUI._ActiveUserCards[i] != "") {
            var div = iasp_FindControl(this._forumUI._ActiveUserCards[i]);
            if (div != null) {
                div.style.display = 'none';
                this._forumUI._ActiveUserCards[i] = '';
                var divs = div.getElementsByTagName("DIV");
                // ensure we never remove the first row
                for (i = divs.length - 1; i >= 1; i--) {
                    divs[i].style.display = "none";
                }
            }
        }
    }

    this._forumUI._ActiveUserCard = false;

}

InstantForumUserCard.prototype.hideUserCardOnMouseOut = function(event) {

    //if (this._forumUI._ActiveUserCard == false) { return; }

    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, "DIV")

    if (container != null) {
        if (container.id.indexOf("usercard_") == -1) {
            this.hideUserCard();
        }
    }

}


InstantForumUserCard.prototype.buildUserCardText = function(user, userlevel, context) {

    // get user levels
    var sLevel = userlevel.renderUserLevel(user, false, true, false);
    var sLevelLabel = userlevel.renderUserLevel(user, true, false, false);

    // get urls
    var installURL = context.CurrentSettings.InstallURL;
    var imgFolder = context.CurrentSettings.InstallImageFolderURL;

    // format username
    var strUsername = "";
    if (user.OpenMarkUp != null) { strUsername += user.OpenMarkUp; }
    if (user.Username != "") {
        strUsername += user.Username;
    } else {
        strUsername += if_OpenIDUser;
    }
    if (user.CloseMarkUp != null) { strUsername += user.CloseMarkUp; }

    var strPhoto = null;
    if (user.PhotoImage != null && user.PhotoImage != "") {
        if (user.PhotoImage.toLowerCase().indexOf("http://") == -1 && user.PhotoImage.toLowerCase().indexOf("https://") == -1) {
            strPhoto = installURL + user.PhotoImage;
        } else {
            strPhoto = user.PhotoImage;
        }
    } else {
        strPhoto = imgFolder + "Misc_NoPhoto.gif";
    }

    // build user card

    var s = "";
    s += "<div style=\"float: left; width: 410px; margin-top: 46px;\" id=\"usercard_1\" class=\"SmallTxt\">";

    s += "<div style=\"float: left; width: 75px;\" id=\"usercard_1a\">";

    s += "<div class=\"userPictureLarge\" id=\"usercard_2\">";
    s += "<a href=\"UserINfo" + user.UserID + ".aspx\" title=\"Goto Profile\">";
    s += "<img src=\"" + strPhoto + "\" alt=\"Profile Picture\"  alt=\"Profile Photo\" />";
    s += "</a>";
    s += "</div>";

    s += "<div style=\"float: left; width: 100%;\" id=\"usercard_3\">";

    s += "<br />";

    s += "<a href=\"" + installURL + "Following.aspx?UserID=" + user.UserID + "\" title=\"Follow " + user.Username + "\">";
    s += "<img src=\"" + imgFolder + "Button_Follow.gif\" display= /><br /><br /> ";
    s += "</a>";

    s += "<br />";
    s += "</div>"

    s += "<div style=\"float: left; width: 100%; line-height: 15pt;\" id=\"usercard_4\">";

    if (user.Twitter != null && user.Twitter != "") {
        s += "<a href=\"" + user.Twitter + "\">Twitter</a><br />";
    }
    if (user.Facebook != null && user.Facebook != "") {
        s += "<a href=\"" + user.Facebook + "\">Facebook</a><br />";
    }
    if (user.LinkedIn != null && user.LinkedIn != "") {
        s += "<a href=\"" + user.LinkedIn + "\">LinkedIn</a><br />";
    }
    if (user.MySpace != null && user.MySpace != "") {
        s += "<a href=\"" + user.MySpace + "\">MySpace</a><br />";
    }
    if (user.YouTube != null && user.YouTube != "") {
        s += "<a href=\"" + user.YouTube + "\">YouTube</a><br />";
    }

    s += "</div>";

    s += "</div>";

    s += "<div style=\"float: right; width: 323px; line-height: 12pt;\" id=\"usercard_5\">";

    // username
    s += "<div style=\"float: left; width: 100%;\" id=\"usercard_6\">";

    s += "<div style=\"float: left; width: 275px;\" id=\"usercard_6a\">";
    s += "<h3>" + strUsername + "</h3>";
    s += user.PrimaryRoleName;
    s += "</div>";

    s += "<div style=\"float: right; width: 44px;\" id=\"usercard_7\">";
    s += "<a href=\"Post.aspx?UserID=" + user.UserID + "&Task=PostPM\" title=\"Send Private Message\">";
    s += "<img src=\"" + imgFolder + "UserCard_Email.gif\" alt=\"Send Private Message\" /><br /><br />";
    s += "</a>";
    s += "</div>";

    // user level

    s += "<div style=\"float: left; width: 100%; margin-top: 12px;\" id=\"usercard_8\">";
    if (sLevel != null) {
        s += sLevel;
        s += "<br />";
    }


    s += "</div>";

    // add lines


    var s1 = ""
    if (user.CompanyName != null && user.CompanyName != "") {
        s1 += user.CompanyName;
    }

    if (user.JobTitle != null && user.JobTitle != "") {
        if (s1 != "") { s1 += ", "; }
        s1 += user.JobTitle;
    }

    // line 2

    var s2 = "";

    if (user.Location != null && user.Location != "") {
        s2 += user.Location;
    }

    if (user.Age != null && user.Age != 0) {
        if (s2 != "") { s2 += ", "; }
        s2 += user.Age + " years old";
    }

    if (s3 == "") {

    }
    // line 3

    var s3 = "";

    // add optional data if available
    if (user.AvgDailyPostCount != null && user.AvgDailyPostCount != 0) {
        s3 += user.AvgDailyPostCount + " posts per day";
    }

    if (user.PostCount != null && user.PostCount != "0") {
        if (s3 != "") { s3 += ". "; }
        if (user.PostCount == 1) {
            s3 += user.PostCount + " post";
        } else {
            s3 += user.PostCount + " total posts";
        }

    }

    // add standard data if optional data was not found
    if (s2 == "" || s3 == "") {

        if (s3 != "") { s3 += ", "; }
        if (sLevelLabel != null) {
            s3 += sLevelLabel;

        }

        if (user.RegisteredDays != null) {

            if (s3 != "") { s3 += "<br/><br/>"; }
            if (user.RegisteredDays == 0 || user.RegisteredDays == 1) {
                s3 += "Joined " + user.CreatedDate;
            }
            else {
                s3 += "Joined " + user.RegisteredDays + " days ago.";
            }
        }

        if (user.TotalVisits != null) {
            if (s3 != "") { s3 += " "; }
            if (user.TotalVisits == 1) {
                s3 += if_Visit.replace("[0]", user.TotalVisits);
            } else {
                s3 += if_Visits.replace("[0]", user.TotalVisits);
            }
        }
    }

    if (s1 != "") {
        s += "<div style=\"float: left; width: 100%; margin-top: 8px;\" id=\"usercard_9\">";
        s += s1;
        s += "</div>";
    }

    if (s2 != "") {
        s += "<div style=\"float: left; width: 100%; margin-top: 8px;\" id=\"usercard_10\">";
        s += s2;
        s += "</div>";
    }

    if (s3 != "") {
        s += "<div style=\"float: left; width: 100%; margin-top: 8px;\" id=\"usercard_11\">";
        s += s3;
        s += "</div>";
    }

    s += "<hr />";
    s += "</div>";

    // main content area
    s += "<div style=\"float: left; width: 100%;\" id=\"usercard_12\">";

    if (user.IsOnline == "true") {
        s += "<a href=\"" + installURL + "WhosOn.aspx\">";
        s += "<img src=\"" + imgFolder + "Contact_OnLine.gif\" style=\"margin-right: 4px;\" /> ";
        s += "</a>";
    }

    s += "<a href=\"" + installURL + "Post.aspx?UserID=" + user.UserID + "&Task=PostPM\">";
    s += "<img src=\"" + imgFolder + "Contact_PM.gif\" style=\"margin-right: 4px;\" /> ";
    s += "</a>";

     if (this._emailMembers && user.HasEmail) {
        s += "<a href=\"" + installURL + "Post.aspx?UserID=" + user.UserID + "&Task=PostEmail\">";
        s += "<img src=\"" + imgFolder + "Contact_Email.gif\" style=\"margin-right: 4px;\" /> ";
        s += "</a>";
    }

    if (user.WebAddress != null && user.WebAddress != "") {
        s += "<a href=\"" + user.WebAddress + "\">";
        s += "<img src=\"" + imgFolder + "Contact_WWW.gif\" style=\"margin-right: 4px;\" /> ";
        s += "</a>";

    }
    if (user.BlogAddress != null && user.BlogAddress != "") {
        s += "<a href=\"" + user.BlogAddress + "\">";
        s += "<img src=\"" + imgFolder + "Contact_Blog.gif\" style=\"margin-right: 4px;\" /> ";
        s += "</a>";
    }


    s += "<a href=\"" + installURL + "RssFeed1.aspx?PostedByUserID=" + user.UserID + "\">";
    s += "<img src=\"" + imgFolder + "Contact_RSS.gif\" style=\"margin-right: 4px;\" /> ";
    s += "</a>";

    s += "</div>"; // end main content

    s += "</div>"
    s += "</div>"

    return s;

}


// InstantForum_Context				   


instantforumcontext = new Object();

function InstantForumContext(strJSON) { 

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.CurrentSettings = new Array();
    
        // setup json proxy object
    if (this.JSON != null) {this.jsonproxy = new InstantASPJSONProxy(this.JSON);}
      
      
    if (instantforumcontext[0]!=null) {
        return instantforumcontext[0];
    } else { 
        instantforumcontext[0]=this;
    }
    return this;
    
}


InstantForumContext.prototype.initialize = function() {

    this.CurrentSettings = this.SelectSettings();

}
  
InstantForumContext.prototype.SelectSettings = function() {
    var data = this.jsonproxy.getData();
    if (data.ForumContext != null) {
        return data.ForumContext.Context[0];
    }
}

// iasp_Roles 			   


instantasproles = new Object();

function InstantASPRoles(strJSON) {

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.userRolesCollection = new Array();

    // setup json proxy object
    if (this.JSON != null) { this.jsonproxy = new InstantASPJSONProxy(this.JSON); }

    if (instantasproles[this.JSON] != null) {
        return instantasproles[this.JSON];
    } else {
        instantasproles[this.JSON] = this;
    }
    return this;

}

InstantASPRoles.prototype.initialize = function() {
    this.userRolesCollection = this.selectUserRoles();
}

InstantASPRoles.prototype.selectUserRoles = function() {
    if (this.jsonproxy == null) { return null; }
    var data = this.jsonproxy.getData();
    if (data.UserRolesCollection != null) {
        return this.jsonproxy.objToArray(data.UserRolesCollection.Roles);
    }
    return;
}

// tags 			   

instantasptags = new Object();

function InstantASPTags(strJSON) {

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.tagCollection = new Array();

    // setup json proxy object
    if (this.JSON != null) { this.jsonproxy = new InstantASPJSONProxy(this.JSON); }

    if (instantasptags[this.JSON] != null) {
        return instantasptags[this.JSON];
    } else {
        instantasptags[this.JSON] = this;
    }
    return this;

}

InstantASPTags.prototype.initialize = function() {
    this.tagCollection = this.selectTags();    
}

InstantASPTags.prototype.selectTags = function() {
    if (this.jsonproxy == null) { return null; }
    var data = this.jsonproxy.getData();
    if (data.TagCollection != null) {   
        return this.jsonproxy.objToArray(data.TagCollection.Tags);
    }
    return;
}

InstantASPTags.prototype.SelectTagsForEntity = function(entityID) {

    var localTags = new Array();
    var tags = this.tagCollection;
    
    if (tags != null) {

        for (var i = 0; i < tags.length; i++) {
            var tag = tags[i];

            if (tag.EntityID == entityID) {
                localTags.push(tag);
            }
        }

    }

    return localTags;

}

// InstantForum_SearchEventArgs				   

instantforumsearcheventargs = new Object();

function InstantForumSearchEventArgs(strJSON) { 

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.Args = new Array();
    
        // setup json proxy object
    if (this.JSON != null) {this.jsonproxy = new InstantASPJSONProxy(this.JSON);}
      
    if (instantforumsearcheventargs[strJSON]!=null) {
        return instantforumsearcheventargs[strJSON];
    } else { 
        instantforumsearcheventargs[strJSON]=this;
    }
    return this;
    
}


InstantForumSearchEventArgs.prototype.initialize = function() {
    this.Args = this.SelectSearchEventArgs();
}
  
InstantForumSearchEventArgs.prototype.SelectSearchEventArgs = function() {
    var data = this.jsonproxy.getData();
    if (data.SearchEventArgs != null) {
        return this.jsonproxy.objToArray(data.SearchEventArgs.Args)[0];
    }
}



//  InstantForum_Forums

instantforumforums = new Object();

function InstantForumForums(strJSON) {

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.ForumCollection = new Array();

    // setup json proxy object
    if (this.JSON != null) { this.jsonproxy = new InstantASPJSONProxy(this.JSON); }

    if (instantforumforums[strJSON] != null) {
        return instantforumforums[strJSON];
    } else {
        instantforumforums[strJSON] = this;
    }
    return this;

}


InstantForumForums.prototype.initialize = function() {
    this.ForumCollection = this.SelectForums();

}

InstantForumForums.prototype.SelectForums = function() {
    if (this.jsonproxy == null) { return null; }
    var data = this.jsonproxy.getData();
    if (data.ForumCollection != null) {
        return this.jsonproxy.objToArray(data.ForumCollection.Forums);
    }

}

// InstantForum_PrivateMessages   

instantforumprivatemessages = new Object();

function InstantForumPrivateMessages(strJSON) {

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.PrivateMessageCollection = null;
    this.TotalRecords = 0;

    // setup json proxy object
    if (this.JSON != null) { this.jsonproxy = new InstantASPJSONProxy(this.JSON); }

    if (instantforumprivatemessages[strJSON] != null) {
        return instantforumprivatemessages[strJSON];
    } else {
        instantforumprivatemessages[strJSON] = this;
    }
    return this;

}

InstantForumPrivateMessages.prototype.initialize = function() {

    if (this.jsonproxy == null) { return null; }

    var data = this.jsonproxy.getData();
    if (data.PrivateMessageCollection != null) {
        this.TotalRecords = data.PrivateMessageCollection.TotalRecords;
        if (data.PrivateMessageCollection.PrivateMessageCollection != null) {
            this.PrivateMessageCollection = this.jsonproxy.objToArray(data.PrivateMessageCollection.PrivateMessageCollection.PrivateMessages);
        }
    }

}

// InstantForum_ForumsRead				   

instantforumforumsread = new Object();

function InstantForumForumsRead(strJSON) { 

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.ForumReadCollection = new Array();

        // setup json proxy object
    if (this.JSON != null) {this.jsonproxy = new InstantASPJSONProxy(this.JSON);}      
    
    if (instantforumforumsread[strJSON]!=null) {
        return instantforumforumsread[strJSON];
    } else { 
        instantforumforumsread[strJSON]=this;
    }
    return this;
    
}

InstantForumForumsRead.prototype.initialize = function() {
    this.ForumReadCollection = this.SelectForumsRead();      
}

InstantForumForumsRead.prototype.SelectForumsRead = function() {

    var data = this.jsonproxy.getData();          
    if (data.ForumReadCollection != null) {    
        return this.jsonproxy.objToArray(data.ForumReadCollection.ForumsRead); 
    }
         
}

InstantForumForumsRead.prototype.SelectForumRead = function(intForumID) { 
   
    if (this.ForumReadCollection != null) {
        for (var i = 0; i < this.ForumReadCollection.length; i++) {                            
            if (this.ForumReadCollection[i].ReadForumID == intForumID) {
                return this.ForumReadCollection[i];
            }
        }
    }
    return null;
    
}

InstantForumForumsRead.prototype.Icon = function(data, strCookieName) {

    // do we have a mark all as read cookie?
    var dtMarkedAsRead = new Date();
    var dtCookieVal = null;
    if (strCookieName != null) {
        dtCookieVal = iasp_GetCookie(strCookieName);
        if (dtCookieVal != null) {
            dtMarkedAsRead = dtCookieVal;
        }
    }

    var strIcon = null;
    var strAltText = null;
    var bolIsRead = false;
    var forumRead = this.SelectForumRead(data.ForumID);

    var UnreadMessages = "Folder_NewPosts.gif";
    var UnreadMessagesToolTip = "ForumKey_NewMessagesUnModerated";
    var NoUnreadMessages = "Folder_NoNewPosts.gif";
    var NoUnreadMessagesToolTip = "ForumKey_NoNewMessagesUnModerated";

    if (data.ModerateType != null) {
        if (data.ModerateType != 1) {
            UnreadMessages = "Folder_NewPostsModerated.gif";
            UnreadMessagesToolTip = "ForumKey_NewMessagesModerated";
            NoUnreadMessages = "Folder_NoNewPostsModerated.gif";
            UnreadMessagesToolTip = "ForumKey_NewMessagesModerated";
        }
    }

    if (!forumRead) {

        if (dtMarkedAsRead > data.dtLastPosterDate) {
            strIcon = NoUnreadMessages
            strAltText = NoUnreadMessagesToolTip
        } else {
            strIcon = UnreadMessages
            strAltText = UnreadMessagesToolTip
        }

    } else {

        if (dtMarkedAsRead > data.dtLastPosterDate) {
            strIcon = NoUnreadMessages;
            strAltText = NoUnreadMessagesToolTip;
            bolIsRead = true;
        } else {
            if (data.LastPostDate > forumRead.ReadDate) {
                strIcon = UnreadMessages
                strAltText = UnreadMessagesToolTip
            } else {
                strIcon = NoUnreadMessages;
                strAltText = NoUnreadMessagesToolTip;
                bolIsRead = true;
            }
        }

    }

    if (data.ClosedForum) {
        strIcon = "Folder_Closed.gif";
        strAltText = "ForumKey_ClosedForum";
    }

    if (data.RedirectURL != null) {     
        strIcon = "Folder_Redirect.gif";
        strAltText = "ForumKey_RedirectForum";
    }
    
    var arrReturn = new Array(2)
    arrReturn[0] = strIcon;
    arrReturn[1] = strAltText;
    arrReturn[2] = bolIsRead;
    return arrReturn;

}


// InstantForum_Topics   


instantforumtopics = new Object();

function InstantForumTopics(strJSON) {

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.TopicCollection = null;
    this.TotalRecords = 0;

    // setup json proxy object
    if (this.JSON != null) { this.jsonproxy = new InstantASPJSONProxy(this.JSON); }

    if (instantforumtopics[strJSON] != null) {
        return instantforumtopics[strJSON];
    } else {
        instantforumtopics[strJSON] = this;
    }
    return this;

}


InstantForumTopics.prototype.initialize = function() {
    
     if (this.jsonproxy == null) { return null; }

    var data = this.jsonproxy.getData();

    if (data.TopicCollection != null) {
        this.TotalRecords = data.TopicCollection.TotalRecords;
        if (data.TopicCollection.TopicCollection != null) {
            this.TopicCollection = this.jsonproxy.objToArray(data.TopicCollection.TopicCollection.Topics);
        }
    }

}

// InstantForum_TopicsRead				   

instantforumtopicsread = new Object();

function InstantForumTopicsRead(strJSON) { 

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.TopicReadCollection = null;

        // setup json proxy object
    if (this.JSON != null) {this.jsonproxy = new InstantASPJSONProxy(this.JSON);}

    if (instantforumtopicsread[strJSON]!=null) {
        return instantforumtopicsread[strJSON];
    } else { 
        instantforumtopicsread[strJSON]=this;
    }
    return this;
    
}

InstantForumTopicsRead.prototype.initialize = function() {
    this.TopicReadCollection = this.SelectTopicsRead();
}

InstantForumTopicsRead.prototype.SelectTopicsRead = function() {

    if (this.jsonproxy == null) { return null; }
    
    var data = this.jsonproxy.getData();
    if (data.TopicReadCollection != null) {
        return this.jsonproxy.objToArray(data.TopicReadCollection.TopicsRead);
    }
    return null;

}

InstantForumTopicsRead.prototype.SelectTopicRead = function(intTopicID) { 
   
    if (this.TopicReadCollection != null) {
        for (var i = 0; i < this.TopicReadCollection.length; i++) {                            
            if (this.TopicReadCollection[i].TopicID == intTopicID) {
                return this.TopicReadCollection[i];
            }
        }
    }
    return null;
    
}

InstantForumTopicsRead.prototype.Icon = function(data, strCookieName) {

    // do we have a mark all as read cookie?
    var dtMarkedAsRead = new Date();
    var dtCookieVal = null;
    if (strCookieName != null) {
        dtCookieVal = iasp_GetCookie(strCookieName);
        if (dtCookieVal != null) {
            dtMarkedAsRead = dtCookieVal;
        }
    }


    var strIcon = null;
    var strAltText = null;
    var bolIsRead = false;  
    var topicRead = this.SelectTopicRead(data.TopicID); 
    

    var UnreadMessages = 'Topic_OpenReplies.gif';
    var UnreadMessagesToolTip = 'TopicKey_TopicReplies';
    var NoUnreadMessages = 'Topic_Open.gif';
    var NoUnreadMessagesToolTip = 'TopicKey_Topic';   
    
    if (data.Replies >= 10) {
        UnreadMessages = "Topic_HotReplies.gif";
        UnreadMessagesToolTip = "TopicKey_HotReplies";
        NoUnreadMessages = "Topic_Hot.gif";
        NoUnreadMessagesToolTip = "TopicKey_Hot";
    }
    
    if (data.IsPoll == 'true') {
        UnreadMessages = "Topic_PollReplies.gif"
        UnreadMessagesToolTip = "TopicKey_PollReplies"
        NoUnreadMessages = "Topic_Poll.gif"
        NoUnreadMessagesToolTip = "TopicKey_Poll"
    }

    if (topicRead == null) {

        if (dtMarkedAsRead != null && dtMarkedAsRead > data.dtLastPosterDate) {
            strIcon = NoUnreadMessages;
            strAltText = NoUnreadMessagesToolTip;
            bolIsRead = true;
        } else {
            strIcon = UnreadMessages;
            strAltText = UnreadMessagesToolTip;
        }

    } else {

        if (dtMarkedAsRead != null && dtMarkedAsRead > data.dtLastPosterDate) {
            strIcon = NoUnreadMessages;
            strAltText = NoUnreadMessagesToolTip;
            bolIsRead = true;
        } else {

            if (data.LastPostDate > topicRead.ReadDate) {
                strIcon = UnreadMessages;
                strAltText = UnreadMessagesToolTip;
            } else {
                strIcon = NoUnreadMessages;
                strAltText = NoUnreadMessagesToolTip;
                bolIsRead = true;
            }
        }
    }


    if (data.IsLocked) {
        strIcon = "Topic_Locked.gif"
        strAltText = "TopicKey_Locked"
    }

    if (data.IsMoved) {
        strIcon = "Topic_Moved.gif"
        strAltText = "TopicKey_Moved"
    }
    
    var arrReturn = new Array(2)
    arrReturn[0] = strIcon;
    arrReturn[1] = strAltText;
    arrReturn[2] = bolIsRead;

    return arrReturn;


}

// InstantForum_ForumsModerators		   

instantforumforummoderators = new Object();

function InstantForumForumModerators(strJSON) {

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.ForumModeratorCollection = new Array();

    // setup json proxy object
    if (this.JSON != null) {this.jsonproxy = new InstantASPJSONProxy(this.JSON);}

    if (instantforumforummoderators[this.JSON] != null) {
        return instantforumforummoderators[this.JSON];
    } else {
    instantforumforummoderators[this.JSON] = this;
    }
    return this;

}

InstantForumForumModerators.prototype.initialize = function() {

    this.ForumModeratorCollection = this.SelectModerators();

}

InstantForumForumModerators.prototype.SelectModerators = function() {

    var data = this.jsonproxy.getData();
    if (data.ForumModeratorCollection != null) {
        return this.jsonproxy.objToArray(data.ForumModeratorCollection.ForumModerators);
    }

}

InstantForumForumModerators.prototype.SelectForumModerators = function(intForumID) {

    var loclModerators = new Array();
    var forumModerators = this.ForumModeratorCollection;

    if (forumModerators != null) {

        for (var i = 0; i < forumModerators.length; i++) {
            var moderator = forumModerators[i];
            if (moderator.ForumID == intForumID) {
                loclModerators.push(moderator);
            }
        }

    }

    return loclModerators;

}

// InstantForum_WhosOn				   

instantforumwhoson = new Object();

function InstantForumWhosOn(strJSON) { 

    this.JSON = strJSON;
    this.jsonproxy = null;

    this.WhosOnCollection = null;
    this.EventCollection = null;
    this.UserCollection = null;
    this.Statistics = null;
    this.CurrentGuests = null;
    this.CurrentMembers = null;
    this.CurrentAnonymous = null;
    this.TotalREcords = null;
    
        // setup json proxy object
    if (this.JSON != null) {this.jsonproxy = new InstantASPJSONProxy(this.JSON);}

    if (instantforumwhoson[strJSON] != null) {
        return instantforumwhoson[strJSON];
    } else { 
        instantforumwhoson[strJSON] = this;
    }
    return this;
    
}


InstantForumWhosOn.prototype.initialize = function() {

    this.Binddata();  
      
    this.CurrentGuests = this.SelectGuests();
    this.CurrentMembers = this.SelectMembers();
    this.CurrentAnonymous = this.SelectAnonymous();
    
}

// get whos on data

InstantForumWhosOn.prototype.Binddata = function() {

    var data = this.jsonproxy.getData();

    // get whos on
    if (data.WhosOnCollection != null) {
        this.TotalRecords = data.WhosOnCollection.TotalRecords;
        if (data.WhosOnCollection.WhosOnCollection != null) {
            this.WhosOnCollection = this.jsonproxy.objToArray(data.WhosOnCollection.WhosOnCollection.WhosOn);
        }
    }

    // get forthcoming events
    if (data.EventCollection != null) {
        if (data.EventCollection.Events != null) {
            this.EventCollection = this.jsonproxy.objToArray(data.EventCollection.Events);
        }
    }

    // get birthdays today
    if (data.UserCollection != null) {
        if (data.UserCollection.UserCollection != null) {
            this.UserCollection = this.jsonproxy.objToArray(data.UserCollection.UserCollection.Users);
        }
    }

    // get birthdays today
    if (data.Statistics != null) {
        this.Statistics = this.jsonproxy.objToArray(data.Statistics.Stats)[0];
    }


}

// select guests

InstantForumWhosOn.prototype.SelectGuests = function() {
    
    var arrReturn =  new Array();      
    if (this.WhosOnCollection != null) {        
       for (var i = 0; i < this.WhosOnCollection.length; i++) {         
            if (this.WhosOnCollection[i].UserID == 0) {            
                arrReturn.push(this.WhosOnCollection[i]);
            }
        }
    }
    
    return arrReturn;
       
}

// select members

InstantForumWhosOn.prototype.SelectMembers = function() {
    
    var arrReturn =  new Array();      
    if (this.WhosOnCollection != null) {        
       for (var i = 0; i < this.WhosOnCollection.length; i++) {  
            if (this.WhosOnCollection[i].UserID > 0) {
                arrReturn.push(this.WhosOnCollection[i]);
            }
        }
    }
    
    return arrReturn;
       
}

// select anonymous

InstantForumWhosOn.prototype.SelectAnonymous = function() {
    
    var arrReturn =  new Array();      
    if (this.WhosOnCollection != null) {        
       for (var i = 0; i < this.WhosOnCollection.length; i++) {  
            if (this.WhosOnCollection[i].IsAnonymous == true) {
                arrReturn.push(this.WhosOnCollection[i]);
            }
        }
    }
    
    return arrReturn;
       
}



// InstantForum_UserLevel (may need to move to common.js)				   


instantforumuserlevel = new Object();

function InstantForumUserLevel(strJSON) { 

    this.defaultNoOfBlocks = 0;
    this.imgFolder = null;
    this.installURL = null;
    
    this.JSON = strJSON;
    this.jsonproxy = null;
    this.userLevelCollection = new Array();

    
    // setup json proxy object
    if (this.JSON != null) {this.jsonproxy = new InstantASPJSONProxy(this.JSON);}

    if (instantforumuserlevel[this.JSON] != null) {
        return instantforumuserlevel[this.JSON];
    } else {
        instantforumuserlevel[this.JSON] = this;
    }
    return this;
    
}


InstantForumUserLevel.prototype.initialize = function() {
    this.userLevelCollection = this.selectUserLevels();  
}

InstantForumUserLevel.prototype.selectUserLevels = function() {

    var data = this.jsonproxy.getData();
    if (data.UserLevelCollection != null) {
        return this.jsonproxy.objToArray(data.UserLevelCollection.UserLevels);
    }
    return null;
}


InstantForumUserLevel.prototype.selectUserLevel = function(intPostCount) {

    intPostCount = tidyInt(intPostCount)
   
    if (this.userLevelCollection != null) {
        for (var i = this.userLevelCollection.length - 1; i >= 0; i--) {                 
            if (intPostCount >= this.userLevelCollection[i].MinPosts) {
                return this.userLevelCollection[i];
            }
        }
    }
    return null;
    
}

InstantForumUserLevel.prototype.renderUserLevel = function(data, showlabel, showImage, dom) {

    // get user level
    var userLevel = this.selectUserLevel(data.PostCount)

    // did we find a user level?
    if (userLevel != null) {

        // create container
        var container = null;
        var s = "";

        if (dom) {
            container = document.createElement("SPAN");
            container.className = "UserLevel";
        } else {
            s += "<span class=\"UserLevel\">";
        }

        var sTitle = null;
        var sImg = null;
        var sURL = "";
        if (this.installURL != null) {
            sURL = this.installURL;
        }

        if (data.UserLevelImageURL != null) {
            sImg = sURL + data.UserLevelImageURL;
        } else if (userLevel.ImageURL != null) {

        if (userLevel.ImageURL.toLowerCase().indexOf("http://") >= 0 || userLevel.ImageURL.toLowerCase().indexOf("http://") >= 0) {
                sImg = userLevel.ImageURL;
            } else {
                sImg = sURL + userLevel.ImageURL;
            }
        }
     

        if (data.UserLevelTitle != null) {
            sTitle = data.UserLevelTitle;
        } else if (userLevel.Description != null) {
            sTitle = userLevel.Description;
        }

        if (sImg != null && showImage) {

            if (container != null) {
                var img = document.createElement("IMG");
                img.alt = userLevel.Description;
                img.title = userLevel.Description;
                img.src = sImg;
                container.appendChild(img)
            } else {
                if (showlabel == true) {
                    s += "<span>" + sTitle + "</span>";
                    s += "<br /><br />";
                }
                if (sImg != null) {
                    s += "<img src=\"" + sImg + "\" title=\"" + userLevel.Description + "\" alt=\"" + userLevel.Description + "\" />";
                }
            }

        } else {

            if (showlabel == true) {
                if (container != null) {

                } else {
                    s += sTitle;
                    if (showImage == true) {
                        s += "<br /><br />";
                    }
                }
            }

            if (showImage == true) {

                for (var i = 0; i < userLevel.NoOfBlocks; i++) {

                    if (container != null) {
                        var img = document.createElement("IMG");
                        img.alt = userLevel.Description;
                        img.title = userLevel.Description;
                        img.src = this.imgFolder + "RankImages/BlockActive.gif";
                        container.appendChild(img);
                    } else {
                        s += "<img src=\"" + this.imgFolder + "RankImages/BlockActive.gif\" title=\"" + userLevel.Description + " alt=\"" + userLevel.Description + "\" />";
                    }
                }

                for (var i = 0; i < (this.defaultNoOfBlocks - userLevel.NoOfBlocks); i++) {
                    if (container != null) {
                        var img = document.createElement("IMG");
                        img.alt = userLevel.Description;
                        img.title = userLevel.Description;
                        img.src = this.imgFolder + "RankImages/BlockDisabled.gif";
                        container.appendChild(img);
                    } else {
                        s += "<img src=\"" + this.imgFolder + "RankImages/BlockDisabled.gif\" title=\"" + userLevel.Description + "\" alt=\"" + userLevel.Description + "\" />";
                    }
                }
            }

        }

        if (!dom) {
            s += "</span>";
        }

        // return container
        if (container != null) {
            return container;
        } else {
            return s;
        }

    }

    return null;

}


// InstantForum_Users		   

instantforumusers = new Object();

function InstantForumUsers(strJSON) {

    this.JSON = strJSON;
    this.jsonproxy = null;
    this.UserCollection = null;
    this.TotalRecords = 0;

    // setup json proxy object
    if (this.JSON != null) { this.jsonproxy = new InstantASPJSONProxy(this.JSON); }

    if (instantforumusers[strJSON] != null) {
        return instantforumusers[strJSON];
    } else {
        instantforumusers[strJSON] = this;
    }
    return this;

}


InstantForumUsers.prototype.initialize = function() {

    if (this.jsonproxy == null) { return null; }

    var data = this.jsonproxy.getData();
    
    if (data.UserCollection != null) {
        this.TotalRecords = data.UserCollection.TotalRecords;
        if (data.UserCollection.UserCollection != null) {
            this.UserCollection = this.jsonproxy.objToArray(data.UserCollection.UserCollection.Users);
        }
    }
    
}


/* forum helpers */

function if_logOut() {

    // disable body
    iasp_disableBody();
    
	if (confirm(if_strLogoutAlertText)) {
	    return true;
    }
    else {
        // enable body if cancel
        iasp_enableBody();
        return false;
    }
		
}


// Attachment Functions
function if_PrintTopic(uri) {	
	var WinNum = 1;
	window.open(uri,WinNum++);
}

// Prompt to grab direct link to post

function if_PostLink(uri) { if_linkPrompt(uri); }

function if_linkPrompt(uri) {
	var link = iasp_RemoveQueryString(uri);
	var linkDialog = prompt(if_linkPromptTxt, link); 
}

// Prompt displayed with unread private messages
function if_UnreadPrivateMessagePrompt(uri) {
	if (confirm(if_UnreadPrivateMessages))
	{location = uri;} else {return false;}
}

// client side event for search checkbox click
function if_SearchChecked(id) {


}

// share with facebook click
function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
    return false;
}

// main navigation forum search
function forumSearch(txtID, defaultVal) {

    var t = iasp_FindControl(txtID);
    
    if (t != null) {
        if (t.value != defaultVal) {
            if (t.value != "") {
                if (t.value.length > 3) {
                    location = "SEarch.aspx?Keywords=" + iasp_EncodeString(t.value);
                } else {
                    alert("You must provide a longer search term");
                }
                return;
            }
        }
        
        location = "Search.aspx";
        
    }
    
    
}

// show quick post & set focus
function if_QuickPost(divid, reply) {

    var div = iasp_FindControl(divid);
    if (reply == null) { reply = false; }

    if (div != null) {
    
        // show quick reply
        div.style.display = '';
        
        // scroll to quick reply
        if_scrollToDiv(divid);

        // set focus to subject

        if (!reply) {

            var inputs = div.getElementsByTagName('input');
            for (var i = 0; i < inputs.length; i++) {
                var input = inputs[i];
                if (input.type.toLowerCase() == 'text') {
                    input.focus();
                    return;
                }

            };

        } else { // quick reply
        
            var frames = div.getElementsByTagName('iframe');
            for (var i = 0; i < frames.length; i++) {
                var frame = frames[i];
                if (frame != null) {                
                    if (iasp_IsIE) {
                        frame.contentWindow.focus();
                    } else {
                        frame.contentWindow.document.body.focus();
                    }
                    return;
                }

            };
        
        }
        
    }

}

// moderation options
function if_modClick(intAction, intForumID, intNewForumID, strPostIds, intPageIndex, strURL, host) {
 
    // callback url
    arrURL = strURL.split("?");

    // setup xmlhttp
    if (this._xmlHttp == null) { 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("Problem updating topics.");
                    } else {

                        if (host != null) {
                            // update json table
                            host.pageIndexChanged(intPageIndex, true);               
                            try {
                                host.get_txtChkBoxIds().value = "";
                            } catch (e) { }
                        

                          
                        }

                    }

                }
            }
        }
    };

    // setup params
    var strParams = arrURL[1] + "&Action=TopicModeration&EnumValue=" + intAction + "&ForumID=" + intForumID + "&id=" + intNewForumID + "&Key=" + strPostIds + "0";

    // make request
    this._xmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler);

}


// rate a topic
function if_RateTopic(ratingTableID, strCallBackURL) {

    // get container
    var tbl = iasp_FindControl(ratingTableID)

    // get rating
    var intRating = 0;
    if (tbl != null) {
        var cboxes = tbl.getElementsByTagName("input");
        for (i = cboxes.length - 1; i >= 0; i--) {
            if (cboxes[i].checked) {
                intRating = cboxes[i].value;
            }
        }
    }
    
    // update user rating
    if (intRating > 0) {

        // 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) {
                            // hide menu
                            iasp_HideAllMenus();
                            // show confirmation
                            alert("Thank you. Your rating has been updated successfully!");
                        } else {
                            // hide menu
                            iasp_HideAllMenus();
                            // show confirmation
                            alert("Thank you. Your rating added successfully!");
                        }
                    }
                }
            }
        };

        // setup params
        var strParams = arrURL[1] + "&ID=" + intRating;
        // setup loader
        iasp_AjaxExtensionsInitializeRequest();
        // make request
        this.XmlHttp.Connect(arrURL[0], "GET", strParams, objXmlHttpHandler); 

    }

}

function if_scrollToDiv(divid) {

    // scroll to div
    var div = iasp_FindControl(divid);
    if (div != null) {
        window.scroll(0, if_absOffset(div) - 16);
    }
    
}

function if_absOffset(div) {
    return div.offsetParent && div.offsetTop + if_absOffset(div.offsetParent);
}


/* generic delete confirmation for admin pages */
function if_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(if_strDeleteItemConfirmation);
        }
    }
    return true;

}
