function $S() {
	if (arguments.length == 1){
		if(typeof arguments[0] == 'string') {
			if (arguments[0].charAt(0) == '#' && arguments[0].indexOf(' ') == -1) 
				return $(arguments[0].slice(1)) || null;
			return dom.getSelector(arguments[0]);
		}
		else return arguments[0];
	}
	var elements = [];
	arguments.each(function(sel){
		if (typeof sel == 'string') {
			dom.getSelector(sel).each(function(el){
				elements.push(el);
			});
		}
		else elements.push(sel);
	});
	return elements;
}

function $e(array){
	var nArray = [];
	for (i=0;el=array[i];i++) nArray.push(el);
	return nArray;
}

Array.prototype.each = function(func){
	for(var i=0;ob=this[i];i++) func(ob, i);
}

Array.prototype.action = function(actions){
	this.each(function(el){
		if (actions.initialize) actions.initialize(el);
		for(action in actions){
			if (action.slice(0,2) == 'on') el[action] = actions[action];
		}
	});
}

Array.prototype.find = function(mode){
	var elements = [];
	this.each(function(el){
		el = el[mode];
		while (el.nodeType != 1) el = el[mode];
		elements.push(el);
	});
	if (elements.length == 1) return elements[0];
	return elements;
}

dom = {
	getSelector: function(selector){		
		var params = [];
		selector.split(' ').each(function(arg, j){
			params[j] = param = [];
			if (arg.indexOf('#') > -1) {
				var bits = arg.split('#');
				param['tag'] = bits[0] || '*';
				param['id'] = bits[1];
			}
			else if (arg.indexOf('.') > -1) {
				var bits = arg.split('.');
				param['tag'] = bits[0] || '*';
				param['class'] = bits[1];
			}
			else param['tag'] = arg;
		});
		this.filter = [document];
		params.each(function(param, k){
			if (k == 0 && param['id']) {
				var id = $(param['id']);
				if (param['tag'] == '*' || id.tagName.toLowerCase() == param['tag'])
					this.filter = [id];
				else return [];
			}
			else {
				this.filter = this._getElementsWithTagName(param['tag']);
				if (param['class']) this.filter = this._getElementsWithClassName(param['class']);
				else if (param['id']) this.filter = this._getElementsWithId(param['id']);
			}
		}.bind(this));
		return this.filter;
	},

	sheets: [],

	append: function(sheet){
		this.sheets.push(sheet);
	},

	start: function(){
		this.sheets.each(function(sheet){
			this.update(sheet);
		}.bind(this));
	},
	
	update: function(sheet){ 
		for (selector in sheet){
			selector.split(',').each(function(comb){
				var elements = this.getSelector(comb.replace(/^\s*|\s*$/g,"")) || null;
				elements.each(function(element){
					sheet[selector](element);
				});
			}.bind(this));
		}
	},

	_getElementsWithId: function(id){
		var found = [];
		this.filter.each(function(el){
			if (el.id == id) found.push(el);
		});
		return found;
	},

	_getElementsWithClassName: function(className){
		var found = [];
		this.filter.each(function(el){
			if (Element.hasClassName(el, className)) found.push(el);
		});
		return found;
	},

	_getElementsWithTagName: function(tagName){
		var found = [];
		this.filter.each(function(el){
			$e(el.getElementsByTagName(tagName)).each(function(tn){
				found.push(tn);
			});
		});
		return found;
	}
};

var Class = {
	create: function() {
		return function() { 
			this.initialize.apply(this, arguments);
		}
	}
}

Object.extend = function(destination, source) {
	for (property in source) destination[property] = source[property];
	return destination;
}

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

Function.prototype.bindAsEventListener = function(object) {
var __method = this;
	return function(event) {
		__method.call(object, event || window.event);
	}
}

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	arguments.each(function(el){
		elements.push(get$(el));
	});
	return elements;
	
	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
}

if (!window.Element) var Element = new Object();

Object.extend(Element, {
	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var hasClass = false;
		element.className.split(' ').each(function(cn){
			if (cn == className) hasClass = true;
		});
		return hasClass;
	},

	addClassName: function(element, className) {
		element = $(element);
		Element.removeClassName(element, className);
		element.className += ' ' + className;
	},
  
	removeClassName: function(element, className) {
		element = $(element);
		if (!element) return;
		var newClassName = '';
		element.className.split(' ').each(function(cn, i){
			if (cn != className){
				if (i > 0) newClassName += ' ';
				newClassName += cn;
			}
		});
		element.className = newClassName;
	},

	cleanWhitespace: function(element) {
		element = $(element);
		$e(element.childNodes).each(function(node){
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) Element.remove(node);
		});
	}
});

var Position = {
	cumulativeOffset: function(element) {
		var valueT = 0, valueL = 0;
		do {
			valueT += element.offsetTop  || 0;
			valueL += element.offsetLeft || 0;
			element = element.offsetParent;
		} while (element);
		return [valueL, valueT];
	}
};

/*---------------------------------------------------------------------------------------------------------*/
//# [1.5kb] moo.ajax: mini ajax class
/*---------------------------------------------------------------------------------------------------------*/

ajax = Class.create();
ajax.prototype = {
	initialize: function(url, options){
		this.transport = this.getTransport();
		this.postBody = options.postBody || '';
		this.method = options.method || 'post';
		this.onComplete = options.onComplete || null;
		this.update = $(options.update) || null;
		this.request(url);
	},

	request: function(url){
		this.transport.open(this.method, url, true);
		this.transport.onreadystatechange = this.onStateChange.bind(this);
		if (this.method == 'post') {
			this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
		}
		this.transport.send(this.postBody);
	},

	onStateChange: function(){
		if (this.transport.readyState == 4 && this.transport.status == 200) {
			if (this.onComplete) 
				setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
			if (this.update) 
				setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10);
			this.transport.onreadystatechange = function(){};
		}
	},

	getTransport: function() {
		if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
		else if (window.XMLHttpRequest) return new XMLHttpRequest();
		else return false;
	}
};
function isUndefined(a)
{
	return typeof a == 'undefined';
}
function postproc(reponse)
{
	try
	{
		items = eval(reponse.responseText);		
		if(items[0].sts==1)
		{
			if(!isUndefined(items[0].hostbox))
			{
				$('hostbox').value = items[0].hostbox;
			}
			if(isUndefined(items[0].cts) || isUndefined(items[0].ctf))
			{
				items[0].cts = '--';
				items[0].ctf = 'Unknown country.';
			}
			outputstr = '<div class="ipaddr">'+items[0].hostname+'</div><div class="cts"><img src="http://www.xenolith0.net/images/flags/'+items[0].cts+'.gif" width="18" height="12" title="'+items[0].ctf+'" alt="'+items[0].ctf+'"> '+items[0].ctf+'</div>';
			if(!isUndefined(items[0].knownprx))
			{
				outputstr += '<div class="isprx">Is known http/https proxy.</div>';
			}
			if(!isUndefined(items[0].ws))
			{
				outputstr += '<div class="whoisdata">'+items[0].ws+'</div>';
			}
			outputstr += '<div class="linky"><a href="http://www.xenolith0.net/ip2loc/njif.do/hostbox/'+items[0].linky+'">Perma Link</a></div>';
			$('results').innerHTML = outputstr;
		}
		else if(items[0].sts==2)
			$('results').innerHTML = '<div class="error">Invalid IP address or Host.</div>';
	}
	catch(error)
	{
		$('results').innerHTML = error.description;		
	}
}

function form_submission()
{
	new ajax ('http://www.xenolith0.net/ip2loc/if.do', {postBody: 'hostbox='+escape($('hostbox').value), onComplete: postproc});
	$('results').innerHTML = '<img src="http://www.xenolith0.net/ip2loc/bouncer.gif" height="16" width="16" alt="Loading..." title="Loading">Please Standby...';
	return true;
}