// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function Popup(url, name, options) {
	popop = window.open(url, name, options);
}

function showpic(e) {
	$('loader').setStyles( {
		background: '#fff url(/images/ajax-loader.gif) 50% 50% no-repeat'
	} );
	$$('#content .list-gallery a').each(function(item) {
		item.setProperty('class', '');
	});
	e.setProperty('class', 'active');
	img = new Element('img', { 'src' : e.href });
	img.setStyle('display', 'none');
	$('loader').empty();
	img.injectInside('loader');
	img.addEvent('load', function(){
		//alert("caricata");
		$('loader').setStyle('background', 'none');
		this.setStyle('display', 'block');
	});
}

function popup_by_size(url) {
	popop = window.open('/popup_by_size.html?' + url, 'pop', 'resizable=1, scrollbars=0, width=100, height=100');
}

function formatDate() {
	document.getElementById("gg").value = document.getElementById("date_gg").value;
	document.getElementById("mm").value = document.getElementById("date_mm").value;
	document.getElementById("aa").value = document.getElementById("date_aa").value;
	return true;
}

function setFieldValue(n, val) {
	if (n == 0) document.getElementById("search_text").value = "";
	if (n == 1 && val == "") document.getElementById("search_text").value = "Inserisci una stringa di ricerca";
}

function jumpToPage(e) {
	var newIndex = e.selectedIndex;
	if (newIndex != 0) { 
		document.location.assign(e.options[newIndex].value);
	}
}

function hideSelects() {
	if (document.getElementById("search")) {
		e = document.getElementById("search");
		e.style.display = (e.style.display == 'none') ? 'block' : 'none';
	}
}

function hideSelectsHotel() {
	e = document.getElementById("hotels");
	if (e.style.display == 'none') {
		document.getElementById("booking").style.display = 'none';
	} else {
		document.getElementById("booking").style.display = 'block';
	}
}

function checkFields(e, lang) {
	
	if (!e.pressrequest_email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/)) {
		lang == "it" ? alert("Il formato del campo e-mail non è corretto") : alert("E-mail format is wrong");
		return false;
	}
	
	if (!e.checkbox_privacy.checked) {
		lang == "it" ? alert("E' necessario prendere atto dell'informativa sulla privacy e autorizzare il trattamento dei dati personali per proseguire") : alert("You have to read privacy statement and authorize the processing of your my personal data to go on")
		return false;
	}
	
	if (!e.radio_privacy[0].checked) {
		lang == "it" ? alert("E' necessario prendere atto dell'informativa sulla privacy e autorizzare il trattamento dei dati personali per proseguire") : alert("You have to read privacy statement and authorize the processing of your my personal data to go on")
		return false;
	}
}

function ValidateCardSubscription(e, lang) {
	
	if (!e.email.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})$/)) {
		lang == "it" ? alert("Il formato del campo e-mail non è corretto") : alert("E-mail format is wrong");
		return false;
	}
	
	if (!e.checkbox_privacy.checked) {
		lang == "it" ? alert("E' necessario prendere atto dell'informativa sulla privacy e autorizzare il trattamento dei dati personali per proseguire") : alert("You have to read privacy statement and authorize the processing of your my personal data to go on")
		return false;
	}
	
	if (!e.radio_privacy[0].checked) {
		lang == "it" ? alert("E' necessario prendere atto dell'informativa sulla privacy e autorizzare il trattamento dei dati personali per proseguire") : alert("You have to read privacy statement and authorize the processing of your my personal data to go on")
		return false;
	}
}