// JavaScript Document


//funções para menu suspenso
function pegaDados(codigo,controle,submenu,menu){
	conter = document.getElementById(controle).value;
	if (conter=="1"){
		h=100;
		document.getElementById(controle).value="0";
		document.getElementById(submenu).padding="0px";
		document.getElementById(submenu).style.lineHeight="0px";
		document.getElementById(submenu).style.display="none";
		
	}else{
		h=0;
		document.getElementById(controle).value="1";
		document.getElementById(submenu).style.lineHeight="normal";
		document.getElementById(submenu).style.display="";
		document.getElementById(controle).value="1";
	}
}

function checado(name, cod, id){
	
	novoCod="";
	if(document.getElementById(name).checked){
		document.getElementById(id).value += cod+"|"; 
	}
	if(document.getElementById(name).checked==false){
		valores = document.getElementById(id).value;
		document.getElementById(id).value="";
		codigos = valores.split("|");
		
		for (i=0;i<=codigos.length-2;i++){
			
			if(codigos[i] != cod){
				novoCod = novoCod+codigos[i]+"|";
				document.getElementById(id).value=novoCod;
			}
		}
	}
}
function isInt(id)
{
   	element = document.getElementById(id)
	var str = /^\d+$/;
	return str.test(valor_text);
}


function formatar(id, mask)
{
	src = document.getElementById(id);
	var i = src.value.length;
  	var saida = mask.substring(0,1);
  	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida)
  	{
    	src.value += texto.substring(0,1);
  	}
}
function formatarFone(id)
{
	src = document.getElementById(id);
	var i = src.value.length;
	if(i==1)
	{
		src.value = "(" + src.value;
	}
	if(i==3)
	{
		src.value = src.value + ") " 
	}
	if(i==9)
	{
		src.value = src.value + "-" 
	}
	
	
}
function formatarValor(id)
{
	obj = document.getElementById(id)
	valor_aux = obj.value;
	if( valor_aux != "")
	{
		if(isFloat(valor_aux) == true)
		{
			pos = valor_aux.search(",");
			if(pos != -1)
			{
				vet_valor = valor_aux.split(",");
				valor = vet_valor[0];
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor= valor.replace(".","")
				valor = valor * 100;
				valor = valor / 100;
				valor = new String(valor);	
				if(valor != "")
				{
					if (vet_valor[1].length == 2)
					{
						valor = formataFloatPonto(valor) + "," + vet_valor[1];
						document.getElementById(id).value = valor;
					}
					else
					{
						if (vet_valor[1].length > 2)
						{
							vet_valor[1] = vet_valor[1].substring(0,2);	
							valor = formataFloatPonto(valor) + "," + vet_valor[1]
							document.getElementById(id).value = valor;
						}
						else
						{
							valor = formataFloatPonto(valor) + "," + vet_valor[1] + "0"	
							document.getElementById(id).value = valor;
						}
					}
				}
				else
				{
					valor = formataFloatPonto(valor) + ",00"; 
					document.getElementById(id).value = valor;
				}
			}
			else
			{
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				valor_aux= valor_aux.replace(".","")
				obj = document.getElementById(id);
				obj.value = formataFloatPonto(valor_aux) + ",00"
				
			}
		}
	}
	
}
function formataFloatPonto(valorParam)
{
	valor = valorParam;	
	tam_vet = parseInt(valor.length / 3)
	var vet_aux = new Array();				
	cont = 0;
	contVet = 0
	if (valor != "")
	{
		if (valor.length > 3)
		{
				
			for(i=valor.length;i>0;i--)
			{
				if( ( cont % 3 == 0)  && (cont > 0) )
				{
					vet_aux[contVet] = i;
					contVet = contVet + 1;
				}	
				cont = cont + 1
			}
			for(i=0;i<vet_aux.length;i++)
			{
				valor = valor.substring(0,vet_aux[i]) + "." + valor.substring(vet_aux[i],valor.length);				
			}
			
		}
	}
	else
	{
		valor = "0";
	}
	return valor
}

function insNumeric(obj,event)
{
    var tecla = event.charCode;
    var ie = event.keyCode;
    if (!event) event = window.event;
    var code;
    if (event.keyCode) code = event.keyCode;
    else if (event.which) code = event.which; // Netscape 4.?
//se nao for número nem parentesis ou espaço
    if ((code < 48 || code > 59) && (code != 8 ) ){
      event.returnValue = false;
      if (event.which){
        event.preventDefault();
      }
      return false;
    }else{
      event.returnValue = true;
      return true;
    }
 }
function insFloat(obj,event)
{
    var tecla = event.charCode;
    var ie = event.keyCode;
    if (!event) event = window.event;
    var code;
    if (event.keyCode) code = event.keyCode;
    else if (event.which) code = event.which; // Netscape 4.?
//se nao for número nem parentesis ou espaço
    if ((code < 48 || code > 59) && (code != 8 ) & (code != 44)){
      event.returnValue = false;
      if (event.which){
        event.preventDefault();
      }
      return false;
    }else{
      event.returnValue = true;
      return true;
    }
 } 

function isFloat(valor)
{
	var valor_text = valor;
	var str = /^[+-]?((\d+|\d{1,3}(\.\d{3})+)(\,\d*)?|\,\d+)$/;
	return str.test(valor_text);
}


function salvarForm()
{
	document.getElementById("form").submit();	
}

function excluirReg(url,codigo)
{
	if (confirm("Deseja realmente excluir o registro"))
	{
		location.href=url+ "&codigo=" + codigo;	
	}
}
function ativar(url,codigo,tipo)
{
	wmsg = ""
	if(tipo = "A")
	{
	    wmsg = "Deseja ativar o registro"    
	}
	else
	{
	    wmsg = "Deseja desativar o registro"    
	}
	if (confirm(wmsg))
	{
		location.href=url+ "&codigo=" + codigo;	
	}
}
function editarReg(url,codigo)
{
	
	location.href=url + "&codigo=" + codigo;	
	
}
function fechar()
{
	close();
}
function salvar(id)
{
	document.getElementById(id).submit();	
}

function abrirMenu(wcontrole, wmenu, walturaIni, walturaMaxima, walfa, wopacity, wmOpacity){
	controle = document.getElementById(wcontrole);
	menu = document.getElementById(wmenu);
	altura = document.getElementById(walturaIni);
	alfa = document.getElementById(walfa);
	opacity = document.getElementById(wopacity);
	mOpacity = document.getElementById(wmOpacity);
	
	if(controle.value == 0){
		menu.style.display = "";
		menu.style.height = altura.value + "px";
		
		if(parseInt(altura.value) != parseInt(walturaMaxima)){
			altura.value = parseInt(altura.value) + 19;
			alfa.value = parseInt(alfa.value) + 7.15;
			opacity.value = parseFloat(opacity.value) + 0.06;
			mOpacity.value = parseFloat(mOpacity.value) + 0.06;
			
			menu.style.filter = "alpha(opacity="+alfa.value+")";
			menu.style.MozOpacity = opacity.value;
			menu.style.opacity = mOpacity.value;
			setTimeout("abrirMenu('"+wcontrole+"', '"+wmenu+"', '"+walturaIni+"', '"+walturaMaxima+"', '"+walfa+"', '"+wopacity+"', '"+wmOpacity+"')",0);
		}else{
			controle.value = 1;
			menu.style.filter = "alpha(opacity=100)";
			menu.style.MozOpacity = "1";
			menu.style.opacity = "1";
		}
		
	}else{
		menu.style.height = altura.value + "px";
		menu.style.filter = "alpha(opacity="+alfa.value+")";
		menu.style.MozOpacity = opacity.value;
		menu.style.opacity = mOpacity.value;
			
		if(parseInt(altura.value) == 19){
			controle.value = 0;
			alfa.value = 0;
			opacity.value = 0;
			mOpacity.value = 0;
			menu.style.display = "none";
		}else{
			altura.value = parseInt(altura.value) - 19;
			alfa.value = parseInt(alfa.value) - 7.15;
			opacity.value = parseFloat(opacity.value) - 0.04;
			mOpacity.value = parseFloat(mOpacity.value) - 0.04;
			setTimeout("abrirMenu('"+wcontrole+"', '"+wmenu+"', '"+walturaIni+"', '"+walturaMaxima+"', '"+walfa+"', '"+wopacity+"', '"+wmOpacity+"')",0);
		}
	}
}



function camposFile(idFoto,idLegenda,contador,acao){
	if(acao == "+"){
		if(parseInt(document.getElementById(contador).value) < 30){
			document.getElementById(contador).value = parseInt(document.getElementById(contador).value)+1;
			//document.getElementById(idFoto + document.getElementById(contador).value).style.display = "";
			document.getElementById(idLegenda + document.getElementById(contador).value).style.display = "";
			document.getElementById('botDel').style.display = "";
		}
		
		if(parseInt(document.getElementById(contador).value) == 30){
			document.getElementById('botAd').style.display = "none";
		}
	}else{
		if(parseInt(document.getElementById(contador).value) > 1){
			//
			document.getElementById('qtde' + document.getElementById(contador).value).value = "";
			document.getElementById('unid' + document.getElementById(contador).value).value = "";
			document.getElementById('cod_espec' + document.getElementById(contador).value).value = "";
			document.getElementById('descricao' + document.getElementById(contador).value).value = "";
			//
			
			//document.getElementById(idFoto + document.getElementById(contador).value).style.display = "none";
			document.getElementById(idLegenda + document.getElementById(contador).value).style.display = "none";
			document.getElementById(contador).value = parseInt(document.getElementById(contador).value)-1;
			document.getElementById('botAd').style.display = "";
		}
		
		if(parseInt(document.getElementById(contador).value) == 5){
			document.getElementById('botDel').style.display = "none";
		}
	}
}
function tipo_arq(id,tipoPermitido)
{        	
    foto = document.getElementById(id);
   
	if(foto)
	{
	    if (foto.value != "" )
		{		
		    wfoto = foto.value
			indice = wfoto.indexOf(".");
			indice = indice + 1; 
			wfoto = wfoto.substr(indice);
			wfoto = wfoto.toLowerCase();
			
			var vetExtensao = new Array();
        	vetExtensao = tipoPermitido.split("|")
        	ret = false
        	for(i=0;i<vetExtensao.length;i++)
        	{
        	    
        	    if( wfoto == vetExtensao[i])
        	    {
        	       ret = true;
        	       break;
        	      
        	    }
        	}
            if(ret == false)
            {
                alert("Arquivo com extensão não permitida")   
            }
        	return ret
			
		 }
		 return true		        		        		        
	 }     	
	 return true	
}


function ocultaModulo(numId)
{
	
	img = document.getElementById("img_" + numId);
	div_modulo = document.getElementById("mod_" + numId);
	var aux = div_modulo.style.display;
	if (aux == "none")
	{
		div_modulo.style.display = "block";
		if (img)
		{
		    img.src = "imagens/icon_menos.gif";
		    img.alt = "Ocultar"
		}
	}
	if (aux == "block")
	{
		div_modulo.style.display = "none";
		if (img)
		{
		    img.src = "imagens/icon_mais.gif";
		    img.alt = "Mostrar"
		}
	}
}
function janelaBusca(wurl)
{
	
	winDt = window.open(wurl,'','top=50,left=200,width=720,height=618,scrollbars=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1');
	winDt.focus();
}
function fechaBanner()
{
    document.getElementById("banner").style.display = "none";
}
function abrirBanner()
{
  document.getElementById("banner").style.display = "block";  
  var wmargin = (screen.availWidth - 1000) / 2
  wmargin = parseInt( (( 1000 - parseInt(document.getElementById("banner").style.width)) / 2) ) + parseInt(wmargin)
 
  document.getElementById("banner").style.marginLeft = wmargin + "px"
  setTimeout("fechaBanner()", 10000);
}


//fim