if (!Object.prototype.toJSONString) {

    Array.prototype.toJSONString = function () {
        var a = [],     // The array holding the member texts.
            i,          // Loop counter.
            l = this.length,
            v;          // The value to be stringified.

        for (i = 0; i < l; i += 1) {
            v = this[i];
            switch (typeof v) {
            case 'object':

                if (v) {
                    if (typeof v.toJSONString === 'function') {
                        a.push(v.toJSONString());
                    }
                } else {
                    a.push('null');
                }
                break;

            case 'string':
            case 'number':
            case 'boolean':
                a.push(v.toJSONString());
            }
        }
        return '[' + a.join(',') + ']';
    };

    Boolean.prototype.toJSONString = function () {
        return String(this);
    };

    Date.prototype.toJSONString = function () {

        function f(n) {

            return n < 10 ? '0' + n : n;
        }

        return '"' + this.getFullYear() + '-' +
                f(this.getMonth() + 1) + '-' +
                f(this.getDate()) + 'T' +
                f(this.getHours()) + ':' +
                f(this.getMinutes()) + ':' +
                f(this.getSeconds()) + '"';
    };
    Number.prototype.toJSONString = function () {
        return isFinite(this) ? String(this) : 'null';
    };

    Object.prototype.toJSONString = function () {
        var a = [],     // The array holding the member texts.
            k,          // The current key.
            v;          // The current value.

        for (k in this) {
            if (this.hasOwnProperty(k)) {
                v = this[k];
                switch (typeof v) {
                case 'object':
                    if (v) {
                        if (typeof v.toJSONString === 'function') {
                            a.push(k.toJSONString() + ':' + v.toJSONString());
                        }
                    } else {
                        a.push(k.toJSONString() + ':null');
                    }
                    break;

                case 'string':
                case 'number':
                case 'boolean':
                    a.push(k.toJSONString() + ':' + v.toJSONString());
                }
            }
        }
        return '{' + a.join(',') + '}';
    };

    (function (s) {
        var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };
        s.parseJSON = function (filter) {
            var j;

            function walk(k, v) {
                var i;
                if (v && typeof v === 'object') {
                    for (i in v) {
                        if (v.hasOwnProperty(i)) {
                            v[i] = walk(i, v[i]);
                        }
                    }
                }
                return filter(k, v);
            }
            if (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(this.
                    replace(/\\./g, '@').
                    replace(/"[^"\\\n\r]*"/g, ''))) {
                j = eval('(' + this + ')');

                if (typeof filter === 'function') {
                    j = walk('', j);
                }
                return j;
            }
            throw new SyntaxError('parseJSON');
        };

        s.toJSONString = function () {
            if (/["\\\x00-\x1f]/.test(this)) {
                return '"' + this.replace(/([\x00-\x1f\\"])/g, function (a, b) {
                    var c = m[b];
                    if (c) {
                        return c;
                    }
                    c = b.charCodeAt();
                    return '\\u00' +
                        Math.floor(c / 16).toString(16) +
                        (c % 16).toString(16);
                }) + '"';
            }
            return '"' + this + '"';
        };
    })(String.prototype);
}


//pop_up

var _FG_tracker=null;
function up_form(formdiv_id,container_id,bg_div_id)
{
var bgdiv = document.getElementById(bg_div_id);
bgdiv.style.display="block";
var formdiv = document.getElementById(formdiv_id);
formdiv.style.display="block";
var pt = window.center({width:700,height:500});
formdiv.style.top = pt.y + "px";
formdiv.style.left = pt.x + "px";
formdiv.handlerobj = new FG_MoveablePopup(formdiv);
var containerdiv = document.getElementById(container_id);
if(containerdiv && containerdiv.SavedInnerHTML)
{
containerdiv.innerHTML = containerdiv.SavedInnerHTML;
}}
function fg_hideform(formdiv_id,bg_div_id)
{
var formdiv = document.getElementById(formdiv_id);
formdiv.style.display="none";
var bgdiv = document.getElementById(bg_div_id);
bgdiv.style.display="none";
}
function FG_MoveablePopup(div_obj)
{
var _div_obj = div_obj;
var downposX = 0;
var downposY = 0;
var dragging = false;
this.isIE    = false;
this.isNS    = false;
this.Init = function()
{
if (navigator.userAgent.indexOf("MSIE") >= 0 ||
navigator.userAgent.indexOf("Opera") >= 0) 
{
this.isIE = true;
}
else
{
this.isNS = true;
}}
_div_obj.onmousedown = function(event)
{
var x=0;
var y=0;
_this = this.handlerobj;
if (_this.isIE) 
{
x = window.event.clientX + 
document.documentElement.scrollLeft + 
document.body.scrollLeft;
y = window.event.clientY + 
document.documentElement.scrollTop + 
document.body.scrollTop;
}
else
{
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
var top = parseInt(this.style.top,  3);
var client_y = y - top;
if(!(client_y>0  && client_y<30))
{
return;
}
_this.cursorStartX = x;
_this.cursorStartY = y;
_this.divStartX   = parseInt(this.style.left, 10);
_this.divStartY   = top;
if (this.handlerobj.isIE) 
{
document.attachEvent("onmousemove", _this.onmousemove);
document.attachEvent("onmouseup",   _this.onmouseup);
window.event.cancelBubble = true;
window.event.returnValue = false;
}
else
{
document.addEventListener("mousemove", _this.onmousemove,   true);
document.addEventListener("mouseup",   _this.onmouseup, true);
event.preventDefault();
}
_FG_tracker = _this;
_this._div_obj = this;
}
this.onmousemove = function(event)
{
_this = _FG_tracker;
var x = 0;
var y = 0;
if (_this.isIE) 
{
x = window.event.clientX + document.documentElement.scrollLeft
+ document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop
+ document.body.scrollTop;
}
else
{
x = event.clientX + window.scrollX;
y = event.clientY + window.scrollY;
}
_this._div_obj.style.left = (_this.divStartX + x - _this.cursorStartX) + "px";
_this._div_obj.style.top  = (_this.divStartY   + y - _this.cursorStartY) + "px";
if (_this.isIE) 
{
window.event.cancelBubble = true;
window.event.returnValue = false;
}
else
{
event.preventDefault();
}}
this.onmouseup = function()
{
_this = _FG_tracker;
if (_this.isIE) 
{
document.detachEvent("onmousemove", _this.onmousemove);
document.detachEvent("onmouseup",   _this.onmouseup);
}
else
{
document.removeEventListener("mousemove", _this.onmousemove,   true);
document.removeEventListener("mouseup",   _this.onmouseup, true);
}
_FG_tracker = null;
}
this.Init();
}
window.size = function()
{
var w = 0;
var h = 0;
if(!window.innerWidth)
{
if(!(document.documentElement.clientWidth == 0))
{
w = document.documentElement.clientWidth;
h = document.documentElement.clientHeight;
}
else
{
w = document.body.clientWidth;
h = document.body.clientHeight;
}}
else
{
w = window.innerWidth;
h = window.innerHeight;
}
return {width:w,height:h};
}
window.center = function()
{
var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
var _x = 0;
var _y = 0;
var offsetX = 0;
var offsetY = 0;
if(!window.pageYOffset)
{
if(!(document.documentElement.scrollTop == 0))
{
offsetY = document.documentElement.scrollTop;
offsetX = document.documentElement.scrollLeft;
}
else
{
offsetY = document.body.scrollTop;
offsetX = document.body.scrollLeft;
}}
else
{
offsetX = window.pageXOffset;
offsetY = window.pageYOffset;
}
_x = ((this.size().width-hWnd.width)/2)+offsetX;
_y = ((this.size().height-hWnd.height)/2)+offsetY;
return{x:_x,y:_y};
}
