function selecionar(linha,botao,obs,qtdade,ambiente,estilo) {

	ant = botao.checked;

	if (ant) {

		linha.style.backgroundColor = estilo;

		linha.style.color = "#000000";

		obs.style.color = "#000000";

		obs.disabled = "";

		qtdade.style.color = "#000000";

		qtdade.disabled = "";

		ambiente.style.color = "#000000";

		ambiente.disabled = "";

	}

	else {

		linha.style.backgroundColor = "#F0F0F0";

		linha.style.color = "#D8D8D8";

		obs.style.color = "#D8D8D8";

		obs.disabled = "disabled";

		qtdade.style.color = "#D8D8D8";

		qtdade.disabled = "disabled";

		ambiente.style.color = "#D8D8D8";

		ambiente.disabled = "disabled";

	}

} 

function voltar()  {

  history.back();

}

function Abre(url, width, height)

{

window.open(url,"_blank","resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height);

}

function Mapa(url, width, height)

{

window.open(url,"_blank","resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height);

}

function Ajuda(url, width, height)

{

window.open(url,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height);

}

function Zoom(url, width, height)

{

window.open(url,"_blank","resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes,width=" + width + ",height=" + height);

}

function formatar(src, mask) 

{

  var i = src.value.length;

  var saida = mask.substring(0,1);

  var texto = mask.substring(i)

if (texto.substring(0,1) != saida) 

  {

	src.value += texto.substring(0,1);

  }

}

function BlockKeybord()

{

	if((event.keyCode < 48) || (event.keyCode > 57))

	{

		event.returnValue = false;

	}

}



function troca(str,strsai,strentra)

{

	while(str.indexOf(strsai)>-1)

	{

		str = str.replace(strsai,strentra);

	}

	return str;

}



function Formatavalor(campo,tammax,teclapres,caracter)

{

	if(teclapres == null || teclapres == "undefined")

	{

		var tecla = -1;

	}

	else

	{

		var tecla = teclapres.keyCode;

	}



	if(caracter == null || caracter == "undefined")

	{

		caracter = ".";

	}



	vr = campo.value;

	if(caracter != "")

	{

		vr = troca(vr,caracter,"");

	}

	vr = troca(vr,"/","");

	vr = troca(vr,",","");

	vr = troca(vr,".","");



	tam = vr.length;

	if(tecla > 0)

	{

		if(tam < tammax && tecla != 8)

		{

			tam = vr.length + 1;

		}

		

		if(tecla == 8)

		{

			tam = tam - 1;

		}

	}

	if(tecla == -1 || tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105)

	{

		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) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);

		}

		if((tam >= 9) && (tam <= 11))

		{

			campo.value = vr.substr(0, tam - 8) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);

		}

		if((tam >= 12) && (tam <= 14))

		{

			campo.value = vr.substr(0, tam - 11) + caracter + vr.substr(tam - 11, 3) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);

		}

		if((tam >= 15) && (tam <= 17))

		{

			campo.value = vr.substr(0, tam - 14) + caracter + vr.substr(tam - 14, 3) + caracter + vr.substr(tam - 11, 3) + caracter + vr.substr(tam - 8, 3) + caracter + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam);

		}

	}

}

function mostra(camada){ 

xShow(camada); 

} 

function oculta(camada){ 

xHide(camada); 

} 

function posiciona (){ 

posx= xOffsetLeft("ancora1") 

posy= xOffsetTop ("ancora1") 

xMoveTo('e1',posx,posy+20) 

posx= xOffsetLeft("ancora2") 

posy= xOffsetTop ("ancora2") 

xMoveTo('e2',posx,posy+20) 

posx= xOffsetLeft("ancora3") 

posy= xOffsetTop ("ancora3") 

xMoveTo('e3',posx,posy+20) 

posx= xOffsetLeft("ancora4") 

posy= xOffsetTop ("ancora4") 

xMoveTo('e4',posx,posy+20) 

} 

window.onload = function() { 

posiciona() 

} 

window.onresize = function() { 

posiciona() 

} 

function ajaxInit() {

	var xmlhttp;

	try {

		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	} 

	catch (e) {

		try {

		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		} 

		catch (E) {

			xmlhttp = false;

		}

	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined' ) {

		try {

			xmlhttp = new XMLHttpRequest();

		} 

		catch (e) {

			xmlhttp = false ;

		}

	}

	return xmlhttp;

}



function url_encode(str) {

	var hex_chars = "0123456789ABCDEF";

	var noEncode = /^([a-zA-Z0-9\_\-\.])$/;

	var n, strCode, hex1, hex2, strEncode = "";

	for(n = 0; n < str.length; n++) {

		if (noEncode.test(str.charAt(n))) {

			strEncode += str.charAt(n);

		} 

		else {

			strCode = str.charCodeAt(n);

			hex1 = hex_chars.charAt(Math.floor(strCode / 16));

			hex2 = hex_chars.charAt(strCode % 16);

			strEncode += "%" + (hex1 + hex2);

		}

	}

return strEncode;

}



function url_decode(str) {

	var n, strCode, strDecode = "";

	for (n = 0; n < str.length; n++) {

		if (str.charAt(n) == "%") {

			strCode = str.charAt(n + 1) + str.charAt(n + 2);

			strDecode += String.fromCharCode(parseInt(strCode, 16));

			n += 2;

		} 

		else {

			strDecode += str.charAt(n);

		}

	}

return strDecode;

}



function getSecoes(pagina,layer,carregando) {

	if(carregando==1000) {

		document.getElementById(layer).innerHTML = "";

	}

	else {

		document.getElementById(layer).innerHTML = "<img src=\"imagens/loader2.gif\" style=\"padding-top:"+carregando+"px\"><br>carregando</div>";

	}

	ajax = ajaxInit();

	pagina = pagina+"?"+ Math.ceil ( Math.random() * 100000 );

	ajax.open("GET",pagina, true);

	ajax.onreadystatechange = function() {

		if(ajax.readyState == 4 && ajax.status == 200) {

			var resultado = ajax.responseText;

			resultado=resultado.replace(/\+/g," ");

			resultado = unescape(resultado);

			document.getElementById(layer).innerHTML = url_decode(resultado);

		}

	}

	ajax.send(null);

}
