var xml = makeXML();

var el = new Array();

var options = new Array();

options['pagerank'] = '<strong>Google PageRank</strong>';

options['alexaRank'] = '<strong>Alexa Rank</strong>';

options['dmoz'] = '<strong>DMOZ Listed</strong>';

options['backlinksGoogle'] = '<strong>Google Backlinks</strong>';

options['backlinksYahoo'] = '<strong>Yahoo Backlinks</strong>';

options['resultsAltaVista'] = '<strong>AltaVista Results</strong>';

options['resultsAllTheWeb'] = '<strong>All the Web Results</strong>';

options['thumbnail'] = 'Website Thumbnail';

function makeXML () {

	if (typeof XMLHttpRequest == 'undefined') {

		objects = Array(

			'Microsoft.XmlHttp',

			'MSXML2.XmlHttp',

			'MSXML2.XmlHttp.3.0',

			'MSXML2.XmlHttp.4.0',

			'MSXML2.XmlHttp.5.0'

		);

		for (i in objects) {

			try {

				return new ActiveXObject(objects[i]);

			} catch (e) {}

		}

	} else {

		return new XMLHttpRequest();

	}

}

function get (id) {

	return document.getElementById(id);

}

function getResults (url) {

	el['results'] = get('results');

	xml.open('get', 'getResults.php?url=' + window.encodeURI(url));

	xml.onreadystatechange = function () {

		if (xml.readyState == 4) {

			el['results'].innerHTML = '';

			if (window.ActiveXObject) {

				doc = new ActiveXObject('Microsoft.XMLDOM');

				doc.async = 'false';

				doc.loadXML(xml.responseText);

			} else {

				parser = new DOMParser();

				doc = parser.parseFromString(xml.responseText,'text/xml');

			}

			xmlDoc = doc.documentElement;

			x = 0;

			for (i in options) {

				x++;

				title = options[i];

				value = xmlDoc.getElementsByTagName(i)[0].childNodes[0].nodeValue;

				if (i == 'thumbnail') {

					value = '<img src="' + value + '" alt="" width="120" height="90" />';

				}

				if (i == 'dmoz') {

					if (value == '1') {

						value = 'Yes';

					} else {

						value = 'No';

					}

				}

				style = (x % 2) ? ' ' : '';

				el['results'].innerHTML += '<div' + style + '><span>' + value + '</span>' + title + '<strong class="clear"></strong></div>';

			}

		} else {

			el['results'].innerHTML = '<div>Loading...</div>';

		}

	}

	xml.send(null);

}
