// JavaScript Document
ky_FileLoader.count=0;
ky_FileLoader.arrInst= new Array();
function ky_FileLoader()
{
	this.bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
//	this.rootdomain="http://"+window.location.hostname;
	this.bustcacheparameter="";
	this.page_request = false;
	
	this.xtimer = null;
	
	this.cName = 'ky_FileLoader';
	
	this.iIndex = ky_FileLoader.count;

	ky_FileLoader.arrInst[ky_FileLoader.count] = this;
	ky_FileLoader.count++;
	
	this.loadDone = false;
}

ky_FileLoader.prototype.ajaxpage = function (url, containerid)
{

	if (window.XMLHttpRequest) // if Mozilla, Safari etc
		this.page_request = new XMLHttpRequest()
	else if (window.ActiveXObject){ // if IE
		try {
			this.page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try{
				this.page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}
	else
		return false;
	var _index = this.iIndex;
	this.loadDone = false;
	this.page_request.onreadystatechange=function()
	{
		_me = ky_FileLoader.arrInst[_index];
		if (_me.page_request.readyState == 4 && (_me.page_request.status==200 || window.location.href.indexOf("http")==-1))
		{
			_me.loadpage(containerid);
		}
		else if (_me.page_request.readyState == 4 && (_me.page_request.status==404 || window.location.href.indexOf("http")==-1))
		{
			_me.loadnopage(containerid);
		}
	}
	
	if (this.bustcachevar) //if bust caching of external page
		this.bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
	
	this.page_request.open('GET', url+this.bustcacheparameter, true)
	this.page_request.send(null)
}

ky_FileLoader.prototype.loadpage = function (containerid)
{
	if (this.page_request.readyState == 4 && (this.page_request.status==200 || window.location.href.indexOf("http")==-1))
	{
		this.xtimer = setInterval("ky_FileLoader.arrInst["+this.iIndex+"].setPage('"+containerid+"')" , 30);
	}
}

ky_FileLoader.prototype.setPage = function(containerid)
{
	obj = document.getElementById(containerid);
	if (obj)
	{
		 clearInterval(this.xtimer);
		 val = this.page_request.responseText;
		 obj.innerHTML=val;
		this.loadDone = true;
	}
}
ky_FileLoader.prototype.loadnopage = function (containerid)
{
	this.xtimer = setInterval("ky_FileLoader.arrInst["+this.iIndex+"].setNoPage('"+containerid+"')" , 30);
}

ky_FileLoader.prototype.setNoPage = function(containerid)
{
	obj = document.getElementById(containerid);
	if (obj)
	{
		 clearInterval(this.xtimer);
		 obj.innerHTML="<p>Content not found</p>";
		this.loadDone = true;
	}
}