/* <![CDATA[ */
$(document).ready(function(){
	$("#form_login_submit").click(function(){login(); return false;});
	$("#form_remember_submit").click(function(){rememberpwd(); return false;});
	$("#form_registrazione").click(function(){registration(); return false;});

	/*
	Carrello
	 alt="Aggiungi al Carrello" title="Aggiungi al Carrello" 
	  alt="Ricetta Obbligatoria"
	   alt="Ricetta NON Obbligatoria"
	$("#form_registrazione").click(function(){registration(); return false;});
	*/
	
});

function cart_add(i, string) {
	$('#'+i).css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
	$.ajax({
		type: "POST",
		url: "/listini/aj/carrello.aj",
		data: "action=carrello_aggiungi&cart="+string,
		beforeSend: function(){
			$('#carrello_box').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
		},
		success: function(result){
			$('#'+i).html('<img src="tick.gif" width=10px height=10px/>').after("<a href='./carrello.php' style='font-size:10px;'>aggiunto al carrello</a>");
			//alert(result);
			$('#carrello_box').empty().html("<a href='./carrello.php'>Articolo aggiunto al carrello</a>");
			$('#carrello_box').empty().html(result);
		},
		error: function() {
			$('#carrello_box').css('display','block').empty().html('Connection Error');
			setTimeout("$('#carrello_box').css('display','none').empty();",5000);
		}
	});

return false;
}

function cart_dettagli() {
	$.ajax({
		type: "POST",
		url: "/listini/aj/carrello.aj",
		data: "action=cart_dettagli",
		beforeSend: function(){
			$('#cart_dettagli').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
		},
		success: function(result){
			$('#cart_dettagli').css('display','block').empty().html(result);
		},
		error: function() {
			$('#cart_dettagli').css('display','block').empty().html('Connection Error');
			setTimeout("$('#cart_dettagli').css('display','none').empty();",5000);
		}
	});

return false;
}

function cart_invia() {
	$.ajax({
		type: "POST",
		url: "/listini/aj/carrello.aj",
		data: "action=carrello_invia&codice_cliente="+$('#codice_cliente').val()+"&ordine_note="+$('#ordine_note').val(),
		beforeSend: function(){
			$('#carrello_inviato').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
			$('#carrello_button_send').attr('disabled','true');
		},
		success: function(result){
			$('#carrello_inviato').css('display','block').empty().html(result);
			$('#carrello_button_send').removeAttr('disabled');
		},
		error: function() {
			$('#carrello_button_send').removeAttr('disabled');
			$('#carrello_inviato').css('display','block').empty().html('Connection Error');
			setTimeout("$('#carrello_inviato').css('display','none').empty();",5000);
		}
	});

return false;
}

function cart_item(string, id) {
	$.ajax({
		type: "POST",
		url: "/listini/aj/carrello.aj",
		data: "action=carrello_articolo&cart="+string+"&q="+$('#'+id).val(),
		beforeSend: function(){
			$('#carrello_loading_totale').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
		},
		success: function(result){
			$('#carrello_box').css('display','block').empty().html(result);
		},
		error: function() {
			$('#carrello_box').css('display','block').empty().html('Connection Error');
			setTimeout("$('#carrello_box').css('display','none').empty();",5000);
		}
	});

return false;
}

function login() {
	user_id = encodeURIComponent($('#form_login_id').val());
	user_pwd = encodeURIComponent($('#form_login_pwd').val());
	var post = "user_id="+user_id+"&user_pwd="+user_pwd;

	$.ajax({
		type: "POST",
		url: "/listini/aj/login.aj",
		data: "action=login&"+post,
		beforeSend: function(){
			$('#form_login_err').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
		},
		success: function(result){
			$('#form_login_err').css('display','block').empty().html(result);
		},
		error: function() {
			$('#form_login_err').css('display','block').empty().html('Connection Error');
			setTimeout("$('#form_login_err').css('display','none').empty();",5000);
		}
	});

return false;
}

function rememberpwd() {
	email = encodeURIComponent($('#form_remember_email').val());
	$.ajax({
		type: "POST",
		url: "/listini/aj/login.aj",
		data: "action=remember&email="+email,
		beforeSend: function(){
			$('#form_remember_err').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
		},
		success: function(result){
			$('#form_remember_err').css('display','block').empty().html(result);
		},
		error: function() {
			$('#form_remember_err').css('display','block').empty().html('Connection Error');
			setTimeout("$('#form_remember_err').css('display','none').empty();",5000);
		}
	});

return false;
}

function registration() {
	nome = encodeURIComponent($('#nome').val());
	cognome = encodeURIComponent($('#cognome').val());
	email = encodeURIComponent($('#email').val());
	password = encodeURIComponent($('#password').val());
	password2 = encodeURIComponent($('#password2').val());
	attivita = encodeURIComponent($('#attivita option:selected').val());
	settore = encodeURIComponent($('#settore option:selected').val());
	iscrizione_n = encodeURIComponent($('#iscrizione_n').val());
	iscrizione_di = encodeURIComponent($('#iscrizione_di').val());
	telefono = encodeURIComponent($('#telefono').val());
	fax = encodeURIComponent($('#fax').val());
	citta = encodeURIComponent($('#citta').val());
	provincia = encodeURIComponent($('#provincia option:selected').val());
	via = encodeURIComponent($('#via').val());
	cap = encodeURIComponent($('#cap').val());
	num = encodeURIComponent($('#num').val());

	url = ''
	+'nome='+nome
	+'&cognome='+cognome
	+'&email='+email
	+'&password='+password
	+'&password2='+password2
	+'&attivita='+attivita
	+'&settore='+settore
	+'&iscrizione_n='+iscrizione_n
	+'&iscrizione_di='+iscrizione_di
	+'&telefono='+telefono
	+'&fax='+fax
	+'&citta='+citta
	+'&provincia='+provincia
	+'&via='+via
	+'&cap='+cap
	+'&num='+num;

	$.ajax({
		type: "POST",
		url: "/listini/aj/login.aj",
		data: "action=registration&"+url,
		beforeSend: function(){
			$('#form_registrazione_err').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
			$('#form_registrazione').attr('disabled','true');
		},
		success: function(result){
			$('#form_registrazione').removeAttr('disabled');
			$('#form_registrazione_err').css('display','block').empty().html(result);
		},
		error: function() {
			$('#form_registrazione').removeAttr('disabled');
			$('#form_registrazione_err').css('display','block').empty().html('Connection Error');
			setTimeout("$('#form_registrazione_err').css('display','none').empty();",5000);
		}
	});
return false;
}


function user_account_update(){
	nome = encodeURIComponent($('#nome').val());
	cognome = encodeURIComponent($('#cognome').val());
	email = encodeURIComponent($('#email').val());
	password = encodeURIComponent($('#password').val());
	attivita = encodeURIComponent($('#attivita option:selected').val());
	settore = encodeURIComponent($('#settore option:selected').val());
	iscrizione_n = encodeURIComponent($('#iscrizione_n').val());
	iscrizione_di = encodeURIComponent($('#iscrizione_di').val());
	telefono = encodeURIComponent($('#telefono').val());
	fax = encodeURIComponent($('#fax').val());
	citta = encodeURIComponent($('#citta').val());
	provincia = encodeURIComponent($('#provincia option:selected').val());
	via = encodeURIComponent($('#via').val());
	cap = encodeURIComponent($('#cap').val());
	num = encodeURIComponent($('#num').val());
	
	url = ''
	+'nome='+nome
	+'&cognome='+cognome
	+'&email='+email
	+'&password='+password
	+'&attivita='+attivita
	+'&settore='+settore
	+'&iscrizione_n='+iscrizione_n
	+'&iscrizione_di='+iscrizione_di
	+'&telefono='+telefono
	+'&fax='+fax
	+'&citta='+citta
	+'&provincia='+provincia
	+'&via='+via
	+'&cap='+cap
	+'&num='+num;

	$.ajax({
		type: "POST",
		url: "/listini/aj/login.aj",
		data: "action=account&tipo=utente&"+url,
		beforeSend: function(){
			$('#form_account_err').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
			$('#form_account').attr('disabled','true');
		},
		success: function(result){
			$('#form_account').removeAttr('disabled');
			$('#form_account_err').css('display','block').empty().html(result);
		},
		error: function() {
			$('#form_account').removeAttr('disabled');
			$('#form_account_err').css('display','block').empty().html('Connection Error');
			setTimeout("$('#form_account_err').css('display','none').empty();",5000);
		}
	});
return false;
}


function send_customer_satisfaction(){
	q_ragsoc = $('#q_ragsoc').val();
	q_indirizzo = $('#q_indirizzo').val();
	q_1 = $('input[name=q_1]:checked').val();
	q_2 = $('input[name=q_2]:checked').val();
	q_3 = $('input[name=q_3]:checked').val();
	q_4 = $('input[name=q_5]:checked').val();
	q_5 = $('input[name=q_5]:checked').val();
	q_6 = $('input[name=q_6]:checked').val();
	q_7 = $('input[name=q_7]:checked').val();
	q_8 = $('input[name=q_8]:checked').val();
	q_9 = $('input[name=q_9]:checked').val();
	q_10 = $('input[name=q_10]:checked').val();
	q_11 = $('input[name=q_11]:checked').val();
	q_12 = $('input[name=q_12]:checked').val();
	q_13 = $('input[name=q_13]:checked').val();
	q_14 = $('input[name=q_14]:checked').val();
	q_15 = $('input[name=q_15]:checked').val();
	q_16 = $('input[name=q_16]:checked').val();
	q_17 = $('input[name=q_17]:checked').val();

	url = 
	'&q_ragsoc='+q_ragsoc+
	'&q_indirizzo='+q_indirizzo+
	'&q_1='+q_1+
	'&q_2='+q_2+
	'&q_3='+q_3+
	'&q_4='+q_4+
	'&q_5='+q_5+
	'&q_6='+q_6+
	'&q_7='+q_7+
	'&q_8='+q_8+
	'&q_9='+q_9+
	'&q_10='+q_10+
	'&q_11='+q_11+
	'&q_12='+q_12+
	'&q_13='+q_13+
	'&q_14='+q_14+
	'&q_15='+q_15+
	'&q_16='+q_16+
	'&q_17='+q_17


	$.ajax({
		type: "POST",
		url: "/listini/aj/login.aj",
		data: "action=customer_satisfaction"+url,
		beforeSend: function(){
			$('#error').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
		},
		success: function(result){
			$('#error').css('display','block').empty().html(result);
		},
		error: function() {
			$('#error').css('display','block').empty().html('Connection Error');
			setTimeout("$('#error').css('display','none').empty();",5000);
		}
	});
}


function send_questionario_indicativo(){
	q_0 = $('#q_0').val();
	q_1 = $('input[name=q_1]:checked').val();
	q_2 = $('input[name=q_2]:checked').val();
	q_3 = $('input[name=q_3]:checked').val();
	q_4 = $('input[name=q_5]:checked').val();
	q_5 = $('input[name=q_5]:checked').val();
	q_6 = $('input[name=q_6]:checked').val();
	q_7 = $('input[name=q_7]:checked').val();
	q_8 = $('input[name=q_8]:checked').val();
	q_9 = $('input[name=q_9]:checked').val();
	q_10 = $('input[name=q_10]:checked').val();
	q_11 = $('input[name=q_11]:checked').val();
	q_12 = $('input[name=q_12]:checked').val();
	q_13 = $('input[name=q_13]:checked').val();
	q_14 = $('input[name=q_14]:checked').val();
	q_15 = $('input[name=q_15]:checked').val();
	q_16 = $('input[name=q_16]:checked').val();
	q_17 = $('input[name=q_17]:checked').val();
	q_18 = $('input[name=q_18]:checked').val();
	q_19 = $('input[name=q_19]:checked').val();
	q_20 = $('input[name=q_20]:checked').val();
	q_21 = $('input[name=q_21]:checked').val();
	q_22 = $('input[name=q_22]:checked').val();
	q_23 = $('#q_23').val();
	q_24 = $('#q_24').val();

	url = 
	'&q_0='+q_0+
	'&q_1='+q_1+
	'&q_2='+q_2+
	'&q_3='+q_3+
	'&q_4='+q_4+
	'&q_5='+q_5+
	'&q_6='+q_6+
	'&q_7='+q_7+
	'&q_8='+q_8+
	'&q_9='+q_9+
	'&q_10='+q_10+
	'&q_11='+q_11+
	'&q_12='+q_12+
	'&q_13='+q_13+
	'&q_14='+q_14+
	'&q_15='+q_15+
	'&q_16='+q_16+
	'&q_17='+q_17+
	'&q_18='+q_18+
	'&q_19='+q_19+
	'&q_20='+q_20+
	'&q_21='+q_21+
	'&q_22='+q_22+
	'&q_23='+q_23+
	'&q_24='+q_24;


	$.ajax({
		type: "POST",
		url: "/listini/aj/login.aj",
		data: "action=questionario"+url,
		beforeSend: function(){
			$('#error').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
		},
		success: function(result){
			$('#error').css('display','block').empty().html(result);
		},
		error: function() {
			$('#error').css('display','block').empty().html('Connection Error');
			setTimeout("$('#error').css('display','none').empty();",5000);
		}
	});
}

function send_contact(){
	nome = $('input[name=nome]').val();
	cognome = $('input[name=cognome]').val();
	email = $('input[name=email]').val();
	telefono = $('input[name=telefono]').val();
	fax = $('input[name=fax]').val();
	citta = $('input[name=citta]').val();
	provincia = $('input[name=provincia]').val();
	cap = $('input[name=cap]').val();
	via = $('input[name=via]').val();
	numero = $('input[name=numero]').val();
	commenti = $('textarea[name=commenti]').val();
	attivita = $('input[name=attivita]:selected').val();
	visita = $('input[name=visita]:selected').val();
	telefonata = $('input[name=telefonata]:selected').val();
	preventivo = $('input[name=preventivo]:selected').val();

	url = 
	'&nome='+nome+
	'&cognome='+cognome+
	'&email='+email+
	'&telefono='+telefono+
	'&fax='+fax+
	'&citta='+citta+
	'&provincia='+provincia+
	'&cap='+cap+
	'&via='+via+
	'&numero='+numero+
	'&attivita='+attivita+
	'&visita='+visita+
	'&telefonata='+telefonata+
	'&preventivo='+preventivo+
	'&commenti='+commenti;


	$.ajax({
		type: "POST",
		url: "/listini/aj/login.aj",
		data: "action=contact"+url,
		beforeSend: function(){
			$('#error').css('display','block').empty().html('<img src="/wp-content/themes/alcyon/css/img/loading.gif" />');
			$('#Submit2').attr('disabled','true');
		},
		success: function(result){
			$('#Submit2').removeAttr('disabled');
			$('#error').css('display','block').empty().html(result);
		},
		error: function() {
			$('#Submit2').removeAttr('disabled');
			$('#error').css('display','block').empty().html('Connection Error');
			setTimeout("$('#error').css('display','none').empty();",5000);
		}
	});
}

/* ]]> */