if (typeof jQuery == 'undefined') {}
else{
    
    jQuery(document).ready(function($){

        /*n*/


			$("#contactLink").click(function(){
				$("#contactForm").slideToggle("slow");
			});

			$("input#email").focus(function () {
				  $("input#email").removeClass("mandatory").addClass("ok");
				  $("label#email").removeClass("mandatory").addClass("ok");
			});
			$("input#email").blur(function() {
				if (this.value == ''){
					this.value = (this.defaultValue ? this.defaultValue : '');
					$(this).removeClass("ok").addClass("mandatory");
					$("label#email").removeClass("ok").addClass("mandatory");
				}
			});
			$("#privacy").click(function(){
				if ($("#privacy").is(":checked")){
					$("#privacy").removeClass("unchecked").addClass("checked");
				}
				else{
					$("#privacy").removeClass("checked").addClass("unchecked");
				}
			});


		/*function closeForm(){
		   $("#messageSent").show("slow");
		   setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
		}*/

		window.validateSign = function(f){
			var espressione = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$");
			var email=f.email.value;
			if(!espressione.test(email)){
				alert("Indirizzo email non valido");
				return false;
			}

			if(!f.privacy.checked){
				alert("Per favore, compila tutti i campi obbligatori");
				return false;
			}
			//closeForm();
		}

		/*endn*/

        $.datepicker.setDefaults({
            closeText:"Chiudi",
            prevText:"&amp;#x3c;Prec",
            nextText:"Succ&amp;#x3e;",
            currentText:"Oggi",
            monthNames:["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"],
            monthNamesShort:["Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic"],
            dayNames:["Domenica","Luned&amp;#236","Marted&amp;#236","Mercoled&amp;#236","Gioved&amp;#236","Venerd&amp;#236","Sabato"],
            dayNamesShort:["Dom","Lun","Mar","Mer","Gio","Ven","Sab"],
            dayNamesMin:["Do","Lu","Ma","Me","Gi","Ve","Sa"],
            weekHeader:"Sm",
            dateFormat:"dd/mm/yy",
            firstDay:1,
            isRTL:false,
            showMonthAfterYear:false,
            yearSuffix:""
        });
        $("#arrDate").datepicker({
            dateFormat:"dd-mm-yy",
            defaultDate:2,
            minDate:1,
            hideIfNoPrevNext:true
        });
        var b=new Date();
        b.setDate(b.getDate());
        $("#arrDate").val($.datepicker.formatDate("dd-mm-yy",b));
        $("#arrDate").change(function(){
            var d=$.datepicker.parseDate("dd-mm-yy",$("#arrDate").val());
            d.setDate(d.getDate()+1);
            $("#depDate").val($.datepicker.formatDate("dd-mm-yy",d))
        });
        $("#depDate").datepicker({
            dateFormat:"dd-mm-yy",
            defaultDate:null,
            minDate:1,
            hideIfNoPrevNext:true
        });
        var c=new Date();
        c.setDate(c.getDate()+1);
        $("#depDate").val($.datepicker.formatDate("dd-mm-yy",c));
        $(".a2").attr("disabled","disabled");
        $("#numRooms").change(function(){
            var d=parseInt($("#numRooms option:selected").attr("value"));
            $(".a2").attr("disabled","");
            $(".a"+(d+1)).attr("disabled","disabled")
        });
        var a=parseInt($("#numRooms option:selected").attr("value"));
        $(".a2").attr("disabled","");
        $(".a"+(a+1)).attr("disabled","disabled");
        $("#prenotazione").submit(function(){
			var father = $("#prenotazione");
            var f=$.datepicker.parseDate("dd-mm-yy",$("#depDate").val());
            var d=$.datepicker.parseDate("dd-mm-yy",$("#arrDate").val());
            if(f.getTime()<d.getTime()){
                alert("La data di partenza non può precedere quella di arrivo");
                return false
            }
            var e=$("#hotel").val();
            if(e=="--"){
                alert("Selezionare un hotel per procedere");
                return false
            }
			//controlli per top-secret
			if(father.find("#tsnome")&& father.find('#tscognome') && father.find('#tsemail') && father.find('#tstelefono')){
				
				var tsnome = $("#tsnome").val(),
					tscognome = $("#tscognome").val(),
					tsemail = $("#tsemail").val(),
					tstelefono = $("#tstelefono").val();
				if(tsnome == ""){
					alert("Inserire il nome.");
					return false
				}
				if(tscognome == ""){
					alert("Inserire il cognome.");
					return false
				}
				if(tsemail == ""){
					alert("Inserire l'indirizzo email.");
					return false
				}
				if(tstelefono == ""){
					alert("Inserire il numero di telefono.");
					return false
				}
				
			}
            return true
        });
    

        var telefono = $('.telefono-content'),
        fax = $('.fax-content'),
        email = $('.mail-content'),
        telefono2 = $('.telefono2-content'),
        fax2 = $('.fax2-content'),
        pixel = new Image();

        telefono.append('<span class="mostra">Mostra Telefono</span>');
        fax.append('<span class="mostra">Mostra Fax</span>');
        telefono2.append('<span class="mostra">Mostra Telefono</span>');
        fax2.append('<span class="mostra">Mostra Fax</span>');
        email.append('<span class="mostra">Mostra Email</span>');
        telefono.children('.mostra').click(function(e){
            $(this).hide();
            $(this).parent().children('.wrapped-content').show();
            //$('.telefono-content .wrapped-content').show();
            if (!pixel.src)
                pixel.src = "http://tools.sembox.it/index.php?load=conversioni&act=conversione&c=1033&cn=3";
        });
        fax.children('.mostra').click(function(e){
            $(this).hide();
            $(this).parent().children('.wrapped-content').show();
            //$('.fax-content .wrapped-content').show();
            if (!pixel.src)
                pixel.src = "http://tools.sembox.it/index.php?load=conversioni&act=conversione&c=1033&cn=3";
        });
        telefono2.children('.mostra').click(function(e){
            $(this).hide();
            $(this).parent().children('.wrapped-content').show();
            //$('.telefono-content .wrapped-content').show();
            if (!pixel.src)
                pixel.src = "http://tools.sembox.it/index.php?load=conversioni&act=conversione&c=1033&cn=3";
        });
        fax2.children('.mostra').click(function(e){
            $(this).hide();
            $(this).parent().children('.wrapped-content').show();
            //$('.fax-content .wrapped-content').show();
            if (!pixel.src)
                pixel.src = "http://tools.sembox.it/index.php?load=conversioni&act=conversione&c=1033&cn=3";
        });

        email.children('.mostra').click(function(e){
            $(this).hide();
            $(this).parent().children('.wrapped-content').show();
            //$('.mail-content .wrapped-content').show();
            if (!pixel.src)
                pixel.src = "http://tools.sembox.it/index.php?load=conversioni&act=conversione&c=1033&cn=3";
        });

        window.getprice = function (data) {
        //console.log(data)
        };
        $('div.price-box').each(function(){
            var idhotel = $(this).attr('id').replace('price-', '');
            if((idhotel != null)||(idhotel == 'IDHOTEL')){
                var urlscript = 'http://81.208.4.141/ideahotel_soapclient/xml_saved/';

                var url_json = urlscript + idhotel + '.php?callback=?';

                $.getJSON(url_json, function(data){
                    var actualprice = data.lowprice;
                    if(actualprice == '0')
                        actualprice = 'n.d.';
                    else
                        actualprice = actualprice + ' €';

                    $('#price-'+idhotel+'num').text(actualprice);
                }
                );

            }
        });

        $('img.fotogallery-pic-details').hover(function(){
            var hoveredImgSrc = $(this).attr('src');
            $('img.fotogallery-pic-details-big').attr('src', hoveredImgSrc)
        }, function(){
            });

        /*function testPop(){
            var a=new Liferay.Popup({
                header:"Codice promozionale",
                modal:false,
                width:300,
                height:200,
                xy:["center",100]
            });
            a.html("&lt;div style='padding:0px 20px'&gt;&lt;h1&gt;Codice promozionale&lt;/h1&gt;&lt;p&gt;Se sei in possesso di un codice promozionale, inseriscilo in questo punto della prenotazione per usufruire degli esclusivi vantaggi.&lt;p&gt;&lt;/div&gt;")
        }*/

        $('.weekend').click(function(){
            $('#weekend').show();
            $('#anticipo').hide();
            $('.box-puntodidomanda').hide();
            return false;
        });

        $('.anticipo').click(function(){
            $('#anticipo').show();
            $('#weekend').hide();
            $('.box-puntodidomanda').hide();
            return false;
        });

        $('.puntodomandaform').click(function(){
            $('.box-puntodidomanda').show();
            $('#anticipo').hide();
            $('#weekend').hide();
            return false;
        });

        $('#chiudiweekend').click(function(){
           $('#weekend').hide();
           return false;
        });

        $('#chiudianticipo').click(function(){
           $('#anticipo').hide();
           return false;
        });

        $('#chiudipuntodomandaform').click(function(){
           $('.box-puntodidomanda').hide();
           return false;
        });

        
        

    });
/*
*/
/*function testPop(){
        var a=new Liferay.Popup({
            header:"Codice promozionale",
            modal:false,
            width:300,
            height:200,
            xy:["center",100]
        });
        a.html("&lt;div style='padding:0px 20px'&gt;&lt;h1&gt;Codice promozionale&lt;/h1&gt;&lt;p&gt;Se sei in possesso di un codice promozionale, inseriscilo in questo punto della prenotazione per usufruire degli esclusivi vantaggi.&lt;p&gt;&lt;/div&gt;")
    }*/
/*]]&gt;*/




}

