/************************************************************************************************************/
//	CAMINHO BASE DE PRODUÇÃO 
/************************************************************************************************************/

//var ROOT_SITE 			= "http://localhost/prefeitura";

/************************************************************************************************************/
//	CAMINHO BASE DE PRODUÇÃO  
/************************************************************************************************************/


/************************************************************************************************************/
//	CAMINHO BASE ON-LINE 
/************************************************************************************************************/

var ROOT_SITE = "http://www.zinni.com.br/prefeituradecaieiras";

/************************************************************************************************************/
//	CAMINHO BASE ON-LINE 
/************************************************************************************************************/




// Início Menu Principal

var arrMenu = [];
	arrMenu[arrMenu.length] = [
//		["","Prefeitura"],
//		["","Prefeitura"],
		["","Serviços"],
		["historia/index.php","História da Cidade"],
		["historia/simbolos.php","Símbolos"],
		["","Galeria de fotos"],
		["prefeito/index.php","Prefeito"],
//		["","Ouvidoria"],
//		["","Leis e Editais"],
		["noticias/noticias.php","Notícias"],
		["eventos/index.php","Eventos"],
     	["telefones/index.php","Telefones Úteis"],
		["tecnologia/index.php","Tecnologia da Informação"],
		["imprensa/index.php","Diretoria de Comunicação Social"],
		["contato/index.php","Contate-nos"],
		["portal_servico/index.php","Portal de Serviços"]
	]

function writeMenu(){
	for (var i = 0; i < arrMenu.length; i++){
		
		document.write('<div style="width:136px; height:500px; background-color:#FFF09F; border-left:1px solid #FCDD6C; border-right:1px solid #FCDD6C; margin-left:2px">')
		document.write('<div style="width:130px; height:500px; position:relative; z-index:1; bottom:7px">')
			document.write('<img src="'+ROOT_SITE+'/img/label_menu.gif" width="130" height="21" alt="" border="0">')
			document.write('<table cellpadding="2" cellspacing="2" border="0" style="margin-left:5px">')
				for (var j = 1; j < arrMenu[i].length; j++){
				document.write('<tr>')
					document.write('<td class="flechaMenu">&raquo;</td>')
						if(arrMenu[i][j][0] == "")
						{
							document.write('<td class="fontMenu_disable">'+arrMenu[i][j][1]+'</td>');
						}else{
							document.write('<td class="fontMenu"><a href="'+ROOT_SITE+'/' + arrMenu[i][j][0] + '" class="linkMenu">' + arrMenu[i][j][1] + '</a></td>');
						}
				document.write('</tr>')
				}
				
				/*
				document.write('<tr>')
					document.write('<td colspan="2" class="fontMenu"><a href="http://www.camaracaieiras.sp.gov.br/" class="linkMenu" target="_blank"><img src="'+ROOT_SITE+'/img/botao_camara.gif" width="120" height="50" alt="" border="0" style="border:1px solid #9DC4A1"></a></td>');
				document.write('</tr>')
				*/
				
				document.write('<tr>')
					document.write('<td colspan="2">')
						document.write('<iframe src="http://selos.climatempo.com.br/selos/MostraSelo120.php?CODCIDADE=416&SKIN=padrao" scrolling="no" frameborder="0" width="120" height="170" marginheight="0" marginwidth="0"></iframe>')
					document.write('</td>')
				document.write('</tr>')
				
			document.write('</table>')
			
		document.write('</div>')
		document.write('</div>')
		document.write('<table cellpadding="0" cellspacing="0" border="0" width="136" style="margin-left:2px">')
			document.write('<tr>')
				document.write('<td><img src="'+ROOT_SITE+'/img/borda_bottom_left.gif" width="10" height="10" alt="" border="0"></td>')
				document.write('<td><img src="'+ROOT_SITE+'/img/cont_center.gif" width="117" height="10" alt="" border="0"></td>')
				document.write('<td><img src="'+ROOT_SITE+'/img/borda_bottom_right.gif" width="10" height="10" alt="" border="0"></td>')
			document.write('</tr>')
		document.write('</table>')
	}
}

// Fim Menu Principal


// Início Bloco Conteúdo 
function writeInicioConteudo(){
	document.write('<div style="width:490px; background-color:; margin-left:4px">')

}	

function writeFimConteudo(){
	document.write('</div>')

}	
// Fim Bloco Conteúdo 

var arrTop = [
	["img_top1.jpg"],
	["img_top2.jpg"],
	["img_top3.jpg"],
	["img_top4.jpg"],
	["img_top5.jpg"],
	["img_top6.jpg"]
]
function writeDinamicTop(){
	document.write('<table cellpadding="0" cellspacing="0" border="0" align="center">');
		document.write('<tr>');
			document.write('<td><img src="'+ROOT_SITE+'/img/a_1.jpg" alt="" border="0"></td>');
			document.write('<td width="630"><img src="'+ROOT_SITE+'/img/' + getRadonItemArray(arrTop, 1) + '" alt="" border="0"></td>');
		document.write('</tr>');
	document.write('</table>');
	
}

function getNumeroRandomico(nroIniItervalo, nroFimItervalo){
	nroFimItervalo++;
	return (Math.floor(Math.random() * (nroFimItervalo-nroIniItervalo))+nroIniItervalo);
}
function getRadonItemArray(arrCompl, qtdeItem){
	var arrTemp = [];
	var achou = 0;
	var str = "";
	while (achou < qtdeItem)
	{
		var indiceTemp = getNumeroRandomico(0, arrCompl.length-1);
		if (str.indexOf("("+indiceTemp+")") == -1)
		{
			arrTemp[arrTemp.length] = arrCompl[indiceTemp];
			str += "("+indiceTemp+")";
			achou++;
		}
	}
	return arrTemp;
}

// Início Menu Secretarias

var arrMenuSecretarias = [];
	arrMenuSecretarias[arrMenuSecretarias.length] = [
		[ROOT_SITE + "/secretarias/cultura/index.php","Ação Cultural"],
		[ROOT_SITE + "/secretarias/cultura/index.php","Ação Cultural"],
		[ROOT_SITE + "/secretarias/desenvolvimento/index.php","Desenvolvimento Econômico"],
		[ROOT_SITE + "/secretarias/educacao/index.php","Educação"],
		[ROOT_SITE + "/secretarias/esportes/index.php","Esporte e Turismo"],
		[ROOT_SITE + "/secretarias/fazenda/index.php","Fazenda"],
		[ROOT_SITE + "/secretarias/fundo/index.php","Fundo Social"],
		[ROOT_SITE + "/secretarias/gabinete/index.php","Gabinete Prefeito"],
		[ROOT_SITE + "/secretarias/meioambiente/index.php","Meio Ambiente"],
		[ROOT_SITE + "/secretarias/juridico/index.php","Negócios Jurídicos"],
		[ROOT_SITE + "/secretarias/obras/index.php","Obras Projetos e Planejamento"],
		[ROOT_SITE + "/secretarias/procon/index.php","Procon"],
		[ROOT_SITE + "/secretarias/promocao/index.php","Promoção Social"],
	    [ROOT_SITE + "/secretarias/saude/index.php","Saúde"],
		[ROOT_SITE + "/secretarias/seguranca/index.php","Segurança"],
		[ROOT_SITE + "/secretarias/transportes/index.php","Transportes"]
]



var menu = [];
var nullTooTip = "";
menu["subDesenvEcon"] = {
	nivel : 1,
	width : 120,
	itens : [
		["", , "Sebrae","",ROOT_SITE + "/secretarias/sebrae/index.php"],
		["", , "Banco do Povo","",ROOT_SITE + "/secretarias/banco/index.php"]
	]
}
menu["subJuridico"] = {
	nivel : 1,
	width : 120,
	itens : [
		["", , "Procon","",ROOT_SITE + "/secretarias/procon/index.php"]
	]
}

menu["subGabinete"] = {
	nivel : 1,
	width : 120,
	itens : [
		["", , "Arquivo Público","",ROOT_SITE + "/secretarias/gabinete/arquivo.php"]
	]
}

menu["subEducacao"] = {
	nivel : 1,
	width : 120,
	itens : [
		["", , "Educação Infantil","",ROOT_SITE + "/secretarias/educacao/infantil.php"],
		["", , "Ensino Fundamental","",ROOT_SITE + "/secretarias/educacao/fundamental.php"],
		["", , "Jovens e Adultos","",ROOT_SITE + "/secretarias/educacao/jovens.php"],
		["", , "Merenda Escolar","",ROOT_SITE + "/secretarias/educacao/merenda.php"],
		["", , "Transporte","",ROOT_SITE + "/secretarias/educacao/transporte.php"]
	]
}

menu["subSeguranca"] = {
	nivel : 1,
	width : 150,
	itens : [
		["", , "Guarda Municipal","",ROOT_SITE + "/secretarias/guarda/index.php"],
		["", , "Trânsito","",ROOT_SITE + "/secretarias/transito/index.php"]
	]
}
GerarItensDoMenu();
function writeMenuSecretarias(){
		document.write('<div style="height:477px; background-color:#FFF09F; margin-left:5px">')
			document.write('<table cellpadding="2" cellspacing="2" border="0" style="margin-left:2px">')
					
					/********************************************/
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/cultura/index.php" class="linkMenuSecretarias">Ação Cultural</a></td>');
					document.write('</tr>')
					/********************************************/
					
					/********************************************/
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/desenvolvimento/index.php" class="linkMenuSecretarias">Desenvolvimento Econômico/PAT</a></td>');
					document.write('</tr>')
					/********************************************/
					
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/educacao/index.php" class="linkMenuSecretarias">Educação</a></td>');
					document.write('</tr>')
					
					/********************************************/
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/esportes/index.php" class="linkMenuSecretarias">Esporte e Turismo</a></td>');
					document.write('</tr>')
					/********************************************/
				
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/fazenda/index.php" class="linkMenuSecretarias">Fazenda</td>');
					document.write('</tr>')
					
					/********************************************/
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/fundo/index.php" class="linkMenuSecretarias">Fundo Social</a></td>');
					document.write('</tr>')
					/********************************************/
					
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/gabinete/index.php" class="linkMenuSecretarias">Gabinete Prefeito</a></td>');
					document.write('</tr>')
					
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/juridico/index.php" class="linkMenuSecretarias">Jurídico</a></td>');
					document.write('</tr>')
					
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/meioambiente/index.php" class="linkMenuSecretarias">Meio Ambiente</a></td>');
					document.write('</tr>')
					
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/obras/index.php" class="linkMenuSecretarias">Obras</a></td>');
					document.write('</tr>')
					
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/promocao/index.php" class="linkMenuSecretarias">Promoção Social</a></td>');
					document.write('</tr>')
					
					/********************************************/
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/saude/index.php" class="linkMenuSecretarias">Saúde</a></td>');
					document.write('</tr>')
					/********************************************/
					
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/seguranca/index.php" class="linkMenuSecretarias">Segurança</a></td>');
					document.write('</tr>')
				
					document.write('<tr>')
						document.write('<td class="flechaMenuSecretarias">&raquo;</td>')
						document.write('<td class="fontMenuSecretarias"><a href="'+ROOT_SITE+'/secretarias/habitacao/index.php" class="linkMenuSecretarias">Habitação</a></td>');
					document.write('</tr>')
					
				document.write('</table>')
			document.write('</div>')
}


function rodape(){
	
	document.write('<div style="width:100%" align="center"><table cellpadding="0" cellspacing="0" border="0" width="775" style="margin-top:4px; margin-left:4px">')
		document.write('<tr>')
			document.write('<td><img src="'+ROOT_SITE+'/img/borda_top_left.gif" width="10" height="10" alt="" border="0"></td>')
			document.write('<td><img src="'+ROOT_SITE+'/img/cont_center_top.gif" width="755" height="10" alt="" border="0"></td>')
			document.write('<td><img src="'+ROOT_SITE+'/img/borda_top_right.gif" width="10" height="10" alt="" border="0"></td>')
		document.write('</tr>')
		document.write('<tr>')
			document.write('<td background="'+ROOT_SITE+'/img/border_center_left.gif" width="10"></td>')
			document.write('<td height="30" bgcolor="#FFF09F" style="text-align:center">')
				document.write('<b style="color:#3B8E65">© Prefeitura Municipal de Caieiras - Todos os direitos reservados.</b>')
				document.write('<br>')
				document.write('Rua Bolívia, 470 - Jardim Santo Antonio - CEP: 07700-000 - Fone: (11)4442-7111')
							
			document.write('</td>')
			document.write('<td background="'+ROOT_SITE+'/img/border_center_right.gif" width="10"></td>')
		document.write('</tr>')
		
		document.write('<tr>')
			document.write('<td><img src="'+ROOT_SITE+'/img/borda_bottom_left.gif" width="10" height="10" alt="" border="0"></td>')
			document.write('<td><img src="'+ROOT_SITE+'/img/cont_center.gif" width="755" height="10" alt="" border="0"></td>')
			document.write('<td><img src="'+ROOT_SITE+'/img/borda_bottom_right.gif" width="10" height="10" alt="" border="0"></td>')
		document.write('</tr>')
	document.write('</table></div>')
}

function abreFoto(nroFoto){
 idFoto = nroFoto;
  open("abreFoto.php",idFoto, "toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=no,width=1,height=1,top=5000,left=5");
}

	function exibeInfo(obj){
		document.getElementById("idInfo1").style.display = (obj)?"":"none";
}

	function escondeInfo(obj){
		document.getElementById("idInfo1").style.display = (obj)?"none":"none";
}

	function exibeInfo2(obj){
		document.getElementById("idInfo2").style.display = (obj)?"":"none";
}

	function escondeInfo2(obj){
		document.getElementById("idInfo2").style.display = (obj)?"none":"none";
}
	
	function exibeInfo3(obj){
		document.getElementById("idInfo3").style.display = (obj)?"":"none";
}

	function escondeInfo3(obj){
		document.getElementById("idInfo3").style.display = (obj)?"none":"none";
}

	function exibeInfo4(obj){
		document.getElementById("idInfo4").style.display = (obj)?"":"none";
}

	function escondeInfo4(obj){
		document.getElementById("idInfo4").style.display = (obj)?"none":"none";
}

	function exibeInfo5(obj){
		document.getElementById("idInfo5").style.display = (obj)?"":"none";
}

	function escondeInfo5(obj){
		document.getElementById("idInfo5").style.display = (obj)?"none":"none";
}

// Fim Menu Secretarias


function showImage(image, num){
	document.getElementById("fotoGrande").src = image;
}

function getFotos(pasta, qtd){
	for (var i = 1; i < (qtd+1); i++){
		if (i<10)
		{
		var endFotoMini = ''+ROOT_SITE+'/fotos/' + pasta + '/mini/00' + i + '.jpg';
		var endFoto = ''+ROOT_SITE+'/fotos/' + pasta + '/00' + i + '.jpg';
		}
		else
		{
		var endFotoMini = ''+ROOT_SITE+'/fotos/' + pasta + '/mini/0' + i + '.jpg';
		var endFoto = ''+ROOT_SITE+'/fotos/' + pasta + '/0' + i + '.jpg';
		}
		document.write('<div style="margin:2px; border:1px solid #828282; float:left; text-align:center; margin-left:6px"><img onclick="showImage(\'' + endFoto + '\')" src="'+ endFotoMini +'" style="cursor:hand; pointer:hand"></div>');
	}
}

function inserirfotos(pasta, qtd)
{

document.write('<table cellpadding="2" cellspacing="2"width="480">');
document.write(' <tr>');
document.write('   <tr><td colspan="2" width="100%" bgcolor="#EAEAEA" style="padding:4px"><b>Mais Fotos</b></td></tr> ');
document.write(' </tr>');
document.write('</table>');
document.write('<table width="470" align="center">');
document.write(' <tr>');
document.write('  <td align="center"><img id="fotoGrande" src="'+ROOT_SITE+'/fotos/'+pasta+'/001.jpg" style="border:1px solid #828282"></td>');
document.write(' </tr>');
document.write('</table>');
document.write('<table align="center"  bgcolor="#FFFAE1" width="470" style="border:1px solid #FFF09F">');
document.write(' <tr>');
document.write('  <td align="center" style="padding-bottom:8px; padding-top:5px"> ');
document.write('   <script>getFotos("'+pasta+'", '+qtd+')</script>  ');
document.write('  </td>');
document.write(' </tr>');
document.write('</table>');

}


/**************************************************************************************************************************/
/*
var IE = (navigator.userAgent.indexOf("MSIE")!=-1);

var INSTANCES = [];
function getInstance(name){
	return INSTANCES[name];
};
*/

function Kernel(){
	this.register = [];
	/**
	 * Array que armazena as intências dos componentes.
	 * @type object[]
	 * @private
	 */
	this.instances = [];
	/**
	 * Array que armazena os comando que serão executados no onload da página.
	 * @type string[]
	 * @private
	 */
	this.onload 	= [];
	/**
	 * Indica se a página já foi carregada.
	 * @type boolean
	 */
	this.loadedDocument = false;
	/**
	 * Determina o path dos arquivos dos jsFramework.
	 * @type string
	 */
	this.root = "/jst/jsTAM/3.0/";
	/**
	 * Indica a posição horizontal(em pixels) em que o mouse está localizado.
	 * @type int
	 */
	this.mouseX = null;
	/**
	 * Indica a posição vertical(em pixels) em que o mouse está localizado.
	 * @type int
	 */
	this.mouseY = null;
	/**
	 * Determina o endereço base de onde está localizado as bibliotecas js.
	 * @param {string} root Endereço onde está localizado as bobliotecas ex. /SISTEMA/js/
	 */	
	this.log = [];
	this.setLog = function(log){
		var d = new Date();
		this.log.unshift([ d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + " - " + log]);
		if ( Kernel.ge("showLog") ){
			this.showLog();
		}
	};
	this.showLog = function(){
		if ( !Kernel.ge("showLog") ){
			alert(this.log.join("\n"));
		} else {
			Kernel.ge("showLog").innerHTML = this.log.join("<br>");
		}
	};
	this.setRoot = function (root){
		this.root = root;
	};
	/**
	 * Indica se o browser usado é Ineternet Explorer.
	 * @return {boolean} 
	 * 					<b>true</b>: Internet Explorer<br>
	 * 					<b>false</b>: outros browsers
	 */	
	this.isIE = function(){
		return (navigator.userAgent.indexOf("MSIE")!=-1);
	};
	this.registerClass = function(value){
		this.register[this.register.length] = value;
	};
	this.execRegisterClass = function(){
		for (var i = 0; i < this.register.length; i++){
			eval("main" + this.register[i] + "()");
		}
	};
	// Executa as classes registradas no Kernel.
	this.execute = function(){
		this.loadedDocument = true;
		
		try{ListenerFlexGrid("onLoadPage")} catch(e){}
		try{writeKernelTags()} catch(e){}
		try{writeHTMLTags()} catch(e){}

		
		for (var i = 0; i < this.onload.length; i++){
			eval(this.onload[i]);
		}
		this.execRegisterClass();
		var eventWindow = new Event(document.body);
			eventWindow.attach("mousemove", Kernel.positionMouse)
	};
	/**
	 * Seta as instâncias das classes usadas.
	 * @param string name Id de indentificação da classe. 
	 * @param object instance Instância da classe. 
	 */
	this.setInstanceClass = function(name, instance){
		this.instances[name] = instance;
	}
	/**
	 * Captura a instência de uma classe a partir de seu Id.
	 * @param string name Id de indentificação da classe. 
	 * @return object Instância da classe.
	 */
	this.getInstanceClass = function(name){
		return this.instances[name];
	};
	this.getInstancesForClass = function(ClassName){
		var arrTemp = [];
		for (var z in this.instances){
			if ( this.instances[z].ClassName == ClassName ){
				arrTemp[z] = this.instances[z];
			}
		}
		return arrTemp;
	};
	/**
	 * Seta o foco em um determinado campo.
	 * @param string name Id de indentificação do campo. 
	 */
	this.setFocus = function(name){
		try{
		this.ge(name).focus();
		}catch(e){}
	}
	/**
	 * Captura de um elemento usado em uma página, similar ao comando <i><b>document.getElementById("name")</b></i>.
	 * @param string name Id de indentificação do elemento. 
	 */
	this.ge = function(name){
		return window.document.getElementById(name);
	};
	/**
	 * Seta os comendos que serão executados no evento de onLoad da página.
	 * @param string func String da função que será executada. 
	 */
	this.setOnload = function(func){
		this.onload[this.onload.length] = func;
	}
	/**
	 * Captura o caminho base onde está localizado os arquivos da biblioteca.
	 * @return string Caminho base da biblioteca. 
	 */
	this.getRoot = function(){
		return this.root;
	};
	/**
	 * Escreve um determinado conteúdo na página utilizando o comando <i><b>document.write()</b></i>, caso a página já tenha sido carregada o método usará o comando <i><b>document.body.innerHTML = "conteúdo"</b></i>.
	 * @param string Conteúdo que será escrito na página.
	 */
	this.dw = function(content, idObjectInput){
		if ( idObjectInput ){
			this.ge(idObjectInput).innerHTML += content;
		}
		if (this.loadedDocument){
			document.body.innerHTML += content;
		} else {
			document.write(content);
		}
	};
	/**
	 * Método executado através do evento <i><b>onMouseMove</b></i> que atualiza os atributos do Kernel <i><b>mouseX</b></i> e  <i><b>mouseY</b></i>.
	 * @param event Evento disparado pelo onMousemove.
	 * @private
	 */
	this.positionMouse = function (evt){
	window.status = evt.clientY + " - " + evt.offsetY
		Kernel.mouseX = evt.clientX
		Kernel.mouseY = evt.clientY;
	};
	/**
	 * Captura as posições do mouse na tela.
	 * @return int[] Array contendo 2 posições:
	 * <pre>
	 * 		0: Posição horizontal(em pixels) do mouse.<br>
	 * 		1: Posição vertical(em pixels) do mouse.
	 * </pre>
	 */
	this.getPositionMouse = function (){
		return [this.mouseX, this.mouseY];
	};
	/**
	 * Modifica um template a partir de parametros pré determinados que são passados utilizando array.
	 * @param string template String contendo o padrão que será usado para inserir os dados, utilizando o seguinte padão:<br>
	 * 				Os parâmetos que serão escritos no template deverão estar entre "{" e "}" sendo o valor o número correspondente a posição do valor no array de parâmetros, <i><b>&lt;input name="{0}" value="{1}" maxlength="{2}"&gt;</b></i>.
	 * @param string[] parameters Array contendo os valores que serão inluídos no template.
	 * @return string Template com os dados inseridos:
	 */
	this.writeParameters = function (template, parameters){
		var strTemp = template;
		for (var x = 0; x < parameters.length; x++){
			strTemp = (strTemp).replace(RegExp("\\{"+x+"}","g"),parameters[x])
		}
		return strTemp;
	};
	/**
	 * Captura os dados referente a largura, altura, posição na tela, entre outras mais.
	 * @param object objTemp Objeto do elemento que o método deverá capturar as informações.
	 * @return object Será retornado um objeto contendo os seguites atributos:<br>
	 * 		<b>w</b>: Largura do elemento.<br>
	 * 		<b>h</b>: Altura do elemento.<br>
	 * 		<b>x</b>: Posição horizontal do elemento.<br>
	 * 		<b>y</b>: Posição vertical do elemento.<br>
	 * 		<b>xw</b>: Posição horizontal do final do elemento.<br>
	 * 		<b>yh</b>: Posição vertical do final do elemento.<br>
	 * 		<b><i>obs.</i></b> Todas as medidas são em pixel.
	 */
	this.getObjectMetrics = function (objTemp){
		var metrics = {w:objTemp.offsetWidth, h:objTemp.offsetHeight, x:0, y:0, xw:0, yh:0};
		do{
			metrics.x += objTemp.offsetLeft;
			metrics.y += objTemp.offsetTop;
			objTemp = objTemp.offsetParent;
		}while(objTemp.tagName != "BODY")
		metrics.xw = (metrics.w + metrics.x);
		metrics.yh = (metrics.h + metrics.y);
		return metrics;
	};
	this.getObject = function (object){
		if (typeof object == "object" ) {
			return object;
		} else {
			if ( object == "body" ) {
				return document.body;
			} else {
				return Kernel.ge(object);
			}
		}
		return;
	};
}
Kernel = new Kernel();
$K = Kernel;


function writeKernelTags(){
	var wkt = getElementsByTagNames("Kernel,Onload");
	for (var i = 0; i < wkt.length; i++){
		if (wkt[i].tagName.toLowerCase() == "kernel"){
			Kernel.setRoot(wkt[i].root);
		}else{
			Kernel.setOnload(wkt[i].action);
		}
	}
}


/**
 * Construtor do Event.
 * @class Classe usada para para manipulação de eventos.
 * @constructor
 * @author Marcos A. Zinni
 * @param {string} objectID Id do objeto que será setado o evento. 
 */
function Event(objectID){
	this.ClassName = "Event";
	this.el = (typeof objectID == "string")?document.getElementById(objectID):objectID;
};
Event.prototype = {
	/**
	 * Adiciona um evento ao objeto.
	 * @author Marcos A. Zinni
	 * @param {string} eventType Tipo do evento que a classe receberá.
	 * @param {object} objectFunction Função que será executada quando o evento for disparado.
	 */
	attach : function(eventType, objectFunction){
		try{
			if (this.el.addEventListener) {
				this.el.addEventListener(eventType, objectFunction,false);
			} else if (this.el.attachEvent) {
				this.el.attachEvent ("on"+eventType, objectFunction);
			}
		}catch(e){

			alert("new Event(): " + this.el.id)

		}
	},

	/**
	 * Remove o evento do objeto.
	 * @author Marcos A. Zinni
	 * @param {string} eventType Tipo do evento que a classe receberá.
	 * @param {object} objectFunction Função que será executada quando o evento for disparado.
	 */
	remove : function(eventType, objectFunction){
		if (this.el.removeEventListener) {
			this.el.removeEventListener(eventType, objectFunction, false );
		} else if (this.el.detachEvent) {
			this.el.detachEvent("on"+eventType, objectFunction);
		}
	}
};


/**
 * Construtor do StringBuffer.
 * @class Classe responsável pela criação e manipulação de string's, sua utilização é aconselhada para criação de string's extremamente
 *		  grandes e com muitas concatenações, por reduzir o consumo de CPU.
 * @constructor
 * @author Marcos A. Zinni
 */
function StringBuffer(){
	this.ClassName = "StringBuffer";
	/**
	 * Array que armazenará o conteúdo da classe.
	 * @type string[]
	 * @private
	 */
	this.buffer = [];

	/**
	 * Adicionar conteúdo à classe.
	 * @author Marcos A. Zinni
	 * @param {string} data Conteúdo a ser adicionado à classe.
	 */
	this.add = function(data){
		this.buffer[this.buffer.length]=data;
	};

	/**
	 * Limpa o conteúdo da string.
	 */
	this.flush = function(){
		this.buffer.length = 0;
	};

	/**
	 * Captura o tamanho da string.
	 * @return {int} Tamanho da string.
	 */
	this.length = function(){
		return this.buffer.join("").length;
	};

	/**
	 * Retorna o conteúdo da classe.
	 * @param string delim Parêmetro opcional caso haja a necessidade de acrescentar um delimitador entre os valores incluídos na classe.
	 * @return string Conteúdo armazenado na classe.
	 */
	this.toString = function(delim){
		return this.buffer.join(delim||"");
	}
};

/**
 * Construtor do Layout.
 * @class Permite a manipulação visual dos componentes.
 * @constructor
 * @author Marcos A. Zinni
 */
function Layout(){
	this.ClassName = "Layout";
	/**
	 * Captura o objeto do componente através de seu nome.
	 * @author Marcos A. Zinni
	 * @return {object} Objeto de refência para o componente.
	 */
	this.getObject = function(){
		return Kernel.ge(this.name);
	};

	/**
	 * Escreve o o código HTML através do método <b>document.write</b>, o conteúdo
	 * escrito é capturado através do método getHTML da classe do componente.
	 * <p>
	 *    Após sua execução o é executado o método <b>finishWrite</b> do componente.
	 * </p>
	 * @author Marcos A. Zinni
	 */
	this.write = function(){
		Kernel.dw(this.getHTML());
		this.finishWrite();
	};

	
	/**
	 * Escreve o o código HTML através do método <b>object.innerHTML</b>, o conteúdo
	 * escrito é capturado através do método getHTML da classe do componente.
	 * <p>
	 *    Após sua execução o é executado o método <b>finishWrite</b> do componente.
	 * </p>
	 * @author Marcos A. Zinni
	 * @replace obj > $O
	 */
	this.writeIn = function(obj){
		if ( typeof obj == "string" ){
			Kernel.dw(this.getHTML(), obj);
		}
		obj.innerHTML += this.getHTML();
		this.finishWriteIn();
	};
	
	/**
	 * Exibe ou esconde o componente.
	 * @param {boolean} flag 
	 * 					<b>true</b>: exibe<br>
	 * 					<b>false</b>: esconde
	 * @author Marcos A. Zinni
	 */
	this.display = function(flag){
		this.getObject().style.display = (flag)?"":"none";
	};
	
	/**
	 * Método a definir.
	 * @private
	 * @author Marcos A. Zinni
	 */
	this.getValue = function(){
	};

	/**
	 * Método a definir.
	 * @private
	 * @author Marcos A. Zinni
	 */
	this.setPosition = function(left, top){
	};
	
	/**
	 * Método a definir.
	 * @private
	 * @author Marcos A. Zinni
	 */
	this.getPosition = function(){
	};
};

/**
 * Classe de manipulação da propriedade "class" das tags.
 * @class Responsável pela manipulação das propriedades do ClassName dos objetos.
 * @constructor
 * @author Marcos A. Zinni
 */
function ClassName(){
	/**
	 * Adiciona uma propriedade o <b>class</b>.
	 * @param {string} name Nome(id) do objeto que receberá a propriedade.
	 * @param {string} selector Nome do Selector.
	 * @author Marcos A. Zinni
	 * @replace name		> $N
	 * @replace selector	> $S
	 */
	this.add = function (name, selector){
		this.getElement(name).className += ' ' + selector;

	};

	/**
	 * Remove as propriedades do atributo class.
	 * @param {string} name Nome(id) do objeto que receberá a propriedade.
	 * @param {string} selector Nome do Selector.
	 * @author Marcos A. Zinni
	 * @replace name		> $N
	 * @replace selector	> $S
	 */
	this.remove = function(name, selector){
		this.getElement(name).className = this.getElement(name).className.replace(RegExp(' '+selector,'g'),'');
	};
	this.get = function(){
		return this.getElement(name).className;
	};
	this.isSelector = function(name, selector){
		return ((this.getElement(name).className).indexOf(" " + selector) > -1);
	};
	/**
	 * Captura o objeto através id.
	 * @private
	 * @return {object} Objeto da tag.
	 * @author Marcos A. Zinni
	 * @replace name > $N
	 */
	this.getElement = function(name){
		if (typeof name == "string"){
			return document.getElementById(name);
		} else {
			return name;
		}
	};
};

/**
 * Construtor do Layout.
 * @class Permite a manipulação visual dos componentes.
 * @constructor
 * @author Marcos A. Zinni
 */
function StyleSheet(){
	this.ClassName = "StyleSheet";
	/**
	 * Seta propriedades em um selector do style da página.
	 * @param {string} selector Nome do selector. 
	 * @param {string} property Nome da propriedade que será alterada. 
	 * @param {string} value Valor da propriedade que será alterada. 
	 * @author Marcos A. Zinni
	 * @replace selector 	> $S
	 * @replace property 	> $P
	 * @replace value 		> $V
	 * @replace objRules 	> _O 
	 */
	this.setProperty = function(selector, property, value){
		var ss = document.styleSheets;
		for (var si = 0; si < ss.length; si++){
			var objRules = ( Kernel.isIE() )?ss[si].rules:ss[si].cssRules;
			for(var i = 0; i < objRules.length; i++){
				if (objRules[i].selectorText == selector){
					eval("document.styleSheets[" + si + "]." +(( Kernel.isIE() )?"rules":"cssRules")+ "["+i+"].style." + property + "='" + value+"';");
					return;
				}
			}
		}
		if ( Kernel.isIE() ){
			ss[ss.length-1].addRule(selector, property+":"+value);
		}else{
			ss[ss.length-1].insertRule(selector+"{"+property+":"+value+"}", ss[ss.length-1].cssRules.length);
		}
	}
}
StyleSheet.prototype = new ClassName();
StyleSheet = new StyleSheet();


function Html(){
	this.ClassName = "Html";
	this.createIframe = function(obj, nome, className){
		var objIframeTemp = document.createElement("IFRAME");
			objIframeTemp.frameBorder = "0";
			objIframeTemp.id = nome;
			objIframeTemp.name = nome;
			objIframeTemp = obj.appendChild(objIframeTemp);
			objIframeTemp.className = className;
		return objIframeTemp;
	};
	this.createDiv = function(obj, strId, className){

		var objDivTemp = obj.appendChild(document.createElement("DIV"));

			objDivTemp.id = strId;

			objDivTemp.className = className;
		return objDivTemp;
	};
	this.creatHref = function (objIn, strId, strLink, className){
		var objDivTemp = Kernel.getObject(objIn).appendChild(document.createElement("A"));
			objDivTemp.name = strId;
			objDivTemp.id = strId;
			if (strLink)
				objDivTemp.className = className;
			if (strLink)
				objDivTemp.href = strLink
		return objDivTemp;
	};
	this.createForm = function(obj, id, action, target, method){
		var objDivTemp = obj.appendChild(document.createElement("FORM"));
			objDivTemp.id = id;
			objDivTemp.name = id;
			objDivTemp.action = action;
			objDivTemp.target = target;
			objDivTemp.method = method;
		return objDivTemp;
	};

	this.getSize = function(id){
		var objTemp = Kernel.ge(id);
		return [objTemp.offsetWidth, objTemp.offsetHeight];
	};

	this.getPosition = function(id){
		var objTemp = Kernel.ge(id);
		var menuLeft=menuTop = 0;
		do{
			menuLeft += objTemp.offsetLeft;
			menuTop  += objTemp.offsetTop;
			objTemp   = objTemp.offsetParent;
		}while (objTemp.tagName != "BODY"); 
		return [menuLeft , menuTop];
	};

	this.getScrollPositions = function(obj) {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( obj.pageYOffset ) == "number" ) {
			scrOfY = obj.pageYOffset;
			scrOfX = obj.pageXOffset;
		} else if(obj && ( obj.scrollLeft || obj.scrollTop ) ) {
			scrOfY = obj.scrollTop;
			scrOfX = obj.scrollLeft;
		}
		return [ scrOfX , scrOfY ];
	};

	this.createBlock = function (name, label, width, height, left, top){
		Kernel.dw('<fieldset class="bloco" id="' + name + '" style="width:' + width + 'px;height:' + height + 'px; position:absolute; z-index:1; top:' + top + 'px; left:' + left + 'px""><legend id="block">&nbsp;' + label + '&nbsp;</legend></fieldset>');
	};

	this.importJs = function(source){
		Kernel.dw('<sc'+'ript type="text/javascript" src="' + source + '"></sc'+'ript>');
	};

	this.createLayer = function(name, content, layer, style, width, height, left, top){
		Kernel.dw('<div id="' + name + '" style="width:' + width + 'px;height:' + height + 'px; position:absolute; z-index:1' + layer + '; top:' + top + 'px; left:' + left + 'px;' + ((style.substring(0,6)=="class:")?'" class="'+style : style) + '">' + content + '</div>');

	};

	this.createStatusBar = function(){
		var statusBar = new StringBuffer();
			statusBar.add('<div style="position:absolute; bottom:0px; width:100%">');
				statusBar.add('<table class="rodape">');
				statusBar.add('<tr><td id=msgStatus></td>');
				statusBar.add('<td width="1%" valign=middle><img src="' + Kernel.getRoot() + '/img/0211007.gif"></td>');
				statusBar.add('</tr></table>');
			statusBar.add('</div>');
		Kernel.dw(statusBar.toString());
	};
	this.setTitle = function(title){
		document.title = title;
	}
}
Html = new Html();

function writeHTMLTags(){
	var wkt = getElementsByTagNames("CreateBlock,CreateStatusBar,CreatHref");
	for (var i = 0; i < wkt.length; i++){
		if (wkt[i].tagName.toLowerCase() == "createblock"){
			Html.createBlock(wkt[i].name, wkt[i].label, wkt[i].width, wkt[i].height, wkt[i].left, wkt[i].top);
		}else if (wkt[i].tagName.toLowerCase() == "createstatusbar"){
			Html.createStatusBar();
		}else if (wkt[i].tagName.toLowerCase() == "creathref"){
			alert("create")
			Html.creatHref(wkt[i].objIn, wkt[i].name, wkt[i].link, wkt[i].className)
		}else{
			Kernel.setOnload(wkt[i].action);
		}
	}
}

/**
 * Construtor do Messenger.
 * @class Classe usada para exibir as mensagens em geral.
 * Exibe as mensagens de forma padronizada as mensagens do sistema.
 * @constructor
 * @author Marcos A. Zinni
 */
function Messenger (){
	this.ClassName = "Messenger";
	/**
	 * Escreve o código HTML básico para a execução ao componente.
	 * @author Marcos A. Zinni
	 */
	this.write = function (){
		var objTemp = Html.createDiv(document.body, "msgInProcess", "Messenger");
					  Html.createDiv(objTemp, "msg_message", "Message");
	};

	/**
	 * Escreve o código HTML básico para a execução ao componente.
	 * @author Marcos A. Zinni
	 * @param {boolean} flag Exibe ou esconde o a mensagem.
	 */
	this.show = function (flag){
		StyleSheet.setProperty(".Messenger", "display", ((flag)?"":"none"));
	};

	/**
	 * Seta o conteúdo que será exibido na mensagem.
	 * @author Marcos A. Zinni
	 * @param {string} data Dado que será exibido na mensagem.
	 */
	this.setMessage = function (value){
		if ( ! Kernel.ge("msg_message") ){
			this.write();
		}
		Kernel.ge("msg_message").innerHTML = value;
	};
	return this;
};
Messenger = new Messenger();

function FloatMessage (name, template){
	this.ClassName = "FloatMessage";
	this.name = name;
	this.template = template||"";
	this.value = "";
	this.x = 0;
	this.y = 0;
	this.isShow = false;

	this.write = function (){
		if ( ! Kernel.getInstanceClass(this.name) ){
			Kernel.setInstanceClass(this.name, this);
			var evt = new Event(document.body)
				evt.attach("click", closeFloatMessage)
			Html.createDiv(document.body, this.name, "FloatMessage");
		}
	};
	this.setTemplate = function (template){
		this.template = template;
	};
	this.show = function(x, y){
		Kernel.ge(this.name).style.display	= "";
		if (Kernel.ge(this.name).innerHTML != this.value){
//			Kernel.ge(this.name).innerHTML 		= this.value;
//			alert("trocou")
		}
//		alert(x +"&&"+ y)
		if (typeof x == "number" && typeof y == "number"){
			this.setPosition(x, y)
		} else {
			setDefaultPosition(this);
		}
		Kernel.ge(this.name).style.left 	= this.x;
		Kernel.ge(this.name).style.top  	= this.y;
//			alert(Kernel.ge(this.name).innerHTML)
		prot(Kernel.ge(this.name), true);
		this.isShow =  true;
	};
	function prot(obj, flag){
		if ( ! Kernel.isIE() ) return;
		var objIframe = Kernel.ge("ifram_aux_"+obj.id);
		if ( ! objIframe ){
			objIframe = Html.createIframe(document.body, "ifram_aux_"+obj.id, "mn_ifrm_aux");
		}
		objIframe.style.display = ( ! flag )? "none" : "";

		objIframe.style.width = obj.offsetWidth;
		objIframe.style.height = obj.offsetHeight;
		objIframe.style.left = obj.offsetLeft;
		objIframe.style.top = obj.offsetTop;
		objIframe.style.zIndex = (obj.style.zIndex);

	}
	this.hidden = function(){
		prot(Kernel.ge(this.name), false)
		Kernel.ge(this.name).style.display	= "none";
		this.isShow =  false;
	};

	this.writeParameters = function (parameters){
		var strTemp = this.template;
		if ( typeof parameters == "object" ){
			strTemp = Kernel.writeParameters(strTemp, parameters);
		}
		this.value = strTemp;
		Kernel.ge(this.name).innerHTML = this.value;
	};
	
	function setDefaultPosition(instance){
		var mX = Kernel.getPositionMouse()[0];
		var mY = Kernel.getPositionMouse()[1];
		var objTempFilho = Kernel.ge(instance.name);
//		alert(objTempFilho.style.display)
		var w = objTempFilho.offsetWidth;
		var h = objTempFilho.offsetHeight;
//		alert("objTempFilho: " + objTempFilho.id)
		var wb = getSizeBody()[0];
		var hb = getSizeBody()[1];
		var x = ( (mX + w) > wb )? (mX-((mX+w)-wb)) : (mX+2);
//			alert((mY + h) > hb)
//			alert(mY +"+"+ h +">"+ hb)
		var y = ( (mY + h) > hb )? (mY - h - 2) : (mY+2);
		instance.setPosition(x, y);
		
	};
	this.setPosition = function(x, y){
		this.x = x;
		this.y = y;
	}
	this.write();
	return this;
}
function closeFloatMessage(){
	for (var i in Kernel.instances){
		if (Kernel.instances[i].ClassName == "FloatMessage"){
			Kernel.instances[i].hidden();
		}
	}
}


function ToolTipText (){
	this.ClassName = "ToolTipText";
	this.show = false;
	this.showFocus = false;
	this.value = null;
	
	this.floatMessage = null;

	this.setMessage = function (value, evt, flagF2, width, height){
		if ( ! Kernel.getInstanceClass("fm_ToolTipText") ){
//			alert("fm_ToolTipText *****************-----------")
			var param = ( width && height ) ? " width:" + width + ";height:" + height : "";
				
			this.floatMessage = new FloatMessage("fm_ToolTipText");
			var html = '<div id="msg_ttt" style="' + param + '" class="ToolTipText"><div id="msg_ttt_message" class="ToolTipTextMessage {1}">{0}</div>';
			if ( !flagF2 ){
				html += '<div id="ToolTipTextPressF2" class="ToolTipTextPressF2">{2}</div>';
			}
			html += '</div>';
			this.floatMessage.setTemplate(html);
			var evt = new Event(document.body)
				evt.attach("keyup", onF2ToolTipText)			
		}

		if (this.value != value){
//			alert("this.value != value")
			this.value = value;
			this.showFocus = false;
			this.floatMessage.writeParameters([value, "", "Pressione F2 para <b>ABRIR</b>."])
			this.show = true;
		}
		this.floatMessage.show();
	};
	this.hidden = function(){
		if ( ! this.showFocus && this.floatMessage ){
			//StyleSheet.remove("msg_ttt_message", "ToolTipTextMessageFocus")
			this.floatMessage.hidden();
			this.show = false;
			this.value = null;
		}
	};
	this.focus = function(){
		this.showFocus = true;
		this.floatMessage.writeParameters([this.value, "ToolTipTextMessageFocus", "Pressione F2 para <b>FECHAR</b>."])
		this.floatMessage.show();
	};
	return this;
}
function onF2ToolTipText(evt){
	if ( ToolTipText.show && evt.keyCode == 113 ){
		if ( ! ToolTipText.showFocus ){
			ToolTipText.focus();
		} else {
			ToolTipText.showFocus = false;
			ToolTipText.hidden();
		}
	}
}
ToolTipText = new ToolTipText();


window.onload=function(){
	Kernel.execute();
}


function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++){
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (testNode && testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
			return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode && testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
			return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}

function getSizeBody() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == "number" ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [ myWidth , myHeight ];
}




var timeClose = null;
function hiddenItem(nivel){
	for (var i in menu){
		var itemMenu = menu[i];
		if (itemMenu.nivel >= nivel && document.getElementById(i).style.display == ""){
			document.getElementById(i).style.display = "none";
			retirarRastro(i);
		}
	}	
}

function retirarRastro(item){
	arrRastro[item].style.color = ""
}

function ligaTimeout(){
	timeClose = window.setTimeout("hiddenItem(0)", 2000);
}

function desligaTimeout(){
	if(timeClose){
		window.clearTimeout(timeClose);
		timeClose=null;
	}
}

var ToolTipTextBKP = {
	setMessage : function (){
		return false
	},
	hidden : function (){
		return false
	}
}
var MyToolTipText = {
	tymeOut : null,
	value : null,
	evt : null,
	flagF2 : null,
	width : null,
	height : null,

	setMessage : function (value, evt, flagF2, width, height){
		this.value = value,
		this.evt = evt,
		this.flagF2 = flagF2,
		this.width = width,
		this.height = height,
		this.tymeOut = window.setTimeout("MyToolTipText.showMessage()", 1500);

	},
	showMessage : function(){
		ToolTipText.setMessage(this.value, this.evt, this.flagF2, this.width, this.height);
	},
	hidden : function (){
		if(this.tymeOut){
			window.clearTimeout(this.tymeOut);
			this.tymeOut=null;
			ToolTipText.hidden();
		}
	}
}
var arrRastro = [];
function showItem(parent, item){
	if ( item == "" ) return;
	parent.style.color = "red"
	arrRastro[item] = parent;
	var obj = document.getElementById(item);
	obj.style.display = "";

	var metrics = Kernel.getObjectMetrics(parent);
	
	var mW = metrics.w;
	var mX = metrics.xw;
	var mY = metrics.y;
	var mH = metrics.h;

	var w = obj.offsetWidth;
	var h = obj.offsetHeight;

	
	var wb = getSizeBody()[0];
	
	var hb = getSizeBody()[1];

	var x = ( (mX + w) > wb )? (mX-(mW+w)+3) : (mX);
	var y = ( (mY + h) > hb )? (mY - h+3 + mH) : (mY+3);
	
	obj.style.left = x;
	obj.style.top = y;
}
function GerarItensDoMenu(){
	// Código usado para escrever os subitens na página.
	for (var i in menu){
		var itemMenu = menu[i];
		document.write('<div class="menu1" id="' + i + '" style="display:none;position:absolute; left=100px; margin-top:3px; z-index:' + itemMenu.nivel + '; ' + ((itemMenu.width)?"width:" + itemMenu.width:"") + '">');
		document.write('<table class="table" cellpadding="0" cellspacing="0" onmouseover="desligaTimeout();"  onmouseout="ligaTimeout()">');
		for (var ii = 0; ii < itemMenu.itens.length; ii++){
			document.write('<tr><td style="border-left:1px solid F9D243; border-right:1px solid F9D243; border-top:1px solid FFF09F;  border-bottom:1px solid F9D243" onmouseover="hiddenItem(' + (itemMenu.nivel+1) + '); MyToolTipText.setMessage(' + itemMenu.itens[ii][1] + ', event, true)" onmouseout="MyToolTipText.hidden();" class="menu1_td"><a id="sub_' + i + '_' + ii + '" class="aMenu" style="' + ((itemMenu.itens[ii][4]=="d")?"color:#999999":"") + '" href="' + ((itemMenu.itens[ii][4]=="")?'JavaScript:void(0)':itemMenu.itens[ii][4]) + '" onclick="showItem(this, \'' + itemMenu.itens[ii][3] + '\');" >' + itemMenu.itens[ii][2] + ' ' + ((itemMenu.itens[ii][3])?"»":"") + '</a></td></tr>');
		} 
		document.write('</table></div>');
	}
}


function abrePagina(){
	window.open("<?echo HTTP_SERVER?>/folders/pagina2.php","fotos", "toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=220,height=350,top=10,left=10");
}

// SCRIPT INSERIR FOTOS 2.0 /////////////////////////////////////////////////////////

function inserirfotos2(pasta, qtd, id_imagem)
{

document.write('<table cellpadding="2" cellspacing="2"width="480">');
document.write(' <tr>');
document.write('   <tr><td colspan="2" width="100%" bgcolor="#EAEAEA" style="padding:4px"><b>Mais Fotos</b></td></tr> ');
document.write(' </tr>');
document.write('</table>');
document.write('<table width="470" align="center">');
document.write(' <tr>');
document.write('  <td align="center"><img id="fotoGrande'+id_imagem+'" src="<?echo HTTP_SERVER?>/fotos/'+pasta+'/001.jpg" style="border:1px solid #828282"></td>');
document.write(' </tr>');
document.write('</table>');
document.write('<table align="center"  bgcolor="#FFFAE1" width="470" style="border:1px solid #FFF09F">');
document.write(' <tr>');
document.write('  <td align="center" style="padding-bottom:8px; padding-top:5px"> ');
document.write('   <script>getFotos2("'+pasta+'", '+qtd+','+id_imagem+')</script>  ');
document.write('  </td>');
document.write(' </tr>');
document.write('</table>');

}

function showImage2(image, id_imagem){
	document.getElementById("fotoGrande"+id_imagem).src = image;
}

function getFotos2(pasta, qtd, id_imagem){
	for (var i = 1; i < (qtd+1); i++){
		if (i<10)
		{
		var endFotoMini = 'fotos/' + pasta + '/mini/00' + i + '.jpg';
		var endFoto = 'fotos/' + pasta + '/00' + i + '.jpg';
		}
		else
		{
		var endFotoMini = 'fotos/' + pasta + '/mini/0' + i + '.jpg';
		var endFoto = 'fotos/' + pasta + '/0' + i + '.jpg';
		}
		document.write('<div style="margin:2px; border:1px solid #828282; float:left; text-align:center; margin-left:6px"><img onclick="showImage2(\'' + endFoto + '\', \''+id_imagem+'\')" src="'+ endFotoMini +'" style="cursor:hand; pointer:hand"></div>');
	}
}

function abreFoto(cod, desc){
	idFoto = cod;
  	open("abreFoto.php?idFoto=" + idFoto + "&desc=" + desc,"fotos", "toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=no,width=424,height=600,top=130,left=270");
}