function getFrameByName(frameName, bframe) {
	if (bframe == null)
		bframe = self;

	for (var i=0, ls=bframe.length; i<ls; i++) {
		try {
			if (bframe.frames[i].length > 0)
				var rf = getFrameByName(frameName, bframe.frames[i]);
				if (rf != null)
					return rf;
			else {
					if (bframe.frames[i].name == frameName)
						return bframe.frames[i];
			}
		} catch(e) {
		}
	}

	return null;
}

function getFrame(frameName, bframe) {
	if (typeof(frameName) == "string")
		frameName = getFrameByName(frameName, bframe);
	return frameName;
}
top.getFrame = getFrame;

function getUrlParam(url, name) {
	if (url == null)
		return null;
	var p = url.indexOf("?");
	if (p > -1) {
		name = name.toUpperCase();
		var aurl = url.substr(p + 1).split("&");
		for (var i=0; i<aurl.length; i++) {
			var v = aurl[i];
			var pe = v.indexOf("=");
			if (pe > -1 && v.substring(0, pe).toUpperCase() == name)
				return v.substring(pe + 1);
		}
	}
	return null;
}

function popup(strUrl, width, height, windowSource, isModal, includePopUpHTML, wleft, wtop, parsArray, useLastPosition, popupFlags) {

    if (popup.arguments[4] == null)
        isModal = !(getUrlParam(strUrl, "_MODAL_") == "0");
    if (isNaN(width)) 
        width = 1000;
    if (isNaN(height))
        height = 650;
    if (strUrl.indexOf("_TEAPOPUP_") < 0) {
        if (strUrl.indexOf("?") < 0)
            strUrl += "?"
        else
            strUrl += "&"
        strUrl += "_TEAPOPUP_=1"
    }

    if(!windowSource)
        windowSource = "iInformacao";

    windowSource = top.getFrame(windowSource);

    if (windowSource == null)
        windowSource = self;

    if (includePopUpHTML != false)
        strUrl = getvdir() + "popup.htm?p=" + escape(strUrl);   

	if (isModal == true) {
		rv = showModalDialog(getvdir() + "Popup.htm", [windowSource, top, strUrl], "dialogHeight:" + (height - 12 - 24) + "px;dialogWidth:" + (width - 12) + "px;resizable:yes;status:no");
	} else {
        top.lastOpener = windowSource;
	    open(strUrl, "", "resizable=yes,status=no,help=no,height=" + (height - 12 - 24) + "px,width=" + (width - 12) + "px");
	}

	execute_popup_flags(popupFlags, windowSource);
}

function execute_popup_flags(popupFlags, windowSource) {
	if (popupFlags == null)
	    popupFlags = 0;

    if (windowSource == null)
        windowSource = self;

    if ((1 | popupFlags) == popupFlags) { // refreshWindowOpennerOnClose
        if(typeof(windowSource.TEARefresh) != "undefined")
            windowSource.TEARefresh();
    }

    if ((2 | popupFlags) == popupFlags) { // closeCurrentPoupAfterOpenNew
        if(top.getFrame){
            var trgFrame = top.getFrame(windowSource.document.forms[0].target);
            if(trgFrame)
                trgFrame.name='';
            else
                windowSource.name='';
        } else {
            windowSource.name='';
        }
        windowSource.setTimeout('try{top.close()}catch(e){}',10);
    }
}

top.popup = popup;
top._TEAShared= "/CGIShared";

function displayInformation (message,popup,customPage) {displayMessage (message,"information",popup,customPage);}
function displayWarning (message,popup,customPage) {displayMessage (message,"warning",popup,customPage);}
function displayError (message,popup,customPage) {displayMessage (message,"error",popup,customPage);}
function displayQuestion (message,popup,customPage)  {return displayMessage (message,"question",true,customPage);}
function display (message,popup,customPage)  {displayMessage (message,"",false,customPage);}
function displayMessage (message,type,popup,customPage)
{
    if (message == "") return null;

    if (type == "question") {
        return confirm(message);
    } else {
        alert(message);
        return null;
    }
}

var _vdir = null;
function initvdir() {
    var s=top.location.href;
    var h=top.location.hostname;
    var i=s.indexOf("/",s.indexOf(h))+1;
    _vdir = "/"+s.substring(i,s.indexOf("/",i))+"/";
}
initvdir();
function getvdir()
{
	return _vdir;
}
function closePopup() {self.name='';top.appSair=true;top.close();}

function waitMessage(s)
{
    var dv = top.document.getElementById('cgiimp');
    if (dv)
        dv.style.display = (s=="START")? "": "none";
}
function CGIOnLoad(win)
{
}
