/*Ajax- Conex*/
ulist = [];
list = [];
ilist=0;
iulist=0;
var li2 = null;
var li3 = null;

function createRequestObject() {
	try{
		cuca = new XMLHttpRequest();
	}catch(ee){
		try{
			cuca = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				cuca = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				cuca = false;
			}
		}
	}
	try{
		cuca2 = new XMLHttpRequest();
	}catch(ee){
		try{
			cuca2 = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				cuca2 = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				cuca2 = false;
			}
		}
	}
	try{
		cuca3 = new XMLHttpRequest();
	}catch(ee){
		try{
			cuca3 = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				cuca3 = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				cuca3 = false;
			}
		}
	}
	try{
		cuca4 = new XMLHttpRequest();
	}catch(ee){
		try{
			cuca4 = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				cuca4 = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				cuca4 = false;
			}
		}
	}
	
}

var cuca = createRequestObject();
var cuca2 = createRequestObject();
var cuca3 = createRequestObject();
var cuca4 = createRequestObject();

/*FIM Ajax- Conex*/
///////////////////////////////
function formReset(){
	document.forms[0].reset();
}

///////////////////////////////////////////////////////////

function noticias(lang){
    cuca.open("POST", "pag/noticias2.php", true);
	post = "lang=" + lang;
    cuca.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	cuca.onreadystatechange = function(){
	    if(cuca.readyState < 4){
	    document.getElementById('conteudo').innerHTML="Aguarde...<img src='images/spinner_gray.gif' border='0' />";
		}
		if(cuca.readyState == 4){
			var resposta = cuca.responseText;
				document.getElementById('conteudo').innerHTML = resposta;
		}		
		//linksub85
	}
    hideList();
	hideMenu();
	
	if(lang=='pt_br') { 
		colorMenu(1);
		document.getElementById('linksub85').style.backgroundColor = '#FFCC00';
		list += "85;";
	} else {
		colorMenu(519);
		document.getElementById('linksub487').style.backgroundColor = '#FFCC00';
		list += "487;";
	}
	
	ilist++;
	cuca.send(post);		

}

function agend(lang){
    cuca.open("POST", "pag/agenda2.php", true);
	post = "lang=" + lang;
    cuca.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	cuca.onreadystatechange = function(){
	    if(cuca.readyState < 4){
	    document.getElementById('conteudo').innerHTML="Aguarde...<img src='images/spinner_gray.gif' border='0' />";
		}
		if(cuca.readyState == 4){
			var resposta = cuca.responseText;
				document.getElementById('conteudo').innerHTML = resposta;
		}		
	}
    hideList();
	hideMenu();
	colorMenu(1);
	document.getElementById('linksub86').style.backgroundColor = '#FFCC00';
	list += "86;";
	ilist++;
	cuca.send(post);		
}

var local = '';

// se a função history tiver sido chamada pelo evento acima (setinterval), chama o renderFromMenu que
// faz a página voltar para a última, caso contrário, grava o local atual...
function history(fromRender){
    localAtual = top.location;
    localAtual = localAtual.toString()
    localAtual = localAtual.split("#");
    localAtual = localAtual[1];
	
	if (fromRender){
        local = localAtual;
    }else if (local != localAtual){
		if(Number(localAtual)){
			sndReq(localAtual);

		}else if(localAtual == "home"){
			home();
		}
        local = localAtual;
    }
}

setInterval("history(0)",100);



function sndReq(id) {
	//colorMenu(id);
		history(id);
		top.location = "#"+id;

	if(Number(id)){
		document.getElementById('cont').src = "pag.php?pag_id="+id+"&ulist="+ulist+"&list="+list+"&ilist="+ilist+"&iulist="+iulist;

//	ajaxHTML('conteudo','pag/pags.php',id);
	}else{
		if(id == "contato"){
			Forms(id);
		}else if(id == "suporte"){
			Forms(id)	
		}else if(id == "treinamento"){
			Forms(id)	
		}else if(id == "parceria"){
			Forms(id)	
		}else if(id == "imprensa"){
			Forms(id)	
		}else if(id == "trabalhe"){
			Forms(id)	
		}else{
			eval(id);
		}
		
	}	
	document.getElementById('conteudo').style.backgroundColor='#ffffff'; 
	hideFlash();

}

function hideList(){
	if(ilist != 0){
			var s = list.split(";");
			total = s.length - 1;
			for(j=0;j<total;j++){
				document.getElementById('linksub'+s[j]).style.backgroundColor="#FFEEA8";
				teste = document.getElementById('sub'+s[j]);
				if(teste != null){
					teste.style.display = "none";
				}				
			}
	}
}
function hideMenu(id){
	if(iulist != 0){
		var m = ulist.split(";");
		total = m.length - 1;
		for(x=0;x<total;x++){
			var find = document.getElementById('sub'+m[x]);
			if(find != null){
				find.style.display = "none";
			}
			document.getElementById(m[x]).style.backgroundColor="";
			document.getElementById('link'+m[x]).style.color="#142B6D";			
		}
	}
}
function colorMenu(id){
    hideList();
	hideMenu();
	cuca3.open("POST", "pag/color_menu.php", true);
	post = "id=" + id;
    cuca3.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	cuca3.onreadystatechange = function(){
		if(cuca3.readyState == 4){
			var respost = cuca3.responseText;
			var resposta = cuca3.responseText.split(";");
			total = resposta.length;
			for(i=0;i<total;i++){
				var sub = document.getElementById('sub'+resposta[i]);
				if(sub != null){
					sub.style.display = "";
				}
				var menu = document.getElementById(resposta[i]);
				if(menu != null){
					menu.style.backgroundColor="#142B6D";
					document.getElementById('link'+resposta[i]).style.color="#ffffff";
					if(iulist != null){
						ulist += resposta[i]+";";
						iulist++;
					}
				}
				var submenu = document.getElementById('linksub'+resposta[i]);
				if(submenu != null){
					submenu.style.backgroundColor = '#FFCC00';
					if(list != null){
						list += resposta[i]+";";
						ilist++;
					}	
				}
			}
		}	
	};
    cuca3.send(post);
}


///////////////////////////////////////////////////////////

function showSub(valor){
	cuca.open("POST", "pag/select_submenu2.php", true);
	post = "id=" + valor;
    cuca.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 	
	cuca.onreadystatechange = ResponseSub;
	cuca.send(post);
}

function ResponseSub(){
	var campo_select = document.forms[0].elements['subMenu2']; 

  if (cuca.readyState == 4) {
    campo_select.options.length = 0;
    results = cuca.responseText.split(",");
	total = results.length-1

    for( i = 0; i < total; i++ )
    { 
      string = results[i].split( "|" );
      campo_select.options[i] = new Option( string[0], string[1] );
    }
  }
}



function showSub2(valor){
	cuca.open("POST", "pag/select_submenu3.php", true);
	post = "id=" + valor;
    cuca.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 	
	cuca.onreadystatechange = ResponseSub2;
	cuca.send(post);
}

function ResponseSub2(){
	var campo_select = document.forms[0].elements['subMenu3']; 

  if (cuca.readyState == 4) {
    campo_select.options.length = 0;
    results = cuca.responseText.split(",");
	total = results.length-1

    for( i = 0; i < total; i++ )
    { 
      string = results[i].split( "|" );
      campo_select.options[i] = new Option( string[0], string[1] );
    }
  }
}

try{
xmlhttp = new XMLHttpRequest();
}catch(ee){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){
xmlhttp = false;
}
}
}

fila=[];
ifila=0;

function ajaxHTML(id,url,id_pag){
	document.getElementById(id).innerHTML="<span class='carregando'><img src='images/spinner_gray.gif' border='0' />"+"Carregando...</span>";
	//Adiciona à fila
	fila[fila.length]=[id,url,id_pag]
	//Se não há conexões pendentes, executa
	if((ifila+1)==fila.length)ajaxRun()
}

function ajaxRun(){
	//Abre a conexão
	xmlhttp.open("POST",fila[ifila][1],true);
	post = "pag_id=" + fila[ifila][2];
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	//Função para tratamento do retorno
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4){
		retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
		document.getElementById(fila[ifila][0]).innerHTML=retorno
	//Roda o próximo
	ifila++
		if(ifila<fila.length)setTimeout("ajaxRun()",20)
		}
	}
//Executa
xmlhttp.send(post);
}

/////////////////////////////////////
/*Ajax- Change page*/

function handleResponse() {
	//document.getElementById('conteudo').style.backgroundColor = "#FFFFFF";
    if(cuca.readyState < 4){
	    document.getElementById('conteudo').innerHTML=
		"<span><img src='images/spinner_gray.gif' border='0' />Aguarde...</span>";
	}
    if(cuca.readyState == 4){
        var resposta = cuca.responseText;
            document.getElementById('conteudo').innerHTML = resposta;
	}
}
/*FIM Ajax- Change page*/
function linkEx(link,janela){
	window.open(link,"" + janela + "","");
}

function contColor(){
	var cont = document.getElementById('conteudo').style.backgroundColor = "#FFFFFF";	
}

function contColorHome(){
	var cont = document.getElementById('conteudo').style.backgroundColor = "";		
}

function contato(){
//	Forms("contato","pt_br");
	Forms("contato","' + lang + '");
}

function suporte(){
//	Forms("suporte","pt_br");
	Forms("suporte","' + lang + '");
}

function treinamento(){
//	Forms("treinamento","pt_br");
	Forms("treinamento","' + lang + '");
}

function parceria(){
//	Forms("parceria","pt_br");
	Forms("parceria","' + lang + '");
}

function imprensa(){
//	Forms("imprensa","pt_br");
	Forms("imprensa","' + lang + '");
}

function trabalhe(){
//	Forms("trabalhe","pt_br");
	Forms("trabalhe","' + lang + '");
}


function Forms(src,lang){
	var cont = document.getElementById('conteudo');
	if(src == "contato"){
		f = 'Forms("contato");';		
	}
	if(src == "suporte"){
		f = 'Forms("suporte");';			
	}
	if(src == "treinamento"){
		f = 'Forms("treinamento");';			
	}
	if(src == "parceria"){
		f = 'Forms("parceria");';			
	}
	if(src == "imprensa"){
		f = 'Forms("imprensa");';			
	}
	if(src == "trabalhe"){
		f = 'Forms("trabalhe");';			
	}
	
	colorMenu(f);
	cont.innerHTML = "<iframe id='Upload' marginheight='0' marginwidth='0' scrolling='no' width='100%' height='800' src='pag/forms.php?src="+ src +"&lang="+ lang +"' frameborder='0' style='background-color:#F0F0F0;'></iframe>";	

}

function limpa(){
	var pes = document.getElementById('pesquisa').value;
	var pesq = document.getElementById('pesq_var').value = pes;
	var pesd = document.getElementById('pesquisa').value = "";
}

function pesquisa(lang,pag){
	var pesq_var = document.getElementById('pesq_var').value;
	if(pesq_var == 0){
		var pes = document.getElementById('pesquisa').value;
		limpa();
	}else{
		var pes = pesq_var;
	}
	var camp = document.getElementById('campo').value;	

    cuca.open("POST", "pag/pesq.php", true);
	post = "pes=" + pes + "&camp=" + camp + "&lang=" + lang + "&pagina=" + pag;
    cuca.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	cuca.onreadystatechange = function(){
	    if(cuca.readyState < 4){
	    document.getElementById('conteudo').innerHTML=
		"<span>Aguarde...<img src='images/spinner_gray.gif' border='0' /></span>";
	}
    if(cuca.readyState == 4){
        var resposta = cuca.responseText;
            document.getElementById('conteudo').innerHTML = resposta;
		
	}		
	}
    cuca.send(post);
}

function flash(lang){
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="946" height="174" id="index2" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="flash/index2.swf?lang='+lang+'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="wmode" value="opaque" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<embed src="flash/index2.swf?lang='+lang+'" wmode="opaque" quality="high" bgcolor="#ffffff" width="946" height="174" name="index2" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');	
}
//////////////////////////

	function stAba(menu,conteudo)
	{
		this.menu = menu;
		this.conteudo = conteudo;
	}

	var arAbas = new Array();
	arAbas[0] = new stAba('td_cadastro','div_cadastro');
	arAbas[1] = new stAba('td_consulta','div_consulta');
	arAbas[2] = new stAba('td_manutencao','div_manutencao');

	function AlternarAbas(menu,conteudo)
	{
		for (i=0;i<arAbas.length;i++)
		{
			m = document.getElementById(arAbas[i].menu);
			m.className = 'menu2';
			c = document.getElementById(arAbas[i].conteudo)
			c.style.display = 'none';
		}
		m = document.getElementById(menu)
		m.className = 'menu-sel';
		c = document.getElementById(conteudo)
		c.style.display = '';
	}
