$(window).load(function(){
	
	elms = $('.record');
	for (i=0;i<elms.length;i++){
		t = $(elms[i]).height();
		$(elms[i]).find('div.record_left').css('height',t-12);
		$(elms[i]).find('div.record_inner').css('height',t-28);
		$(elms[i]).find('div.record_right').css('height',t/2);
		$(elms[i]).find('div.record_right').css('padding-top',t/2-20);
	}
	
	h = $('.orange_box').height();
	$('.grey_box').css('height',h+28);
	
	$('.hint').bind("focus", function(e) {
      if(this.value==this.title){this.value='';}
    });
  
    $('.hint').bind("blur", function(e) {
      if(this.value==''){this.value=this.title;}
    });
	
	$('.combo').combobox(
	{
		comboboxContainerClass: "comboboxContainer",
		comboboxValueContainerClass: "comboboxValueContainer",
		comboboxValueContentClass: "comboboxValueContent",
		comboboxDropDownClass: "comboboxDropDownContainer",
		comboboxDropDownButtonClass: "comboboxDropDownButton",
		comboboxDropDownItemClass: "comboboxItem",
		comboboxDropDownItemHoverClass: "comboboxItemHover",
		animationType: "fade",
		width: "440px"
	});

});




function votaStelle(v, filmid) {
    for (k = 1; k <= v; k++) {
        prendiElementoDaId("star" + k).src = '/images/stellina.on.png';
    }
    c = eseguiInRemoto('/votaACT.php?m=' + filmid + '&v=' + v + '&nocache=' + new Date().getTime());
    if (c == '0') {
        Sexy.error('<p>Problemi durante il salvataggio del voto; riprovare pił tardi</p>');
    }
    if (c == '-1') {
        Sexy.error('<p>Servizio dedicato agli utenti registrati</p>');
    }

    if (c == '1') {
        Sexy.error('<p>Voto registrato con successo</p>');
    }    
}


function offStelle() {
    for (k = 1; k <= 5; k++) {
        var f = prendiElementoDaId("star" + k).src;
        if (f.indexOf('/images/stellina.on.png') == -1) {
            prendiElementoDaId("star" + k).src = '/images/stellina.off.png';
        }
    }
}
function onStelle(v) {
    for (k = 1; k <= v; k++) {
        var f = prendiElementoDaId("star" + k).src;
        if (f.indexOf('/images/stellina.on.png') == -1) {
            prendiElementoDaId("star" + k).src = '/images/stellina.rollon.png';
        }
    }
    switch(v) {
        case 1:
            document.getElementById('descVoto').innerHTML = 'Orrendo!';
            break;
        case 2:
            document.getElementById('descVoto').innerHTML = 'Non molto bello';
            break;
        case 3:
            document.getElementById('descVoto').innerHTML = 'Decente...';
            break;
        case 4:
            document.getElementById('descVoto').innerHTML = 'Carino...';
            break;
        case 5:
            document.getElementById('descVoto').innerHTML = 'Bellissimo, entusiasmante!';
            break;
    }
}


function salvaDEM(q) {
    if (q > 1)
        q = 0;
    var alertSTD = "<h1>Newsletter</h1><em>Cinema Teatro San Giovanni Bosco</em><br/><p>";
    var MailMissed = new Array("E-Mail missed", "E-Mail mancante", "E-Mail missed");
    var MailInvalid = new Array("Invalid E-Mail", "E-Mail non valida", "Invalid E-Mail");
    //var Privacy = new Array("Privacy not accepted", "Privacy non accettata!", "Privacy not accepted");
    var StoringKO = new Array("Service unavailable; please retry later", "Registrazione non terminata a causa di errori;<br />riprovare in seguito", "Service unavailable; please retry later");
    var StoringOK = new Array("Thank you!<br>Your E-Mail was successfully recorded", "Grazie!<br>Registrazione terminata con successo!", "Thank you!<br>Your E-Mail was successfully recorded");
    var StoringYET = new Array("E-mail is already existing!", "E-Mail gi&agrave; registrata!", "E-mail is already existing!");

    if (document.frmNewsletter.email.value == '') {
        Sexy.error(alertSTD + MailMissed[q] + '</p>');
        return false;
    }
    if (document.frmNewsletter.email.value.indexOf('@') == -1) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }
    if (document.frmNewsletter.email.value.indexOf('.') == -1) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }
    if (document.frmNewsletter.email.value.indexOf(',') >= 0) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }


    /*
    if (!document.frmNewsletter.privacy.checked) {
        Sexy.error(alertSTD + Privacy[q] + '</p>');
        return;
    }
    */

    strP = "email=" + document.frmNewsletter.email.value;
    s = fmk$PostCall('/EXECnewsletter', strP, true, 'catalogoDati');
    
    switch (s) {
        case '-1':
            Sexy.error(alertSTD + StoringKO[q] + '</p>');
            break;
        case '0':
            Sexy.error(alertSTD + StoringYET[q] + '</p>');
            break;
        case '1':
            Sexy.info(alertSTD + StoringOK[q] + '</p>');
            document.frmNewsletter.email.value = '';
            //document.frmNewsletter.privacy.checked = false;
            break;
        default:
            Sexy.error(alertSTD + StoringKO[q] + '</p>');
            break;
    }
    return false;
}


function salvaPROPOSTA(q) {
    if (q > 1)
        q = 0;
    var alertSTD = "<h1>Proponi uno spettacolo</h1><em>Cinema Teatro San Giovanni Bosco</em><br/><p>";
    var MailMissed = new Array("E-Mail missed", "E-Mail mancante", "E-Mail missed");
    var MailInvalid = new Array("Invalid E-Mail", "E-Mail non valida", "Invalid E-Mail");
    var StoringKO = new Array("Service unavailable; please retry later", "Registrazione non terminata a causa di errori;<br />riprovare in seguito", "Service unavailable; please retry later");
    var StoringOK = new Array("Thank you!<br>Your E-Mail was successfully recorded", "Grazie!<br>Registrazione terminata con successo!", "Thank you!<br>Your E-Mail was successfully recorded");
    var StoringYET = new Array("E-mail is already existing!", "E-Mail gi&agrave; registrata!", "E-mail is already existing!");

    if (document.frmProposta.email.value == '') {
        Sexy.error(alertSTD + MailMissed[q] + '</p>');
        return false;
    }
    if (document.frmProposta.email.value.indexOf('@') == -1) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }
    if (document.frmProposta.email.value.indexOf('.') == -1) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }
    if (document.frmProposta.email.value.indexOf(',') >= 0) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }

}



function richiediNoleggio(q)
{

    if (q > 1)
        q = 0;
    var alertSTD = "<h1>Richiesta di Noleggio</h1><em>Cinema Teatro San Giovanni Bosco</em><br/><p>";
    var MailMissed = new Array("E-Mail missed", "E-Mail mancante", "E-Mail missed");
    var MailInvalid = new Array("Invalid E-Mail", "E-Mail non valida", "Invalid E-Mail");
    var StoringKO = new Array("Service unavailable; please retry later", "Registrazione non terminata a causa di errori;<br />riprovare in seguito", "Service unavailable; please retry later");
    var StoringOK = new Array("Thank you!<br>Your E-Mail was successfully recorded", "Grazie!<br>La richiesta e\' stata presa in carico, verri ricontattato al piu\' presto", "Thank you!<br>Your E-Mail was successfully recorded");
    var StoringYET = new Array("E-mail is already existing!", "E-Mail gi&agrave; registrata!", "E-mail is already existing!");

    if (document.frmNoleggio.email.value == '') {
        Sexy.error(alertSTD + MailMissed[q] + '</p>');
        return false;
    }
    if (document.frmNoleggio.email.value.indexOf('@') == -1) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }
    if (document.frmNoleggio.email.value.indexOf('.') == -1) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }
    if (document.frmNoleggio.email.value.indexOf(',') >= 0) { Sexy.error(alertSTD + MailInvalid[q] + '</p>'); return false; }

    if (document.frmNoleggio.nome.value == '') { Sexy.error(alertSTD + 'Nome mancante</p>'); return false; }
    if (document.frmNoleggio.cognome.value == '') { Sexy.error(alertSTD + 'Cognome mancante</p>'); return false; }
    if (document.frmNoleggio.telefono.value == '') { Sexy.error(alertSTD + 'Telefono mancante</p>'); return false; }
    if (document.frmNoleggio.giornodesiderato.value == '') { Sexy.error(alertSTD + 'Giorno Desiderato mancante</p>'); return false; }
    if (document.frmNoleggio.dalleore.value == '') { Sexy.error(alertSTD + 'Dalle Ore mancante</p>'); return false; }
    if (document.frmNoleggio.alleore.value == '') { Sexy.error(alertSTD + 'Alle Ore mancante</p>'); return false; }



    email = document.frmNoleggio.email.value;
    nome = document.frmNoleggio.nome.value;
    cognome = document.frmNoleggio.cognome.value;
    telefono = document.frmNoleggio.telefono.value;
    giornodesiderato = document.frmNoleggio.giornodesiderato.value;
    dalleore = document.frmNoleggio.dalleore.value;
    alleore = document.frmNoleggio.alleore.value;
    giorniprove = document.frmNoleggio.giorniprove.value;
    dalleoreprove = document.frmNoleggio.dalleoreprove.value;
    alleoreprove = document.frmNoleggio.alleoreprove.value;
    
    serviceaudio = document.frmNoleggio.serviceaudio.checked;
    serviceluci = document.frmNoleggio.serviceluci.checked;
    tecnico = document.frmNoleggio.tecnico.checked;
    servicecompleto = document.frmNoleggio.servicecompleto.checked;
    
    altrerichieste = document.frmNoleggio.altrerichieste.value;


    strP = "email=" + email + "&nome=" + nome + "&cognome=" + cognome + "&telefono=" + telefono + "&giornodesiderato=" + giornodesiderato + "&dalleore=" + dalleore + "&alleore=" + alleore + "&giorniprove=" + giorniprove + "&dalleoreprove=" + dalleoreprove + "&alleoreprove=" + alleoreprove + "&serviceaudio=" + serviceaudio + "&serviceluci=" + serviceluci + "&tecnico=" + tecnico + "&servicecompleto=" + servicecompleto + "&altrerichieste=" + altrerichieste;
    s = fmk$PostCall('/EXECnoleggio', strP, true, 'catalogoDati');
    
    
    
    
    
    switch (s) {
        case '-1':
            Sexy.error(alertSTD + StoringKO[q] + '</p>');
            break;
        case '0':
            Sexy.error(alertSTD + StoringYET[q] + '</p>');
            break;
        case '1':
            Sexy.info(alertSTD + StoringOK[q] + '</p>');
            setTimeout("document.location.href='/'",2500);
            break;
        default:
            Sexy.error(alertSTD + StoringKO[q] + '</p>');
            break;
    }
    return false;
    
        
}



function Prenota() {
    var alertSTD = "<h1>Servizio prenotazione spettacoli</h1><em>Cinema Teatro San Giovanni Bosco</em><br/><p>";
    if (document.frmData.spettacoloid.value == '' || document.frmData.spettacoloid.value == '0') { Sexy.error(alertSTD + 'Spettacolo non selezionato!'); return };
    if (document.frmData.nome.value == '') { Sexy.error(alertSTD+'Nome non inserito'); return };
    if (document.frmData.cognome.value == '') { Sexy.error(alertSTD + 'Cognome non inserito'); return };
    if (document.frmData.telefono.value == '') { Sexy.error(alertSTD + 'Telefono non inserito'); return };
    if (document.frmData.email.value == '') { Sexy.error(alertSTD + 'E-Mail non inserita'); return };

    if (document.frmData.email.value.indexOf('@') == -1) { Sexy.error(alertSTD + 'E-Mail no valida'); return false; }
    if (document.frmData.email.value.indexOf('.') == -1) { Sexy.error(alertSTD + 'E-Mail no valida'); return false; }
    if (document.frmData.email.value.indexOf(',') >= 0) { Sexy.error(alertSTD + 'E-Mail no valida'); return false; }


    if (document.frmData.annotazioni.value == '' || document.frmData.annotazioni.value == 'Indicare numero interi, numero ridotti, altre annotazioni') { Sexy.error(alertSTD + 'Annotazioni non inserite'); return };
    if (document.frmData.posto.value == '' || document.frmData.posto.value == 'Hai scelto...') { Sexy.error(alertSTD + 'Posti non selezionati'); return };

    nome = document.frmData.nome.value;
    cognome = document.frmData.cognome.value;
    telefono = document.frmData.telefono.value;
    email = document.frmData.email.value;
    annotazioni =document.frmData.annotazioni.value;
    posto =document.frmData.posto.value;
    spettacoloid = document.frmData.spettacoloid.value;

    strP = 'nome=' + nome + '&cognome=' + cognome + '&telefono=' + telefono + '&email=' + email + '&annotazioni=' + annotazioni + '&posto=' + posto + '&spettacoloid=' + spettacoloid;
    s = fmk$PostCall('/EXECprenotazione', strP, true, 'catalogoDati');
    
    switch (s) {
        case '-1':
            Sexy.error(alertSTD + 'Non posso completare l\'operazione; riprovare pi&ugrave; tardi</p>');
            break;
        case '-3':
            Sexy.error(alertSTD + 'Non posso completare l\'operazione; uno o pi&ugrave; posti che hai scelto sono impegnati o in attesa di conferma. Cambiare la propria scelta o riprovare fra qualche minuto.</p>');
			setTimeout("document.location.href=''",4000);
            break;			
        case '-2':
            Sexy.error(alertSTD + 'Per questo spettacolo esiste una prenotazione con questa E-Mail e questo Cognome.<br>Verifica bene la cartella SPAM della tua casella di posta elettronica per verificare eventuali altre prenotazoni che hai fatto ma NON CONFERMATO!</p>');
            break;			
        case '1':
            Sexy.alert(alertSTD + 'Prenotazione inserita ma NON CONFERMATA.<br>Per confermare segui le istruzion inviate all\'indirizzo ' + document.frmData.email.value + '<p>Grazie per aver scelto cinesgbosco.it</p></p>');
            setTimeout("document.location.href='/'",10000);
            break;
        default:
            Sexy.error(alertSTD + 'Non posso completare l\'operazione; riprovare pi&ugrave; tardi</p>');
            break;
    }
    return false;    
}


function fmk$PostCall(url, parString, callBack, content) {
    var ajax = assegnaXMLHttpRequest();
    if (ajax) {
        ajax.open("POST", url, false);
        ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajax.setRequestHeader("Content-length", parString.length);
        ajax.setRequestHeader("connection", "close");
        ajax.send(parString);
        return ajax.responseText;
    }
    else {
        return false;
    }
}

