if (!Object.prototype.toJSONString) {

    Array.prototype.toJSONString = function () {
        var a = [],    
            i,        
            l = this.length,
            v;        
        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 = [],    
            k,         
            v;    
        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};
}



function removeselectoption(item_id,item_code)
{
	var prod_id_code='';
	var selobj=document.getElementById("mySelect");
	var len=selobj.length;
	var temp = new Array();
	for(var i=0;i<len;i++)
	{
		prod_id_code = selobj.options[i].value;
		if(prod_id_code!='')
		{
			temp = prod_id_code.split('?');
			if(temp[0]=='')
			{
				if(temp[1] == item_id || temp[1] == item_code)
				{
					selobj.remove(i);
					break;	
				}
			}
			else if(temp[0]!='')
			{
				if(temp[0]==item_id)
				{
					selobj.remove(i);
					break;
				}
			}
		}
	}
	return true;
}
function addoption(i)
{
        var item_id = '';
	var item_code = '';
	var item_name = '';
	if((cookie = getCartCookie("CART_SESSION")) > "")
    	{
		var myCart = eval("(" + cookie + ")");
		var p = myCart[0];	
		if(p[i].item_code == "")
		{
			item_id=p[i].item_id;
		}
		else
		{
			item_code=p[i].item_code;
		}
		item_name=unescape(p[i].item_name);
	}
	var selobj=document.getElementById("mySelect");
	var option=document.createElement("option");
	option.text=item_name;
	option.value=item_id+'?'+item_code+'?'+item_name;
	try
	{
		// for IE earlier than version 8
		selobj.add(option,selobj.options[null]);
	}
	catch (e)
	{
		selobj.add(option,null);
	}
	return true;
}

function AddItem(selectObj)
{
	var temp = new Array();
	var prod_id_code = selectObj.options[selectObj.selectedIndex].value;
	if(prod_id_code!='')
	{
		temp = prod_id_code.split('?');
		add(temp[0],temp[1],temp[2],'window.location.href');
		selectObj.remove(selectObj.selectedIndex);
	}
	return true;
}

function selectoptionlength()
{
	var len=document.getElementById("mySelect").length;
	if(len==1)
	{
		document.getElementById("containerselect").className="off";
	}
	else
	{
		document.getElementById("containerselect").className="on";
	}
	return true;
}

