function showSendForm(id,indirizzo) {
	new Ajax.Updater(id,'spedizioneForm.php?mustind='+indirizzo);
	$('sbmtTick').disabled = '';
}


function addTicket(isShow) {

	var nome, cognome, email, mustind , indirizzo, comune,cap, provincia, note;
	nome = $('nome').value;
	cognome = $('cognome').value;
	email = $('email').value;
	mustind = $('mustind').value;
	if(mustind == 1) {
		indirizzo = $('indirizzo').value;
		comune = $('comune').value;
		cap = $('cap').value;
		provincia = $('provincia').value;
	}

	if (nome.length < 2) {
		alert('Il nome deve avere almeno 2 caratteri');
		$('nome').focus();
		return false;
	}
	if (cognome.length < 1) {
		alert('Il cognome deve avere almeno 2 caratteri');
		$('cognome').focus();
		return false;
	}
	if (email.length < 1) {
		alert('L\'indirizzo e-mail deve avere almeno 8 caratteri');
		$('email').focus();
		return false;
	}
	var mailok=checkEmail(email);
	if(!mailok) {
		$('email').focus();
		return false;
	}
	if (mustind == 1) {
		if (indirizzo.length < 5) {
			alert('L\'indirizzo e\' troppo corto.');
			$('indirizzo').focus();
			return false;
		}
		if (comune.length < 2) {
			alert('Il comune e\' troppo corto.');
			$('comune').focus();
			return false;
		}
		if (cap.length != 5) {
			alert('Il cap deve essere lungo esattamente 5 caratteri.');
			$('cap').focus();
			return false;
		}
		if (provincia.length != 2) {
			alert('Devi selezionare la provincia');
			return false;
		}
	}

	var upage='';
	if(isShow)
		upage='carrello.add.show.php';
	else
		upage='carrello.add.nonshow.php';
	new Ajax.Request (upage , {
		  method: 'post',
		  parameters: $('acq').serialize(),
		  onSuccess: function(transport) {
		  	var json = transport.responseText.evalJSON();
		        if(json.executeError) {
	                	alert(json.executeError);
	                	return false;
	          	} else {
	          		if (json.status == 'ok') {
	          			alert(json.message);
					window.location.href='carrelloAdded.php';
//	          			Dialog.okCallback();
	          		} else {
	          			alert('Si \u00E8 verificato un errore:\n' + json.message);
	          		}
          		}
      	  	}
	});
}

function checkEmail(value) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
		return (true)
	}
	alert("L'indirizzo email inserito non è valido. Ricontrolla!");
	return (false)
}


function addProduct(isShow,fid,numMaxBiglietti) {
	var maxBiglietti = 0;
	var maxTipo;
	var theForm;
	if (Prototype.Browser.IE) {
		theForm=document.forms['eventrepl'+fid];
		maxBiglietti = theForm.elements['maxBiglietti'].value;
		maxTipo      = theForm.elements['maxTipo'].value;
	} else {
       		theForm=$('eventrepl'+fid);
	        maxBiglietti = theForm['maxBiglietti'].getValue();
	        maxTipo = theForm['maxTipo'].getValue();
	}
	        if (maxBiglietti == '')
	                maxBiglietti = numMaxBiglietti;
	        if (maxBiglietti>0) {
	                var i_maxTipo = Number(maxTipo);
	                var totalePosti=0;
	                for (var x=0;x<i_maxTipo;x++) {
	                        var currPosti;
				if (Prototype.Browser.IE)
					currPosti=theForm.elements['numposti'+x].value;
				else
					currPosti=theForm['numposti'+x].getValue();
	                        totalePosti=Number(totalePosti)+Number(currPosti);
	                }
	                if (totalePosti>maxBiglietti) {
	                        alert('ATTENZIONE! Per questo evento non \u00E8 possibile acquistare pi\u00F9 di ' + maxBiglietti +     ' biglietti');
	                        return false;
	                }
	                if (totalePosti == 0) {
	                        alert('ATTENZIONE! Selezionare almeno un biglietto');
	                        return false;
	                }

	        }
	
        var u;
	if(isShow)
		u='acquistaOut.php';
	else
		u='acquistaOutNS.php';
        Dialog.info({
                        url: u,
                        options: {
                                method: 'post',
                                parameters: $('eventrepl'+fid).serialize()
                        }
                },
                {
                        className: "alphacube",
                        width: 600,
                        height: 600,
                        closable: true,
                        title: "Acquisto Biglietti",
                        showEffect:Effect.Appear,
                        zIndex: 110
                }
        );
        return false;
}

function callSetefi() {
        var u='setefiForm.php';
        Dialog.info({
                        url: u,
                        options: {
                                method: 'post'
                        }
                }, {
                        className: "alphacube",
                        width: 600,
                        height: 600,
                        closable: true,
                        title: "Pagamento Acquisti",
                        showEffect:Effect.Appear,
                        zIndex: 110
                }
        );
        return false;

}
