// "/scripts/funcoes.js"

// MM_preloadImages
// MM_reloadPage
// GoTo
// Menu
// addMenuItem
// Find
// writeMenus
// NS4resize
// onMenuItemOver
// onMenuItemAction
// MM_clearTimeout
// MM_startTimeout
// mmDoHide
// MM_showMenu
// onMenuItemDown
// mouseupMenu
// getExplorerVersion
// mouseoutMenu
// hideMenu
// hideChildMenu
// hideActiveMenus
// moveXbySlicePos
// moveYbySlicePos
// Limpar
// formatavalor
// filtracampo
// desformatar
// formatadata
// formatahora
// formatacep
// arredondar
// apresentaValor
// ValidaEmail
// formatafone
// trim
// counter
// GravarCookie
// LerCookie
// ExcluirCookie
// GetQueryString
// validaMacAddress
// ValidaCpfCnpj
// SoNumero
// SoNumeroLetra
// SoLetra
// MudaMenu
// ValidaUserLogin
// LoadIframe
// Asc
// Chr
// ValidaData
// ValidaHora
// -------------------------

// --- Declaração de variáveis pública ---
var lefttime = 0;
var righttime = 0;
var idNrFrame = '';
var CorFoco = '';
//----------------------------------------

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function GoTo(url, janela) {
   document.getElementById('redireciona').action=url;
   document.getElementById('redireciona').target=janela;
   document.getElementById('redireciona').submit();
}

function Menu(label, mw, mh, fnt, fs, fclr, fhclr, bg, bgh, halgn, valgn, pad, space, to, sx, sy, srel, opq, vert, idt, aw, ah) 
{
	this.version = "020320 [Menu; mm_menu.js]";
	this.type = "Menu";
	this.menuWidth = mw;
	this.menuItemHeight = mh;
	this.fontSize = fs;
	this.fontWeight = "plain";
	this.fontFamily = fnt;
	this.fontColor = fclr;
	this.fontColorHilite = fhclr;
	this.bgColor = "#555555";
	this.menuBorder = 1;
	this.menuBgOpaque=opq;
	this.menuItemBorder = 1;
	this.menuItemIndent = idt;
	this.menuItemBgColor = bg;
	this.menuItemVAlign = valgn;
	this.menuItemHAlign = halgn;
	this.menuItemPadding = pad;
	this.menuItemSpacing = space;
	this.menuLiteBgColor = "#ffffff";
	this.menuBorderBgColor = "#777777";
	this.menuHiliteBgColor = bgh;
	this.menuContainerBgColor = "#cccccc";
	this.childMenuIcon = "arrows.gif";
	this.submenuXOffset = sx;
	this.submenuYOffset = sy;
	this.submenuRelativeToItem = srel;
	this.vertical = vert;
	this.items = new Array();
	this.actions = new Array();
	this.childMenus = new Array();
	this.hideOnMouseOut = true;
	this.hideTimeout = to;
	this.addMenuItem = addMenuItem;
	this.writeMenus = writeMenus;
	this.MM_showMenu = MM_showMenu;
	this.onMenuItemOver = onMenuItemOver;
	this.onMenuItemAction = onMenuItemAction;
	this.hideMenu = hideMenu;
	this.hideChildMenu = hideChildMenu;
	if (!window.menus) window.menus = new Array();
	this.label = " " + label;
	window.menus[this.label] = this;
	window.menus[window.menus.length] = this;
	if (!window.activeMenus) window.activeMenus = new Array();
}

function addMenuItem(label, action) {
	this.items[this.items.length] = label;
	this.actions[this.actions.length] = action;
}

function Find(item) {
	if( window.mmIsOpera ) return(document.getElementById(item));
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}

function writeMenus(container) {
	if (window.triedToWriteMenus) return;
	var agt = navigator.userAgent.toLowerCase();
	window.mmIsOpera = agt.indexOf("opera") != -1;
	if (!container && document.layers) {
		window.delayWriteMenus = this.writeMenus;
		var timer = setTimeout('delayWriteMenus()', 500);
		container = new Layer(100);
		clearTimeout(timer);
	} else if (document.all || document.hasChildNodes || window.mmIsOpera) {
		document.writeln('<span id="menuContainer"></span>');
		container = Find("menuContainer");
	}

	window.mmHideMenuTimer = null;
	if (!container) return;	
	window.triedToWriteMenus = true; 
	container.isContainer = true;
	container.menus = new Array();
	for (var i=0; i<window.menus.length; i++) 
		container.menus[i] = window.menus[i];
	window.menus.length = 0;
	var countMenus = 0;
	var countItems = 0;
	var top = 0;
	var content = '';
	var lrs = false;
	var theStat = "";
	var tsc = 0;
	if (document.layers) lrs = true;
	for (var i=0; i<container.menus.length; i++, countMenus++) {
		var menu = container.menus[i];
		if (menu.bgImageUp || !menu.menuBgOpaque) {
			menu.menuBorder = 0;
			menu.menuItemBorder = 0;
		}
		if (lrs) {
			var menuLayer = new Layer(100, container);
			var lite = new Layer(100, menuLayer);
			lite.top = menu.menuBorder;
			lite.left = menu.menuBorder;
			var body = new Layer(100, lite);
			body.top = menu.menuBorder;
			body.left = menu.menuBorder;
		} else {
			content += ''+
			'<div id="menuLayer'+ countMenus +'" style="position:absolute;z-index:1;left:10px;top:'+ (i * 100) +'px;visibility:hidden;color:' +  menu.menuBorderBgColor + ';">\n'+
			'  <div id="menuLite'+ countMenus +'" style="position:absolute;z-index:1;left:'+ menu.menuBorder +'px;top:'+ menu.menuBorder +'px;visibility:hide;" onmouseout="mouseoutMenu();">\n'+
			'	 <div id="menuFg'+ countMenus +'" style="position:absolute;left:'+ menu.menuBorder +'px;top:'+ menu.menuBorder +'px;visibility:hide;">\n'+
			'';
		}
		var x=i;
		for (var i=0; i<menu.items.length; i++) {
			var item = menu.items[i];
			var childMenu = false;
			var defaultHeight = menu.fontSize+2*menu.menuItemPadding;
			if (item.label) {
				item = item.label;
				childMenu = true;
			}
			menu.menuItemHeight = menu.menuItemHeight || defaultHeight;
			var itemProps = '';
			if( menu.fontFamily != '' ) itemProps += 'font-family:' + menu.fontFamily +';';
			itemProps += 'font-weight:' + menu.fontWeight + ';fontSize:' + menu.fontSize + 'px;';
			if (menu.fontStyle) itemProps += 'font-style:' + menu.fontStyle + ';';
			if (document.all || window.mmIsOpera) 
				itemProps += 'font-size:' + menu.fontSize + 'px;" onmouseover="onMenuItemOver(null,this);" onclick="onMenuItemAction(null,this);';
			else if (!document.layers) {
				itemProps += 'font-size:' + menu.fontSize + 'px;';
			}
			var l;
			if (lrs) {
				var lw = menu.menuWidth;
				if( menu.menuItemHAlign == 'right' ) lw -= menu.menuItemPadding;
				l = new Layer(lw,body);
			}
			var itemLeft = 0;
			var itemTop = i*menu.menuItemHeight;
			if( !menu.vertical ) {
				itemLeft = i*menu.menuWidth;
				itemTop = 0;
			}
			var dTag = '<div id="menuItem'+ countItems +'" style="position:absolute;left:' + itemLeft + 'px;top:'+ itemTop +'px;'+ itemProps +'">';
			var dClose = '</div>'
			if (menu.bgImageUp) dTag = '<div id="menuItem'+ countItems +'" style="background:url('+menu.bgImageUp+');position:absolute;left:' + itemLeft + 'px;top:'+ itemTop +'px;'+ itemProps +'">';

			var left = 0, top = 0, right = 0, bottom = 0;
			left = 1 + menu.menuItemPadding + menu.menuItemIndent;
			right = left + menu.menuWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
			if( menu.menuItemVAlign == 'top' ) top = menu.menuItemPadding;
			if( menu.menuItemVAlign == 'bottom' ) top = menu.menuItemHeight-menu.fontSize-1-menu.menuItemPadding;
			if( menu.menuItemVAlign == 'middle' ) top = ((menu.menuItemHeight/2)-(menu.fontSize/2)-1);
			bottom = menu.menuItemHeight - 2*menu.menuItemPadding;
			var textProps = 'position:absolute;left:' + left + 'px;top:' + top + 'px;';
			if (lrs) {
				textProps +=itemProps + 'right:' + right + ';bottom:' + bottom + ';';
				dTag = "";
				dClose = "";
			}
			
			if(document.all && !window.mmIsOpera) {
				item = '<div align="' + menu.menuItemHAlign + '">' + item + '</div>';
			} else if (lrs) {
				item = '<div style="text-align:' + menu.menuItemHAlign + ';">' + item + '</div>';
			} else {
				var hitem = null;
				if( menu.menuItemHAlign != 'left' ) {
					if(window.mmIsOpera) {
						var operaWidth = menu.menuItemHAlign == 'center' ? -(menu.menuWidth-2*menu.menuItemPadding) : (menu.menuWidth-6*menu.menuItemPadding);
						hitem = '<div id="menuItemHilite' + countItems + 'Shim" style="position:absolute;top:1px;left:' + menu.menuItemPadding + 'px;width:' + operaWidth + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
						item = '<div id="menuItemText' + countItems + 'Shim" style="position:absolute;top:1px;left:' + menu.menuItemPadding + 'px;width:' + operaWidth + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
					} else {
						hitem = '<div id="menuItemHilite' + countItems + 'Shim" style="position:absolute;top:1px;left:1px;right:-' + (left+menu.menuWidth-3*menu.menuItemPadding) + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
						item = '<div id="menuItemText' + countItems + 'Shim" style="position:absolute;top:1px;left:1px;right:-' + (left+menu.menuWidth-3*menu.menuItemPadding) + 'px;text-align:' 
							+ menu.menuItemHAlign + ';visibility:visible;">' + item + '</div>';
					}
				} else hitem = null;
			}
			if(document.all && !window.mmIsOpera) item = '<div id="menuItemShim' + countItems + '" style="position:absolute;left:0px;top:0px;">' + item + '</div>';
			var dText	= '<div id="menuItemText'+ countItems +'" style="' + textProps + 'color:'+ menu.fontColor +';">'+ item +'&nbsp</div>\n'
						+ '<div id="menuItemHilite'+ countItems +'" style="' + textProps + 'color:'+ menu.fontColorHilite +';visibility:hidden;">' 
						+ (hitem||item) +'&nbsp</div>';
			if (childMenu) content += ( dTag + dText + '<div id="childMenu'+ countItems +'" style="position:absolute;left:0px;top:3px;"><img src="'+ menu.childMenuIcon +'"></div>\n' + dClose);
			else content += ( dTag + dText + dClose);
			if (lrs) {
				l.document.open("text/html");
				l.document.writeln(content);
				l.document.close();	
				content = '';
				theStat += "-";
				tsc++;
				if (tsc > 50) {
					tsc = 0;
					theStat = "";
				}
				status = theStat;
			}
			countItems++;  
		}
		if (lrs) {
			var focusItem = new Layer(100, body);
			focusItem.visiblity="hidden";
			focusItem.document.open("text/html");
			focusItem.document.writeln("&nbsp;");
			focusItem.document.close();	
		} else {
		  content += '	  <div id="focusItem'+ countMenus +'" style="position:absolute;left:0px;top:0px;visibility:hide;" oonclick="onMenuItemAction(null,this);">&nbsp;</div>\n';
		  content += '   </div>\n  </div>\n</div>\n';
		}
		i=x;
	}
	if (document.layers) {		
		container.clip.width = window.innerWidth;
		container.clip.height = window.innerHeight;
		container.onmouseout = mouseoutMenu;
		container.menuContainerBgColor = this.menuContainerBgColor;
		for (var i=0; i<container.document.layers.length; i++) {
			proto = container.menus[i];
			var menu = container.document.layers[i];
			container.menus[i].menuLayer = menu;
			container.menus[i].menuLayer.Menu = container.menus[i];
			container.menus[i].menuLayer.Menu.container = container;
			var body = menu.document.layers[0].document.layers[0];
			body.clip.width = proto.menuWidth || body.clip.width;
			body.clip.height = proto.menuHeight || body.clip.height;
			for (var n=0; n<body.document.layers.length-1; n++) {
				var l = body.document.layers[n];
				l.Menu = container.menus[i];
				l.menuHiliteBgColor = proto.menuHiliteBgColor;
				l.document.bgColor = proto.menuItemBgColor;
				l.saveColor = proto.menuItemBgColor;
				l.onmouseover = proto.onMenuItemOver;
				l.onclick = proto.onMenuItemAction;
				l.mmaction = container.menus[i].actions[n];
				l.focusItem = body.document.layers[body.document.layers.length-1];
				l.clip.width = proto.menuWidth || body.clip.width;
				l.clip.height = proto.menuItemHeight || l.clip.height;
				if (n>0) {
					if( l.Menu.vertical ) l.top = body.document.layers[n-1].top + body.document.layers[n-1].clip.height + proto.menuItemBorder + proto.menuItemSpacing;
					else l.left = body.document.layers[n-1].left + body.document.layers[n-1].clip.width + proto.menuItemBorder + proto.menuItemSpacing;
				}
				l.hilite = l.document.layers[1];
				if (proto.bgImageUp) l.background.src = proto.bgImageUp;
				l.document.layers[1].isHilite = true;
				if (l.document.layers.length > 2) {
					l.childMenu = container.menus[i].items[n].menuLayer;
					l.document.layers[2].left = l.clip.width -13;
					l.document.layers[2].top = (l.clip.height / 2) -4;
					l.document.layers[2].clip.left += 3;
					l.Menu.childMenus[l.Menu.childMenus.length] = l.childMenu;
				}
			}
			if( proto.menuBgOpaque ) body.document.bgColor = proto.bgColor;
			if( proto.vertical ) {
				body.clip.width  = l.clip.width +proto.menuBorder;
				body.clip.height = l.top + l.clip.height +proto.menuBorder;
			} else {
				body.clip.height  = l.clip.height +proto.menuBorder;
				body.clip.width = l.left + l.clip.width  +proto.menuBorder;
				if( body.clip.width > window.innerWidth ) body.clip.width = window.innerWidth;
			}
			var focusItem = body.document.layers[n];
			focusItem.clip.width = body.clip.width;
			focusItem.Menu = l.Menu;
			focusItem.top = -30;
            focusItem.captureEvents(Event.MOUSEDOWN);
            focusItem.onmousedown = onMenuItemDown;
			if( proto.menuBgOpaque ) menu.document.bgColor = proto.menuBorderBgColor;
			var lite = menu.document.layers[0];
			if( proto.menuBgOpaque ) lite.document.bgColor = proto.menuLiteBgColor;
			lite.clip.width = body.clip.width +1;
			lite.clip.height = body.clip.height +1;
			menu.clip.width = body.clip.width + (proto.menuBorder * 3) ;
			menu.clip.height = body.clip.height + (proto.menuBorder * 3);
		}
	} else {
		if ((!document.all) && (container.hasChildNodes) && !window.mmIsOpera) {
			container.innerHTML=content;
		} else {
			container.document.open("text/html");
			container.document.writeln(content);
			container.document.close();	
		}
		if (!Find("menuLayer0")) return;
		var menuCount = 0;
		for (var x=0; x<container.menus.length; x++) {
			var menuLayer = Find("menuLayer" + x);
			container.menus[x].menuLayer = "menuLayer" + x;
			menuLayer.Menu = container.menus[x];
			menuLayer.Menu.container = "menuLayer" + x;
			menuLayer.style.zindex = 1;
		    var s = menuLayer.style;
			s.pixeltop = -300;
			s.pixelleft = -300;
			s.top = '-300px';
			s.left = '-300px';

			var menu = container.menus[x];
			menu.menuItemWidth = menu.menuWidth || menu.menuIEWidth || 140;
			if( menu.menuBgOpaque ) menuLayer.style.backgroundColor = menu.menuBorderBgColor;
			var top = 0;
			var left = 0;
			menu.menuItemLayers = new Array();
			for (var i=0; i<container.menus[x].items.length; i++) {
				var l = Find("menuItem" + menuCount);
				l.Menu = container.menus[x];
				l.Menu.menuItemLayers[l.Menu.menuItemLayers.length] = l;
				if (l.addEventListener || window.mmIsOpera) {
					l.style.width = menu.menuItemWidth + 'px';
					l.style.height = menu.menuItemHeight + 'px';
					l.style.pixelWidth = menu.menuItemWidth;
					l.style.pixelHeight = menu.menuItemHeight;
					l.style.top = top + 'px';
					l.style.left = left + 'px';
					if(l.addEventListener) {
						l.addEventListener("mouseover", onMenuItemOver, false);
						l.addEventListener("click", onMenuItemAction, false);
						l.addEventListener("mouseout", mouseoutMenu, false);
					}
					if( menu.menuItemHAlign != 'left' ) {
						l.hiliteShim = Find("menuItemHilite" + menuCount + "Shim");
						l.hiliteShim.style.visibility = "inherit";
						l.textShim = Find("menuItemText" + menuCount + "Shim");
						l.hiliteShim.style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						l.hiliteShim.style.width = l.hiliteShim.style.pixelWidth;
						l.textShim.style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						l.textShim.style.width = l.textShim.style.pixelWidth;	
					}
				} else {
					l.style.pixelWidth = menu.menuItemWidth;
					l.style.pixelHeight = menu.menuItemHeight;
					l.style.pixelTop = top;
					l.style.pixelLeft = left;
					if( menu.menuItemHAlign != 'left' ) {
						var shim = Find("menuItemShim" + menuCount);
						shim[0].style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						shim[1].style.pixelWidth = menu.menuItemWidth - 2*menu.menuItemPadding - menu.menuItemIndent;
						shim[0].style.width = shim[0].style.pixelWidth + 'px';
						shim[1].style.width = shim[1].style.pixelWidth + 'px';
					}
				}
				if( menu.vertical ) top = top + menu.menuItemHeight+menu.menuItemBorder+menu.menuItemSpacing;
				else left = left + menu.menuItemWidth+menu.menuItemBorder+menu.menuItemSpacing;
				l.style.fontSize = menu.fontSize + 'px';
				l.style.backgroundColor = menu.menuItemBgColor;
				l.style.visibility = "inherit";
				l.saveColor = menu.menuItemBgColor;
				l.menuHiliteBgColor = menu.menuHiliteBgColor;
				l.mmaction = container.menus[x].actions[i];
				l.hilite = Find("menuItemHilite" + menuCount);
				l.focusItem = Find("focusItem" + x);
				l.focusItem.style.pixelTop = -30;
				l.focusItem.style.top = '-30px';
				var childItem = Find("childMenu" + menuCount);
				if (childItem) {
					l.childMenu = container.menus[x].items[i].menuLayer;
					childItem.style.pixelLeft = menu.menuItemWidth -11;
					childItem.style.left = childItem.style.pixelLeft + 'px';
					childItem.style.pixelTop = (menu.menuItemHeight /2) -4;
					childItem.style.top = childItem.style.pixelTop + 'px';
					l.Menu.childMenus[l.Menu.childMenus.length] = l.childMenu;
				}
				l.style.cursor = "hand";
				menuCount++;
			}
			if( menu.vertical ) {
				menu.menuHeight = top-1-menu.menuItemSpacing;
				menu.menuWidth = menu.menuItemWidth;
			} else {
				menu.menuHeight = menu.menuItemHeight;
				menu.menuWidth = left-1-menu.menuItemSpacing;
			}

			var lite = Find("menuLite" + x);
			var s = lite.style;
			s.pixelHeight = menu.menuHeight +(menu.menuBorder * 2);
			s.height = s.pixelHeight + 'px';
			s.pixelWidth = menu.menuWidth + (menu.menuBorder * 2);
			s.width = s.pixelWidth + 'px';
			if( menu.menuBgOpaque ) s.backgroundColor = menu.menuLiteBgColor;

			var body = Find("menuFg" + x);
			s = body.style;
			s.pixelHeight = menu.menuHeight + menu.menuBorder;
			s.height = s.pixelHeight + 'px';
			s.pixelWidth = menu.menuWidth + menu.menuBorder;
			s.width = s.pixelWidth + 'px';
			if( menu.menuBgOpaque ) s.backgroundColor = menu.bgColor;

			s = menuLayer.style;
			s.pixelWidth  = menu.menuWidth + (menu.menuBorder * 4);
			s.width = s.pixelWidth + 'px';
			s.pixelHeight  = menu.menuHeight+(menu.menuBorder*4);
			s.height = s.pixelHeight + 'px';
		}
	}
	if (document.captureEvents) document.captureEvents(Event.MOUSEUP);
	if (document.addEventListener) document.addEventListener("mouseup", onMenuItemOver, false);
	if (document.layers && window.innerWidth) {
		window.onresize = NS4resize;
		window.NS4sIW = window.innerWidth;
		window.NS4sIH = window.innerHeight;
		setTimeout("NS4resize()",500);
	}
	document.onmouseup = mouseupMenu;
	window.mmWroteMenu = true;
	status = "";
}

function NS4resize() {
	if (NS4sIW != window.innerWidth || NS4sIH != window.innerHeight) window.location.reload();
}

function onMenuItemOver(e, l) {
	MM_clearTimeout();
	l = l || this;
	a = window.ActiveMenuItem;
	if (document.layers) {
		if (a) {
			a.document.bgColor = a.saveColor;
			if (a.hilite) a.hilite.visibility = "hidden";
			if (a.Menu.bgImageOver) a.background.src = a.Menu.bgImageUp;
			a.focusItem.top = -100;
			a.clicked = false;
		}
		if (l.hilite) {
			l.document.bgColor = l.menuHiliteBgColor;
			l.zIndex = 1;
			l.hilite.visibility = "inherit";
			l.hilite.zIndex = 2;
			l.document.layers[1].zIndex = 1;
			l.focusItem.zIndex = this.zIndex +2;
		}
		if (l.Menu.bgImageOver) l.background.src = l.Menu.bgImageOver;
		l.focusItem.top = this.top;
		l.focusItem.left = this.left;
		l.focusItem.clip.width = l.clip.width;
		l.focusItem.clip.height = l.clip.height;
		l.Menu.hideChildMenu(l);
	} else if (l.style && l.Menu) {
		if (a) {
			a.style.backgroundColor = a.saveColor;
			if (a.hilite) a.hilite.style.visibility = "hidden";
			if (a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
			if (a.Menu.bgImageUp) a.style.background = "url(" + a.Menu.bgImageUp +")";;
		} 
		l.style.backgroundColor = l.menuHiliteBgColor;
		l.zIndex = 1;
		if (l.Menu.bgImageOver) l.style.background = "url(" + l.Menu.bgImageOver +")";
		if (l.hilite) {
			l.hilite.style.visibility = "inherit";
			if( l.hiliteShim ) l.hiliteShim.style.visibility = "visible";
		}
		l.focusItem.style.pixelTop = l.style.pixelTop;
		l.focusItem.style.top = l.focusItem.style.pixelTop + 'px';
		l.focusItem.style.pixelLeft = l.style.pixelLeft;
		l.focusItem.style.left = l.focusItem.style.pixelLeft + 'px';
		l.focusItem.style.zIndex = l.zIndex +1;
		l.Menu.hideChildMenu(l);
	} else return;
	window.ActiveMenuItem = l;
}

function onMenuItemAction(e, l) {
	l = window.ActiveMenuItem;
	if (!l) return;
	hideActiveMenus();
	if (l.mmaction) eval("" + l.mmaction);
	window.ActiveMenuItem = 0;
}

function MM_clearTimeout() {
	if (mmHideMenuTimer) clearTimeout(mmHideMenuTimer);
	mmHideMenuTimer = null;
	mmDHFlag = false;
}

function MM_startTimeout() {
	if( window.ActiveMenu ) {
		mmStart = new Date();
		mmDHFlag = true;
		mmHideMenuTimer = setTimeout("mmDoHide()", window.ActiveMenu.Menu.hideTimeout);
	}
}

function mmDoHide() {
	if (!mmDHFlag || !window.ActiveMenu) return;
	var elapsed = new Date() - mmStart;
	var timeout = window.ActiveMenu.Menu.hideTimeout;
	if (elapsed < timeout) {
		mmHideMenuTimer = setTimeout("mmDoHide()", timeout+100-elapsed);
		return;
	}
	mmDHFlag = false;
	hideActiveMenus();
	window.ActiveMenuItem = 0;
}

function MM_showMenu(menu, x, y, child, imgname) {
	if (!window.mmWroteMenu) return;
	MM_clearTimeout();
	if (menu) {
		var obj = Find(imgname) || document.images[imgname] || document.links[imgname] || document.anchors[imgname];
		x = moveXbySlicePos (x, obj);
		y = moveYbySlicePos (y, obj);
	}
	if (document.layers) {
		if (menu) {
			var l = menu.menuLayer || menu;
			l.top = l.left = 1;
			hideActiveMenus();
			if (this.visibility) l = this;
			window.ActiveMenu = l;
		} else {
			var l = child;
		}
		if (!l) return;
		for (var i=0; i<l.layers.length; i++) { 			   
			if (!l.layers[i].isHilite) l.layers[i].visibility = "inherit";
			if (l.layers[i].document.layers.length > 0) MM_showMenu(null, "relative", "relative", l.layers[i]);
		}
		if (l.parentLayer) {
			if (x != "relative") l.parentLayer.left = x || window.pageX || 0;
			if (l.parentLayer.left + l.clip.width > window.innerWidth) l.parentLayer.left -= (l.parentLayer.left + l.clip.width - window.innerWidth);
			if (y != "relative") l.parentLayer.top = y || window.pageY || 0;
			if (l.parentLayer.isContainer) {
				l.Menu.xOffset = window.pageXOffset;
				l.Menu.yOffset = window.pageYOffset;
				l.parentLayer.clip.width = window.ActiveMenu.clip.width +2;
				l.parentLayer.clip.height = window.ActiveMenu.clip.height +2;
				if (l.parentLayer.menuContainerBgColor && l.Menu.menuBgOpaque ) l.parentLayer.document.bgColor = l.parentLayer.menuContainerBgColor;
			}
		}
		l.visibility = "inherit";
		if (l.Menu) l.Menu.container.visibility = "inherit";
	} else if (Find("menuItem0")) {
		var l = menu.menuLayer || menu;	
		hideActiveMenus();
		if (typeof(l) == "string") l = Find(l);
		window.ActiveMenu = l;
		var s = l.style;
		s.visibility = "inherit";
		if (x != "relative") {
			s.pixelLeft = x || (window.pageX + document.body.scrollLeft) || 0;
			s.left = s.pixelLeft + 'px';
		}
		if (y != "relative") {
			s.pixelTop = y || (window.pageY + document.body.scrollTop) || 0;
			s.top = s.pixelTop + 'px';
		}
		l.Menu.xOffset = document.body.scrollLeft;
		l.Menu.yOffset = document.body.scrollTop;
	}
	if (menu) window.activeMenus[window.activeMenus.length] = l;
	MM_clearTimeout();
}

function onMenuItemDown(e, l) {
	var a = window.ActiveMenuItem;
	if (document.layers && a) {
		a.eX = e.pageX;
		a.eY = e.pageY;
		a.clicked = true;
    }
}

function mouseupMenu(e) {
	hideMenu(true, e);
	hideActiveMenus();
	return true;
}

function getExplorerVersion() {
	var ieVers = parseFloat(navigator.appVersion);
	if( navigator.appName != 'Microsoft Internet Explorer' ) return ieVers;
	var tempVers = navigator.appVersion;
	var i = tempVers.indexOf( 'MSIE ' );
	if( i >= 0 ) {
		tempVers = tempVers.substring( i+5 );
		ieVers = parseFloat( tempVers ); 
	}
	return ieVers;
}

function mouseoutMenu() {
	if ((navigator.appName == "Microsoft Internet Explorer") && (getExplorerVersion() < 4.5))
		return true;
	hideMenu(false, false);
	return true;
}

function hideMenu(mouseup, e) {
	var a = window.ActiveMenuItem;
	if (a && document.layers) {
		a.document.bgColor = a.saveColor;
		a.focusItem.top = -30;
		if (a.hilite) a.hilite.visibility = "hidden";
		if (mouseup && a.mmaction && a.clicked && window.ActiveMenu) {
 			if (a.eX <= e.pageX+15 && a.eX >= e.pageX-15 && a.eY <= e.pageY+10 && a.eY >= e.pageY-10) {
				setTimeout('window.ActiveMenu.Menu.onMenuItemAction();', 500);
			}
		}
		a.clicked = false;
		if (a.Menu.bgImageOver) a.background.src = a.Menu.bgImageUp;
	} else if (window.ActiveMenu && Find("menuItem0")) {
		if (a) {
			a.style.backgroundColor = a.saveColor;
			if (a.hilite) a.hilite.style.visibility = "hidden";
			if (a.hiliteShim) a.hiliteShim.style.visibility = "inherit";
			if (a.Menu.bgImageUp) a.style.background = "url(" + a.Menu.bgImageUp +")";
		}
	}
	if (!mouseup && window.ActiveMenu) {
		if (window.ActiveMenu.Menu) {
			if (window.ActiveMenu.Menu.hideOnMouseOut) MM_startTimeout();
			return(true);
		}
	}
	return(true);
}

function hideChildMenu(hcmLayer) {
	MM_clearTimeout();
	var l = hcmLayer;
	for (var i=0; i < l.Menu.childMenus.length; i++) {
		var theLayer = l.Menu.childMenus[i];
		if (document.layers) theLayer.visibility = "hidden";
		else {
			theLayer = Find(theLayer);
			theLayer.style.visibility = "hidden";
			if( theLayer.Menu.menuItemHAlign != 'left' ) {
				for(var j = 0; j < theLayer.Menu.menuItemLayers.length; j++) {
					var itemLayer = theLayer.Menu.menuItemLayers[j];
					if(itemLayer.textShim) itemLayer.textShim.style.visibility = "inherit";
				}
			}
		}
		theLayer.Menu.hideChildMenu(theLayer);
	}
	if (l.childMenu) {
		var childMenu = l.childMenu;
		if (document.layers) {
			l.Menu.MM_showMenu(null,null,null,childMenu.layers[0]);
			childMenu.zIndex = l.parentLayer.zIndex +1;
			childMenu.top = l.Menu.menuLayer.top + l.Menu.submenuYOffset;
			if( l.Menu.vertical ) {
				if( l.Menu.submenuRelativeToItem ) childMenu.top += l.top + l.parentLayer.top;
				childMenu.left = l.parentLayer.left + l.parentLayer.clip.width - (2*l.Menu.menuBorder) + l.Menu.menuLayer.left + l.Menu.submenuXOffset;
			} else {
				childMenu.top += l.top + l.parentLayer.top;	
				if( l.Menu.submenuRelativeToItem ) childMenu.left = l.Menu.menuLayer.left + l.left + l.clip.width + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
				else childMenu.left = l.parentLayer.left + l.parentLayer.clip.width - (2*l.Menu.menuBorder) + l.Menu.menuLayer.left + l.Menu.submenuXOffset;
			}
			if( childMenu.left < l.Menu.container.clip.left ) l.Menu.container.clip.left = childMenu.left;
			var w = childMenu.clip.width+childMenu.left-l.Menu.container.clip.left;
			if (w > l.Menu.container.clip.width)  l.Menu.container.clip.width = w;
			var h = childMenu.clip.height+childMenu.top-l.Menu.container.clip.top;
			if (h > l.Menu.container.clip.height) l.Menu.container.clip.height = h;
			l.document.layers[1].zIndex = 0;
			childMenu.visibility = "inherit";
		} else if (Find("menuItem0")) {
			childMenu = Find(l.childMenu);
			var menuLayer = Find(l.Menu.menuLayer);
			var s = childMenu.style;
			s.zIndex = menuLayer.style.zIndex+1;
			if (document.all || window.mmIsOpera) {
				s.pixelTop = menuLayer.style.pixelTop + l.Menu.submenuYOffset;
				if( l.Menu.vertical ) {
					if( l.Menu.submenuRelativeToItem ) s.pixelTop += l.style.pixelTop;
					s.pixelLeft = l.style.pixelWidth + menuLayer.style.pixelLeft + l.Menu.submenuXOffset;
					s.left = s.pixelLeft + 'px';
				} else {
					s.pixelTop += l.style.pixelTop;
					if( l.Menu.submenuRelativeToItem ) s.pixelLeft = menuLayer.style.pixelLeft + l.style.pixelLeft + l.style.pixelWidth + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
					else s.pixelLeft = (menuLayer.style.pixelWidth-4*l.Menu.menuBorder) + menuLayer.style.pixelLeft + l.Menu.submenuXOffset;
					s.left = s.pixelLeft + 'px';
				}
			} else {
				var top = parseInt(menuLayer.style.top) + l.Menu.submenuYOffset;
				var left = 0;
				if( l.Menu.vertical ) {
					if( l.Menu.submenuRelativeToItem ) top += parseInt(l.style.top);
					left = (parseInt(menuLayer.style.width)-4*l.Menu.menuBorder) + parseInt(menuLayer.style.left) + l.Menu.submenuXOffset;
				} else {
					top += parseInt(l.style.top);
					if( l.Menu.submenuRelativeToItem ) left = parseInt(menuLayer.style.left) + parseInt(l.style.left) + parseInt(l.style.width) + (2*l.Menu.menuBorder) + l.Menu.submenuXOffset;
					else left = (parseInt(menuLayer.style.width)-4*l.Menu.menuBorder) + parseInt(menuLayer.style.left) + l.Menu.submenuXOffset;
				}
				s.top = top + 'px';
				s.left = left + 'px';
			}
			childMenu.style.visibility = "inherit";
		} else return;
		window.activeMenus[window.activeMenus.length] = childMenu;
	}
}

function hideActiveMenus() {
	if (!window.activeMenus) return;
	for (var i=0; i < window.activeMenus.length; i++) {
		if (!activeMenus[i]) continue;
		if (activeMenus[i].visibility && activeMenus[i].Menu && !window.mmIsOpera) {
			activeMenus[i].visibility = "hidden";
			activeMenus[i].Menu.container.visibility = "hidden";
			activeMenus[i].Menu.container.clip.left = 0;
		} else if (activeMenus[i].style) {
			var s = activeMenus[i].style;
			s.visibility = "hidden";
			s.left = '-200px';
			s.top = '-200px';
		}
	}
	if (window.ActiveMenuItem) hideMenu(false, false);
	window.activeMenus.length = 0;
}

function moveXbySlicePos (x, img) { 
	if (!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);
			if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);
			if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}
	} else if (img.x) x += img.x;
	return x;
}

function moveYbySlicePos (y, img) {
	if(!document.layers) {
		var onWindows = navigator.platform ? navigator.platform == "Win32" : false;
		var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;
		var par = img;
		var lastOffset = 0;
		while(par){
			if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);
			if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);
			if( par.offsetTop != 0 ) lastOffset = par.offsetTop;
			par = macIE45 ? par.parentElement : par.offsetParent;
		}		
	} else if (img.y >= 0) y += img.y;
	return y;
}

function Limpar(valor, validos) {
// retira caracteres invalidos da string
   var result = "";
   var aux;
   for (var i=0; i < valor.length; i++) {
      aux = validos.indexOf(valor.substring(i, i+1));
      if (aux>=0) {
         result += aux;
      }
   }
   return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function formatavalor(campo) {
   campo.value = filtracampo(campo);
   vr = campo.value;
   tam = vr.length;

   if ( tam <= 2 ) { 
      campo.value = vr; }
   if ( (tam > 2) && (tam <= 5) ) {
      campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 6) && (tam <= 8) ) {
      campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 9) && (tam <= 11) ) {
      campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 12) && (tam <= 14) ) {
      campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
   if ( (tam >= 15) && (tam <= 18) ) {
      campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
}

function filtracampo(campo){
   var s = "";
   var cp = "";
   vr = campo.value;
   tam = vr.length;
   for (i = 0; i < tam ; i++) {  
      if (vr.substring(i,i + 1) != "(" && vr.substring(i,i + 1) != ")" && vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != ":" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "."  && vr.substring(i,i + 1) != "," ) {
         s = s + vr.substring(i,i + 1);
	  }
   }
   campo.value = s;
   return cp = campo.value;
}

function desformatar(num) {
   num = num.replace('.','');
   num = num.replace(',','.');
   return parseFloat(num);
}

function formatadata(campo) {
   campo.value = filtracampo(campo);
   vr = campo.value;
   tam = vr.length;
   if ( tam > 2 && tam < 5 ) {
      campo.value = vr.substr( 0, 2  ) + '/' + vr.substr( 2, tam ); }
   if ( tam >= 5 && tam <= 10 ) {
      campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
   return vr = campo.value;
}

function formatahora(campo) {
   campo.value = filtracampo(campo);
   vr = campo.value;
   tam = vr.length;
   if ( tam > 2 && tam < 5 ) {
      campo.value = vr.substr( 0, 2  ) + ':' + vr.substr( 2, tam ); }
   if ( tam >= 5 && tam <= 8 ) {
      campo.value = vr.substr( 0, 2 ) + ':' + vr.substr( 2, 2 ) + ':' + vr.substr( 4, 2 ); }
   return vr = campo.value;
}

function formatacep(campo) {
   campo.value = filtracampo(campo);
   vr = campo.value;
   tam = vr.length;
   if ( tam > 2 && tam < 6 ) {
      campo.value = vr.substr( 0, 2  ) + '.' + vr.substr( 2, tam - 2 ); }
   if ( tam >= 6 && tam <= 10 ) {
      campo.value = vr.substr( 0, 2 ) + '.' + vr.substr( 2, 3 ) + '-' + vr.substr( 5, 3 ); }
   return vr = campo.value;
}

function arredondar(num) {
   return Math.round(num*Math.pow(10,2))/Math.pow(10,2);
}

function apresentaValor(campooriginal,decimais,tipodecimal) {
   var posicaoPontoDecimal;
   var campo = '';
   var resultado = '';
   var pos,sep,dec,iddecimal,idmilhar;
   if (tipodecimal == ".") {
	  var iddecimal=".";
	  var idmilhar=",";
   } else {
	  var iddecimal=",";
	  var idmilhar=".";
   }

//Retira possiveis separadores de milhar
   for (pos=0; pos < campooriginal.length; pos ++) {
      if (campooriginal.charAt(pos)!=idmilhar) {
         campo = campo + campooriginal.charAt(pos);
	  }
   }

//Formata valor monetário com decimais
   posicaoPontoDecimal = campo.indexOf(iddecimal);
   if (posicaoPontoDecimal != -1) {
      sep = 0;
      for (pos=posicaoPontoDecimal-1;pos >= 0;pos--) {
         sep ++;
         if (sep > 3) {
            resultado = '.' + resultado;
            sep = 1;
         }
         resultado = campo.charAt(pos) + resultado;   
      }

// Trata parte decimal
      if (parseInt(decimais) > 0 )
      {
         resultado = resultado + ',';
      
         pos=posicaoPontoDecimal+1;
         for (dec = 1;dec <= parseInt(decimais); dec++)
         {
           if (pos < campo.length)
           {
              resultado = resultado + campo.charAt(pos);
              pos++;
           }
           else
              resultado = resultado + '0';   
         }

      } // trata decimais
   }
   // Trata valor monetário sem decimais
   else
   {
      sep = 0;
      for (pos=campo.length-1;pos >= 0;pos--)
      {
        sep ++;
        if (sep > 3)
        {
           resultado = '.' + resultado;
           sep = 1;
        }
        resultado = campo.charAt(pos) + resultado;   
      }
      // Trata parte decimal
      if (parseInt(decimais) > 0 )
      {
         resultado = resultado + ',';
         for (dec = 1;dec <= parseInt(decimais); dec++)
         {
              resultado = resultado + '0';   
         }
      } // trata decimais
   }
   return resultado;
}
 
function ValidaEmail(email) {
	var arroba = email.indexOf("@");
	var arrobaprimeiro = email.lastIndexOf(".");
	var space = email.indexOf(" ");
	if ((arroba != -1) && (arroba != 0) && (arrobaprimeiro != -1) && (arrobaprimeiro > arroba + 1) && (arrobaprimeiro < email.length -1) && (space == -1) ) {
		// E-mail foi digitado correto
		return true;
	} else {
		// E-mail inválido
		return false;
	}
}

function formatafone(campo) {
   campo.value = filtracampo(campo);
   vr = campo.value;
   tam = vr.length;
   if ( tam == 0 ) {
	  campo.value = ''; }
   if ( tam > 0 && tam <= 2 ) {
	  campo.value = '(' + vr.substr( 0, tam ); }
   if ( tam > 2 && tam < 7 ) {
	  campo.value = '(' + vr.substr( 0, 2 ) + ')' + vr.substr( 2, tam - 2 ); }
   if ( tam >= 7 ) {
	  campo.value = '(' + vr.substr( 0, 2 ) + ')' + vr.substr( 2, 4 ) + '.' + vr.substr( 6 ); }
   return vr = campo.value;
}

function trim(str) {
   str=str.replace(/\s+/g," ");
   str=str.replace(/^ /,"");
   str=str.replace(/ $/,"");
   return str;
}

function counter(max, objeto) {
   var count;
   var str = new String(objeto.value);
   if (str.length > max) {
      str = str.substr(0, max);
	  objeto.value = str;
   }
   count = max - str.length;
	if (count > 1 && count <= max) {
		document.all.cartext.innerHTML = 'Restam '+count+' caracteres';
	} else if (count == 1) {
		document.all.cartext.innerHTML = 'Resta '+count+' caracter';
	} else if (count == 0) {
		document.all.cartext.innerHTML = 'Limite máximo de '+max+' caracteres atingido';
	}
	return count;
}

function GravarCookie(strCookie, strValor, lngDias) {
   var dtmData = new Date();
   if (lngDias) {
      dtmData.setTime(dtmData.getTime() + (lngDias * 24 * 60 * 60 * 1000));
      var strExpires = "; expires=" + dtmData.toGMTString();
   } else {
      var strExpires = "";
   }
   document.cookie = strCookie + "=" + strValor + strExpires + "; path=/";
}

function LerCookie(strCookie) {
//   var strNomeIgual = strCookie + "=";
//   var arrCookies = document.cookie.split(';');
//   for(var i = 0; i < arrCookies.length; i++) {
//      var strValorCookie = arrCookies[i];
//      while(strValorCookie.charAt(0) == ' ') {
//         strValorCookie = strValorCookie.substring(1, strValorCookie.length);
//      }
//      if (strValorCookie.indexOf(strNomeIgual) == 0) {
//         return strValorCookie.substring(strNomeIgual.length, strValorCookie.length);
//      }
//   }
//   return null;
	var cookieValue = "";
	var search = strCookie + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

function ExcluirCookie(strCookie) {
   GravarCookie(strCookie, '', -1);
//	document.cookie = strCookie+"=; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function GetQueryString(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if (results == null) {
		return "";
	} else {
		return results[1];
	}
}

function validaMacAddress(vMA) {
	var string;
	string = vMA.substr(1,17);
	string = string.split(":");
	if (string.length!=6) {
		return false;
	} else {
		for (var i=string.length; i--;) {
			if (!/[0-9]|[a-f]{2}/.test(string[i])) {
		   	return false;
			} else {
				return true;
			}
		}
	}
}

function ValidaCpfCnpj(s_aux) {
	if (s_aux.length == 11) {
		var cpf;
		cpf = s_aux;
      var numeros, digitos, soma, i, resultado, digitos_iguais;
      digitos_iguais = 1;
      if (cpf.length < 11) {
			return false;
		};
		for (i = 0; i < cpf.length - 1; i++) {
			if (cpf.charAt(i) != cpf.charAt(i + 1)) {
				digitos_iguais = 0;
				break;
			};
		};
      if (!digitos_iguais) {
			numeros = cpf.substring(0,9);
			digitos = cpf.substring(9);
			soma = 0;
			for (i = 10; i > 1; i--) {
				soma += numeros.charAt(10 - i) * i;
			};
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(0)) {
				return false;
			};
			numeros = cpf.substring(0,10);
			soma = 0;
			for (i = 11; i > 1; i--) {
				soma += numeros.charAt(11 - i) * i;
			};
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(1)) {
				return false;
			};
			return true;
		} else {
			return false;
      };
	} else if (s_aux.length == 14) {
		var cnpj;
		cnpj = s_aux;
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
      if (cnpj.length < 14 && cnpj.length < 15) {
			return false;
		};
      for (i = 0; i < cnpj.length - 1; i++) {
			if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
				digitos_iguais = 0;
				break;
			};
		};
      if (!digitos_iguais) {
			tamanho = cnpj.length - 2;
			numeros = cnpj.substring(0,tamanho);
			digitos = cnpj.substring(tamanho);
			soma = 0;
			pos = tamanho - 7;
			for (i = tamanho; i >= 1; i--) {
				soma += numeros.charAt(tamanho - i) * pos--;
				if (pos < 2) {
					pos = 9;
				};
			};
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(0)) {
				return false;
			};
			tamanho = tamanho + 1;
			numeros = cnpj.substring(0,tamanho);
			soma = 0;
			pos = tamanho - 7;
			for (i = tamanho; i >= 1; i--) {
				soma += numeros.charAt(tamanho - i) * pos--;
 				if (pos < 2) {
	 				pos = 9;
				};
			};
			resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
			if (resultado != digitos.charAt(1)) {
				return false;
			};
			return true;
		} else {
			return false;
      } 
	} else {
		return false;
	}
}

function SoNumero(campo) {
	if (document.all) { // Internet Explorer
		var tecla = event.keyCode;
	} else if(document.layers) { // Nestcape
		var tecla = campo.which;
	}
	if (tecla >= 47 && tecla <= 58) { // numeros de ´0´ a ´9´
		return true;
	} else {
		if (tecla != 8) { // backspace
			event.keyCode = 0;
			//return false;
		} else {
			return true;
		}
	}
}

function SoNumeroLetra(campo) {
	if (document.all) { // Internet Explorer
		var tecla = event.keyCode;
	} else if(document.layers) { // Nestcape
		var tecla = campo.which;
	}
	if (tecla >= 47 && tecla <= 58) { // numeros de ´0´ a ´9´
		return true;
	} else if (tecla >= 65 && tecla <= 90) { // letras de ´A´ a ´Z´
		return true;
	} else if (tecla >= 97 && tecla <= 122) { // letras de ´a´ a ´z´
		return true;
	} else {
		if (tecla != 8) { // backspace
			event.keyCode = 0;
			//return false;
		} else {
			return true;
		}
	}
}

function SoLetra(campo) {
	if (document.all) { // Internet Explorer
		var tecla = event.keyCode;
	} else if(document.layers) { // Nestcape
		var tecla = campo.which;
	}
	if (tecla >= 65 && tecla <= 90) { // letras de ´A´ a ´Z´
		return true;
	} else if (tecla >= 97 && tecla <= 122) { // letras de ´a´ a ´z´
		return true;
	} else {
		if (tecla != 8) { // backspace
			event.keyCode = 0;
			//return false;
		} else {
			return true;
		}
	}
}

function ValidaUF(campo) {
	var estado=campo.toUpperCase()
	if (estado == "AC") {
   	// Acre
		return true;
	} else if (estado == "AL") {
		// Alagoas
		return true;
	} else if (estado == "AP") {
		// Amapá
		return true;
	} else if (estado == "AM") {
		// Amazonas
		return true;
	} else if (estado == "BA") {
		// Bahia
		return true;
	} else if (estado == "CE") {
		// Ceará
		return true;
	} else if (estado == "DF") {
		// Distrito Federal
		return true;
	} else if (estado == "ES") {
		// Espírito Santo
		return true;
	} else if (estado == "GO") {
		// Goiás
		return true;
	} else if (estado == "MA") {
		// Maranhão
		return true;
	} else if (estado == "MT") {
		// Mato Grosso
		return true;
	} else if (estado == "MS") {
		// Mato Grosso do Sul
		return true;
	} else if (estado == "MG") {
		// Minas Gerais
		return true;
	} else if (estado == "PA") {
		// Pará
		return true;
	} else if (estado == "PB") {
		// Paraíba
		return true;
	} else if (estado == "PR") {
		// Paraná
		return true;
	} else if (estado == "PE") {
		// Pernambuco
		return true;
	} else if (estado == "PI") {
		// Piauí
		return true;
	} else if (estado == "RJ") {
		// Rio de Janeiro
		return true;
	} else if (estado == "RN") {
		// Rio Grande do Norte
		return true;
	} else if (estado == "RS") {
		// Rio Grande do Sul
		return true;
	} else if (estado == "RO") {
		// Rondônia
		return true;
	} else if (estado == "RR") {
		// Roraima
		return true;
	} else if (estado == "SC") {
		// Santa Catarina
		return true;
	} else if (estado == "SE") {
		// Sergipe
		return true;
	} else if (estado == "SP") {
		// São Paulo
		return true;
	} else if (estado == "TO") {
		// Tocantins
		return true;
	} else {
		return false;
	}
}

function MudaMenu(item, status) {
	var opcao;
	document['imagemA'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/off_home.jpg";
	document['imagemB'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/off_aradio.jpg";
	document['imagemC'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/off_muraldoouvinte.jpg";
	document['imagemD'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/off_nossacidade.jpg";
	document['imagemE'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/off_contato.jpg";
	if (item == 1) {
		document['imagemA'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/"+status+"_home.jpg";
	} else if (item == 2) {
		document['imagemB'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/"+status+"_aradio.jpg";
	} else if (item == 3) {
		document['imagemC'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/"+status+"_muraldoouvinte.jpg";
	} else if (item == 4) {
		document['imagemD'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/"+status+"_nossacidade.jpg";
	} else if (item == 5) {
		document['imagemE'].src="http://www.avantesistemas.com.br/pampiana/imagens/menu/"+status+"_contato.jpg";
	}
}

function ValidaUserLogin() {
	var nr, mensagem;
	nr = 0;
	mensagem = "";
	// analisa o campo ´codigo´
	if (document.getElementById('login_id').value == "") {
		nr += 1; mensagem = mensagem + nr + ") ´CÓDIGO AVANTE´: não preenchido\n";
	} else if (document.getElementById('login_id').value.length < 6) {
		nr += 1; mensagem = mensagem + nr + ") ´CÓDIGO AVANTE´: tamanho único de 6 (seis) dígitos\n";
	}
	// analisa o campo ´login_senha´
	if (document.getElementById('login_senha').value == "") {
		nr += 1; mensagem = mensagem + nr + ") ´SENHA DE ACESSO´: não preenchido\n";
	} else if (document.getElementById('login_senha').value.length < 6) {
		nr += 1; mensagem = mensagem + nr + ") ´SENHA DE ACESSO´: mínimo de 6 (seis) dígitos\n";
	}
	if (mensagem == "") {
		document.loginuser.action="/login.asp";
		document.loginuser.submit();
	} else {
		alert("Fo"+((nr==1)?"i":"ram")+" encontrado"+((nr==1)?"":"s")+" "+nr+" erro"+((nr==1)?"":"s")+" no preenchimento:\n\n" + mensagem);
	}
}

function LoadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location.href = url;
    return false;
  }
  else
    return true;
}

function Asc(String) {
	return String.charCodeAt(0);
}

function Chr(AsciiNum) {
	return String.fromCharCode(AsciiNum);
}

function MudaMouse(objeto) {
	objeto.style.cursor = "pointer";
}

function ViewTreeview(objeto) {
	var vtImagem, vtQuadro;
	vtImagem = "Img_"+objeto;
	vtQuadro = "Sub_"+objeto;
	if (document.getElementById(vtQuadro).style.display == "block") {
		document.getElementById(vtQuadro).style.display = "none";
		document.getElementById(vtImagem).src = "/treeview/images_arrows/plus.gif";
	} else {
		document.getElementById(vtQuadro).style.display = "block";
		document.getElementById(vtImagem).src = "/treeview/images_arrows/minus.gif";
	}
}

function car_taille(lettre) {
	var res=0;
	switch(lettre)	{
		case 'i':
		case 'j':
		case 'l':
		case 'f':
		case 'r':
		case 't':
		case ' ':
		case '(':
		case ')':
		case '{':
		case '}':
		case '.':
		case ',':
		case ':':
		case '"':
			res=3;
			break;
		case 'v':
		case 'x':
		case 'y':
		case 'z':
			res=5;
			break;
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'H':
		case 'K':
		case 'N':
		case 'O':
		case 'P':
		case 'Q':
		case 'R':
		case 'S':
		case 'U':
		case 'X':
		case 'w':
		case '&':
			res=9;
			break;
		case 'm':
		case 'M':
		case 'W':
		case '@':
		case '%':
			res=11;
			break;
		default:
			res=7;
	}
	return res;
}

function LimitaCelula(folder,taille) {
	var taille;
	result = folder.search(/<b>/i);
	if (result != -1) {
		folder = folder.substr(3,folder.length-3);
		folder = folder.substr(0,folder.length-5);
		folder = troncature(folder,taille,1);                    
		folder = "<b>"+folder+"</b>";
	} else {
		folder = troncature(folder,taille,1);
	}
	return folder;
}

function troncature(mot,taille_voulue,taille_multi) {
	folder1 = mot;
	mot = mot.replace(/&quot;/g,'"');
	var taille=0;
	var i;
	var mot_tronque="";
	for(i=0;i<mot.length;i++) {
		taille = taille + taille_multi * car_taille(mot.charAt(i));
		if (taille > taille_voulue) {
			while (taille > (taille_voulue-9*taille_multi)) {
				taille = taille - taille_multi*car_taille(mot.charAt(i));
				i--;
			}
			mot_tronque = mot.substring(0,i) + '...';
			mot_tronque = mot_tronque.replace(/"/g,'&quot;');                    
//			mot_tronque = '<span title="'+folder1+'">'+mot_tronque+'</span>';
			break;
		} else {
			mot_tronque = mot;
			mot_tronque = mot_tronque.replace(/"/g,'&quot;');                      
		}
	}
	return mot_tronque;
}

function HexToR(h) {
	return parseInt((cutHex(h)).substring(0,2),16);
}

function HexToG(h) {
	return parseInt((cutHex(h)).substring(2,4),16);
}

function HexToB(h) {
	return parseInt((cutHex(h)).substring(4,6),16);
}

function cutHex(h) {
	return (h.charAt(0)=="#") ? h.substring(1,7):h;
}

function RGBtoHex(R,G,B) {
	return toHex(R)+toHex(G)+toHex(B);
}

function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N);
 if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N);
 N=Math.min(N,255);
 N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
}

function escolharadio(objeto_a, selecao, objeto_b) {
   var quadro_a, quadro_b;
	quadro_a = document.getElementsByName(objeto_a)[selecao].checked;
   quadro_b = document.getElementById(objeto_b);
   if (quadro_a == true) {
      quadro_b.style.display = "block";
   } else {
      quadro_b.style.display = "none";
   }
}

function escolha(objeto_a, selecao, objeto_b) {
   var quadro_a, quadro_b;
   quadro_a = document.getElementById(objeto_a).value;
   quadro_b = document.getElementById(objeto_b)
   if (quadro_a == selecao) {
      quadro_b.style.display = "block";
   } else {
      quadro_b.style.display = "none";
   }
}

function naovazio(objeto_a, objeto_b) {
   var quadro_a, quadro_b;
   quadro_a = document.getElementById(objeto_a).value.length;
   quadro_b = document.getElementById(objeto_b)
   if (quadro_a > 0) {
      quadro_b.style.display = "block";
   } else {
      quadro_b.style.display = "none";
   }
}

function ValidaData(digData) {
	var bissexto = 0;
	var data = digData;
	var tam = data.length;
	var barras = digData.split("/");
	if (barras.length != 3) {
		return false
	}
	if (tam == 10) {
		var dia = data.substr(0,2);
		var mes = data.substr(3,2);
		var ano = data.substr(6,4);
		if ((ano > 1900)||(ano < 2100)) {
			switch (mes) {
				case '01':
				case '03':
				case '05':
				case '07':
				case '08':
				case '10':
				case '12':
					if (dia <= 31) {
						return true;
					}
					break
				case '04':
				case '06':
				case '09':
				case '11':
					if (dia <= 30) {
						return true;
					}
					break
				case '02':
					/* Validando ano Bissexto / fevereiro / dia */
					if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)) {
						bissexto = 1;
					}
					if ((bissexto == 1) && (dia <= 29)) {
						return true;
					}
					if ((bissexto != 1) && (dia <= 28)) {
						return true;
					}
					break
			}
		}
	}
//	alert("A Data "+data+" é inválida!");
	return false;
}

function ChangeFrame(cf_Forma, cf_Novo, cf_Total, cf_Frame, cf_URL) {
	if (cf_Forma == "V") {
		var borda;
		borda = document.getElementById('frm_left'+cf_Novo).style.borderRight;
		if (borda == "") {
			return;
		} else {
			for (i=0; i<=cf_Total; i++) {
				var atual, numero, objeto, objeto2;
				atual = i;
				numero = ('00'+(i+1));
				numero = numero.substring(numero.length, numero.length-2);
				objeto = 'frm_left'+numero;
				seta = 'frm_arrow'+numero;
				if (numero == cf_Novo) {
					document.getElementById(objeto).style.borderBottom = "white 1px solid";
					document.getElementById(objeto).style.borderRight = "";
					document.getElementById(objeto).style.borderTop = "";
					document.getElementById(seta).innerHTML = '<img src="/imagens/seta_branca.png" width="10" height="10" border="0">';
				} else {
					document.getElementById(objeto).style.borderBottom = "white 1px solid";
					document.getElementById(objeto).style.borderRight = "white 1px solid";
					document.getElementById(objeto).style.borderTop = "";
					document.getElementById(seta).innerHTML = '<img src="/imagens/transparente.png" width="10" height="10" border="0">';
				}
			}
		}
	} else {
		var borda;
		borda = document.getElementById('frm_top'+cf_Novo).style.borderBottom;
		if (borda == "") {
			return;
		} else {
			for (i=0; i<=cf_Total; i++) {
				var atual, numero, objeto, objeto2;
				atual = i;
				colors = new Array(10);
				colors[0] = "4C4C4C";
				colors[1] = "575757";
				colors[2] = "626262";
				colors[3] = "6D6D6D";
				colors[4] = "787878";
				colors[5] = "838383";
				colors[6] = "8E8E8E";
				colors[7] = "999999";
				colors[8] = "A4A4A4";
				colors[9] = "AFAFAF";
				numero = ('00'+(i+1));
				numero = numero.substring(numero.length, numero.length-2);
				objeto = 'frm_top'+numero;
				abaixo = 'frm_under'+numero;
				if (numero == cf_Novo) {
					var idnumero, idcor, novacor;
					idnumero = cf_Novo;
					idcor = (idnumero-1);
					novacor = colors[idcor];
					document.getElementById(objeto).style.borderBottom = ("solid 1px #"+novacor);
					document.getElementById(abaixo).innerHTML = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="center"><img src="/imagens/indicador_superior.png" width="9" height="7" border="0"></td></tr><tr><td bgcolor="white"><img src="/imagens/transparente.png" width="1" height="3" border="0"></td></tr></table>';
				} else {
					document.getElementById(objeto).style.borderBottom = "white 1px solid";
					document.getElementById(abaixo).innerHTML = '<img src="/imagens/transparente.png" width="1" height="10" border="0">';
				}
			}
		}
	}

	document.getElementById('frm_extse').style.background = "url(/imagens/guias/"+cf_Novo+"_ext_se.png)";
	document.getElementById('frm_extsd').style.background = "url(/imagens/guias/"+cf_Novo+"_ext_sd.png)";
	document.getElementById('frm_extie').style.background = "url(/imagens/guias/"+cf_Novo+"_ext_ie.png)";
	document.getElementById('frm_extid').style.background = "url(/imagens/guias/"+cf_Novo+"_ext_id.png)";

	document.getElementById('frm_superior').style.background = "url(/imagens/guias/"+cf_Novo+".png)";
	document.getElementById('frm_esquerdo').style.background = "url(/imagens/guias/"+cf_Novo+".png)";
	document.getElementById('frm_direito').style.background = "url(/imagens/guias/"+cf_Novo+".png)";
	document.getElementById('frm_inferior').style.background = "url(/imagens/guias/"+cf_Novo+".png)";

	document.getElementById('frm_intse').style.background = "url(/imagens/guias/"+cf_Novo+"_int_se.png)";
	document.getElementById('frm_intsd').style.background = "url(/imagens/guias/"+cf_Novo+"_int_sd.png)";
	document.getElementById('frm_intie').style.background = "url(/imagens/guias/"+cf_Novo+"_int_ie.png)";
	document.getElementById('frm_intid').style.background = "url(/imagens/guias/"+cf_Novo+"_int_id.png)";
	
	var rota;
	rota = cf_Frame+".location.href='"+cf_URL+"'";
	eval(rota);
	
	if (cf_Forma == "V") {
		AjustaFrameVertical();
	}
}

function AjustaFrameVertical() {
	var alt_left, alt_right;
	alt_left = document.getElementById('tab_left').offsetHeight;
	alt_right = document.getElementById('tab_right').offsetHeight;
//	alert('alt_left: '+alt_left);
//	alert('alt_right: '+alt_right);
	if (alt_right < alt_left) {
		document.getElementById('tab_right2').height = alt_left - 30;
	}
}

function DimensionaImagem(obj, percent, maximo) {
   var atual;
   atual = obj.width;
   obj.width = (atual * (percent/100)); 
//	alert("Original: "+atual+"\nFinal: "+obj.width+"\nMaximo: "+maximo);
   if (obj.width > maximo) {
		obj.width = maximo;
	}
} 

function IsField(o) {
	if (o != undefined && o != null) {
		return true;
	} else {
		return false;
	}
}

function showLightbox(idLight, idFade, idURLFrame, idWidth, idHeight) {
	var idFrame, altura_scroll, idFadeWidth, idFadeHeight, idFadeTop, idLightWidth, idLightHeight, localParam;
	idFrame = "FRM_lightbox";
	// memoriza a altura do scroll atual
	altura_scroll = pageScrollX(0);
	if (pageScrollX(1) > altura_scroll) {
		altura_scroll = pageScrollX(1);
	}
	if (pageScrollX(2) > altura_scroll) {
		altura_scroll = pageScrollX(2);
	}
	// anula a denificao do lightbox se parametro ´idWidth´ ou ´idHeight´ nao informado
	if (idWidth == null || idHeight == null) {
		idWidth = null;
		idHeight = null;
	}
	alert('etapa 1');
	// zera a pagina de exibicao do frame
	if (IsField(document.getElementById(idFrame)) == true) {
//		document.getElementById(idFrame).style.display = "none";
		document.getElementById(idFrame).style.width = "0px";
		document.getElementById(idFrame).style.height = "0px";
	} else if (IsField(parent.document.getElementById(idFrame)) == true) {
//		parent.document.getElementById(idFrame).style.display = "none";
		parent.document.getElementById(idFrame).style.width = "0px";
		parent.document.getElementById(idFrame).style.height = "0px";
	} else if (IsField(parent.parent.document.getElementById(idFrame)) == true) {
//		parent.parent.document.getElementById(idFrame).style.display = "none";
		parent.parent.document.getElementById(idFrame).style.width = "0px";
		parent.parent.document.getElementById(idFrame).style.height = "0px";
	} else if (IsField(parent.parent.parent.document.getElementById(idFrame)) == true) {
//		parent.parent.parent.document.getElementById(idFrame).style.display = "none";
		parent.parent.parent.document.getElementById(idFrame).style.width = "0px";
		parent.parent.parent.document.getElementById(idFrame).style.height = "0px";
	}
	alert('etapa 2');
	// define a altura e a largura do ´fade´ e, desabilita o scroll
	if (IsField(document.getElementById(idFade)) == true) {
		document.getElementById(idFade).style.display = "block";
		document.getElementById(idFade).style.marginTop = '0px';
		idFadeWidth = document.getElementById(idFade).offsetWidth;
		idFadeWidth = parseInt(idFadeWidth);
		idFadeHeight = document.getElementById(idFade).offsetHeight;
		idFadeHeight = parseInt(idFadeHeight);
		idFadeTop = document.getElementById(idFade).style.marginTop;
		idFadeTop = parseInt(idFadeTop);
		document.body.style.overflow = "hidden";
	} else if (IsField(parent.document.getElementById(idFade)) == true) {
		parent.document.getElementById(idFade).style.display = "block";
		parent.document.getElementById(idFade).style.marginTop = '0px';
		idFadeWidth = parent.document.getElementById(idFade).offsetWidth;
		idFadeWidth = parseInt(idFadeWidth);
		idFadeHeight = parent.document.getElementById(idFade).offsetHeight;
		idFadeHeight = parseInt(idFadeHeight);
		idFadeTop = parent.document.getElementById(idFade).style.marginTop;
		idFadeTop = parseInt(idFadeTop);
		parent.document.body.style.overflow = "hidden";
	} else if (IsField(parent.parent.document.getElementById(idFade)) == true) {
		parent.parent.document.getElementById(idFade).style.display = "block";
		parent.parent.document.getElementById(idFade).style.marginTop = '0px';
		idFadeWidth = parent.parent.document.getElementById(idFade).offsetWidth;
		idFadeWidth = parseInt(idFadeWidth);
		idFadeHeight = parent.parent.document.getElementById(idFade).offsetHeight;
		idFadeHeight = parseInt(idFadeHeight);
		idFadeTop = parent.parent.document.getElementById(idFade).style.marginTop;
		idFadeTop = parseInt(idFadeTop);
		parent.parent.document.body.style.overflow = "hidden";
	} else if (IsField(parent.parent.parent.document.getElementById(idFade)) == true) {
		parent.parent.parent.document.getElementById(idFade).style.display = "block";
		parent.parent.parent.document.getElementById(idFade).style.marginTop = '0px';
		idFadeWidth = parent.parent.parent.document.getElementById(idFade).offsetWidth;
		idFadeWidth = parseInt(idFadeWidth);
		idFadeHeight = parent.parent.parent.document.getElementById(idFade).offsetHeight;
		idFadeHeight = parseInt(idFadeHeight);
		idFadeTop = parent.parent.parent.document.getElementById(idFade).style.marginTop;
		idFadeTop = parseInt(idFadeTop);
		parent.parent.parent.document.body.style.overflow = "hidden";
	}
	alert('etapa 3');
	// determina a largura e a altura do lightbox
	if (idHeight == null) {
		idHeight = parseInt(idFadeHeight) * 0.80;
		idHeight = parseInt(idHeight);
	}
	if (idWidth == null) {
		idWidth = (idFadeWidth - (idFadeHeight - idHeight));
		idWidth = parseInt(idWidth);
	}
	alert('etapa 4');
	// formata o lightbox
	if (IsField(document.getElementById(idLight)) == true) {
		document.getElementById(idLight).style.display = "block";
		document.getElementById(idLight).style.width = (idWidth+'px');
		document.getElementById(idLight).style.height = (idHeight+'px');
	} else if (IsField(parent.document.getElementById(idLight)) == true) {
		parent.document.getElementById(idLight).style.display = "block";
		parent.document.getElementById(idLight).style.width = (idWidth+'px');
		parent.document.getElementById(idLight).style.height = (idHeight+'px');
	} else if (IsField(parent.parent.document.getElementById(idLight)) == true) {
		parent.parent.document.getElementById(idLight).style.display = "block";
		parent.parent.document.getElementById(idLight).style.width = (idWidth+'px');
		parent.parent.document.getElementById(idLight).style.height = (idHeight+'px');
	} else if (IsField(parent.parent.parent.document.getElementById(idLight)) == true) {
		parent.parent.parent.document.getElementById(idLight).style.display = "block";
		parent.parent.parent.document.getElementById(idLight).style.width = (idWidth+'px');
		parent.parent.parent.document.getElementById(idLight).style.height = (idHeight+'px');
	}
	alert('etapa 5');
	// centraliza o lightbox na tela
	if (IsField(document.getElementById(idLight)) == true) {
		idLightWidth = document.getElementById(idLight).offsetWidth;
		idLightHeight = document.getElementById(idLight).offsetHeight;
		document.getElementById(idLight).style.marginLeft = ((((idFadeWidth - idLightWidth)/2) - 10)+'px');
		document.getElementById(idLight).style.marginTop = ((((idFadeHeight - idLightHeight)/2) - 10)+'px');
	} else if (IsField(parent.document.getElementById(idLight)) == true) {
		idLightWidth = parent.document.getElementById(idLight).offsetWidth;
		idLightHeight = parent.document.getElementById(idLight).offsetHeight;
		parent.document.getElementById(idLight).style.marginLeft = ((((idFadeWidth - idLightWidth)/2) - 10)+'px');
		parent.document.getElementById(idLight).style.marginTop = ((((idFadeHeight - idLightHeight)/2) - 10)+'px');
	} else if (IsField(parent.parent.document.getElementById(idLight)) == true) {
		idLightWidth = parent.parent.document.getElementById(idLight).offsetWidth;
		idLightHeight = parent.parent.document.getElementById(idLight).offsetHeight;
		parent.parent.document.getElementById(idLight).style.marginLeft = ((((idFadeWidth - idLightWidth)/2) - 10)+'px');
		parent.parent.document.getElementById(idLight).style.marginTop = ((((idFadeHeight - idLightHeight)/2) - 10)+'px');
	} else if (IsField(parent.parent.parent.document.getElementById(idLight)) == true) {
		idLightWidth = parent.parent.parent.document.getElementById(idLight).offsetWidth;
		idLightHeight = parent.parent.parent.document.getElementById(idLight).offsetHeight;
		parent.parent.parent.document.getElementById(idLight).style.marginLeft = ((((idFadeWidth - idLightWidth)/2) - 10)+'px');
		parent.parent.parent.document.getElementById(idLight).style.marginTop = ((((idFadeHeight - idLightHeight)/2) - 10)+'px');
	}
	alert('etapa 6');
	// insere a altura e a largura do frame no endereco da URL
	localParam = idURLFrame.indexOf("?")
	if (localParam < 0) { // Não existem parâmetros
		idURLFrame = idURLFrame + '?FRM_Width='+(parseInt(idLightWidth) - 25)+'&FRM_Height='+(parseInt(idLightHeight) - 50);
	} else { // Existem parâmetros
		idURLFrame = idURLFrame + '&FRM_Width='+(parseInt(idLightWidth) - 25)+'&FRM_Height='+(parseInt(idLightHeight) - 50);
	}
	// determina a altura do frame e exibe a pagina do lightbox
	if (IsField(document.getElementById(idFrame)) == true) {
		document.getElementById(idFrame).src=idURLFrame;
		document.getElementById(idFrame).style.width = ((parseInt(idLightWidth) - 25)+'px');
		document.getElementById(idFrame).style.height = ((parseInt(idLightHeight) - 50)+'px');
		document.getElementById(idFrame).style.display = "none";
	} else if (IsField(parent.document.getElementById(idFrame)) == true) {
		parent.document.getElementById(idFrame).src=idURLFrame;
		parent.document.getElementById(idFrame).style.width = ((parseInt(idLightWidth) - 25)+'px');
		parent.document.getElementById(idFrame).style.height = ((parseInt(idLightHeight) - 50)+'px');
		parent.document.getElementById(idFrame).style.display = "none";
	} else if (IsField(parent.parent.document.getElementById(idFrame)) == true) {
		parent.parent.document.getElementById(idFrame).src=idURLFrame;
		parent.parent.document.getElementById(idFrame).style.width = ((parseInt(idLightWidth) - 25)+'px');
		parent.parent.document.getElementById(idFrame).style.height = ((parseInt(idLightHeight) - 50)+'px');
		parent.parent.document.getElementById(idFrame).style.display = "none";
	} else if (IsField(parent.parent.parent.document.getElementById(idFrame)) == true) {
		parent.parent.parent.document.getElementById(idFrame).src=idURLFrame;
		parent.parent.parent.document.getElementById(idFrame).style.width = ((parseInt(idLightWidth) - 25)+'px');
		parent.parent.parent.document.getElementById(idFrame).style.height = ((parseInt(idLightHeight) - 50)+'px');
		parent.parent.parent.document.getElementById(idFrame).style.display = "none";
	}
	alert('FINAL');
}

function hideLightbox(idLight, idFade, idOverflow) {
	var idFrame;
	idFrame = "FRM_lightbox";
	// zera a pagina de exibicao do frame
	if (IsField(document.getElementById(idFrame)) == true) {
		document.getElementById(idFrame).src = "about:blank";
	} else if (IsField(parent.document.getElementById(idFrame)) == true) {
		parent.document.getElementById(idFrame).src = "about:blank";
	} else if (IsField(parent.parent.document.getElementById(idFrame)) == true) {
		parent.parent.document.getElementById(idFrame).src = "about:blank";
	} else if (IsField(parent.parent.parent.document.getElementById(idFrame)) == true) {
		parent.parent.parent.document.getElementById(idFrame).src = "about:blank";
	}
	if (IsField(document.getElementById(idLight)) == true) {
		document.getElementById(idLight).style.display = "none";
	} else if (IsField(parent.document.getElementById(idLight)) == true) {
		parent.document.getElementById(idLight).style.display = "none";
	} else if (IsField(parent.parent.document.getElementById(idLight)) == true) {
		parent.parent.document.getElementById(idLight).style.display = "none";
	} else if (IsField(parent.parent.parent.document.getElementById(idLight)) == true) {
		parent.parent.parent.document.getElementById(idLight).style.display = "none";
	}
	if (IsField(document.getElementById(idFade)) == true) {
		document.getElementById(idFade).style.display = "none";
		document.body.style.overflow = idOverflow;
	} else if (IsField(parent.document.getElementById(idFade)) == true) {
		parent.document.getElementById(idFade).style.display = "none";
		parent.document.body.style.overflow = idOverflow;
	} else if (IsField(parent.parent.document.getElementById(idFade)) == true) {
		parent.parent.document.getElementById(idFade).style.display = "none";
		parent.parent.document.body.style.overflow = idOverflow;
	} else if (IsField(parent.parent.parent.document.getElementById(idFade)) == true) {
		parent.parent.parent.document.getElementById(idFade).style.display = "none";
		parent.parent.parent.document.body.style.overflow = idOverflow;
	}
}

function NrObjetos(nroObjeto, nroJanela) { 
	var soma = 0; 
   var input = new Array();
	if (nroJanela == 'parent') {
		input = parent.document.getElementsByTagName( nroObjeto );
	} else {
		input = document.getElementsByTagName( nroObjeto );
   }
	for(var i = 0; i < input.length; i++) { 
		soma++; 
	} 
} 

function PreLoadImagens() {
	var d=document; 
	if (d.images) { 
		if (!d.MM_p) {
			d.MM_p=new Array();
		}
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++) {
			if (a[i].indexOf("#")!=0) {
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

/*
function moveleft(mlObjeto) {
   var atual, objetoFinal, RenovaFuncao;
   if (IsField(parent.document.getElementById(mlObjeto)) == true) {
		objetoFinal = parent.document.getElementById(mlObjeto);
   } else {
		objetoFinal = document.getElementById(mlObjeto);
   }
   atual = objetoFinal.style.left;
   atual = atual.replace('px','');
   atual = atual.replace('pt','');
   atual = Number(atual);
	if (atual<0) {
		objetoFinal.style.left=atual+6;
	}
   RenovaFuncao = ("moveleft('"+mlObjeto+"')");
   if (IsField(parent.document.getElementById('tempLeft')) == true) {
	   parent.document.getElementById('tempLeft').value=setTimeout(RenovaFuncao,50);
      alert(parent.document.getElementById('tempLeft').value);
   } else {
	   document.getElementById('tempLeft').value=setTimeout(RenovaFuncao,50);
      alert(document.getElementById('tempLeft').value);
	}
}

function moveright(mrObjeto) {
   var atual, objetoFinal, RenovaFuncao;
   if (IsField(parent.document.getElementById(mrObjeto)) == true) {
		objetoFinal = parent.document.getElementById(mrObjeto);
   } else {
		objetoFinal = document.getElementById(mrObjeto);
   }
   atual = objetoFinal.style.left;
   atual = atual.replace('px','');
   atual = atual.replace('pt','');
   atual = Number(atual);
	if (atual>(222-objetoFinal.offsetWidth)) {
		objetoFinal.style.left=atual-6;
	}

   RenovaFuncao = ("moveright('"+mrObjeto+"')");
   if (IsField(parent.document.getElementById('tempRight')) == true) {
	   parent.document.getElementById('tempRight').value=setTimeout(RenovaFuncao,50);
      alert(parent.document.getElementById('tempRight').value);
   } else {
	   document.getElementById('tempRight').value=setTimeout(RenovaFuncao,50);
      alert(document.getElementById('tempRight').value);
	}
}
*/

function moveleft() {
   var atual, mlObjeto, mlObjetoFinalA, mlObjetoFinalC;
   mlObjetoFinalA = 'parte_A' + idNrFrame;
   mlObjetoFinalC = 'parte_C' + idNrFrame;
   if (eval("IsField(document.getElementById('parte_C"+idNrFrame+"'))") == true) {
		mlObjeto = eval("document.getElementById('parte_C"+idNrFrame+"')");
	} else {
		mlObjeto = eval("parent.document.getElementById('parte_C"+idNrFrame+"')");
	}
   atual = eval('mlObjeto.style.left');
   atual = atual.replace('px','');
   atual = atual.replace('pt','');
   atual = Number(atual);
	if (atual<0) {
		mlObjeto.style.left=((atual+10)+'px');
	}
   lefttime=setTimeout("moveleft()",50);
}

function moveright() {
   var atual,mrObjeto,mrLargura, mrObjetoFinalA, mrObjetoFinalC;
   mrObjetoFinalA = 'parte_A' + idNrFrame;
   mrObjetoFinalC = 'parte_C' + idNrFrame;
//   alert(mrObjetoFinalC);
//   alert();
//   alert(eval("IsField(parent.document.getElementById('parte_C"+mrFrame+"'))"));
	if (eval("IsField(document.getElementById('parte_C"+idNrFrame+"'))") == true) {
		mrObjeto = eval("document.getElementById('parte_C"+idNrFrame+"')");
	} else {
		mrObjeto = eval("parent.document.getElementById('parte_C"+idNrFrame+"')");
	}
   atual = eval('mrObjeto.style.left');
   atual = atual.replace('px','');
   atual = atual.replace('pt','');
   atual = Number(atual);
	if (IsField(document.getElementById(mrObjetoFinalA)) == true) {
		mrLargura = document.getElementById(mrObjetoFinalA).offsetWidth;
	} else {
		mrLargura = parent.document.getElementById(mrObjetoFinalA).offsetWidth;
	}
	if (atual>(mrLargura-mrObjeto.offsetWidth)) {
		mrObjeto.style.left=((atual-10)+'px');
	}
	righttime=setTimeout("moveright()",50);
}

function pageWidth() {
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight() {
	return  window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function pageScrollX(pageParentNivel) {
	if (pageParentNivel == 0 ) {
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0) {
			if (window.pageYOffset) {
				ScrollTop = window.pageYOffset;
			} else {
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}
		return ScrollTop;
	} else if (pageParentNivel == 1 ) {
		var ScrollTop = parent.document.body.scrollTop;
		if (ScrollTop == 0) {
			if (parent.window.pageYOffset) {
				ScrollTop = parent.window.pageYOffset;
			} else {
				ScrollTop = (parent.document.body.parentElement) ? parent.document.body.parentElement.scrollTop : 0;
			}
		}
		return ScrollTop;
	} else if (pageParentNivel == 2 ) {
		var ScrollTop = parent.parent.document.body.scrollTop;
		if (ScrollTop == 0) {
			if (parent.parent.window.pageYOffset) {
				ScrollTop = parent.parent.window.pageYOffset;
			} else {
				ScrollTop = (parent.parent.document.body.parentElement) ? parent.parent.document.body.parentElement.scrollTop : 0;
			}
		}
		return ScrollTop;
	}
}

function pageScrollY(pageParentNivel) {
	if (pageParentNivel == 0 ) {
		var ScrollLeft = document.body.scrollLeft;
		if (ScrollLeft == 0) {
			if (window.pageXOffset) {
				ScrollLeft = window.pageXOffset;
			} else {
				ScrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
			}
		}
		return ScrollLeft;
	} else if (pageParentNivel == 1 ) {
		var ScrollLeft = parent.document.body.scrollLeft;
		if (ScrollLeft == 0) {
			if (parent.window.pageXOffset) {
				ScrollLeft = parent.window.pageXOffset;
			} else {
				ScrollLeft = (parent.document.body.parentElement) ? parent.document.body.parentElement.scrollLeft : 0;
			}
		}
		return ScrollLeft;
	} else if (pageParentNivel == 2 ) {
		var ScrollLeft = parent.parent.document.body.scrollLeft;
		if (ScrollLeft == 0) {
			if (parent.parent.window.pageXOffset) {
				ScrollLeft = parent.parent.window.pageXOffset;
			} else {
				ScrollLeft = (parent.parent.document.body.parentElement) ? parent.parent.document.body.parentElement.scrollLeft : 0;
			}
		}
		return ScrollLeft;
	}
}

function identificaSO() {
	if (navigator.userAgent.indexOf('Linux') != -1) {
		var so = "Linux";
	} else if (navigator.userAgent.indexOf('Mac') != -1) {
		var so = "Macintosh";
	} else if (navigator.userAgent.toLowerCase().indexOf('unix') != -1) {
		var so = "Unix";
	} else if ((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('NT 2.0')!= -1)) {
		var so = "Windows 95";
	} else if ((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('NT 3.0')!= -1)) {
		var so = "Windows 98";
	} else if ((navigator.userAgent.indexOf('Win')!=-1)&&(navigator.userAgent.indexOf('NT 4.0')!=-1)) {
		var so = "Windows 2000";
	} else if ((navigator.userAgent.indexOf('Win')!=-1)&&(navigator.userAgent.indexOf('NT 5.0')!=-1)) {
		var so = "Windows XP";
	} else if ((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('NT 6.0')!= -1)) {
		var so = "Windows Vista";
	} else if ((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('NT 7.0')!= -1)) {
		var so = "Windows 7";
	} else if ((navigator.userAgent.indexOf('Win')!= -1)&&(navigator.userAgent.indexOf('NT 8.0')!= -1)) {
		var so = "Windows 8";
	} else {
		var so = "";
	}
	return so;
}

function identificaBROWSERname() {
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
		//testando se encontrou Firefox/x.x ou Firefox x.x;
		var BrowserNome = "Firefox";
	} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		//testando se encontrou MSIE x.x
		var BrowserNome = "Internet Explorer"
	} else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { 
		//testando se encontrou Chrome x.x
		var BrowserNome = "Google Chrome"
	} else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
		//teste para Opera/x.x ou Opera x.x
		var BrowserNome = "Opera"
	} else {
		var BrowserNome = ""
	}
	return BrowserNome;
}

function identificaBROWSERversion() {
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
		//testando se encontrou Firefox/x.x ou Firefox x.x;
   	var BrowserVersao = new Number(RegExp.$1);
	} else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		//testando se encontrou MSIE x.x
	   var BrowserVersao = new Number(RegExp.$1) 
	} else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { 
		//testando se encontrou Chrome x.x
	   var BrowserVersao = new Number(RegExp.$1) 
	} else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
		//teste para Opera/x.x ou Opera x.x
	   var BrowserVersao = new Number(RegExp.$1) 
	} else {
	   var BrowserVersao = 0
	}
	return BrowserVersao;
}

function ValidaHora(vhObj) {
	var vhTemp;
	vhTemp = vhObj;
	hrs = vhTemp.substr(0,2);
	mnt = vhTemp.substr(3,2);
	seg = vhTemp.substr(6,2);

	// verifica a hora
	if ((hrs < 00) || (hrs > 23)) {
		return false;
	}
	// verifica os minutos
	if ((mnt < 00) || (mnt > 59)) {
		return false;
	}
	// verifica os segundos
	if ((seg < 00) || (seg > 59)) {
		return false;
	}
}

function CalcularIdade(nascimento, hoje){ 
	//calculo a data que recebo
	//descomponho a data em um array
	var array_nascimento = nascimento.split("/");
	var array_hoje = hoje.split("/");
	var idade = 0;
	//verifica a validade das datas recebidas
	if (ValidaData(nascimento) == false || ValidaData(hoje) == false) {
		return false;
	}
	//se o array nao tem tres partes, uma das datas é incorreta
	if ((array_nascimento.length != 3) || (array_hoje.length != 3)) {
		return false;
	}
	//comprovo que o ano, mes, dia são corretos
	var anoN, anoH;
	anoN = array_nascimento[2];
	anoH = array_hoje[2];
	if (isNaN(anoN) || isNaN(anoH)) {
		return false;
	}
	var mesN, mesH;
	mesN = array_nascimento[1]; 
	mesH = array_hoje[1];
	if (isNaN(mesN) || isNaN(mesH)) {
		return false;
	}
	var diaN, diaH;
	diaN = array_nascimento[0];
	diaH = array_hoje[0];
	if (isNaN(diaN) || isNaN(diaH)) {
		return false;
	}
	//subtraio os anos das duas datas
	idade = anoH - anoN - 1; //-1 porque ainda nao fez anos durante este ano
	//se subtraio os meses e for menor que 0 entao nao cumpriu anos. Se for maior sim ja cumpriu
	if (mesH < mesN) { //+ 1 porque os meses comecam em 0
		return idade;
	}
	if (mesH > mesN) {
		return idade + 1;
	}
	//entao eh porque sao iguais. Vejo os dias
	//se subtraio os dias e der menor que 0 entao nao cumpriu anos. Se der maior ou igual sim que já cumpriu
	if (diaH >= diaN) {
		return idade + 1;
	}
	return idade;
}

function Left(str, n){
	if (n <= 0) {
		return "";
	} else if (n > String(str).length) {
		return str;
	} else {
		return String(str).substring(0,n);
	}
}

function Right(str, n){
	if (n <= 0) {
		return "";
	} else if (n > String(str).length) {
		return str;
	} else {
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

function ApresentaIdade(aiObjeto, aiDiv, aiHoje) {
	var aiValidade, aiNascimento;
	aiValidade = ValidaData(aiObjeto.value);
	if (aiValidade == true) {
		aiNascimento = aiObjeto.value;
		document.getElementById(aiDiv).innerHTML = CalcularIdade(aiNascimento,aiHoje) + ' anos';
	} else {
		document.getElementById(aiDiv).innerHTML = '';
	}
}

//var varEnter = '<%=dar.getObservacao().replace((char)13, '$')%>'
//parent.corpo.document.form1['Observacoes'].value = replaceAll(varEnter,"$","\n");
//e criamos em javascript:
function replaceAll( str, from, to ) {
	var idx = str.indexOf( from );
	while ( idx > -1 ) {
		str = str.replace( from, to ); 
		idx = str.indexOf( from );
	}
	return str;
}

function NivelField(nfObj) {
	if (IsField(document.getElementById(nfObj)) == true) {
		return 0;
	} else if (IsField(parent.document.getElementById(nfObj)) == true) {
		return 1;
	} else if (IsField(parent.parent.document.getElementById(nfObj)) == true) {
		return 2;
	} else if (IsField(parent.parent.parent.document.getElementById(nfObj)) == true) {
		return 3;
	} else if (IsField(parent.parent.parent.parent.document.getElementById(nfObj)) == true) {
		return 4;
	} else {
		return (-1);
	}
}

function EvalObjeto(epObj, epAtributo, epParam) {
	var epNivel, epEval;
	epNivel = NivelField(epObj);
	epEval = '';
	while (epNivel > 0) {
		epEval = epEval + 'parent.';
		epNivel = epNivel - 1;
	}
	epLinha = epEval + "document.getElementById('" + epObj + "')." + epAtributo + " = " + epParam;
	eval(epLinha);
}

function CenterIn(ciObjA, ciObjB) {
	var ciNivelA, ciNivelB, ciEvalA, ciEvalB, ciLinha, ciEspacoA, ciEspacoB;
	var ciWidthA, ciHeightA, ciLeftB, ciTopB, ciWidthB, ciHeightB;
	ciNivelA = NivelField(ciObjA);
	ciNivelB = NivelField(ciObjB);
	ciEvalA = '';
	while (ciNivelA > 0) {
		ciEvalA = ciEvalA + 'parent.';
		ciNivelA = ciNivelA - 1;
	}
	ciEvalB = '';
	while (ciNivelB > 0) {
		ciEvalB = ciEvalB + 'parent.';
		ciNivelB = ciNivelB - 1;
	}
	ciLinha = "ciWidthA = " + ciEvalA + "document.getElementById('" + ciObjA + "').offsetWidth;";
	eval(ciLinha);
	ciLinha = "ciHeightA = " + ciEvalA + "document.getElementById('" + ciObjA + "').offsetHeight;";
	eval(ciLinha);
	ciLinha = "ciWidthB = " + ciEvalB + "document.getElementById('" + ciObjB + "').offsetWidth;";
	eval(ciLinha);
	ciLinha = "ciHeightB = " + ciEvalB + "document.getElementById('" + ciObjB + "').offsetHeight;";
	eval(ciLinha);
	ciEspacoA = ((ciWidthA - ciWidthB)/2);
	ciEspacoA = parseInt(ciEspacoA);
	ciEspacoB = ((ciHeightA - ciHeightB)/2);
	ciEspacoB = parseInt(ciEspacoB);
	EvalObjeto(ciObjB, 'style.marginLeft', "'"+ciEspacoA+"px'");
	EvalObjeto(ciObjB, 'style.marginTop', "'"+ciEspacoB+"px'");
}

function MudaFoco(mfObjeto, mfFoco, mfTipo) {
	if (mfFoco == true) {
		mfObjeto.style.border = "dotted 1px #666666";
		mfObjeto.style.backgroundColor = "#CCCCCC";
	} else {
		mfObjeto.style.backgroundColor = "#FFFFFF";
		if (mfTipo == null) {
			mfObjeto.style.border = "solid 1px #FFFFFF";
		} else if (mfTipo == 'checkbox') {
			mfObjeto.style.border = "solid 1px #FFFFFF";
		}
	}
}
