function trim(campo) {
	campo.value = campo.value.replace(/^\s*/, '').replace(/\s*$/, '');
}

function trim2(txtVal) {
	return txtVal.replace(/^\s*/,'').replace(/\s*$/,'');
}

function isEmailAddr(emailAddr) {
	if (emailAddr.match(/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)$/gi) == null)
		return false;
	return true;
}

function isCAP(capVal) {
	if (capVal.match(/^\d{5}$/gi) == null)
		return false;
	return true;
}

function isBadDate(campo, msg) {
	var data=campo.value.replace(/[^-\d\.\/]/gi,'');
	data=data.replace(/-/gi,"/");
	data=data.replace(/\./gi,"/");

	if (data.indexOf("/")!=-1) {
		var vData=data.split("/");
		var d=new Date(vData[2],vData[1]-1,vData[0]);
		var ds=vData[0].replace(/^0*/,'')+"/"+vData[1].replace(/^0*/,'')+"/"+vData[2];
		if (ds!=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear()) {
			alert(msg);
			if (campo.type!='hidden') {
				campo.select();
				campo.focus();
			}
			return true;
		}
	}
	else {
		if(data.length==8||data.length==6) {
			var gg=data.substr(0,2);
			var mm=data.substr(2,2);
			var yy=data.substr(4);
			if (yy.length==2) {
				yy="20"+yy;
			}
			var d=new Date(yy,mm-1,gg);
			var ds=gg.replace(/^0*/,'')+"/"+mm.replace(/^0*/,'')+"/"+yy;
			if (ds!=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear()) {
				alert(msg);
				if (campo.type!='hidden') {
					campo.select();
					campo.focus();
				}
				return true;
			}
		}
		else {
			alert(msg);
			if (campo.type!='hidden') {
				campo.select();
				campo.focus();
			}
			return true;
		}
	}
	campo.value = (d.getDate() < 10 ? '0' : '') + d.getDate().toString() + '/' + (d.getMonth() < 9 ? '0' : '') + (d.getMonth() + 1).toString() + '/' + d.getFullYear();
	return false;
}

function verifyLoginInfo(frm) {
	frm.log.value = ''
	trim(frm.username);
	trim(frm.psw);
	if (frm.username.value=='' || frm.psw.value=='') {
		alert('Indicare E-mail e Password');
		return false;
	}
	frm.log.value = 1;
	return true;
}

function expSubDest(id) { var p = document.getElementById(id + "_items"), a = document.getElementById(id); if (p.style.display != "none") { p.style.display = "none"; a.style.fontStyle = ""; a.className = "filters-grp-row filters-grp-row-collapsed" } else { p.style.display = "inline"; a.style.fontStyle = "italic"; a.className = "filters-grp-row filters-grp-row-expanded" } }

function openPage(pg) {var frm = document.frmRefineSrc; if (frm) { if (pg>1) frm.action += '?pg=' + pg } frm.submit() }
function resetSrcFld(frm) { frm.dest.options[0].selected = true; frm.datapart.value = ""; frm.prezzo.options[0].selected = true; frm.srcByMonth.value = ""; frm.srcTratt.value = ""; frm.srcSingGratis.value = "" }
function monthSrc(m) { var frm = document.frmSrcOffers; if (frm) { resetSrcFld(frm); frm.srcByMonth.value = m; if (verifySrc(frm, 'offerte-vacanze/', '')) { frm.issrc.value = 'OK'; frm.submit() } } }
function freeSingleRoom() { var frm = document.frmSrcOffers; if (frm) { resetSrcFld(frm); frm.srcSingGratis.value = 'true'; if (verifySrc(frm, 'offerte-vacanze/', '')) { frm.issrc.value = 'OK'; frm.submit() } } }
function refineSrcPrice(price) {var frm = document.frmSrcOffers; if (frm) {var c = getSrcTabCode(); var prz = document.getElementById('prezzo'+c); var l = prz.options.length; for (j = 1; j < l; j++) { if (price == prz.options[j].value) prz.options[j].selected = true; else prz.options[j].selected = false; } if (verifySrc(frm)) { frm.submit() } } }
function refineSrcDest(dest) { var frm = document.frmSrcOffers; if (frm) { var c = getSrcTabCode(); var d = document.getElementById('dest' + c); var l = d.options.length; for (j = 1; j < l; j++) { if (dest == d.options[j].value) d.options[j].selected = true; else d.options[j].selected = false; } if (verifySrc(frm)) { frm.submit() } } }
function refineSrcTratt(tratt) { var frm = document.frmSrcOffers; if (frm) { frm.srcTratt.value = tratt; if (verifySrc(frm)) { frm.submit() } } }
function refineSrcPrice2(price) { var frm = document.frmRefineSrc; if (frm) { frm.prezzo.value = price; frm.submit() } }
function refineSrcDest2(dest) { var frm = document.frmRefineSrc; if (frm) { frm.dest.value = dest; frm.submit() } }
function refineSrcTratt2(tratt) { var frm = document.frmRefineSrc; if (frm) { frm.srcTratt.value = tratt; frm.submit() } }
function verifySrc(frm, act, cod) { var dest = 'any', dp = 'any', prz = 'any'; if (cod == undefined) { cod = getSrcTabCode() } if (act == undefined) { act = document.getElementById('srcUrl').value; if (act == '') return; } if (document.getElementById('dest' + cod).value != '') dest = document.getElementById('dest' + cod).value; if (document.getElementById('prezzo' + cod).value != '') prz = document.getElementById('prezzo' + cod).value; var datap = document.getElementById('datapart' + cod); trim(datap); if (datap.value != '') { if (isBadDate(datap, 'Data di partenza non accettabile')) { return false } dp = datap.value.substring(6).toString() + datap.value.substring(3, 5).toString() + datap.value.substring(0, 2).toString() } frm.action += act + dest + '/' + dp + '/' + prz + '/'; setWaitingStatus(true); return true; }
function submitSearch(frm, act, cod) { var v = verifySrc(frm, act, cod), b = document.getElementById('btnSrcCnt' + cod), l = document.getElementById('srcLoader' + cod); if (v) { frm.issrc.value = 'OK'; b.style.display = "none"; l.style.display = "inline"; } else { b.style.display = "inline"; l.style.display = "none" } if (v) frm.submit(); }
function getSrcTabCode() { return (openTab == '1' ? '' : '-' + (parseInt(openTab, 10) - 1)) }
//wait
function setWaitingStatus(waiting) { var c1 = document.getElementById("pgcontent"), c2 = document.getElementById("search_wait"); c1.style.display = waiting ? "none" : "block"; c2.style.display = waiting ? "block" : "none" }
//social networks
function shareOnFacebook(offimg, title) { var url = 'http://www.marevero.com/catalogo_sfogliabile/pages/img/' + offimg + '.jpg'; var f = 'http://www.facebook.com/share', p = '.php?u=' + encodeURIComponent(url) + '&amp;t=' + encodeURIComponent(title); try { if (!/^(.*\.)?facebook\.[^.]*$/.test(document.location.host)) { throw (0) } share_internal_bookmarklet(p) } catch (z) { a = function() { if (!window.open(f + 'r' + p, 'sharer', 'toolbar=0,status=0,resizable=1,width=626,height=436')) { document.location.href = f + p } }; if (/Firefox/.test(navigator.userAgent)) { setTimeout(a, 0) } else { a() } } void (0) }
//collapsible menu panels
function hideMenuPanel(id) { var tr = document.getElementById(id), tt = document.getElementById(id + '_tit'); if (tr.style.display != "none") { tr.style.display = "none"; tt.className = tt.className.replace(/green-min/g, "green-max"); tt.className = tt.className.replace(/orange-min/g, "orange-max"); tt.className = tt.className.replace(/azure-min/g, "azure-max") } else { tr.style.display = "inline"; tt.className = tt.className.replace(/green-max/g, "green-min"); tt.className = tt.className.replace(/orange-max/g, "orange-min"); tt.className = tt.className.replace(/azure-max/g, "azure-min") } }
function showOffDet(pos) { $('#boxOffDetails').html($('#offdett_' + pos).html()); $('#boxOffDetails').dialog('open') }
function OpenFlip() { var w = screen.availWidth ? screen.availWidth : 1000, h = screen.availHeight ? screen.availHeight : 700; window.showModalDialog('/catalogo_sfogliabile/index.html', null, 'dialogWidth:' + w + 'px;dialogHeight:' + h + 'px;resizable:1;center:1;scroll:0;status:0') }

function openWindow(url, w, h) { if (url && url != "") { w = w || screen.availWidth; h = h || screen.availHeight; window.showModalDialog(url, null, 'dialogWidth:' + w + 'px;dialogHeight:' + h + 'px;resizable:1;center:1;scroll:1;status:0') } }

function addGrayedLayer() {
	if (!$('#grayed-layer').length) {
		$('body').append('<div id=\"grayed-layer\"></div><div id=\"grayed-layer-close\">Chiudi</div>');
		$('#grayed-layer-close').click(function() { closeFlickrGallery() });
	}
	$('#grayed-layer').css({ "display": "block", "opacity": 0.5, "width": $(document).width(), "height": $(document).height() });
}
function removeGrayedLayer() {
	$('#grayed-layer').remove();
	$('#grayed-layer-close').remove();
}

var flickrFirstTime = '';
function openFlickrGallery(tag) {
	addGrayedLayer();
	$('#flickrgallery').css({ "display": "block" });
	if (flickrFirstTime != tag) {
		$(window).resize(function() { if ($('#grayed-layer').length) openFlickrGallery(tag) });
		showFlickrGallery(tag);
		flickrFirstTime = tag;
	}
}

function closeFlickrGallery() {
	$('#flickrgallery').css({ "display": "none" });
	removeGrayedLayer();
}

function showFlickrGallery(tags) {
	var fo = new SWFObject("/swf/TiltViewer.swf", "viewer", "100%", "100%", "9.0.28", "#000000");
	fo.addParam("wmode", "transparent");
	fo.addVariable("bkgndTransparent", "true");
	fo.addVariable("showFullscreenOption", "false");

	fo.addVariable("useFlickr", "true");
	fo.addVariable("user_id", "54229855@N02");
	fo.addVariable("tags", tags);
	fo.addVariable("tag_mode", "all");
	fo.addVariable("showTakenByText", "false");

	fo.addVariable("useReloadButton", "false");
	fo.addVariable("columns", "4");
	fo.addVariable("rows", "4");
	//fo.addVariable("showFlipButton", "true");
	//fo.addVariable("showLinkButton", "true");	
	//fo.addVariable("linkLabel", "View image info");
	//fo.addVariable("frameColor", "0xFF0000");
	fo.addVariable("backColor", "0x164397");
	//fo.addVariable("bkgndInnerColor", "0x800000");
	//fo.addVariable("bkgndOuterColor", "0x0000FF");
	fo.addVariable("langGoFull", "Vai a schermo intero");
	fo.addVariable("langExitFull", "Esci dalla modalità a schermo intero");
	fo.addVariable("langAbout", "Informazioni su");

	fo.addVariable("frameWidth", "20");
	fo.addVariable("zoomedInDistance", "1200");
	fo.addVariable("zoomedOutDistance", "4600");
	fo.addVariable("fontName", "Verdana");
	fo.addVariable("titleFontSize", "74");
	//fo.addVariable("descriptionFontSize", "32");
	//fo.addVariable("linkFontSize", "41");
	//fo.addVariable("linkTarget", "_self");
	fo.addVariable("navButtonColor", "0xFFFFFF");
	//fo.addVariable("flipButtonColor", "0x0000FF");
	//fo.addVariable("textColor", "0xFFFFFF");
	//fo.addVariable("linkTextColor", "0x000000");
	//fo.addVariable("linkBkgndColor", "0xFFFFFF");
	fo.addVariable("enableSounds", "false");
	//fo.addVariable("tiltAmountIn", "75");
	//fo.addVariable("tiltAmountOut", "120");

	fo.addParam("allowFullScreen", "false");
	fo.write("flickrgallery");
}

var offersTimeout = null;
function mOffersOver() { clearTimeout(offersTimeout); }
function mOffersOut() { offersClip(); }
function offersClip() {
	var contWidth = 180;
	var contHeight = 425;

	var id1 = document.getElementById('slideOffersA');
	var id2 = document.getElementById('slideOffersB');
	var height = id1.offsetHeight;
	id1.style.top = parseInt(id1.style.top) - 1 + 'px';

	document.getElementById('slideOffers').style.height = contHeight + "px";
	document.getElementById('slideOffers').style.clip = 'rect(auto,' + contWidth + 'px,' + contHeight + 'px,auto)';
	id2.style.display = '';
	if (parseFloat(id1.style.top) == -(height / 2)) {
		id1.style.top = '0px';
	}
	offersTimeout = setTimeout(offersClip, 50);
}
