/*
  Last modified: Derianto Kusuma, Apr 1 2007
*/

XMLHTTP_READYSTATE_COMPLETE = 4;
XMLHTTP_STATUS_OK = 200;
XMLHTTP_STATUS_NOT_FOUND = 404;

var xmlHttp = null;

var moreBannerShowed = false;

/*****************************************************************************
  System
/****************************************************************************/

function getXmlHttp(){
  xmlHttp = null;

  try{              
    xmlHttp = new XMLHttpRequest(); //Firefox, Opera 8.0+, Safari
  }catch(err){
    try{   
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); //IE 6.0+
    }catch(err){      
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE 5.5+
    }
  }
  
  if(!xmlHttp)alert("Your browser does not support AJAX.");
}

function xmlHttpOpen(url, fnStateChange){
  getXmlHttp();
  if(!xmlHttp)return false;
  
  //alert("xmlHttpOpen called");
  
  xmlHttp.onreadystatechange = fnStateChange;
  xmlHttp.open("GET", url, true);
  xmlHttp.send(null);
  return true;
}

function xmlHttpReady(){
  //alert(xmlHttp.readyState);
  if(xmlHttp.readyState == XMLHTTP_READYSTATE_COMPLETE){
    //alert(xmlHttp.readyState + " " + xmlHttp.status);
    if(xmlHttp.status == XMLHTTP_STATUS_OK){
	  return true;
    }else if(xmlHttp.status == XMLHTTP_STATUS_NOT_FOUND){
      alert("XML data not found.");
	  return false;
	}else{
      //WARNING: Potential error point if bandwidth is too big
      alert("Problem retrieving XML data.");
	  return false;
	}
  }else{
    return false;
  }
}

/*****************************************************************************
  Main
/****************************************************************************/

function bodyOnLoad(){
  xmlHttpOpen("cgi-bin/log.php", nullFn);
}

function nullFn(){
  if(!xmlHttpReady())return;
  //alert(xmlHttp.responseText);
}

function bannerIn(message){ 
  document.getElementById("bannercomment").innerHTML = message;
  document.getElementById("bannercomment").style.backgroundColor = "#FFFFFF";
}

function bannerOut(){
  document.getElementById("bannercomment").innerHTML = "";
  document.getElementById("bannercomment").style.backgroundColor = "transparent";
}

function moreBannerSwitch(){
  moreBannerShowed = !moreBannerShowed;

  if(moreBannerShowed){
    document.getElementById("morebannermsg").innerHTML = ">>> less";
    document.getElementById("morebanner").style.display = "block";
  }else{
    document.getElementById("morebannermsg").innerHTML = "<<< more";
    document.getElementById("morebanner").style.display = "none";
  }
}



