// JavaScript Document

var xmlHttp = createXmlhttpRequestobject();
var useId=null;

function createXmlhttpRequestobject()
{
	var xmlHttp;	
	
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch(e)
	{
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for(var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch(e){}
		}
	}
	if(!xmlHttp)
	{
		alert("创建XMLHttpRequest对象出错");
	}
	else
	{		
		return xmlHttp;
	}
}

function process(now)
{
	useId=now.id;
	
	if(xmlHttp)
	{
		try
		{
			xmlHttp.open("GET","http://www.youwebdir.com/catecount.php?id="+useId,true);
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.send(null);
		}
		catch(e)
		{
			alert("不能连接服务器:\n" + e.toString());	
		}
	}
}

function handleRequestStateChange()
{	
	if(xmlHttp.readyState ==4)
	{
		//http状态为OK时继续
		if(xmlHttp.status == 200)
		{
			try
			{
				handleServerResponse();				
			}
			catch(e)
			{
				alert("读取文件错误:" + e.toString());
			}
		}
	}	
}

function handleServerResponse()
{
	var xmlResponse = xmlHttp.responseXML;
  // catching potential errors with IE and Opera
 /* if (!xmlResponse || !xmlResponse.documentElement)
    throw("Invalid XML structure:\n" + xmlHttp.responseText);*/
  // catching potential errors with Firefox
  var rootNodeName = xmlResponse.documentElement.nodeName;
  if (rootNodeName == "parsererror") throw("Invalid XML structure");
  // obtain the XML's document element
  xmlRoot = xmlResponse.documentElement;  
  // obtain arrays with book titles and ISBNs 
  titleArray = xmlRoot.getElementsByTagName("title");
//  isbnArray = xmlRoot.getElementsByTagName("isbn");
  // generate HTML output
  var html = "";  
  // iterate through the arrays and create an HTML structure
 
  html += titleArray.item(0).firstChild.data + " sites";
	
  // obtain a reference to the <div> element on the page
  myA = document.getElementById(useId);
  
  // display the HTML output
  myA.title = html;
  useId=0;
	
}