var IE5=(document.getElementById && document.all)? true : false;
var W3C=(document.getElementById)? true: false;
var currIDb=null, currIDs=null, xoff=0, yoff=0; zctr=500; totz=0;

function trackmouse(evt){
	if((currIDb!=null) && (currIDs!=null)){
		var x=(IE5)? event.clientX+document.body.scrollLeft : evt.pageX;
		var y=(IE5)? event.clientY+document.body.scrollTop : evt.pageY;
		currIDb.style.left=x+xoff+'px';
		currIDs.style.left=x+xoff+5+'px';
		currIDb.style.top=y+yoff+'px';
		currIDs.style.top=y+yoff+5+'px';
		return false;
	}
}
function stopdrag(){
	currIDb=null;
	currIDs=null;
	NS6bugfix();
}
function grab_id(evt){
	xoff=parseInt(this.IDb.style.left)-((IE5)? event.clientX+document.body.scrollLeft : evt.pageX);
	yoff=parseInt(this.IDb.style.top)-((IE5)? event.clientY+document.body.scrollTop : evt.pageY);
	currIDb=this.IDb;
	currIDs=this.IDs;
}
function NS6bugfix(){
	if(!IE5){
//		self.resizeBy(0,1);
//		self.resizeBy(0,-1);
	}
}
function incrzindex(){
	zctr=zctr+2;
	this.subb.style.zIndex=zctr;
	this.subs.style.zIndex=zctr-1;
}
function createPopup(id, title, width, height, x , y , isdraggable, text){
	if(W3C){
		zctr+=2;
		totz=zctr;
		var txt='';
		txt+='<div id="'+id+'"  style="cursor: hands"><div id="'+id+'_s" style="position:absolute; left:'+(x+5)+'px; top:'+(y+5)+'px; width:'+width+'px; height:'+height+'px; background: silver; filter:alpha(opacity=50); visibility:visible; z-index: 500;">&nbsp;</div>';
		txt+='<div id="'+id+'_b" style="border: 1px solid black; position:absolute; background: white; left:'+x+'px; top:'+y+'px; visibility:visible; z-index: 500;">';
		txt+='<div id="'+id+'_ov">'+text+'</div></div></div>';
		document.write(txt);
		this.IDh=document.getElementById(id);
		this.IDh.IDb=document.getElementById(id+'_b');
		this.IDh.IDs=document.getElementById(id+'_s');
		this.IDh.IDb.subs=this.IDh.IDs;
		this.IDh.IDb.subb=this.IDh.IDb;
		this.IDh.IDb.IDov=document.getElementById(id+'_ov');
		if(IE5){
			this.IDh.IDb.IDov.style.width=width-6;
			this.IDh.IDb.IDov.style.height=height-6;
//			this.IDh.IDb.IDov.style.overflow="auto";
		}else{
			this.IDh.IDs.style.MozOpacity=.5;
		}
		this.IDh.IDb.onmousedown=incrzindex;
		if(isdraggable){
			this.IDh.onmousedown=grab_id;
			this.IDh.onmouseup=stopdrag;
		}
	}
}

if(W3C)document.onmousemove=trackmouse;
if(!IE5 && W3C)window.onload=NS6bugfix;

function popupMax (url, nome, largura, altura, pos, barras, resize) {
	if (pos == 0) {
		posleft = 20;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (pos == 1) {
		posleft = (screen.width) ? (screen.width - largura) / 2 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	} else if (pos == 2) {
		posleft = (screen.width) ? (screen.width - largura) - 28 : 100;
		postop  = (screen.height) ? (screen.height - altura) / 2 - 50 : 100;
	}
	if (barras == true) opbarras = "yes"; else opbarras = "no";
	if (resize == true) opresize = "yes"; else opresize = "no";

	settings = 'width=' + largura + ', height=' + altura + ', top=' + postop + ', left=' + posleft + ', scrollbars=' + opbarras + ', location=no, directories=no, status=no, menubar=no, toolbar=no, resizable='+opresize;
	window.open(url, nome, settings);
}

