function displayNote (el)
{
    $(el).style.display = 'block';
}

function hideNote (el)
{
    $(el).style.display = 'none';
}

function showList(ch)
{
    var elem = ch.parentNode;
    elem.className += " over";
}

function hideList(ch)
{
    var elem = ch.parentNode;
    setTimeout(function()
    {
        elem.className=elem.className.replace(" over", "");
    }, 200);
}

function startList()
{
    navRoot = $('dmenu');

    for (i=0; i<navRoot.childNodes.length; i++)
    {
        node = navRoot.childNodes[i];
        if (node.nodeName == "LI")
        {
            node.onmouseover=function()
            {
                this.className += " over";
            };

            node.onmouseout=function()
            {
                this.className=this.className.replace(" over", "");
            };
        }
    }
};

function startList2(what)
{
    navRoot = $(what);

    for (i=0; i<navRoot.childNodes.length; i++)
    {
        node = navRoot.childNodes[i];
        if (node.nodeName == "LI")
        {
            node.onmouseover=function()
            {
                this.className += " over";
            };

            node.onmouseout=function()
            {
                this.className=this.className.replace(" over", "");
            };
        }
    }
};

toggleForecast = function()
{
   $('city2').toggle();
   $('day2').toggle();
   $('city4').toggle();
   $('day4').toggle();
   $('city5').toggle();
   $('day5').toggle();
   if ($F('btnForecast') == 'Daugiau miestų')
   {
       $('btnForecast').value = 'Atgal';
   }
   else
   {
       $('btnForecast').value = 'Daugiau miestų';
   }
   if ($('klaipeda').className == 'city even')
   {
       $('klaipeda').className = 'city odd';
   }
   else
   {
       $('klaipeda').className = 'city even';
   }

} 

showHoroscope = function (no)
{
   var crnt = $('currentHoroscope');
   switch (crnt.value)
   {
       case 'All':
           for (i = 0; i < 12; i++) 
           {
               if (i != no) 
               {
                   $('horoscope' + i).hide();
               }
               else
               {
                   $('horoscope' + i).style.borderBottom = 'none';
               }
           }
           $('horoscopesNav').style.borderBottom = '1px solid #003366';
           crnt.value = no;
           break;
       
       case '-1':
           $('horoscopesNav').style.borderBottom = '1px solid #003366';
           $('horoscope' + no).style.borderBottom = 'none';
           $('horoscope' + no).show();
           crnt.value = no;
           break;
       
       default:
           var last = 'horoscope' + crnt.value;
           $(last).hide();
           if (crnt.value == no) 
           {
               crnt.value = -1;
              $('horoscopesNav').style.borderBottom = 'none';
           }
           else
           {
               $('horoscopesNav').style.borderBottom = '1px solid #003366';
               $('horoscope' + no).style.borderBottom = 'none';
               $('horoscope' + no).show();
               crnt.value = no;
           }   
   }
   $('btnHoroscopes').value = 'Rodyti visus';
}

toggleHoroscopes = function ()
{
   if ($('btnHoroscopes').value == 'Rodyti visus')
   {
       for (i = 0; i < 11; i++) 
       {
           $('horoscope' + i).style.borderBottom = '1px solid #003366';
           $('horoscope' + i).show();
       }
       $('horoscope' + '11').style.borderBottom = 'none';
       $('horoscope' + '11').show();
       $('currentHoroscope').value = 'All';
       $('btnHoroscopes').value = 'Slėpti visus';
       $('horoscopesNav').style.borderBottom = '1px solid #003366';
   }  
   else
   {
       for (i = 0; i < 12; i++) 
       {
           $('horoscope' + i).hide();
       }
       $('horoscopesNav').style.borderBottom = 'none';
       $('currentHoroscope').value = -1;
       $('btnHoroscopes').value = 'Rodyti visus';
   }  
}

//For pazintys block
function checkSelectedAge()
{
 age_start = document.getElementById("age_start");
 age_end = document.getElementById("age_end");

 if (age_start.value > age_end.value)
 {
   alert("Pasirinktas neteisingas amžiaus intervalas");
   age_end.focus();
   return false;
 }
 else
 {
   return true;
 }       
}

var doBlink = false;
var doBlinkTimer;

function blinkTitle(title, blink)
{
    if(blink == 1)
    {
        document.title = '***** '+title+' *****';
        blink = 0;
    }
    else
    {
        document.title = title;
        blink = 1;
    }
    if(doBlink)
        doBlinkTimer = setTimeout('blinkTitle(\''+title+'\', '+blink+')', 1000);
}

function checkReminders(subsystem)
{
    if(typeof(dh) != 'undefined')
    {
    	if(dh.show == null) dh.show = false;
    	if(dh.show) return; // yra chato zinute
	}

    new Ajax.Request('/pazintys/ajax_reminders.php',
    {
        method: 'post',
        parameters: {subsystem:subsystem},
        onSuccess: function remindersReceived(r)
        {
            response = r.responseXML.documentElement;
            var subsystem = response.getElementsByTagName('subsystem')[0].firstChild.data;
            var hr = false; // Ar yra priminimų
            var rt = 'Yra naujovių'; // Priminimų tekstas
            var klase = response.getElementsByTagName('klase')[0];
            //var grupe = response.getElementsByTagName('grupe')[0];
            //var biciuliai = response.getElementsByTagName('biciuliai')[0];
            var pazintys = response.getElementsByTagName('pazintys')[0];
            // Kiekiai:
            var kk =  parseInt(klase.getElementsByTagName('kiekis')[0].firstChild.data);
            //var gk =  parseInt(grupe.getElementsByTagName('kiekis')[0].firstChild.data);
            //var bk =  parseInt(biciuliai.getElementsByTagName('kiekis')[0].firstChild.data);
            var pk =  parseInt(pazintys.getElementsByTagName('kiekis')[0].firstChild.data);
            
            if(kk > 0)
            {/*
                if(subsystem == 1)
                {
                    x=klase.getElementsByTagName('left')[0];
                    for(i = 0; i<x.childNodes.length; i++)
                        if($('notifications_'+x.childNodes[i].getAttribute('id')) != null)
                            $('notifications_'+x.childNodes[i].getAttribute('id')).innerHTML = x.childNodes[i].firstChild.data;
                }
                else
                    $('notifications1').innerHTML = klase.getElementsByTagName('top')[0].firstChild.data;
                */
                rt += ' mano KLASĖJE';
                hr = true;
            }
            /*
            if(gk > 0)
            {
                if(subsystem == 2)
                {
                    x=grupe.getElementsByTagName('left')[0];
                    for(i = 0; i<x.childNodes.length; i++)
                        if($('notifications_'+x.childNodes[i].getAttribute('id')) != null)
                            $('notifications_'+x.childNodes[i].getAttribute('id')).innerHTML = x.childNodes[i].firstChild.data;
                }
                else
                    $('notifications2').innerHTML = grupe.getElementsByTagName('top')[0].firstChild.data;
                if(hr)
                    rt += ',';
                rt += ' mano GRUPĖJE';
                hr = true;
            }
            if(bk > 0)
            {
                if(subsystem == 3)
                {
                    x=biciuliai.getElementsByTagName('left')[0];
                    for(i = 0; i<x.childNodes.length; i++)
                        if($('notifications_'+x.childNodes[i].getAttribute('id')) != null)
                            $('notifications_'+x.childNodes[i].getAttribute('id')).innerHTML = x.childNodes[i].firstChild.data;
                }
                else
                    $('notifications3').innerHTML = biciuliai.getElementsByTagName('top')[0].firstChild.data;
                if(hr)
                    rt += ',';
                rt += ' mano BIČIULIUOSE';
                hr = true;
            }*/
            if(pk > 0)
            {/*
                if(subsystem == 4)
                    $('notifications').innerHTML = pazintys.getElementsByTagName('left')[0].firstChild.data;
                else
                    $('notifications4').innerHTML = pazintys.getElementsByTagName('top')[0].firstChild.data;*/
                $('notifications').innerHTML = pazintys.getElementsByTagName('left')[0].firstChild.data;
                if(hr)
                    rt += ',';
                rt += ' mano PAŽINTYSE';
                hr = true;
            }
            if(hr)
            {
                if(!doBlink)
                {
                    doBlink = true;
                    blinkTitle(rt, 1);
                }
            }
        }
    });
    setTimeout('checkReminders('+subsystem+')', 120000)
}




function getChatInfo(){
	
	new Ajax.Request('/chat2/chatBlock.php',
            {
               onCreate: function preloader()
                {
                    $('chatinfoblock').innerHTML = "<sup>ieško aktyvių pokalbių...</sub>";
                    $('chatinfoblock').style.display = "block";
                },
                onSuccess: function ready(rx)
                {
                    $('chatinfoblock').innerHTML = rx.responseText;               
                },
                onFailure: function fail()
                {
                	$('chatinfoblock').style.display = "none";
                }

            });
}