var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#cbutton").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

calendar = new Object();
tr = new Object();
tr.nextMonth = "Mese successivo";
tr.prevMonth = "Mese precedente";
tr.closeCalendar = "Chiudi calendario";
tr.pressCtlD = "Premi control-d o scegli bookmarks/add or preferiti/aggiungi nel tuo browser";
tr.pressCtlP = "Premi control-p o scegli file/stampa nel tuo browser";
tr.url = "./";
tr.title = "Benvenuti";
tr.icons = "./js/datePicker/img/";
var months=['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre',];
var days=['Lu','Ma','Me','Gi','Ve','Sa','Do'];
var days3=['Lun','Mar','Mer','Gio','Ven','Sab','Dom'];
var $t_hotels = 'Alberghi'.toLowerCase();
var $t_hotels_around = 'Hotel nelle vicinanze'.toLowerCase().replace(/ /g, '&#160;');




if (document.getElementById) {
  document.write("<style type='text/css'>");
  document.write(".blocktoggle {display: none}");
  document.write("</"+"style>");
  var shown = new Array();
}

function blocktoggle(i) {
  if (document.getElementById) {
    shown[i] = (shown[i]) ? false : true;
    currentdisplay = (shown[i]) ? 'block' : 'none';
    document.getElementById('blocktoggle'+i).style.display = currentdisplay;
  }
}

function blockdisplay(i) {
  if (document.getElementById){
    if (document.getElementById("blockdisplay"+i)) {
      for ( j = 1; j < 1000; j++ ) {
        if (document.getElementById('blockdisplay' + j)) {document.getElementById('blockdisplay' + j).style.display = 'none';}
        else {j = 1000;}
      }
      if (i) {document.getElementById("blockdisplay"+i).style.display = 'block';}
    }
  }
}
function validateEmail(email){
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	str = email;
	if(!str.match(emailRegEx)) return false;
	else return true;
}
function controlla($frm){
	if(!validateEmail(document.getElementById("newsletter_campo").value)){
		alert("Email non valida !");
		return false;
	} else return true;
}

$(document).ready(function(){
 
	$(".secure-popup a").hover(function() {
	$(this).next("div").stop(true, true).animate({opacity: "show", top: "-200"}, "slow");
	}, function() {
	$(this).next("div").animate({opacity: "hide", top: "-210"}, "fast");
	});
 
});
