// Browser Class

Browser = function() {
	this.appVersion = navigator.appVersion.toLowerCase();
	this.userAgent 	= navigator.userAgent.toLowerCase();
	this.appName	= navigator.appName.toLowerCase();

	this.mac	= (this.appVersion.indexOf("mac")>=0);
	this.win	= (this.appVersion.indexOf("win")>=0);
	this.xwin	= (this.appVersion.indexOf("x11")>=0);
	
	this.opera	= (this.userAgent.indexOf('opera')>=0);
	this.safari	= (this.userAgent.indexOf('safari')>=0);
	this.gecko	= ((this.userAgent.indexOf('gecko')>=0) && (!this.opera));
	this.ie		= ((this.userAgent.indexOf('msie')>=0) && (!this.opera));
	this.ns		= (document.layers);
	
	this.ver 	= 0;
	if (this.opera) this.ver = parseFloat(this.userAgent.slice(this.userAgent.indexOf('opera')+6));
	if (this.gecko) this.ver = parseFloat(this.appVersion);
	if (this.ie) this.ver = parseFloat(this.userAgent.slice(this.userAgent.indexOf('msie')+5));
	if (this.ns) this.ver = parseFloat(this.appVersion);
	
	this.compatible=((this.ie && (this.ver>=4)) || (this.ns && (this.ver>=4.04)) || (this.gecko) || (this.opera && (this.ver>=6)));
	
	if (this.ns) {
		var openPageWidth = innerWidth;
		var openPageHeight = innerHeight;
		onresize = this.nsResizeReload;
	}

	this.nsResizeReload = function() {
		if (this.openPageWidth != innerWidth || this.openPageHeight != innerHeight) location.reload();
	}
	
	this.width = function() {
		if (this.ie || this.opera) return document.body.clientWidth;
		else if (this.gecko)	return self.innerWidth;
		else return window.innerWidth-20;
	}
	this.height = function() {
		if (this.ie || this.opera) return document.body.clientHeight;
		else if (this.gecko)	return self.innerHeight;
		else return self.innerHeight-20;
	}
	this.docWidth = function() {
		if (this.ie) return document.body.scrollWidth;
		else if (this.opera) return document.body.style.width;
		else return document.width;
	}
	this.docHeight = function() {
		if (this.ie) return document.body.scrollHeight;
		else if (this.opera) return document.body.style.height;
		else return document.height;
	}
	this.scrollX = function () {
		if (this.ie) return document.body.scrollLeft;
		else return self.pageXOffset;
	}
	this.scrollY = function () {
		if (this.ie) return document.body.scrollTop;
		else return self.pageYOffset;
	}
}

// Layer Class

Layer = function(elementId) {

	this.elementId = elementId;
	
	this.getElement = function() {
		if (browser.gecko || browser.opera) return document.getElementById(this.elementId);
		else if (browser.ns) return document.layers[this.elementId];
		else return document.all[this.elementId];
	}
	
	this.moveTo = function(x, y) {
		this.element = this.getElement(this.elementId);
		if(!x) x = this.x();
		if(!y) y = this.y();
	
		if (browser.gecko) {
			this.element.style.left = x+"px";
			this.element.style.top = y+"px";
		} else if (browser.ns) {
			this.element.moveTo(x, y);
		} else {
			this.element.style.pixelLeft = x;
			this.element.style.pixelTop = y;
		}
	}
	
	this.x = function(x) {
		if(x) this.moveTo(x,null);
		this.element = this.getElement(this.elementId);
		if (browser.gecko) return parseInt(this.element.style.left);
		else if (browser.ns) return this.element.left;
		else return this.element.offsetLeft;
	}

	this.y = function(y) {
		if(y) this.moveTo(null,y);
	
		this.element = this.getElement(this.elementId);
		if (browser.gecko) return this.element.style.top;
		else if (browser.ns) return this.element.top;
		else return this.element.offsetTop;
	}
	
	this.display = function(d) {
		this.element = this.getElement(this.elementId);

		if (browser.gecko) {
			if(d) this.element.style.display=d;
			return this.element.style.display;
		}
		else if (browser.ns) {
			if(d) this.element.display=d;
			return this.element.display;
		}
		else {
			if(d) this.element.style.display=d;
			return this.element.style.display;
		}
	}

	this.width = function(w) {
		if(w) this.resizeTo(w,null);
	
		this.element = this.getElement(this.elementId);
		if (browser.ns) return this.element.clip.width;
		else return this.element.offsetWidth;
	}
	
	this.html = function(c) {
		this.element = this.getElement(this.elementId);
		this.element.innerHTML = c;
	}

	this.height = function(h) {
		if(h) this.resizeTo(null,h);
	
		this.element = this.getElement(this.elementId);
		if (browser.ns) return this.element.clip.height;
		else return this.element.offsetHeight;
	}

	this.show = function() {
		this.element = this.getElement(this.elementId);
		if (browser.ns) this.element.visibility = "show";
		else this.element.style.visibility = "visible";
	}

	this.hide = function() {
		this.element = this.getElement(this.elementId);
		if (browser.ns) this.element.visibility = "hide";
		else this.element.style.visibility = "hidden";
	}

	this.resizeTo = function(w, h, clip) {
		this.element = this.getElement(this.elementId);
		
		if(!w) w = this.width();
		if(!h) h = this.height();
		
		if (browser.gecko) {
			this.element.style.pixelWidth = w+"px";
			this.element.style.pixelHeight = h+"px";
		} else if (browser.ns) {
			this.element.resizeTo(w,h);
		} else {
			this.element.style.pixelWidth = w;
			this.element.style.pixelHeight = h;
		}
		if (clip) this.clipTo(0,0,w,h);
	}

	clipTo = function(x, y, w, h) {
		this.element = this.getElement(this.elementId);
		if (browser.ns) {
			this.element.clip.left = x;
			this.element.clip.top = y;
			this.element.clip.width = w;
			this.element.clip.height = h;
		} else if (!browser.opera) {
			this.element.style.clip = "rect("+y+"px "+w+"px "+h+"px "+x+"px)";
	    	this.element.style.overflow = "hidden";
		}
	}
}

function centerPopup(sUrl, sName, iWidth, iHeight, sScroll) {
	var iLeft = (screen.width - iWidth) / 2;
	var iTop = (screen.height - iHeight) / 2;
	sProps = 'height='+iHeight+',width='+iWidth+',top='+iTop+',left='+iLeft+',scrollbars='+sScroll;
	win = window.open(sUrl, sName, sProps)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}