
function loadGraph(judge, field, hex) {
  var id = document.getElementById('span'+field+hex);
  if( id.innerHTML.length == 0 )
    sendRequest("../ajax/resultspiegraph.php?judge="+judge+"&field="+field+"&hex="+hex);
  else
    id.innerHTML = '';
}
function loadMonthGraph(judge, field) {
  var id = document.getElementById('span'+field);
  if( id.innerHTML.length == 0 )
    sendRequest("../ajax/resultsmonthpiegraph.php?judge="+judge+"&field="+field);
  else
    id.innerHTML = '';
}
function loadAgree(judge) {
  sendRequest("../ajax/resultsagree.php?judge="+judge);
}
function loadDaily(judge, days) {
  sendRequest("../ajax/resultsdailygraph.php?judge="+judge+"&days="+days);
}
function loadMonthly(judge) {
  sendRequest("../ajax/resultsmonthlygraph.php?judge="+judge);
}
function loadSurvey(judge) {
  sendRequest("../ajax/resultssurveygraph.php?judge="+judge);
}



/******** This code runs everything ajax, entry point is sendRequest ****************/
var isWorking = false;
var httpObject = getHTTPObject();

function sendRequest(url) {
  if (!isWorking) {
    httpObject.open('GET', url, true);
    isWorking = true;
    httpObject.onreadystatechange = messageProcessor;
    httpObject.send(null);
  }
}

function getHTTPObject() {
  var http = false;
  if (window.XMLHttpRequest) { // Non-IE

    http = new XMLHttpRequest();

    if (http.overrideMimeType)
      http.overrideMimeType('text/xml');

  } else if (window.ActiveXObject) { // IE

    try {
      http = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {

      try {
        http = new ActiveXObject('Microsoft.XMLHTTP');
      } catch (e) {}

    }

  }

  return http;
}

function messageProcessor() {
  if( httpObject.readyState == 4) {
    if( httpObject.responseText.indexOf('message') >= 0 || true) {
      var xmlDoc = httpObject.responseXML;
      var commands = xmlDoc.getElementsByTagName('command');

      for(var i = 0; i < commands.length; i++){
        var command = commands.item(i);
        var functionName = command.getElementsByTagName('function').item(0).firstChild.data;
        eval( functionName + "(command.getElementsByTagName('arguments').item(0));" );
      }
    }
    isWorking = false;
  }
}

function changeAttribute( args ) {
  var id    = args.getElementsByTagName('id').item(0).firstChild.data;
  var name  = args.getElementsByTagName('name').item(0).firstChild.data;
  var value = args.getElementsByTagName('value').item(0).firstChild.data;

  id    = stripSpaces(id);
  name  = stripSpaces(name);
  value = stripSpaces(value);

  var idTag = document.getElementById(id);
  if( idTag ) {
    eval( "idTag."+name+" = '"+value+"';");
  }
}

function changeStyle( args ) {
  var id    = args.getElementsByTagName('id').item(0).firstChild.data;
  var name  = args.getElementsByTagName('name').item(0).firstChild.data;
  var value = args.getElementsByTagName('value').item(0).firstChild.data;

  id    = stripSpaces(id);
  name  = stripSpaces(name);
  value = stripSpaces(value);

  var idTag = document.getElementById(id);
  if( idTag ) {
    eval( "idTag.style."+name+" = '"+value+"';");
  }
}

function replaceHTML( args ) {
  var id   = args.getElementsByTagName('id').item(0).firstChild.data;
  var html = args.getElementsByTagName('html').item(0).firstChild.data;

  id = stripSpaces(id);
  var idTag = document.getElementById(id);

  if( idTag ) {
    idTag.innerHTML = html;
  }
}

function runCode( args ) {
  var code = args.getElementsByTagName('code').item(0).firstChild.data;

  eval( code );
}

function stripSpaces( in_str ) {
  var out = '';
  for(var i = 0; i < in_str.length; i++)
    if( in_str.charAt(i) != ' ' && in_str.charAt(i) != '\n' && in_str.charAt(i) != '\r' )
      out += in_str.charAt(i);
  return out;
}
/****************************************************************************/