// JavaScript Document

function data()
{
dia = new Date();
ano = dia.getYear();
if (ano < 2000)
  {
  ano = 1900 + dia.getYear();
  }
mes = new Array("Janeiro","Fevereiro","Mar&ccedil;o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")
dia_semana = new Array("Domingo","Segunda-feira","Ter&ccedil;a-feira","Quarta-feira","Quinta-feira","Sexta-feira","S&aacute;bado");
hora = dia.getHours();
if (hora < 10)
  {
  hora = "0" + hora;
  }

minuto = dia.getMinutes();
if (minuto < 10)
  {
  minuto = "0" + minuto;
  }
document.writeln(dia_semana[dia.getDay()] + ", " + dia.getDate() + " de " +  mes[dia.getMonth()] + " de " + ano);
}

function associese()
{
	alert("Este arquivo está disponível somente para os associados do Sinduscon. \n Veja a seguir as vantagens de ser um associado.");
	location.href = 'associe-se.php?associe=1';
}

function menu(item)
{
	var div=document.getElementById('submenu'+item);
	var filhos=document.getElementById('menu_esquerda').getElementsByTagName('div');
	var menu=document.getElementById('menu'+item);
	var filhos2=document.getElementById('menu_esquerda').getElementsByTagName('a');
	next = parseInt(item)+1
	if (div == null)
	{
		for (i=0;i<filhos.length;i++)
		{
			if (filhos[i].className=='submenu2')
			{
				filhos[i].style.display='none';
			}
		}
		for (f=0;f<filhos2.length;f++)
		{
			if (filhos2[f].className=='menuprincipal')
			{
				filhos2[f].style.borderTop='none';
				filhos2[f].style.borderBottom='1px solid #cfcfcf';
			}
		}
	}
	else if (div.style.display=='none')
	{
		for (i=0;i<filhos.length;i++)
		{
			if (filhos[i].className=='submenu2')
			{
				filhos[i].style.display='none';
			}
		}
		for (f=0;f<filhos2.length;f++)
		{
			if (filhos2[f].className=='menuprincipal')
			{
				filhos2[f].style.borderTop='none';
				filhos2[f].style.borderBottom='1px solid #cfcfcf';
			}
		}
		document.getElementById('menu'+next).style.borderTop='1px solid #cfcfcf';
		menu.style.borderBottom='none';
		div.style.display='block';
	}
	else if (div.style.display=='block') 
	{
		document.getElementById('menu'+next).style.borderTop='none';
		menu.style.borderBottom='1px solid #cfcfcf';
		div.style.display='none';
	}
}

function publicacoes(id,pag)
{
	postPage('publicacoes','id='+id,'replaceInnerHTML','meio');
}
function publicacao(id)
{
	postPage('publicacoes','id='+id,'replaceInnerHTML','meio');
}

function paginaPublicacoes(pag)
{
	//replaceInnerHTML(html, 'meio');
	postPage('publicacoesdir', 'pagina='+pag, 'replaceInnerHTML', 'direita' );
}

function opcao(item)
{
	postPage(item,'','returnFromOpcao', item);
}
function returnFromOpcao(html, item)
{
	replaceInnerHTML(html, 'meio');
	if ( item=='artigos' ||
		 item=='assessoria_economica' ||
		 item=='assessoria_juridica' ||
		 item=='assessoria_tecnica' ||
		 item=='banco_de_dados' ||
		 item=='boletins' ||
		 item=='capacitacao_home' ||
		 item=='convencoes' ||
		 item=='editais' ||
		 item=='eventos' ||
		 item=='imprensa' ||
		 item=='noticias' ||
		 item=='pbqp' ||
		 item=='publicacoes' ||
		 item=='assessoria_comunicacao' ||
		 item=='cub_home' ||
		 item=='over_cdi'
		)
	{
		if (item == 'over_cdi')
		{
			item = 'assessoria_economica';
		}
		postPage(item+'dir', '', 'replaceInnerHTML', 'direita' );
	}
	else if (item=='associe-se_vantagens' || item=='associe-se_diferencas')
	{
		postPage('associe-sedir', '', 'replaceInnerHTML', 'direita' );
	}
	else if (item == 'assessoria_tecnica_videos')
	{
		postPage('assessoria_tecnicadir', '', 'replaceInnerHTML', 'direita' );
	}
	else
	{
		postPage('conteudodir', '', 'replaceInnerHTML', 'direita' );
	}
}
/****************************************************
 * 
 * 			S	S	D	S
 * 
 ****************************************************/
function associe(item)
{
 	postPage(item,'', 'returnFromAssocie' ,'');
}
function returnFromAssocie(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('associe-sedir', '', 'replaceInnerHTML', 'direita' );
}
function artigo(id)
{
 	postPage('artigos', 'id='+id, 'returnFromArtigo' ,'');
}
function assessoria_juridica(nome)
{
 	postPage('assessoria_juridica_'+nome, '', 'replaceInnerHTML' ,'meio');
}
function returnFromArtigo(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('artigosdir', '', 'replaceInnerHTML', 'direita' );
}
function boletim( id,area)
{
	postPage('boletins', 'id='+id+'&area='+area, 'returnFromBoletim',area);
}
function returnFromBoletim(html,area)
{
 	replaceInnerHTML(html, 'meio');
	postPage('boletinsdir', 'area='+area, 'replaceInnerHTML', 'direita' );
}
function calendario( id)
{
	postPage('calendario', 'id='+id, 'returnFromCalendario','');
}
function returnFromCalendario(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('calendariodir', '', 'replaceInnerHTML', 'direita' );
}

function circular( id)
{
	postPage('circular', 'id='+id, 'returnFromCircular','');
}
function returnFromCircular(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('circulardir', '', 'replaceInnerHTML', 'direita' );
}


function pesquisa( id)
{
	postPage('pesquisa', 'id='+id, 'returnFromPesquisa','');
}
function returnFromPesquisa(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('conteudodir', '', 'replaceInnerHTML', 'direita' );
}

function kit_2009( id)
{
	postPage('kit_2009', 'id='+id, 'returnFromKit_2009','');
}
function returnFromKit_2009(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('conteudodir', '', 'replaceInnerHTML', 'direita' );
}



function decreto_ipi( id)
{
	postPage('decreto_ipi', 'id='+id, 'returnFromDecretoIpi','');
}
function returnFromDecretoIpi(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('conteudodir', '', 'replaceInnerHTML', 'direita' );
}


function mp459( id)
{
	postPage('mp459', 'id='+id, 'returnFromMP459','');
}
function returnFromMP459(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('conteudodir', '', 'replaceInnerHTML', 'direita' );
}




function capacitacao(nome)
{
	postPage('capacitacao_'+nome,'', 'replaceInnerHTML', 'meio');
}
function cub(nome)
{
	postPage('cub_'+nome,'', 'replaceInnerHTML', 'meio');
}
function convencoes(id)
{
	postPage('convencoes', 'id_ano='+id, 'returnFromConvencoes','');
}
function returnFromConvencoes(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('convencoesdir', '', 'replaceInnerHTML', 'direita' );
}
function edital( id)
{
 	postPage('editais', 'id='+id, 'returnFromEdital','meio');
}
function returnFromEdital(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('editaisdir', '', 'replaceInnerHTML', 'direita' );
}
function eventos(id)
{
	postPage('eventos', 'id='+id, 'returnFromEventos','');
}
function returnFromEventos(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('eventosdir', '', 'replaceInnerHTML', 'direita' );
}
function noticia(id)
{
	postPage('noticias', 'id='+id, 'returnFromNoticia','');
}

function clipping(id)
{
	postPage('clipping', 'id='+id, 'returnFromNoticia','');
}

function returnFromNoticia(html)
{
 	replaceInnerHTML(html, 'meio');
	postPage('noticiasdir', '', 'replaceInnerHTML', 'direita' );
}
 function release(id)
 {
	postPage('imprensa', 'id='+id, 'replaceInnerHTML','meio');
 }
 function passapagina(modulo, tipo, prioridade, pagina, publicacao)
 {
 	postPage(modulo, 'action=paginacao&tipo='+tipo+'&prioridade='+prioridade+'&pagina='+pagina+'&publicacao='+publicacao, 'returnFromPassaPagina', modulo);
 }
 
 function returnFromPassaPagina(html, item){
 	replaceInnerHTML(html, 'meio');
 	if (item == 'artigos' ||
 	item == 'assessoria_economica' ||
 	item == 'assessoria_juridica' ||
 	item == 'assessoria_tecnica' ||
 	//item == 'banco_de_dados' ||
 	item == 'boletins' ||
 	item == 'capacitacao_home' ||
 	item == 'convencoes' ||
 	item == 'editais' ||
 	item == 'eventos' ||
 	item == 'imprensa' ||
 	item == 'noticias' ||
 	item == 'pbqp' ||
 	item == 'publicacoes' ||
 	item == 'assessoria_comunicacao' ||
 	item == 'cub_home' ||
 	item == 'over_cdi') {
 		if (item == 'over_cdi') {
 			item = 'assessoria_economica';
 		}
 		postPage(item + 'dir', '', 'replaceInnerHTML', 'direita');
 	}
 }	
 function pagina_assoc(letra, pagina)
 {
 	postPage('associadosdir', '', 'replaceInnerHTML','direita');
	postPage('associados', 'action=paginacao&letra='+letra+'&pagina='+pagina, 'replaceInnerHTML','meio');
 }
 function pbqp(nome)
 {
 	postPage(nome,'', 'replaceInnerHTML', 'meio');
 }
 function pbqp_noticia(id)
 {
 	postPage('pbqp_noticias','&id='+id, 'replaceInnerHTML', 'meio');
 }
 function bd(id_no, modulo,pag)
 {
 	postPage('banco_de_dados','id_no='+id_no+'&modulo='+modulo+'&pag='+pag, 'replaceInnerHTML', 'meio');
 }
 function votaenquete(id)
 {
 	alternativas=document.getElementsByName('enquete_alternativa'+id);
	vazio=true;
	for (k=0;k<alternativas.length;k++)
	{
		if(alternativas[k].checked==true)
		{
			selecao=alternativas[k].value;
			vazio=false;
			break;
		}
	}
	if(vazio)
	{
		alert(unescape('Por favor, escolha uma op%E7%E3o.'));
	}
	else
	{
		postPage('intranet/enquetes.uc', 'action=votar&alternativa='+selecao, 'returnFromVotaenquete', '');
	}
 }
 function returnFromVotaenquete(html)
 {
 	alert(html);
	postPage('conteudodir', '','replaceInnerHTML', 'direita');
 }
 function mostra_dados(id_div,id_div2,classe)
{
	var div=document.getElementById(id_div);
	var filhos=document.getElementById(id_div2).getElementsByTagName('div');
	if (div.style.display=='none')
	{
		for (i=0;i<filhos.length;i++)
		{
			if (filhos[i].className==classe)
			{
				filhos[i].style.display='none';
			}
		}
		div.style.display='block';
	}
	else if (div.style.display=='block') 
	{
		div.style.display='none';
	}
}

function getTagValue(str, tagName)
{
	var temp = str.substring(0,str.indexOf("</"+tagName+">"));
	temp = temp.substring(temp.indexOf("<"+tagName+">")+ tagName.length +2);
	return temp;
}

function fale_conosco()
{
	var subarea = '';
	var nome = escape(get('nome').value);
	var email = escape(get('email').value);
	var empresa = escape(get('empresa').value);
	var telefone = escape(get('telefone').value);
	var mesg = escape(get('mensagem').value);
	var assunto = escape(get('assunto').value);
	var indice = get('area').selectedIndex;
	var area =   escape(get('area').options[indice].value) 
	or = document.getElementsByName('subarea');
    for (var i = 0; i < or.length; i++) {
         if (or[i].checked) {
		 	subarea = or[i].value;
			break;
		 }
    }
	re = new RegExp('^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,60}$');
	re2 = new RegExp('^[(][0-9]{2}\[)] [0-9]{4}\-[0-9]{4}$');
	erro=false;
	msg='';
	if (nome=='')
	{
		erro=true;
		msg=msg+'Favor preencher o campo nome.\r\n';
	}
	if (area=='')
	{
		erro=true;
		msg=msg+'Favor selecionar uma area.\r\n';
	}
	if (empresa=='')
	{
		erro=true;
		msg=msg+'Favor preencher o campo empresa.\r\n';
	}
	if (mesg=='')
	{
		erro=true;
		msg=msg+'Favor preencher o campo mensagem.\r\n';
	}
	if (telefone=='')
	{
		erro=true;
		msg=msg+'Favor preencher o campo telefone.\r\n';
	} else if (!re2.test(unescape(telefone))) {
		erro=true;
		msg=msg+'Favor redigitar o telefone (Ex.:(31) 3333-3333) .\r\n';
		
	}
	if (email=='')
	{
		erro=true;
		msg=msg+'Favor preencher o campo email.\r\n';
	}
	else
	{
		if (!re.test(email))
		{
			erro=true;
			msg=msg+'Favor redigitar o email.\r\n';
		}
	}
	if(erro)
	{
		alert(unescape(msg));
	}
	else
	{
		postPage('email','assunto='+assunto+'&nome='+nome+'&email='+email+'&mesg='+mesg+'&telefone='+telefone+'&empresa='+empresa+'&subarea='+subarea+'&area='+area,'returnFromFaleconosco','');
	}
}

function returnFromFaleconosco(html) 
{
	status = getTagValue(html, 'status');
	if (status = 'enviado')
	{
		alert(unescape('email enviado com sucesso.'));
	}
	opcao('conteudomeio');
} 

function addnewsletter(nome,email)
{
	re = new RegExp('^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,60}$');
	re2 = new RegExp(unescape('^[a-zA-Z%E1%E2%E3%E9%EA%ED%F3%F4%F5%FA%FC%E7%C1%C2%C3%C9%CA%CD%D3%D4%D5%DA%DC%C7\\s]{4,60}$'));
	erro=false;
	msg='';
	if (nome=='')
	{
		erro=true;
		msg=msg+'Favor preencher o campo nome.\r\n';
	}
	else
	{
		if (!re2.test(nome))
		{
			erro=true;
			msg=msg+'Favor redigitar o nome.\r\n';
		}
	}
	if (email=='')
	{
		erro=true;
		msg=msg+'Favor preencher o campo email.';
	}
	else
	{
		if (!re.test(email))
		{
			erro=true;
			msg=msg+'Favor redigitar o email.\r\n';
		}
	}
	if(erro)
	{
		alert(unescape(msg));
	}
	else
	{
		postPage('newsletter','nome='+nome+'&email='+email,'returnFromAddNewsletter','');
	}
}
function returnFromAddNewsletter(html)
{
	alert(html);
}
function abrir_janela(site)
{
	window.open(site);
}
/****************************************************
 * 
 * 			B U S C A
 * 
 ****************************************************/
function buscar()
{
	texto=get('busca').value;
	if (texto.length<3)
	{
		alert('A busca deve conter ao menos 3 caracteres.');
		
	}
	else
	{
		document.frmBusca.submit()
	}
	return false;
}
function returnFromBuscar(html)
{
	replaceInnerHTML(html, 'meio');
	postPage('conteudodir', '', 'replaceInnerHTML', 'direita');
}

/****************************************************
 * 
 * 			P O P - U P   W I N D O W
 * 
 ****************************************************/
 
function MM_openBrWindow(theURL,winName,features) 
{ //v2.0
  window.open(theURL,winName,features);
}

function editarDados(id)
{
	erro = false;
	login = get('login').value;
	email = get('email').value;
	senha = get('senha').value;
	rsenha = get('rsenha').value;
	re = new RegExp('^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$');
	if(login == '')
	{
		erro = true;
		alert('Preencha o campo "Login" por favor.')
	}
	if(email == '')
	{
		erro = true;
		alert('Preencha o campo "Email" por favor.')
	}
	else if (!re.test(email))
	{
		erro=true;
		alert('Endere&ccedil;o de email inv&aacute;lido.');
	}
	if(senha != '')
	{
		if(rsenha !='')
		{
			if (senha!=rsenha)
			{
				erro=true;
				alert('As senhas n%C3%A3o s%C3%A3o iguais.');
			}
		}
		else 
		{
			erro = true;
			alert('Preencha o campo "Redigite a senha" por favor.')
		}
	}
	if (!erro)
	{
		postPage('usuarios.uc','id='+id+'&login='+login+'&email='+email+'&senha='+senha,'replaceInnerHTML','meio' );
	}
}

function MM_jumpMenu(targ,selObj,restore){ 
 	url = selObj.value;
	if (url != '') {
		window.open(url);
	}
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

function comunicacao(item)
{
	postPage(item,'', 'replaceInnerHTML', 'meio');
}

function textCounter( field, maxlimit ) {
  if ( field.value.length > maxlimit )
  {
    field.value = field.value.substring( 0, maxlimit );
    alert( 'Associe-se ao Sinduscon-MG para ter um suporte diferenciado.' );
    return false;
  }
}

function subitems() {
	selectVal = get('area').value;
	filhos = get('interesse').getElementsByTagName('div');
	for (i=0;i<filhos.length;i++)
	{
		if (filhos[i].className=='subitem')
		{
			filhos[i].style.display='none';
		}
	}
	or = document.getElementsByName('subarea');
      for (var i = 0; i < or.length; i++) {
         or[i].checked = false;
     }

	get(selectVal).style.display='block';
}

function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}
 
	var s = new String(campo.value);
	// Remove todos os caracteres ï¿½ seguir: ( ) / - . e espaï¿½o, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;
 
		case 'CNPJ' :
 
			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;
 
		case 'TEL' :
			if (tam > 2 && tam < 4) 
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
			if (tam >= 11)
				campo.value = campo.value.substring( 0, 13 );	
			
		break;
 
		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;
		}
	}
}
