// JavaScript Document
  if(typeof(DOMParser) == 'undefined') {
   DOMParser = function() {}
   DOMParser.prototype.parseFromString = function(str, contentType) {
	if(typeof(ActiveXObject) != 'undefined') {
	 var xmldata = new ActiveXObject('MSXML.DomDocument');
	 xmldata.async = false;
	 xmldata.loadXML(str);
	 return xmldata;
	} else if(typeof(XMLHttpRequest) != 'undefined') {
	 var xmldata = new XMLHttpRequest;
	 if(!contentType) {
	  contentType = 'application/xml';
	 }
	 xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' + encodeURIComponent(str), false);
	 if(xmldata.overrideMimeType) {
	  xmldata.overrideMimeType(contentType);
	 }
	 xmldata.send(null);
	 return xmldata.responseXML;
	}
   }
  }
  
function blockSubmit()
  {
	sendChatText();
	return false;
  }
  
function CheckEnter(e)
  {
	var keynum;
	var keychar;
	var numcheck;
	
	if(window.event) // IE
	  {
	  keynum = e.keyCode;
	  }
	else if(e.which) // Netscape/Firefox/Opera
	  {
	  keynum = e.which;
	  }
	if (keynum==13)
		sendChatText();
  }

var sendSearchReq = getXmlHttpRequestObject();
var glob_district = 0;

function getXmlHttpRequestObject()
  {
	if (window.XMLHttpRequest)
	  {
		return new XMLHttpRequest();
	  }
	else if(window.ActiveXObject)
	  {
		return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	else
	  {
		document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.' + 'Consider upgrading your browser.';
	  }
  }
  
  
  
//Function for handling the return of logged users
function handleGetSearchDistricts()
  {
	if (sendSearchReq.readyState == 4)
	  {
		var xmldoc = (new DOMParser()).parseFromString(sendSearchReq.responseText, 'text/xml');
		var cities_nodes = xmldoc.getElementsByTagName("DISTRICT");
		var n_cities = cities_nodes.length;
		var cities_list_name=new Array();
		var cities_list_id=new Array();
		for (i = 0; i < n_cities; i++)
		  {
			var id_node = cities_nodes[i].getElementsByTagName("ID");
			var name_node = cities_nodes[i].getElementsByTagName("NAME");
			cities_list_name[i]=name_node[0].firstChild.nodeValue;
			cities_list_id[i]=id_node[0].firstChild.nodeValue;
			//document.chat.users[document.chat.users.length] = new Option(name_node[0].firstChild.nodeValue, document.chat.users.length);

			//alert(name_node[0].firstChild.nodeValue);
			//document.getElementById("users").appendChild(newOption(name_node[0].firstChild.nodeValue,name_node[0].firstChild.nodeValue))
			//document.getElementById("users").scrollTop = document.getElementById("users").scrollHeight;
	 	 }
		removeDistrictsSearch();
		addSearchDistricts(cities_list_name,cities_list_id);
	  }
  }
  
//Function to add new logged users to the menu
function addSearchDistricts(cities_list_name, cities_list_id)
  {
	index=0;
	for (i = 0; i < cities_list_name.length; i++)
	  {
		if (glob_district == cities_list_id[i])
		  {
			document.getElementById('searchdistric')[document.getElementById('searchdistric').length] = new Option(cities_list_name[i], cities_list_id[i], true);
			index=i+1;
		  }
		else
			document.getElementById('searchdistric')[document.getElementById('searchdistric').length] = new Option(cities_list_name[i], cities_list_id[i], false);
	  }
	document.getElementById('searchdistric').selectedIndex=index;
  }
  
//Function to add new logged users to the menu
function removeDistrictsSearch()
  {
	list_length=document.getElementById('searchdistric').length;
	i=1;
	for (i = 1; i < list_length; i++)
	  {
		//alert (list_length + '-' + i + '-' + document.register.city.options[i].text);
		document.getElementById('searchdistric').options[1]= null;
	  }
  }

//This cleans out the database so we can start a new chat session.
function getSearchDistricts(value,district)
  {
	if (sendSearchReq.readyState == 4 || sendSearchReq.readyState == 0)
	  {
		glob_district=district;
		sendSearchReq.open("POST", 'getDistrict.php?action=getcities&city=' + value, true);
		sendSearchReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		sendSearchReq.onreadystatechange = handleGetSearchDistricts;
		sendSearchReq.send(null);
	  }
  }
  
  