var ipexits = 0;
var gpexits = {};
function fdebugout(debugstr)
{
	var d = document.getElementById('debugbox');
	if ((d) && (d.insertBefore))
	{
		nc = document.createElement('br');
		d.insertBefore(nc,d.firstChild);
		var nc = document.createTextNode(Next++ +' '+debugstr);
		d.insertBefore(nc,d.firstChild);
	}
	var d = document.getElementById('debugboxswitch');
	if ((d)&&(d.style) )
		d.style.display='';
}

function XMLRequest(areadyfunc)
{
	this.xmlHttpReq = false;
	if (window.XMLHttpRequest)
	{
			this.xmlHttpReq = new XMLHttpRequest();
			if (this.xmlHttpReq.overrideMimeType)
				this.xmlHttpReq.overrideMimeType('text/xml');
			this.enabled = ((this.xmlHttpReq) && (this.xmlHttpReq.onreadystatechange === null));
	}
	else if (window.ActiveXObject)
		this.enabled = (this.xmlHttpReq = new ActiveXObject('Microsoft.XMLHTTP'));
	this.readyfunc = areadyfunc;
	this.src = '';
}

XMLRequest.prototype.setSrc = function(newsrc)
{
	this.src = newsrc;
}

//example ready state function
XMLRequest.prototype.readystatechange = function()
{
		/*
		if (<XMLRequestobject>.getStatus() == 4)
		{
			//do stuff
		}*/
		
}
XMLRequest.prototype.send = function(querydata)
{
		//this.debugout(this.src+'&'+querydata);
		if (this.enabled)
		{
			this.xmlHttpReq.open('POST',this.src,true);
			this.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			
			this.xmlHttpReq.onreadystatechange = this.readyfunc;
			this.xmlHttpReq.send(querydata);
												
		}
}

XMLRequest.prototype.getStatus = function()
{
	return this.xmlHttpReq.readyState;
}
var Next = 0;
XMLRequest.prototype.resetdebug = function ()
{
	var d = document.getElementById('debugbox');
	if ((d) && (d.firstChild)) 
	{
		while (d.firstChild) 
		{
			d.removeChild(d.firstChild);
		}
	}
}

XMLRequest.prototype.debugout = fdebugout;
function PageExit(elem)
{
	this.href = elem.href;
	this.elem = elem;
}

function PageExits()
{
	this.pexits = new Array();
	this.index = ipexits++;
	gpexits[this.index] = this;
	var func = new Function('gpexits['+this.index+'].getExits();');
	try {window.attachEvent('onload',func)} catch (e) {}
	try {window.addEventListener('load',func,false);}	catch (e){}

}

PageExits.prototype.getExits = function()
{
	links = document.body.getElementsByTagName('A');
	
	for (i = 0;i < links.length;i++)
	{
		if (links[i].href != '')
		{
			//if (!links[i].id)
			//	links[i].id = 'exit'+i;
			this.pexits[i] = new PageExit(links[i]);
		}
	}
}
PageExits.prototype.getExit = function(wrapstring,pexit)
{
	wrapstring = wrapstring.replace(/%id%/g,pexit.elem.id);
	wrapstring = wrapstring.replace(/%href%/g,pexit.href);
	return wrapstring;
}
PageExits.prototype.fixExits = function (wrapstring)
{
	for (i = 0;i<this.pexits.length;i++)
		this.pexits[i].elem.href = this.getExit(wrapstring,this.pexits[i]);
}


