var xmlHttp = false;
var url_site = 'www.pinheiros.com.br';
// trying to avoid browser incompatibilities
try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (error) {
    try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (error) { xmlHttp = false; }
}
if (!xmlHttp) {
    xmlHttp = new XMLHttpRequest();
}

function request(url,fun) {
	var output   = null;
	var resource = url;
	var callback = fun;

	xmlHttp.open("GET", resource, true);
	xmlHttp.onreadystatechange = function (aEvent) {
		this.state = xmlHttp.readyState;
		if (this.state == 4) {
			if (xmlHttp.status == 200) {
				output = xmlHttp.responseText;
				callback(output);
			}
		}
	};
	xmlHttp.send(null);
}

function instante(data) {
	var servicos = eval(data);
	htmlRodizio = '<table width="100%" height="15" border="0" cellpadding="0" cellspacing="0">';
    htmlRodizio += '<tr align="center">';
    htmlRodizio += '<td width="100%">Rod&iacute;zio&nbsp;&nbsp;<img border="0" src="http://'+ url_site +'/cidade_agora/rodizio.gif" width="21" height="14">' + '&nbsp;&nbsp;' + servicos.rodizio; +'</td>';
    htmlRodizio += '</tr>';
    htmlRodizio += '</table>';
	getById('header-2-linha-02-rodizio').innerHTML = htmlRodizio;
		
	if(!isNaN(servicos.transito)) {
		htmlTransito = '<table width="100%"  border="0" cellpadding="0" cellspacing="0">';
	    htmlTransito+= '<tr align="center">';
	    htmlTransito+= '<td width="62%">Situa&ccedil;&atilde;o Tr&acirc;nsito&nbsp;</td>';
		htmlTransito+= '<td width="15%"><a target="_black" href="http://www.prefeitura.sp.gov.br/servicos/cidadaos/transito_e_transporte/lentidao/index.php"><img src="http://'+ url_site +'/cidade_agora/transito.gif" alt="Tr&acirc;nsito" width="30" height="15" border="0"></a></td>';
		htmlTransito+= '<td width="23%">&nbsp;<a target="_black" href="http://www.prefeitura.sp.gov.br/servicos/cidadaos/transito_e_transporte/lentidao/index.php">';
		htmlTransito+= servicos.transito;
		htmlTransito+= 'km</a></td>';
	    htmlTransito+= '</tr></table>';
   		getById('header-2-linha-02-transito').innerHTML = htmlTransito;
	}
	
	if(!isNaN(servicos.transito)) {
	    var imagem = 'http://prefeitura.sp.gov.br/portal/img/temp/' + servicos.tempo.image + 'capa.gif';
		htmlClima  = '<table height="10" width="100%"  border="0" cellpadding="0" cellspacing="0">';
		htmlClima += '<tr align="center">';
		htmlClima += '<td>Clima&nbsp;</td>';
		htmlClima += '<td><a target="_black" href="http://www.prefeitura.sp.gov.br/servicos/cidadaos/meio_ambiente/clima/index.php"><img src="' + imagem + '" alt="' + servicos.tempo.alt + '" title="' + servicos.tempo.alt + '" width="27" height="15" border="0"></a></td>';
		htmlClima += '<td>&nbsp;<a target="_black" href="http://www.prefeitura.sp.gov.br/servicos/cidadaos/meio_ambiente/clima/index.php">' + servicos.tempo.valor + '&#176;C</a></td>';			
		htmlClima += '</tr></table>';
   		getById('header-2-linha-02-clima').innerHTML = htmlClima;		
	}
	
}

function getById(element) {
	return document.getElementById(element);
}