
function wizard_callback()
{
	$.ajax({
		type: "POST",
		url: path + "ajax.php",
		data: "f=get_wizard_content",
		success: function(result) {
			if(result.match(/^Error:/i)) {
				result = result.replace("Error:","");
			}
			$("a#wizard-link").hide();
			$("#wizard-content").html( result );
			window.setTimeout('get_wizard_content();', 12000);
		}
	});
}

function wizard_answer(aObj)
{
	var c = $.cookie(wcn);
	if(c == null) {
		alert("Per proseguire \xE8 necessario abilitare i cookie!");
		window.location.reload();
		return;
	}
	var radio_td = $(aObj).parent().parent().prev().children("td#wizard-content");
	var radio_length =  radio_td.find("input:radio").length;
	if(radio_length < 1) return false;
	var is_checked = 0;
	var value_checked = null;
	for(i = 0; i < radio_length; i++) {
		if(radio_td.find("input:radio")[i].checked == true) {
			value_checked = i;
			is_checked = 1;
			break;
		}
	}
	if(is_checked == 0) {
		alert("Devi seleziona una opzione!");
		return;
	}

	var radio_name = radio_td.find("input:radio")[0].name;
	var radio_value = radio_td.find("input:radio")[value_checked].value;
	$.ajax({
		type: "POST",
		url: path + "ajax.php",
		data: "f=wizard_answer&name=" + radio_name + "&value=" + radio_value,
		success: function(result) {
			if(result.match(/^Error:/i)) {
				result = result.replace("Error:","");
			}
			var step_number = parseInt(radio_name.replace("a_", ""));
			$("#wizard-content").html( result );
			wizard_register();
			init_casehistory();
			if(step_number == 5) {
				$("a#wizard-link").hide();
				if(ir == 0) {
					$("a.wiz-ch").click(
						function(e) {
							e.preventDefault();
							register( $(this).attr("rel") );
						}
					);
				}
				if(ir == 1) window.setTimeout('get_wizard_content();', 12000);
			}
		}
	});
}

function get_wizard_content()
{
	$.ajax({
		type: "POST",
		url: path + "ajax.php",
		data: "f=get_wizard_content",
		success: function(result) {
			if(result.match(/^Error:/i)) {
				result = result.replace("Error:","");
			}
			$("a#wizard-link").show();
			$("#wizard-content").html( result );
			wizard_register();
			init_casehistory();
		}
	});
}

function wizard_register()
{
	return true;
	$("a#wizard-register").click(
		function(e) {
			e.preventDefault();
			register($(this).attr("rel"));
		}
	);
}

function init_casehistory()
{
	return true;
	if(ir == 0) {
		$("a.ch").each(
			function() {
				$(this).click(
					function(e) {
						e.preventDefault();
						var href = this.href.match(/\?id=([a-z_]+)/);
						if(href) register("ch-" + href[1]);
					}
				);
			}
		);
	}
}

function init_home()
{
	get_wizard_content();
	$("a#wizard-link").click(
		function(e) {
			e.preventDefault();
			wizard_answer(this);
		}
	);
	wizard_register();
	init_casehistory();
}

$(document).ready( init_home );