function getHost(url,handler) {
	this.url=url
	this.errorstring=''
	this.handler=handler
	this.answer=''
	this.ans=new Array()
	this.row=0
	this.rows=0
	this.EOF=true
	this.BOF=true
	this.args=new Array()
	this.state=new Array()
	this.moveNext=function() {
		this.row++
		this.BOF=false
		if (this.row>this.rows) {
			this.row=this.rows
			this.EOF=true
		}
	}
	this.movePrev=function() {
		this.row--
		this.EOF=false
		if (this.row<0) {
//			this.row=this.rows
			this.BOF=true
		}
	}
	this.moveFirst=function() {
		this.row=0
		this.EOF=false
	}
	this.moveLast=function() {
		this.row=this.rows
	}
	this.read=function(col) {
		if (this.EOF) {return 'EOF'}
		if (this.BOF) {return 'BOF'}
		return this.ans[this.row][col]
	}
	this.saveAnswer=function(answer,xml) {
		xml.answer=answer
		splt1=answer.split('|')
		xml.rows=splt1.length-1
		for (var i=0;i<splt1.length;i++) {
			splt2=splt1[i].split('^')
			xml.ans[i]=new Array()
			for (var j=0;j<splt2.length;j++) {
				xml.ans[i][j]=rDecodeAll(splt2[j],false)
			}
		}
		if (xml.ans[xml.rows].length==1 && xml.ans[xml.rows][0]=='') {xml.rows=xml.rows-1}
		if (xml.rows>-1) {
			xml.EOF=false
			xml.BOF=false
			xml.row=0
		}
	}
	this.setreadystatehandler=function(xml,handler) {
		xml.XMLHTTP.onreadystatechange=function() { 
			if (xml.XMLHTTP.readyState==4) {
				if (xml.XMLHTTP.status==200) {
						xml.saveAnswer(xml.XMLHTTP.responseText,xml)
						return handler(xml)
				}
				else {
					return xml.retry()
				}
			}
		}
	}
	this.retrycount=3
	this.retry=function() {
		if (xml.retrycount>0) {
			xml.retrycount=xml.retrycount-1
			xml.makeXMLHTTP()
			xml.setreadystatehandler(xml,handler)
			xml.exec()
		}
		else {
			if (xml.errorstring=='')
			{
				alert('Unable to contact the server. Please try again!')
			}
			else
			{
				alert(xml.errorstring)
			}
		}
	}
	var xml=this
	
	this.makeXMLHTTP=function() {
		xml.XMLHTTP = false;

		try
		{
			xml.XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xml.XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E)
			{
				xml.XMLHTTP = false;
			}
		}

		if (!xml.XMLHTTP && typeof XMLHttpRequest!='undefined')
		{
			xml.XMLHTTP = new XMLHttpRequest();
		}
	}
	this.makeXMLHTTP()
	this.setreadystatehandler(xml,handler)
	
	this.exec=function() {
		this.args.url=this.url
		var d=new Date()
		var data=''
		for (arg in this.args) {
			data+="&" + arg + "=" + rEncodeAll(this.args[arg],false) 
		}
				this.XMLHTTP.open( "GET", xml.url+ '?d=' + d + data, true);
		try {
			xml.XMLHTTP.send(null)
		}
		catch (e) {
			return(e.number)
		}
	}
}
function $(obj) {
	return document.getElementById(obj);
}
function replaceAll( str, from, to ) {
	str=''+str
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    return str;
}

function rEncodeAll(str,bDoSpace)
{
	str=replaceAll(str,'\n','')
	str=replaceAll(str,'\r',' ')
	str=replaceAll(str,'&','*amp*')
	str=replaceAll(str,'\'','*ap*')
	str=replaceAll(str,'|','*pipe*')
	str=replaceAll(str,'^','*caret*')
	str=replaceAll(str,'"','*quot*')
	if (bDoSpace)
	{
		str=replaceAll(str,' ','*sp*')
	}
	return str
}
function rDecodeAll(str,bDoSpace)
{
	str=replaceAll(str,'*ap*','\'')
	str=replaceAll(str,'*amp*','&')
	str=replaceAll(str,'*pipe*','|')
	str=replaceAll(str,'*caret*','^')
	str=replaceAll(str,'*quot*','"')
	if (bDoSpace)
	{
		str=replaceAll(str,'*sp*',' ')
	}
	return str
}