//DHTML Window script- Copyright Dynamic Drive (http://www.dynamicdrive.com)
//For full source code, documentation, and terms of usage,
//Visit http://www.dynamicdrive.com/dynamicindex9/dhtmlwindow.htm
//
//==========================================================================
//		Alterado por: Francisco Silva					Nov/2001
//--------------------------------------------------------------------------

var dragapproved=false
var minrestore=0
var initialwidth, initialheight, initialLeft, initialTop, pLeft, pTop, PopWnd
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all&&!(window.opera)
var i5n6=(ie5||ns6)
// imagens default dos botões: maximizar, restaurar, fechar
var imgMax="max.gif", imgRes="restore.gif", imgClo="close.gif" 

function drag_drop(e){
	if (minrestore==0) {
		var DocDW = document.getElementById("dwindow")
		if (ie5&&dragapproved&&event.button==1){
					DocDW.style.left=tempx+event.clientX-offsetx
					DocDW.style.top =tempy+event.clientY-offsety
				}
		else if (ns6&&dragapproved){
					DocDW.style.left=tempx+e.clientX-offsetx
					DocDW.style.top =tempy+e.clientY-offsety
				}
		initialLeft = DocDW.style.left
		initialTop  = DocDW.style.top
	}
}


function initializedrag(e){
	var DocDW = document.getElementById("dwindow")

	offsetx=ie5? event.clientX : e.clientX
	offsety=ie5? event.clientY : e.clientY
	if (ie5)
	document.getElementById("saver").style.display=''

	tempx=parseInt(DocDW.style.left)
	tempy=parseInt(DocDW.style.top)

	dragapproved=true
	document.onmousemove=drag_drop
}


function loadwindow(url,width,height){
	if (i5n6) {
			var htm = '<IFRAME src="'+url+'" width="100%" height="100%" frameborder="0"></IFRAME>'
			DW_Html( htm, "Soluções para a Internet", 450, 80, -1, -1 ) 
		}
	  else {
			if (PopWnd && !PopWnd.closed)  PopWnd.top.location = url
				else  PopWnd = window.open(url,"","width="+width+",height="+height+",scrollbars=1")
		}
}


function maximize(){
	var DocDW = document.getElementById("dwindow")
	if (minrestore==0){
		minrestore=1	//maximize window
		pLeft = DocDW.style.left
		pTop  = DocDW.style.top
		DocDW.style.left  = ns6 ? window.pageXOffset    : document.body.scrollLeft
		DocDW.style.top   = ns6 ? window.pageYOffset    : document.body.scrollTop
		DocDW.style.width = ns6 ? window.innerWidth -20 : document.body.clientWidth
		DocDW.style.height= ns6 ? window.innerHeight-20 : document.body.clientHeight
		document.getElementById("maxname").setAttribute("src",imgRes)
	}
	else{
		minrestore=0	//restore window
		DocDW.style.left	= pLeft
		DocDW.style.top		= pTop
		DocDW.style.width	= initialwidth
		DocDW.style.height	= initialheight
		document.getElementById("maxname").setAttribute("src",imgMax)
	}
}


function closeit(){
	document.getElementById("dwindow").style.display="none"
}

function mouseUp(){
	dragapproved=false
	document.onmousemove=null
	document.getElementById('saver').style.display='none'
}


if (i5n6)  document.onmouseup = new Function("mouseUp()")



//==========================================================================
//		Acrescentado por: Francisco Silva					Nov/2001
//--------------------------------------------------------------------------

// inicializar: criar a estrutura da janela (DIVs, Table e IFRAME...)
function DW_init( cor ) {					// optional: cor da janela
	var htm
	if (!i5n6)  return						// se não é IE5+ ou NS6+ => sair...
	if (cor==null)   cor = "#006699"		// cor de default da janela
	htm = '<DIV id="dwindow" ' 
		+ 'style="position:absolute;background-color:#F1F1F1; '
		+ 'cursor:hand;left:0px;top:0px; border:2px solid ' + cor
		+ ';display:none;z-index:9" onMousedown="initializedrag(event)"> '
		+	'<div align="right">'
		+	'<TABLE  cellspacing=0 cellpadding=0 width="100%" bgcolor="'+ cor +'">'
		+	'<tr> <td style="color:White;text-align:center;vertical-align:middle;'
		+	'		font-family:tahoma,arial;font-size:11px;font-weight:Bold">'
		+		'<div id="dwintit">Janela</div></td><td width=38>'
		+		'<img src="max.gif" id="maxname" onMousedown="maximize()"> '
		+		'<img src="close.gif" onMousedown="closeit()"></td>'
		+	'</tr> </TABLE></div>'
		+	'<DIV id="iFrame"></DIV>'
		+	'<div id="saver"   style="width:100%; display:none;'
		+	'		position:absolute; left:0px; top:0px"> </div>'
		+ '</DIV>'
	document.write( htm )
}


// inicializa de forma idêntica a DW_init(), mas com um layout <> só compatível com IE5+ 
// se tit  ="" Barra de título default ...
// se max: ="" -> não há botão, ="1" -> botão default, {else} -> IMG src="[max],[res]"
// se clo: ="" -> não há botão, ="1" -> botão default, {else} -> IMG src="[clo]"
function DW_initPlus( tit, max, clo, cor ) {	// optional: cor da janela (não se aplica no IE+)
	var htm
	if (!i5n6)  return							// se não é IE5+ ou NS6+ => sair...						
	if (tit=="")  { tit = '<TABLE class="titBody" cellspacing=0 cellpadding=0> <tr>'
						+ '	<td class="titLeft"></td>'
						+		DW_titBordo( max, clo )
						+ '	</tr> </TABLE>'   }
	htm = '	<DIV id="dwindow" 		onMouseDown="initializedrag(event)"'
		+ '				style="position:absolute;left:0px;top:0px;display:none;z-index:9" >'
		+ '		<DIV class="titLine">' + tit + '</DIV>'	
		+ '		<DIV id="iFrame"></DIV>'
		+ '		<DIV id="saver"  style="width:100%; display:none;'
		+ '							 position:absolute; left:0px; top:0px"> </DIV>'
		+ '	</DIV>'	
	document.write( htm )
}


function DW_titBordo( max, clo ) {
	if (max=="") imgMax = "" 
		else {	 if (max!="1" && max!=null)  set_MaxRes(max)
				 max = '<img class="BotMax"   src="'+imgMax+'" id="maxname" '
					 + '     alt="Maximizar / Restaurar" onMouseDown="maximize()">'  }
	if (clo=="") imgClo = ""
		else {	 if (clo!="1" && clo!=null)  imgClo = clo 
				 clo = '<img class="BotClose" src="'+imgClo+'" '
					 + '     alt="Fechar" onMouseDown="closeit()">'  }
	var htm = '<td  class="titBordo">'
			+ '  <table class="titTab" cellspacing=0 cellpadding=0><tr>'
			+ '	   <td  class="titTexto" nowrap>'
			+ '		   &nbsp; &nbsp; <span id="dwintit">Janela</span> &nbsp;</td>'
			+ '	   <td class="titBotoes" nowrap>' + max + clo + '</td> </tr>'
			+ '  </table>  </td>'
	return htm
}


function set_MaxRes(max) {
	var pos, gif1, gif2
	pos  = max.indexOf(",")
	gif1 = max.substring(0,pos)
	gif2 = max.substring(pos+1,max.length)
	
	if (pos==-1) imgMax = gif2
		else {	 imgMax = gif1;  imgRes = gif2	}
}


// abre a janela carregando o "url" ou "htm" (se IE5+/NS6)
function DW_UrlHtm( url, htm, tit, width, height, left, top ) {
	if (i5n6)	DW_Html( htm, tit, width, height, left, top )
		else	DW_Url(  url, tit, width, height, left, top ) 
}


// abre a janela carregando o "url"  -  permite indicar tit, size, pos  (""/-1 = default)
function DW_Url( url, tit, width, height, left, top ) {
	loadwindow( url, width, height )
	if (i5n6)  {
			if (tit!="")  document.getElementById("dwintit").innerHTML = tit
			DW_SizePos( width, height, left, top )	
		}
}


// abre a janela carregando o "html"  -  permite indicar tit, size, pos  (""/-1 = default)
function DW_Html( htm, tit, width, height, left, top ) {
	var DocIF = document.getElementById("iFrame")
	DocIF.innerHTML	   = htm
	DocIF.style.height = height
	if (tit!="")  document.getElementById("dwintit").innerHTML = tit
	document.getElementById("dwindow").style.display=''
	DW_SizePos( width, height, left, top )	
}


// alterar size e pos  (-1 = default)
function DW_SizePos( width, height, left, top ) {
	var DocDW = document.getElementById("dwindow")
	DocDW.style.left   = (left  >=0) ? left : initialLeft
	DocDW.style.top    = (top   >=0) ? top  : initialTop
	DocDW.style.width  = (width >=0) ? initialwidth = width  : initialwidth
	DocDW.style.height = (height>=0) ? initialheight= height : initialheight
	minrestore = 0			// repor o estado da janela (normal)
	if (imgMax!="")	document.getElementById("maxname").setAttribute("src",imgMax)
}

