// PortalStructure
// This object get header/footer informations and provide methods to
// print informations on HTML structure
PortalStructure = {
	show: undefined,
	information: undefined,
	htmlHeader: "",
	htmlFooter: "",

	printHeader: function() {
		if (PortalConfiguration == undefined) { return false; }
		this.mountHeader();
		document.write(this.htmlHeader);
	},
	printFooter: function() {
		if (PortalConfiguration == undefined) { return false; }
		this.mountFooter();
		document.write(this.htmlFooter);
	},

	init: function() {
		if (PortalConfiguration == undefined) { return false; }
		this.show = PortalConfiguration.show;
		this.data = PortalConfiguration.data;

		var cssIncludes = "";
		if (this.show.defaultStyles) {
			if (PortalConfiguration.getNavigatorType() == 1) {
					cssIncludes += '<link href="'+this.data.CSSBaseURL+'default_txt.css" rel="stylesheet" type="text/css" />\n';
			} else if (PortalConfiguration.getNavigatorType() == 3) {
					cssIncludes += '<link href="'+this.data.CSSBaseURL+'padrao.css" rel="stylesheet" type="text/css" />\n';
					cssIncludes += '<link href="'+this.data.CSSBaseURL+'barra_'+this.show.color+'.css" rel="stylesheet" type="text/css" />\n';
			}
		}
		
		if (this.show.menu == 'claro') {
			cssIncludes += '<link href="'+this.data.CSSBaseURL+'entidade.css" rel="stylesheet" type="text/css" />\n';
			cssIncludes += '<link href="'+this.data.CSSBaseURL+'menu_e.css" rel="stylesheet" type="text/css" />\n';
		}
		
		var jsIncludes = "";
		if (this.show.infoInstante) {
			// Arrumar este script
			jsIncludes += '<script type="text/javascript" src="//www.capital.sp.gov.br/portalpmsp/infocge.js"><\/script>\n';
		}
		if (this.show.search) {
			jsIncludes += '<script type="text/javascript" src="'+this.data.JSBaseURL+'busca.js"><\/script>\n';
		}

		document.write(jsIncludes+cssIncludes);
	},
	mountHeader: function() {
		this.htmlHeader = '';
		this.htmlHeader += '<div id="wrap">\n';
		
		if (this.show.header) {
			this.htmlHeader += '  <div id="topo">\n';
			this.htmlHeader += '    <div id="bprint"><img src="'+this.data.IMGBaseURL+'bprint.png" alt="Barra de Impressão" width="200" height="40" /></div>\n';
	
			if (this.show.infoInstante) {
				this.htmlHeader += '	<div id="spagora">\n';
				this.htmlHeader += '      <h1 class="hide">S&atilde;o Paulo Agora</h1>\n';
				this.htmlHeader += '      <h2 class="cge"><span><strong class="hide">Avisos do</strong> <acronym lang="pt-br" title="Significado de CGE">CGE:</acronym> <a href="1" tabindex="21"><strong class="status">Status</strong> - Texto contendo n&uacute;mero m&aacute;ximo de caracteres.</a></span></h2>\n';
		
				this.htmlHeader += '      <p><span class="boxes"><a href="4" tabindex="22">Rod&iacute;zio: 3 e 4</a></span></p>\n';
				this.htmlHeader += '      <p><span class="boxes"><a href="2" tabindex="23">Lentid&atilde;o: 47 km</a></span></p>\n';
				this.htmlHeader += '      <p><span class="boxes">Clima:</span><a href="aaa"><img src="img/ico_pn_16.png" alt="Tempo parcialmente nublado com possibilidade de chuvas" width="16" height="16" border="0" title="Tempo parcialmente nublado com possibilidade de chuvas" /></a> <span class="boxes">26&ordm;</span></p>\n';
				this.htmlHeader += '    </div>\n';
			}
			
			this.htmlHeader += '    <div id="ferramentas"> <a href="http://www.capital.sp.gov.br/"><img src="'+this.data.IMGBaseURL+'logo_portal.gif" alt="Portal da Prefeitura de S&atilde;o Paulo" width="211" height="45" border="0" class="logo" /></a>\n';
	
			this.htmlHeader += '      <div class="cont">\n';
			
			if (this.show.tools) {
				this.htmlHeader += '        <h2 class="hide">Ferramentas</h2>\n';
				this.htmlHeader += '        <ul>\n';
				this.htmlHeader += '          <li><a href="http://www.capital.sp.gov.br/portalpmsp/do/mapa?op=insertForm" onmouseover="document.getElementById(\'descricao\').innerHTML=this.title;" onmouseout="document.getElementById(\'descricao\').innerHTML=\'&nbsp;\';" title="Mapa do site"><img src="'+this.data.IMGBaseURL+'ico_mapa.gif" alt="Mapa do site" width="16" height="16" /></a></li>\n';
				this.htmlHeader += '          <li><a href="http://www.prefeitura.sp.gov.br/portal/portal/contato/index.php?contato=1&url=' + window.location + '" onmouseover="document.getElementById(\'descricao\').innerHTML=this.title;" onmouseout="document.getElementById(\'descricao\').innerHTML=\'&nbsp;\';" title="Contato"><img src="'+this.data.IMGBaseURL+'ico_contato.gif" alt="Contato" width="16" height="16" /></a></li>\n';
				this.htmlHeader += '          <li><a href="http://www.capital.sp.gov.br/portalpmsp/do/ajuda" onmouseover="document.getElementById(\'descricao\').innerHTML=this.title;" onmouseout="document.getElementById(\'descricao\').innerHTML=\'&nbsp;\';" title="Ajuda do site"><img src="'+this.data.IMGBaseURL+'ico_ajuda.gif" alt="Ajuda do site" width="16" height="16" /></a></li>\n';
				this.htmlHeader += '        </ul>\n';
			}
			
			this.htmlHeader += '        <div id="descricao">&nbsp;</div>\n';
			this.htmlHeader += '      </div>\n';
			this.htmlHeader += '    </div>\n';
	
			this.htmlHeader += '  </div>\n';
			this.htmlHeader += '  <hr />\n';
	
			if (this.show.search || this.show.title) {

				if (this.show.title) {
					this.htmlHeader += '  <div id="topo_capa">\n';
					this.htmlHeader += '    <div id="titulo">\n';
					this.htmlHeader += '      <h1>'+this.data.title+'</h1>\n';
					this.htmlHeader += '    </div>\n';
				} else {
					this.htmlHeader += '  <div id="busca_simples">\n';
				}
				if (this.show.search) {
	                this.htmlHeader += '    <form name="form" onSubmit="busca();return false;" action="" class="busca">\n';
	                this.htmlHeader += '      <input type="hidden" name="op"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="buscaAvancada"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="buscaSimples"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="contadorServico"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="contadorInstituicao"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="contadorUnidade"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="contadorNoticia"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="orderBy"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="filter"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="unidadeForm"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="servicoForm"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="coInstituicao"/>\n';
	                this.htmlHeader += '      <input type="hidden" name="isHead"/>\n';
	                this.htmlHeader += '      <input name="param" type="text" class="txtbusca" value="Buscar em todo o portal" onBlur="if (this.value == \'\') { this.value=this.defaultValue; }" onFocus="if (this.value == this.defaultValue) { this.value=\'\'; }" tabindex="1" />\n';
					this.htmlHeader += '      <input name="imageField2" type="image" class="corrigebt" src="'+this.data.IMGBaseURL+'bt_topo_buscar_'+this.show.color+'.gif" />\n';
					this.htmlHeader += '    </form>\n';
				}
				this.htmlHeader += '  </div>\n';
				this.htmlHeader += '  <hr />\n';
			}
	
			if (this.show.trackBack) {
				this.htmlHeader += '  <div id="topo_sec"><p>'
		
				if (this.data.trackBack != "") {
					this.htmlHeader += this.data.trackBack;
					// Para manter compatibilidade com o antigo
				} else if (typeof(PortalStructureTrackBack) == 'string') {
					this.htmlHeader += '		'+PortalStructureTrackBack+'\n';
				} else if (typeof(PortalStructureOrgao) == 'object') {
					this.htmlHeader += '		<a href="'+PortalStructureOrgao.url+'" title="'+PortalStructureOrgao.nome+'" target="_self">'+PortalStructureOrgao.nome+' <acronym title="'+PortalStructureOrgao.nome+'">('+PortalStructureOrgao.sigla+')<\/acronym><\/a>\n';			
				}
				
				this.htmlHeader += '</p></div>\n';
				this.htmlHeader += '  <hr />\n';
			}
		}
		this.htmlHeader += '  <div id="body">\n';
	},
	mountFooter: function() {
		if (this.show.footer) {
			this.htmlFooter = '';
			this.htmlFooter += '    <hr />\n';
			this.htmlFooter += '    <div id="rodape_p"><img src="'+this.data.IMGBaseURL+'rodape_p.png" alt="Rodapé de impressão" height="21" width="90"></div>\n';
			this.htmlFooter += '	<div id="rodape">\n';
			this.htmlFooter += '      <ul>\n';
			this.htmlFooter += '        <li>Copyright</li>\n';
			this.htmlFooter += '        <li><a href="http://www.capital.sp.gov.br/portalpmsp/do/aspectosLegais?op=viewForm">Expediente</a></li>\n';
			this.htmlFooter += '        <li><a href="http://www.prefeitura.sp.gov.br/portal/portal/contato/index.php?contato=1&url=' + window.location + '">Fale Conosco</a></li>\n';
			this.htmlFooter += '        <li><a href="http://sac.prefeitura.sp.gov.br/">SAC</a></li>\n';
			this.htmlFooter += '	  </ul>\n';
			this.htmlFooter += '	  <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '      <!--s -->\n';
			this.htmlFooter += '    </div>\n';
		}
		this.htmlFooter += '  </div>\n';
		this.htmlFooter += '</div>\n';
		
		// Fix para o problema de float do menu
		if ((document.getElementById('texto') != null) && (document.getElementById('menu_esq').offsetHeight > document.getElementById('texto').offsetHeight)) {
			document.getElementById('texto').style.height=(document.getElementById('menu_esq').offsetHeight+15)+"px";
		}
		if ((document.getElementById('interna_lista') != null) && (document.getElementById('menu_esq').offsetHeight > document.getElementById('interna_lista').offsetHeight)) {
			document.getElementById('interna_lista').style.height=(document.getElementById('menu_esq').offsetHeight+15)+"px";
		}
	}
}
PortalStructure.init();

