/* JavaScript Document
Author: Fabio Butti
Email: butti.fabio@gmail.com
*/

var AW = screen.availWidth;
var dim = 1024;
var css = '<link type="text/css" rel="stylesheet" href="css/';
var logo = '<a href="index.php" title="Torna alla homepage"><img src="images/struct/header_';
var home_img_src = "images/content/home/home_immagini/";
var home_img_src_swf = "images/content/home/home_immagini/";

if (AW <= 800) {
	dim = "800";
} else {
	if (AW <= 1024) {
		dim = "1024";
	} else {
		dim = "1280";
	}
}

css = css + dim + '.css" />';
// Seleziono il logo corretto
logo = logo + dim
var oggi = new Date();
if (oggi.getMonth() != 11) { // Se siamo a dicembre scelgo il logo natalizio
	logo = logo + '.png" alt="RUGBY DALMINE" /></a>';
} else {
	logo = logo + '_xmas.png" alt="RUGBY DALMINE" /></a>';
}
home_img_src = home_img_src + dim + "/Home_immagini";
home_img_src_swf = home_img_src_swf + dim + "/Home_immagini.swf";

document.write(css);

function attaccaLogo() {
	document.write(logo);
}

/* Funzione per gestire il timer al nextmatch */

function countDown() {
	
	adesso = new Date(); /* data attuale */
	nm = new Date(target); /* data nextmatch */
	
	days = (nm - adesso) / 1000 / 60 / 60 / 24;
	daysRound = Math.floor(days);
	
	hours = (nm - adesso) / 1000 / 60 / 60 - (24 * daysRound);
	hoursRound = Math.floor(hours);

	minutes = (nm - adesso) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
	minutesRound = Math.floor(minutes);

	seconds = (nm - adesso) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
	secondsRound = Math.round(seconds);
	
	if (hoursRound == 24) {
		hoursRound = 0;
		daysRound += 1;
	}
	
	if (minutesRound == 60) {
		minutesRound = 0;
		hoursRound += 1;
	}
	
	if (secondsRound == 60) {
		secondsRound = 0;
		minutesRound += 1;
	}
	
	if ((nm - adesso) > 0) {
		document.getElementById('c_gl').innerHTML  = daysRound;
		document.getElementById('c_ol').innerHTML  = (hoursRound < 10) ? ("0" + hoursRound) : hoursRound;
		document.getElementById('c_ml').innerHTML  = (minutesRound < 10) ? ("0" + minutesRound) : minutesRound;
		document.getElementById('c_sl').innerHTML  = (secondsRound < 10) ? ("0" + secondsRound) : secondsRound;
	
		window.setTimeout("countDown();", 1000);
	}

}

// Funzione per risolvere rollover giocatori su IE: VACCA MERDA!!!
function cambiaAlpha(img, flag) {
	if (flag==0) img.filters.alpha.opacity=100
		else img.filters.alpha.opacity=0
}

// Funzione per cambiare l'ordinamento dei giocatori
function cambiaOrdinamento(layout) {
	var ord = document.getElementById('ord');
	var oOpt = ord.options.selectedIndex;
	var ordScelto = ord.options[oOpt].value;
	
	var aod = document.getElementById('aod');
	var aOpt = aod.options.selectedIndex;
	var aodScelto = aod.options[aOpt].value;
	
	var pag = 'squadre.php?layout=' + layout + '&section=Giocatori&order=' + ordScelto + aodScelto;
	window.open(pag,'_self');
}

// Funzione per regolare il numero di latest news in home page
function regolaLatestNews(a,b,c) {
	var ln = document.getElementById('latest_news');
	if (dim == "800") {
		for (i=10;i>a;i--) {
			ln.removeChild(ln.lastChild);
		}
	} else if (dim == "1024") {
		for (i=10;i>b;i--) {
			ln.removeChild(ln.lastChild);
		}
	} else if (dim == "1280") {
		for (i=10;i>c;i--) {
			ln.removeChild(ln.lastChild);
		}
	}
}

// La funzione ajaxupdatediv tiene presente delle differenze tra IE e gli altri browsers
function ajaxupdatediv(url, containerid){
	var element = document.getElementById(containerid);
	var pagina = false;
	// richiesta per Mozilla, Safari etc
	if (window.XMLHttpRequest){
		pagina = new XMLHttpRequest();
	}
	else if (window.ActiveXObject){ // richiesta per IE
		try {
		pagina = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch (e){
		try{
		pagina = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch (e){}
		}
	}
	else
		return false;
	pagina.onreadystatechange = function(){
		loadpage(pagina, containerid, element);
	}
	pagina.open('GET', url, true);
	pagina.send(null);
}

function loadpage(pagina, containerid, element){
	if (pagina.readyState == 4 && (pagina.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(containerid).innerHTML = pagina.responseText;
}
