var IntWinDebug = false;
var WinDebug = false;
var xwin = null;

function RemovePrefix(str,pre)
{
	s = new String(str);
	pr = new String(pre);
  	p=s.indexOf(pre);
  	if (p!=-1)
  	{
	    s2=s.substring(0,p)+s.substring(p+pr.length);
	}
	else
	{
	  s2=str;
	}
	return s2;
}
SCIWindow = function () 
{
	this.x = 0;
	this.y = 0;
	this.cx = 400;
	this.cy = 250;
	this.divobj = null;
	this.divintobj = null;

	this.diviframeobj = null;
	this.iframeobj = null;

	this.divcaptionobj = null;
	this.divcaptiontableobj = null;
	this.divtitleobj = null;

	this.divstatusobj = null;

//=========================================================================
//TENTATIVA DE SOLUCIONAR PROBLEMA COM COMBO
//=========================================================================
	this.iframecaptionobj = null;
	this.iframestausobj = null;
//=========================================================================

	this.divstatustableobj = null;
	this.divstatusLoadobj = null;
	this.divstatuscellobj = null;
	
	
	this.winstyle = sciwindow_defautstyle(this);
	
	this.onclosewindow = null;
	this.ondestroywindow  = null;
	this.winscount = 0;
	this.pos = 0;
	this.pai = null;
	this.Execute = false;
	this.hideManta = false;

};
SCIWindow.prototype.addEvent = function(el, evname, func) 
{
	//alert('is_ie'+this.is_ie);
	if (this.is_ie) {
		el.attachEvent("on" + evname, func);
	} else {
		el.addEventListener(evname, func, true);
	}
};
SCIWindow.prototype.removeEvent = function(el, evname, func) 
{
	//alert('is_ie'+this.is_ie);
	if (this.is_ie) {
		el.detachEvent("on" + evname, func);
	} else {
		el.removeEventListener(evname, func, true);
	}
};
SCIWindow.prototype._InternalWindow = null;
SCIWindow.prototype.is_ie = ( (navigator.userAgent.toLowerCase().indexOf("msie") != -1) &&
		    (navigator.userAgent.toLowerCase().indexOf("opera") == -1) );
SCIWindow.prototype.getAbsolutePos = function(el) 
{
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = this.getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
};
SCIWindow.prototype.getElement = function(ev) 
{
	if (this.is_ie) 
	{
		return window.event.srcElement;
	}
	else
	{
		return ev.currentTarget;
	}
};
SCIWindow.prototype.show = function () 
{
//	this.winstyle.caption.buttons.close.showBtn();
	this.winstyle.caption.buttons.showBtns();
	this.winstyle.status.buttons.showBtns();
	this.divobj.style.display = "block";
//	this.winstyle.caption.buttons.close.showBtn();
	this.winstyle.caption.buttons.showBtns();
	this.winstyle.status.buttons.showBtns();
	//this.divobj.style.visibility = "visible";
//	this.hideShowCovered();
};

SCIWindow.prototype.hide = function () 
{
	if (this.hideManta)
	{
		SCIWins.hideManta();
		this.hideManta=false;
	}
	this.hideLoading();
	this.divobj.style.display = "none";
};
SCIWindow.prototype.Print = function () 
{
	iframe=this.iframeobj;
	if (IS_IE)
	{
		iframe.contentWindow.focus();
	   	iframe.contentWindow.print();
	}
	else
	{
	   	iframe.contentWindow.print();
	/*	pb=iframe.contentWindow.document.body;
		pw=window.open('','print');
		pw.document.open();
		pw.document.write(pb.innerHTML);
		pw.print();
		pw.document.close();
		pw.close();
	*/
	}
}
SCIWindow.prototype.Reload = function () 
{
  	this.iframeobj.contentWindow.location.reload(true);
}
SCIWindow.prototype.IsVisible = function () 
{
	if (this.divobj.style.display == "none")
	{
		return false;
	}
	else
	{
		return true;
	}
};
SCIWindow.prototype.showAt = function (x, y) 
{
	this.move(x, y);
	this.show();
};
SCIWindow.prototype.showAtElement = function (el) 
{
	this.element=el;
	var p = this.getAbsolutePos(el);
//	var p = this.getAbsolutePos(el);
	this.showAt(p.x, p.y + el.offsetHeight);
};
SCIWindow.prototype.create = function (x,y,cx,cy,scroll,framename,vparent) 
{
	// ==============================================================
	// função para criar uma celula da tabela
	// ==============================================================
//	var cell = null;
	var row = null;
	var thead = null;
	var hh = function (text, cs, navtype) 
	{
		cell = document.createElement("td");
		row.appendChild(cell);
		cell.colSpan = cs;
		cell.className = "button";
		cell.win = win;
		cell.navtype = navtype;
		if (text.substr(0, 1) != '&') 
		{
			cell.appendChild(document.createTextNode(text));
		}
		else 
		{
			// FIXME: dirty hack for entities
			cell.innerHTML = text;
		}
		return cell;
	};
	// ==============================================================

	var win = this;

	(x!=null) ? this.x = x : b=0;
	(y!=null) ? this.y = y : b=0;
	(cx!=null) ? this.cx = cx : b=0;
	(cy!=null) ? this.cy = cy : b=0;

	if (! vparent) 
	{
		pai = document.getElementsByTagName("body")[0];
		this.winstyle.ispopup = true;
	} else {
		pai = vparent;
		this.winstyle.ispopup = false;
	}
	
	this.winscount=this.winscount+1;

	// Criando div principal da janela
	var div = document.createElement("div");
	div.win=this;
	div.style.display = "none";
	div.style.overflow="hidden";
	div.style.backgroundColor=this.winstyle.borderbgcolor;
	div.style.zIndex=1000+this.winscount;
	this.divobj = div;	
	div.className = "SCIWindow";
	if (this.winstyle.ispopup)
	{
		div.style.position = "absolute";
//		div.style.display = "none";
	}

	// Criando div interna da janela (definição de borda)
	var divint = document.createElement("div");
//	divint.win=this;
//	divint.style.display = "none";
	divint.style.overflow="hidden";
	divint.style.backgroundColor=this.winstyle.borderbgcolorinternal;
	divint.style.position = "relative";
	this.divintobj = divint;	
	divint.className = "SCIWindow_int";
	this.divobj.appendChild(this.divintobj);

	// ==============================================================
	// title bar
	// ==============================================================
	// Criando div titulo da janela
	var divcaption = document.createElement("div");
	divcaption.win=this;
	divcaption.style.height=this.winstyle.caption.height;
	divcaption.style.overflow="hidden";
	divcaption.style.backgroundColor=this.winstyle.caption.bgcolor;
	divcaption.style.position = "relative";
	divcaption.className = "SCIWindow_caption";
	this.divcaptionobj = divcaption;
	this.updatestyle();

//=========================================================================
//TENTATIVA DE SOLUCIONAR PROBLEMA COM COMBO
//=========================================================================
	var iframecaption = document.createElement("iframe");
	iframecaption.style.display = "block";
	iframecaption.name ='SCIWindow_frame_caption';
	if (!framename)
	{
		iframecaption.setAttribute('name','SCIWindow_frame_caption'+ this.winscount);
		iframecaption.setAttribute('id','SCIWindow_frame_caption'+ this.winscount);
	}		
	else
	{
		iframecaption.setAttribute('name',framename);
		iframecaption.setAttribute('id',framename);
	}
	iframecaption.setAttribute('left',0);
	iframecaption.setAttribute('right',0);
	iframecaption.setAttribute('marginwidth',0);
	iframecaption.setAttribute('marginheight',0);
	iframecaption.setAttribute('border',0);
	iframecaption.setAttribute('vspace',0);
	iframecaption.setAttribute('hspace',0);
	iframecaption.setAttribute('frameBorder',0);
	iframecaption.setAttribute('scrolling',scroll);
	iframecaption.src=this.winstyle.blankpage;
	iframecaption.style.position="absolute";
	iframecaption.style.left=0;
	iframecaption.style.right=0;
	iframecaption.style.borderwidth=0;
	iframecaption.style.borderstyle="solid";
	iframecaption.style.zIndex=-100;
	iframecaption.win=this;
	this.iframecaptionobj=iframecaption;
	divcaption.appendChild(iframecaption);
//=========================================================================

	//criar tabela
	var divcaptiontable = document.createElement("table");
	divcaptiontable.cellSpacing = 0;
	divcaptiontable.cellPadding = 0;
	divcaptiontable.win = this;
	divcaptiontable.width="100%";
//  Removido em testes
	divcaptiontable.height=this.winstyle.caption.defaultbuttonsheight;
//=========================================================================
//TENTATIVA DE SOLUCIONAR PROBLEMA COM COMBO
//=========================================================================
	divcaptiontable.style.backgroundColor=this.winstyle.caption.bgcolor;
//=========================================================================
	this.divcaptiontableobj=divcaptiontable;
	this.divcaptionobj.appendChild(divcaptiontable);

	//criar tabela caption (head)
	thead = document.createElement("thead");
	divcaptiontable.appendChild(thead);

	//criar linha da tabela (tr)
	row = document.createElement("tr");
	thead.appendChild(row);
	row.className = "headrow";

	//criar botoes da esquerda (td)
	for (t=0;t<this.winstyle.caption.buttons.Count();t++)
	{
	  
		bot=this.winstyle.caption.buttons.items[t];
	  	if (bot.isLeft())
	  	{
			cell = hh("", 1, 300);
			cell.width=bot.width;
			cell.className = "leftbot";
			cell.style.cursor = SYSTEM_CURSOR_HAND; //"hand";
			cell.setAttribute('SCIWinPos',this.pos);
			cell.setAttribute('BTNPOS',t);
		    cell.style.overflowX='hidden';
		    cell.style.overflowY='hidden';
/*
			cell.onmouseover=SCIWindowBtnOvr;
			cell.onmouseout=SCIWindowBtnOut;
			cell.onmousedown=SCIWindowBtnDown;
			cell.onmouseup=SCIWindowBtnUp;
*/
			//bot.imgatual.src=bot.img.src;
			cell.innerHTML='';
			//cell.appendChild(bot.imgatual);
			cell.appendChild(bot.imgDiv);
			bot.cell=cell;
			bot.win=this;
			bot.showUp();
			row.appendChild(cell);
		}
	}

	//criar titulo (td)
	this.title = hh("&nbsp;&nbsp;&nbsp;", 1, 300);
	this.title.className = "title";
	this.title.style.cursor = SYSTEM_CURSOR_MOVE;
	row.appendChild(this.title);
	var divtitle = document.createElement("div");
	divtitle.style.color = this.winstyle.caption.color;
//	this.title.cellSpacing = this.winstyle.caption.cellspacing;
	divtitle.style.margin = this.winstyle.caption.margin;
	divtitle.style.fontFamily = this.winstyle.caption.fontfamily;
	divtitle.style.fontStyle = this.winstyle.caption.fontstyle;
	divtitle.style.fontWeight = this.winstyle.caption.fontweight;
	divtitle.style.fontSize = this.winstyle.caption.fontsize;
	divtitle.style.textAlign = this.winstyle.caption.textAlign;
	divtitle.style.width="100%";
	divtitle.style.win = this;
	divtitle.innerHTML='&nbsp;&nbsp;&nbsp;';
	this.divtitleobj=divtitle;
	this.title.innerHTML='';
	this.title.appendChild(divtitle);
	
	//criar botoes da direita (td)
	for (t=0;t<this.winstyle.caption.buttons.Count();t++)
	{
	  
		bot=this.winstyle.caption.buttons.items[t];
	  	if (bot.isRight())
	  	{
			cell = hh("", 1, 300);
			cell.width=bot.width;
			cell.className = "leftbot";
			cell.style.cursor = SYSTEM_CURSOR_HAND; //"hand";
			cell.setAttribute('SCIWinPos',this.pos);
			cell.setAttribute('BTNPOS',t);
		    cell.style.overflowX='hidden';
		    cell.style.overflowY='hidden';
/*
			cell.onmouseover=SCIWindowBtnOvr;
			cell.onmouseout=SCIWindowBtnOut;
			cell.onmousedown=SCIWindowBtnDown;
			cell.onmouseup=SCIWindowBtnUp;
*/
			//bot.imgatual.src=bot.img.src;
			cell.innerHTML='';
//			cell.appendChild(bot.imgatual);
			cell.appendChild(bot.imgDiv);
			bot.showUp();
			bot.win=this;
			bot.cell=cell;
			row.appendChild(cell);
		}

	}
	// ==============================================================

	// ==============================================================
	// conteudo da janela
	// ==============================================================
	// Criando div interna da janela (definição de borda)
	var diviframe = document.createElement("div");
	diviframe.win=this;
	diviframe.backgroundColor=this.winstyle.borderbgcolorinternal;
	diviframe.style.display = "none";
	diviframe.style.overflow="hidden";
	diviframe.style.position = "absolute";
	diviframe.setAttribute('id','SCIWindow_DIV_frame'+ this.winscount);
	diviframe.setAttribute('name','SCIWindow_DIV_frame'+ this.winscount);
	this.diviframeobj=diviframe;

	// Criando iframe da janela (frame da janela)
	var iframe = document.createElement("iframe");
	iframe.style.display = "block";
	iframe.name='SCIWindow_frame';
	if (!framename)
	{
		iframe.setAttribute('name','SCIWindow_frame'+ this.winscount);
		iframe.setAttribute('id','SCIWindow_frame'+ this.winscount);
	}		
	else
	{
		iframe.setAttribute('name',framename);
		iframe.setAttribute('id',framename);
	}
	iframe.setAttribute('marginwidth',0);
	iframe.setAttribute('marginheight',0);
	iframe.setAttribute('border',0);
	iframe.setAttribute('vspace',0);
	iframe.setAttribute('hspace',0);
	iframe.setAttribute('frameBorder',0);
	iframe.setAttribute('scrolling',scroll);
//	iframe.setAttribute('onload','alert("load");');
/*	if (scroll)
	{
		iframe.setAttribute('scrolling','auto');
	}
	else
	{
		iframe.setAttribute('scrolling','no');
	}
*/
	iframe.src=this.winstyle.blankpage;
	iframe.style.borderwidth=0;
	iframe.style.borderstyle="solid";
	iframe.win=this;
	this.iframeobj=iframe;
	diviframe.appendChild(iframe);
	

	pai.appendChild(this.divobj);
	if (this.winstyle.caption.visible)
	{
		divint.appendChild(divcaption);
	}
	divint.appendChild(diviframe);
	// ==============================================================

	// ==============================================================
	// status bar
	// ==============================================================
	// Criando div status da janela
	var divstatus = document.createElement("div");
	divstatus.win=this;
	divstatus.style.height=this.winstyle.status.height;
	divstatus.style.overflow="hidden";
	divstatus.style.backgroundColor=this.winstyle.status.bgcolor;
	divstatus.style.position = "absolute";
	divstatus.style.left=0;
	divstatus.style.top=0;
//	divstatus.style.verticalalign = "bottom";

	divstatus.className = "SCIWindow_status";
	this.divstatusobj = divstatus;

//=========================================================================
//TENTATIVA DE SOLUCIONAR PROBLEMA COM COMBO
//=========================================================================
	var iframest = document.createElement("iframe");
	iframest.style.display = "block";
	iframest.name ='SCIWindow_frame_status';
	if (!framename)
	{
		iframest.setAttribute('name','SCIWindow_frame_status'+ this.winscount);
		iframest.setAttribute('id','SCIWindow_frame_status'+ this.winscount);
	}		
	else
	{
		iframest.setAttribute('name',framename);
		iframest.setAttribute('id',framename);
	}
	iframest.setAttribute('left',0);
	iframest.setAttribute('right',0);
	iframest.setAttribute('marginwidth',0);
	iframest.setAttribute('marginheight',0);
	iframest.setAttribute('border',0);
	iframest.setAttribute('vspace',0);
	iframest.setAttribute('hspace',0);
	iframest.setAttribute('frameBorder',0);
	iframest.setAttribute('scrolling',scroll);
	iframest.src=this.winstyle.blankpage;
	iframest.style.position="absolute";
	iframest.style.left=0;
	iframest.style.right=0;
	iframest.style.borderwidth=0;
	iframest.style.borderstyle="solid";
	iframest.style.zIndex=-100;
	iframest.win=this;
	this.iframestausobj=iframest;
	divstatus.appendChild(iframest);
//=========================================================================

	//criar tabela
	var divstatustable = document.createElement("table");
	divstatustable.cellSpacing = 0;
	divstatustable.cellPadding = 0;
	divstatustable.win = this;
	divstatustable.width="100%";
	divstatustable.style.zIndex=2;
	divstatustable.height=this.winstyle.status.defaultbuttonsheight;
//=========================================================================
//TENTATIVA DE SOLUCIONAR PROBLEMA COM COMBO
//=========================================================================
	divstatustable.style.backgroundColor=this.winstyle.status.bgcolor;
//=========================================================================
	this.divstatustableobj=divstatustable;
	this.divstatusobj.appendChild(divstatustable);
	this.updatestyle();

	//criar tabela status (head)
	var thead = document.createElement("thead");
	divstatustable.appendChild(thead);
	var cell = null;
	var row = null;

	//criar linha da tabela (tr)
	row = document.createElement("tr");
	thead.appendChild(row);
	row.className = "headrow";

	//criar botoes da esquerda (td)
	for (t=0;t<this.winstyle.status.buttons.Count();t++)
	{
	  
		bot=this.winstyle.status.buttons.items[t];
	  	if (bot.isLeft())
	  	{
			cell = hh("", 1, 300);
			cell.width=bot.width;
			cell.className = "leftbot";
			cell.style.cursor = SYSTEM_CURSOR_HAND; //"hand";
			cell.setAttribute('SCIWinPos',this.pos);
			cell.setAttribute('BTNPOS',t);
		    cell.style.overflowX='hidden';
		    cell.style.overflowY='hidden';
/*
			cell.onmouseover=SCIWindowBtnOvr;
			cell.onmouseout=SCIWindowBtnOut;
			cell.onmousedown=SCIWindowBtnDown;
			cell.onmouseup=SCIWindowBtnUp;
*/
			//bot.imgatual.src=bot.img.src;
			cell.innerHTML='';
			//cell.appendChild(bot.imgatual);
			cell.appendChild(bot.imgDiv);
			bot.showUp();
			bot.win=this;
			bot.cell=cell;
			row.appendChild(bot.cell);
		}
	}

	//criar status cell (td)
	this.statusCell = hh("&nbsp;&nbsp;&nbsp;", 1, 300);
	this.statusCell.className = "status";
//	this.statusCell.style.cursor = SYSTEM_CURSOR_MOVE;
	row.appendChild(this.statusCell);
	
	var divstatusCell = document.createElement("div");
	divstatusCell.style.color = this.winstyle.status.color;
//	this.title.cellSpacing = this.winstyle.status.cellspacing;
	divstatusCell.style.margin = this.winstyle.status.margin;
	divstatusCell.style.fontFamily = this.winstyle.status.fontfamily;
	divstatusCell.style.fontStyle = this.winstyle.status.fontstyle;
	divstatusCell.style.fontWeight = this.winstyle.status.fontweight;
	divstatusCell.style.fontSize = this.winstyle.status.fontsize;
	divstatusCell.style.textAlign = this.winstyle.status.textAlign;
	divstatusCell.style.width="100%";
	divstatusCell.style.win = this;
	divstatusCell.innerHTML='&nbsp;&nbsp;&nbsp;';
	this.divstatuscellobj=divstatusCell;
	this.statusCell.innerHTML='';
	this.statusCell.appendChild(divstatusCell);
	
	//criar botoes da direita (td)
	for (t=0;t<this.winstyle.status.buttons.Count();t++)
	{
	  
		bot=this.winstyle.status.buttons.items[t];
	  	if (bot.isRight())
	  	{
			cell = hh("", 1, 300);
			cell.width=bot.width;
			cell.className = "leftbot";
			cell.style.cursor = SYSTEM_CURSOR_HAND; //"hand";
			cell.setAttribute('SCIWinPos',this.pos);
			cell.setAttribute('BTNPOS',t);
		    cell.style.overflowX='hidden';
		    cell.style.overflowY='hidden';
/*
			cell.onmouseover=SCIWindowBtnOvr;
			cell.onmouseout=SCIWindowBtnOut;
			cell.onmousedown=SCIWindowBtnDown;
			cell.onmouseup=SCIWindowBtnUp;
*/
			//bot.imgatual.src=bot.img.src;
			cell.innerHTML='';
			//cell.appendChild(bot.imgatual);
			cell.appendChild(bot.imgDiv);
			bot.showUp();
			bot.win=this;
			bot.cell=cell;
			row.appendChild(bot.cell);
		}

	}
	// Criando div status Loading da janela
	var divstatusLoad = document.createElement("div");
	divstatusLoad.win=this;
	divstatusLoad.style.height=this.winstyle.status.height;
	divstatusLoad.style.overflow="hidden";
	divstatusLoad.style.backgroundColor=this.winstyle.status.bgcolor;
// 	divstatusLoad.style.backgroundColor="FF00FF";
	divstatusLoad.style.display = "none";
	divstatusLoad.style.position = "absolute";
	divstatusLoad.style.left=0;
	divstatusLoad.style.top=0;
	divstatusLoad.style.width="100%";
//	divstatusLoad.style.width="100";
	divstatusLoad.style.height="100%";

	divstatusLoad.style.display = "block";

	divstatusLoad.className = "SCIWindow_status";
	this.divstatusLoadobj = divstatusLoad;
	this.divstatusobj.appendChild(this.divstatusLoadobj);
	AB = new SCIActionBar(this.divstatusLoadobj);
	AB.create(0,0,150,this.winstyle.status.height-6);
	AB.divxobj.align="right";
	AB.divxobj.style.margin="3px";
	AB.divxobj.style.position="relative";
	this.divstatusobj.align="right";
	this.LoadBar=AB;
	// ==============================================================

	win.size(this.cx,this.cy);
    win.move(this.x,this.y);
};
SCIWindow.prototype.showLoading = function ()
{
	divstatusLoad = this.divstatusLoadobj;
//	alert(this.divstatustableobj.style.display);
	this.divstatustableobj.style.display = "none";
	divstatusLoad.style.display = "block";
	this.LoadBar.show();
};
SCIWindow.prototype.hideLoading = function ()
{
	divstatusLoad = this.divstatusLoadobj;
	this.LoadBar.hide();
	divstatusLoad.style.display = "none";
	this.divstatustableobj.style.display = "";
};
SCIWindow.prototype.updatestyle = function () 
{
	var LocateNode = function (par,node) 
	{
	  	p=-1;
		if (par.childNodes)
		{
		  for (t=0;t<par.childNodes.length;t++)
		  {
		    node2=par.childNodes[t];
		    if(node2==node)
		    {
			  p=t;
			  break;
			}
		  }
		}
		return(p);
	}
	// Atualizando div principal da janela
	div=this.divobj;
	div.style.backgroundColor=this.winstyle.borderbgcolor;

	// Atualizando div interna da janela (definição de borda)
	divint=this.divintobj;
	divint.style.backgroundColor=this.winstyle.borderbgcolorinternal;

	// Atualizando div titulo da janela
	divcaption=this.divcaptionobj;
	divcaption.style.height=this.winstyle.caption.height;
	divcaption.bgcolor=this.winstyle.caption.bgcolor;
	divcaption.heigth=this.winstyle.caption.height;

	divint=this.divintobj;	
	
	diviframe=this.diviframeobj;	
	if (this.winstyle.caption.visible)
	{
		if (LocateNode(divint,divcaption)==-1)
		{
		  if (diviframe)
		  {
			if (LocateNode(divint,diviframe)==-1)
			{
		    	divint.appendChild(divcaption);
		    }
		    else
			{
		    	divint.insertBefore(divcaption,diviframe);
		    }
			this.size(this.cx,this.cy);
		    this.move(this.x,this.y);
		  }
		  else
		  {
	    	divint.appendChild(divcaption);
		  }
		}
	}
	else
	{
		if (LocateNode(divint,divcaption)>=0)
		{
		    divint.removeChild(divcaption);
			this.size(this.cx,this.cy);
		    this.move(this.x,this.y);
		}
	}

	// Atualizando div status da janela
	divstatus=this.divstatusobj;
	if (divstatus)
	{
		divstatus.style.height=this.winstyle.status.height;
		divstatus.bgcolor=this.winstyle.status.bgcolor;
		divstatus.heigth=this.winstyle.status.height;

		if (this.winstyle.status.visible)
		{
	    	divint.appendChild(divstatus);
		}
	}

	bot=this.winstyle.caption.buttons.close.onclick=SCIWindowBtnClose;
	bot=this.winstyle.status.buttons.atualizer.onclick=SCIWindowBtnAtualizar;
	bot=this.winstyle.status.buttons.imprimir.onclick=SCIWindowBtnImprimir;
};
SCIWindow.prototype.move = function (x, y) 
{
	var s = this.divobj.style;
	s.left = x + "px";
	s.top = y + "px";
	var s = this.divintobj.style;
	s.left = this.winstyle.bordersize + "px";
	s.top = this.winstyle.bordersize + "px";

	var s = this.divcaptionobj.style;
	s.left = 0 + "px";
	s.top = 0 + "px";
};
SCIWindow.prototype.size = function (cx, cy) 
{
	this._size(cx,cy,"px")
}
SCIWindow.prototype.sizebox100 = function (cx, cy) 
{
	//Ajustando Div principal da janela 
	var s = this.divobj.style;
	s.width = cx;
	s.height = cy;

	//Ajustando Div interna principal da janela 
	var s = this.divintobj.style;
	s.width = "100%";
	s.height = "100%";

	//Ajustando diviframe da janela 
	var s = this.diviframeobj.style;
	s.width = "100%";
	s.height = "100%";

	//Ajustando iframe da janela 
	var s = this.iframeobj.style;
	s.width = "100%";
	s.height = "100%";
	var s = this.iframeobj;
	s.width = "100%";
	s.height = "100%";
}
SCIWindow.prototype._size = function (cx, cy, pt) 
{
	if (this.winstyle.caption.visible)
	{
		cr=this.winstyle.caption.height;
	}
	else
	{
		cr=0;
	}
	if (this.winstyle.status.visible)
	{
		crh=cr+this.winstyle.status.height;
	}
	else
	{
		crh=cr;
	}

	//Ajustando Div principal da janela 
	var s = this.divobj.style;
	s.width = cx + pt;
	s.height = cy + pt;

	//Ajustando Div interna principal da janela 
	var s = this.divintobj.style;
	s.left = this.winstyle.bordersize + "px";
	s.top = this.winstyle.bordersize + "px";
	s.width = (cx-(this.winstyle.bordersize*2)) + pt;
	s.height = (cy-(this.winstyle.bordersize*2)) + pt;

	//Ajustando iframe da janela 
	var s = this.iframeobj.style;
	s.left = 0 + "px";
	s.top = cr + "px";
	s.width = (cx-(this.winstyle.bordersize*2)) + pt;
	s.height = (cy-(this.winstyle.bordersize*2)-crh) + pt;

	//Ajustando Div container do Titulo 
	var s = this.divcaptionobj.style;
	s.left = 0 + "px";
	s.top = 0 + "px";
	s.width = (cx-(this.winstyle.bordersize*2)) + pt;
	s.height = this.winstyle.caption.height + pt;

	//Ajustando Div container do Staus
	var s = this.divstatusobj.style;
	s.left = 0 + "px";
	s.top = cr + (cy-(this.winstyle.bordersize*2)-crh) + "px";
	s.width = (cx-(this.winstyle.bordersize*2)) + pt;
	s.height = this.winstyle.status.height + pt;

//=========================================================================
//TENTATIVA DE SOLUCIONAR PROBLEMA COM COMBO
//=========================================================================
	//Ajustando iframe do titulo
	var s = this.iframecaptionobj.style;
	s.left = 0 + "px";
	s.top = 0 + "px";
	s.width = (cx-(this.winstyle.bordersize*2)) + pt;
	s.height = this.winstyle.status.height + pt;
	//Ajustando iframe do status
	var s = this.iframestausobj.style;
	s.left = 0 + "px";
	s.top = 0 + "px";
	s.width = (cx-(this.winstyle.bordersize*2)) + pt;
	s.height = this.winstyle.status.height + pt;
//=========================================================================

	diviframe=this.diviframeobj;
	diviframe.style.display = "none";
	diviframe.style.display = "block";
};
SCIWindow.prototype.setcaption = function (title) 
{
	divtitle=this.divtitleobj;
	divtitle.innerHTML=title;
}
SCIWindow.prototype.openpage = function (title,page) 
{
	if (title=="")
	{ 
		title="&nbsp;&nbsp;&nbsp;";
	}
	this.setcaption(title);
//	this.title.innerHTML=title;
	this.iframeobj.src=page;
/*	if (this.winstyle.status.visible)
	{
		this.divintobj.insertBefore(this.diviframeobj,this.divstatusobj);
	}
	else
	{
*/
		this.divintobj.appendChild(this.diviframeobj);
//	}
};
SCIWindow.prototype.closepage = function () 
{
	this.iframeobj.src=this.winstyle.blankpage;
//	this.iframeobj.src='';//this.winstyle.blankpage;
//	this.hide();
	this.divintobj.removeChild(this.diviframeobj);
	if (this.onclosewindow)
	{
		this.onclosewindow(this);
	}
};
SCIWindow.prototype.close = function () 
{
	this.closepage();
	this.hide();
};
SCIWindow.prototype.hideVscroll = function () 
{
	iframe=this.iframeobj;
	iframe.style.overflowY="hidden";
//	alert(iframeobj.document.body.outerHTML);
//	iframeobj.style.overflowY = "hidden";

//	iframeobj.setAttribute('scroll','no');
//	iframeobj.setAttribute('scrolling','no');
};
SCIWindow.prototype.showVscroll = function () 
{
	iframe=this.iframeobj;
	iframe.style.overflowY="visible";
//	iframeobj.style.overflowY = "scroll";
//	iframeobj.setAttribute('scroll','yes');
//	iframeobj.setAttribute('scrolling','yes');
};
SCIWindow.prototype.showVscrollauto = function () 
{
	iframe=this.iframeobj;
	iframe.style.overflowY="auto";
//	iframeobj.style.overflowY = "auto";
//	iframeobj.setAttribute('scrolling','no');
};
SCIWindow.prototype.hideHscroll = function () 
{
	iframe=this.iframeobj;
	iframe.style.overflowX="hidden";
//	iframeobj=this.iframeobj;
//	iframeobj.style.overflowX = "hidden";
//	this.iframeobj.setAttribute('scrolling','no');
};
SCIWindow.prototype.showHscroll = function () 
{
	iframe=this.iframeobj;
	iframe.style.overflowX="visible";
//	iframeobj=this.iframeobj;
//	iframeobj.style.overflowX = "scroll";
//	this.iframeobj.setAttribute('scrolling','no');
};
SCIWindow.prototype.showHscrollauto = function () 
{
	iframe=this.iframeobj;
	iframe.style.overflowX="auto";
//	iframeobj=this.iframeobj;
//	iframeobj.style.overflowX = "auto";
//	this.iframeobj.setAttribute('scrolling','no');
};
/*SCIWindow.prototype.hideShowCovered = function () 
{
	var tags = new Array ('applet', 'iframe', 'select');
	var el = this.win;

	var p = this.getAbsolutePos(el);
	var EX1 = p.x;
	var EX2 = el.offsetWidth + EX1;
	var EY1 = p.y;
	var EY2 = el.offsetHeight + EY1;

	for (var k = 0; k < tags.length; k++) {
		var ar = document.getElementsByTagName(tags[k]);
		var cc = null;

		for (var i = 0; i < ar.length; i++) {
			cc = ar[i];

			p = this.getAbsolutePos(cc);
			var CX1 = p.x;
			var CX2 = cc.offsetWidth + CX1;
			var CY1 = p.y;
			var CY2 = cc.offsetHeight + CY1;

			if ((CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
				cc.style.visibility = "visible";
			} else {
				cc.style.visibility = "hidden";
			}
		}
	}
};*/

/* 
Show Hide Scroll
document.body.style.overflowY = val - 'hidden'/'scroll'/'auto'


*/

SCIWindows = function () 
{
	this.wins = new Array();
	this.intwins = new Array();
	this.MantaCount = 0;
	this.FrameZeroDivObj = null;
	this.FrameZeroiframeObj = null;
	this.FrameZeroBackDivObj = null;
};
SCIWindows.prototype.CreateWindows = function(x,y,cx,cy,scroll,vparent) 
{
  xwin = new SCIWindow();
	xwin.winstyle=new sciwindow_defautstyle(xwin);
	//xwin.winstyle=new sciwindow_floatboxstyle(this);
	xwin.pos=this.wins.length;
	ps=xwin.pos;
	//xwin.create(x,y,cx,cy,scroll,vparent);
	xwin.create(100+(ps*10)+x,100+(ps*10)+y,cx,cy,scroll,vparent);
	xwin.iframeobj.setAttribute('winpos',xwin.pos);
	this.wins[this.wins.length]= xwin;
	if(WinDebug)
	{
		xwin.show();
		//alert('CW:'+ps);
	}
	return (xwin);
};

SCIWindows.prototype.OpenWindow = function(caption,page,x,y,cx,cy,scroll,vparent) 
{
  xwin = new SCIWindow();
	xwin.pos=this.wins.length;
	ps=xwin.pos;
//	xwin.create(x,y,cx,cy,scroll,vparent);
	xwin.create(100+(ps*10)+x,100+(ps*10)+y,cx,cy,scroll,vparent);
	xwin.iframeobj.setAttribute('winpos',xwin.pos);
	this.wins[this.wins.length]= xwin;
	xwin.show();
	xwin.openpage(caption,page);
	if(WinDebug)
	{
		xwin.show();
	}
	return (xwin);
};
SCIWindows.prototype.CreateWindowsBox = function(x,y,cx,cy,scroll,vparent) 
{
  xwin = new SCIWindow();
	xwin.pos=this.wins.length;
	xwin.winstyle=new sciwindow_floatboxstyle(xwin);
	ps=xwin.pos;
	//xwin.create(x,y,cx,cy,scroll,vparent);
	xwin.create(100+(ps*10)+x,100+(ps*10)+y,cx,cy,scroll,vparent);
	this.wins[this.wins.length]= xwin;
	if(WinDebug)
	{
		xwin.show();
		//alert('CWB:'+ps);
	}
	return (xwin);
};
SCIWindows.prototype.createFrameZero = function (vparent) 
{
	if (! vparent) 
	{
		pai = document.getElementsByTagName("body")[0];
	} else {
		pai = vparent;
	}
	var div = document.createElement("div");
//	div.style.backgroundColor="FF0000";
	div.style.display = "none";
	div.style.overflow="hidden";
	div.style.position = "absolute";
	div.style.left=0;
	div.style.top=0;
	div.style.height="100%";
	div.style.width="100%";
	div.style.zIndex=2;
	div.name="framezero_div";
	div.id="framezero_div";
	this.FrameZeroDivObj = div;
	if (FrameZeroOpenPage=="")
	{
	  FrameZeroOpenPage=sciwindow_blankpage;
	}
	// Criando iframe da janela (frame da janela)
	var iframe = document.createElement("iframe");
	iframe.style.display = "block";
	iframe.style.overflowX="hidden";
	iframe.name='SCIWindow_frame';
	iframe.setAttribute('name','framezero');
	iframe.setAttribute('id','framezero');
	iframe.setAttribute('marginwidth',0);
	iframe.setAttribute('marginheight',0);
	iframe.setAttribute('border',0);
	iframe.setAttribute('vspace',0);
	iframe.setAttribute('hspace',0);
	iframe.setAttribute('frameBorder',0);
	iframe.setAttribute('scrolling',"yes");
	iframe.setAttribute('target',"_self");
//	iframe.setAttribute('noresize');
	iframe.setAttribute('height',"100%");
	iframe.setAttribute('width',"100%");
	iframe.setAttribute('onload','SCIWinsOnLoad();');
//	iframe.contentWindow.onload=SCIWinsOnLoad;
	iframe.setAttribute('src',FrameZeroOpenPage);
	this.FrameZeroiframeObj = iframe;

	div.appendChild(this.FrameZeroiframeObj);
	pai.appendChild(this.FrameZeroDivObj);

	div.style.display = "none";
	div.style.display = "block";
	return (this.FrameZeroDivObj);
};
SCIWindows.prototype.createManta = function (vparent) 
{
	if (! vparent) 
	{
		pai = document.getElementsByTagName("body")[0];
	} else {
		pai = vparent;
	}
	var div = document.createElement("div");
	div.style.backgroundColor="000000";
	div.style.display = "none";
	div.style.overflow="hidden";
	div.style.position = "absolute";
	div.style.left=0;
	div.style.top=0;
	div.style.height="100%";
	div.style.width="100%";
	div.style.zIndex=998;
	div.name="framezero_div_Back_Trans";
	div.id="framezero_div_Back_Trans";
	this.FrameZeroBackDivObj = div;
	div.setAttribute("className","SCIActionBarDIV50");
  	div.style.MozOpacity = 50/100;

	pai.appendChild(this.FrameZeroBackDivObj);

//	div.style.display = "none";
//	div.style.display = "block";
//	div.style.display = "none";
	
	return (this.FrameZeroBackDivObj);
}
SCIWindows.prototype.TransparenteManta = function () 
{
  	MantaCount=MantaCount+1;
	div = this.FrameZeroBackDivObj;
	if (IS_IE)
	{
	 	div.filters.alpha.opacity = 0;
	}
	else
	{
	  	div.style.MozOpacity = 0;
	}
	div.style.display = "block";
}
SCIWindows.prototype.showManta = function () 
{
  	MantaCount=MantaCount+1;
	div = this.FrameZeroBackDivObj;
	div.style.display = "block";
//	alert(IS_IE);
	if (IS_IE)
	{
	 	div.filters.alpha.opacity = 50;
	}
	else
	{
	  	div.style.MozOpacity = 50/100;
	}
}
SCIWindows.prototype.hideManta = function () 
{
  	if (MantaCount>0)
  	{
	  	MantaCount=MantaCount-1;
  	}
  	if (MantaCount==0)
  	{
		this.FrameZeroBackDivObj.style.display = "none";
	}
}
SCIWindows.prototype.createExecuteWin = function (vparent) 
{
  xwin = new SCIWindow();
	xwin.pos=this.intwins.length;
	ps=xwin.pos;
	xwin.winstyle=new sciwindow_floatboxstyle(xwin);
	//xwin.winstyle=new sciwindow_defautstyle(this);
	xwin.create(250,250,"400","400",scroll,"ExecutarForm",vparent);
	this.intwins[this.intwins.length]= xwin;
	xwin.Execute=true;
	//win.sizebox100("100%","100%");
	if (IntWinDebug)
	{
			xwin.show();
			//alert('EXEX:'+ps);
	}
	return (xwin);
}
SCIWindows.prototype.createStartupWin = function (vparent) 
{
  xwin = new SCIWindow();
	xwin.pos=this.intwins.length;
	ps=xwin.pos;
	xwin.winstyle=new sciwindow_floatboxstyle(xwin);
	//xwin.winstyle=new sciwindow_defautstyle(this);
	xwin.create(450,450,"400","400",scroll,"StatupForm",vparent);
	this.intwins[this.intwins.length]= xwin;
	//xwin.Execute=true;
	//win.sizebox100("100%","100%");
	if (IntWinDebug)
	{
			xwin.show();
			//alert('STUP:'+ps);
	}
	return (xwin);
}

var SCIWins = new SCIWindows();
var SCIWinExec = null;
var SCIWinStartUp = null;
var SCIWinFZ = null;
var SCIWinManta = null;

function SCIWinsStartSystem()
{
	SCIWinFZ = SCIWins.createFrameZero();
	SCIWinExec  = SCIWins.createExecuteWin();
	SCIWinStartUp = SCIWins.createStartupWin();
	SCIWinManta = SCIWins.createManta();
	//SCIWinExec.show();
	return true;
}
function SCIWinsOnLoad()
{
  
}
function SCIWindowBtnClose(vwin)
{
//	SCIWinPos=this.getAttribute('SCIWinPos');
//	win=SCIWins.wins[SCIWinPos];
	//alert('vwin:'+vwin);
	vwin.closepage();
	vwin.hide();
}
function SCIWindowBtnImprimir(win)
{
	win.Print();
}
function SCIWindowBtnAtualizar(win)
{
	win.Reload();
}
function SCIWindowBtnOvr()
{
	SCIWinPos=this.getAttribute('SCIWinPos');
	win=SCIWins.wins[SCIWinPos];
	BTNPOS=this.getAttribute('BTNPOS');
	bot=win.winstyle.caption.buttons.items[BTNPOS];
//	bot.imgatual.src=bot.imgover.src;
	bot.showOver();
}
function SCIWindowBtnOut()
{
	SCIWinPos=this.getAttribute('SCIWinPos');
	win=SCIWins.wins[SCIWinPos];
	BTNPOS=this.getAttribute('BTNPOS');
	bot=win.winstyle.caption.buttons.items[BTNPOS];
//	bot.imgatual.src=bot.img.src;
	bot.showUp();
}
function SCIWindowBtnDown()
{
	SCIWinPos=this.getAttribute('SCIWinPos');
	win=SCIWins.wins[SCIWinPos];
	BTNPOS=this.getAttribute('BTNPOS');
	bot=win.winstyle.caption.buttons.items[BTNPOS];
//	bot.imgatual.src=bot.imgdown.src;
	bot.showDown();
}
function SCIWindowBtnUp()
{
	SCIWinPos=this.getAttribute('SCIWinPos');
	win=SCIWins.wins[SCIWinPos];
	BTNPOS=this.getAttribute('BTNPOS');
	bot=win.winstyle.caption.buttons.items[BTNPOS];
//	bot.imgatual.src=bot.imgover.src;
	bot.showOver();
	if (bot.onclick!=null)
	{
		bot.onclick(win);
	}
}
