$(document).ready(function(){
//-------------------------- SCELTA MANUALE -----------------------------
if (typeof tipoPostoJSON == 'object') {
SHOW.sceltaManuale.impostaEventiMappa();
}
//-------------------------- TABELLA PREZZI BESTSEAT -----------------------------
else if ($('table#tablePrice').length>0) {
SHOW.tabellaPrezzi.impostaEventi();
SHOW.tabellaPrezzi.impostaEventiMappa ();
}
//-------------------------- SET ANAGRAFICHE -----------------------------
else {
SHOW.SetAnagrafiche.impostaEventi ();
SHOW.SetAnagrafiche.impostaDatiAnagraficheErrate ();
SHOW.SetAnagrafiche.impostaDatiRiduzioni ();
}
});
//-------------------------- MAPPA - Parametri comumi tra bestseat e scelta manuale -----------------------------
staticAreaOption = {
fillOpacity: 0.5,
mapKey: 'data-key'
};
rebindOption = {
fillOpacity: 0.5,
isSelectable: false,
highlight:false,
singleSelect: true,
mapKey: 'data-key',
showToolTip: true,
toolTipClose: ["area-mouseout"],
onMouseover: function (data) {
if ($('.mapster_tooltip').length == 0) {
$('#mappaEvento img').mapster('tooltip',this,frasi.tabellaPrezzi['noSeat']);
}
}
};
//Imposto il Namespace per SHOW
var SHOW = {};
//-------------------------- TABELLA PREZZI BESTSEAT -----------------------------
SHOW.tabellaPrezzi = {
//imposta gli eventi sulla tabella prezzi
impostaEventi: function () {
// ----------------- SENZA MAPPA -----------------------
//apro e chiudo il tipoPosto
$('#tablePrice .tipoPosto').click( function () {
//Reset
$('#tablePrice tr.settore, #tablePrice tr.sceltaposti').hide();
$('#tablePrice .arrow').removeClass('downArrow').addClass('rightArrow');
//ed ora apro
id = $(this).attr('data-id');
$('#arrow_'+id).removeClass('rightArrow').addClass('downArrow');
$('#tablePrice tr.settore[data-tipoPosto=\''+id+'\'],#tablePrice tr.sceltaposti[data-tipoPosto=\''+id+'\']').show();
});
// ----------------- MAPPA -----------------------
$('map').click(SHOW.tabellaPrezzi.controlloLogin);
// ----------------- TUTTI -----------------------
$('input[type=radio][name=sector]').change (SHOW.tabellaPrezzi.controlloLogin);
//CHECK SUBMIT
$('#tablePriceSubmit #acquistaShow').click (function (e){
sector = $('input[name=sector]:checked').val();
if (sector == undefined) {
$('#nTickets').val(0);
alert (frasi.tabellaPrezzi['zonaSel']);
e.preventDefault();
return false;
}
data = sector.split('-');
//Se esiste il campo non ho la mappa su cui scegliere ma la lista dei settori
if ($('#nTickets_'+data[0]).length > 0) {
$('#nTickets').val(0);
$('#nTickets').val($('#nTickets_'+data[0]).val());
}
if ($('#nTickets').val() == 0) {
alert (frasi.tabellaPrezzi['nTickets']);
e.preventDefault();
return false;
}
});
},
controlloLogin: function (){
if ($('#btnAccediRegistrati').length >0 ) {
alert (frasi.tabellaPrezzi['accediRegistrati']);
}
if ($('#btnCompleta').length >0) {
alert (frasi.tabellaPrezzi['completaAnagrafica']);
}
},
// ----------------- MAPPA -----------------------
impostaEventiMappa: function () {
if ($('map').length == 0) return;
//Ilumino la mappa al mouseover
staticArea = new Array(); //Per illuminare staticamente le zone selezionabili
rebindArea = new Array(); //Funzionalitą della mappa
$('tr.settore').each (function (){
// tolgo dal codice colore il #
color = $(this).attr('data-color').substr(1);
a = {key: $(this).attr('data-sector'), staticState: true, render_select:{fillColor: color}};
ra = {key: $(this).attr('data-sector'), highlight:true, isSelectable: true,
toolTip:$(this).attr('data-tooltip')};
staticArea.push(a);
rebindArea.push(ra);
});
$.extend(staticAreaOption, { areas: staticArea } );
$.extend(rebindOption, { areas: rebindArea, onClick: SHOW.tabellaPrezzi.clickMappa } );
$('#mappaEvento img').mapster(staticAreaOption)
.mapster('snapshot')
.mapster('rebind', rebindOption, true);
$('tr.settore').mouseover(function(e) {
$('#mappaEvento img').mapster('highlight', $(this).attr('data-sector'));
}).mouseout(function(e) {
$('#mappaEvento img').mapster('highlight', false);
}).click(function(e) {
$('#mappaEvento img').mapster('set', true, $(this).attr('data-sector'));
});
},
clickMappa: function (data){
$('#tablePrice tr.Prezzi, #tablePrice tr.settore').hide();
if (data.selected) {
var k = data.key.split('-');
$('h4.selectDescr').show();
$('#tableWrap').show();
$('.extMsgLocation').addClass('priceTable');
$('#tablePrice [data-id='+k[0]+']').show();
$('#tablePriceSubmit').show();
$('input[type=radio][value='+data.key+']').attr('checked','checked');
if ($(window).scrollTop() < $('#mappaEvento').offset().top)
$('html, body').animate({scrollTop: $('#mappaEvento').offset().top}, 2000);
}
else {
$('h4.selectDescr').hide();
$('#tableWrap').hide();
$('.extMsgLocation').removeClass('priceTable');
$('#tablePriceSubmit').hide();
$('input[type=radio]').attr('checked', '');
}
return true;
}
};
//-------------------------- SCELTA MANUALE -----------------------------
SHOW.sceltaManuale = {
controlloLogin: function (){
if ($('#btnAccediRegistrati').length >0 ) {
alert (frasi.tabellaPrezzi['accediRegistrati']);
}
if ($('#btnCompleta').length >0) {
alert (frasi.tabellaPrezzi['completaAnagrafica']);
}
},
// ----------------- MAPPA -----------------------
impostaEventiMappa: function () {
//Creo la mappa
if ($('#mappaEvento.mappahtml img').length == 0) return;
//Ilumino la mappa al mouseover
staticArea = new Array(); //Per illuminare staticamente le zone selezionabili
rebindArea = new Array(); //Funzionalitą della mappa
$.each(tipoPostoJSON, function (){
var tp = $(this)[0];
$.each (tp.settori, function () {
var s = $(this)[0];
if (s.posti>0) {
a = {key: tp.id+'-'+s.id, staticState: true, render_select:{fillColor: 'd6eaff'}};
ra = {key: tp.id+'-'+s.id, tp:tp.id, sector:s.id, highlight:true, isSelectable: true,
toolTip:tp.descrizione+' - '+s.id+'
DISPONIBILITA\': '+s.posti};
staticArea.push(a);
rebindArea.push(ra);
}
});
});
$.extend(staticAreaOption, { areas: staticArea } );
$.extend(rebindOption, { areas: rebindArea, onClick: SHOW.sceltaManuale.clickMappa } );
$('#mappaEvento.mappahtml img').mapster(staticAreaOption)
.mapster('snapshot')
.mapster('rebind', rebindOption, true);
//Click sul pulsante mappa principale
$('#btnMappa').click ( function () {
//Mostro la mappa generale
$('#mappaEvento.mappahtml').show();
//Nascondo la mappa dei settori
$('#mappaSettori.mappahtml').hide();
//Nascondo le istruzioni
$('.mappahtml.istruzioni').hide();
//Resetto gli stati selezionati
$('#mappaSettori.mappahtml td.stato_S').addClass('stato_L').removeClass('stato_S');
showSeatDescription();
//Nascondo i bottoni
$('.mappahtml.buttons').hide();
});
//Faccio partire la rotellina intanto che aspetto Ajax
$("#loading").bind("ajaxStart", function(){ $(this).show(); }).
bind("ajaxStop", function(){ $(this).hide(); });
//Submit del form
$('#eventPricesMaps form').submit(function (e) {
var postiSel = $('#mappaSettori.mappahtml td.stato_S');
if (postiSel.length == 0 || postiSel.length < minBuy) {
e.preventDefault();
//FIXME ENG
alert ('Selezionare almeno ' + minBuy + ((minBuy == 1)?' posto':' posti'));
return;
}
postiSel.each (function () {
//FIXME ENG
desc = tipoPostoName+ ' Fila ' + $(this).attr('data-fila') + ' Posto ' + $(this).attr('data-posto');
if ($('#mappahtml_seats').val().length == 0) {
$('#mappahtml_seats').val($(this).attr('data-idposto'));
$('#mappahtml_descs').val(desc);
$('#mappahtml_zone').val(tipoPostoCode);
$('#mappahtml_reds').val(reduction);
}
else {
$('#mappahtml_seats').val($('#mappahtml_seats').val() + ',' + $(this).attr('data-idposto'));
$('#mappahtml_descs').val($('#mappahtml_descs').val() + '||' + desc);
$('#mappahtml_zone').val( $('#mappahtml_zone').val() + ',' + tipoPostoCode);
$('#mappahtml_reds').val($('#mappahtml_reds').val() + ',' + reduction);
}
});
});
},
clickMappa: function (request){
if (request.selected) {
$.ajax({
url : "/extscript/getShowStatoPostiInPianta.php",
type : "POST",
data : { sector: request.key},
dataType : 'html',
cache : false,
success : function (data, stato) {
$('#mappaEvento.mappahtml').hide();
$('#mappaSettori.mappahtml').html(data).css('display', 'inline-block');
$('.mappahtml.istruzioni').show();
$('.mappahtml.buttons').show();
$('#mappaSettori.mappahtml td.stato_L').click (bindStatoL);
$('#mappaSettori.mappahtml td.stato_S').click (bindStatoS);
},
error : function (request, stato, errori) {
alert("E' evvenuto un errore. Il stato della chiamata: "+stato);
}
});
}
}
};
function bindStatoS () {
$(this).addClass('stato_L').removeClass('stato_S');
$('#mappaSettori.mappahtml td.stato_L').click (bindStatoL);
showSeatDescription();
}
function bindStatoL () {
if ($('.stato_S').length >= maxBuy) return;
$(this).addClass('stato_S').removeClass('stato_L');
$('#mappaSettori.mappahtml td.stato_S').click (bindStatoS);
showSeatDescription();
}
function showSeatDescription () {
var scelti = '';
$('#mappaSettori.mappahtml td.stato_S').each (function () {
scelti = scelti + '