SHOW_ADDED = 1;
Offset_X = -10;
Offset_Y = -30;
var global_qty;

function Subsys_JsHttpRequest_Js() {
    this._construct()
}(function () {
    var COUNT = 0;
    var PENDING = {};
    var CACHE = {};
    Subsys_JsHttpRequest_Js.dataReady = function (id, text, js) {
        var undef;
        var th = PENDING[id];
        delete PENDING[id];
        if (th) {
            delete th._xmlReq;
            if (th.caching) CACHE[th.hash] = [text, js];
            th._dataReady(text, js);
        } else if (typeof (th) != typeof (undef)) {
            alert("ScriptLoader: unknown pending id: " + id);
        }
    }
    Subsys_JsHttpRequest_Js.prototype = {
        onreadystatechange: null,
        readyState: 0,
        responseText: null,
        responseXML: null,
        status: 200,
        statusText: "OK",
        session_name: "osCsid",
        responseJS: null,
        caching: false,
        _span: null,
        _id: null,
        _xmlReq: null,
        _openArg: null,
        _reqHeaders: null,
        dummy: function () {},
        abort: function () {
            if (this._xmlReq) return this._xmlReq.abort();
            if (this._span) {
                this.readyState = 0;
                if (this.onreadystatechange) this.onreadystatechange();
                this._cleanupScript();
            }
        },
        open: function (method, url, asyncFlag, username, password) {
            this._openArg = {
                'method': method,
                'url': url,
                'asyncFlag': asyncFlag,
                'username': username,
                'password': password
            };
            this._id = null;
            this._xmlReq = null;
            this._reqHeaders = [];
            return true;
        },
        send: function (content) { 
            var id = (new Date().getTime()) + "" + COUNT++;
            var query = this._hash2query(content);
            var url = this._openArg.url;
            var sid = this._getSid();
            if (sid) url += (url.indexOf('?') >= 0 ? '&' : '?') + this.session_name + "=" + this.escape(sid);
            var hash = this.hash = url + '?' + query;
            if (this.caching && CACHE[hash]) {
                var c = CACHE[hash];
                this._dataReady(c[0], c[1]);
                return false;
            }
            this._xmlReq = this._obtainXmlReq(id, url);
            var hasSetHeader = this._xmlReq && (window.ActiveXObject || this._xmlReq.setRequestHeader);
            var href, body;
            if (this._xmlReq && hasSetHeader && ("" + this._openArg.method).toUpperCase() == "POST") {
                this._openArg.method = "POST";
                href = url;
                body = query;
            } else {
                this._openArg.method = "GET";
                href = url + (url.indexOf('?') >= 0 ? '&' : '?') + query;
                body = null;
            }
            href = href + (href.indexOf('?') >= 0 ? '&' : '?') + id;
            PENDING[id] = this;
            if (this._xmlReq) {
                var a = this._openArg;
                this._xmlReq.open(a.method, href + "-xml", a.asyncFlag, a.username, a.password);
                if (hasSetHeader) {
                    for (var i = 0; i < this._reqHeaders.length; i++) {
                        this._xmlReq.setRequestHeader(this._reqHeaders[i][0], this._reqHeaders[i][1]);
                    }
                    this._xmlReq.setRequestHeader('Content-Type', 'application/octet-stream');
					
                }
                return this._xmlReq.send(body);
            } else {
                this._obtainScript(id, href);
                return true;
            }
        },
        getAllResponseHeaders: function () {
            if (this._xmlReq) return this._xmlReq.getAllResponseHeaders();
            return '';
        },
        getResponseHeader: function (label) {
            if (this._xmlReq) return this._xmlReq.getResponseHeader(label);
            return '';
        },
        setRequestHeader: function (label, value) {
            this._reqHeaders[this._reqHeaders.length] = [label, value];
        },
        _construct: function () {},
        _dataReady: function (text, js) {
            with(this) {
                if (text !== null || js !== null) {
                    readyState = 4;
                    responseText = responseXML = text;
                    responseJS = js;
                } else {
                    readyState = 0;
                    responseText = responseXML = responseJS = null;
                }
                if (onreadystatechange) onreadystatechange();
                _cleanupScript();
            }
        },
        _obtainXmlReq: function (id, url) {
            if (url.match(new RegExp('^[a-z]+://', 'i'))) return null;
            var req = null;
            if (window.XMLHttpRequest) {
                try {
                    req = new XMLHttpRequest()
                } catch (e) {}
            } else if (window.ActiveXObject) {
                try {
                    req = new ActiveXObject("Microsoft.XMLHTTP")
                } catch (e) {}
                if (!req) try {
                    req = new ActiveXObject("Msxml2.XMLHTTP")
                } catch (e) {}
            }
            if (req) {
                var th = this;
                req.onreadystatechange = function () {
                    var s = req.readyState;
                    if (s == 4) {
                        req.onreadystatechange = th.dummy;
                        var responseText = req.responseText;
                        try {
                            eval(responseText);
                        } catch (e) {
                            Subsys_JsHttpRequest_Js.dataReady(id, "JavaScript code generated by backend is invalid!\n" + responseText, null);
                        }
                    } else {
                        th.readyState = s;
                        if (th.onreadystatechange) th.onreadystatechange()
                    }
                };
                this._id = id;
            }
            return req;
        },
        _obtainScript: function (id, href) {
            with(document) {
                var span = null;
                span = body.appendChild(createElement("SPAN"));
                span.style.display = 'none';
                span.innerHTML = 'Text for stupid IE.<s' + 'cript></' + 'script>';
                setTimeout(function () {
                    var s = span.getElementsByTagName("script")[0];
                    s.language = "JavaScript";
                    if (s.setAttribute) s.setAttribute('src', href);
                    else s.src = href;
                }, 10);
                this._id = id;
                this._span = span;
            }
        },
        _cleanupScript: function () {
            var span = this._span;
            if (span) {
                this._span = null;
                setTimeout(function () {
                    span.parentNode.removeChild(span);
                }, 50);
            }
            return false;
        },
        _hash2query: function (content, prefix) {
            if (prefix == null) prefix = "";
            var query = [];
            if (content instanceof Object) {
                for (var k in content) {
                    var v = content[k];
                    if (v == null || ((v.constructor || {}).prototype || {})[k]) continue;
                    var curPrefix = prefix ? prefix + '[' + this.escape(k) + ']' : this.escape(k);
                    if (v instanceof Object) query[query.length] = this._hash2query(v, curPrefix);
                    else query[query.length] = curPrefix + "=" + this.escape(v);
                }
            } else {
                query = [content];
            }
            return query.join('&');
        },
        _getSid: function () {
            var m = document.location.search.match(new RegExp('[&?]' + this.session_name + '=([^&?]*)'));
            var sid = null;
            if (m) {
                sid = m[1];
            } else {
                var m = document.cookie.match(new RegExp(s = '(;|^)\\s*' + this.session_name + '=([^;]*)'));
                if (m) sid = m[2];
            }
            return sid;
        },
        escape: function (s) {
            return escape(s).replace(new RegExp('\\+', 'g'), '%2B');
        }
    }
})();

function addHandler(object, event, handler) {
    if (typeof object.addEventListener != 'undefined') object.addEventListener(event, handler, false);
    else if (typeof object.attachEvent != 'undefined') object.attachEvent('on' + event, handler);
    else {
        var handlersProp = '_handlerStack_' + event;
        var eventProp = 'on' + event;
        if (typeof object[handlersProp] == 'undefined') {
            object[handlersProp] = [];
            if (typeof object[eventProp] != 'undefined') object[handlersProp].push(object[eventProp]);
            object[eventProp] = function (e) {
                var ret = true;
                for (var i = 0; ret != false && i < object[handlersProp].length; i++)
                ret = object[handlersProp][i](e);
                return ret;
            }
        }
        object[handlersProp].push(handler);
    }
}

function removeHandler(object, event, handler) {
    if (typeof object.removeEventListener != 'undefined') object.removeEventListener(event, handler, false);
    else if (typeof object.detachEvent != 'undefined') object.detachEvent('on' + event, handler);
    else {
        var handlersProp = '_handlerStack_' + event;
        if (typeof object[handlersProp] != 'undefined') {
            for (var i = 0; i < object[handlersProp].length; i++) {
                if (object[handlersProp][i] == handler) {
                    object[handlersProp].splice(i, 1);
                    return;
                }
            }
        }
    }
}
var x, y;
var loadingImage = new Image();
var okImage = new Image();
loadingImage.src = "images/loading.gif";
okImage.src = "images/ok.gif";
if (window.opera || window.safari || (navigator.userAgent.indexOf('MSIE') > -1)) {
    getM_x = function () {
        Xadder = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
        return event.clientX + Xadder;
    }
    getM_y = function () {
        Yadder = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
        return event.clientY + Yadder;
    }
} else {
    addHandler(document, 'mousemove', function (e) {
        x = e.pageX;
        y = e.pageY;
    });
    getM_x = function () {
        return x;
    }
    getM_y = function () {
        return y;
    }
}
/*function ShowDivInCenter(Xwidth,Yheight,divid) {
// First, determine how much the visitor has scrolled

var scrolledX, scrolledY;
if( self.pageYOffset ) {
scrolledX = self.pageXOffset;
scrolledY = self.pageYOffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
scrolledX = document.documentElement.scrollLeft;
scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
scrolledX = document.body.scrollLeft;
scrolledY = document.body.scrollTop;
}

// Next, determine the coordinates of the center of browser's window

var centerX, centerY;
if( self.innerHeight ) {
centerX = self.innerWidth;
centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
centerX = document.documentElement.clientWidth;
centerY = document.documentElement.clientHeight;
} else if( document.body ) {
centerX = document.body.clientWidth;
centerY = document.body.clientHeight;
}

// Xwidth is the width of the div, Yheight is the height of the
// div passed as arguments to the function:
var leftOffset = scrolledX + (centerX - Xwidth) / 2;
var topOffset = scrolledY + (centerY - Yheight) / 2;
// The initial width and height of the div can be set in the

// style sheet with display:none; divid is passed as an argument to // the function
var o=document.getElementbyId(divid);
var r=o.style;
r.position='absolute';
r.top = topOffset + 'px';
r.left = leftOffset + 'px';
r.display = "block";
}*/ 
function ShowDivInCenter(divWidth, divHeight, divId) { 
    try {
        var centerX, centerY;
		// First, determine how much the visitor has scrolled

		var scrolledX, scrolledY;
		if( self.pageYOffset ) {
		scrolledX = self.pageXOffset;
		scrolledY = self.pageYOffset;
		} else if( document.documentElement && document.documentElement.scrollTop ) {
		scrolledX = document.documentElement.scrollLeft;
		scrolledY = document.documentElement.scrollTop;
		} else if( document.body ) {
		scrolledX = document.body.scrollLeft;
		scrolledY = document.body.scrollTop;
		}
		
        if (self.innerHeight) {
            centerX = self.innerWidth;
            centerY = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            centerX = document.documentElement.clientWidth;
            centerY = document.documentElement.clientHeight;
        } else if (document.body) {
            centerX = document.body.clientWidth;
            centerY = document.body.clientHeight;
        }
        var offsetLeft = scrolledX + (centerX - divWidth) / 2;
        var offsetTop = scrolledY + (centerY - divHeight) / 2;
        var ojbDiv = document.getElementById(divId);
        ojbDiv.style.position = 'absolute';
        ojbDiv.style.top = offsetTop + 'px';
        ojbDiv.style.left = offsetLeft + 'px';
        ojbDiv.style.display = "block";

    } catch (e) {}
}

function createDiv2() {
	
	//alert('test');
    var rqty, sw, sh;
    var divTag = document.createElement("div");
    divTag.id = "qtybox";
    ShowDivInCenter(315, 105, 'qtybox');
     document.body.appendChild(divTag); 
   /* var divTag1=document.createElement("div");
	divTag1.id="qtybox1";
	document.body.appendChild(divTag1);
	document.getElementById('qtybox1').appendChild(divTag); */
	
}
function createDiv2_V2() {
    var rqty, sw, sh;
    var divTag = document.createElement("div");
    divTag.id = "qtybox_new";
    ShowDivInCenter(315, 105, 'qtybox_new');
     document.body.appendChild(divTag); 
   /* var divTag1=document.createElement("div");
	divTag1.id="qtybox1";
	document.body.appendChild(divTag1);
	document.getElementById('qtybox1').appendChild(divTag); */
	
}

function createDivnotify() {
    var rqty, sw, sh;
    var divTag = document.createElement("div");
    divTag.id = "notify_box";
    ShowDivInCenter(315, 105, 'notify_box');
     document.body.appendChild(divTag); 
   /* var divTag1=document.createElement("div");
	divTag1.id="qtybox1";
	document.body.appendChild(divTag1);
	document.getElementById('qtybox1').appendChild(divTag); */
	
}

function gotocheckout()
{
	window.location.href="shopping_cart.php";
}
function showOk_V2() {
    var rqty;
    var imgLoading = document.getElementById("_loading_");
    with(imgLoading) {
        style.visibility = "hidden";
        var qty123 = document.getElementById('gqty').value;
		
        var gcartqty = parseInt(document.getElementById('gcartqty').value);
        document.getElementById('fancy_overlay2').style.display = 'block';
        document.getElementById('qtybox_new').style.display = 'block';
		ShowDivInCenter(315, 105, 'qtybox_new');
        if (!IsNumeric(qty123)) rqty = 1;
        else rqty = qty123;
        var prd_q = parseInt(document.getElementById('pqty_total').value);
        var prd_avi = parseInt(document.getElementById('avi_prd').value);
        if (prd_avi == 1) {
            if (parseInt(rqty) < prd_q || (parseInt(rqty) == prd_q)) {
                if (gcartqty < prd_q || gcartqty == prd_q) {
					//alert("hello");
                    document.getElementById('qtybox_new').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/true.jpg\" /></td><td>" + rqty + " Have been added to cart successfully</td></tr><tr><td colspan=\"2\"><table border=\"0\"  width=\"100%\" cellspacing=\"2\" cellpadding=\"2\"><tr><td align=\"center\"><input type=\"button\" value=\"Go to Checkout\" style=\"width:150px;\" OnClick=\"gotocheckout()\" name=\"buttonlogin\" class=\"custom_button\"></td><td  align=\"center\"><input style=\"width:150px;\" type=\"button\" value=\"Continue Shopping\" name=\"buttonlogin\" OnClick=\"hideOk_V2()\" class=\"custom_button\"></td></tr></table><tr><td colspan=\"2\" style=\"padding-left:5px;color:#666666;font-size:13px; \"><input type=\"checkbox\" onclick=\"toggle(this,'myGroup')\" id=\"chk_show\" name=\"chk_show\" value=\"1\" >&nbsp;&nbsp;Don't show this window again</td></tr></td></tr></table>";
                } else {
                    document.getElementById('qtybox_new').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\"  /></td><td>Sorry but there are only " + prd_q + " left in stock, only " + prd_q + " has been added to your basket</td></tr><tr><td colspan=\"2\"><table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr><td  align=\"center\"><input style=\"width:150px;\" type=\"button\" OnClick=\"gotocheckout()\" value=\"Go to Checkout\" name=\"buttonlogin\" class=\"custom_button\"></td><td  align=\"center\"><input style=\"width:150px;\" type=\"button\" value=\"Continue Shopping\" OnClick=\"hideOk_V2()\" name=\"buttonlogin\" class=\"custom_button\"></td></tr></table><tr><td colspan=\"2\" style=\"padding-left:5px;color:#666666;font-size:13px;\"><input type=\"checkbox\" onclick=\"toggle(this,'myGroup')\" id=\"chk_show\" name=\"chk_show\" value=\"1\" >&nbsp;&nbsp;Don't show this window again</td></tr></td></tr></table>";
                }
            } else if (prd_q == 1) {
                document.getElementById('qtybox_new').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\"  /></td><td>Sorry but there is only 1 left in stock, only 1 has been added to your basket</td></tr><tr><td colspan=\"2\"><table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr><td  align=\"center\"><input type=\"button\" style=\"width:150px;\" value=\"Go to Checkout\" OnClick=\"gotocheckout()\" name=\"buttonlogin\" class=\"custom_button\"></td><td align=\"center\"><input  style=\"width:150px;\" type=\"button\" value=\"Continue Shopping\" name=\"buttonlogin\"  OnClick=\"hideOk_V2()\" class=\"custom_button\"></td></tr><tr><td colspan=\"2\" style=\"padding-left:5px;color:#666666;font-size:13px;\"><input type=\"checkbox\" onclick=\"toggle(this,'myGroup')\" id=\"chk_show\" name=\"chk_show\" value=\"1\" >&nbsp;&nbsp;Don't show this window again</td></tr></table></td></tr></table>";
            } else if ((parseInt(rqty) > prd_q) && prd_q != 0) {
                document.getElementById('qtybox_new').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\"  /></td><td>Sorry but there are only " + prd_q + " left in stock, only " + prd_q + " has been added to your basket</td></tr><tr><td colspan=\"2\"><table  width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr><td  align=\"center\"><input type=\"button\" style=\"width:150px;\" OnClick=\"gotocheckout()\" value=\"Go to Checkout\" name=\"buttonlogin\" class=\"custom_button\"></td><td  align=\"center\"><input type=\"button\" style=\"width:150px;\" value=\"Continue Shopping\"  OnClick=\"hideOk_V2()\" name=\"buttonlogin\" class=\"custom_button\"></td></tr><tr><td colspan=\"2\" style=\"padding-left:5px;color:#666666;font-size:13px;\"><input type=\"checkbox\" onclick=\"toggle(this,'myGroup')\" id=\"chk_show\" name=\"chk_show\" value=\"1\" >&nbsp;&nbsp;Don't show this window again</td></tr></table></td></tr></table>";
            } else if (prd_q == 0) {
                document.getElementById('qtybox_new').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\" width=\"80\" height=\"90\" /></td><td>Sorry but this item is stocked out</td></tr><tr><td colspan=\"2\"><table  width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr><td  align=\"center\"><input style=\"width:150px;\" type=\"button\"  OnClick=\"gotocheckout()\" value=\"Go to Checkout\" name=\"buttonlogin\" class=\"custom_button\"></td><td align=\"center\"><input type=\"button\" value=\"Continue Shopping\" style=\"width:150px;\" name=\"buttonlogin\"  OnClick=\"hideOk_V2()\"  class=\"custom_button\"></td></tr></table><tr><td colspan=\"2\" style=\"padding-left:5px;color:#666666;font-size:13px;\"><input type=\"checkbox\" onclick=\"toggle(this,'myGroup')\" id=\"chk_show\" name=\"chk_show\" value=\"1\" >&nbsp;&nbsp;Don't show this window again</td></tr></table>";
            }
        } else {
            document.getElementById('qtybox_new').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/true.jpg\" /></td><td>" + rqty + " Have been added to cart successfully</td></tr><tr><td colspan=\"2\"><table  width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr><td  align=\"center\"><input  OnClick=\"gotocheckout()\" style=\"width:150px;\" type=\"button\" value=\"Go to Checkout\" name=\"buttonlogin\" class=\"custom_button\"></td><td  align=\"center\"><input style=\"width:150px;\" type=\"button\" value=\"Continue Shopping\" name=\"buttonlogin\"  OnClick=\"hideOk_V2()\" class=\"custom_button\"></td></tr></table><tr><td colspan=\"2\" style=\"padding-left:5px;color:#666666;font-size:13px;\"><input type=\"checkbox\" onclick=\"toggle(this,'myGroup')\" id=\"chk_show\" name=\"chk_show\" value=\"1\" >&nbsp;&nbsp;Don't show this window again</td></td></tr></table>";
        }
    }
}
function showOk() {
    var rqty;
    var imgLoading = document.getElementById("_loading_");
    with(imgLoading) {
        style.visibility = "hidden";
        var qty123 = document.getElementById('gqty').value;
        var gcartqty = parseInt(document.getElementById('gcartqty').value);
		
        document.getElementById('fancy_overlay2').style.display = 'block';
        document.getElementById('qtybox').style.display = 'block';
		ShowDivInCenter(315, 105, 'qtybox');
		
        if (!IsNumeric(qty123)) rqty = 1;
        else rqty = qty123;
        var prd_q = parseInt(document.getElementById('pqty_total').value);
        var prd_avi = parseInt(document.getElementById('avi_prd').value);
        if (prd_avi == 1) {
            if (parseInt(rqty) < prd_q || (parseInt(rqty) == prd_q && prd_q != 1)) {
                if (gcartqty < prd_q || gcartqty == prd_q) {
                    document.getElementById('qtybox').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/true.jpg\" width=\"90\" height=\"90\" /></td><td>" + rqty + " Have been added to cart successfully</td></tr></table>";
                } else {
                    document.getElementById('qtybox').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\" width=\"90\" height=\"90\" /></td><td>Sorry but there are only " + prd_q + " left in stock, only " + prd_q + " has been added to your basket</td></tr></table>";
                }
            } else if (prd_q == 1) {
                document.getElementById('qtybox').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\" width=\"90\" height=\"90\" /></td><td>Sorry but there is only 1 left in stock, only 1 has been added to your basket</td></tr></table>";
            } else if ((parseInt(rqty) > prd_q) && prd_q != 0) {
                document.getElementById('qtybox').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\" width=\"90\" height=\"90\" /></td><td>Sorry but there are only " + prd_q + " left in stock, only " + prd_q + " has been added to your basket</td></tr></table>";
            } else if (prd_q == 0) {
                document.getElementById('qtybox').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/addtocart_caution.jpg\" width=\"90\" height=\"90\" /></td><td>Sorry but this item is stocked out</td></tr></table>";
            }
        } else {
            document.getElementById('qtybox').innerHTML = "<table border=\"0\" cellspacing=\"5\" cellpadding=\"5\"><tr><td><img src=\"images/true.jpg\" width=\"90\" height=\"90\" /></td><td>" + rqty + " Have been added to cart successfully</td></tr></table>";
        }
    }
}

function hideOk() {
    if (document.getElementById("_loading_")) document.getElementById('_loading_').style.visibility = "hidden"; /*removeHandler(document,'mousemove',hideOk);*/
    document.getElementById('fancy_overlay2').style.display = 'none';
    document.getElementById('qtybox').style.display = 'none';
	//document.getElementById('qtybox1').style.display = 'none';
}
function hideOk_V2() {
    if (document.getElementById("_loading_")) document.getElementById('_loading_').style.visibility = "hidden"; /*removeHandler(document,'mousemove',hideOk);*/
    document.getElementById('fancy_overlay2').style.display = 'none';
    document.getElementById('qtybox_new').style.display = 'none';
	//document.getElementById('qtybox1').style.display = 'none';
}

function hidenotify() {
    if (document.getElementById("_loading_")) document.getElementById('_loading_').style.visibility = "hidden"; /*removeHandler(document,'mousemove',hideOk);*/
    document.getElementById('fancy_overlay2').style.display = 'none';
    document.getElementById('notify_box').style.display = 'none';
	//document.getElementById('qtybox1').style.display = 'none';
}

function docWH() {
		var b = document.body,
			e = document.documentElement,
			w = 0,
			h = 0;
		if (e) {
			w = Math.max(w, e.scrollWidth, e.offsetWidth);
			h = Math.max(h, e.scrollHeight, e.offsetHeight);
		}
		if (b) {
			w = Math.max(w, b.scrollWidth, b.offsetWidth);
			h = Math.max(h, b.scrollHeight, b.offsetHeight);
			if (window.innerWidth) {
				w = Math.max(w, window.innerWidth);
				h = Math.max(h, window.innerHeight);
			}
		}
		return [w, h];
	}
function createDiv() {
    var body = document.body,
        html = document.documentElement;
    var divTag = document.createElement("div");
    divTag.id = "fancy_overlay2";
    divTag.setAttribute("align", "center");
    divTag.style.opacity = "0.3";
    divTag.style.display = "block";
   // divTag.style.height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
    divTag.style.height =docWH()[1] + "px";
	divTag.style.width =docWH()[0] + "px";
//    alert(divTag.style.height);
    document.body.appendChild(divTag);
}

function showLoading() {
    var imgLoading = document.getElementById("_loading_");
    if (!imgLoading) {
        imgLoading = document.createElement("img");
        with(imgLoading) {
            id = "_loading_";
            style.position = "fixed";
            style.visibility = "hidden";
        }
        createDiv();
		createDivnotify();
		var popup_v=document.getElementById('addtocart_popup').value;
		if(popup_v=='2')   createDiv2_V2();
		else(popup_v=='1')
		 createDiv2();
        document.body.appendChild(imgLoading);
    }
    with(imgLoading) {
        src = loadingImage.src;
        ShowDivInCenter(16, 22, '_loading_');
    }
}

function hideLoading() {
    if (document.getElementById("_loading_")) document.getElementById("_loading_").style.visibility = "hidden";
}

function doBuyNowGet(link) {
    showLoading();
    if (!document.getElementById("gqty")) {
        var inputtag = document.createElement("input");
        inputtag.type = "hidden";
        inputtag.id = "gqty";
        inputtag.value = 1;
        document.body.appendChild(inputtag);
    } else {
        document.getElementById('gqty').value = 1;
    }
    var arr_url = link.split("&");
    var avi = 0;
    var pqty_total = 0;
    for (i = 0; i < arr_url.length; i++) {
        if (arr_url[i].substring(0, 4) == "avi=") {
            avi = arr_url[i].substring(4, arr_url[i].length);
        }
        if (arr_url[i].substring(0, 11) == "pqty_total=") {
            pqty_total = arr_url[i].substring(11, arr_url[i].length);
        }
    }
    makehidden_ele(pqty_total, "pqty_total");
    makehidden_ele(avi, "avi_prd");
    var reqAddCart = new Subsys_JsHttpRequest_Js();
    reqAddCart.onreadystatechange = function () {
        if (reqAddCart.readyState == 4) {
            if (reqAddCart.responseJS) {
                document.location.href = reqAddCart.responseJS.ajax_redirect;
                return;
            } else {
                document.getElementById('divShoppingCard').innerHTML = '<table border="0" width="100%" cellspacing="0" cellpadding="2">' + (reqAddCart.responseText || '') + '</table>';
                hideLoading();
                if (SHOW_ADDED) {
					var popup_v=document.getElementById('addtocart_popup').value;
	             	if(popup_v=='2') 
					{
						 showOk_V2();
						// timerID = setTimeout("hideOk_V2()", 1000);
					}
					else
					{
                    showOk(); 
					}
                }
            }
        }
    }
    reqAddCart.caching = false;
    reqAddCart.open('GET', link, true);
    reqAddCart.send(null);
}

function IsNumeric(strString) {
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;
    if (strString.length == 0) return false;
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function makehidden_ele(val, name) {
    if (!document.getElementById(name)) {
        var inputtag = document.createElement("input");
        inputtag.type = "hidden";
        inputtag.id = name;
        inputtag.value = val;
        document.body.appendChild(inputtag);
    } else {
        document.getElementById(name).value = val;
    }
}

function doAddProduct(form) {
	
    showLoading();
    var act = "add_product";
    if (!document.getElementById("gqty")) {
        var inputtag = document.createElement("input");
        inputtag.type = "hidden";
        inputtag.id = "gqty";
        inputtag.value = form.quantity.value;
        document.body.appendChild(inputtag);
    } else {
        document.getElementById('gqty').value = form.quantity.value;
    }
    makehidden_ele(form.prdqty.value, "pqty_total");
    makehidden_ele(form.avi.value, "avi_prd");
    makehidden_ele(form.cartqty.value, "gcartqty");
    var senddata121;
    var product_qty = parseInt(form.prdqty.value);
    var cart_prd_qty = parseInt(form.cartqty.value);
    var req_prd_qty = parseInt(form.quantity.value);
    if (!IsNumeric(req_prd_qty) || isNaN(req_prd_qty)) req_prd_qty = 1;
    if (form.avi.value == '1') {
        cart_prd_qty = cart_prd_qty + req_prd_qty;
        makehidden_ele(cart_prd_qty, "gcartqty");
        if (cart_prd_qty > product_qty) {
            if (parseInt(form.cartqty.value) < parseInt(form.prdqty.value)) {
                var remain_qty = parseInt(form.prdqty.value) - parseInt(form.cartqty.value);
                senddata121 = remain_qty;
                form.cartqty.value = parseInt(form.cartqty.value) + parseInt(senddata121);
            } else {
                act = "";
            }
        } else if (cart_prd_qty < product_qty || cart_prd_qty == product_qty) {
            senddata121 = req_prd_qty;
            form.cartqty.value = parseInt(form.cartqty.value) + parseInt(senddata121);
        }
    }
    var reqAddCart = new Subsys_JsHttpRequest_Js();
    reqAddCart.onreadystatechange = function () {  
        if (reqAddCart.readyState == 4) {
            if (reqAddCart.responseJS) {
                document.location.href = reqAddCart.responseJS.ajax_redirect;
                return;
            } else {
                document.getElementById('divShoppingCard').innerHTML = '<table width="100%">' + (reqAddCart.responseText || '') + '</table>';
				
			//vikas
			 var cookieName ='addtocart_popup';	
				var i,x,y,ARRcookies=document.cookie.split(";");
				//alert('vikas');
				for (i=0;i<ARRcookies.length;i++)
				  {
					  
				  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
				  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
				  x=x.replace(/^\s+|\s+$/g,"");
				 // alert(x);
				  if (x==cookieName)
					{
						 
						//alert(x);
						
						var cookieName1 = x;
					//return unescape(y);
					}
				  }
				  
			//vikas	
			
                if (SHOW_ADDED)
				 {
					  var popup_v= document.getElementById('addtocart_popup').value;
					if(cookieName1 =='addtocart_popup')
					{
                    var popup_v='1';
					//alert(popup_v);
					}
					else {
						 var popup_v= document.getElementById('addtocart_popup').value;
						 //alert(popup_v);
					}
					//alert(cookieName1);
				/*if(cookieName1 =='addtocart_popup')
				{ 
				 popup_v ='1';
				  popup_v1 ='popup_v';
				 alert(popup_v);
				
				alert(popup_v);*/
	             if(popup_v=='2') 
					{
						
						 showOk_V2();
						// alert('test');
						 	
					
						 //timerID = setTimeout("hideOk_V2()", 1000);
					}
					else
					{
					showOk();
                   /* timerID = setTimeout("hideOk()", 1000); */timerID=setTimeout("addHandler(document, \'mousemove\', hideOk)",500);
					
					}
				}
				
					/*else
					{
					/*alert(cookieName1);
                    showOk();*/
                  /*  timerID = setTimeout("hideOk()", 1000); timerID=setTimeout("addHandler(document, \'mousemove\', hideOk)",500);
					}*/
                
            }
        }
    }
    var senddata = new Object();
    var fe = form.elements;
    for (var i = 0; i < fe.length; i++) {
        if (fe[i].type == "radio" || fe[i].type == "checkbox") {
            if (fe[i].checked) senddata[fe[i].name] = fe[i].value;
        } else {
            if (fe[i].name == "quantity" && !IsNumeric(fe[i].value)) fe[i].value = 1;
            senddata[fe[i].name] = fe[i].value;
        }
    }
    if (form.avi.value == '1') {
        senddata.quantity = senddata121;
    }
    var url = 'ajax_shopping_cart.php?' + (senddata.products_id ? 'products_id=' + senddata.products_id + '&quantity=' + senddata.quantity + '&' : "") + 'action=' + act;
    reqAddCart.caching = false;
    reqAddCart.open(form.method, url, true);
    reqAddCart.send(senddata);
    return false;
}


function stock_alert(p_model,c_code,email)
{
	showLoading();
	shownotify(p_model,c_code,email);
	
	
	
  // timerID = setTimeout("hideOk()", 1000);
}



function shownotify(p_model,c_code,email) {
	//alert("hi"); for ajax pop up for notify 
   
    var imgLoading = document.getElementById("_loading_");
    with(imgLoading) {
        style.visibility = "hidden";
      
        document.getElementById('fancy_overlay2').style.display = 'block';
        document.getElementById('notify_box').style.display = 'block';
		ShowDivInCenter(315, 105, 'notify_box');
       
	   if(email =='')
	   { email1 ="Enter the email adress"}
	   else{email1=email}
       
                    document.getElementById('notify_box').innerHTML = "<table border=\"0\" cellspacing=\"10\" cellpadding=\"5\"><tr><td colspan=\"2\"> Enter your email address below and we will let you know when this item is coming into stock</td></tr><tr><td colspan=\"2\"><input type=\"text\" name=\"notify_email\" id=\"notify_email\" style=\"width:100%; color:grey;\" onfocus=\"blackemail(this)\"  onblur=\"greyemail(this)\" value='"+email1+ "' /></td></tr><tr><td><input style=\"width:65px;\" type=\"button\" value=\"close\" name=\"close\" OnClick=\"hidenotify();\" class=\"custom_button\"></td><td  align=\"right\"><input style=\"width:150px;\" type=\"button\" value=\"Notify Me\" name=\"notify\" id=\"notify\" OnClick=\"notifycust('"+ p_model +"','"+ c_code +"');\" class=\"custom_button\" ></td></tr></table>";
                
    }
}

		 
function blackemail(obj)
{
  obj.style.color="black";
   obj.value=""; 
}
function greyemail(obj)
{
  
  var str= obj.value;
  
  if(obj.name=="notify_email" &&  str.length==0 )  
  {
	  
	obj.style.color="grey";
	obj.value="enter email address....."; 
  }
 
}

function notifycust(p_model,c_code)		 
{		 

var email=  document.getElementById('notify_email').value;

if(email.length!=0 && email!="enter email address.....")
{
	

	var chk_email =  /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
	if(!chk_email.test(email)){
		alert("Invalid Email address");
		return false;
	}
	else
	{	

		document.getElementById('notify').className="";

	document.getElementById('notify').disabled="disabled";
	

	
	var reqAddCart = new Subsys_JsHttpRequest_Js();
    reqAddCart.onreadystatechange = function () {  
        if (reqAddCart.readyState == 4) {
			
            if (reqAddCart.responseJS)
			 {
				
				
				document.location.href = reqAddCart.responseJS.ajax_redirect;
                
				return;
            } else {
				//alert(reqAddCart.responseText);
				hidenotify();
                
            }
        }
    }
	
	
	
    var senddata = new Object();
   
    var url = 'ajax_notify_cust.php?email='+ email +'&model='+p_model+'&code='+c_code;
    reqAddCart.caching = false;
    reqAddCart.open("GET", url, true);
    reqAddCart.send(senddata);
    return false;
	}
}
else
{
	alert("please enter email address");
}
}

/*function toggle(chkbox) { 
    var visSetting = (chkbox.checked) ? "visible" : "hidden"; 
	var c_value =document.getElementById('chk_show').value;
	//var c_name =addtocart_popup;
	//alert(c_value);
	var cookieName ='addtocart_popup';
	alert(cookieName);

 document.cookie = cookieName+"="+escape(c_value);
	



}*/
function toggle(chkbox)
{ 
    var visSetting = (chkbox.checked) ? "visible" : "hidden"; 
	var c_value =document.getElementById('chk_show').value;
	var c_name ='addtocart_popup';
	//alert(c_value);
	var cookieName ='addtocart_popup';
	var exdays =1;
	
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value1=escape(c_value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
 document.cookie = cookieName+"="+escape(c_value1);
		
		
	


}
