/*
*
* NetGenie AJAX Cart
*
*/

function cart(div) {
	this.divname = div;
	this.div = document.getElementById(div);
}

cart.prototype.display = function() {
	this.loadXMLDoc('/_cart/basket.php?mode=xml',this.div);
}

cart.prototype.additem = function(item) {
	qb = document.getElementById('quant_'+item);
	this.loadXMLDoc('/_cart/add.php?mode=xml&pid='+item+'&quant='+qb.value,null,'this.display()');
	var pd = document.getElementById('addcart_'+item);
	pd.innerHTML = '<span style="padding: 4px; border: 1px solid #808080; background-color: #eaeaea"><b style="color: #808080">Added '+qb.value+' to cart</b></span>';
}

cart.prototype.loadXMLDoc = function (url,div,pa) {	
	var self = this;	
    if (window.XMLHttpRequest) {
        self.req = new XMLHttpRequest();
        self.req.onreadystatechange = function (){
			self.processReqChange(div,pa);
		}        
        self.req.open("GET", url, true);
        self.req.send(null);        
    } else if (window.ActiveXObject) {
        //isIE = true;
        self.req = new ActiveXObject("Microsoft.XMLHTTP");
        if (self.req) {
            self.req.onreadystatechange = function (){
				self.processReqChange(div,pa);
			}        
            self.req.open("GET", url, true);
            self.req.send();
        }
    }
}

cart.prototype.processReqChange = function (div,pa){
	if (this.req.readyState == 4) {
		if (this.req.status == 200) {
			if(div != null) {
				this.start = this.req.responseText.indexOf('<result>') + 8;
				this.stop = this.req.responseText.indexOf('</result>');
				this.response = this.req.responseText.substring(this.start,this.stop);
				div.innerHTML = this.response;
			}
			if(pa != null) {
				eval(pa);
				Effect.Highlight('ajc');
			}
		} else {
			alert("There was a problem retrieving the XML data:\n" + this.req.status);
		}
	}
}
