function newWindow(uri, width, height){
	var screenWidth = window.screen.availWidth;
	var screenHeight = window.screen.availHeight;
	var left = (screenWidth-width)/2;
	var top = (screenHeight-height)/2;	
	window.open(uri,'', 'status=no,location=no,toolbar=no,scrollbars=no,directories=no,resizable=yes,menubar=no,width='+width+',height='+height+",left="+left+",top="+top);
}

function Is(){
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && 
        ((agent.indexOf('spoofer')==-1) && 
        (agent.indexOf('compatible') == -1)));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ie = (agent.indexOf("msie") != -1);
    this.ie4 = (this.ie && (this.major >= 4));
	if(!this.ns) this.ie4=true;
}

var is = new Is();
var dynObjOK = (is.ns4 || is.ie4)? true : false;

function DynLayer(id,nestref){
	if (is.ns4){
		this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id];
		this.elm = this.css;
		this.doc = this.css.document;
	    	this.x = this.css.left;
	    	this.y = this.css.top;
	    	this.w = this.css.clip.width;
	    	this.h = this.css.clip.height;
	}
	else if (is.ie4) {
		this.elm = document.all[id];
		this.css = this.elm.style;
		this.doc = document;
		this.x = this.elm.offsetLeft;
		this.y = this.elm.offsetTop;
		this.w = this.elm.offsetWidth;
		this.h = this.elm.offsetHeight;
	}
	this.id = id;
	this.nestref = nestref;
	this.obj = id + "DynLayer";
	eval(this.obj + "=this");
}

function DynLayerMoveTo(x,y){
	if(x!=null){
		this.x = x;
		if (is.ns) this.css.left = this.x;
		else this.css.pixelLeft = this.x;
	}
	if(y!=null){
		this.y = y;
		if (is.ns) this.css.top = this.y;
		else this.css.pixelTop = this.y;
	}
}

function DynLayerMoveBy(x,y){
	this.moveTo(this.x+x,this.y+y);
}

DynLayer.prototype.moveTo = DynLayerMoveTo;
DynLayer.prototype.moveBy = DynLayerMoveBy;

function initMouseEvents(){
	document.onmousedown = mouseDown;
	document.onmousemove = mouseMove;
	document.onmouseup = mouseUp;
	if (is.ns) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}

initMouseEvents();

function mouseDown(e){
//	if ((is.ns && e.which!=1) || (is.ie && event.button!=1)) return true;
	var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft;
	var y = (is.ns)? e.pageY : event.y+document.body.scrollTop;
	return DynMouseDown(x,y);
}

function mouseMove(e){
	var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft;
	var y = (is.ns)? e.pageY : event.y+document.body.scrollTop;
	if (is.ns && e.target!=document) routeEvent(e);
	return DynMouseMove(x,y);
}

function mouseUp(e){
	var x = (is.ns)? e.pageX : event.x+document.body.scrollLeft;
	var y = (is.ns)? e.pageY : event.y+document.body.scrollTop;
	return DynMouseUp(x,y);
}

function DynMouseDown(x,y){return true}
function DynMouseMove(x,y){return true}
function DynMouseUp(x,y){return true}

function DynLayerSetbg(color){
	if (is.ns) this.doc.bgColor = color;
	else this.css.backgroundColor = color;
}

DynLayer.prototype.setbg = DynLayerSetbg;
