var curPanel;

//**************THIS CODE MAKES THE SCRIPTS SYNCHRONOUS TO ALLOW THE AJAX TO RUN BEFORE THE REDIRECT WHEN ADDING TO CART******//
    var __xmlHttpRequest = window.XMLHttpRequest;
    window.XMLHttpRequest = XMLHttpRequest = function() {
        var _xmlHttp = null;
        if (!__xmlHttpRequest) {
            try {
                _xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(ex) {}
        }
        else {
            _xmlHttp = new __xmlHttpRequest();
        }
        
        if (!_xmlHttp) return null;
        
        this.abort = function() {return _xmlHttp.abort();}
        this.getAllResponseHeaders = function() {return _xmlHttp.getAllResponseHeaders();}
        this.getResponseHeader = function(header) {return _xmlHttp.getResponseHeader(header);}
        this.open = function(method, url, async, user, password) {
            return _xmlHttp.open(method, url, false, user, password);
        }
        this.send = function(body) {
            _xmlHttp.send(body);
            this.readyState = _xmlHttp.readyState;
            this.responseBody = _xmlHttp.responseBody;
            this.responseStream = _xmlHttp.responseStream;
            this.responseText = _xmlHttp.responseText;
            this.responseXML = _xmlHttp.responseXML;
            this.status = _xmlHttp.status;
            this.statusText = _xmlHttp.statusText;
            this.onreadystatechange();
        }
        this.setRequestHeader = function(name, value) {return _xmlHttp.setRequestHeader(name, value);}
    }
//**********END OF SYNCHRONOUS CODE*******************//

function addToCart(prd_id){


	msg = document.getElementById("shopMessage");
	cartImg = document.getElementById("cartImg" + prd_id);

	msg.style.top = getImagePageTop(cartImg) -10 + 'px';
	msg.style.left = getImagePageLeft(cartImg)+ 'px';
	msg.style.display = "";
	
	
	//quantity = document.getElementById("cart"+prd_id).value
	formData = "procType=ADD&prd_id=" + prd_id + "&quantity=" + 1;
	getData(pageURL + "_shopping_cart.asp",updatePanel,formData,document.getElementById("shopItems"));
}
function addToCart_Category(prd_id,cat_id){


	msg = document.getElementById("shopMessage");
	cartImg = document.getElementById("cartImg" + prd_id + "_" + cat_id);

	msg.style.top = getImagePageTop(cartImg) -10 + 'px';
	msg.style.left = getImagePageLeft(cartImg)+ 'px';;
	msg.style.display = "";
	
	
	//quantity = document.getElementById("cart"+prd_id).value
	formData = "procType=ADD&prd_id=" + prd_id + "&quantity=" + 1;
	getData(pageURL + "_shopping_cart.asp",updatePanel,formData,document.getElementById("shopItems"));
}

var req;
function getData(url,processFunction,postData,cPanel) {
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		curPanel = cPanel;
		req.onreadystatechange = processFunction;
		req.open("POST", url, true);
		req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');		
		req.send(postData);
	}
}	

function updatePanel() {
    if (req.readyState == 4) {
        if (req.status == 200) {
          curPanel.innerHTML = req.responseText
        } else {
		  alert(req.responseText)
		  alert("Error Retrieving Files.");
        }
    }
}

function getImagePageLeft(img) {
  var x, obj;
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
}

function getImagePageTop(img) {
  var y, obj;
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
}

function fade(tmpText){
	tmp = document.getElementById(tmpText);
	tmp.style.opacity = tmp.style.opacity * .80;
	
	alert(tmp.style.opacity )
	if(tmp.style.opacity > .15){
		window.setTimeout('fade("shopMessage")',50);
	}

}