//---------------------------------------- Elemento

/*
 * Retorna o elemento com o id informado
 * @param String nis Id do elemento
 */
function den(nis) {
	return document.getElementById(nis);
}

function tags(nis) {
	return document.getElementsByTagName(nis);
}

//---------------------------------------- Elemento.innerHTML
/*
 * Insere o valor passado como conteúdo HTML do elemento.
 * @param String nis Id do elemento
 * @param String conteudo Conteudo a ser inserido
 */
function insereHTML(nis,conteudo) {
	den(nis).innerHTML = conteudo;
}

/*
 * Retorn o valor do elemento.
 * @param String nis Id do elemento
 * @param String valor Valor a ser inserido
 */
function oValor(nis) {
	return den(nis).value;
}

/*
 * Remove o conteúdo HTML do elemento.
 * @param nis Id do elemento
 */
function removeHTML(nis) {
	den(nis).innerHTML = '';
}

//----------------------------------------- Elemento.value

/*
 * Insere o valor passado como valor do elemento.
 * @param String nis Id do elemento
 * @param String valor Valor a ser inserido
 */
function insereValor(nis,valor) {
	den(nis).value = valor;
}

/*
 * Remove o valor do elemento.
 * @param nis Id do elemento
 */
function removeValor(nis) {
	den(nis).value = '';
}

//------------------------------------------- Elemento.style.display

/*
 * Mostra ou esconde o elemento, dependendo do estado de exibição dele
 * @param nis Id do elemento
 */
function mostraEsconde(nis) {
	//den(nis).style.display = (den(nis).style.display == 'none') ? "block" : "none";
	try {
		attr = den(nis).getAttributeNode("class");
		valores = attr.value.split(" ");
		escondido = false;
		
		for(var i = 0; i < valores.length; i++) {
			if (valores[i].match("esconde")) {
				escondido = true;
				continue;
			}
		}
		
		if(!escondido) {
			den(nis).className +=" esconde";
		} else {
			den(nis).className = den(nis).className.replace("esconde","");
		}
		
	} catch(e) {
		alert(e.message);
	}
}

function temPalavra(palavra,string) {
	var tem = false;
	valores = string.split(" ");
	for(var i = 0; i < valores.length; i++) {
		if (valores[i].match(palavra)) {
			tem = true;
		}
	}
	return tem;
}

/*
 * Esconde o elemento definindo o seu display para none
 * @param nis Id do elemento
 */
function esconde(nis) {
	var novosValores = "";
	try {
		attr = den(nis).getAttributeNode("class");
		if(!temPalavra("esconde",attr.value)) {
			den(nis).className +=" esconde"
		}
	} catch(e) {
		alert(e.message);
	}
}


/*
 * Mostr o elemento definindo o seu display para ''
 * @param nis Id do elemento
 */
function mostra(nis) {
	var novosValores = "";
	try {
		attr = den(nis).getAttributeNode("class");
		if(temPalavra("esconde",attr.value)) {
			den(nis).className = den(nis).className.replace("esconde", "");
		}
	} catch(e) {
		alert(e.message);
	}
}


//--------------------------------------- Confirma

/*
 * Pergunta para o usuário se ele deseja confirmar a execução da função
 * @param String msg Pergunta a ser feita para o usuário
 * @param function funcao Função a ser executada
 */
function confirma(msg,funcao){
	if(confirm(a)) { funcao(); }
}


function enviarFormulario(id) {
	den(id).submit();
}

//------------------------------------------ Menu Interno
// JavaScript Document
var omenu = true;
function menue(a) {
	obj = document.getElementById(a);
	if (omenu) { 
		omenu = false; 
		Effect.BlindDown(obj);

	}
	else {
		omenu = true; 
		Effect.BlindUp(obj);
	}
}
//------------------------------------------ Menu flutuante
function exibirmenu(Estado){
		//O estado pode ser Mostrar ou nMostrar
		if(Estado == "nMostrar") {
			den("listaMenuFlutuante").className +=" invisivel";
		} else {
			den("listaMenuFlutuante").className = den("listaMenuFlutuante").className.replace("invisivel","");
		}	
	
	}
	
//---------------------------------------------------------------menu Principal

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_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=MM_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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' Deve conter um endereço de e-mail.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' Deve conter um número entre '+min+' e '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' tem que ser preenchido.\n'; }
    } if (errors) alert('O seguinte erro(s) ocorreu:\n'+errors);
    document.MM_returnValue = (errors == '');
} }



function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

/********************** Efeito safari nos inputs ******************************/



function trocaBG(id){
	document.getElementById(id).style.backgroundImage='url('+pic1.src+')';
}

function trocaBGOriginal(id){
	document.getElementById(id).style.backgroundImage='url(imagens/input_inativo.jpg)';
}

function trocaBG2(id){
	document.getElementById(id).style.backgroundImage='url('+pic2.src+')';
}

function trocaBGOriginal2(id){
	document.getElementById(id).style.backgroundImage='url(imagens/textarea_inativo.jpg)';
}

function trocaBG3(id){
	document.getElementById(id).style.backgroundImage='url('+pic3.src+')';
}

function trocaBGOriginal3(id){
	document.getElementById(id).style.backgroundImage='url(imagens/botoes/bt-limpar.jpg)';
}

function trocaBG4(id){
	document.getElementById(id).style.backgroundImage='url('+pic4.src+')';
}

function trocaBGOriginal4(id){
	document.getElementById(id).style.backgroundImage='url(imagens/botoes/bt-enviar.jpg)';
}

function trocaBG5(id){
	document.getElementById(id).style.backgroundImage='url('+pic5.src+')';
}

function trocaBGOriginal5(id){
	document.getElementById(id).style.backgroundImage='url(imagens/select_inativo.jpg)';
}

/*===================================================*/

function verificaInput(elemento, evento)
{
	if (evento == 'onfocus') {
		if((elemento.id == 'nome') || (elemento.id == 'email') || (elemento.id == 'telefone') || (elemento.id == 'empresa') || (elemento.id == 'profissao'))
		{
			trocaBG('input' + elemento.id);
		}
		else if(elemento.id == 'limpar')
		{
			trocaBG3('input' + elemento.id);
		}
		else if(elemento.id == 'enviar')
		{
			trocaBG4('input' + elemento.id);
		}
		else if(elemento.id == 'nascimento')
		{
			trocaBG5('input' + elemento.id);
		}
	}
	else if (evento == 'onblur') {
		if((elemento.id == 'nome') || (elemento.id == 'email') || (elemento.id == 'telefone') || (elemento.id == 'empresa') || (elemento.id == 'profissao'))
		{
			trocaBGOriginal('input' + elemento.id);
		}
		else if(elemento.id == 'limpar')
		{
			trocaBGOriginal3('input' + elemento.id);
		}
		else if(elemento.id == 'enviar')
		{
			trocaBGOriginal4('input' + elemento.id);
		}
		else if(elemento.id == 'nascimento')
		{
			trocaBGOriginal5('input' + elemento.id);
		}
	}
}


/*function limpaValor(campo, valorOriginal, valorAtual){
	if(document.getElementById(campo).value == valorOriginal){
		document.getElementById(campo).value="";
	}else{
		document.getElementById(campo).value=valorAtual;
	}
}

function matemValor(campo, valor){
	if(	document.getElementById(campo).value==""){
		document.getElementById(campo).value = valor;
	}
}*/

function paraMovimento(campo)
{
	document.getElementById(campo).Scrollamount = 0;
}


/* Expandi campo ====================*/
function ExpandeCampo(idCampo)
{
	var Campo = den(idCampo);
	
	if (Campo.className == 'mostraCampo')
	{
		Campo.className = 'escondeCampo';
	}
	else
	{
		Campo.className = 'mostraCampo';
	}
}

