/* AJAX FUNCTIONS */

// JavaScript Document
function gEBI(element) {
		return document.getElementById(element);
	}
	function clearInputText(element){
		gEBI(element).value='';	
	}
	function getValue(element){
		return gEBI(element).value;	
	}
	function showElement(element)
	{
		var e=gEBI(element);
		e.style.visibility='visible';
		e.style.display='block';	
	}	
	function hideElement(element)
	{
		var e=gEBI(element);
		e.style.visibility='hidden';
		e.style.display='none';	
	}
	function toggleElement(element){
		var e=gEBI(element);
		if (e.style.visibility=='hidden'){
			showElement(e);
		}else{
			hideElement(e);
		}	
	}
	
	function showWaitMessage(div){	
		gEBI(div).style.background="url(images/stili/spinner.gif) center no-repeat";
	}
	function hideWaitMessage(div){
		gEBI(div).style.background="none";
	}
	
	function hideHTML(element){
		gEBI(element).innerHTML='';
	}



/* OTHER FUNCTIONS */
function VisualizzaNews(idnews)
{ 
   win = window.open("news.php?news="+idnews,"win",'width=1000,height=600,left=200,top=100,resizable=no,scrollbars=yes,toolbar=no,status=yes');
   win.focus();
}

function ApriGiocatore(idgiocatore)
{ 
   win = window.open("caricaplayer.php?s="+idgiocatore,"win",'width=400,height=620,left=200,top=100,resizable=no,scrollbars=yes,toolbar=no,status=yes');
   win.focus();

}

function ApriRegistrazione() {

	document.location.href = "registrazione.php";
}


function CaricaProfilo() {

	document.location.href = "profilo.php";
}


function Logout() {

	document.location.href = "logout.php";
}

function ApriArticolo(idart)
{
				// va bene a qualsiasi risoluzione
  // alert("IDNEWS:  " + idnews);
   var w = screen.width;
   var h = screen.height;
   var l = Math.floor((screen.width-w)/2);		// intero numerico inferiore
   var t = Math.floor((screen.height-h)/2);
   win = window.open("articolo.php?art="+idart,"win","status=no, menubar=no, toolbar=no, scrollbars=yes," +"width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
   win.focus();
} 

function VisualizzaSocieta(idsoc)
	{
	 indirizzo = "societacalcio.php?id=" + idsoc;
	 setTimeout("location.href='"+indirizzo+"' " ,0000);
	}

function ApriPannello() 
{
	if(document.getElementById('divanimato').style.display == 'none')
		{ 
		 document.getElementById('divanimato').style.display = 'block'; 
		}
	else
		{ 
		 document.getElementById('divanimato').style.display = 'none'; 
		}
}

function InserisciImmagine(valore)
{	
	var input = document.formchat.txtmessaggio;
	input.value = input.value + " :" + valore + " ";
	input.focus();
	TextCounter(document.formchat.txtmessaggio,document.formchat.percentuale,300);
}
	
function InserisciTag(valore)
{	
	var input = document.formnews.testo;
	input.value = input.value + "<br />" +valore + " ";
	input.focus();
}
		
	
function ApriPopupMessaggi() 
{
	      
	win = window.open("chatmessaggi.php","win",'width=900,height=700,left=200,top=100,resizable=no,scrollbars=yes,toolbar=no,status=yes');
   	win.focus();
	   
}
	
		// funzione per la percentuale del testo della chat
function TextCounter(field,contatore,maxlimit)	// field = campo dei messaggi
 {												// contatore = campo con la percentuale 
												// maxlimit = caratteri massimi = 300
	var fieldWidth = parseInt(field.offsetWidth);
	var charcnt = field.value.length;	// lunghezza attuale del testo
	if (charcnt > maxlimit)	// se ho superato il limite
	  { 
		field.value = field.value.substring(0, maxlimit); 	// non scrivo altro
	  } 
	else 
	  {			// progress bar percentuale
		var percentage = parseInt(100 - (( maxlimit - charcnt) * 100)/ maxlimit) ;
		contatore.style.width = 70 + parseInt((fieldWidth*percentage)/(150))+"px";
		contatore.value= percentage + "%";
	  }
}


function VisualizzaCronaca(idpar)
{
   win = window.open("partita.php?partita="+idpar,"win",'width=760,height=600,left=200,top=100,resizable=no,scrollbars=yes,toolbar=no,status=yes');
   win.focus();
}

function ApriCampo(idcampo)
	{
					// va bene a qualsiasi risoluzione
	  // alert("IDNEWS:  " + idnews);
	   var w = screen.width;
	   var h = screen.height;
	   var l = Math.floor((screen.width-w)/2);		// intero numerico inferiore
	   var t = Math.floor((screen.height-h)/2);
	   win = window.open("campo.php?campo="+idcampo,"win","status=no, menubar=no, toolbar=no, scrollbars=yes," +"width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
	   win.focus();

} 

function CaricaSquadre(selObj) 
{

	indirizzo = "reinserimentogiocatore.php?stag=" + selObj.options[selObj.selectedIndex].value
	setTimeout("location.href='"+indirizzo+"' " ,0000);
			// metto nel campo hidden il valore della stagione
	document.formgiocatore.h_stagione.value = selObj.options[selObj.selectedIndex].value;
}

function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
  		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  		if (restore) selObj.selectedIndex=0;
}

function apricronaca(idpar,stagione)
{
			// va bene a qualsiasi risoluzione
   //alert(" " + stagione);
   var w = 1000;
   var h = 800;
   var l = Math.floor((screen.width-w)/2);		// intero numerico inferiore
   var t = Math.floor((screen.height-h)/2);
   win = window.open("cronaca.php?partita="+idpar+"&stagione="+stagione,"win","scrollbars=yes," +"width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
   win.focus();
}

function AggiornaFoto() 
{
	percorso = new String(document.formnews.file.value);  // percorso dell'immagine
	vetparole = percorso.split("\\"); // suddivido tramite \ o \
	dim = vetparole.length; // dimensione split
	document.formnews.nascosto.value = "images/news/" + vetparole[dim-1];  // mi serve quando recupero l'informazione
	document.images[0].src = "images/news/" + vetparole[dim-1];   // prendo l'ultimo elemento che è il nome del file	
}

function AggiornaArticolo() 
{

	percorso = new String(document.formnews.file.value);  // percorso dell'immagine
	vetparole = percorso.split("\\"); // suddivido tramite \ o \
	dim = vetparole.length; // dimensione split
	document.formnews.nascosto.value = "images/articoli/" + vetparole[dim-1];  // mi serve quando recupero l'informazione
	document.images[0].src = "images/articoli/" + vetparole[dim-1];   // prendo l'ultimo elemento che è il nome del file	
	//alert(document.formnews.nascosto.value);
}

function AttivaSondaggio(selObj) 
{	
	indirizzo = "attivasondaggio.php?id=" + selObj.options[selObj.selectedIndex].value
	setTimeout("location.href='"+indirizzo+"' " ,0000);	
}

function CaricaTabella(selObj) 
{
	indirizzo = "dati.php?tab=" + selObj.options[selObj.selectedIndex].value
	setTimeout("location.href='"+indirizzo+"' " ,0000);
	
}

function MettiInHidden()
{
	  var delim = " - ";
	  var selObj = document.formcronaca.marcatori;
	  var hideObj = document.formcronaca.marcatorinascosto;
	  hideObj.value = '';
	  for (var i = 0; i < selObj.options.length; i++) 
		{
			hideObj.value = hideObj.value ==
		  '' ? selObj.options[i].value : hideObj.value + delim + selObj.options[i].value;
		}
}	
		
function InserisciMarcatore(valore, testo, goaltotali) 	// valore e testo dell'opzione 
{		// inserisco solo se il numero totale di goal è < di quelli inseriti
	if (document.formcronaca.marcatori.length < goaltotali)
		{
		var k = document.formcronaca.marcatori.length;  // lunghezza iniziale
		document.formcronaca.marcatori.options[k] = new Option(testo, valore);  // nuova opzione		
		document.formcronaca.marcatori.length = k + 1;  // uno piu lungo
		}
	else
		alert ("Se vuoi inserire un altro marcatore, devi prima toglierne uno.\nHai già inserito " + goaltotali + " marcatori.");
}
	
			// premo delete e cancello il giocatore
function RimuoviMarcatore(evento)	// indice dell'elemento da rimuovere
{
	if (evento.keyCode == 46)		// se premo delete
	{
		nome = document.formcronaca.marcatori;
		for(i = nome.options.length-1; i >= 0; i--)
			 if(nome.options[i].selected)
					nome.options[i] = null;
	}	

}
function ApriArticolo(idart)
{
				// va bene a qualsiasi risoluzione
  // alert("IDNEWS:  " + idnews);
   var w = screen.width;
   var h = screen.height;
   var l = Math.floor((screen.width-w)/2);		// intero numerico inferiore
   var t = Math.floor((screen.height-h)/2);
   win = window.open("articolo.php?art="+idart,"win","status=no, menubar=no, toolbar=no, scrollbars=yes," +"width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
   win.focus();
} 
	