var shared = {
    "_init" : false,
    "_ie" : false,
    "_opera" : false,
    "_safari" : false,
    "_konqueror" : false,
    "_mozilla" : false,
    "_mousex" : null,
    "_mousey" : null,
    "_offsetx" : null,
    "_offsety" : null,
    "_dragobj" : null,
    "_dragflag" : null,

    "init" : function()
    {
        if(shared._init) return;

        shared._ie = (document.documentElement.getAttribute("style") == document.documentElement.style);
        var ua = navigator.userAgent;
        shared._opera = (window.opera);
        shared._safari = (ua.indexOf("Safari") != -1);
        shared._konqueror = (ua.indexOf("Konqueror") != -1);
        shared._mozilla  = (((a = navigator.userAgent.split("Gecko/")[1]) ? a.split(" ")[0] : 0) >= 20011128);

        shared._init = true;
    },

    "text" : function(text)
    {
        return document.createTextNode(text);
    },

    "element" : function(name, child, properties)
    {
        shared.init();
        var node = document.createElement(name);
        if(properties)
        {
            for(var i in properties)
            {
                if(shared._ie && (i.toLowerCase()).substr(0, 2) === "on")
                {
                    node.setAttribute(i, new Function(properties[i]));
                }else if(i.toLowerCase() === "csstext")
                {
                    node.style.cssText = properties[i];
                }else if(i.toLowerCase() === "classname")
                {
                    node.className = properties[i];
                }else
                {
                    node.setAttribute(i, properties[i]);
                }
            }
        }
        if(child) node.appendChild(child);
        return node;
    },

    "bodyappend" : function(node, id)
    {
        if(!node)
        {
            if(!id || !$(id)) return;
            node = $(id);
        }
        document.getElementsByTagName("body")[0].appendChild(node);
    },

    "bodyremove" : function(id)
    {
        if(!$(id)) return;
        document.getElementsByTagName("body")[0].removeChild($(id));
    },

    "clear" : function(id)
    {
        if(!$(id)) return;
        while($(id).childNodes.length > 0)
        {
            $(id).removeChild($(id).childNodes[0]);
        }
    },

    "browse_width" : function()
    {
        shared.init();
        if(window.opera)
        {
            return parseInt(window.innerWidth);          //o6,o7
        }
        else if(document.all)
        {
            if(shared._ie)
            {
                return parseInt(document.documentElement.clientWidth);
            }
            return parseInt(document.body.clientWidth);
        }
        else if(document.layers)
        {
            return parseInt(window.innerWidth);          //n4
        }
        else if(document.getElementById)
        {
            return parseInt(window.innerWidth);          //n6,n7,m1,s1
        }
        return 0;
    },

    "browse_height" : function()
    {
        shared.init();
        if(window.opera)
        {
            return parseInt(window.innerHeight);          //o6,o7
        }
        else if(document.all)
        {
            if(shared._ie)
            {
                return parseInt(document.documentElement.clientHeight);
            }
            return parseInt(document.body.clientHeight);
        }
        else if(document.layers)
        {
            return parseInt(window.innerHeight);          //n4
        }
        else if(document.getElementById)
        {
            return parseInt(window.innerHeight);          //n6,n7,m1,s1
        }
        return 0;
    },

    "scroll_left" : function()
    {
        shared.init();
        if(document.all)
        {
            if(shared._ie)
            {
                return parseInt(document.documentElement.scrollLeft);
            }
            return parseInt(document.body.scrollLeft);
        }
        else if(document.layers || document.getElementById)
        {
            return parseInt(window.pageXOffset);
        }
        return 0;
    },

    "scroll_top" : function()
    {
        shared.init();
        if(document.all)
        {
            if(shared._ie)
            {
                return parseInt(document.documentElement.scrollTop);
            }
            return parseInt(document.body.scrollTop);
        }
        else if(document.layers || document.getElementById)
        {
            return parseInt(window.pageYOffset);
        }
        return 0;
    },

    "bytelen" : function(str)
    {
        count = 0;
        for(i = 0;i < str.length;i ++)
        {
            var n = escape(str.charAt(i));
            if (n.length < 4) count ++; else count += 2;
        }
        return count;
    },

    "draginit" : function(obj)
    {
        for(var i = 0;i < obj.length;i ++)
        {
            $(obj[i]).onmousedown = shared.dragstart;
            $(obj[i]).onmouseup = shared.dragend;
            $(obj[i]).style.top = '0px';
            $(obj[i]).style.left = '0px';
        }
        window.document.onmousemove = shared.dragproc;
    },

    "dragstart" : function(evt)
    {
        if(window.addEventListener)
        {
            shared._dragobj = evt.target;
        }else
        {
            shared._dragobj = event.srcElement;
        }

        shared._dragflag = true;
        shared._offsetx = shared._mousex - parseInt(shared._dragobj.style.left);
        shared._offsety = shared._mousey - parseInt(shared._dragobj.style.top);
    },

    "dragend" : function()
    {
        shared._dragflag = false;
    },

    "dragproc" : function(evt)
    {
        if(document.all)
        {
            shared._mousex = event.x;
            shared._mousey = event.y;
        }else
        {
            shared._mousex = evt.pageX;
            shared._mousey = evt.pageY;
        }

        if(!shared._dragflag) return;

        shared._dragobj.style.left = (shared._mousex - shared._offsetx) + 'px';
        shared._dragobj.style.top = (shared._mousey - shared._offsety) + 'px';

        return false;
    },

    "request" : function(url, properties)
    {
        if(!properties.callback) return null;
        shared.init();

        var httpobj = shared.httpobject();
        if(httpobj === null) return null;

//        if(shared._opera || shared._safari || shared._mozilla)
        if(shared._safari)
        {
            httpobj.onload = function()
            {
                properties.callback(httpobj);
            }
        }else
        {
            var timeout = setTimeout("shared.requesttimeout", 30000);
            httpobj.onreadystatechange = function()
            {
                if(httpobj.readyState == 4 && httpobj.responseText)
                {
                    clearTimeout(timeout);
                    properties.callback(httpobj);
                }
            }
        }

        if(!properties.async) properties.async = true;
        if(!properties.method || (properties.method).toLowerCase() !== "post") properties.method = "get";

        if(properties.method === "get" && properties.parameters)
        {
            url = url + "?" + properties.parameters;
        }

        httpobj.open((properties.method).toUpperCase(), url, properties.async);

        if(properties.method === "post" && properties.parameters)
        {
            if(!shared._opera)
            {
                httpobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            }
        }

        if(!properties.parameters) properties.parameters = null;
        httpobj.send(properties.parameters);

        return httpobj;
    },

    "requesttimeout" : function()
    {
        return {"responseText" : {"result" : false, "error" : null}};
    },

    "httpobject" : function()
    {
        if(window.ActiveXObject)
        {
            try
            {
                return new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e)
            {
                try
                {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }catch (e2)
                {
                    return null;
                }
            }
        }else if(window.XMLHttpRequest)
        {
            return new XMLHttpRequest();
        }else
        {
            return null;
        }
    },

    "getmousex":function(e)
    {
        if(window.opera)
        {
            return e.clientX;
        }else if(document.all)
        {
            return document.body.scrollLeft + event.clientX;
        }else if(document.layers || document.getElementById)
        {
            return e.pageX;
        }
    },

    "getmousey":function(e)
    {
        if(window.opera)
        {
            return e.clientY;
        }else if(document.all)
        {
            return document.body.scrollTop + event.clientY;
        }else if(document.layers || document.getElementById)
        {
            return e.pageY;
        }
    }
}
/*
function $(id)
{
    return (document.getElementById(id)) ? document.getElementById(id) : null;
}

function encodeURL(str)
{
    var character = '';
    var unicode   = '';
    var string    = '';
    var i         = 0;
    for (i = 0;i < str.length;i++)
    {
        character = str.charAt(i);
        unicode   = str.charCodeAt(i);
        if(character == ' ')
        {
            string += '+';
        }else
        {
            if(unicode == 0x2a || unicode == 0x2d || unicode == 0x2e || unicode == 0x5f || ((unicode >= 0x30) && (unicode <= 0x39)) || ((unicode >= 0x41) && (unicode <= 0x5a)) || ((unicode >= 0x61) && (unicode <= 0x7a)))
            {
                string = string + character;
            }else
            {
                if((unicode >= 0x0) && (unicode <= 0x7f))
                {
                    character   = '0' + unicode.toString(16);
                    string += '%' + character.substr(character.length - 2);
                }else if (unicode > 0x1fffff)
                {
                    string += '%' + (oxf0 + ((unicode & 0x1c0000) >> 18)).toString(16);
                    string += '%' + (0x80 + ((unicode & 0x3f000) >> 12)).toString(16);
                    string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
                    string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
                }else if (unicode > 0x7ff)
                {
                    string += '%' + (0xe0 + ((unicode & 0xf000) >> 12)).toString(16);
                    string += '%' + (0x80 + ((unicode & 0xfc0) >> 6)).toString(16);
                    string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
                }else
                {
                    string += '%' + (0xc0 + ((unicode & 0x7c0) >> 6)).toString(16);
                    string += '%' + (0x80 + (unicode & 0x3f)).toString(16);
                }
            }
        }
    }
    return string;
}
*/

