/*******************************************************
************		Copyright notice		************
* This software belongs to Elite Sport Ltd. All rights *
* reserved. This software may not be freely distributed*
* and must only be used under terms of licence.        *
* For more information, visit elite-sport.com          *
*******************************************************/

//Buffered writing functions
echo=unbufferwrite;
buffer="";
function bufferwrite(text)
{
	buffer+=text;
}

function unbufferwrite(text)
{
	document.write(text);
}

function bufferon()
{
	buffer="";
	echo=bufferwrite;
}

function bufferoff()
{
	echo=unbufferwrite;
	return buffer;
}


function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
var detect=navigator.userAgent.toLowerCase();
var platform,browser,version,total,thestring;
if(checkIt('konqueror'))
{
	browser="konq";
	platform="linux";
}
else if(checkIt('safari'))browser="safari";
else if(checkIt('omniweb'))browser="omniweb";
else if(checkIt('opera'))browser="opera";
else if(checkIt('webtv'))browser="webtv";
else if(checkIt('icab'))browser="icab";
else if(checkIt('msie'))browser="ie";
else if(!checkIt('compatible'))
{
	if(checkIt('netscape'))browser="nn";
	else
	{
		//Gecko or something, call it nn and use Mozilla version
		browser="nn"
		version=detect.charAt(8);
	}
}
else browser="unknown";

if(!version)version=detect.charAt(place + thestring.length);

if (!platform)
{
	if (checkIt('linux')) platform = "linux";
	else if (checkIt('x11')) platform = "unix";
	else if (checkIt('mac')) platform = "mac"
	else if (checkIt('win')) platform = "win"
	else platform = "unknown";
}

function getbroswer()
{
	if(document.getElementById)return "dom";
	if(document.all)return "ie4";
	if(document.layers)return "ns4";
	return "";
}
type=getbroswer();

ns4=false;
if(type=="ns4")ns4=true;

function layercreate(id,classname,other,content,link,linkother)
{
	if(ns4)return;
	this._id=id;
	if(!classname)classname="";
	if(!other)other="";
	if(!content)content="";
	if(!link)link="";
	if(!linkother)linkother="";
	/*if(type=="ns4")
	{
		echo("<LAYER id=\""+id+"\" class=\""+classname+"\""+other+">"+content+"</LAYER>");
	}*/
	if(type=="ie4" || type=="dom")
	{
		if(link!="")echo("<A "+linkother+" HREF=\""+link+"\">");
		echo("<DIV id=\""+id+"\" class=\""+classname+"\" "+other+">"+content+"</DIV>");
		if(link!="")echo("</A>");
	}
}

function layerattach(id)
{
	this._id=id;
}

function layersethtml(html)
{
	if(ns4)return;
	if(type=="ns4")
	{
		document.layers[this._id].document.open();
		document.layers[this._id].document.write(html);
		document.layers[this._id].document.close();
	}
	if(type=="ie4")
	{
		document.all[this._id].innerHTML=html;
	}
	if(type=="dom")
	{
		document.getElementById(this._id).innerHTML=html;
	}
}

function layersetevent(eventname,func)
{
	if(type=="ns4")
	{
		eval("document.layers[this._id].on"+eventname+"="+func+";");
	}
	if(type=="ie4")
	{
		eval("document.all[this._id].on"+eventname+"="+func+";");
	}
	if(type=="dom")
	{
		if(document.all)
		{
			document.getElementById(this._id).attachEvent("on"+eventname,func);
		}
		else
		{
			document.getElementById(this._id).addEventListener(eventname,func,true);
		}
	}
}

function layergetobj()
{
	if(type=="ie4")
	{
		return document.all[this._id];
	}
	if(type=="dom")
	{
		return document.getElementById(this._id);
	}
}

function layergetstyleobj()
{
	if(type=="ie4" || type=="dom")
		return this.getobj().style;
}

function layersetvis(vis)
{
	if(vis)
		this.style().visibility="visible";
	else
		this.style().visibility="hidden";
}

function layersetpos(f_x,f_y)
{
	obj=this.getobj();
	if(obj.offsetParent)
	{
		pos=layergetposofobj(obj.offsetParent);
		f_x-=pos[0];
		f_y-=pos[1];
	}
	this.style().left=f_x+"px";
	this.style().top=f_y+"px";
}

function layersetsize(w,h)
{
	if(w)this.style().width=w+"px";
	else
		this.style().width="";

	if(h)this.style().height=h+"px";
	else
		this.style().height="";
}

function layergetposofobj(obj)
{		
	if(ns4)return;
	if(type=="ns4")
	{
		f_t=obj.top;
		f_l=obj.left;
		f_h=obj.clip.height;
		f_w=obj.clip.width;
	}
	else if(browser=="opera")
	{
		f_t=obj.style.pixelTop;
		f_l=obj.style.pixelLeft;
		f_h=obj.style.pixelHeight;
		f_w=obj.style.pixelWidth;
	}
	else if(browser=="nn" && type=="dom" && version==6)
	{
		f_t=obj.offsetTop;
		f_l=obj.offsetLeft;
		f_h=obj.offsetHeight;
		f_w=obj.offsetWidth;
	}
	else
	{
		if(platform=="mac")
		{
			topM=obj.offsetParent.topMargin;
			if(!topM)topM=0;
			leftM=obj.offsetParent.leftMargin;
			if(!leftM)leftM=0;
			f_t=parseInt(topM)+obj.offsetTop;
			f_l=parseInt(leftM)+obj.offsetLeft;
		}
		else
		{
			p=obj;
			f_t=0;
			f_l=0;
			while(p)
			{
				f_t+=p.offsetTop;
				f_l+=p.offsetLeft;
				p=p.offsetParent;
			}
		}
		f_h=obj.offsetHeight;
		f_w=obj.offsetWidth;
	}
	if(browser=="konq")
	{
		f_w=parseInt(obj.style.width);
		f_h=parseInt(obj.style.height);
	}
	var pos=new Array();
	pos[0]=f_l;
	pos[1]=f_t;
	pos[2]=f_w;
	pos[3]=f_h;
	return(pos);
}

function layergetpos()
{
	if(ns4)return;
	obj=this.getobj();
	return layergetposofobj(obj);
}

function Layer(id)
{
	if(id)
		this._id=id;
	else
		this._id="";
}

Layer.prototype.create=layercreate;
Layer.prototype.sethtml=layersethtml;
Layer.prototype.setevent=layersetevent;
Layer.prototype.setvis=layersetvis;
Layer.prototype.style=layergetstyleobj;
Layer.prototype.attach=layerattach;
Layer.prototype.getobj=layergetobj;
Layer.prototype.getpos=layergetpos;
Layer.prototype.setpos=layersetpos;
Layer.prototype.setsize=layersetsize;


