function getXmlHttpObject(){
  var xmlhttp=false;
  try
  {
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); /* for IE < 5 */
  }
  catch (e)
  {
     try
     {
     xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
     }
     catch (E)
     {
     xmlhttp = false;
     }
  }

  /* mozilla & opera */
  if (!xmlhttp && typeof XMLHttpRequest!='undefined')
  {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function voteResult(id,direction){
  // Call tip approval page.
  xml = getXmlHttpObject();
  url = '/?action=voteresult&id=' + id + '&direction=' + direction;
  try{
    params = "";
    xml.open('GET', url, false);
    xml.send(params);
    if(xml.responseText != 'error'){
      // Vote successful.  Swap graphics.
      if(xml.responseText.substr(0, 5)=='reset'){
         // Vote reset.  Set graphics to gray.
        document.getElementById('up-' + id).src = '/images/up-gray.gif';
        document.getElementById('down-' + id).src = '/images/down-gray.gif';
        cred = xml.responseText.substr(5);
      }
      else if(direction==1){
        document.getElementById('up-' + id).src = '/images/up-green.gif';
        document.getElementById('down-' + id).src = '/images/down-gray.gif';
        cred = xml.responseText;
      }
      else if(direction==-1){
        document.getElementById('up-' + id).src = '/images/up-gray.gif';
        document.getElementById('down-' + id).src = '/images/down-red.gif';
        cred = xml.responseText;
      }
      // Update result credibility.
      // document.getElementById('cred-' + id).innerHTML = cred;
      ret = true;
    }
    else{
      // Problems.
      ret = false;
    }
  }
  catch(e){
    ret = false;
  }

  if(!ret){
    alert('A problem was encountered while attemping to cast your vote.');
  }

  return false;
}

function jse(){
  img = new Image();
  img.src = '/jse';
}

function showLength(o){
  left = 255 - o.value.length;
  cd = document.getElementById('countdown');
  cd.innerHTML = left;
  if(left<0){
    cd.style.color = 'red';
  }
  else if(left == 0){
    cd.style.color = 'black';
  }
  else{
    cd.style.color = 'green';
  }
  return true;
}
