var menuHasSub = false;                         // Toggle for sub-menu header

function createAjaxObject() {
    var ajaxObj;
    var browser = navigator.appName;
    if(browser.indexOf('Microsoft') >= 0)
        ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
    else
        ajaxObj = new XMLHttpRequest();

    return ajaxObj;
}


//----------------------------------------------
// Menu
function menuHover(menuId) {
   document.getElementById('headerMenuArrow' + menuId).style.display = 'none';
   document.getElementById('headerMenuArrowOn' + menuId).style.display = '';

   menuHasSub = false;

   for (i = 0; i < 10; i++) {
      if (document.getElementById('headerSubMenu' + i)) {

         if (i == menuId) {
            document.getElementById('headerSubMenu' + i).style.display = '';
            menuHasSub = true;
         } else {
            document.getElementById('headerSubMenu' + i).style.display = 'none';
            document.getElementById('headerMenuArrowOn' + i).style.display = 'none';
            document.getElementById('headerMenuArrow' + i).style.display = '';
         }

      }
   }
}

function menuOut(menuId) {
   if (!menuHasSub) {
      document.getElementById('headerMenuArrowOn' + menuId).style.display = 'none';
      document.getElementById('headerMenuArrow' + menuId).style.display = '';
   }
}

//----------------------------------------------
// Comments
var comment_ajaxObject;


function mondoCommentSubmit(db, idstring, id) {
   comment_ajaxObject = createAjaxObject();
   var timenow = Math.floor(Math.random()*1000);

   var text = escape(document.getElementById('commentText').value);
   var url = '/ajax_add_comment.php?db=' + db + '&idstring=' + idstring + '&id=' + id + '&salt=' + timenow + '&comment=' + text;

   comment_ajaxObject.onreadystatechange = mondoCommentSubmit_handleResponse;
   comment_ajaxObject.open('get', url);
   comment_ajaxObject.send(null);
}

function mondoCommentSubmit_handleResponse() {
   if(comment_ajaxObject.readyState == 4){
      document.getElementById('commentBlock').innerHTML = comment_ajaxObject.responseText;
      document.getElementById('commentText').value = '';
   }
}

