<!--//

var shoppingBasket =
{
    updateBasket : function(rootPath, formName)
    {
        this.rootPath     = rootPath;
        this.formLocation = eval('document.' + formName);
        this.theProductID = this.formLocation.product_id.value;
        this.theQuantity  = this.formLocation.quantity.value;
        this.theColour  = this.formLocation.colour.value;
        
        if (this.theQuantity < 1 || this.theQuantity == '')
        {
            alert("Please select the quantity you would like to add to the basket.");
        }
        else
        {
            this.stringToSend = 'quantity=' + this.theQuantity + '&theColour=' + this.theColour + '&product_id=' + this.theProductID;
            sendHttpRequest.request('post', rootPath + '/updateBasket', this.stringToSend, this.updateBox);
        }
    },
    
    updateBox : function()
    {
        if (sendHttpRequest.isReadyState())
        {
            var askForConfirmation = confirm("Product has been added to your shopping basket,\nplease click 'OK' to continue to your shopping basket\n or click 'CANCEL' to continue viewing the current page");
            //var askForConfirmation = false;
            if (askForConfirmation)
            {
                self.location = '../cart';
            }
            else
            {
                if (sendHttpRequest.responseText().length > 0)
                {
                    var theText = sendHttpRequest.responseText();
                    
                    if (theText.indexOf('|') != -1 && theText.indexOf('=') != -1)
                    {
                        var theSplit = theText.split('|');
                        
                        if (theSplit.length > 0)
                        {
                            var subTotalSplit = theSplit[0].split('=');
                            var subTotal = subTotalSplit[1];
                            
                            var itemCountSplit = theSplit[1].split('=');
                            var itemCount = itemCountSplit[1];
                        }
                        
                        if (subTotal)
                        {
                            document.getElementById('theTotal').innerHTML = subTotal;
                        }
                        
                        if (itemCount > 0)
                        {
                            document.getElementById('theTotalItems').innerHTML = itemCount;
                        }
                    }
                }
            }
        }
    }
}

//-->
