// JavaScript Document
function Ajax(){
	var ajax;
	try {
	  ajax = new XMLHttpRequest();
	} 
	catch (e) {
		try {
		ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try {
			  ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {
			  alert("Seu browser não da suporte à AJAX!");
			  return false;
			}
		}
	}
	return ajax;
}

function Navegador() {
	var caminho = "";
	var navegador = navigator.appVersion;	
	var navegador = navegador.split(" ");
	var tipo   = navegador[2];
	
	if ( tipo == "MSIE" ) {
		var versao = navegador[3];	
		if ( versao == "8.0;" ) {
			caminho = "_ie8";
		}
		if ( versao == "7.0;" ) {
			caminho = "_ie7";
		}
		if ( versao == "6.0;" ) {
			caminho = "_ie6";
		}
	}
	if ( tipo == "U;" ) {
		caminho = "_ch";
	}
	if ( tipo == "pt-BR)" ) {
		caminho = "_ff";
	}
	document.write('<link rel="stylesheet" type="text/css" href="../../style/style'+ caminho + '.css">')
}

function AbreFecha( id ) {
	if ( document.getElementById(id).style.display == "none"  ) {
		document.getElementById(id).style.display = "block";
	}
	else {
		document.getElementById(id).style.display = "none";
	}
}

function TrocaValor ( id, valor ) {
	if ( valor == id ) {
		document.getElementById(id).value = "";		
	}
	if ( valor == "" ) {
		document.getElementById(id).value = id;		
	}
}

function 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 = 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 BotaoAtivo (id, tag, classe) {
	var ArrayTag = document.getElementsByTagName(tag);
	for ( i=0; i < ArrayTag.length; i++) {
		if ( ( ArrayTag[i].className == classe ) || ( ArrayTag[i].className == classe + '_over' ) ) {
			if ( ArrayTag[i].id == id ) {
				if ( ArrayTag[i].className == classe + '_over' ) {
					ArrayTag[i].className = classe;
				}
				else {
					ArrayTag[i].className = classe + '_over';
				}
			}
			else {
				ArrayTag[i].className = classe;
			}
		}
	}
}

function BotaoCheck ( id, classe ) {
	var resultado = classe.indexOf("_over"); 
	if ( Number(resultado) > 0 ) {
		document.getElementById(id).value = 'S';
	}
	else {
		document.getElementById(id).value = 'N';
	}
}

function Balao(id, tag, classe) {
	var ArrayTag = document.getElementsByTagName(tag);
	for ( i=0; i < ArrayTag.length; i++) {
		if ( ( ArrayTag[i].className == classe ) || ( ArrayTag[i].className == classe + '_over' ) ) {
			if ( ArrayTag[i].id == id ) {
				if ( ArrayTag[i].className == classe + '_over' ) {
					//Encolhe(ArrayTag[i].id);
					//ArrayTag[i].className = classe;
				}
				else {
					Expande(ArrayTag[i].id);
					ArrayTag[i].className = classe + '_over';
					
					var BaloesCadastro = document.getElementsByTagName('div');
					
					for ( b=0; b < BaloesCadastro.length; b++) {
						
						if ( BaloesCadastro[b].className == 'balao_cadastro_over' ) {
							Encolhe2(BaloesCadastro[b].id);
						}
					}
				}
			}
			else {
				Encolhe(ArrayTag[i].id);
				ArrayTag[i].className = classe;
			}
		}
	}
}

function BalaoCadastro(id, tag, classe) {
	var ArrayTag = document.getElementsByTagName(tag);
	for ( i=0; i < ArrayTag.length; i++) {
		if ( ( ArrayTag[i].className == classe ) || ( ArrayTag[i].className == classe + '_over' ) ) {
			if ( ArrayTag[i].id == id ) {
				if ( ArrayTag[i].className == classe + '_over' ) {
					//Encolhe(ArrayTag[i].id);
					//ArrayTag[i].className = classe;
				}
				else {
					Expande2(ArrayTag[i].id);
					ArrayTag[i].className = classe + '_over';
				}
			}
			else {
				Encolhe2(ArrayTag[i].id);
				ArrayTag[i].className = classe;
			}
		}
	}
}

function Expande (id) {
	
	var largura = document.getElementById(id).style.width;
		largura = largura.split("p");
		largura = largura[0];

	var altura = document.getElementById(id).style.height;
		altura = altura.split("p");
		altura = altura[0];
		
	if ( Number(largura) < 270  ) {
		var px_largura = Number(largura) + 27;
		var px_altura  = Number(altura) + 14;

		document.getElementById(id).style.width = px_largura + 'px';
		document.getElementById(id).style.height = px_altura + 'px';

		window.setTimeout("Expande('" + id + "')", 1);
	}
}

function Encolhe (id) {

	var largura = document.getElementById(id).style.width;
		largura = largura.split("p");
		largura = largura[0];

	var altura = document.getElementById(id).style.height;
		altura = altura.split("p");
		altura = altura[0];

	if ( Number(largura) >= 27  ) {
		var px_largura = Number(largura) - 27;
		var px_altura  = Number(altura) - 14;

		document.getElementById(id).style.width = px_largura + 'px';
		document.getElementById(id).style.height = px_altura + 'px';

		window.setTimeout("Encolhe('" + id + "')", 1);
	}
}

function Expande2 (id) {
	
	var largura = document.getElementById(id).style.width;
		largura = largura.split("p");
		largura = largura[0];

	var altura = document.getElementById(id).style.height;
		altura = altura.split("p");
		altura = altura[0];
		
	if ( Number(largura) < 270  ) {
		var px_largura = Number(largura) + 27;
		var px_altura  = Number(altura) + 27;

		document.getElementById(id).style.width = px_largura + 'px';
		document.getElementById(id).style.height = px_altura + 'px';

		window.setTimeout("Expande2('" + id + "')", 1);
	}
}

function Encolhe2 (id) {

	var largura = document.getElementById(id).style.width;
		largura = largura.split("p");
		largura = largura[0];

	var altura = document.getElementById(id).style.height;
		altura = altura.split("p");
		altura = altura[0];

	if ( Number(largura) >= 27  ) {
		var px_largura = Number(largura) - 27;
		var px_altura  = Number(altura) - 27;

		document.getElementById(id).style.width = px_largura + 'px';
		document.getElementById(id).style.height = px_altura + 'px';

		window.setTimeout("Encolhe2('" + id + "')", 1);
	}
}

var selectId     = "";
var selectAtivo  = "";
var selectAltura = "";

function SelExp( id, fim, mais ) {
	document.getElementById(id).style.visibility = "visible";
	var altura = document.getElementById(id).style.height;
		altura = altura.split("p");
		altura = altura[0];
	if ( Number(altura) < Number(fim) ) {
		var px_altura  = Number(altura) + Number(mais);
		document.getElementById(id).style.height = px_altura + 'px';
		window.setTimeout("SelExp('" + id +"', '" + fim +"', '" + mais +"')", 1);
	}
	if ( Number(altura) == Number(fim) ) {
		selectAltura = Number(fim);
		selectAtivo  = "S";
		selectId  = id;
	}
}

function SelEnc( id, menos ) {
	var altura = document.getElementById(id).style.height;
		altura = altura.split("p");
		altura = altura[0];
	if ( Number(altura) > 1  ) {
		var px_altura  = Number(altura) - Number(menos);
		document.getElementById(id).style.height = px_altura + 'px';
		window.setTimeout("SelEnc('" + id + "', " + menos + ")", 1);
	}
	if ( Number(altura) == 0  ) {
		selectAtivo = "";
		selectAltura = "";
		document.getElementById(id).style.visibility = "hidden";
	}
}

window.onload=function() { 
	elementos = document.body.getElementsByTagName('*'); 
	for( i = 0; i < elementos.length; i++) { 
		if ( elementos[i].onclick == undefined ){
			elementos[i].onclick = function () {
				if ( this.tagName == 'LI') {
					if ( this.className == 'opcao_ativa' ) {
						Id = 'lista_' + this.title;
						var title = document.getElementById(Id).title;	
						var	title = title.split("_");
						var	fim   = title[0];
						var	mais  = title[1];

						if ( selectAtivo == "S"){
							SelExp(Id, fim, mais);
							SelEnc(selectId, mais);
						}
						if ( selectAtivo == ""){
							SelExp(Id, fim, mais);
						}
					}
					if ( this.className == 'li_op' ) {
						document.getElementById('ativa_' + this.title).innerHTML = this.innerHTML;
						document.getElementById('valor_' + this.title).value = this.id;
						selectId = 'lista_' + this.title;
						selectAtivo = "";
						var title = document.getElementById(selectId).title;	
						var	title = title.split("_");
						var	menos = title[1];
						
						if ( selectAltura != "" ) {	
							SelEnc(selectId, menos);
						}
					}
				}
				else {
					if ( selectAtivo == 'S' ) {
						if ( selectAltura != '' ) {
							var title = document.getElementById(selectId).title;	
							var	title = title.split("_");
							var	menos = title[1];
							selectAtivo = "";
							SelEnc(selectId, menos);
						}
					}
				}
			}
		}
	} 
}

function Resize() {
	var largura = document.body.clientWidth;
	var navegador = navigator.appVersion;
	var navegador = navegador.split(" ");
	var tipo   = navegador[2];
	if ( tipo == "MSIE" ) {
		var versao = navegador[3];
		if ( versao == "6.0;" ) {
			if ( largura < 784 ) {
				document.getElementById('geral').style.width = '783px';
			}
			else {
				document.getElementById('geral').style.width = '';
			}
		}
	}
}

$(document).ready(function() {
  var browser = navigator.userAgent;
  if(browser.indexOf('AppleWebKit') >= 0) {
	  if($('.conteudo').children('.left').html() != null && $('.conteudo').children('.left').html() != undefined) {
		  $('.left').eq(2).width('311');
	  }
  }
});

