<!--//

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.theTypeCode  		= this.formLocation.type_code.value;
        this.theTypeName  		= this.formLocation.type_name.value;
        this.theOption1   		= this.formLocation.option1.value;
        this.theOption1_name   	= this.formLocation.option1_name.value;
        this.theOption2   		= this.formLocation.option2.value;
        this.theOption2_name   	= this.formLocation.option2_name.value;
        this.theOption3   		= this.formLocation.option3.value;
        this.theOption3_name   	= this.formLocation.option3_name.value;
        this.theOption4   		= this.formLocation.option4.value;
        this.theOption4_name   	= this.formLocation.option4_name.value;


        /*if (this.formLocation.firstColour)
        {
          this.firstColour = this.formLocation.firstColour.options[this.formLocation.firstColour.selectedIndex].value;
        }else{
          this.firstColour = 0;
        }
        if (this.formLocation.secondColour)
        {
          this.secondColour = this.formLocation.secondColour.options[this.formLocation.secondColour.selectedIndex].value;
        }else{
          this.secondColour = 0;
        }*/
        if (this.theQuantity < 1 || this.theQuantity == '')
        {
            alert("Please select the quantity you would like to add to the basket.");
        }else if (this.theTypeCode == ''){
        	alert("Please select the type you would like to add to the basket.");
    	}else if (this.theOption1 == 0){
        	alert("Please select the polycarbonate option you would like to add to the basket.");
    	}else if (this.theOption2 == 0){
        	alert("Please select the dome type option you would like to add to the basket.");
       	}else if (this.theOption3 == 0){
        	alert("Please select the ventilation option you would like to add to the basket.");
        }//else if (this.theOption4 == 0){
        //	alert("Please select the kerb option you would like to add to the basket.");
        //}
        else
        {
            this.stringToSend = 'quantity=' + this.theQuantity + '&firstColour=' + this.firstColour + '&secondColour=' + this.secondColour + '&product_id=' + this.theProductID + '&type_code=' + this.theTypeCode + '&type_name=' + this.theTypeName + '&option1=' + this.theOption1 + '&option2=' + this.theOption2 + '&option3=' + this.theOption3 + '&option4=' + this.theOption4 + '&option1_name=' + this.theOption1_name + '&option2_name=' + this.theOption2_name + '&option3_name=' + this.theOption3_name + '&option4_name=' + this.theOption4_name;
            //alert (this.stringToSend);
            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");

            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;
                        }
                    }
                }
            }
        }
    }
}

//-->
