/* ajax e finestre */

function getHTTPObjectOLD()
{
	if (window.ActiveXObject) 
	return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) 
	return new XMLHttpRequest();
	else
	{
	alert("il tuo browser non supporta AJAX!");
	return null;
	}
}

function getHTTPObject()
{
	var req = false;   
    if (typeof XMLHttpRequest != "undefined")   
        req = new XMLHttpRequest();   
    if (!req && typeof ActiveXObject != "undefined") {   
        try {   
            req=new ActiveXObject("Msxml2.XMLHTTP");   
        } catch (e1) {   
            try {   
                req=new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e2) {   
                try {   
                    req=new ActiveXObject("Msxml2.XMLHTTP.4.0");   
                } catch (e3) {   
                    req=null;   
                }   
            }   
        }   
    }   
  
    if(!req && window.createRequest)   
        req = window.createRequest();
    
    if (!req) alert("Il browser non supporta AJAX");   
  
    return req;   
}

function ShowWin(wn,par)
{
	document.getElementById("back").style.display = "block";
	document.getElementById("window").innerHTML = "ATTENDERE...";
	
	ajaxwin = null;
	
	ajaxwin=new getHTTPObject();
	
	ajaxwin.open("get","http://www.ilcambiamento.it/rpc/getwin.php?w="+wn+"&id="+par,true);
	
	ajaxwin.send(null);
	
	ajaxwin.onreadystatechange = function()
	{
		if(ajaxwin.readyState == 4)
		{
			risposta = ajaxwin.responseText;
			if (risposta!="") document.getElementById("window").innerHTML = risposta;
			else
			{
				document.getElementById("window").innerHTML = "errore: risposta vuota";
				alert(ajaxwin.status);
			}
		}
	}
}

function CloseWin()
{
	document.getElementById("window").innerHTML = "";
	document.getElementById("back").style.display = "none";
}

function SendComment()
{
	artid=document.getElementById("cartid").value;
	nome=document.getElementById("cnome").value;
	commento=document.getElementById("ccommento").value;
	mail=document.getElementById("cmail").value;
	
	document.getElementById("window").innerHTML = "ATTENDERE...<br /><br />Invio commento in corso...";
	
	ajaxcomment=null;
	
	ajaxcomment=new getHTTPObject();
		
	ajaxcomment.open("post","http://www.ilcambiamento.it/rpc/sendcomment.php",true);
	
	ajaxcomment.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	
	datipost="artid="+artid+"&nome="+escape(nome)+"&commento="+escape(commento);
	
	if (mail!="") datipost+="&mail="+mail;
	
	//alert(datipost);
	
	ajaxcomment.send(datipost);
	
	ajaxcomment.onreadystatechange = function()
	{
		if(ajaxcomment.readyState == 4)
		{
			risposta = ajaxcomment.responseText;
			if (risposta!="") document.getElementById("window").innerHTML = risposta;
			else
			{
				document.getElementById("window").innerHTML = "errore: risposta vuota";
				alert(ajaxcomment.status);
			}
		}
	}
}

function Send2Friend()
{
	cartid=document.getElementById("cartid").value;
	nome=document.getElementById("cnome").value;
	semail=document.getElementById("semail").value;
	demail=document.getElementById("demail").value;
		
	document.getElementById("window").innerHTML = "ATTENDERE...<br /><br />Invio mail in corso...";
	
	ajaxcomment=null;
	
	ajaxcomment=new getHTTPObject();
		
	ajaxcomment.open("post","http://www.ilcambiamento.it/rpc/send2friend.php",true);
	
	ajaxcomment.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	
	datipost="cartid="+cartid+"&nome="+escape(nome)+"&semail="+semail+"&demail="+demail;
	
	//alert(datipost);
	
	ajaxcomment.send(datipost);
	
	ajaxcomment.onreadystatechange = function()
	{
		if(ajaxcomment.readyState == 4)
		{
			risposta = ajaxcomment.responseText;
			if (risposta!="") document.getElementById("window").innerHTML = risposta;
			else
			{
				document.getElementById("window").innerHTML = "errore: risposta vuota";
				alert(ajaxcomment.status);
			}
		}
	}
}

function SendContact()
{
	nome=document.getElementById("cnome").value;
	messaggio=document.getElementById("cmessaggio").value;
	email=document.getElementById("cmail").value;
	titolo=document.getElementById("ctitolo").value;
	
	document.getElementById("window").innerHTML = "ATTENDERE...<br /><br />Invio messaggio in corso...";
	
	ajaxcontact=null;
	
	ajaxcontact=new getHTTPObject();
		
	ajaxcontact.open("post","http://www.ilcambiamento.it/rpc/sendcontact.php",true);
	
	ajaxcontact.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	
	datipost="nome="+escape(nome)+"&messaggio="+escape(messaggio)+"&titolo="+escape(titolo)+"&email="+email;
	
	//alert(datipost);
	
	ajaxcontact.send(datipost);
	
	ajaxcontact.onreadystatechange = function()
	{
		if(ajaxcontact.readyState == 4)
		{
			risposta = ajaxcontact.responseText;
			if (risposta!="") document.getElementById("window").innerHTML = risposta;
			else
			{
				document.getElementById("window").innerHTML = "errore: risposta vuota";
				alert(ajaxcontact.status);
			}
		}
	}
}

function SendMailAutore()
{
	autid=document.getElementById("autid").value;
	nome=document.getElementById("manome").value;
	titolo=document.getElementById("matitolo").value;
	testo=document.getElementById("matesto").value;
	mail=document.getElementById("mamail").value;
	
	document.getElementById("window").innerHTML = "ATTENDERE...<br /><br />Invio messaggio in corso...";
	
	ajaxmailautore=null;
	
	ajaxmailautore=new getHTTPObject();
		
	ajaxmailautore.open("post","http://www.ilcambiamento.it/rpc/sendmailautore.php",true);
	
	ajaxmailautore.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	
	datipost="autid="+autid+"&nome="+escape(nome)+"&testo="+escape(testo)+"&titolo="+escape(titolo)+"&mail="+mail;
	
	//alert(datipost);
	
	ajaxmailautore.send(datipost);
	
	ajaxmailautore.onreadystatechange = function()
	{
		if(ajaxmailautore.readyState == 4)
		{
			risposta = ajaxmailautore.responseText;
			if (risposta!="") document.getElementById("window").innerHTML = risposta;
			else
			{
				document.getElementById("window").innerHTML = "errore: risposta vuota";
				alert(ajaxmailautore.status);
			}
		}
	}
}

function SendNews(wn,par)
{
	document.getElementById("back").style.display = "block";
	document.getElementById("window").innerHTML = "ATTENDERE...";
	
	ajaxwin=null;
	
	ajaxwin=new getHTTPObject();
	
	mail=document.getElementById("newsmail").value;
		
	mail=escape(mail);
	
	ajaxwin.open("get","http://www.ilcambiamento.it/rpc/sendnews.php?mail="+mail,true);
	
	ajaxwin.send(null);
	
	ajaxwin.onreadystatechange = function()
	{
		if(ajaxwin.readyState == 4)
		{
			risposta = ajaxwin.responseText;
			if (risposta!="") 
			{
				document.getElementById("window").innerHTML = risposta;
				document.getElementById("newsmail").value="";
			}
			else
			{
				document.getElementById("window").innerHTML = "errore: risposta vuota";
				alert(ajaxwin.status);
			}
		}
	}
}

function SendNews2(wn,par)
{
	document.getElementById("back").style.display = "block";
	document.getElementById("window").innerHTML = "ATTENDERE...";
	
	ajaxwin=null;
	
	ajaxwin=new getHTTPObject();
	
	mail=document.getElementById("newsmail").value;
		
	mail=escape(mail);
	
	ajaxwin.open("get","http://www.ilcambiamento.it/rpc/sendnews2.php?mail="+mail,true);
	
	ajaxwin.send(null);
	
	ajaxwin.onreadystatechange = function()
	{
		if(ajaxwin.readyState == 4)
		{
			risposta = ajaxwin.responseText;
			if (risposta!="") 
			{
				document.getElementById("window").innerHTML = risposta;
				document.getElementById("newsmail").value="";
			}
			else
			{
				document.getElementById("window").innerHTML = "errore: risposta vuota";
				alert(ajaxwin.status);
			}
		}
	}
}

function SendNews2b(par)
{
	if (par=="paea") document.getElementById("snlpaea").innerHTML = "ATTENDERE...";
	else document.getElementById("snlday").innerHTML = "ATTENDERE...";
	
	ajaxwin=null;
	
	ajaxwin=new getHTTPObject();
	
	mail=document.getElementById("snlmail").innerHTML;
		
	mail=escape(mail);
	
	ajaxwin.open("get","http://www.ilcambiamento.it/rpc/sendnews2b.php?mail="+mail+"&action="+par,true);
	
	ajaxwin.send(null);
	
	ajaxwin.onreadystatechange = function()
	{
		if(ajaxwin.readyState == 4)
		{
			risposta = ajaxwin.responseText;
			if (risposta!="") 
			{
				if (par=="paea") document.getElementById("snlpaea").innerHTML = risposta;
				else document.getElementById("snlday").innerHTML = risposta;
				
			}
			else
			{
				if (par=="paea") document.getElementById("snlpaea").innerHTML = "errore: risposta vuota";
				else document.getElementById("snlday").innerHTML = "errore: risposta vuota";
				alert(ajaxwin.status);
			}
		}
	}
}

function CheckEventi()
{
	tipo=document.getElementById("stipo").value;
	paea=document.getElementById("spaea").value;
	
	if (paea==0)
	{
	if (tipo==0)
	{
		document.styleSheets[1].cssRules[0].style.display="table-row";
		document.styleSheets[1].cssRules[1].style.display="table-row";
		document.styleSheets[1].cssRules[2].style.display="table-row";
		document.styleSheets[1].cssRules[3].style.display="table-row";		
	}
	
	if (tipo==1)
	{
		document.styleSheets[1].cssRules[0].style.display="none";
		document.styleSheets[1].cssRules[1].style.display="table-row";
		document.styleSheets[1].cssRules[2].style.display="none";
		document.styleSheets[1].cssRules[3].style.display="table-row";
	}
	
	if (tipo==2)
	{
		document.styleSheets[1].cssRules[0].style.display="table-row";
		document.styleSheets[1].cssRules[1].style.display="none";
		document.styleSheets[1].cssRules[2].style.display="table-row";
		document.styleSheets[1].cssRules[3].style.display="none";
	}
	}
	else
	{
	if (tipo==0)
	{
		document.styleSheets[1].cssRules[0].style.display="table-row";
		document.styleSheets[1].cssRules[1].style.display="table-row";
		document.styleSheets[1].cssRules[2].style.display="none";
		document.styleSheets[1].cssRules[3].style.display="none";		
	}
	
	if (tipo==1)
	{
		document.styleSheets[1].cssRules[0].style.display="none";
		document.styleSheets[1].cssRules[1].style.display="table-row";
		document.styleSheets[1].cssRules[2].style.display="none";
		document.styleSheets[1].cssRules[3].style.display="none";
	}
	
	if (tipo==2)
	{
		document.styleSheets[1].cssRules[0].style.display="table-row";
		document.styleSheets[1].cssRules[1].style.display="none";
		document.styleSheets[1].cssRules[2].style.display="none";
		document.styleSheets[1].cssRules[3].style.display="none";
	}
	}
	
}

function svuotaSearch()
{
	if (document.getElementById("ttos").value=="cerca nel sito") document.getElementById("ttos").value="";
	document.getElementById("ttos").style.color="#000";
}

function catStart()
{
	document.getElementById("morelink").innerHTML="... <a href='#' onClick='catShow(); return false;'>mostra tutto</a>";
	document.getElementById("catmore").style.display="none";
}

function catShow()
{
	document.getElementById("morelink").style.display="none";
	document.getElementById("catmore").style.display="inline";
}
