var cat4Visible=0; // globale, tiene traccia del div di categoria di livello 4 visibile
var cat2Visible=0; // globale, tiene traccia del div di categoria di livello 2 visibile
function manageDiv(id,level)
{
     var check=false;
     
     if (cat4Visible!=0)
     {
        check=document.getElementById(cat4Visible);
        if(check)
        {
            check.style.display='none';
        }
        
     }
     if (cat2Visible!=0)
     {
        if (level==2)
        {
            check=false;
            check=document.getElementById(cat2Visible);
            if(check)
            {
                check.style.display='none';
            }
            
        }
     }
     check=false;
     check=document.getElementById(id);
     if(check)
     {
         check.style.display='block';
         if (level==4)
         {
             cat4Visible=id;
             document.location="#"+cat2Visible;
         }
         else if (level==2)
         {
             cat2Visible=id;
             managePhotoMenu(id);
             if (id=="cat42")
             {
                document.location="#"+cat2Visible;
             }  
         }
     }  
}

function managePhotoMenu(id)
{
    if (id=="cat42")
    {
        document.getElementById("fotoFt").src="templates/1/imgFitness/fotoFitness.png";
    }
    else if (id=="cat73")
    {
        document.getElementById("fotoFt").src="templates/1/imgFitness/entrySalaAttrezzi.png";     
    }
    else if (id=="cat74")
    {
        document.getElementById("fotoFt").src="templates/1/imgFitness/entryCalcetto4.png";     
    }
    else if (id=="cat75")
    {
        document.getElementById("fotoFt").src="templates/1/imgFitness/entryBeachTennis.png";     
    }
}

function setLocation (id)
{
    document.location="#"+id;      
} 

function ajaxFunction(id)
{  
    id2=id+"V";
    var xmlHttp;
    try
    {    // Firefox, Opera 8.0+, Safari    
        xmlHttp=new XMLHttpRequest();    
    }
    catch (e)
    {    // Internet Explorer   
        try
        {      
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
        }
        catch (e)
        {      try
                {        
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
                }
                catch (e)
                {        
                alert("Your browser does not support AJAX!");        return false;        
                }      
        }    
    }
    if (id=="checkResponse")
    {
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
                var el=document.getElementById(id);

                var res=""+xmlHttp.responseText;

                
                if (eval(res)==true)
                {
                    location.replace("contatti.php");
                }
                else
                {
                  el.innerHTML="Modulo non compilato correttamente!";
                }
            }
        }
        qs="lib/regAjax.php";
        cognome=document.getElementById("cognome").value;  
        titolo=document.getElementById("titolo").value;
        messaggio=document.getElementById("messaggio").value;

        params="el=checkResponse&titolo="+titolo+"&messaggio="+messaggio+"&cognome="+cognome;   

        xmlHttp.open("POST",qs,true);

        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(params);

    }
    else
    {
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
                var el=document.getElementById(id2);

                el.innerHTML=xmlHttp.responseText;
            }
        }
        value=document.getElementById(id).value;
        qs="lib/regAjax.php";
        params="el="+id+"&value="+value;  
        if (id=="mailR")
        { 
            value2=document.getElementById("mail").value;
            params="el="+id+"&value="+value+"&value2="+value2;          
        }
        if (id=="mail")
        {
            value2=document.getElementById("mailR").value;
            params="el="+id+"&value="+value+"&value2="+value2;  
        } 
        xmlHttp.open("POST",qs,true);

        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", params.length);
        xmlHttp.setRequestHeader("Connection", "close");
        xmlHttp.send(params);
    }  
}
          
function checkReg(id)
{
    ajaxFunction(id);
}

function clearCont(id)
{
    document.getElementById(id).innerHTML="";
}     
