var ajax = new sack();
var ajaxContentObj;
var valueStr;
var ajaxElemName;

function showContent() {
	var resp = ajax.response;
	ajaxContentObj.innerHTML = resp;	// ajax.response is a variable that contains the content of the external file
	//alert(resp);
	var num = resp.indexOf("ok [begin_id]");
	var num2 = resp.indexOf("[end_id]");
	if (num > -1) {
		var idn = resp.substr(num + 13, num2 - num - 13);
		//alert(idn);
		closeBox(idn);
		loadBoxDati(idn);
	}
	if (resp.indexOf("loadAjaxForm") > -1) {
		updateSpese()
	}
	if (resp.indexOf("updateSpese") > -1) {
		updateSpese()
	}
	if (resp.indexOf("updatePrezzoTotale") > -1) {
		updatePrezzoTotale()
	}
	if (resp.indexOf("dati_cliente") > -1) {
		//alert(resp);
		if (resp.indexOf("registrati") > -1) {
			window.location = "?action=ok";
		} else {
			window.location = "?action=dati_cliente";
		}
	}
	if (resp.indexOf("copia_saggio") > -1) {
		window.location = "?action=ok";
	}
	if (resp.indexOf("catalogo_gratuito") > -1) {
		var num = resp.indexOf("gratuito[");
		var num2 = resp.indexOf("]");
		var idn = resp.substr(num + 9, num2 - num - 9);
		window.location = "?action=ok&id=" + idn;
	}
	var num_e = resp.indexOf("ecard [");
	var num_e2 = resp.indexOf("]");
	if (num_e > -1) {
		var idn = resp.substr(num_e + 7, num_e2 - num_e - 7);
		//alert(idn);
		//loadBoxDati(idn);
		Lightview.show({
			href: 'ecard_preview.asp?id=' + idn
			, options: {
   			   width: 650,
			   height: 400
			}
		});
	}
	var num_g = resp.indexOf("goto [");
	var num_g2 = resp.indexOf("]");
	if (num_g > -1) {
		var idn = resp.substr(num_g + 6, num_g2 - num_g - 6);
		//alert(idn);
		window.location = idn;

	}
}

function showWaitMessage() {
	ajaxContentObj.innerHTML = '<img src="img/ajax-loader.gif" alt="" style="display: inline; margin: 10px 0; vertical-align: middle;" /> <span style="font-size: 11px;">LOADING...</span>';
	//ajaxContentObj.innerHTML = "";
}

function getAjaxFile(fileName) {
	ajax.requestFile = fileName;	// Specifying which file to get
	ajax.onCompletion = showContent;	// Specify function that will be executed after file has been found
	ajax.onLoading = showWaitMessage;	// Action when AJAX is loading the file
	ajax.runAJAX();		// Execute AJAX function	
}

function ajaxProvince(regione) {
	var provincia = document.getElementById("provincia");
	//contentObj = provincia;
	num_option = provincia.options.length;
	for (a=num_option;a>=0;a--) {
		provincia.options[a]=null;
	}
	//alert(regione);
	ajax.requestFile = "ajax/form_province.asp?regione=" + regione;	// Specifying which file to get
	ajax.onCompletion = function() {
		var provStr = ajax.response;
		//alert(provStr);
		var provArray = provStr.split("|");
		for (a=0;a<provArray.length;a++) {
			var thisProv = provArray[a];
			var thisProvArray = thisProv.split(",");
			var provValue = thisProvArray[0];
			var provName = thisProvArray[1];
			provincia.options[a]=new Option(provName, provValue, false, false);
		}
	};	// Specify function that will be executed after file has been found
	ajax.onLoading = function() {
		provincia.options[0] = new Option("Elenco province in caricamento...", "", true, false);
	};	// Action when AJAX is loading the file
	ajax.onError = function() {
		provincia.options[0] = new Option("Si è verificato un errore!", "", true, false);
	};	// Action when AJAX is loading the file
	ajax.runAJAX();		// Execute AJAX function
}