function zoom(element){ //zoom image
	var a,html,o,img
	o = element.childNodes[0].getAttribute("src")
	a = o.replace(/_sml./,".")	
	html='<html>\n<head>\n<link href="popgallery.css" type="text/css" rel="stylesheet" />\n<title>Ingrandimento</title>\n</head>\n<body>\n<table border="0" cellpadding="0" cellspacing="0" >\n<tr>\n<td align="center" valign="middle"><img src="' + a + '" width="420" height="310" /></td>\n</tr>\n</table>\n</body>\n</html>'
	img = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0,top=50,left=200,width=550,height=470')
	img.document.write(html)
	
}
function requiredField(form){ // Controlla i campi obbligatori
	var i, pass, tot, temp
	pass = true
	tot = form.length
	for(i=0;i<=tot;i++){
		temp = form[i].name.substring(0,4)	
		//alert(temp)
		if(temp == "req_"){
				if(form[i].value == ""){
						form[i].focus()
						pass = false
						break
				}
		}
	}
	if(!pass){
		alert("Non hai compilato i campi necessari per l'invio!")
		return false
	}
	else{
		return true
		}
}

function disabledField(i){
	switch (i){
		case("si"):
			document.prenotazioni.m_persone.disabled = ""
			break
		case("no"):
			document.prenotazioni.m_persone.disabled = "disabled"
			break
		default:
			document.prenotazioni.m_persone.disabled = "disabled"
			break
	}
}

function openPopUp(url,w,h,desc){
	var param
	param = "width=" + w + ",height=" + h + ",toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0"
	window.open(url,desc,param)
}

function zooMap(a){
	map.src=a
}

function prinThis(){
	self.print()
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * |  Function Image trail
 * |  Simple Image Trail script- By JavaScriptKit.com
 * |  Visit http://www.javascriptkit.com for this script and more
 * |  This notice must stay intact
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
var offsetfrommouse=[15,15]; //immagine coord x y tenute a 15 px dalla posizione del mouse
var displayduration=0; //Durata in secondi dell'immagine che resta visibile.0per tutti
var currentimageheight = 410;	// La massima altezza di un'immagine.

var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;
var currentimagewidth = 490;	// La massima larghezza di un'img.
var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
else if (document.all)
return document.all.trailimagid.style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
else if (document.all)
return document.all.trailimagid
}

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}
 
function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-800px"
	clearTimeout(timer);
}

function stiEventi(){
	if(typeof window.event=="undefined") return ("firefox")
	if(typeof window.event!="undefined") return ("IE")
}


function showtrail(imagename,showthumb){	
	if(document.all){// IE, Opera
		if(navigator.userAgent.toLowerCase().indexOf("opera") != -1){//Opera
			img1=imagename.childNodes[1]
			//alert(img1.nodeName)
		}
		else{//IE
			img1=imagename.childNodes[0];
			//alert(img1.nodeName)
		}
	}
	else{// FireFox
		img1=imagename.childNodes[1];
		//alert(img1.nodeName)
	}
	img1=img1.src;
	str_start = img1.indexOf("_");
	str_end = img1.length;
	img2 = img1.substring(str_start + 1,str_end);
	
	if(img1.match('_x')){
		tempg="_x";
		width1='500px';
		height1='420px';
		width2='420px';
		height2='310px';
		widthDiv='520px';
		heightDiv='438px';
		
	}else{ 
		tempg="_y";
		width1='403px';
		height1='502px';
		width2='311px';
		height2='421px';
		widthDiv='423px';
		heightDiv='520px';
		
	}
	url="preview"+tempg;
	temp = img2.replace(/_sml/,".")
	i1 = temp.replace(/._x/,"")
	i = i1.replace(/._y/,"")
	s = showthumb
	timer = setTimeout("show('"+i+"',s,url,width1,height1,width2,height2,widthDiv,heightDiv);",0);
}
function show(imagename,showthumb,url,width1,height1,width2,height2,widthDiv,heightDiv){
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	if(docwidth>650 && docheight>500){
		newHTML = '<div class="border_preview" style="width:' + widthDiv + '; height:' + heightDiv +';"><div id="loader_container"><div id="loader"><div align="center">Caricamento immagine...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
		
		document.onmousemove=followmouse;
	
		if (showthumb > 0){
   	 		creazione_div='<div align="center" style="padding: 8px 10px 10px 10px;"><div style=" background-image:url('+url+'.jpg);background-position:center;background-repeat:no-repeat; width:'+width1+'; height:'+height1+';" ><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img onload="javascript:remove_loading();" src="gallery/' + imagename + '" border="0"   width="'+width2+'" height="'+height2+'"></td></tr></table></div></div>';
			newHTML = newHTML + creazione_div;	 
		}
		newHTML = newHTML + '</div>';
		if(navigator.userAgent.indexOf("Firefox")==-1){	
			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="390" height="390"></iframe>';
		}
		
	gettrailobjnostyle().innerHTML = newHTML;
	gettrailobj().display="block";
	
}

function followmouse(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	
	if (typeof e != "undefined"){
		//alert("ok1")
		if (docwidth - e.pageX < currentimagewidth){

		if(navigator.userAgent.indexOf("Firefox")!=-1)	{xcoord = e.pageX - xcoord - currentimagewidth + 2*offsetfrommouse[0]} else{ xcoord = e.pageX - xcoord - currentimagewidth + 6*offsetfrommouse[0] ;} // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 140)){
			ycoord += e.pageY - Math.max(0,(140 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		//alert("ok2")
		if (docwidth - event.clientX < currentimagewidth){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth + 2*offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 140)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(140 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-offsetfrommouse[0]
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}
}
