var rootdomain="http://"+window.location.hostname;
rootdomain2=rootdomain=="http://localhost" || rootdomain=="http://192.168.0.40"?rootdomain+'/pol':rootdomain;
//alert(rootdomain2);
function LoadPage()
{
	l = location.href;
	pagina=l.substr(l.lastIndexOf("/")+1).split(/[?#]/)[0];
	hu = window.location.search.substring(1);
	
	if(pagina=="DaGiocare.php")
		CheckVoto();
	if(pagina=="Competizioni.php")		
		if (hu.indexOf("Tipo=R")>=0)
			ajaxpage1('Risultati.php','contentarea','POST');
		else if (hu.indexOf("Tipo=U")>=0)
			ajaxpage1('Iscritti.php','contentarea','POST');
		else
			ajaxpage1('Classifica.php','contentarea','POST');
		script="Classifica.php";
	if(pagina=="Leghe.php")
		ajaxpage1('VisualizzaLeghe.php?'+hu,'contentarea','GET');
	if(pagina=="Profilo.php")
	{
		 if (hu.indexOf("Tipo=SP")>=0)
			ajaxpage1('StoriaPartite.php?'+hu,'contentarea','GET');
		else
			ajaxpage1('Feedback.php?'+hu,'contentarea','GET');
	}
	if(pagina=="Scu.php")
		ajaxpage1('ScuPlayer.php?'+hu,'contentarea','GET');
	if(pagina=="Totali.php")
	{
		if (hu.indexOf("Tipo=T")>=0)
			ajaxpage1('CompGiocate.php?'+hu,'contentarea','GET');
		else if (hu.indexOf("Tipo=P")>=0)
			ajaxpage1('Partite.php?'+hu,'contentarea','GET');
		else if (hu.indexOf("Tipo=UC")>=0)
			ajaxpage1('GraficoAccessi.php?'+hu,'contentarea','GET');
		else if (hu.indexOf("Tipo=UI")>=0)
			ajaxpage1('Iscritti.php?'+hu,'contentarea','GET');
		else if (hu.indexOf("Tipo=FB")>=0)
			ajaxpage1('TotFeedback.php?'+hu,'contentarea','GET');
		else
			ajaxpage1('CompGiocate.php?'+hu,'contentarea','GET');
	}
}
function VaiRisPop(idcalendario,par)
{
    window.open("../AdminLega/VisualizzaRisultato.php?ID="+idcalendario,"PromoWindow","toolbar=no,menubar=no,width=600,height=300,scrollbars=yes")
}
function CheckPassword()
{	
	User=document.forms["Logon"].elements["User"].value;	
	User=User.toLowerCase();
	Pwd=document.forms["Logon"].elements["Password"].value;	
	Pwd=User.toLowerCase()
	if ( User!="" && Pwd!="" )
		ajaxpageno(rootdomain2+'/check.php','contentarea','POST');
	else
		alert('Digitare il nome utente e password !!.');
}
function SendMail()
{
	if ( document.forms["Logon"].elements["User"].value!="")
		document.forms["Logon"].submit();
	else
		alert('Digitare il nome utente !!.');
}
function ajaxpageno(url, containerid,tipo)
{
	if(tipo=="POST")
	{
		document.forms[0].action=url;
		document.forms[0].submit();
	}
	else
		top.location.href = url;
		
}
function ReloadUrl(url)
{
//	alert(document.forms['utenti'].elements['fk_leghe'].value);
	document.forms[0].target="";
	document.forms[0].action=url;	
	document.forms[0].submit();
}
function ajaxpage(url, containerid,tipo)
{
	//alert(tipo);
	//$('test').request();
	/*
	$('test').request({
		onComplete: function(){ alert('Form data saved!') }
	})
	
	var form=$('test');
	form.getInputs();
	*/
	new Ajax.Updater(containerid, url, {
  	method: tipo,
	onLoading: function(transport){updatepage();},
	onComplete: function(transport){document.getElementById("loading").style.visibility="hidden";}
  	});	
}
function updatepage(){
	document.getElementById("loading").style.visibility="visible";
    document.getElementById("loading").innerHTML = "<td  style='height:10px;width:960px' align='center'><img src='"+rootdomain2+"/images/ajax-loader1.gif'><td>";
}
function ReloadLang(id)
{    
    url=rootdomain2+"/index.php?langid="+id;  
    location.replace(url);   
}
function checkHome()
{
	ajaxpage1(rootdomain2+'/home.php','contentarea','GET');
}
/***********************************************
* Dynamic Ajax Content- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage1(url, containerid,tipo){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open(tipo, url+bustcacheparameter, true)
params=null;
//alert(tipo);
if(tipo=='POST')
{
	params="";
	//alert(document.forms[0].elements.length);
	for(i=0; i<document.forms[0].elements.length; i++)
	{
		//alert(document.forms[0].elements[i].name);
		//alert(document.forms[0].elements[i].value);
		params=params+document.forms[0].elements[i].name+"="+document.forms[0].elements[i].value+"&";
	}
	//xabe
	//alert(params);
	//if(i!=0)
	//{
		page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		page_request.setRequestHeader("Content-length", params.length);
		page_request.setRequestHeader("Connection", "close");
	//}
}
page_request.send(params)
}
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{
//t contiene la risposta
var t = page_request.responseText;
//execJS esegue javascript contenuto in t e restituisce
//t senza javascript
t = execJS(t);
//finalmente metto t 'pulito' dento il div
//t="<form>"+t+"</form>";
document.getElementById(containerid).innerHTML = t;
//alert(t);
document.getElementById("loading").style.visibility="hidden";

//document.getElementById('contentarea1').style.display = "block";
//document.getElementById('contentarea1').innerHTML = t;
//alert(document.getElementById('contentarea1').value);
//document.getElementById(containerid).innerHTML=page_request.responseText
}
else
// In attesa della risposta del form visualizzo il msg di attesa
updatepage();
}

//-----------------------------------------------------
//valuta il codice javascript e restituisce la stringa
//senza codice
//-----------------------------------------------------
function execJS(t)
{
    var p1 = 0, p2 = 0, p3 = 0, p4 = 0;
    p1 = t.indexOf("<" + "script", 0);
    if(p1 == -1) return t;
    
    p2 = t.indexOf(">", p1 + 7) + 1;
    p3 = t.indexOf("<" + "/script>", p2);
    p4 = p3 + 9;
    
    var c = t.substring(p2, p3);
    var s = document.createElement("script");
    s.type = "text/javascript";
    s.text = c;
    document.getElementsByTagName("head")[0].appendChild(s);
    
    t = t.substring(0, p1) + t.substr(p4);
    return t;

}
function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
function VaiScuAdm(tipo,obj)
{
	if ((typeof(obj)!="undefined")&&(typeof(obj.value)!="undefined"))
		document.forms[0].elements[obj.name].value=obj.value;
	ajaxpage1(tipo,'contentarea','POST');
}
function ChangeColorA(obj)
{
	obj.style.backgroundColor="#0033FF"	 
}
function ChangeColorB(obj)
{
    obj.style.backgroundColor="#00379b";
}
function OpenWinSquadra(Record)
{
    window.open("../AdminClan/GestioneClan.php?Tipo=S&Par=V&IDClan="+Record,"PromoWindow","toolbar=no,menubar=no,width=600,height=400,scrollbars=yes")
}
function ReloadPage(tipo,mode,obj)
{
	//alert("dato:"+obj.name);
	//alert("valore:"+obj.value);	
	if ((typeof(document.forms[0].elements['OPE'])!="undefined")&&(typeof(document.forms[0].elements['OPE'].value)!="undefined"))
		document.forms[0].elements['OPE'].value="";	
	if ((typeof(obj)!="undefined")&&(typeof(obj.value)!="undefined"))
		document.forms[0].elements[obj.name].value=obj.value;	
	//alert("valore form:"+document.forms[0].elements[obj.name].value);	
	if (tipo.indexOf("?")<0)
		tipo=tipo+"?";
	ajaxpage1(tipo,'contentarea',mode);
}
function ReloadPageOpe(tipo,ope,obj,id,obj_def)
{
	/*
	alert("dato:"+obj.name);
	alert("valore:"+obj.value);
	alert("dat_def:"+obj_def);
	alert("id:"+id);
	alert("tipo:"+tipo);
	*/
	if ((typeof(document.forms[0].elements['OPE'])!="undefined")&&(typeof(document.forms[0].elements['OPE'].value)!="undefined"))
		document.forms[0].elements['OPE'].value=ope;
	if (tipo.indexOf("?")<0)
		tipo=tipo+"?";
	if ((typeof(obj)!="undefined")&&(typeof(obj.value)!="undefined"))
		document.forms[0].elements[obj.name].value=id;
	if ((typeof(obj_def)!="undefined"))
		document.forms[0].elements[obj_def].value=id;
	ajaxpage1(tipo,'contentarea','POST');
}
function Reload(tipo)
{
	//Storia partite
	if(tipo==1)
	{
		tipo="StoriaPartite.php";
		ajaxpage1(tipo,'contentarea','POST');
	}
	//Tessera
	if(tipo==2)
	{
		document.forms[0].target="elaborazione";
		parent.frames['centro'].location.href="tessera.php?ID=<?=$UtenteRequest?>";
		//document.forms[0].submit();
	}
	//Feedback
	if(tipo==3)
	{
		tipo="Feedback.php";
		ajaxpage1(tipo,'contentarea','POST');
	}
	//Gallery
	if(tipo==4)
	{
		tipo="Gallery.php";
		ajaxpage1(tipo,'contentarea','POST');
	}
	//Dati personali
	if(tipo==5)
	{
		document.forms[0].target="elaborazione";
		parent.frames['centro'].location.href="NuovoUtente.php?Tipo=<?=$_GET['Tipo']?>&ID=<?=$UtenteRequest?>";
		//document.forms[0].submit();
	}
	//Grafici
	if(tipo==6)
	{
		document.forms[0].elements['TipoGrafico'].value=1;
		tipo="GraficoUtente.php";
		ajaxpage1(tipo,'contentarea','POST');
	}
	//Gestione squadra
	if(tipo==7)
	{
		//document.forms[0].submit();
		tipo="Clan.php";
		if ((typeof(document.forms[0].elements['OPE'])!="undefined")&&(typeof(document.forms[0].elements['OPE'].value)!="undefined"))
		document.forms[0].elements['OPE'].value="";
		if ((typeof(document.forms[0].elements['id_clan'])!="undefined")&&(typeof(document.forms[0].elements['id_clan'].value)!="undefined"))
		document.forms[0].elements['id_clan'].value="";
		if ((typeof(document.forms[0].elements['id_utenticlan'])!="undefined")&&(typeof(document.forms[0].elements['id_utenticlan'].value)!="undefined"))
		document.forms[0].elements['id_utenticlan'].value="";
		if ((typeof(document.forms[0].elements['nome'])!="undefined")&&(typeof(document.forms[0].elements['nome'].value)!="undefined"))
		document.forms[0].elements['nome'].value="";
		ajaxpage1(tipo,'contentarea','POST');
	}
	//Livelli
	if(tipo==8)
	{
		tipo="StatiPagamenti.php";
		document.forms[0].elements['OPE'].value="";
		ajaxpage1(tipo,'contentarea','POST');
	}
	//Generali
	if(tipo==9)
	{
		document.forms[0].target="elaborazione";
		parent.frames['centro'].location.href="../Report/Report.php?Tipo=TG&ID=<?=$UtenteRequest?>";
		//document.forms[0].submit();
	}
	//Amici
	if(tipo==10)
	{
		tipo="Amici.php";
		ajaxpage1(tipo,'contentarea','POST');
	}	
}
function VaiInfoIp(idutente)
{
    window.open("../Report/Report.php?Tipo=IP&ID="+idutente,"PromoWindow","toolbar=no,menubar=no,width=800,height=600,scrollbars=yes")
}
function ContaCaratteri()
{
    document.forms[0].conta.value = document.forms[0].alert.value.length;
    var massimo = 255;
    if (document.forms[0].alert.value.length > massimo)
    {
        document.forms[0].alert.value = document.forms[0].alert.value.substr(0, massimo);
        document.forms[0].conta.value = massimo;
        alert("Massimo " + massimo + " caratteri!");
    }
}
function checkform()
{
    document.forms[0].target="elaborazione";
    document.forms[0].submit();    
}
function ApriIscritti(idlega)
{
	window.open("../AdminLega/Competizioni.php?Tipo=U&ID="+idlega,"PromoWindow","toolbar=no,menubar=no,width=800,height=600,scrollbars=yes")
}
function GotoPageScript(script,Start)
{
	//document.forms[0].action="<?=$SCRIPT_NAME?>?Start="+Start+"&Tipo=<?=$_GET['Tipo']?>";
	//document.forms[0].submit();
	tipo=script+"?Start="+Start+"&Tipo=P";
	document.forms[0].elements["Start"].value=Start;
	//alert(document.forms[0].elements["Start"].value);
	ajaxpage1(tipo,'contentarea','POST');	
}