//function initNickNames() {
//	receiveNickNamesData();
//}
var nickNames = new Array();

//initiates the first data query
function receiveNickNamesData() {
	if (httpReceiveNickNames.readyState == 4 || httpReceiveNickNames.readyState == 0) {
		httpReceiveNickNames.open("GET", 'pages/chat/GetNicknames.php', true);
    	httpReceiveNickNames.onreadystatechange = handlehttpReceiveNickNames; 
		httpReceiveNickNames.send(null);
	}
}

function handlehttpReceiveNickNames() {
  if (httpReceiveNickNames.readyState == 4) {
   // DATA RX //
	NickNamesResults = httpReceiveNickNames.responseText; //.split('---'); // the fields are seperated by ---
	document.getElementById('nicklist').innerHTML = httpReceiveNickNames.responseText; //NickNamesResults;
	
	
	nickNames = httpReceiveNickNames.responseText.split('||---!N!');
//	textContent = document.getElementById('chatbarText').value += nickNames[1];
	}
}

function completeNick() {
	textContent = document.getElementById('chatbarText').value;

	var explodedString = document.getElementById('chatbarText').value.split(' ');
	var explodedString = explodedString[explodedString.length-1];
	
	if (explodedString != '') {	
		for (x = 0; x < nickNames.length; x++) {
			if (nickNames[x].substr(0, explodedString.length) == explodedString) {
				document.getElementById('chatbarText').value += nickNames[x].substr(explodedString.length, nickNames[x].length - explodedString.length);
				break;
			}
		}
		reFocusTimer = setTimeout("document.getElementById('chatbarText').focus();", 100);
	}
}

function getHTTPNickNamesObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

var httpReceiveNickNames = getHTTPNickNamesObject();
//var httpSendChat = getHTTPNickNamesObject();