function cartItemXMLresponse(XMLdoc)
{
	var doc = XMLdoc;
	this.getStatus = getCartItemXMLresponseStatus;
	this.getResult = getCartItemXMLresponseResult;
	this.getErrors = getCartItemXMLresponseErrors;
	this.isSuccess = getCartItemXMLresponseStatusIsSuccess;
	this.alertErrors = getCartItemXMLresponseAlertErrors;
	this.getCartItems = getCartItemXMLreponseGetCartItems;
	this.hasCartItems = getCartItemXMLreponseHasCartItems;

	function getCartItemXMLresponseStatus()
	{
		try {
			return doc.getElementsByTagName("status")[0].firstChild.data;
		} catch (e) {
			alert("A problem has occured with this action.  Please try again.");
			return "failure";
		}
	}

	function getCartItemXMLresponseResult()
	{
		var result = doc.getElementsByTagName("result");
		if(result.length != 0)
			return result[0].firstChild.data;
		else
			return null;
	}

	function getCartItemXMLresponseErrors()
	{
		try {
			var result = doc.getElementsByTagName("error");
		} catch (e) { return null; }
		if(result.length != 0)
		{
			var errors = new Array(result.length);
			for(var i=0; i<errors.length; i++)
			{
				errors[i] = new Error(result[i]);
			}
			return errors;
		}
		else
			return null;
	}

	function getCartItemXMLresponseStatusIsSuccess()
	{
		if(getCartItemXMLresponseStatus()=="failure")
			return false;
		else
			return true;
	}

	function getCartItemXMLreponseHasCartItems()
	{
		if(getCartItemXMLreponseGetCartItems() != null)
			return true;
		else
			return false;
	}

	function getCartItemXMLreponseGetCartItems()
	{
		var result = doc.getElementsByTagName("cartItem");
		if(result.length != 0)
		{
			var cartItems = new Array(result.length);
			for(var i=0; i<cartItems.length; i++)
			{
				cartItems[i] = new CartItem(result[i]);
			}
			return cartItems;
		}
		else
			return null;
	}

	function Error(errorTag)
	{
		var tag = errorTag;
		this.getName = returnName;
		this.getDescription = returnDescription;

		function returnName()
		{
			return tag.getElementsByTagName("name")[0].firstChild.data;
		}

		function returnDescription()
		{
			return tag.getElementsByTagName("description")[0].firstChild.data;
		}
	}
	
	function CartItem(cartItemTag)
	{
		var tag = cartItemTag;
		this.getId = returnId;
		this.getFormat = returnFormat;
		this.getPrice = returnPrice;
		this.getOos = returnOos;
		this.isAvailable = returnIsAvailable;
		this.getHTML = returnHTML;
		
		var OOSsent = false;

		function returnIsAvailable()
		{
			if(returnOos()=="true")
				return false;
			else
				return true;
		}
		
		function returnHTML()
		{
			var avail = returnIsAvailable();
			var result = "";
			result += '<p class="cartinput';
			if(!avail)
				result += ' carterror cartoutofstock';
			result += '"><input class="qty';
			if(!avail)
				result += ' cartoutofstock';
			// no name here
			result += '" type="text" size="4" maxlength="4" onBlur="return addToCartCalc(event)" onKeyPress="return numbersonly(this,event)" id="' + returnId() + '_qty"';
			if(!avail)
				result += ' value="" disabled';
			else
				result += ' value="0"';
			result += ' />' + returnFormat() + ' $' + parseFloat(returnPrice()).toFixed(2);
			if(!avail)
				result += '<br>(Out of Stock)';
			result += '</p>\n';
			result += '<span id="' + returnId() + '_format" style="display: none;">' + returnFormat() + '</span>\n';
			result += '<span id="' + returnId() + '_price" style="display: none;">' + returnPrice() + '</span>\n';
			result += '<p class="carterrormsg" id="' + returnId() + '_error">';
			if(!avail)
				if(!this.OOSsent)
				{
					result += '<a href="javascript: addToCartOOSEmailPop(\'outofstockemail\', \'bottomlcenter\', \'' + returnId() + '\');">';
					result += "Email me when it's available</a>";
				}
				else
					result += '<em>In-stock Notification Requested</em>';
			result += '</p>';
			return result;
		}

		function returnId()
		{
			return tag.getElementsByTagName("id")[0].firstChild.data;
		}

		function returnFormat()
		{
			return tag.getElementsByTagName("format")[0].firstChild.data;
		}

		function returnPrice()
		{
			return tag.getElementsByTagName("price")[0].firstChild.data;
		}

		function returnOos()
		{
			return tag.getElementsByTagName("oos")[0].firstChild.data;
		}
	}

	function getCartItemXMLresponseAlertErrors()
	{
		var errors = getCartItemXMLresponseErrors();
		var msg = "";
		if(errors==null || errors.length<=0)
			return false;
		else
			msg += "Following error" + (errors.length==1?"":"s") + " occured:";
		for(var i=0; i<errors.length; i++)
		{
			msg += "\n(" + (i+1) + ") " + errors[i].getName() + ": " + errors[i].getDescription();
		}
		alert(msg);
		return true;
	}
}