/*
FORMULRIO DE LOGIN
*/

function js_start(){
	startList(); // Hack para ie6 do menu drop down
	getTooltip(); // inicia o processo sobre as tooltips (getTooltip.js e MouseCoord.js necessrios)
	oquevcprecisa(); // inicia a navegao do item "o que voc precsia" no menu institucional
	openExternalPages(); //Abre todas as pginas setadas como externas em novas janelas e pop-ups
	lowprofile();
	cidadesDC('noBrasil');//Controla a exibição de cidades DC
	
	/*
	area_cliente_login = document.getElementById('area_cliente_login').value;
	area_cliente_senha = document.getElementById('area_cliente_senha').value;
	navegacao_senha = document.getElementById('navegacao_senha').value;
	
	if(area_cliente_login==''){
		document.getElementById('area_cliente_login').value = 'login';
	}
	if(area_cliente_senha==''){
		document.getElementById('area_cliente_senha').value = 'senha';
	}
	if(navegacao_senha==''){
		document.getElementById('navegacao_senha').value = 'sua senha';
	}
	*/
}

/*
START (para pginas externas e popups)
*/
function start(){
	window.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
	window.document.write('<html xmlns="http://www.w3.org/1999/xhtml">')
	window.document.write('<head>');
	window.document.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
	window.document.write('<title>DirectCall</title>');
	window.document.write('<script language="javascript" src="../js/AC_RunActiveContent.js"></script>');
	window.document.write('<script language="javascript" src="../js/MouseCoord.js"></script>')
	window.document.write('<script language="javascript" src="../js/getTooltip.js"></script>')
	window.document.write('</head>');
	window.document.write('<body onload="js_start()">');
}

/*
STOP (para pginas externas e popups)
*/
function stop(){
	window.document.write('</body>');
	window.document.write('</html>');
}

/*
HACK PARA IE6 DO MENU DROPDOWN
Agradecimentos a Maurcio Sami Silva (www.maujor.com.br)
*/

function startList() {
	if (document.all&&document.getElementById)
	{
		navRoot = document.getElementById("institucional");
		if(navRoot){
			for (i=0; i<navRoot.childNodes.length; i++)
			{
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI")
				{
					node.onmouseover=function()
					{
						this.className+=" over";
					}
					node.onmouseout=function()
					{
					this.className=this.className.replace
					(" over", "");
					}
				}
			}
		}
	}
}

/*
PGINAS EXTERNAS
*/

function openExternalPages(){
	var links = document.getElementsByTagName("A");
	
	for(a=0; a<links.length; a++){
		var href = links[a].getAttribute("href").split('.com.br/');
		//href = href[1];		
		if(href[1]=='cidades'){
			links[a].onclick=function(){
				//popup('http://www.directcall.com.br/cidades/1',795,600);
				popup('http://www.signallink.com.br/cidades',850,550)
				return false;
			}
		}
	}
	
	for(a=0; a<links.length; a++){
		if(links[a].getAttribute('rel')){
			
			switch(links[a].getAttribute('rel')){
				case 'popup':
				case '_popup':
					links[a].setAttribute('title','Este link abrirá um pop-up');
					links[a].onclick = function(){
						popup(this.getAttribute('href'),850,550);
						return false;
					}
					break;
				
				case 'blank':
				case '_blank':
					links[a].setAttribute('title','Este link abrirá uma nova janela');
					links[a].onclick = function(){
						window.open(this.getAttribute('href'));
						return false;
					}
					break;
				
				case '0800web':
				case '_0800web':
				case '0800ip':
				case '_0800ip':
					links[a].setAttribute('title','Este link abrirá o 0800 IP');
					links[a].onclick = function(){
						popup(this.getAttribute('href'),690,410);
						return false;
					}
					break;
					
				case 'dcsoft':
				case '_dcsoft':
				case 'softweb':
				case '_softweb':
					links[a].setAttribute('title','Este link abrirá o DirectCall SoftWeb');
					links[a].onclick = function(){
						popup(this.getAttribute('href'),785,535);
						return false;
					}
					break;
					
				case 'parent':
				case '_parent':
					links[a].setAttribute('title','Este link abrirá a página na janela anterior');
					links[a].onclick = function(){
						window.opener.location.href = this.getAttribute('href');
						return false;
					}
					break;
			}
		}
	}
}

/*
POP-UPS
*/

function popup(url,w,h){
	var screenW = screen.width;
	var screenH = screen.height;
	var left = (screenW-w)/2;
	var top = (screenH-h)/2;
	window.open(url,'popup', 'width='+w+', height='+h+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}


function janelaDirectCallSoft (URL){
   window.open(URL,"janela1","width=800,height=520,scrollbars=NO")
}

/*
MUDA A CLASSE DE DE DETERMINADO ELEMENTO BASEADO NO SEU ID
*/
function muda_classe(origem,destino){
	document.getElementById(origem).className=destino;
}

/*
EXIBE UM ELEMENTO BASEADO EM SEU ID
*/

function show(id){
	document.getElementById(id).style.display = 'block';
}

/*
ESCONDE UM ELEMENTO BASEADO EM SEU ID
*/

function hide(id){
	document.getElementById(id).style.display = 'none';
}

/*
ESCONDE OU EXIBE UM ELEMENTO BASEADO EM SEU ID E ESTADO
*/
function show_hide(id){
	var elemento = document.getElementById(id);
	if(elemento){
		if(!elemento.style.display || elemento.style.display=='none'){
			elemento.style.display = 'block';
		}else{
			elemento.style.display = 'none';
		}
	}
}

/*
MUDA O ID DE DE DETERMINADO ELEMENTO
*/
function mudaId(origem,destino){
	document.getElementById(origem).id=destino;
}

/*
MUDA A CLASSE DE UM ELEMENTO BASEADO EM SEU ID
*/
function mudaClasse(id,classe){
	var elemento = document.getElementById(id);
	if(elemento.className != classe){
		elemento.className = classe;
	}else{
		elemento.className = '';
	}
}

/*
FAZ A NAVEGAO DO TEM "O QUE VOC PRECISA"
*/

function oquevcprecisa(){
	var browser = navigator.appName;
	var r = document.getElementById('oquevcprecisa_menu');  
	var retorno = document.getElementById('conteudo');
	if(r){
		
		var rs = r.childNodes;
		
		function limpaLinhas(){
			for(i=0; i<rs.length; i++){
				if(rs[i].tagName=='LI'){
					rs[i].childNodes[2].style.display = 'none';
					rs[i].childNodes[0].className = '';
				}
			}
		}
		
		for(a=0; a<rs.length; a++){
			if(rs[a].tagName=='LI'){
				var ul = rs[a].childNodes[2];
				ul.id = 'ul'+a;
				ul.style.display = 'none';
				var aLink = rs[a].childNodes[0];
				aLink.id = 'alink'+a;
				aLink.onclick = function(){
					limpaLinhas();
					var href = this.id;
					href = 'ul'+href.replace('alink','');
					show_hide(href);
					//mudaClasse(href,'aberto');
					return false;
				}
			}
		}
		
		retorno.onmouseover = function(){
			limpaLinhas();
		}
	}
}

/*function oqvcprecisa(){
	
	var oqvcp = document.getElementsByClassName('oquevcprecisa');
	if(oqvcp){ alert(oqvcp.length); }
	remove = function(){
		$(".oquevcprecisa_menu ul").css("display","none");
		$(".oquevcprecisa_menu .aberto").removeClass('aberto');
	}
	
	$("#conteudo").mouseover( function(){
		remove();
	});
	
	$("#institucional .oquevcprecisa_menu .linha").children().click( function(){ 
		if(this.tagName=='A'){
			remove();
			$(this).addClass('aberto');
			$(this).parent().find("ul").css("display","block");
			return false;
		}
	});
	
	$("#navegacao .linha .aberto").css("color","#990000");
	$("#navegacao .linha .aberto").css("font-weight","bold");
	$("#navegacao .linha .aberto .normal").css("font-weight","bold");
	$("#navegacao .linha .aberto .bullet").css("display","inline");
	
	remove();
}*/



/*
ABRE AS ABAS DO FAQ (PERGUNGAS FREQUENTES);
*/
function faq(categoria, pagina){
	document.getElementById('cat0').className = '';
	document.getElementById('cat1').className = '';
	document.getElementById('cat2').className = '';
	document.getElementById('cat3').className = '';
	document.getElementById(categoria).className = 'aberto';
	
	document.getElementById('oquee').className = 'faq';
	document.getElementById('operacionais').className = 'faq';
	document.getElementById('mobilidade').className = 'faq';
	document.getElementById('gerais').className = 'faq';
	document.getElementById(pagina).className = 'faq aberto';
	
	//faq_pergunta('');
	return false;
}

/*
ABRE AS PERGUNTAS DO FAQ (PERGUNGAS FREQUENTES)
*/
function faq_pergunta(abre){
	var p = document.getElementById(abre);
	
	if(p){
		if(p.className!='aberto'){
			p.className = 'aberto';
		}else{
			p.className = '';
		}
	}
}


/*
INJETA UM VALOR EM DETERMINADO ELEMENTO
*/
function set_value(elemento,inicial,final){
	v = document.getElementById(elemento);
	if(v.value == ''){
		v.value = final;
	}
	if(v.value == inicial){
		v.value = final;
	}
}

/* CONTROLA A PGINA DE VERSES */

function versoes(versao){
	document.getElementById("tradicional").style.display = 'none';
	document.getElementById("ver_tradicional").className = '';
	document.getElementById("gateway").style.display = 'none';
	document.getElementById("ver_gateway").className = '';
	document.getElementById("ip").style.display = 'none';
	document.getElementById("ver_ip").className = '';
	
	var aba = "ver_"+versao;
	
	document.getElementById(versao).style.display = 'block';
	document.getElementById(aba).className = 'aberto';
	

}

/* MENU DE ESTADOS DO BRASIL */
function estados(){
	var e = document.getElementById('estados');
	for(a=0; a<e.childNodes.length; a++){
		if(e.childNodes[a].tagName=='LI'){
			if(e.childNodes[a].childNodes[0].tagName=='A'){
				var tabelas = e.childNodes[a].childNodes[0].getAttribute("href",2);
				tabelas = tabelas.replace(/#/,'');
				show_hide(tabelas);
				show_hide(tabelas);
				e.childNodes[a].childNodes[0].onclick = function(){
					var link = this.getAttribute("href",2);
					link = link.replace(/#/,'');
					show_hide(link);
					return false;
				}
			}
		}
	}
}

/**/
function show_paises(){
	document.write('<p><a href="#ramalGlobal_testeJa" onclick="hide(\'ramalGlobal_testeJa\'); show(\'ramalGlobal_testeJa_abrir\'); return false">Fechar</a></p>');
}

function hide_paises(){
	document.write('<p><a href="#paises" onclick="hide(\'paises\'); return false">Fechar</a></p>');
}

function show_teste(){
	document.write('<p id="ramalGlobal_testeJa_abrir"><a href="#ramalGlobal_testeJa" onclick="show_hide(\'ramalGlobal_testeJa\'); hide(\'ramalGlobal_testeJa_abrir\'); return false">Clique aqui, teste já!</a></p>');
}

/* CIDADES DC */

function cidadesDC(exibir){
	noBr = document.getElementById('noBrasil');
	noEx = document.getElementById('noExterior');
	exi = document.getElementById(exibir);
	if(noBr){ noBr.style.display = 'none'; }
	if(noEx){ noEx.style.display = 'none'; }
	if(exi){ exi.style.display = 'block'; }
		
	if(document.getElementById('exibirNoBrasil')){
		document.getElementById('exibirNoBrasil').onclick = function(){
			cidadesDC('noBrasil');
			document.getElementById('exibirNoExterior').className = '';
			document.getElementById('exibirNoBrasil').className = 'aberto';
			return false;
		}
	}
	
	if(document.getElementById('exibirNoExterior')){
		document.getElementById('exibirNoExterior').onclick = function(){
			cidadesDC('noExterior');
			document.getElementById('exibirNoExterior').className = 'aberto';
			document.getElementById('exibirNoBrasil').className = '';
			//var paises = document.getElementById('noExterior').childNodes[1];
			var paises = document.getElementById('noExterior').childNodes[0];
			for(a=0; a<paises.childNodes.length; a++){
				var pais = paises.childNodes[a].childNodes[0];
				pais.onclick = function(){
					var abra = this.getAttribute("href").split('#');
					abra = abra[1];
					show_hide(abra);
					return false;
				}
				var cidades = paises.childNodes[a].childNodes[1];
				cidades.style.display = 'none';
			}
			return false;
		}
	}
}

function lowprofile(){
	var html = document.getElementsByTagName("html");
	var s = parseInt(html[0].offsetWidth);
	if(s<=800){
		document.getElementById("lowProfile").style.width = '1000px';
	}
}

