// array de janelas
var windowOpened=[];
var PWCWindow=[];

function janela(url, cabtitulo, wid, hei, posx, posy, tipos)
{
	if(typeof(posx) == 'undefined' || posx == "")
		posx = 0;

	if(typeof(posy) == 'undefined' || posy == "")
		posy = 0;

	param = ',width=' + wid + ',height=' + hei;
	var str = 'fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no';

	if(tipos != "" && typeof(tipos) != 'undefined')
	{
		types = tipos.split(",");
		for(i=0; i < types.length; i++)
		{
			str = str.replace((types[i] + '=no'), (types[i] + '=yes'));
		}
	}

	str += param;
	if(posx == 0 && posy == 0)
	{
		//centralizar janela
		pleft = ((screen.width/2)-(wid/2));
		ptop = ((screen.height/2)-(hei/2));
	}
	else
	{
		pleft = posx;
		ptop = posy;
	}

	str  += ',left='+pleft+',top='+ptop;

	// tenta abrir a janela popup
	try	{
		var w = window.open(url, cabtitulo, str);
		var wid = windowOpened.length;

		// verifica se já existe uma janela aberta com este nome.
		for(var i=0; i<wid; i++)
		{
			if(cabtitulo == windowOpened[i].id)
			{
				windowOpened[i].obj = w;
				w = windowOpened[i].obj;
				w.focus();
				return w;
			}
		}
		// coloca a nova janela no array de janelas
		windowOpened[wid] = {id: cabtitulo, obj: w};
		w = windowOpened[wid].obj;
		w.focus();
		return w;
	}
	// caso não consiga
	catch(err) {
		alert("Para o sistema funcionar você deve desabilitar o bloqueador de pop-up para este site!.")
	}
}

function janela_modal (url, wid, hei, posx, posy, scrbar, wcenter, wobj)
{
	if (posx   == "") posx   = 0;
	if (posy   == "") posy   = 0;
	if (scrbar == "") scrbar = "no";
	if(wcenter == "")
		var str =('help: no;status: no;scroll: '+scrbar+'; resizable: no;dialogWidth: ' + wid + 'px;dialogHeight: ' + hei + 'px;dialogLeft: ' + posx + 'px;dialogTop: ' + posy + 'px');
	else
		var str =('help: no;center: '+wcenter+';status: no;scroll: '+scrbar+'; resizable: no;dialogWidth: ' + wid + 'px;dialogHeight: ' + hei + 'px');

	returnstr = window.showModalDialog(url,'',str);
	if(wobj)
		wobj.value = returnstr;
}

function janelaPWC(url, windowTitle, windowId, wid, hei, opcoes)
{
	if(typeof(windowId) == 'undefined' || windowId == "")
		windowId = 0;
	if(typeof(windowTitle) == 'undefined' || windowTitle == "")
		windowTitle = '';

	opcoes += "draggable:true, wiredDrag: true, destroyOnClose: true, recenterAuto:true, showEffect: Element.show, hideEffect: Element.hide";
	PWCWindow[windowId] = eval("new Window({className: 'sb',  width: wid, height: hei, title: 'ShoppingBrasil" + windowTitle +"', " + opcoes + " });");
	PWCWindow[windowId].showCenter(true);
	if(opcoes.indexOf("maximize") != -1)
		PWCWindow[windowId].maximize();
	PWCWindow[windowId].setZIndex(200);
	setTimeout("PWCWindow['"+windowId+"'].setURL('"+url+"');", 500);
}
