﻿//********************** AJAX ********************************************
function CallBack(serverURL, javaScriptHandler, content, asyc) {

    try { disableControls(true); } catch (e) { }
    try { onServerCallBackStart(); } catch (e) { }

    this.handler = javaScriptHandler;
    this.req = createRequest();
    this.serverHandlerName = serverURL;
    this.isAsyc = asyc;

    this.responseXML = "";
    this.responseText = "";

    var thisObj = this;

    this.handleCallBack = function(req, handler) {
        if (req.readyState == 4) {
            if (req.status == 200) {
                thisObj.responseXML = req.responseXML;
                thisObj.responseText = req.responseText;
                thisObj.lastResponse = thisObj.responseText;

                if (typeof handler == "string") {

                    try { eval(handler + "(req.responseXML);"); } catch (e) { }

                } else {

                    try { handler(req.responseXML); } catch (e) { }

                }
            } else {
                alert("An error occurred while processing your request.  Try again later.");
            }
            try { disableControls(false); } catch (e) { }
            try { onServerCallBackEnd(); } catch (e) { }
        }
    }

    this.processRequest = function(req, handler) {

        if (handler != null && thisObj.isAsyc) {
            req.onreadystatechange = function() { thisObj.handleCallBack(req, handler); }
        }
        req.open("POST", thisObj.serverHandlerName, thisObj.isAsyc);
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        req.send(thisObj.content);

        if (!thisObj.isAsyc) {

            thisObj.lastResponse = req.responseText;
            
            if (typeof handler == "string") {

                try { eval(handler + "(req.responseXML);"); } catch (e) { }

            } else {

                try { handler(req.responseXML); } catch (e) { }

            }

        }

    }

    thisObj.processRequest(this.req, this.handler);

    function createRequest() {
        var req = null;
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
        } else {
            try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        return req;
    }

}

//********************** HashTable ***************************************
function Hashtable() {

    this.keys = new Array();
    this.values = new Array();

    this.put = function(key, value) {

        for (var x = 0; x < this.keys.length; x++) {

            if (this.keys[x] != null && this.keys[x] == key) {

                this.values[x] = value;

                if (value == null) {

                    this.keys[x] = null;

                }

                return;

            }

        }

        if (value != null) {

            this.keys[this.keys.length] = key;
            this.values[this.values.length] = value;

        }

    }

    this.get = function(key) {

        for (var x = 0; x < this.keys.length; x++) {

            if (this.keys[x] != null && this.keys[x] == key) {

                return this.values[x];

            }

        }

        return null;

    }

    this.remove = function(key) {

        this.put(key, null);

    }

    this.indexOf = function(key) {

        for (var x = 0; x < this.keys.length; x++) {

            if (this.keys[x].toUpperCase() == key.toUpperCase()) {

                return x;

            }

        }

        return null;

    }

    this.sortByKey = function(ignoreCase) {

        for (var x = 0; x < this.keys.length; x++) {

            for (var y = 0; y < this.keys.length - 1; y++) {

                var thisKey = this.keys[y];
                var thisValue = this.values[y];
                var nextKey = this.keys[y + 1];
                var nextValue = this.values[y + 1];

                if (ignoreCase) {

                    thisKey = thisKey.toUpperCase();
                    nextKey = nextKey.toUpperCase();

                }

                if (thisKey > nextKey) {

                    var tempKey = this.keys[y];
                    var tempValue = this.values[y];

                    this.keys[y] = this.keys[y + 1];
                    this.values[y] = this.values[y + 1];

                    this.keys[y + 1] = tempKey;
                    this.values[y + 1] = tempValue;

                }

            }

        }

    }

}

//********************** Cookies *****************************************
function setCookie(name, value, expire) {

    var dt = new Date();

    if (expire) {

        dt.setTime(dt.getTime - 1000);

    } else {

        dt.setFullYear(9999, 12, 31);
    }

    document.cookie = name + "=" + value + "; expires=" + dt.toGMTString() + "; path=/";

}

function getCookie(name) {

    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;

}

//********************** Key Events **************************************
function getEventKeyCode(event) {

    if (window.event) {
        return window.event.keyCode;
    } else if (event != null) {
        return event.which;
    }

}

function handleEnterKeyButtonClick(e, button) {

    if (getEventKeyCode(e) == 13) {   //enter key

        button.click();
        return false;


    }

    return true;

}
 
//********************** Accordian ***************************************
function Accordian(div, direction, autoPlaySpeed, size) {

    this.parentDiv = div;
    this.speed = 1;
    this.dir = direction.toUpperCase();

    this.headerItems = new Array();
    this.contentItems = new Array();
    this.contentWidths = new Array();
    this.contentHeights = new Array();

    this.items = div.childNodes;
    this.timer = null;
    this.autoSlideItem = new Array();

    this.playSpeed = autoPlaySpeed;
    this.playTimer = null;

    this.divProcessed = false;
    this.size = size;

    this.active = false;
    this.pendingSection = null;

    var thisObj = this;

    this.isHorizontal = function() {
        return thisObj.dir == "H";
    }

    this.startOpenAnimation = function(element) {

    }

    this.startCloseAnimation = function(element) {

    }

    this.completeOpenAnimation = function(element) {

    }

    this.completeCloseAnimation = function(element) {

    }

    for (var x = 0; x < this.items.length; x++) {

        var e = this.items[x];

        this.autoSlideItem[x] = true;

        var headerItem = null;
        var contentItem = null;
        var contentChilds = e.childNodes;
        
        for (var y = 0; y < contentChilds.length; y++) {

            if (contentChilds[y].nodeName.toUpperCase() == "SPAN") {
                headerItem = contentChilds[y];
            }
            
            if (contentChilds[y].nodeName.toUpperCase() == "DIV") {
                contentItem = contentChilds[y];
            }
        }

        if (headerItem != null) {

            headerItem.onclick = function(evt) {

                if (thisObj.active) { return; }

                var source = getSourceEventElement(evt);

                while (source.innerHTML.toUpperCase().indexOf("<DIV") == -1) {
                    source = source.parentNode;
                }

                thisObj.active = true;

                clearInterval(thisObj.timer);

                thisObj.timer = setInterval(function() { thisObj.slideAccordian(source); }, thisObj.speed);

            }

            headerItem.onmouseover = function(evt) {

                this.style.cursor = "pointer";

            }

            headerItem.onmouseout = function(evt) {

                this.style.cursor = "default";

            }

        }

        thisObj.contentItems[x] = contentItem;
        thisObj.headerItems[x] = headerItem;

        if (contentItem != null) {

            if (thisObj.size == null) {

                thisObj.contentWidths[x] = contentItem.offsetWidth;
                thisObj.contentHeights[x] = contentItem.offsetHeight;

            } else {

                thisObj.contentWidths[x] = thisObj.size;
                thisObj.contentHeights[x] = thisObj.size;

            }

            contentItem.style.overflow = "hidden";

            if (thisObj.isHorizontal()) {

                contentItem.style.display = "inline";
                thisObj.contentWidths[x] = contentItem.offsetWidth;

                if (thisObj.size != null) {

                    thisObj.contentWidths[x] = thisObj.size;

                }

                contentItem.style.cssFloat = "left";
                contentItem.style.styleFloat = "left";

                if (contentItem.nodeName.toUpperCase() != "DIV" || thisObj.divProcessed) {
                    contentItem.style.width = "0px";
                } else {
                    contentItem.style.width = thisObj.contentWidths[x] + "px";
                    thisObj.divProcessed = true;
                }

            } else {

                if (contentItem.nodeName.toUpperCase() != "DIV" || thisObj.divProcessed) {
                    contentItem.style.height = "0px";
                } else {
                    contentItem.style.height = thisObj.contentHeights[x] + "px";
                    thisObj.divProcessed = true;
                }

            }

        }

        if (headerItem != null) {

            headerItem.style.overflow = "hidden";

            if (thisObj.isHorizontal()) {

                headerItem.style.cssFloat = "left";
                headerItem.style.styleFloat = "left";

            }

        }

    }

    this.startAnimation = function() {

        if (thisObj.playSpeed != null) {

            thisObj.playTimer = setInterval(function() { thisObj.automateAccordian(); }, thisObj.playSpeed);

        }

    }

    this.stopAnimation = function() {

        clearInterval(thisObj.playTimer);

    }

    thisObj.startAnimation();

    thisObj.parentDiv.onmouseover = function() {

        thisObj.stopAnimation();

    }

    this.slideAccordian = function(e) {

        var item = e;

        var continueAnimation = false;

        var startCloseEventProcessed = false;

        var increasingElement = null;

        thisObj.startOpenAnimation(e);

        for (var x = 0; x < thisObj.items.length; x++) {

            if (thisObj.contentItems[x] == null) continue;

            var size = parseInt(getStyle(thisObj.contentItems[x], "height"));

            if (thisObj.isHorizontal()) {
                size = parseInt(getStyle(thisObj.contentItems[x], "width"));
            }

            if (isNaN(size)) {
                size = 0;
            }

            if (size > 0 && !startCloseEventProcessed) {

                thisObj.startCloseAnimation(thisObj.items[x]);
                startCloseEventProcessed = true;

            }

            if (thisObj.items[x] != item) {

                if (size > 0) {

                    if (size - 20 <= 0) {

                        this.completeCloseAnimation(thisObj.items[x]);

                    }

                    if (thisObj.isHorizontal()) {

                        thisObj.contentItems[x].style.width = size - 20 + "px";

                    } else {

                        thisObj.contentItems[x].style.height = size - 20 + "px";

                    }


                    continueAnimation = true;

                }

            } else {

                increasingElement = e;

                if (thisObj.contentWidths[x] > size) {

                    if (thisObj.isHorizontal()) {

                        thisObj.contentItems[x].style.width = size + 20 + "px";

                        continueAnimation = true;

                    }

                }

                if (thisObj.contentHeights[x] > size) {

                    if (!thisObj.isHorizontal()) {

                        thisObj.contentItems[x].style.height = size + 20 + "px";

                        continueAnimation = true;

                    }

                }

            }

        }

        if (!continueAnimation) {

            clearInterval(thisObj.timer);

            if (increasingElement != null) {

                thisObj.active = false;
                thisObj.completeOpenAnimation(e);

                if (thisObj.pendingSection != null) {

                    thisObj.showSection(thisObj.pendingSection);
                    thisObj.pendingSection = null;

                }

            }

        }

    }

    this.automateAccordian = function() {

        var currentIdx = -1;
        var idx = 0;
        var firstIdx = -1;

        for (var x = 0; x < thisObj.items.length; x++) {

            if (thisObj.contentItems[x] == null) continue;

            if (thisObj.autoSlideItem[x] == false) continue;

            if (firstIdx == -1) {
                firstIdx = x;
            }

            var size = parseInt(getStyle(thisObj.contentItems[x], "height"));

            if (thisObj.isHorizontal()) {
                size = parseInt(getStyle(thisObj.contentItems[x], "width"));
            }

            if (isNaN(size)) {
                size = 0;
            }

            if (size > 0) {

                currentIdx = x;

            } else if (currentIdx > -1 && idx == 0) {

                idx = x;

            }

        }

        if (firstIdx > idx) {
            idx = firstIdx;
        }

        thisObj.active = true;

        clearInterval(thisObj.timer);

        thisObj.timer = setInterval(function() { thisObj.slideAccordian(thisObj.items[idx]); }, thisObj.speed);

    }

    this.showSection = function(divID) {

        for (var x = 0; x < thisObj.items.length; x++) {

            if (thisObj.items[x].id != null && thisObj.items[x].id.toUpperCase() == divID.toUpperCase()) {

                if (thisObj.active) {

                    thisObj.pendingSection = divID;
                    return;

                }

                thisObj.stopAnimation();

                var showItem = thisObj.items[x];

                thisObj.active = true;

                clearInterval(thisObj.timer);

                thisObj.timer = setInterval(function() { thisObj.slideAccordian(showItem); }, thisObj.speed);

            }

        }

    }

}

//****************************** Util Functions ************************************

function getSourceEventElement(e) {

    if (window.event) {
        return window.event.srcElement;
    } else if (e != null) {
        return e.target;
    }


}

function getAttr(e, attrName) {

    try {

        for (var y = 0; y < e.attributes.length; y++) {

            var attr = e.attributes[y];

            if (attr.nodeName.toUpperCase() == attrName.toUpperCase()) {

                return attr;

            }

        }

    } catch (e) { }

    return null;

}

function getStyle(oElm, sCssRule) {
    var sValue = "";
    if (document.defaultView && document.defaultView.getComputedStyle) {
        sValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(sCssRule);
    }
    else if (oElm.currentStyle) {
        sCssRule = sCssRule.replace(/\-(\w)/g, function(sMatch, p1) { return p1.toUpperCase(); });
        sValue = oElm.currentStyle[sCssRule];
    }
    return sValue;
}

function bindEvent(element, event, handler) {

    try {

        if (element.addEventListener) {
            element.addEventListener(event, handler, false);
        } else if (element.attachEvent) {
            element.attachEvent("on" + event, handler);
        } else {
            element.onload += handler;
        }

    } catch (e) { alert(e); }

}

function addBookMark() {

    var title = document.title;
    var url = document.URL;

    if (window.sidebar) {

        window.sidebar.addPanel(title, url, "");

    } else if (window.external) {

        window.external.AddFavorite(url, title);

    }

}

function formatCurrency(num) {

    num = "" + num;

    if (num.length == 0) {

        return num;

    }

    if (num.indexOf(".") == -1) {

        num = num + ".00";

    }

    var parts = num.split(".");

    while (parts[1].length < 2) {
        parts[1] += "0";
    }

    var formatted = "";
    var c = 0;

    for (var x = parts[0].length - 1; x >= 0; x--) {

        if (c == 3) {

            formatted = "," + formatted;
            c = 1;

        } else {

            c++;

        }

        formatted = parts[0].substr(x, 1) + formatted;

    }

    return "$" + formatted + "." + parts[1];

}

function getClipboard() {

    return window.clipboardData.getData('Text');

}

function setClipboard(text) {

    window.clipboardData.setData('Text', text);

}

function replaceString(str, search, replace) {

    var regex = new RegExp('(' + search + ')', 'gi');

    return str.replace(regex, replace);

}

function getQueryStringValues() {

    var values = new Hashtable();

    var q = window.location.search;

    q = trimString(q.substr(1));

    if (q.length > 0) {

        var items = q.split("&");

        for (var x = 0; x < items.length; x++) {

            var parts = items[x].split("=");

            var name = parts[0];

            var value = "";

            if (parts.length > 1) {

                value = parts[1];

            }

            values.put(name, value);

        }

    }

    return values;

}

function trimString(str) {

    var temp = str;

    var x = 0;

    while (temp.length > 0 && temp.substr(x, 1) == " ") {
        temp = temp.substr(x + 1);
        x++;
    }

    x = temp.length - 1;

    while (temp.length > 0 && temp.substr(x, 1) == " ") {
        temp = temp.substr(0, x);
        x--;
    }

    return temp;

}

//******************************* Scrolling Marquee **********************************************

function ScrollingMarquee(marqueeDiv, marqueewidth, marqueeheight) {

    this.marqueeDiv = marqueeDiv;
    this.marqueewidth = marqueewidth + "px";
    this.marqueeheight = marqueeheight + "px";
    this.marqueespeed = 2;
    this.initPause = 0;
    this.full = 1;
    this.marqueebgcolor = "#FFFFFF";
    this.pauseit = 1;

    //this.marqueecontent = "<nobr>" + this.marqueeDiv.innerHTML + "</nobr>";
    this.marqueecontent = this.marqueeDiv.innerHTML;

    this.copyspeed = this.marqueespeed;
    this.pausespeed = (this.pauseit == 0) ? this.copyspeed : 0;
    this.iedom = document.all || document.getElementById;
    
    if (this.iedom)
        document.write('<span id="' + this.marqueeDiv.id + 'temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">' + this.marqueecontent + '</span>');
    this.actualwidth = '';

    this.cross_marquee = null; 
    this.cross_marquee2 = null;
    this.ns_marquee = null;

    var thisObj = this;
    
    this.populate = function() {
        if (thisObj.iedom) {
            var initFill = (thisObj.full == 1) ? '8px' : parseInt(thisObj.marqueewidth) + 8 + "px";
            thisObj.actualwidth = document.getElementById(thisObj.marqueeDiv.id + "temp").offsetWidth;
            thisObj.cross_marquee = document.getElementById(thisObj.marqueeDiv.id + "iemarquee");
            thisObj.cross_marquee.style.left = initFill;
            thisObj.cross_marquee2 = document.getElementById(thisObj.marqueeDiv.id + "iemarquee2");
            thisObj.cross_marquee2.innerHTML = thisObj.cross_marquee.innerHTML = thisObj.marqueecontent;
            thisObj.cross_marquee2.style.left = (parseInt(thisObj.cross_marquee.style.left) + thisObj.actualwidth + 8) + "px";  
        }
        else if (document.layers) {
            ns_marquee = document.ns_marquee.document.ns_marquee2;
            ns_marquee.left = parseInt(marqueewidth) + 8;
            ns_marquee.document.write(marqueecontent);
            ns_marquee.document.close();
            actualwidth = ns_marquee.document.width;
        }
        var lefttime = setInterval(function() { thisObj.scrollmarquee(); }, 30);
    }

    bindEvent(window, 'load', this.populate);

    this.scrollmarquee = function() {
        var stepValue = 8;
        if (thisObj.iedom) {
            if (parseInt(thisObj.cross_marquee.style.left) < (thisObj.actualwidth * (-1) + stepValue))
                thisObj.cross_marquee.style.left = (parseInt(thisObj.cross_marquee2.style.left) + thisObj.actualwidth + stepValue) + "px";
            if (parseInt(thisObj.cross_marquee2.style.left) < (thisObj.actualwidth * (-1) + stepValue))
                thisObj.cross_marquee2.style.left = (parseInt(thisObj.cross_marquee.style.left) + thisObj.actualwidth + stepValue) + "px";
            thisObj.cross_marquee2.style.left = parseInt(thisObj.cross_marquee2.style.left) - thisObj.copyspeed + "px";
            thisObj.cross_marquee.style.left = parseInt(thisObj.cross_marquee.style.left) - thisObj.copyspeed + "px";
        }
        else if (document.layers) {
            if (ns_marquee.left > (actualwidth * (-1) + 8))
                ns_marquee.left -= copyspeed;
            else
                ns_marquee.left = parseInt(marqueewidth) + 8;
        }
    }

    if (this.iedom || document.layers) {

        var html = ''; 
        
        //html = '<table border="0" cellspacing="0" cellpadding="0"><td>';
        
        if (this.iedom) {
            html += '<div style="position:relative;width:' + this.marqueewidth + ';height:' + this.marqueeheight + ';overflow:hidden">';
            html += '<div style="position:absolute;width:' + this.marqueewidth + ';height:' + this.marqueeheight + ';background-color:' + this.marqueebgcolor + ';overflow:hidden;">';
            html += '<div id="' + this.marqueeDiv.id + 'iemarquee" style="position:absolute;left:0px;top:3px;display:inline;overflow:none;"></div>';
            html += '<div id="' + this.marqueeDiv.id + 'iemarquee2" style="position:absolute;left:0px;top:3px;display:inline;overflow:none;"></div>';
            html += '</div></div>';
        }
        else if (document.layers) {
            html += '<ilayer width=' + marqueewidth + ' height=' + marqueeheight + ' name="ns_marquee" bgColor=' + marqueebgcolor + '>';
            html += '<layer name="ns_marquee2" left=0 top=3 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>';
            html += '</ilayer>';
        }
        //html += '</td></table>';

        this.marqueeDiv.innerHTML = html;

        var marqueeDivs = this.marqueeDiv.getElementsByTagName("div");

        for (var i = 0; i < marqueeDivs.length; i++) {

            if (marqueeDivs[i].id == marqueeDiv.id + "iemarquee") {

                marqueeDivs[i].parentNode.onmouseover = function() { thisObj.copyspeed = thisObj.pausespeed; }
                marqueeDivs[i].parentNode.onmouseout = function() { thisObj.copyspeed = thisObj.marqueespeed; }

            }

        }
        
    }

}

//********************************** DataView Grid **********************************************************

function DataViewGrid(parentDiv) {

    this.parentDiv = parentDiv;
    this.thumbNailCSSClass = null;
    this.itemWidth = 150;
    this.itemHeight = 170;

    this.showViews = true;
    this.currentView = "Thumbnail";

    this.recordItems = new Array();

    this.currentSortField = null;
    this.currentSortDirection = null;

    this.noDataMessage = "Data does not exist.";
    this.searchNotFound = "We could not find what you are looking for.  Please try searching another item.";

    this.stores = new Hashtable();
    this.currentFilter = "";

    this.clearItemsCommand = "Remove All Items";

    this.activeSearches = 0;
    this.currentSearch = "";

    this.priorityStores = "";

    this.pageSize = 8;
    this.currentPage = 1;

    this.cache = new Hashtable();
    this.cacheStores = new Hashtable();

    var thisObj = this;

    this.addItem = function(item) {
        thisObj.recordItems[thisObj.recordItems.length] = item;
        thisObj.stores.put(item.store, item.store);
    }

    this.removeItem = function(item) {
        for (var x = 0; x < thisObj.recordItems.length; x++) {
            if (thisObj.recordItems[x] != null && item.id == thisObj.recordItems[x].id) {
                thisObj.recordItems[x] = null;
            }
        }
    }

    this.getItem = function(id) {
        for (var x = 0; x < thisObj.recordItems.length; x++) {
            if (id == thisObj.recordItems[x].id) {
                return thisObj.recordItems[x];
            }
        }
        return null;
    }

    this.clear = function() {
        thisObj.recordItems = new Array();
        thisObj.stores = new Hashtable();
        thisObj.currentFilter = "";
        thisObj.currentSortDirection = null;
        thisObj.currentSortField = null;
        thisObj.currentView = "Thumbnail";
        thisObj.currentPage = 1;
    }

    this.sort = function(field) {

        if (thisObj.currentSortField == null) {

            thisObj.currentSortDirection = "DSC";
            thisObj.currentSortField = "Name";

        }

        if (field == thisObj.currentSortField) {

            if (thisObj.currentSortDirection == "DSC") {

                thisObj.currentSortDirection = "ASC";

            } else {

                thisObj.currentSortDirection = "DSC";

            }

        } else {

            thisObj.currentSortDirection = "ASC";

        }

        thisObj.currentSortField = field;

        var currentValue = null;
        var nextValue = null;
        var temp = null;

        for (var x = 0; x < thisObj.recordItems.length; x++) {

            for (var y = 0; y < thisObj.recordItems.length - 1; y++) {

                if (field.toUpperCase() == "NAME") {
                    currentValue = thisObj.recordItems[y].name;
                    nextValue = thisObj.recordItems[y + 1].name
                }

                if (field.toUpperCase() == "DESCRIPTION") {
                    currentValue = thisObj.recordItems[y].desc;
                    nextValue = thisObj.recordItems[y + 1].desc;
                }

                if (field.toUpperCase() == "PRICE") {
                    currentValue = parseFloat(thisObj.recordItems[y].price);
                    nextValue = parseFloat(thisObj.recordItems[y + 1].price);
                }

                if (field.toUpperCase() == "STORE") {
                    currentValue = thisObj.recordItems[y].store;
                    nextValue = thisObj.recordItems[y + 1].store;
                }

                if (thisObj.currentSortDirection == "ASC") {

                    if (currentValue > nextValue) {

                        temp = thisObj.recordItems[y];
                        thisObj.recordItems[y] = thisObj.recordItems[y + 1];
                        thisObj.recordItems[y + 1] = temp;

                    }

                } else {

                    if (currentValue < nextValue) {

                        temp = thisObj.recordItems[y];
                        thisObj.recordItems[y] = thisObj.recordItems[y + 1];
                        thisObj.recordItems[y + 1] = temp;

                    }

                }

            }

        }

        thisObj.currentPage = 1;

        thisObj.refresh();

    }

    this.refresh = function() {

        var html = "";

        var showThumbnails = true;

        if (this.recordItems.length == 0) {

            thisObj.parentDiv.innerHTML = thisObj.noDataMessage;
            return;

        }

        if (thisObj.showViews) {

            html += "<table style=\"width:100%;\"><tr><td><a style=\"font-size:10px;\" href=\"javascript:return false;\" id=\"" + thisObj.parentDiv.id + "ToggleViewLink\">";

            if (thisObj.currentView == "Thumbnail") {
                html += "Show List View";
                showThumbnails = true;
            } else {
                html += "Show Thumbnail View";
                showThumbnails = false;
            }

            html += "<a/></td><td align=\"right\" style=\"font-size:10px;\">";

            html += "Filter: <select style=\"font-size:10px;\"><option value=\"\">Show All Stores</option>";

            this.stores.sortByKey(true);

            for (var x = 0; x < this.stores.keys.length; x++) {

                var selected = "";
                var store = this.stores.keys[x];

                if (this.currentFilter == store) {

                    selected = " selected=\"true\"";

                }

                html += "<option" + selected + " value=\"" + store + "\">" + store + "</option>";

            }

            html += "</select><td></tr></table>";

        }

        var items = thisObj.recordItems;
        var count = 0;

        if (thisObj.currentFilter.length > 0) {

            items = new Array();

            for (var x = 0; x < thisObj.recordItems.length; x++) {

                if (thisObj.currentFilter == thisObj.recordItems[x].store) {

                    items[count] = thisObj.recordItems[x];
                    count++;

                }

            }

        }

        var itemCount = 0;
        var startingIdx = (thisObj.currentPage - 1) * thisObj.pageSize;

        for (var x = startingIdx; x < items.length; x++) {

            var item = items[x];

            if (thisObj.currentFilter.length > 0 &&
                thisObj.currentFilter != item.store) {

                continue;

            }

            if (item == null) {
                continue;
            }

            if (itemCount > thisObj.pageSize) {

                break;

            }

            if (showThumbnails) {

                itemCount++;

                if (itemCount > thisObj.pageSize) {

                    break;

                }

                if (thisObj.thumbNailCSSClass == null) {

                    //html += "<div style=\"vertical-align:bottom;width:" + thisObj.itemWidth + "px;height:" + thisObj.itemHeight + "px;margin-left:10px;float:left;text-align:center;\">";
                    html += "<div style=\"display:table;table-layout:fixed;float:left;text-align:center;width:" + thisObj.itemWidth + "px;min-width:" + thisObj.itemWidth + "px;height:" + thisObj.itemHeight + "px;min-height:" + thisObj.itemHeight + "px;margin-left:10px;\">";
                    html += "<div style=\"display:table-cell;vertical-align:bottom;\">";

                } else {

                    html += "<div><div class=\"" + thisObj.thumbNailCSSClass + "\">";

                }

                html += "<a href=\"" + item.href + "\" title=\"" + item.name + " &#10;" + item.desc + " &#10;" + formatCurrency(item.price) + "\" target=\"_blank\" id=\"" + thisObj.parentDiv.id + "" + item.id + "\">";
                html += "<img src=\"" + item.imgURL + "\" style=\"max-width:" + thisObj.itemWidth + "px;max-height:" + parseInt(thisObj.itemHeight * .70) + "px;border-style:none;\" onError=\"this.src='noImg.gif';\" /> <br />";

                var name = item.name;

                html += shortenText(name, 20) + " ";
                html += formatCurrency(item.price);

                html += "</a>";
                html += "</div></div>";

            } else {

                html += "<table id=\"" + thisObj.parentDiv.id + "DataViewGridTable\" style=\"width:100%;\" cellpadding=\"0px\" cellspacing=\"0px\">";

                html += "<tr>";

                html += "<td width=\"" + thisObj.itemWidth + "px\">Name</td>";
                html += "<td>Store</td>";
                html += "<td>Description</td>";
                html += "<td align=\"right\">Price</td>";

                html += "</tr>";

                var bgColor = "style=\"background-color: #CCCCCC\"";

                for (var x = startingIdx; x < items.length; x++) {

                    var item = items[x];

                    if (thisObj.currentFilter.length > 0 &&
                        thisObj.currentFilter != item.store) {

                        continue;

                    }

                    itemCount++;

                    if (itemCount > thisObj.pageSize) {

                        break;

                    }

                    html += "<tr " + bgColor + ">";

                    html += "<td>";

                    if (thisObj.thumbNailCSSClass == null) {

                        html += "<div style=\"margin:10px;\">";

                    } else {

                        html += "<div class=\"" + thisObj.thumbNailCSSClass + "\">";

                    }

                    html += "<a href=\"" + item.href + "\" title=\"" + item.name + " &#10;" + item.desc + " &#10;" + formatCurrency(item.price) + "\" target=\"_blank\" id=\"" + thisObj.parentDiv.id + "" + item.id + "\">";
                    html += "<img src=\"" + item.imgURL + "\" style=\"max-width:" + thisObj.itemWidth + "px;max-height:" + thisObj.itemHeight + "px;border-style:none;\" onError=\"this.src='noImg.gif';\" /> <br />";

                    var name = item.name;

                    html += name + "<br />";
                    html += formatCurrency(item.price);

                    html += "</a>";
                    html += "</div>";

                    html += "</td>";

                    html += "<td valign=\"top\"><a href=\"" + item.href + "\" id=\"" + thisObj.parentDiv.id + "" + item.id + "\" target=\"_blank\">" + item.store + "</a></td>";
                    html += "<td valign=\"top\"><a href=\"" + item.href + "\" id=\"" + thisObj.parentDiv.id + "" + item.id + "\" target=\"_blank\">" + shortenText(item.desc, 500) + "</a></td>";
                    html += "<td valign=\"top\" align=\"right\"><a href=\"" + item.href + "\" id=\"" + thisObj.parentDiv.id + "" + item.id + "\" target=\"_blank\">" + formatCurrency(item.price) + "</a></td>"

                    html += "</tr>";

                    if (bgColor.length == 0) {
                        bgColor = "style=\"background-color: #CCCCCC\"";
                    } else {
                        bgColor = "";
                    }

                }

                html += "</table>";

            }

        }

        itemCount = items.length;

        if (itemCount > thisObj.pageSize) {

            html += "<div style=\"width:100%;text-align:center;clear:both;padding-top:10px;\">Page ";

            var page = 1;

            while (itemCount > ((page - 1) * thisObj.pageSize)) {

                if (thisObj.currentPage == page) {

                    html += page + " ";

                } else {

                    html += "<a href=\"javascript:return false;\" id=\"Page" + page + "\">" + page + "</a> ";

                }

                page++;

            }

            html += "</div>";

        }

        if (thisObj.clearItemsCommand.length > 0) {

            html += "<div style=\"width:100%;text-align:right;font-size:10px;clear:both;padding-top:10px;\">";
            html += "<a href=\"javascript:return false;\" id=\"RemoveItems\">" + thisObj.clearItemsCommand + "</a>";
            html += "</div>";

        }

        thisObj.parentDiv.innerHTML = html;

        var anchors = thisObj.parentDiv.getElementsByTagName("a");

        for (var x = 0; x < anchors.length; x++) {

            if (anchors[x].id == thisObj.parentDiv.id + "ToggleViewLink") {

                anchors[x].onclick = function() {

                    if (this.innerHTML.indexOf("Thumbnail") > -1) {

                        thisObj.currentView = "Thumbnail";

                    } else {

                        thisObj.currentView = "List";

                    }

                    thisObj.refresh();

                    return false;

                }

            } else if (anchors[x].id == "RemoveItems") {

                anchors[x].onclick = function() {

                    if (confirm("Are you sure you want to remove all items?")) {

                        thisObj.currentPage = 1;
                        thisObj.clear();
                        thisObj.refresh();
                        return false;

                    }

                }

            } else if (anchors[x].id.indexOf("Page") == 0) {

                anchors[x].onclick = function() {

                    var page = parseInt(this.id.substr(4));

                    thisObj.currentPage = page;

                    thisObj.refresh();

                    return false;

                }

            } else {

                var id = anchors[x].id.substr(thisObj.parentDiv.id.length);

                if (!isNaN(id) && id.length > 0) {

                    anchors[x].onclick = function() {

                        var index = this.id.substr(thisObj.parentDiv.id.length);

                        thisObj.onClick(thisObj.getItem(parseInt(index)));

                    }

                }

            }

        }

        var tables = thisObj.parentDiv.getElementsByTagName("table");

        for (var x = 0; x < tables.length; x++) {

            if (tables[x].id == thisObj.parentDiv.id + "DataViewGridTable") {

                var headerRow = tables[x].getElementsByTagName("tr")[0];

                var headerCells = headerRow.getElementsByTagName("td");

                for (y = 0; y < headerCells.length; y++) {

                    var columnName = headerCells[y].innerHTML;

                    headerCells[y].innerHTML = "<a href=\"return false;\">" + columnName + "</a>";

                    var link = headerCells[y].getElementsByTagName("a")[0];

                    link.onclick = function() {

                        thisObj.sort(this.innerHTML);

                        return false;

                    }

                }

            }

        }

        var filterSelect = thisObj.parentDiv.getElementsByTagName("select");

        if (filterSelect.length > 0) {

            filterSelect[0].onchange = function() {

                thisObj.currentPage = 1;
                thisObj.currentFilter = this.value;
                thisObj.refresh();

            }

        }

        thisObj.parentDiv.scrollTop = 0;

    }

    this.onClick = function(item) {

    }

    this.performSearch = function(searchURL, currentSearch) {

        thisObj.currentSearch = currentSearch;

        if (thisObj.cache.get(currentSearch.toUpperCase()) != null) {

            thisObj.recordItems = thisObj.cache.get(currentSearch.toUpperCase());
            thisObj.stores = thisObj.cacheStores.get(currentSearch.toUpperCase());
            thisObj.currentPage = 1;

            thisObj.applyDefaultSort();

            thisObj.refresh();

            thisObj.searchComplete();

            return;

        }

        showStatus("Searching for items");
        //showMessage("Searching for items...");

        thisObj.activeSearches++;

        new CallBack(searchURL, thisObj.processSearch, "", true);

    }

    this.processSearch = function(rootElement) {

        try {

            var items = rootElement.getElementsByTagName("item");

            var maxCount = items.length;

            for (var x = 0; x < maxCount; x++) {

                var name = getElementValue(items[x], "name", "");
                var price = getElementValue(items[x], "price", "0.00");
                var href = getElementValue(items[x], "href", "");
                var desc = getElementValue(items[x], "desc", "");
                var imgURL = getElementValue(items[x], "imgURL", "");
                var store = getElementValue(items[x], "store", "");

                var salePrice = getElementValue(items[x], "sale-price", "0.00");

                if (salePrice.length > 0 && salePrice != "0.00" && !isNaN(salePrice)) {

                    if (parseFloat(salePrice) > 0) {

                        price = salePrice;

                    }

                }

                store = replaceString(store, "affiliate ", "");

                thisObj.addItem(new DataViewGridItem(name, price, href, desc, imgURL, store));

            }

        } catch (e) { }

        thisObj.activeSearches--;

        if (thisObj.activeSearches > 0) {
            return;
        }

        thisObj.currentPage = 1;

        if (thisObj.recordItems.length > 0) {

            thisObj.cache.put(thisObj.currentSearch.toUpperCase(), thisObj.recordItems);
            thisObj.cacheStores.put(thisObj.currentSearch.toUpperCase(), thisObj.stores);

            thisObj.applyDefaultSort();

            thisObj.refresh();

            //closeMessage();

            closeStatus();

            thisObj.searchComplete();

        } else {

            thisObj.parentDiv.innerHTML = thisObj.searchNotFound;

            //closeMessage();

            closeStatus();

        }

    }

    this.applyDefaultSort = function() {

        var matchItems = new Array();
        var priorityStoreItems = new Array();
        var priorityContainItems = Array();
        var containItems = new Array();
        var unMatchedItems = new Array();

        var priorityTable = new Hashtable();

        var priorityArray = thisObj.priorityStores.split(",");

        for (var x = 0; x < priorityArray.length; x++) {

            priorityTable.put(priorityArray[x], priorityArray[x]);

        }

        for (var x = 0; x < thisObj.recordItems.length; x++) {

            var item = thisObj.recordItems[x];

            //if (item.name.toUpperCase() == thisObj.currentSearch.toUpperCase() || item.name.toUpperCase().indexOf(thisObj.currentSearch.toUpperCase()) == 0) {
            if (item.name.toUpperCase() == thisObj.currentSearch.toUpperCase()) {

                matchItems[matchItems.length] = item;

            } else if (thisObj.indexSearch(item, thisObj.currentSearch) && (thisObj.priorityStores.toUpperCase() + ",").indexOf(item.store.toUpperCase() + ",") > -1) {

                priorityContainItems[priorityContainItems.length] = item;
                item.sortOrder = (priorityTable.indexOf(item.store) + 1) * 1000000;

            } else if ((thisObj.priorityStores.toUpperCase() + ",").indexOf(item.store.toUpperCase() + ",") > -1) {

                priorityStoreItems[priorityStoreItems.length] = item;
                item.sortOrder = (priorityTable.indexOf(item.store) + 1) * 1000000;

                //item.sortOrder = priorityTable.keys.length - parseInt(item.sortOrder);

                //item.sortOrder = item.sortOrder + "";

            } else if (thisObj.indexSearch(item, thisObj.currentSearch)) {

                containItems[containItems.length] = item;

            } else {

                unMatchedItems[unMatchedItems.length] = item;

            }

        }

        thisObj.sortByPrice(matchItems, false);
        thisObj.sortByPrice(priorityContainItems, true);
        thisObj.sortByPrice(containItems, false);
        thisObj.sortByPrice(priorityStoreItems, true);

        var index = 0;

        for (var x = 0; x < matchItems.length; x++) {
            thisObj.recordItems[index] = matchItems[x];
            index++;
        }

        for (var x = 0; x < priorityContainItems.length; x++) {
            thisObj.recordItems[index] = priorityContainItems[x];
            index++;
        }

        for (var x = 0; x < priorityStoreItems.length; x++) {
            thisObj.recordItems[index] = priorityStoreItems[x];
            index++;
        }

        for (var x = 0; x < containItems.length; x++) {
            thisObj.recordItems[index] = containItems[x];
            index++;
        }

        for (var x = 0; x < unMatchedItems.length; x++) {
            thisObj.recordItems[index] = unMatchedItems[x];
            index++;
        }

    }

    this.sortByPrice = function(items, appendSortKey) {

        for (var x = 0; x < items.length; x++) {

            for (var y = 0; y < items.length - 1; y++) {

                var currentPrice = parseFloat(items[y].price);
                var nextPrice = parseFloat(items[y + 1].price);

                if (appendSortKey) {

                    currentPrice = parseFloat(items[y].sortOrder + currentPrice);
                    nextPrice = parseFloat(items[y + 1].sortOrder + nextPrice);

                }

                if (currentPrice > nextPrice) {

                    var temp = items[y];
                    items[y] = items[y + 1];
                    items[y + 1] = temp;

                }

            }

        }

    }

    this.indexSearch = function(item, search) {

        var searchWords = search.toUpperCase().split(" ");

        for (var x = 0; x < searchWords.length; x++) {

            if (item.name.toUpperCase().indexOf(searchWords[x]) == -1) {

                return false;

            }

        }

        return true;

    }

    this.searchComplete = function() {

    }

}

var idCounter = 0;

function DataViewGridItem(name, price, href, desc, imgURL, store) {

    this.id = ++idCounter;
    this.name = name;
    this.price = price;
    this.href = href;
    this.desc = desc;
    this.imgURL = imgURL;
    this.store = store;

    this.sortOrder = "999";

}

function handleChars(str) {

    var temp = str.replace(/\"/g, "").replace(/\'/g, "");
    
    return trimString(temp);

}

function getElementValue(element, item, defaultValue) {

    var items = element.getElementsByTagName(item);

    if (items == null || items.length == 0) {

        return defaultValue;

    }

    if (items[0].firstChild == null) {

        return defaultValue;

    }

    return handleChars(items[0].firstChild.nodeValue);

}

function shortenText(text, length) {

    var originalText = text;

    if (text.length > length) {

        text = text.substr(0, length);

        if (text.indexOf(" ") > -1) {
            text = text.substr(0, text.lastIndexOf(" ")) + "...";
        } else {
            text = originalText.substr(0, length) + "...";
        }

    }

    return text;

}

//**************************** Popup Message *********************************************
var popupItem = null;
function showMessage(text, textStyleClass, additionalCommands, tabs) {

    if (popupItem == null) {

        popupItem = document.createElement("span");
        popupItem.id = "_popupWindowItem";
        document.forms[0].appendChild(popupItem);

    }

    var tabStr = "";

    if (tabs != null) {

        tabStr += "<div style=\"border-bottom:solid thin;width:100%;\">";

        var tabParts = tabs.split(";");

        for (var x = 0; x < tabParts.length; x++) {

            tabStr += "<a href=\"javascript:showTab(" + x + ");\" id=\"tab" + x + "\" class=\"tab\">" + tabParts[x] + "</a>";

        }

        tabStr += "</div><br />";

    }

    var t = "<span id=\"popupDisplayMessageError\" style=\"color:#FF0000;\"></span>" + tabStr + text;

    if (additionalCommands == null) {
        additionalCommands = "";
    }

    t = "<table><tr><td>" + t + "</td></tr><tr><td align=\"center\"><br />" + additionalCommands + " <a href=\"javascript:closeMessage();\">Close</a></td></tr></table>"

    popupItem.innerHTML = t;
    popupItem.className = textStyleClass;
    popupItem.removeAttribute("style");

    var position = "absolute";

    s = "position:" + position + ";z-index:999;border:solid #000000;padding:10px;overflow:auto;background-color: #FFFFFF;";

    popupItem.removeAttribute("style");
    popupItem.setAttribute("style", s);
    popupItem.style.cssText = s;
    
    var left = (getWindowWidth() - popupItem.offsetWidth) / 2;

    var top = 0;
    top = getScrollXY()[1];

    s = "left:" + left + "px;top:" + top + "px;position:" + position + ";z-index:999;border:solid #000000;padding:10px;overflow:auto;background-color: #FFFFFF;";

    popupItem.removeAttribute("style");
    popupItem.setAttribute("style", s);
    popupItem.style.cssText = s;

    popupItem.style.display = "block";

    var inputs = popupItem.getElementsByTagName("input");

    if (tabs != null) {

        showTab(0);

    }

    if (inputs.length > 0) {

        try {

            inputs[0].focus();

        } catch (e) { }

    }

}

function showTab(tabId) {

    var activeContent = null;

    for (var x = 0; x < 10; x++) {

        var tabElement = document.getElementById("tab" + x);
        var tabContentElement = document.getElementById("tabContent" + x);

        if (tabElement != null) {

            if (x == tabId) {

                tabElement.className = "activeTab";
                activeContent = tabContentElement;

            } else {

                tabElement.className = "tab";

                if (tabContentElement != null) {

                    tabContentElement.style.display = "none";

                }

            }

        } else {

            break;

        }

    }

    if (activeContent != null) {

        activeContent.style.display = "block";

        var inputs = activeContent.getElementsByTagName("input");

        if (inputs.length > 0) {

            try {

                inputs[0].focus();

            } catch (e) { }

        }

    }

}

function closeMessage() {

    if (popupItem != null) {
        popupItem.style.display = 'none';
    }

}

function getScrollXY() {

    var scrOfX = 0, scrOfY = 0;

    if (typeof (window.pageYOffset) == 'number') {

        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;

    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {

        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;

    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {

        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;

    }

    //window.status = scrOfX + ":" + scrOfY;

    return [scrOfX, scrOfY];

}

function getWindowWidth() {

    return document.documentElement.clientWidth;

}

function getWindowHeight() {

    return document.documentElement.clientHeight;

}

//**********************************  Auto Assist *************************************************
function AutoAssist(textBox) {

    this.sourceTextBox = textBox;
    this.values = "";
    this.valueArray = null;
    this.minChars = 3;

    this.selectElement = document.createElement("SELECT");
    this.selectElement.id = this.sourceTextBox.id + "AutoAssistList";
    this.selectElement.size = 7;
    document.forms[0].appendChild(this.selectElement);

    this.isInputActive = false;
    this.isSelectActive = false;

    this.selectElement.style.visibility = "hidden";

    var thisObj = this;

    this.sourceTextBox.onblur = function(event) {

        thisObj.isInputActive = false;
        thisObj.handleBlur();

    }

    this.sourceTextBox.onfocus = function(event) {

        thisObj.isInputActive = true;

    }

    this.selectElement.onblur = function() {

        thisObj.isSelectActive = false;
        thisObj.handleBlur();

    }

    this.selectElement.onfocus = function() {

        thisObj.isSelectActive = true;

    }

    this.handleBlur = function() {

        var timer = setTimeout(function() { try { if (!thisObj.isInputActive && !thisObj.isSelectActive) thisObj.selectElement.style.visibility = "hidden"; } catch (e) { } }, 100);

    }

    this.applyValues = function(values) {

        if (values == null) {

            values = "";

        }

        thisObj.values = values;

        var items = thisObj.values.split("|");

        for (var x = 0; x < items.length; x++) {

            for (y = 0; y < items.length - 1; y++) {

                if (items[y] > items[y + 1]) {

                    var temp = items[y];
                    items[y] = items[y + 1];
                    items[y + 1] = temp;

                }

            }

        }

        thisObj.valueArray = items;

    }

    this.sourceTextBox.onkeyup = function(event) {

        var keyCode = getEventKeyCode(event);
        var keyPressed = String.fromCharCode(keyCode).toUpperCase();

        if ("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ".indexOf(keyPressed) == -1 && keyCode != 40 && keyCode != 13) {

            return;

        }

        if (thisObj.sourceTextBox.value.length < thisObj.minChars) {

            thisObj.selectElement.style.visibility = "hidden";
            return;

        }

        if (thisObj.valueArray == null) {

            thisObj.selectElement.style.visibility = "hidden";
            return;

        }

        if (keyCode == 13) {  //enter key
            thisObj.selectElement.style.visibility = "hidden";
            return;
        }

        for (var x = thisObj.selectElement.options.length - 1; x >= 0; x--) {

            thisObj.selectElement.remove(x);

        }

        for (var x = 0; x < thisObj.valueArray.length; x++) {

            if (thisObj.valueArray[x].toUpperCase().indexOf(thisObj.sourceTextBox.value.toUpperCase()) > -1) {

                thisObj.selectElement.options[thisObj.selectElement.options.length] = new Option(thisObj.valueArray[x], thisObj.valueArray[x]);

            }

        }

        if (thisObj.selectElement.options.length == 0) {

            thisObj.selectElement.style.visibility = "hidden";

        } else {

            var left = 0;
            var top = thisObj.sourceTextBox.offsetHeight;
            var parent = thisObj.sourceTextBox;
            var width = thisObj.sourceTextBox.offsetWidth;

            while (parent != null) {
                left = left + parent.offsetLeft;
                top = top + parent.offsetTop;
                parent = parent.offsetParent;
            }

            var s = "left:" + left + "px;top:" + top + "px;width:" + width + "px;position:absolute;z-index:99;";

            thisObj.selectElement.removeAttribute("style");
            thisObj.selectElement.setAttribute("style", s);

            thisObj.selectElement.style.cssText = s;

            if (keyCode == 40) {   //down arrow

                thisObj.isSelectActive = true;
                thisObj.selectElement.focus();

                if (thisObj.selectElement.options.length > 0) {

                    thisObj.selectElement.selectedIndex = 0;

                }

            } else {

                if (thisObj.selectElement.options.length > 0) {

                    thisObj.selectElement.selectedIndex = -1;

                }

            }

        }

    }

    this.selectElement.ondblclick = function(event) {

        thisObj.selectOption();

    }

    this.selectElement.onkeypress = function(event) {

        if (getEventKeyCode(event) == 13) {   //enter key

            thisObj.selectOption();

        }

    }

    this.itemSelected = function(selection) {

    }

    this.selectOption = function() {

        var selection = thisObj.selectElement.options[thisObj.selectElement.selectedIndex].text;

        thisObj.sourceTextBox.value = selection;

        thisObj.selectElement.style.visibility = "hidden";

        thisObj.itemSelected(selection);

    }

}

//**************************** Status Message *********************************************
var statusItem = null;
var statusTimer = null;
var statusText = "";
var statusWidth = 140;

function showStatus(text) {

    statusText = text;

    if (statusItem == null) {

        statusItem = document.createElement("span");
        statusItem.id = "_statusItem";
        document.forms[0].appendChild(statusItem);

    }

    statusItem.innerHTML = "<nobr>" + text + "&nbsp;&nbsp;&nbsp;</nobr>";

    statusItem.removeAttribute("style");

    var position = "absolute";

    var s = "position:" + position + ";z-index:9999;padding:10px;background-color: #FFFFFF;overflow:none; width:" + statusWidth + "px;";

    statusItem.removeAttribute("style");
    statusItem.setAttribute("style", s);
    statusItem.style.cssText = s;

    positionStatus();

    bindEvent(window, "resize", positionStatus);

    statusTimer = setInterval(updatePeriod, 500);

}

function updatePeriod() {

    var count = 0;
    var html = statusItem.innerHTML;

    for (var x = 0; x < html.length; x++) {

        if (html.substr(x, 1) == ".") {

            count++;

        }

    }

    var periods = "";

    if (count < 3) {

        for (var x = 0; x < count; x++) {

            periods = periods + ".";

        }

        periods = periods + ".";

    } else {

        count = 0;

    }

    var spaceCount = 3 - count;

    for (var x = spaceCount; x <= 3; x++) {

        periods = periods + "&nbsp;";

    }

    statusItem.innerHTML = "<nobr>" + statusText + periods + "</nobr>";

}

function positionStatus() {

    var left = (getWindowWidth() - statusItem.offsetWidth);
    var top = (getWindowHeight() - statusItem.offsetHeight);

    position = "fixed";

    s = "left:" + left + "px;top:" + top + "px;position:" + position + ";z-index:999;padding:10px;overflow:none;background-color:#0000FF;color:#FFFFFF;width:" + statusWidth + "px;";

    statusItem.removeAttribute("style");
    statusItem.setAttribute("style", s);
    statusItem.style.cssText = s;

    statusItem.style.display = "block";

}

function closeStatus() {

    if (statusItem != null) {
        statusItem.style.display = 'none';
        clearInterval(statusTimer);
    }

}
