
var Cart = {

	/*	f4 AJAX Shopping Cart module
		Martin Latter (copysense.co.uk)
		for flowers4 Nov 2010 */

	debug: false,
	sFilePath: "includes/",
	sProcessorFile: "cartajax.php",
	sReturnDiv: "testimonials",

	/*************************/

	product: function(sPCode, iPIndex, sPrice, sProductText) {

		var sFileName = Cart.sFilePath + Cart.sProcessorFile;
		var sUrl = "";

		if (sPCode !== "" && typeof iPIndex === "undefined") {
			sUrl = sFileName + "?delete=" + sPCode;
		}
		else {
			sUrl = sFileName + "?code=" + sPCode + "&pindex=" + iPIndex + "&selprice=" + sPrice + "&ptxt=" + sProductText;
		}

		sUrl = encodeURI(sUrl);

		/*************************************************************************/

		var oXmlHttp = createXHR();
		oXmlHttp.open("GET", sUrl, true);
		oXmlHttp.onreadystatechange = function() {

			if (oXmlHttp.readyState === 4 || oXmlHttp.readyState === "complete") {
				if (oXmlHttp.status === 200 || oXmlHttp.status === 304) {

					var sResponse = oXmlHttp.responseText;
					document.getElementById(Cart.sReturnDiv).innerHTML = sResponse;
				}
				else {
					if (Cart.debug) {
						alert("An error occurred: " + oXmlHttp.statusText);
					}
				}
			}
		};

		oXmlHttp.send(null);

		/*************************************************************************/
		function createXHR() {
			/* inner method to create cross browser AJAX object  - amalgamation of techniques: Wrox and O'Reilly
				tested in IE6 (6.0.2900.2180), IE7, IE8, Safari (Mac), Opera 9-10, Firefox Mac/Win */
			if (typeof XMLHttpRequest !== "undefined") {
				return new XMLHttpRequest();
			}
			else if (window.ActiveXObject) {
				try {
					var oXMLHttp = new ActiveXObject("MSXML2.XMLHttp"); // IE5 is Microsoft.XMLHTTP
						// O'Reilly: specific version of MSXML not necessary, saves Wrox IE6 trouble
					return oXMLHttp;
				}
				catch (xhrError) {
					alert("AJAX functionality is not supported (or trusted ActiveX has been disabled) in this version of Internet Explorer.");
				}
			}
		}
		/*************************************************************************/
	}
};


window.onunload = function() {

	Cart = null;
};


