var rectangleDiv
var boxcounter		= 0
var nameOfCookie	= 'web_janelas';
var cookieCounter	= 0;

function zTop (obj) {
	if(!obj) obj = this
	var zt = 0
	for (var i=0;i<$$('div').length;i++) {
		if ($$('div')[i].id.indexOf('caixa') != -1) {
			if ($$('div')[i].style.zIndex > zt) zt = $$('div')[i].style.zIndex
		}
	}
	try { if (obj.style.zIndex <= zt) obj.style.zIndex = zt + 1 } catch(e) {}
	$('caixadaVezNo').value = obj.id.replace('caixa','');
}

function criajanela(pagina, width_, top_, left_) {
	/* Creating rectangle div */
	if(!pagina) return false
	boxcounter += 1;
	if	(top_  == 'x')		top_	= posy;
	if	(left_ == 'y')		left_	= posx;
	if	(!top_)		top_	= 10;
	if	(!left_)	left_	= 160;
	if	(!width_)	width_	= 600;
//	if(!ie4) { 
//		scrll = window.scrollY
//	} else {
		scrll = window.document.documentElement.scrollTop;
//	}
	top_	+=  (boxcounter * 5)+scrll;
	top_ = 100 + scrll;
	left_	+=  boxcounter * 5;

	rectangleDiv = document.createElement('DIV');
	rectangleDiv.id	= 'caixa'+ boxcounter;
	rectangleDiv.className = 'janela';
	rectangleDiv.style.cssText	= 'padding:0px; border:3px #036 solid';
	rectangleDiv.style.left 	= left_ +'px';
	rectangleDiv.style.top	 	= top_ +'px';
	rectangleDiv.style.width 	= width_ +'px';
	rectangleDiv.style.position	= 'absolute';
	rectangleDiv.onmousedown = zTop
	zTop(rectangleDiv)
	document.forms[0].appendChild(rectangleDiv);
		
	if (boxcounter == 1) {
//		ajaxHTML('scripts/janela.php',rectangleDiv.id, getpostdata() );
		$(rectangleDiv.id).style.display = 'none';
		criajanela(pagina, width_, top_, left_)
	} else {
		ajaxHTML(dominio+'scripts/janela.php?janela='+boxcounter+'&pagina='+pagina,rectangleDiv.id);
	}
	top_	= 10;
//////////////////////////////////////////////////////////////////////CRIA COOKIE C/ INFO DA JANELA
//	var variaveis = pagina +'@'+ top_ +'@'+ left_
//	Set_Cookie(nameOfCookie + boxcounter, variaveis , 60000);
}

//window.onload = inicio;
function inicio() {
	var cookieValue = Get_Cookie(nameOfCookie + '1');
	if (cookieValue && cookieValue!='') {
	var v = cookieValue.split('@')
	criajanela(v[0], v[1], v[2])
}

var ccs = ''

cookieCounter = 2

while(cookieValue && cookieValue!=''){

//var items = cookieValue.split('#;#');
			
//if(items.length>1 && !tmpArray[items[0]]){
//tmpArray[items[0]] = true;
//createARSSBox(items[0],items[1],items[3],items[2],items[4],items[5]);
//cookieRSSSources[items[0]]=cookieCounter;
//}else{
//criajanela(cookieValue);
ccs = ccs +'#'+ cookieValue;

cookieValue = Get_Cookie(nameOfCookie + cookieCounter);

cookieCounter += 1;

}

ccs = ccs.substring(1,ccs.length);

var c = ccs.split('#')

for(i=1;i<c.length;i++) {

var v = c[i].split('@')
criajanela(v[0], v[1], v[2])

}
}

function fechaJanela(obj) {
	try {
		document.forms[0].removeChild($parent(obj,2))
	} catch(e) {
		document.forms[0].removeChild($parent(obj,3))
	}
}

function tituloJanela(obj, mensagem) {
	try {
		lbl = $('dragtitle' + $parent(obj).id.replace('in',''))
		lbl.innerHTML = mensagem
	} catch(e) {
		try {
			lbl = $('dragtitle' + $parent(obj,2).id.replace('in',''))
			lbl.innerHTML = mensagem
		} catch(e) {
			lbl = $('dragtitle' + $parent(obj,3).id.replace('in',''))
			lbl.innerHTML = mensagem
		}
	}
}