function smartOrder(async) {
	var getValuesArr = new Array();
	var putValuesArr = new Array();
	this.sucess = new Boolean();  // retorna o resultado
	
	this.getValues = new function() {
		this.add = function(key) {
			getValuesArr[key] = null;
		}
		this.item = function(key) {
			return getValuesArr[key];
		}
	}
	
	this.putValues = new function() {
		this.add = function(key, value) {
			putValuesArr[key] = value;
		}
		this.item = function(key) {
			return putValuesArr[key];
		}
	}
	
	this.run = function(commit) {
		var request = new xmlhttp();
		var data = "";
		
		var store;
		var queryp = location.href.split("?")[1].split("&");
		for (el in queryp)
			if (queryp[el].split("=")[0] == "store")
				store = queryp[el].split("=")[1];
		request.open("post", root() + "/include/SmartOrder/run_pipe.asp?store=" + store, async);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Cookie", document.cookie);
		window.smartOrder.onsucess = this.onsucess;
		window.smartOrder.onfail = this.onfail;
			for (putv in putValuesArr)
				data += "putv=" + putv + "=" + putValuesArr[putv] + "&";
			data = data.substring(0, data.length - 1);
			if (getValuesArr.length != -1)  data += "&";
			for (getv in getValuesArr)
				data += "getv=" + getv + "&";
			data = data.substring(0, data.length - 1);
			if (commit)  data += "&commit=1";
		if (async)  request.onreadystatechange = request_onreadystatechange;
		request.send(data);
		if (!async) request_onreadystatechange();
				
		function request_onreadystatechange() {
			if (request.readyState == 4)
				if (request.status == 200) {
					writeData();
					_this.sucess = true;		// houve sucesso no processamento
				} else
					_this.sucess = false;	// houve um erro no processamento
		}

		function writeData() {
			_this.data = request.responseText;
			var data = request.responseText.split("\r");
			for (el in data) {
				var key = unescape(data[el].split("=")[0]);
				var value = unescape(data[el].split("=")[1]);
				getValuesArr[key] = value;
			}
		}
	}
	
	function root() {
		/* Retorna o root da pasta atual */
		var protocol = location.protocol;
		var host = location.host;
		var port = location.port;
		var shop = location.pathname.split("/")[1];  //ex.: /lojadev42t1/televendas/shipping.asp = lojadev42t1
		return protocol + "//" + host + (port.length != 0 ? ":" : "") + port + "/" + shop;
	}

	
	var _this = this;  // disponibilizar objeto pai publicamente
}


function xmlhttp() {
	if (window.opera)  // Opera retorna Microsoft Internet Explorer
		return new XMLHttpRequest();
	else if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		return new XMLHttpRequest();
}

