/////////////////////functions for basket

/////builds a communication object between page and server
function httpRequest(url) {

    var httpObj = false;

    if (typeof XMLHttpRequest != 'undefined') {

        httpObj = new XMLHttpRequest();

    } else if (window.ActiveXObject) {

        try{

            httpObj = new ActiveXObject('Msxml2.XMLHTTP');

        } catch(e) {

            try{

                httpObj = new ActiveXObject('iMicrosoft.XMLHTTP');

            } catch(e) {}

        }

    }

    if (!httpObj) return;


//////handles response from server
    httpObj.onreadystatechange = function() {

        if (httpObj.readyState == 4) { 
        
        // when request is complete
				var response = httpObj.responseText;
				
				if (response >= 0) {
				/////update basket items count
				document.getElementById('numberBasketItems').innerHTML=response;
				} else {
				/////Add item response
				alert(response);
				}
							
        }

    };

/////////sends the info to server
    httpObj.open('GET', url, true);
    httpObj.send(null);

}


//////add items to basket function - pass =  type of edit, prod code, prod id, qty, type(sub or main)

function AddToBasket (basketedit, prodcode, prodid, qty, type) {


/////get basket id
var basketid = document.getElementById('add_basket').innerHTML;	

//////build request URL
httpRequest('javascript/ajax.php?basketedit=' + basketedit + '&basketid=' + basketid + '&prodcode=' + prodcode + '&prodid=' + prodid + '&quantity=' + qty + '&prodtype=' + type + '&timestamp=' + Date() );

/////DEBUG
///location.href = 'javascript/ajax.php?basketedit=' + basketedit + '&basketid=' + basketid + '&prodcode=' + prodcode + '&prodid=' + prodid + '&quantity=' + qty + '&prodtype=' + type + '&timestamp=' + Date();
//alert ('basketedit=' + basketedit + '&basketid=' + basketid + '&prodcode=' + prodcode + '&prodid=' + prodid + '&quantity=' + qty + '&prodtype=' + type + '&timestamp=' + Date());

////update basket items count
getNumBaskItems();

}



/////get number of basket items
function getNumBaskItems() {

////get basket id
var basketid = document.getElementById('add_basket').innerHTML;
var basketedit = 'number';

/////DEBUG
////alert('javascript/ajax.php?basketedit=' + basketedit + '&basketid=' + basketid);

///perform a http request to get num items
httpRequest('javascript/ajax.php?basketedit=' + basketedit + '&basketid=' + basketid);
}


