function gestione_giocatore_soccer(azione, posizione, squadra, ruolo){
  var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
      xScroll = document.body.scrollWidth;
      yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
  }
	document.getElementById('sfondo').style.height=yScroll;
	document.getElementById('sfondo').style.width=xScroll;
	document.getElementById('content').style.width=xScroll/2;
	document.getElementById('content').style.left=(xScroll-(xScroll/2))/2;

	if(squadra!=''){document.getElementById('content').style.display='none';}

	if(!(Ajax.Request)){
		document.write('<script language="javascript" type="text/javascript" src="cms/js/prototype.js"></script><script language="javascript" type="text/javascript" src="cms/js/scriptaculous.js"></script>');
	}

	if(azione=='compreavendita'){
	  var opt = {
			onComplete: result,
			method: 'post',
			postBody: 'posizione='+posizione+'&&squadra='+squadra+'&&ruolo='+ruolo
		}
		new Ajax.Request('class_torneo_ajax.php?action=compravendita', opt);
	}
	else if(azione=='sostituzione'){
	  var opt = {
			onComplete: result,
			method: 'post',
			postBody: 'posizione='+posizione+'&&ruolo='+ruolo
		}
		new Ajax.Request('class_torneo_ajax.php?action=sostituzione', opt);
	}
	document.getElementById('sfondo').style.display='inline';
}

function gestione_giocatore(azione, posizione, squadra){
  var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
      xScroll = document.body.scrollWidth;
      yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
      xScroll = document.body.scrollWidth;
      yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
      xScroll = document.body.offsetWidth;
      yScroll = document.body.offsetHeight;
  }
	document.getElementById('sfondo').style.height=yScroll;
	document.getElementById('sfondo').style.width=xScroll;
	document.getElementById('content').style.width=xScroll/2;
	document.getElementById('content').style.left=(xScroll-(xScroll/2))/2;

	if(squadra!=''){document.getElementById('content').style.display='none';}

	if(!(Ajax.Request)){
		document.write('<script language="javascript" type="text/javascript" src="cms/js/prototype.js"></script><script language="javascript" type="text/javascript" src="cms/js/scriptaculous.js"></script>');
	}

	if(azione=='compreavendita'){
	  var opt = {
			onComplete: result,
			method: 'post',
			postBody: 'posizione='+posizione+'&&squadra='+squadra
		}
		new Ajax.Request('class_torneo_ajax.php?action=compravendita', opt);
	}
	else if(azione=='sostituzione'){
	  var opt = {
			onComplete: result,
			method: 'post',
			postBody: 'posizione='+posizione
		}
		new Ajax.Request('class_torneo_ajax.php?action=sostituzione', opt);
	}
	document.getElementById('sfondo').style.display='inline';
}

function result(originalRequest){
	var risposta = originalRequest.responseText;
	document.getElementById('content').innerHTML=risposta;
	document.getElementById('content').style.display='inline';
	document.getElementById('top').focus();
}

function nascondi(){
	document.getElementById('sfondo').style.display='none';
	document.getElementById('content').style.display='none';
}

function acquisto(giocatore_new, posizione){
	nascondi()
	var opt = {
		onComplete: refresh_giocatore,
		method: 'post',
		postBody: 'posizione='+posizione+'&&giocatore_new='+giocatore_new
	}
	new Ajax.Request('class_torneo_ajax.php?action=acquista_giocatore', opt);
}

function sostituisci(giocatore_riserva, posizione_riserva, giocatore_titolare, posizione_titolare){
	nascondi();
	var opt = {
		onComplete: refresh_giocatore,
		method: 'post',
		postBody: 'giocatore_riserva='+giocatore_riserva+'&&posizione_riserva='+posizione_riserva+'&&giocatore_titolare='+giocatore_titolare+'&&posizione_titolare='+posizione_titolare
	}
	new Ajax.Request('class_torneo_ajax.php?action=sostituisci_giocatore', opt);
}

function refresh_giocatore(originalRequest){
	var risposta = originalRequest.responseText;
	if(risposta == ''){history.go(0);}
	else{
		document.getElementById('content').innerHTML=risposta;	
		document.getElementById('content').style.display='inline';
		document.getElementById('sfondo').style.display='inline';	
	}
}
