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

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 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(alteza/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 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;
}
}

function tabSkiTest() {
if (http==false) {http = createRequestObject();} 
http.abort()
http.open('GET', '/cache/mod/guida_prodotti/HomePage.php', true);
http.onreadystatechange = AperturaCentEnd;
http.send(null);
}
function tabBecomeTester(){
if (http==false) {http = createRequestObject();} 
http.abort()
http.open('GET', '/cache/mod/guida_prodotti/BecomeTester.php', true);
http.onreadystatechange = AperturaCentEnd;
http.send(null);
}
function AperturaCentEnd(){
if(http.readyState == 4)
{
	var response = http.responseText;
	document.getElementById("tabAperturaCentrale").innerHTML = response;
}
}

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

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(){
dateFuture = new Date(2010,1,13,3,00,00);
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.login', function(response) {
  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;
}
}
function facebook_onload(already_logged_into_facebook) {
FB.ensureInit(function() {
  FB.Facebook.get_sessionState().waitUntilReady(function(session) {
	  var is_now_logged_into_facebook = session ? true : false;
	  if (is_now_logged_into_facebook == already_logged_into_facebook) {
		return;
	  }
	  refresh_page();
	});
});
}
function facebook_onlogin_ready() {
refresh_page();
}
function refresh_page() {
window.location.reload();
}
function justexpand(myid) {
document.getElementById('tc'+myid).style.display = 'inline';
document.getElementById('c'+myid).innerHTML = '<a onClick="javascript:justcollapse(\''+myid+'\');"><b> << Nascondi Testo</b></a>';
}
function justcollapse(myid) {
document.getElementById('tc'+myid).style.display = 'none';
document.getElementById('c'+myid).innerHTML = '<a onClick="javascript:justexpand(\''+myid+'\');"><b> >> Visualizza Testo</b></a>';
}
function loadSkiHolidayDate(acId,prId,dtId) {
var urlbase='http://www.skihorizon.com/partner/appaf/';
var i=0;
while ((skihorizon[i][0]!=acId)||(skihorizon[i][1]!=prId)||(skihorizon[i][2]!=dtId)) i++;

var duratavacanza = skihorizon[i][3];
var DTprice = skihorizon[i][4];
var DTpriceDiscounted = skihorizon[i][5];
var linkvacanza = urlbase+skihorizon[i][6];
document.getElementById('lp'+acId+prId).href = linkvacanza;
document.getElementById('lv1'+acId+prId).href = linkvacanza;
document.getElementById('lv2'+acId+prId).href = linkvacanza;
document.getElementById('dv'+acId+prId).innerHTML = duratavacanza;
document.getElementById('pv'+acId+prId).innerHTML = DTprice;
document.getElementById('pvi'+acId+prId).innerHTML = DTpriceDiscounted;
}

var idHoliday;
function loadSkiHolidayDateComplex(acId,prId,dtId,currLang) {
idHoliday = 'aj'+acId+prId;
if (http==false) {http = createRequestObject();} 
http.abort()
http.open('GET', '/cache/mod/vacanze-offerte/'+acId+prId+dtId+'-'+currLang+'.php', true);
http.onreadystatechange = changeHolidayDate;
http.send(null);
}
function changeHolidayDate() {
if(http.readyState == 4) {
	var response = http.responseText;
	document.getElementById(idHoliday).innerHTML = response;
}
}
var idGara;
function vediGara(myid) {
idGara = myid;
if (http==false) {http = createRequestObject();} 
http.abort()
http.open('GET', '/cache/mod/Content/coppadelmondo-'+myid, true);
http.onreadystatechange = displayGara;
http.send(null);
}
function displayGara() {
if(http.readyState == 4)
{
	var response = http.responseText;
	document.getElementById(idGara).innerHTML = response;
}
}
function expandtecnologie(type) {
if(type == 1) {
	document.getElementById('tecnologie').style.display='inline';
	document.getElementById('tecnologiedescbuttonleggi').style.display='none';
	document.getElementById('tecnologiedescbuttonchiudi').style.display='inline';
} else if(type == 2) {
	document.getElementById('tecnologie').style.display='none';
	document.getElementById('tecnologiedescbuttonleggi').style.display='inline';
	document.getElementById('tecnologiedescbuttonchiudi').style.display='none';
}
}
function setLink(url,txtlink,mode) {
//mode 0 plain, 1 target blank, 2 nofollow, 3 nofollow target blank
if (mode>1) var rel=' rel="nofollow"';
else var rel='';
if ((mode==1) || (mode==3)) var target=' target="_blank"';
else var target='';
document.write('<a href="'+url+'" '+rel+target+'>'+txtlink+'</a>');
}

function showPicOverlay(){
	if (document.getElementById('zoom_icon')) document.getElementById('zoom_icon').style.display='block';
	if (document.getElementById('prev_icon')) document.getElementById('prev_icon').style.display='block';
	if (document.getElementById('next_icon')) document.getElementById('next_icon').style.display='block';
}
function hidePicOverlay(){
	if (document.getElementById('zoom_icon')) document.getElementById('zoom_icon').style.display='none';
	if (document.getElementById('prev_icon')) document.getElementById('prev_icon').style.display='none';
	if (document.getElementById('next_icon')) document.getElementById('next_icon').style.display='none';
}
