function createXMLHttpRequest() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }


/* the following code is basically borrowed from apple's itunes example, it's highly recommended that people wanting to know about this script to read and undestand their function first: http://developer.apple.com/internet/webcontent/xmlhttpreq.html */

/* possibilites:
<title>1. My Band - D12</title> -> getElementTextNS("", "title", items[i], 0);
<itms:artist>D12</itms:artist> -> getElementTextNS("itms", "artist", items[i], 0);
*/
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}

/* shauns's functions */
/* This is a simple functio to grab xml data and write innerHTML tags for DIV's given:
	<item>
		<field>nameme</field><newdata>Shaun</newdata>
	</item>
*/
String.prototype.trim=function(){
    return this.replace(/^\s*|\s*$/g,'');
}

String.prototype.alttrim=function(){
    return this.replace(/^\s+/g,'');
}

function rewriteDiv(x)
{
  var items = x.responseXML.getElementsByTagName("item");
    for (var i = 0; i < items.length; i++) {
/* we need to determine what value we are updating */
var divtag = document.createTextNode(getElementTextNS("", "field", items[i], 0)).nodeValue;
/* now let's update the div */
var newvalue = document.createTextNode(getElementTextNS("", "newdata", items[i], 0)).nodeValue;
//alert("data:"+divtag+" & "+newvalue);
var current = document.getElementById(divtag).innerHTML;
if (current.alttrim() != newvalue.alttrim()){ 
document.getElementById(divtag).innerHTML = newvalue;
}
	 }
}
	function scrollDown() {
		i=0;
		while (document.getElementById("chatcontent").offsetHeight!=i) {
			i=document.getElementById("chatcontent").offsetHeight;
		}
		document.getElementById("chattextzone").scrollTop=document.getElementById("chatcontent").offsetHeight;
	}	
function sendtoxml(fragment_url, element_id) {
var xmlhttp = createXMLHttpRequest();
xmlhttp.open("GET", fragment_url,true);
    xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
					rewriteDiv(xmlhttp);
      			} else {
					/* alert("There was a problem getting xml data:"+ xmlhttp.statusText); */
				}
		}
	}
    xmlhttp.send(null);
} 
function sendtotext(fragment_url, element_id, xdoafter) {
var xmlhttp = createXMLHttpRequest();
xmlhttp.open("GET", fragment_url,true);
//xmlhttp.setRequestHeader("Content-type", "text/html; charset=ISO-8859-1");
xmlhttp.onreadystatechange = function() {
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 		/* if all goes well, we re-write the innerHTML to the element supplied */
//document.getElementById(element_id).innerHTML = "<div id=\"backbut\"><a href=\"javascript:void(0)\" onclick=\"showmain()\"><img src=\"/usa/templates/default/images/back.gif\" onmouseover=\"this.src='/usa/templates/default/images/back_over.gif'\" onmouseout=\"this.src='/usa/templates/default/images/back.gif'\"/></a></div>";
//document.getElementById(element_id).innerHTML = document.getElementById(element_id).innerHTML + xmlhttp.responseText;
document.getElementById(element_id).innerHTML = xmlhttp.responseText;
//alert("id:"+element_id);
//alert(xmlhttp.responseText);
	if (xdoafter){
	eval(xdoafter);
	}
}
    }
    xmlhttp.send(null);
}