var myRequest = null;

function CreateXmlHttpReq(handler){
  var agt = navigator.userAgent.toLowerCase();
  var is_ie5 = (agt.indexOf('msie 5') != -1);
  var xmlhttp = null;
  try {
    xmlhttp = new XMLHttpRequest();
    try {
        // Fix for some version of Mozilla browser.
        http_request.overrideMimeType('text/xml');
    } catch(e) { }
    xmlhttp.onload = handler;
    xmlhttp.onerror = handler;
  } catch(e) {
    var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    xmlhttp = new ActiveXObject(control);
    xmlhttp.onreadystatechange = handler;
  }
  return xmlhttp;
}

function myHandler(){
    if (myRequest.readyState == 4 && myRequest.status == 200) {
        document.getElementById("content").innerHTML=myRequest.responseText;
    }
}

window.onload=function(){
	accesskeys();
	switch(screen.width){
		case 800:
			document.getElementById("dataora").style.left=10;
			break;
		case 1024:
			document.getElementById("dataora").style.left=26;
			break;
		case 1280:
			document.getElementById("dataora").style.left=154;
			break;
	}
	document.getElementById("dataora").style.display="block";
}

function toggleNews(id){
	/*if( document.getElementById(id).style.display=="block" ){
		document.getElementById(id).style.display="none";
	}
	else{
		document.getElementById(id).style.display="block";
		document.getElementById("t"+id).style.background="#C8C8F0";
		document.getElementById("t"+id).style.border="2px solid #00A000";
	}*/
	if( document.getElementById(id).aperto==true ){
		document.getElementById(id).aperto=false;
		new Effect.BlindUp(id);
	}
	else{
		document.getElementById(id).aperto=true;
		document.getElementById("t"+id).style.background="#beffd6";
		document.getElementById("t"+id).style.border="2px solid #00A000";
		new Effect.BlindDown(id);
	}
}

function toggleDiv(id){
	if( document.getElementById(id).aperto==true ){
		new Effect.toggle(id,'slide');
		document.getElementById(id).aperto=false;
	}
	else{
		new Effect.toggle(id,'blind');
		document.getElementById(id).aperto=true;
	}
}

/*
Funzione per l'apertura di una PopUp dimensionata
*/
function PrevFoto(img){
    foto1= new Image();
    foto1.src=(img);
    Controlla(img);
    }

function Controlla(img){
    if((foto1.width!=0)&&(foto1.height!=0)){
        viewFoto(img);
        }
    else{
        funzione="Controlla('"+img+"')";
        intervallo=setTimeout(funzione,100);
    }
}
function viewFoto(img){

 var winLocation, winName, winParam, winObj;
 var winPos, winPosTop, winPosLeft, winWidth, winHeight;

 winWidth=foto1.width+20;
 winHeight=foto1.height+25;

 winPosTop = (screen.height / 2) - winHeight / 2;
 winPosLeft = (screen.width / 2) - winWidth / 2;

 winPos = ',top=' + winPosTop + ',left=' + winPosLeft;
 winLocation = "zoom.asp?img="+img;
 winName = 'popUp';
 winParam = 'status=0,toolbars=0,menubar=0,history=0,width=' + winWidth + ',height=' + winHeight + winPos;

 winObj = window.open(winLocation, winName, winParam);

}

function switchButtons(id,idswitch){
	if( document.getElementById(id).style.display=="block" ){
		document.getElementById(id).style.display="none";
		document.getElementById(idswitch).src="images/ingrandisci.gif";
	}
	else{
		document.getElementById(id).style.display="block";
		document.getElementById(idswitch).src="images/riduci.gif";
	}
}

function closeDiv(id){
	document.getElementById(id).style.display='none';
}

function CalcolaItinerario(){
	if( document.getElementById("paese_start").value=="" )
		alert("Devi specificare una citta' di partenza!");
	else
		window.open('http://www.tuttocitta.it/tcolnew/index_tcol.html#sez=1110&tpr=C&ft=1&com='+document.getElementById('paese_start').value+'&ind='+document.getElementById('via_start').value+'&nc='+document.getElementById('n_start').value+'&comR=Campagna%20Lupia%20(VE)&indR=Via%20Repubblica&ncR=34');
}


function accesskeys(){
	if (document.getElementsByTagName){
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++){
			var anchor = anchors[i];

			//Rimuovo i tag
			myregexp=new RegExp("<[^<>]+>","gi");
			testo=anchor.innerHTML.replace(myregexp, "");
			anchor.accessKey = testo.substring(0,1);
		}
	}
}
