var xml = makeXML();
var el = new Array();
var options = new Array();
var option = new Array();
var optionsg = new Array();
var snapshot = new Array();
snapshot['thumbnail'] = '';
options['pagerank'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/google3.gif" /> PageRank';
options['alexaRank'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/alexa.jpg" /> Rank';
options['dmoz'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/dmoz.gif" /> Listed?';
options['yahooDir'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/yahoodir.gif" /> Listed?';
options['saturationYahoo'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/yahoo3.gif" /> Page Saturation';
options['backlinksYahoo'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/yahoo3.gif" /> Backlinks';
optionsg['saturationGoogle'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/google3.gif" /> Page Saturation';
optionsg['backlinksGoogle'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/google3.gif" /> Total Backlinks';
optionsg['edubacklinksGoogle'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/google3.gif" /> .edu Backlinks';
optionsg['govbacklinksGoogle'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/google3.gif" /> .gov Backlinks';
option['resultsAltaVista'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/altavista.gif" /> Page Saturation';
option['resultsAllTheWeb'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/alltheweb.jpg" /> Page Saturation';
option['resultsWikipedia'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/wikipedia.jpg" /> Results';
option['resultsDelicious'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/delicious.gif" /> Results';
option['resultsTechnorati'] = '<img src="http://www.smegoconsulting.com/tools/multiple/images/technorati.png" /> Results';

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 snapshot) {
				x++;
				title = snapshot[i];
				value = xmlDoc.getElementsByTagName(i)[0].childNodes[0].nodeValue;
				if (i == 'thumbnail') {
					value = '<img src="' + value + '" alt="' + window.encodeURI(url) + '" />';
				}
				style = ' style="background-color: #333333;font-weight:bold;color:#FFFFFF; text-align: center;"';
				el['results'].innerHTML += '<div' + style + '>Results for ' + window.encodeURI(url) + '</div><div align="center">' + value + '' + title + '<b class="clear"></b></div>';
			}				
			
			
			
			for (i in options) {
				x++;
				title = options[i];
				value = xmlDoc.getElementsByTagName(i)[0].childNodes[0].nodeValue;
				if (i == 'pagerank') {
						value = '' + value + '/10';		
				}
			
				
				if (i == 'dmoz') {
					if (value == '1') {
						value = '<a href=\"http://search.yahoo.com/search?p=linkdomain%3A' + window.encodeURI(url) + '+site:dmoz.org\" target="_blank">Yes</a>';
					} else {
						value = '<a href=\"http://search.yahoo.com/search?p=linkdomain%3A' + window.encodeURI(url) + '+site:dmoz.org\" target="_blank">No</a>';
					}
				}
				if (i == 'yahooDir') {
					if (value == '1') {
						value = '<a href=\"http://search.yahoo.com/search/dir?ei=UTF-8&fr=sfp&p=' + window.encodeURI(url) + '\" target="_blank">Yes</a>';
					} else {
						value = '<a href=\"http://search.yahoo.com/search/dir?ei=UTF-8&fr=sfp&p=' + window.encodeURI(url) + '\" target="_blank">No</a>';
					}
				}		
				if (i == 'saturationYahoo') {
						value = '<a href=\"http://siteexplorer.search.yahoo.com/search?p=' + window.encodeURI(url) + '&bwm=p&bwmf=a&bwms=p&searchbwm=Explore+URL\" target="_blank">' + value + '</a>';		
						}
				if (i == 'backlinksYahoo') {
						value = '<a href=\"http://siteexplorer.search.yahoo.com/search?p=' + window.encodeURI(url) + '&bwm=i\" target="_blank">' + value + '</a>';
					} 
				if (i == 'saturationMSN') {
						value = '<a href=\"http://search.live.com/results.aspx?q=site%3A' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				if (i == 'backlinksMSN') {
						value = '<a href=\"http://search.live.com/results.aspx?q=link%3A' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				style = ' style="background-color: #ffffff"';
				el['results'].innerHTML += '<div' + style + '><span class="links">' + value + '</span>' + title + '<b class="clear"></b></div>';
			}
			for (i in optionsg) {
				x++;
				title = optionsg[i];
				value = xmlDoc.getElementsByTagName(i)[0].childNodes[0].nodeValue;
				if (i == 'saturationGoogle') {
						value = '<a href=\"http://www.google.com/search?q=site%3A' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				if (i == 'backlinksGoogle') {
						value = '<a href=\"http://www.google.com/search?q=link%3A' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				if (i == 'edubacklinksGoogle') {
						value = '<a href=\"http://www.google.com/search?as_q=link%3A+' + window.encodeURI(url) + '+site%3A.edu\" target="_blank">' + value + '</a>';
					} 
				if (i == 'govbacklinksGoogle') {
						value = '<a href=\"http://www.google.com/search?as_q=link%3A+' + window.encodeURI(url) + '+site%3A.gov\" target="_blank">' + value + '</a>';
					} 
				style = ' style="background-color: #ffffff"';

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

			}			
			for (i in option) {
				x++;
				title = option[i];
				value = xmlDoc.getElementsByTagName(i)[0].childNodes[0].nodeValue;
				if (i == 'thumbnail') {
					value = '<img src="' + value + '" alt="Thumbnail Not Available" />';
				}
				if (i == 'resultsAltaVista') {
						value = '<a href=\"http://www.altavista.com/web/results?q=' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				if (i == 'resultsAllTheWeb') {
						value = '<a href=\"http://www.alltheweb.com/search?q=' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				if (i == 'resultsWikipedia') {
						value = '<a href=\"http://search.yahoo.com/search?p=linkdomain%3A' + window.encodeURI(url) + '+site:wikipedia.org\" target="_blank">' + value + '</a>';
					} 
				if (i == 'resultsDelicious') {
						value = '<a href=\"http://del.icio.us/url/?url=' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				if (i == 'resultsTechnorati') {
						value = '<a href=\"http://www.technorati.com/search/' + window.encodeURI(url) + '\" target="_blank">' + value + '</a>';
					} 
				style = ' style="background-color: #ffffff"';
				el['results'].innerHTML += '<div' + style + '><span class="links">' + value + '</span>' + title + '<b class="clear"></b></div>';
			}			
			
			
		} else {
				style = ' id="toolinfo"';		  
			el['results'].innerHTML = '<div' + style + '><img src="http://www.smegoconsulting.com/tools/multiple/images/loading.gif" /> Results are loading. Please Wait.</div>';
		}
	}
	xml.send(null);
}