var exclude=1;
var agt=navigator.userAgent.toLowerCase();

function WebcamOra() {
var TimezoneOffset = +1;
var Now,Jan,Jul;
with (new Date()) {Now = getTimezoneOffset();setMonth(0);Jan = getTimezoneOffset();setMonth(6);Jul = getTimezoneOffset();}
if (Now == Math.min(Jan,Jul))
TimezoneOffset = +2; var localTime = new Date(); var ms = localTime.getTime() + (localTime.getTimezoneOffset() * 60000) + TimezoneOffset * 3600000;
var t=new Date(ms),a=WebcamOra.arguments,str="",i,a1,lang="4"; var month=new Array('Gennaio','genn', 'Febbraio','febbr', 'Marzo','mar', 'Aprile','apr', 'Maggio','magg', 'Giugno','giugno', 'Luglio','luglio', 'Agosto','ag', 'Settembre','sett', 'Ottobre','ott', 'Novembre','nov', 'Dicembre','dic');
var tday= new Array('Domenica','Domenica','Luned&igrave;','Luned&igrave;', 'Marted&igrave;','Marted&igrave;', 'Mercoled&igrave;','Mercoled&igrave;','Gioved&igrave;','Gioved&igrave;','Venerd&igrave;','Venerd&igrave;','Sabato','Sabato');
for(i=0;i<a.length;i++){a1=a[i].charAt(1);switch (a[i].charAt(0)){
case "M":if  ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;
case "W":str+=tday[t.getDay()*2+Number(a1)];break;
case "H": if ((t.getHours()<10)) str+="0";str+=t.getHours();break;
case "N": if ((t.getMinutes()<10)) str+="0";str+=t.getMinutes();break;
default: str+=unescape(a[i]);} } return str; 
}

function LanguageChange(langToChange, cookiedomain) {
var today = new Date();
var expirydate = new Date();
expirydate.setTime(today.getTime()+ 31536000);
document.cookie = 'lang=' + langToChange + ';expires=' + expirydate.toGMTString() + ';path=/;domain='+ cookiedomain;
document.location.reload();
}

function ShowMyPic(myImage) { 
	document.getElementById('map_div').style.visibility = 'visible';
	document.getElementById('map_divi').style.height = myImage.height;
	imgWidth = myImage.width; imgHeigth = myImage.height;
	leftOffset = -((imgWidth- winWidth)/2);
	topOffset = -((imgHeigth- winHeigth)/2);
	document.getElementById('map_divi').style.left = leftOffset+'px';
	document.getElementById('map_divi').style.top = topOffset+'px';
	if ((imgWidth > winWidth) || (imgHeigth > winHeigth)) {	
		draggabile = "1"; 
		document.getElementById('cmd_map').innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabletable"><tr><td width="100%" align="center">Attenzione: Puoi usare il mouse con il <i>drag & drop</i> per spostarti sulla mappa (ottimizzato con Internet Explorer)<br><a href="javascript:SmallSize()">Rendi la mappa più piccola per vedere tutto il comprensorio</a><br><a href="javascript:MediumSize()">Dimensione Intermedia</a></td><td nowrap="yes" align="center"><div id="sponsor"></div></td></tr></table>'; 
	}; 
	document.getElementById('img_map').src = myImage.src; 
	setSponsor();
}

function SmallSize() {
	if ((imgWidth/winWidth) > (imgHeigth/winHeigth)) { 
		document.img_map.width = winWidth;
	} else { 
		document.img_map.height = winHeigth;
	}; 
	leftOffset = 0; 
	topOffset = 0; 
	document.getElementById('map_divi').style.left = leftOffset+'px';
	document.getElementById('map_divi').style.top = topOffset+'px'; 
	document.getElementById('cmd_map').innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabletable"><tr><td width="100%" align="center"><a href="javascript:NormalSize()">Torna alla dimensione originale e naviga con il drag & drop</a><br><a href="javascript:MediumSize()">Dimensione Intermedia</a></td><td nowrap="yes" align="center"><div id="sponsor"></div></td></tr></table>';
	draggabile = "0"; 
	setSponsor();
}; 

function MediumSize() { 
	if ((imgWidth/winWidth) > (imgHeigth/winHeigth)) { 
		document.img_map.width = (winWidth+imgWidth)/2; 
	} else { 
		document.img_map.height = (winHeigth+imgHeigth)/2;
	}; 
	leftOffset = - ((imgWidth- winWidth)/4); 
	topOffset = - ((imgHeigth- winHeigth)/4); 
	document.getElementById('map_divi').style.left = leftOffset+'px'; 
	document.getElementById('map_divi').style.top = topOffset+'px'; 
	document.getElementById('cmd_map').innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabletable"><tr><td width="100%" align="center">Attenzione: Puoi usare il mouse con il <i>drag & drop</i> per spostarti sulla mappa<br><a href="javascript:NormalSize()">Torna alla dimensione originale</a><br><a href="javascript:SmallSize()">Rendi la mappa più piccola per vedere tutto il comprensorio</a></td><td nowrap="yes" align="center"><div id="sponsor"></div></td></tr></table>';
	draggabile = "1"; 
	setSponsor();
}; 
function NormalSize() { 
	if ((imgWidth/winWidth) > (imgHeigth/winHeigth)) { 
		document.img_map.width = imgWidth;
	} else { 
		document.img_map.height = imgHeigth;
	}; 
	leftOffset = - ((imgWidth- winWidth)/2);  
	topOffset = - ((imgHeigth- winHeigth)/2); 
	document.getElementById('map_divi').style.left = leftOffset+'px'; 
	document.getElementById('map_divi').style.top = topOffset+'px'; 
	document.getElementById('cmd_map').innerHTML = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="tabletable"><tr><td width="100%" align="center">Attenzione: Puoi usare il mouse con il <i>drag & drop</i> per spostarti sulla mappa<br><a href="javascript:SmallSize()">Rendi la mappa più piccola per vedere tutto il comprensorio</a><br><a href="javascript:MediumSize()">Dimensione Intermedia</a></td><td nowrap="yes" align="center"><div id="sponsor"></div></td></tr></table>';
	draggabile = "1"; 
	setSponsor();
}; 
function SetStarPos(dragEvent) { 
	cursorStartX = dragEvent.offsetX; 
	cursorStartY = dragEvent.offsetY; 
}; 

function dragImage(dragEvent){ 
	if (draggabile == "1") { 
		posX = eval("document.getElementById('map_divi').offsetLeft");
		posY = eval("document.getElementById('map_divi').offsetTop"); 
		newXsize = dragEvent.offsetX; 
		newYsize = dragEvent.offsetY; 
		newXsize = newXsize + posX; 
		newYsize = newYsize + posY; 
		if ((newXsize - cursorStartX) > 0) newXsize = cursorStartX; 
		if ((newYsize - cursorStartY) > 0) newYsize = cursorStartY; 
		if ((newXsize - cursorStartX) <= (2*leftOffset)) newXsize = (2*leftOffset)+ cursorStartX; 
		if ((newYsize - cursorStartY) <= (2*topOffset)) newYsize = (2*topOffset)+ cursorStartY; 
		document.getElementById('map_divi').style.left = newXsize - cursorStartX; 
		document.getElementById('map_divi').style.top = newYsize  - cursorStartY; 
	};
	//setSponsor();
};

function drag(ereignis) {
  if (draggabile == "1") {
	  //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.
	  posx = document.all ? window.event.clientX : ereignis.pageX;
	  posy = document.all ? window.event.clientY : ereignis.pageY;
	  if(dragobjekt != null) {
	    if (posx < dragx) dragobjekt.style.left = (posx - dragx) + 'px';
	    if (posy < dragy) dragobjekt.style.top = (posy - dragy) + 'px';
	  }
	}
}

function dragstop() {
  //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
  dragobjekt=null;
  setSponsor();
}	

function dragstart(element) {
  if (draggabile == "1") { 
	  //Wird aufgerufen, wenn ein Objekt bewegt werden soll.
	  dragobjekt = element;
	  dragx = posx - dragobjekt.offsetLeft;
	  dragy = posy - dragobjekt.offsetTop;
	}
}

function draginit() {
	// Initialisierung der Überwachung der Events
	document.onmousemove = drag;
	document.onmouseup = dragstop;
}

function AdminImmaginiCaseInEvidenza() {
	for(i=0;i<5;i++){if (document.getElementById('casa'+i).height > 80) {var altezza=document.getElementById('casa'+i).height; var rapporto=Math.round(altezza/80); document.getElementById('casa'+i).height=80; document.getElementById('casa'+i).width=Math.round(100/rapporto)}}
}

function ShareThis(id) {
	var url;
	var dtitle;
	dtitle = escape(document.title);
	url = escape(document.location);
	wtitle = document.title.substring(0,document.title.indexOf('- Neve Italia.IT'));
	wtitle = escape(wtitle.replace(/\s+$/g,''));
	switch(id)
	{
		case "oknotizie":
		  url = "http://oknotizie.alice.it/post?url=" + url + "&title=" + dtitle;
		  break;  
		case "facebook":
		  url = "http://www.facebook.com/sharer.php?u=" + url;
		  break; 
		case "wikio":
		  url = "http://www.wikio.it/vote?domain=neveitalia.it&title=" + wtitle;
		  break;	
		case "delicious":
		  url = "http://del.icio.us/post?v=4&noui&jump=close&url=" + url + "&title=" + dtitle;
		  break;    
		case "digg":
		  url = "http://digg.com/submit?phase=2&url=" + url + "&title=" + dtitle;
		  break;
		case "technorati":
		  url = "http://technorati.com/faves?add=" + url;
		  break;
		case "yahoo":
		  url = "http://myweb.yahoo.com/myresults/bookmarklet?t=" + dtitle + "&u=" + url + "&ei=UTF";
		  break;
	}
	document.location = url;
}

function PngFix()
{
	if (typeof document.body.style.maxHeight == 'undefined') {
		var imgs = document.getElementsByTagName("img");
		for (i = 0; i < imgs.length; i++)
		{
			if (imgs[i].src.indexOf(".png") != -1)
			{
				imgs[i].parentNode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgs[i].src + "',sizingMethod='crop')";
				imgs[i].parentNode.style.display = "inline-block";
				imgs[i].style.visibility = "hidden";
			}
		}
	}
}

function createRequestObject()
{
	var request = false;
    try
    {
        // Mozilla/Safari
        if (window.XMLHttpRequest)
        {
            request = new XMLHttpRequest();
        }
        // IE
        else if (window.ActiveXObject)
        {
            request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    catch (e)
    {
        alert(e);
    }
    if(!request )
    {
        alert("Impossibile creare l'oggetto XHR.");
    }
    return request;
}

var http = false;
function tabDallaRete()
{
    if (http==false) {http = createRequestObject();} 
    http.abort()
    http.open('GET', '/cache/mod/SportNews/HomePage.php', true);
    http.onreadystatechange = homepageEnd;
    http.send(null);
}
function tabWebcam()
{
    if (http==false) {http = createRequestObject();} 
    http.abort()
    http.open('GET', '/cache/mod/Webcam/HomePage.php', true);
    http.onreadystatechange = homepageEnd;
    http.send(null);
}

function homepageEnd()
{
    if(http.readyState == 4)
    {
        var response = http.responseText;
        document.getElementById("tabCentrali").innerHTML = response;
    }
}

function tabCalendarioMaschile()
{
    if (http==false) {http = createRequestObject();} 
    http.abort()
    http.open('GET', '/cache/mod/HomeSpecialeSfondo/calendarioCdMmaschile.html', true);
    http.onreadystatechange = coppadelmondoEnd;
    http.send(null);
}
function tabCalendarioFemminile()
{
    if (http==false) {http = createRequestObject();} 
    http.abort()
    http.open('GET', '/cache/mod/HomeSpecialeSfondo/calendarioCdMfemminile.html', true);
    http.onreadystatechange = coppadelmondoEnd;
    http.send(null);
}
function coppadelmondoEnd()
{
    if(http.readyState == 4)
    {
        var response = http.responseText;
        document.getElementById("worldcuptablecontajax").innerHTML = response;
    }
}


if (document.all && !window.opera)
	attachEvent("onload", PngFix);

function storeCaret_post(textEl) {
        if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}


dateFuture = new Date(2010,1,13,3,00,00);

function readCookie(cookieName){
   var searchName = cookieName + "="
   var cookies = document.cookie
   var start = cookies.indexOf(cookieName)
   if (start == -1){ // cookie not found
     return ""
     }
   start += searchName.length //start of the cookie data
   var end = cookies.indexOf(";", start)
   if (end == -1){
     end = cookies.length
     }
   return cookies.substring(start, end)
}

function GetCount(){
	dateNow = new Date();									//grab current date
	amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
	delete dateNow;

	// time is already past
	if (document.getElementById('countbox')) {
		if(amount < 0){
			document.getElementById('countbox').innerHTML="Now!";
		}
		// date is still good
		else{
			days=0;hours=0;mins=0;secs=0;out="";
			amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
			days=Math.floor(amount/86400);//days
			amount=amount%86400;
			hours=Math.floor(amount/3600);//hours
			amount=amount%3600;
			mins=Math.floor(amount/60);//minutes
			amount=amount%60;
			secs=Math.floor(amount);//seconds
			
			var myLang = readCookie('lang');
			if (myLang == 'italian') {sDays = "g ";}
			else {sDays = "d ";};
			
			if(days != 0){out += days +sDays+((days!=1)?"":"")+", ";}
			if(days != 0 || hours != 0){out += hours +"h "+((hours!=1)?"":"")+", ";}
			if(days != 0 || hours != 0 || mins != 0){out += mins +"' "+((mins!=1)?"":"")+", ";}
			out += secs +"\" ";
			document.getElementById('countbox').innerHTML=out;
			setTimeout("GetCount()", 1000);
		}
	}
}

/*  2010  */

var menu=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

var menuregioni=function(){
	var t=15,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();

function initFB() {
FB.init({appId: '166243148283', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
  window.location.reload();
});

/*
FB.Event.subscribe('4142887b3446ce8c3649ed3baef1473c', function(response) {
  if (response.session) {
    // A user has logged in, and a new cookie has been saved
    window.location.reload();
  } else {
    // The user has logged out, and the cookie has been cleared
    window.location.reload();
  }
});
*/

}

function viewRegioni() {
  if (document.getElementById("menusotto").innerHTML != "pippo") {
    if (http==false) {http = createRequestObject();} 
    http.abort()
    http.open('GET', '/cache/header/menuregioni-italian.html', true);
    http.onreadystatechange = menuRegionale;
    http.send(null);
  }
}
function menuRegionale() {
  if(http.readyState == 4)
  {
      var response = http.responseText;
      document.getElementById("menusotto").innerHTML = response;
  }
}


/*
 * The facebook_onload statement is printed out in the PHP. If the user's logged in
 * status has changed since the last page load, then refresh the page to pick up
 * the change.
 *
 * This helps enforce the concept of "single sign on", so that if a user is signed into
 * Facebook when they visit your site, they will be automatically logged in -
 * without any need to click the login button.
 *
 * @param already_logged_into_facebook  reports whether the server thinks the user
 *                                      is logged in, based on their cookies
 *
 */
function facebook_onload(already_logged_into_facebook) {
  // user state is either: has a session, or does not.
  // if the state has changed, detect that and reload.
  FB.ensureInit(function() {
      FB.Facebook.get_sessionState().waitUntilReady(function(session) {
          var is_now_logged_into_facebook = session ? true : false;

          // if the new state is the same as the old (i.e., nothing changed)
          // then do nothing
          if (is_now_logged_into_facebook == already_logged_into_facebook) {
            return;
          }

          // otherwise, refresh to pick up the state change
          refresh_page();
        });
    });
}

/*
 * Our <fb:login-button> specifies this function in its onlogin attribute,
 * which is triggered after the user authenticates the app in the Connect
 * dialog and the Facebook session has been set in the cookies.
 */
function facebook_onlogin_ready() {
  // In this app, we redirect the user back to index.php. The server will read
  // the cookie and see that the user is logged in, and will deliver a new page
  // with content appropriate for a logged-in user.
  //
  // However, a more complex app could use this function to do AJAX calls
  // and/or in-place replacement of page contents to avoid a full page refresh.
  refresh_page();
}

/*
 * Do a page refresh after login state changes.
 * This is the easiest but not the only way to pick up changes.
 * If you have a small amount of Facebook-specific content on a large page,
 * then you could change it in Javascript without refresh.
 */
function refresh_page() {
  window.location.reload();
}

/*
 * Prompts the user to grant a permission to the application.
 */
function facebook_prompt_permission(permission) {
  FB.ensureInit(function() {
    FB.Connect.showPermissionDialog(permission);
  });
}
