//========================================================
// sciwindow_defautstyle class
//========================================================
var IMGID = 0;
var SCIWindowBots = new Array();
function SCIWindow_buttonOut(BTNPOS)
{
//  alert('out');
	bot=this.bot;
	win=bot.bots.winstyle.win;
	bot.showUp();
}
function SCIWindow_buttonOvr(BTNPOS)
{
	bot=this.bot;
	win=bot.bots.winstyle.win;
	bot.showOver();
}
function SCIWindow_buttonUp(BTNPOS)
{
	bot=this.bot;
	win=bot.bots.winstyle.win;
	bot.showOver();
	if (bot.onclick!=null)
	{
		bot.onclick(win);
	}
}
function SCIWindow_buttonDown(BTNPOS)
{
	bot=this.bot;
	win=bot.bots.winstyle.win;
	bot.showDown();
}
sciwindow_button = function(stoolbar,sname,shint,sfilename,svisible,spath,spos,x,y,sfilenameover,sfilenamedown,scaption)
{
  if (svisible!=null)
  {
	  this.visible=svisible;
  }
  else
  {
	  this.visible=true;
  }
  if (spath!=null)
  {
	  this.path=path;
  }
  else
  {
	  this.path=sciwindow_images;
  }
  if (sfilenameover==null)
  {
	  sfilenameover=sfilename;
  }
  if (sfilenamedown==null)
  {
	  sfilenamedown=sfilename;
  }
  this.filename=sfilename;
  this.sfilenamedown=sfilenamedown;
  this.sfilenameover=sfilenameover;
  this.name=sname;
  this.hint=shint;
  if (spos!=null)
  {
	  this.pos=spos;
  }
  else
  {
	  this.pos='right';
  }

  this.BTNPOS=SCIWindowBots.length;
  SCIWindowBots[SCIWindowBots.length]=this;


  // ==============================================================
  // DIV PRINCIPAL
  // ==============================================================
  div = document.createElement("div");
  this.imgDiv = div;
  div.style.position="relative";
  div.style.width="100%";
  div.style.height="100%";
  
  // ==============================================================
  // criar tabela
  // ==============================================================
  imgDivTable = document.createElement("div");
  this.imgDivTable = imgDivTable;
  this.imgDiv.appendChild(this.imgDivTable); 
//  div.setAttribute('bot',this);
  imgDivTable.bot=this;
  imgDivTable.ID="imgDivTable";
  imgDivTable.style.zIndex=1;
  imgDivTable.style.position="absolute";
  imgDivTable.style.left=0;
  imgDivTable.style.top=0;
  imgDivTable.style.width="100%";
  imgDivTable.style.height="100%";

  tableObj = document.createElement("table");
  this.tableObj=tableObj;
  tableObj.cellSpacing = 0;
  tableObj.cellPadding = 0;
  tableObj.win = this;
  tableObj.width="100%";
  tableObj.height="100%";
  tableObj.style.width="100%";
  tableObj.style.height="100%";

  thead = document.createElement("thead");
  tableObj.appendChild(thead);
  
  row = document.createElement("tr");
  thead.appendChild(row);

  cell = document.createElement("td");
  row.appendChild(cell);
  cell.colSpan = 1;
  cell.align=stoolbar.buttonalign;//"center";
  cell.valign=stoolbar.buttonvalign;
  cell.style.verticalAlign=stoolbar.buttonvalign;  
  if (scaption)
  {
	  if (scaption!="")
	  {
		  cell2 = document.createElement("td");
  		  cell2div = document.createElement("div");
		  cell2.colSpan = 1;
//		  cell2.align=stoolbar.buttontextalign;
		  cell2.valign=stoolbar.buttontextvalign;

		  cell2div.style.textAlign=stoolbar.buttontextalign;
		  cell2div.style.valign=stoolbar.buttontextvalign;  
		  cell2div.style.verticalAlign=stoolbar.buttontextvalign;  
		  cell2div.style.fontFamily = stoolbar.buttonfontfamily;
		  cell2div.style.fontStyle = stoolbar.buttonfontstyle;
		  cell2div.style.fontSize = stoolbar.buttonfontsize;
		  cell2div.style.color = stoolbar.buttonfontcolor;
		  cell2div.style.fontWeight = stoolbar.buttonfontweight;
		  cell2div.innerHTML=scaption;
		  cell2.appendChild(cell2div);
		  row.appendChild(cell2);
		  
	  }
  }
  imgDivTable.appendChild(tableObj);
  // ==============================================================

  // ==============================================================
  // DIV IMAGENS
  // ==============================================================
  div = document.createElement("div");
  this.imgDivImage = div;
  div.ID="imgDivImage";
  cell.appendChild(this.imgDivImage); 
  div.style.zIndex=1;
  div.style.position="relative";
  div.style.left=0;
  div.style.top=0;
//  div.style.width="100%";
//  div.style.height="100%";
  div.align="center";

  imgDivBT = document.createElement("div");
  this.imgDivBT = imgDivBT;
  this.imgDiv.appendChild(this.imgDivBT); 
//  div.setAttribute('bot',this);
  imgDivBT.bot=this;
//  imgDivBT.style.display = "block";
  imgDivBT.style.position = "absolute";
  imgDivBT.style.zIndex=2;
  imgDivBT.style.left=0;
  imgDivBT.style.top=0;
  imgDivBT.style.width=x+"px";
  imgDivBT.style.height=y+"px";
// NÃO FUNCIONA COM TRANSPARENCIA  
//  imgDivBT.style.width="100%";
//  imgDivBT.style.height="100%";
//  imgDivBT.style.overflow="hidden";
  imgDivBT.style.backgroundColor="999999";
  imgDivBT.style.MozOpacity = 20/100;
  imgDivBT.onmousedown=SCIWindow_buttonDown;
  imgDivBT.onmouseup=SCIWindow_buttonUp;
  imgDivBT.onmouseover=SCIWindow_buttonOvr;
  imgDivBT.onmouseout=SCIWindow_buttonOut;
  imgDivBT.setAttribute("className","SCIActionBarDIV50");
  imgDivBT.name="BTN_Trans";
  imgDivBT.id="BTN_Trans";
//  imgDivBT.setAttribute("className","SCIActionBarDIV50");
//  imgDivBT.setAttribute("id","imgDivBT1");
  //imgDivBT.setAttribute("name","imgDivBT1");
//  div.onmouseup='SCIWindow_buttonDown('+this.BTNPOS+');';

/*
  thead = document.createElement("thead");
  tableObj.appendChild(thead);
  
  row = document.createElement("tr");
  thead.appendChild(row);

  cell = document.createElement("td");
  row.appendChild(cell);
  cell.colSpan = 1;
  cell.align="center";
  cell.valign="middle";
  imgDivBT.appendChild(tableObj);
*/
  
  this.img = new Image();
  this.img.src=this.path+this.filename;
  this.imgover = new Image();
  this.imgover.src=this.path+this.sfilenameover;
  this.imgdown = new Image();
  this.imgdown.src=this.path+this.sfilenamedown;
  this.imgatual = null;
//  this.imgatual = new Image();
//  this.imgatual = document.createElement("img");
//  this.imgatual.setAttribute('id','img'+IMGID);
//  this.imgatual.setAttribute('name','img'+IMGID);
//  this.imgatual.src=this.img.src;
  IMGID=IMGID+1;
  this.width=x;
  this.height=y;
  this.onclick = null; 
  this.cell = null;
}
sciwindow_button.prototype.showBtn = function()
{
  this.imgDivBT.style.display = "none";
  this.imgDivBT.style.display = "block";
  if (IS_IE)
  {
  	if (this.imgDivBT)
  	{
	  	if (this.imgDivBT.filters)
	  	{
		  	if (this.imgDivBT.filters.alpha)
		  	{
			  	if (this.imgDivBT.filters.alpha.opacity)
			  	{
				 		this.imgDivBT.filters.alpha.opacity = 10;
				 	}
			 	}
		 	}
	 	}
  }
  else
  {
  	this.imgDivBT.style.MozOpacity = 10/100;
  }
  this.imgDivBT.style.display = "none";
  this.imgDivBT.style.display = "block";
}

sciwindow_button.prototype.isLeft = function()
{
  if ((this.visible) && (this.pos=='left'))
  {
	  return (true);
  }
  else
  {
	  return (false);
  }
}
sciwindow_button.prototype.isRight = function()
{
  if ((this.visible) && (this.pos=='right'))
  {
	  return (true);
  }
  else
  {
	  return (false);
  }
}
sciwindow_button.prototype.showOver = function()
{
  div=this.imgDivImage;
  if (this.imgatual != null)
  {
   	div.removeChild(this.imgatual);  
  }
  this.imgatual=this.imgover;
  div.appendChild(this.imgatual);  
}
sciwindow_button.prototype.showDown = function()
{
  div=this.imgDivImage;
  if (this.imgatual != null)
  {
   	div.removeChild(this.imgatual);  
  }
  this.imgatual=this.imgdown;
  div.appendChild(this.imgatual);  
}
sciwindow_button.prototype.showUp = function()
{
  div=this.imgDivImage;
  if (this.imgatual != null)
  {
   	div.removeChild(this.imgatual);  
  }
  this.imgatual=this.img;
  div.appendChild(this.imgatual);  
}
//========================================================
// sciwindow_buttons class
//========================================================
sciwindow_buttons = function(winstyle,spath)  
{
  this.isupdate=0;
  this.items = new Array();
  this.BeginUpdate();
  this.winstyle=winstyle;
  this.defaultWidth=winstyle.defaultbuttonswidth;
  this.defaultheight=winstyle.defaultbuttonsheight; 
  this.EndUpdate();
}
sciwindow_buttons.prototype.BeginUpdate = function()
{
  this.isupdate=this.isupdate+1;
}	
sciwindow_buttons.prototype.EndUpdate = function(force)
{
  if (force==true)
  {
	  this.isupdate=0;
  }
  else
  {
	  this.isupdate=this.isupdate-1;
  }
  this.Update();
}	
sciwindow_buttons.prototype.Update = function()
{
  if (this.isupdate==0)
  {
	  this.isupdate=false;
  }
}	
sciwindow_buttons.prototype.Add = function(stoolbar,sname,shint,sfilename,svisible,spath,spos,x,y,sfilenameover,sfilenamedown,scaption)
{

  Bot = new sciwindow_button(stoolbar,sname,shint,sfilename,svisible,spath,spos,x,y,sfilenameover,sfilenamedown,scaption);
  Bot.bots=this;
  this.items.push(Bot);
  this.Update();
  return(Bot);
}
sciwindow_buttons.prototype.isLeft = function(p)
{
  if ((this.items[p].visible) && (this.items[p].pos=='left'))
  {
	  return (true);
  }
  else
  {
	  return (false);
  }
}
sciwindow_buttons.prototype.isRight = function(p)
{
  if ((this.items[p].visible) &&  (this.items[p].pos=='right'))
  {
	  return (true);
  }
  else
  {
	  return (false);
  }
}
sciwindow_buttons.prototype.Count = function()
{
  return (this.items.length);
}
sciwindow_buttons.prototype.VisibleCount = function(spos)
{
  if (spos==null)
  {
	  spos='right';
  }
  c=0;
  tot=this.items.length;
  for (t=0;t<tot;t++)
  {
  	if ((this.items[t].visible) &&  (this.items[t].pos==spos))
  	{
	    c=c+1;
	}
  }
  return (c);
}
sciwindow_buttons.prototype.showBtns = function()
{
  c=0;
  tot=this.items.length;
  for (t=0;t<tot;t++)
  {
  	if (this.items[t].visible)
  	{
  	  	this.items[t].showBtn();
  	  	if (!IS_IE)
  	  	{
	  	  	this.items[t].showOver();
  		  	this.items[t].showUp();
  		}
	    c=c+1;
	}
  }
  return (c);
}
//========================================================
// sciwindow_caption_buttons class
//========================================================
sciwindow_caption_buttons = function (stoolbar,spath)
{
  	winstyle=stoolbar.winstyle;
	ar=new sciwindow_buttons(winstyle,spath);
 	ar.BeginUpdate();

  	ar.winstyle=winstyle;
    ar.defaultWidth=winstyle.defaultbuttonswidth;
  	ar.defaultheight=winstyle.defaultbuttonsheight; 

  	ar.close = ar.Add(stoolbar,'close','Fecha a janela e o documento atual.','close_up.gif',true,spath,'right',ar.defaultWidth,ar.defaultheight,'close_ovr.gif','close_dwn.gif');
  	ar.help = ar.Add(stoolbar,'Ajuda','Exibe uma janela de ajuda sobre o documento atual.','help.gif',false,spath,'right',ar.defaultWidth,ar.defaultheight);
  	ar.minimize = ar.Add(stoolbar,'Minimizar','Minimiza a janela e mantem o documento atual aberto.','minimize.gif',false,spath,'right',ar.defaultWidth,ar.defaultheight);
  	ar.maximize = ar.Add(stoolbar,'Maximizar','Maxmiza a janela para toda a area do browser.','maximize.gif',false,spath,'right',ar.defaultWidth,ar.defaultheight);

  	ar.EndUpdate();

	return(ar);
}
//========================================================
// sciwindow_status_buttons class
//========================================================
sciwindow_status_buttons = function (stoolbar,spath)
{
  	winstyle=stoolbar.winstyle;
	ar=new sciwindow_buttons(winstyle,spath);
 	ar.BeginUpdate();

  	ar.winstyle=winstyle;
    ar.defaultWidth=winstyle.defaultbuttonswidth;
  	ar.defaultheight=winstyle.defaultbuttonsheight; 
  	ar.atualizer = ar.Add(stoolbar,'atualizar','atualizar o documento atual.','icon_recycle.gif',true,spath,'right',ar.defaultWidth,ar.defaultheight,'icon_recycle.gif','icon_recycle.gif','Atualizar');
  	ar.imprimir = ar.Add(stoolbar,'imprimir','imprime o documento atual.','icon_impressora.gif',true,spath,'right',ar.defaultWidth,ar.defaultheight,'icon_impressora.gif','icon_impressora.gif','Imprimir');

  	ar.EndUpdate();

	return(ar);
}
sciwindow_bar_defultstyle = function (winstyle) 
{
	this.visible=true;
	this.height=19;
	this.bgcolor='1D357B';
	this.color='FFFFFF';
	this.buttonalign="left";
	this.buttontextalign="left";
	this.margin=2;
	this.fontfamily='Verdana';
	this.fontstyle='';
	this.fontsize='9px';
	this.fontweight='bold';
	this.textAlign='left';
	this.buttonalign="left";
	this.buttonvalign="middle";
	this.buttontextalign="left";
	this.buttontextvalign="middle";
	this.buttonfontfamily='Verdana';
	this.buttonfontweight='bold';
	this.buttonfontstyle='';
	this.buttonfontsize='9px';
	this.buttonfontcolor='000000';
	this.defaultbuttonswidth=16;
	this.defaultbuttonsheight=19;
	this.winstyle=winstyle;
}
sciwindow_bar_titlestyle = function (winstyle) 
{
	style = new sciwindow_bar_defultstyle(winstyle);

	style.visible=true;
	style.height=19;
	style.bgcolor='112B70';//'1D357B';
	style.color='FFFFFF';
	style.margin=2;
	style.fontfamily='Verdana';
	style.fontstyle='';
	style.fontsize='11px';
	style.fontweight='bold';
	style.textAlign='left';
	style.buttonalign="left";
	style.buttonvalign="middle";
	style.buttontextalign="left";
	style.buttontextvalign="middle";
	style.buttonfontfamily='Verdana';
	style.buttonfontweight='bold';
	style.buttonfontstyle='';
	style.buttonfontsize='9px';
	style.buttonfontcolor='000000';
	style.defaultbuttonswidth=16;
	style.defaultbuttonsheight=19;

	winstyle.defaultbuttonswidth=style.defaultbuttonswidth;
	winstyle.defaultbuttonsheight=style.defaultbuttonsheight;

	style.buttons = sciwindow_caption_buttons(style);

	return(style);
}
sciwindow_bar_statusstyle = function (winstyle) 
{
	style = new sciwindow_bar_defultstyle(winstyle);

	style.visible=true;
	style.height=19;
	style.bgcolor='D4D0C8';
	style.color='FFFFFF';
	style.margin=2;
	style.fontfamily='Verdana';
	style.fontstyle='';
	style.fontsize='9px';
	style.fontweight='bold';
	style.textAlign='left';
	style.buttonalign="left";
	style.buttonvalign="middle";
	style.buttontextalign="left";
	style.buttontextvalign="middle";
	style.buttonfontfamily='Verdana';
	style.buttonfontweight='bold';
	style.buttonfontstyle='';
	style.buttonfontsize='9px';
	style.buttonfontcolor='000000';
	style.defaultbuttonswidth=85;
	style.defaultbuttonsheight=19;

	winstyle.defaultbuttonswidth=style.defaultbuttonswidth;
	winstyle.defaultbuttonsheight=style.defaultbuttonsheight;

	style.buttons = sciwindow_status_buttons(style);

	return(style);
}
//========================================================
// sciwindow_style class
//========================================================
sciwindow_style = function (win) 
{
	this.win=win;
	this.bordersize=1;
	this.borderbgcolor='000000';
	this.borderbgcolorinternal='00FF00';
	this.defaultbuttonswidth=16;
	this.defaultbuttonsheight=19;
	
	this.caption = sciwindow_bar_titlestyle(this);
	this.status = sciwindow_bar_statusstyle(this);

	this.ispopup=true;
	this.blankpage=sciwindow_blankpage;
	this.iframetext='style="DISPLAY: block; WIDTH: 398px; HEIGHT: 248px" border=0 scrolling=no marginwidth="0" marginheight="0" frameborder="0"';//<IFRAME name="sciwindow_frame" id="sciwindow_frame" ></IFRAME>'

}
//========================================================
// sciwindow_defautstyle class
//========================================================
sciwindow_defautstyle = function (win)
{
	style = new sciwindow_style(win);

	style.bordersize=2;
	style.caption.visible=true;
	style.status.visible=true;

	return(style);
}
//========================================================
// sciwindow_defautstyle class
//========================================================
sciwindow_floatboxstyle = function (win)
{
	style = new sciwindow_style(win);

	style.bordersize=1;
	style.caption.visible=false;
	style.status.visible=false;
	

	return(style);
}
//========================================================
