function getXMLObject()
{
         var xmlHttp = null;
         try
         {
           xmlHttp = new XMLHttpRequest();
         }
         catch(e)
         {
              try
              {
                  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
              }
              catch(e)
              {
                   try
                   {
                       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                   }
                   catch(e)
                   {
                         xmlHttp = null;
                   }
              }
         }

         return(xmlHttp);
}

var ajax = getXMLObject();

function logIn()
{
         ajax.onreadystatechange = confirmLogin;

         ajax.open("POST", root_path() + 'forum/php/login.php', true);

         var Login = 'login=' + document.getElementById('login').value +
                     '&password=' + document.getElementById('password').value +
                     '&duration=' + document.getElementById('duration').value;

         ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	     ajax.setRequestHeader("Content-length", Login.length);
	     ajax.setRequestHeader("Connection", "close");

         ajax.send(Login);
}

function logout()
{
         ajax.onreadystatechange = confirmLogin;

         ajax.open("POST", root_path() + 'forum/php/login.php', true);

         var Logout = 'login=&password=&duration=-1';

         ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	     ajax.setRequestHeader("Content-length", Logout.length);
	     ajax.setRequestHeader("Connection", "close");

         ajax.send(Logout);
}

function saveComment(path)
{
         ajax.onreadystatechange = confirmSave;

         ajax.open("POST", root_path() + 'forum/php/save-comment.php', true);

         var Save = 'path=' + path +
                    '&body=' + document.getElementById('new_comment').value;

         ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	     ajax.setRequestHeader("Content-length", Save.length);
	     ajax.setRequestHeader("Connection", "close");

         ajax.send(Save);
}

function deleteComment(id)
{
         ajax.onreadystatechange = confirmDeletion;

         ajax.open("POST", root_path() + 'forum/php/delete-comment.php', true);

         var Delete = 'id=' + id;

         ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	     ajax.setRequestHeader("Content-length", Delete.length);
	     ajax.setRequestHeader("Connection", "close");

         ajax.send(Delete);
}

function confirmLogin()
{
         if(ajax.readyState == 4)
         {
            if(ajax.status == 200)
            {
               eval(ajax.responseText);
            }
         }
}

function confirmSave()
{
         if(ajax.readyState == 4)
         {
            if(ajax.status == 200)
            {
               eval(ajax.responseText);
            }
         }
}

function confirmDeletion()
{
         if(ajax.readyState == 4)
         {
            if(ajax.status == 200)
            {
               eval(ajax.responseText);
            }
         }
}

function setCookie(name, value)
         {
         //If name is the empty string, it places a ; at the beginning
         //of document.cookie, causing clearCookies() to malfunction.
         if(name != '')
            document.cookie = name + '=' + value;
         }

function openAddComment()
         {
         document.getElementById("add_comment").style.visibility = 'visible';
         document.getElementById("open_add_comment").style.visibility = 'collapse';
         }

function closeAddComment()
         {
         document.getElementById("add_comment").style.visibility = 'collapse';
         document.getElementById("open_add_comment").style.visibility = 'visible';
         }
