// JavaScript Document
function ajaxInit() {
	var req;
	try {
		 req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch(e) {
		 try {
			  req = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch(ex) {
		 try {
		   req = new XMLHttpRequest();
	     } catch(exc) {
	 		  alert("Esse browser não tem recursos para uso do Ajax");
	  		 req = null;
	     }
	 }
}
return req;
}

function carregaCombo(url, codigo, id) {
	//alert(url + "?tipo=" + tipo)
	$("#" + id).load(url + "?codigo=" + codigo)
}

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)
{
    if(obj.id == "cep1")
	{
		maxLengh = 4
		if( $.browser.msie || $.browser.safari)
		//if( $.browser.msie )
		{
			setTimeout(function(){
				if( obj.value.length == 5)
				{
					document.getElementById("cep2").focus();	
				}
			},300)
			
		}
		else
		{		
			if( obj.value.length == maxLengh)
			{
				document.getElementById("cep2").focus();	
			}
		}
	}
	
	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 != 13 ) ){      
	  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) && (code != 13 )){
      event.returnValue = false;
      if (event.which){
        event.preventDefault();
      }
      return false;
    }else{
      event.returnValue = true;
      return true;
    }
} 
function mask(_mask, val) {
	var i, mki;
	var aux="";
	
	for(i=mki=0; i<val.length; i++, mki++) {
		if(_mask.charAt(mki)=='' || _mask.charAt(mki)=='#' || _mask.charAt(i)==val.charAt(i)) {
			aux+=val.charAt(i);
		} else {
			aux+=_mask.charAt(mki)+val.charAt(i);
			mki++;
		}
	}
	return aux;
}
function mascaraNumero(obj,event,_mask)
{
    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
    var strCheck = '0123456789';
	rcode = code
    key=String.fromCharCode(rcode);
	
	
	  if( code != 8 && code != 9 && code != 46 && code != 39 && code !=37 && code !=116 && code !=13 ){
	//Not a valid key
		
		if( (strCheck.indexOf(key)==-1 || (obj.value.length >= _mask.length) ) )
		{
			return false;
		}
		aux=obj.value+key;
		//window.alert(aux);
		aux=mask(_mask,aux);
		//window.alert(aux);
		obj.value=aux;	
		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 pegarHora(campo){
	hora = new Date;
	wHora = hora.getHours();
	wMin = hora.getMinutes();
	if(wMin < 10){
		wMin = "0" + wMin;
	}
	wSec = hora.getSeconds();
	if(wSec < 10){
		wSec = "0" + wSec;
	}
	
	//wHoraF = wHora +":"+ wMin +":"+ wSec;
	wHoraF = wHora +":"+ wMin;
	
	document.getElementById(campo).innerHTML = wHoraF;
	
	setTimeout("pegarHora('"+campo+"')",1);
}
function pegarData(){
	var nomeDia;
	data = new Date;
	dia  = data.getDay();
	mes = data.getMonth();
	ano = data.getFullYear();
	
	switch(dia){
		case 0:
			nomeDia = "Domingo";
		case 1:
			nomeDia = "Segunda-feira";
		case 2:
			nomeDia = "Terça-feira";
		case 3:
			nomeDia = "Quarta-feira";
		case 4:
			nomeDia = "Quinta-feira";
		case 5:
			nomeDia = "Sexta-feira";
		case 6:
			nomeDia = "Sábado";
	}
	
	switch(mes){
		case 0:
			nomeMes = "janeiro";
		case 1:
			nomeMes = "fevereiro";
		case 2:
			nomeMes = "março";
		case 3:
			nomeMes = "abril";
		case 4:
			nomeMes = "maio";
		case 5:
			nomeMes = "junho";
		case 6:
			nomeMes = "julho";
		case 7:
			nomeMes = "agosto";
		case 8:
			nomeMes = "setembro";
		case 9:
			nomeMes = "outubro";
		case 10:
			nomeMes = "novembro";
		case 11:
			nomeMes = "dezembro";
	}
	
	campoData = document.getElementById("data_semana");
	campoData.innerHTML = nomeDia +", "+ dia +" de "+ nomeMes +" de "+ ano +".";	
}


function janelaBusca(url,id,idIns,IdDel,largura,altura)
{
	element = document.getElementById(id)
	extra = document.getElementById("extra")
	wurl = url + "&digitado="+ element.value + "&camposIns=" + idIns + "&camposApagar=" + IdDel	
	
	if( (extra) && (extra.value != "") )
	{
		vet_extra = extra.value.split("|");
		campoExtra = vet_extra[0];
		valorCampo = document.getElementById(vet_extra[1]);
		if (valorCampo)
		{
			wurl = wurl + "&campoExtra=" + campoExtra + "&valorExtra=" + valorCampo.value
		}
	}
	
	winDt = window.open(wurl,'','top=300,left=600,width='+ largura +',height='+ altura +',scrollbars=1,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0');
	winDt.focus();
}

function excluirReg(url)
{
	urlRetornoAlert=url;
	confirm("Deseja realmente excluir o registro?")
	
}

function trocaPag(url){
	urlRetornoAlert = url;
	confirm("Deseja realmente excluir o registro?")
}

function fechar()
{
	close();
}
function salvar(id)
{
	document.getElementById(id).submit();	
}

function abrirMenu(wcontrole)
{	
	$("#"+wcontrole).slideToggle("normal")
}

function abrirDiv(wcontrole, elemento, total){
	for(i=0;i<=total;i++){
		if(elemento+i != wcontrole){
			$("#"+elemento+i).css("display", "none");
		}
	}
	
	if($("#"+wcontrole).is(":visible")){
		$("#"+wcontrole).slideUp("slow");
	}else{
		$("#"+wcontrole).slideDown("slow");
	}
}

function janelaRelatorio(wurl)
{
	var winDt = window.open(wurl,'','scrollbars=1,status=1,toolbar=1,location=0,menubar=1,directories=1,resizable=1');
	winDt.focus();
}

function horaImpressao()
{
	data_aux = new Date;
	whora = data_aux.getHours()
	wminuto = data_aux.getMinutes()
	
	dia = data_aux.getDate();
	mes = data_aux.getMonth();
	mes = parseInt(mes) + 1;
	ano = data_aux.getFullYear();
	if (dia < 10)
	{
		dia = "0" + dia;
	}
	if (mes < 10)
	{
		mes = "0" + mes;
	}
	if (whora < 10)
	{
		whora = "0" + whora;
	}
	if (wminuto < 10)
	{
		wminuto = "0" +wminuto;
	}
	
	obj = document.getElementsByTagName("span");
	
	for (i=0;i<obj.length;i++)
	{
		
		if (obj[i])
		{
			if (obj[i].className == "hora")
			{
				obj[i].innerHTML = dia + "/" + mes + "/" + ano + " " + whora + ":" + wminuto;
			}
		}
	}		
	
}

function iniciarFuncoes()
{
	
	/*Controle de tipo de dado nos inputs*/
	$(".int").keypress(function(event){ insNumeric(this,event) }) 

	$(".menuAbrir").click(function(){
		ocultaFaq($(this).attr("id"))
	})
}

function buscaCep()
{
	wcep = $("#cep").val();	
	wcep = wcep.replace("-","")
	ajax = ajaxInit();	
	if(ajax) {
		ajax.open("GET","busca_cep.asp?cep=" + wcep, true);
		
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4) {
				if(ajax.status == 200) {
					retorno = ajax.responseText;
					if( retorno != "erro" )
					{
						vetRet = retorno.split("|")	
						$("#endereco").val(vetRet[0])
						$("#bairro").val(vetRet[1])
						//$("#cidade").val(vetRet[2])
						if( $("#estado").attr("type") == "input" )
						{
							if( vetRet[3].split("-").length > 0 )
							{							
								$("#estado").val(vetRet[3])						
							}
							if( vetRet[2].split("-").length > 0 )
							{
								$("#cidade").val(vetRet[2])							
							}
						}
						else
						{
							$("#cidade").val(vetRet[2])
							objSelect = document.getElementById("estado")
							posItem = 0
							for(i=1;i<objSelect.options.length;i++)
							{
								if(objSelect.options[i].value == vetRet[3].split("-")[0])
								{
									$("#estado").val( objSelect.options[i].text )
									objSelect.options[i].selected =  true
									posItem = i								
									break
								}
							}
						}
					}
				}else{
					//alert(ajax.statusText);
				}
			}
		}
		ajax.send(null);
	}	
	
}
function janelaExterna(url)
{
	var largura = window.width 
	var altura =  window.height
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var wleft = parseInt( ( parseInt(xScroll)-1100 ) /2 )
	largura = parseInt(xScroll)-1000
	altura = yScroll
	//alert(xScroll + " - " + yScroll)
	var winDt = window.open(url,'','left='+ wleft +',width=1050,height='+ altura +',scrollbars=1,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1');
	winDt.focus();
}


function selecionaFrete(tipo,valor_frete,valor_total){
	document.getElementById('totalmostra').value='R$ ' + valor_total;
	document.getElementById('totalenvia').value=valor_total;
	document.getElementById('freteenvia').value=valor_frete;
	document.getElementById('freteescolhido').value='R$ ' + valor_frete;
	document.getElementById('tipo_frete').value=tipo;
	
	if(document.getElementById('tipofretel')){
		document.getElementById('tipofretel').value=tipo;
		document.getElementById('valorfretel').value=valor_frete;
		document.getElementById('valortotall').value=valor_total;
	}
	document.getElementById("freteCalculado").value = "S"
}

function selecionaFrete2(tipo,valor_frete,valor_total){
	document.getElementById('mostraTotal').value = 'R$ ' + valor_total;
	document.getElementById('mostraFrete').value = 'R$ ' + valor_frete;
	document.getElementById('tipo_frete').value=tipo;
	
	document.getElementById('valorTotal').value = valor_total;
	document.getElementById('valorFrete').value = valor_frete;
}

function calculaFrete()
{
	
	if(document.getElementById("cep1").value != "" && document.getElementById("cep2").value != "")
	{
		document.getElementById('labelTotal').childNodes[0].nodeValue = "R$0,00"
		document.getElementById('valorTotal').value="";
		document.getElementById('valorFrete').value="";
		
		var  cep1 = document.getElementById("cep1").value
		var cep2 = document.getElementById("cep2").value
		var peso  = document.getElementById("peso").value
		var preco = document.getElementById("valor").value
		
		wurl = "calc_frete.asp?cep1=" + cep1 + "&cep2="+cep2 + "&peso="+ peso + "&valor=" + preco
		
		document.getElementById("calcFrete").innerHTML = "<img src='imagens/ajax-loader.gif'>"
		carregaCombo(wurl,"calcFrete")	
		
	}
	else
	{
		alert("Atenção, preencha o campo CEP")		
	}
}
function verSelecao()
{
  obj = document.getElementsByTagName("input")
  for(i=0;i<obj.length;i++)
  {
	  if( obj[i].type == "radio" && obj[i].checked == true)
	  {
		  obj[i].click();		
		  
	  }
  }
  
}
function janelaCorreios(wurl)
{
	
	winDt = window.open(wurl,'','left=100,width=800,scrollbars=1,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1');
	winDt.focus();
	
}


function verifCheck(campo1, campo2){
	if(document.getElementById(campo1).checked == true){
		document.getElementById(campo2).style.display = "";
	}else{
		document.getElementById(campo2).style.display = "none";
	}
}

function janelaBoleto(wurl)
{

	winDt = window.open(wurl,'','left=100,width=800,scrollbars=1,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1');

	winDt.focus();
	

}

function dimensoesTela()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;


	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	
	if(yScroll <= windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
		
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
		
	dimensao = pageWidth + "x" + pageHeight
	return dimensao
}

function incluirCarregando(txt)
{
	
	$("#caixaCarregando").remove()
	pageWidth = dimensoesTela().split("x")[0]
	pageHeight = dimensoesTela().split("x")[1]	
	$("<div id='caixaCarregando'><img src='imagens/loading2.gif'><label></label></div>").appendTo("body").hide()
	$("#caixaCarregando label").text(txt)
	wleft = ( parseInt(dimensoesTela().split("x")[0]) - parseInt($("#caixaCarregando").width() ) ) / 2
	if (document.all)
	{
		var wtop = parseInt(document.documentElement.scrollTop) + 250
		
	}
	else
	{
		var wtop = parseInt(window.scrollY) + 250	
	}
	//wtop = ( parseInt(dimensoesTela().split("x")[1]) - parseInt( ) ) / 2	
	$("#caixaCarregando").css("left",parseInt(wleft))
	$("#caixaCarregando").css("top",wtop)
	$("#caixaCarregando").show()

}

//FUNCOES DE AUTOCOMPLETAR E BUSCA

function opcoesAutoComplete(tabela,campoTabela,inputCodigo,inputText,inputExtra,campoTabelaExtra)
{
	this.tabela = tabela;	
	this.campoTabela = campoTabela;
	this.inputCodigo = inputCodigo
	this.inputText = inputText
	this.inputExtra = inputExtra;
	this.campoTabelaExtra = campoTabelaExtra;		
}
var historicoTextAutocomplete = ""
var verificaFocusInput = false
var posicaoAutocomplete = -1
objOpcoesAutocomple = new Object()
function iniciaFuncoesInputBusca()
{
	
	for(i=0;i<$("input[alt!='']").length;i++)
	{
		if( $("input[alt!='']:eq("+ i +")").attr("alt").substring(0,13) == "completeInput" )
		{
			altElement = ""
			insFuncao = false
			if( $("input[alt!='']:eq("+ i +")").attr("alt").replace("completeInput","").split(",").length >2 )
			{
				altElement = $("input[alt!='']:eq("+ i +")").attr("alt").replace("completeInput","")
				insFuncao = true
			}
			else
			{
				idReferencia = $("input[alt!='']:eq("+ i +")").attr("alt").replace("completeInput","").replace("{","").replace("}","")
				
				if( $("#" + idReferencia).length > 0)
				{
					if( $("#" + idReferencia).attr("alt").replace("autocomplete","").split(",").length >2 )
					{
						altElement = $("#" + $("input[alt!='']:eq("+ i +")").attr("alt").replace("completeInput","")).replace("autocomplete","")
						insFuncao = true
					}
				}
			}
			if( insFuncao == true )
			{
				$("input[alt!='']:eq("+ i +")").blur(function(){
					
					if( $(this).val() != "" && validaTipoDado($(this).val(),"int") )
					{
						
						setObjectAutoComplete(altElement)					
						
						$.post("paginaLoad.html",function(retornoPost){
							
							if(retornoPost.length > 0 && retornoPost!="")
							{
								if( retornoPost.substring(0,4) != "erro" )
								{
									
								}
								else
								{
									mensagemErroSessao()
								}
							}
											
						})
					}			
				})
			}	
		}
		if( $("input[alt!='']:eq("+ i +")").attr("alt").substring(0,12) == "autocomplete" )
		{
			
			altElement = ""
			insFuncao = false
			if( $("input[alt!='']:eq("+ i +")").attr("alt").replace("autocomplete","").split(",").length >2 )
			{
				insFuncao = true
			}
			else
			{
				idReferencia = $("input[alt!='']:eq("+ i +")").attr("alt").replace("autocomplete","").replace("{","").replace("}","")
				
				if( $("#" + idReferencia).length > 0)
				{
					
					if( $("#" + idReferencia).attr("alt").replace("completeInput","").replace("autocomplete","").split(",").length >2 )
					{
						insFuncao = true
					}
				}
			}
			
			if( insFuncao == true )
			{
				
				$("input[alt!='']:eq("+ i +")").keyup(function(e){
					
					if( $(this).attr("alt").replace("autocomplete","").split(",").length >2 )
					{
						objInputAutcomplete = $(this)
					}
					else
					{
						idReferencia = $(this).attr("alt").replace("autocomplete","").replace("{","").replace("}","")
						objInputAutcomplete = $("#" + idReferencia)
					}
					
					
					if( e.which != 13 && e.which != 9)
					{
						if( e.which == 38 || e.which == 40)
						{
							if( $("#autocomplete li").length > 0 )
							{
								posicaoItem = -1
								if( $("#autocomplete li").is(":hidden") )
								{
									posicaoItem = $("#autocomplete li").index($("#autocomplete li:contains('"+ $(this).val() +"')"))
									posicaoAutocomplete = -1
								}
								
								if( posicaoItem >= 0 )
								{
									$("#autocomplete li:eq("+ posicaoItem +")").removeClass("autocompleteInativo").addClass("autocompleteAtivo")
									$("#autocomplete li:gt("+ posicaoItem +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
									$("#autocomplete li:lt("+ posicaoItem +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
									posicaoAutocomplete = posicaoItem
									$("#autocomplete").show()
								}
								else
								{
									
									if( e.which == 40	)
									{
										posicaoAutocomplete = parseInt(posicaoAutocomplete) + 1								
										if( posicaoAutocomplete == $("#autocomplete li").length)
										{
											posicaoAutocomplete = 0
										}
										
									}
									else
									{
										posicaoAutocomplete = parseInt(posicaoAutocomplete) - 1				
										if( posicaoAutocomplete < 0 )
										{
											posicaoAutocomplete = parseInt($("#autocomplete li").length)-1
										}
									}
									$("#"+ objOpcoesAutocomple.inputText ).val($("#autocomplete li:eq("+ posicaoAutocomplete +")").text())
									$("#autocomplete li:eq("+ posicaoAutocomplete +")").removeClass("autocompleteInativo").addClass("autocompleteAtivo")
									$("#autocomplete li:gt("+ posicaoAutocomplete +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
									$("#autocomplete li:lt("+ posicaoAutocomplete +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
								}
							}
							else
							{
								loadAutoComplete(this)
							}
													
						}							
						else
						{
							
							if( $(this).val() != "" )
							{
								loadAutoComplete(this)	
							}
							else
							{
								$("#autocomplete").remove()
							}
							
						}		
					}
					else
					{
						e.returnValue = false;
						e.preventDefault();							
						return false;
					}		
											
					
					
				})
				$("input[alt!='']:eq("+ i +")").keypress(function(e){				
					if( e.which == 13 )
					{						
						if( $("#autocomplete li:eq("+ posicaoAutocomplete +")").is(":visible") )
						{
							$("#autocomplete li:eq("+ posicaoAutocomplete +")").click()
							e.returnValue = false;
							e.preventDefault();							
							return false;
						}
						
						
					}												 
				})
								
				
				$("input[alt!='']:eq("+ i +")").focus(function(){
					
					if( $(this).attr("alt").replace("autocomplete","").split(",").length >2 )
					{
						objInputAutcomplete = $(this)
					}
					else
					{
						idReferencia = $(this).attr("alt").replace("autocomplete","").replace("{","").replace("}","")
						objInputAutcomplete = $("#" + idReferencia)
					}					
										
					altElement = $(objInputAutcomplete).attr("alt").replace("{","").replace("}","")
					setObjectAutoComplete(altElement)
				})
				
				$("input[alt!='']:eq("+ i +")").blur(function(){ 
					//if( $("#autocomplete li").length > 0 )
					//{
						/*setTimeout(function(){
							if( $("#autocomplete li").length > 0 )
							{
								$("#autocomplete").remove() 								
							}
							
							if( historicoTextAutocomplete != "" )
							{
								$("#"+ objOpcoesAutocomple.inputText).val(historicoTextAutocomplete)
							}							
							posicaoAutocomplete = -1
							if( verificaFocusInput == true )
							{
								$("#"+ objOpcoesAutocomple.inputText).focus()
							}
							verificaFocusInput = false
						},300)*/
					//}
					//else
					//{
						//$("#autocomplete").remove() 
						//posicaoAutocomplete = -1
					//}
					
				})
			}
			
		}
	}
	
	for(i=0;i<$("button[name!='']").length;i++)
	{
		$("button[name!='']:eq("+ i +")").unbind()
		if( $("button[name!='']:eq("+ i +")").attr("name").substring(0,5) == "busca" )
		{
			funcaoClick = false
			if( $(this).attr("name").replace("busca","").split(",").length >2 )
			{
				funcaoClick = true
			}
			else
			{
				funcaoClick = true
			}
			if( funcaoClick == true )
			{
				$("button[name!='']:eq("+ i +")").click(function(){
					if( $(this).attr("name").replace("busca","").split(",").length >2 )
					{
						objInputAutcomplete = $(this)
					}
					else
					{
						idReferencia = $(this).attr("name").replace("busca","").replace("{","").replace("}","")
						objInputAutcomplete = $("#" + idReferencia)
					}
					
					
					
					altElement = $(objInputAutcomplete).attr("alt").replace("{","").replace("}","")
					
					setObjectAutoComplete(altElement)												 
				})
				
			}
		}
		
	}
	
}
function loadAutoComplete(objInput)
{
	$("#autocomplete").remove()
	if( $("#autocomplete").length==0)
	{
		
		$("<ul id='autocomplete'/>").appendTo("body").css("left",$(objInput).offset().left).css("top",parseInt($(objInput).offset().top)+parseInt($(objInput).innerHeight())).css("width",$(objInput).width())
	}
	wurl = "buscaAutoListagem.asp?tabelaBusca="+ objOpcoesAutocomple.tabela +"&campo="+ objOpcoesAutocomple.campoTabela + "&digitado=" + $("#"+objOpcoesAutocomple.inputText).val()
	erroExtra = false
	if( objOpcoesAutocomple.campoTabelaExtra != "")
	{
		if( $("#"+objOpcoesAutocomple.inputExtra).val() != "" )
		{
			wurl += "&campoExtra=" + objOpcoesAutocomple.campoTabelaExtra + "&valorExtra=" + $("#"+objOpcoesAutocomple.inputExtra).val()
		}
		else
		{
			erroExtra = true
			objFocus = ("#"+objOpcoesAutocomple.inputExtra)
			alert("Preencha o campo " + $("#"+objOpcoesAutocomple.inputExtra).attr("title"))
		}
	}
	
	if( erroExtra == false )
	{
		$.post(wurl,function(retornoPost){
			$("#autocomplete").html(retornoPost)				 
			$("#autocomplete li").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
			$("#autocomplete li").hover(function(){
				
				posicaoAutocomplete = $("#autocomplete li").index($(this))
				$("#autocomplete li:eq("+ posicaoAutocomplete +")").removeClass("autocompleteInativo").addClass("autocompleteAtivo")
				$("#autocomplete li:gt("+ posicaoAutocomplete +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
				$("#autocomplete li:lt("+ posicaoAutocomplete +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
				
			})
			$("#autocomplete li").click(function(){
				
				verificaFocusInput = true
				$("#"+ objOpcoesAutocomple.inputText ).val($(this).text())
				$("#"+ objOpcoesAutocomple.inputCodigo).val($(this).attr("id"))
				historicoTextAutocomplete = $(this).text()
				$("#autocomplete").remove()
			})					 
		})
	}
	/*$("#autocomplete").load(wurl,function(){
		$("#autocomplete li").hover(function(){
			
			posicaoAutocomplete = $("#autocomplete li").index($(this))
			$("#autocomplete li:eq("+ posicaoAutocomplete +")").removeClass("autocompleteInativo").addClass("autocompleteAtivo")
			$("#autocomplete li:gt("+ posicaoAutocomplete +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
			$("#autocomplete li:lt("+ posicaoAutocomplete +")").removeClass("autocompleteAtivo").addClass("autocompleteInativo")
			
		})
		$("#autocomplete li").click(function(){
			
			verificaFocusInput = true
			$("#"+ objOpcoesAutocomple.inputText ).val($(this).text())
			$("#"+ objOpcoesAutocomple.inputCodigo).val($(this).attr("id"))
			historicoTextAutocomplete = $(this).text()
			$("#autocomplete").remove()
		})
	})*/
}

function setObjectAutoComplete(altElement)
{
	
	altElement = altElement.replace("autocomplete","").replace("completeInput","").replace("busca","")
	
	if( altElement.split(",").length == 5 )
	{
		tabela = altElement.split(",")[0]
		campoTabela = altElement.split(",")[1]
		inputCodigo = altElement.split(",")[2]
		inputText = altElement.split(",")[3]
		inputExtra = altElement.replace("autocomplete","").split(",")[4].split("|")[0]
		campoTabelaExtra = altElement.replace("autocomplete","").split(",")[4].split("|")[1] 
	}
	else
	{
		tabela = altElement.split(",")[0]
		campoTabela = altElement.split(",")[1]
		inputCodigo = altElement.split(",")[2]
		inputText = altElement.split(",")[3]
		inputExtra = ""
		campoTabelaExtra = ""
	}
	
	objOpcoesAutocomple = new opcoesAutoComplete(tabela,campoTabela,inputCodigo,inputText,inputExtra,campoTabelaExtra)	
	
}

var linhaAtual = 1 
				
function adicionaLinhaQtd(pos)
{
	if( validaFormGeral("linha_" + pos  ) )
	{
		linhaAtual = parseInt(linhaAtual)+1
		$("#totalItens").val(linhaAtual)
		strLinha = "<tr id='linha_"+ linhaAtual +"'>"
		strLinha += "<td class='td_codigo'><input type='text' name='qtd_" + linhaAtual + "' id='qtd_" + linhaAtual + "' class='obrigatorio int' title='Quantidade'></td>"
		strLinha += "<td class='td_codigo'><input type='text' name='peso_" + linhaAtual + "' id='peso_" + linhaAtual + "' class='obrigatorio' title='Peso' alt='valor'></td>"
		strLinha += "<td class='td_codigo'><input type='text' name='valorCli_" + linhaAtual + "' id='valorCli_" + linhaAtual + "' class='obrigatorio' title='Valor Cliente' alt='valor'></td>"
		strLinha += "<td class='td_codigo'><input type='text' name='valorRev_" + linhaAtual + "' id='valorRev_" + linhaAtual + "' class='obrigatorio' title='Valor Revendedor' alt='valor'></td>"
		strLinha += "<td class='td_opcao'><button type='button' class='btnVendaAdiciona btnAdicionaQtd' id='btnAdiciona_" + linhaAtual + "'></button><button type='button' class='btnVendaExclui btnExcluiQtd' id='btnExcluir_" + linhaAtual + "' style='margin-left:10px;'></button></td>"
		strLinha += "</tr>"
		$(strLinha).appendTo("#tabelaQtd")
		$("#peso_" + linhaAtual + ",#valorCli_" + linhaAtual + ",#valorRev_" + linhaAtual).keypress(function(e){ insFloat($(this),e); })
		$("#peso_" + linhaAtual + ",#valorCli_" + linhaAtual + ",#valorRev_" + linhaAtual).blur(function(){ formatarValor($(this).attr("id")) })
		$("#btnAdiciona_" + linhaAtual).click(function(){ adicionaLinhaQtd( $(this).attr("id").split("_")[1] ) })
		$("#btnExcluir_" + linhaAtual).click(function(){ excluiLinhaQtd( $(this).attr("id").split("_")[1] ) })
	}	
}
function excluiLinhaQtd(pos)
{
	
	if( $("#tabelaQtd tr").index( $("#linha_" + pos) ) > 1 )
	{
		$("#linha_" + pos).remove()	
	}
	else
	{
		$("#linha_" + pos).find("input").val("")	
	}
}
function mudaDive(dive, divId, divId2){
	wdive = dive;
	wdiv = document.getElementById(divId);
	wdiv2 = document.getElementById(divId2);
	if(wdive == 'J'){
		wdiv.style.display = 'block';
		$("#cnpj").addClass("obrigatorio");
		$("#razao").addClass("obrigatorio");
	}else{
		wdiv.style.display = 'none';
		$("#cnpj").removeClass("obrigatorio");
		$("#razao").removeClass("obrigatorio");
	}
	if(wdive == 'F'){
		wdiv2.style.display = 'block';
		$("#cpf").addClass("obrigatorio")
	}else{
		wdiv2.style.display = 'none';
		$("#cpf").removeClass("obrigatorio")
	}
}

var posSelect = -1
var vetSelect = new Array();

function selecao(campo,posSelecao)
{
	this.campo = campo
	this.posSelecao = posSelecao		
		
}

fundoOption = new String()
corOption =  new String()
fundoOptionHover = new String()
corOptionHover =  new String()
function iniciaSelectPersonalizado(parametrosOptions)
{
	
	fundoOption = parametrosOptions[0]
	corOption = parametrosOptions[1]
	fundoOptionHover = parametrosOptions[2]
	corOptionHover =  parametrosOptions[3]
	
	$(".caixaTextSelect").show()
	$(".btnOpenSelect").show()
	$(".selectPersonalizado select").hide()
	for(i=0;i<$(".inputSelect").length;i++)
	{
		
		idElement = $(".inputSelect:eq("+ i +")").attr("id").replace("text_select_","") 
		for(y=0;y<$("#"+ idElement).find("option").length;y++)
		{
			if( $("#"+ idElement).find("option:eq("+ y +")").is(":selected") )
			{
				vetSelect[vetSelect.length] = new selecao(idElement,y)	
			}
		}
		$(".inputSelect:eq("+ i +")").val( $("#"+ idElement).find("option:selected").text() )
		//$("#"+ idElement).find("option:eq(0)").attr("selected","selected")
		
			
	}
	$(".inputSelect").keydown(function(event){

		
		if( event.keyCode == 38 || event.keyCode ==40 || event.keyCode ==116 || event.keyCode ==32 || event.keyCode ==13 || event.keyCode ==27 || event.keyCode ==9)
		{
		
			if( event.keyCode == 38 || event.keyCode ==40 )
			{
				if( event.keyCode == 40 )
				{
					if( $(".listSelect:visible").length > 0 )
					{
						posSelect = parseInt(posSelect)+1
						
						if( posSelect == $(".listSelect:visible").find(".option").length)
						{
							posSelect = 0
						}
					}
					else
					{
						$(this).click()
						//$(".listSelect:visible").find(".option:eq(0)").removeClass("selectOff")
						//$(".listSelect:visible").find(".option:eq(0)").addClass("selectOn")
						idList = $(this).attr("id")
						if( posicaoVetSelect(idList.replace("text_select_","")) < 0 )
						{
							posSelect = 0
							$(".listSelect:visible").find(".option").css("background",fundoOption).css("color",corOption)
							$(".listSelect:visible").find(".option:eq(0)").css("background",fundoOptionHover).css("color",corOptionHover)
							$(this).val($(".listSelect:visible").find(".option:eq(0)").text())
						}
						else
						{
							//$("#"+idList).find(".option:eq("+ posSelect +")").removeClass("selectOff")
							//$("#"+idList).find(".option:eq("+ posSelect +")").addClass("selectOn")
							$("#"+idList.replace("text_","")).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("text_select_",""))].posSelecao +")").css("background",fundoOptionHover).css("color",corOptionHover)
							$(this).val( $("#"+idList.replace("text_","")).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("text_select_",""))].posSelecao +")").text() )   
							posSelect = vetSelect[posicaoVetSelect(idList.replace("text_select_",""))].posSelecao
						}
						
					}
				}
				else
				{
					if( $(".listSelect:visible").length > 0 )
					{
						posSelect = parseInt(posSelect)-1
						if( posSelect < 0 )
						{
							posSelect = $(".listSelect:visible").find(".option").length-1
						}	
					}
				}	
				if( $(".listSelect:visible").length > 0 )
				{
					if( parseInt(posSelect%4) ==0 )
					{
						var divOffset = $(".listSelect:visible").offset().top;
						var pOffset = $(".listSelect:visible").find(".option:eq("+ posSelect +")").offset().top;
						var pScroll = pOffset - divOffset;
						$(".listSelect:visible").animate({scrollTop: '+='  + pScroll + 'px'}, 100);
					}
					//$(".listSelect .option").removeClass("selectOn")
					//$(".listSelect .option").addClass("selectOff") 
					$(".listSelect:visible").find(".option").css("background",fundoOption).css("color",corOption)					
					//$(".listSelect:visible").find(".option:eq("+ posSelect +")").removeClass("selectOff")
					//$(".listSelect:visible").find(".option:eq("+ posSelect +")").addClass("selectOn") 
					$(".listSelect:visible").find(".option:eq("+ posSelect +")").css("background",fundoOptionHover).css("color",corOptionHover)
					idUl = $(".listSelect:visible").attr("id")
					$("#"+ idUl.replace("select_","text_select_") ).val($(".listSelect:visible").find(".option:eq("+ posSelect +")").text())
					
				}
				event.returnValue = false;
				if (event.which){
					event.preventDefault();
				}
				return false;
				
				
			}
			else
			{
				if( event.keyCode ==32 || event.keyCode ==13 )
				{
					if( posSelect >=0 )
					{
						$(".listSelect:visible").find(".option:eq("+ posSelect +")").click()
					}
					event.returnValue = false;
				  	if (event.which){
						event.preventDefault();
				 	}
				  	return false;	
					
					
				}
				else
				{
					
					if( $(".listSelect:visible").length > 0 )
					{
						idList = $(this).attr("id")
						if( posicaoVetSelect(idList.replace("text_select_","")) < 0 )
						{
							posSelect = 0						
							$(this).val($(".listSelect:visible").find(".option:eq(0)").text())
						}
						else
						{
							//$("#"+idList).find(".option:eq("+ posSelect +")").removeClass("selectOff")
							//$("#"+idList).find(".option:eq("+ posSelect +")").addClass("selectOn")						
							$(this).val( $("#"+idList.replace("text_","")).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("text_select_",""))].posSelecao +")").text() )   
						}
					}
					$(".listSelect:visible").slideUp("hide")
					$("#fundoSelect").remove()	
					
				}
				
				//$(".listSelect .option").removeClass("selectOn")
				//$(".listSelect .option").addClass("selectOff")
				$(".listSelect .option").css("background",fundoOption).css("color",corOption)
			}
			
		
		}	
		else
		{
			event.returnValue = false;
			if (event.which){
			event.preventDefault();
			}
		}			
		
	});
	
	
	
	
	$(".listSelect .option").mouseover(function(){ 
		//$(".listSelect .option").removeClass("selectOn")
		//$(".listSelect .option").addClass("selectOff") 
		$(".listSelect .option").css("background",fundoOption).css("color",corOption)
		//$(".listSelect .option").css("background",fundoOptionHover).css("color",corOptionHover)
		//$(this).removeClass("selectOff")
		//$(this).addClass("selectOn") 
		$(this).css("background",fundoOptionHover).css("color",corOptionHover)
		idUl = $(".listSelect:visible").attr("id")
		$("#"+ idUl.replace("select_","text_select_") ).val($(this).text())
		for(i=0;i<$(".listSelect .option").length;i++)
		{
			if( $("#" + idUl + " .option:eq("+ i +")").attr("id").split("_")[1] == $(this).attr("id").split("_")[1] )
			{
				posSelect = i
				break;
			}
		}
	} )
	$(".listSelect .option").mouseout(function(){ 
		//$(this).removeClass("selectOn")
		//$(this).addClass("selectOff") 
		$(this).css("background",fundoOption).css("color",corOption)
	})
	var controleSelecao = ""
	$(".btnOpenSelect,.inputSelect").click(function(){
		controleBtnList = true
		idBtn= $(this).attr("id")
		idList = idBtn.replace("btn_","")
		idList = idList.replace("text_","")		
		
		setTimeout(function(){ $("#text_" + idList).focus() },300)
		if( $("#"+idList).is(":hidden") )
		{
			$("#fundoSelect").remove()
			$("<div id='fundoSelect'>&nbsp;</div>").appendTo("body").hide()	
			/*$("#fundoSelect").css("z-index",2)
			objF = document.getElementById("fundoSelect")
			objF.style.width = dimensoesTela().split("x")[0] + "px"
			objF.style.height = dimensoesTela().split("x")[1] + "px"*/
			
			
			//$(".listSelect .option").removeClass("selectOn")
			//$(".listSelect .option").addClass("selectOff")
			$(".listSelect .option").css("background",fundoOption).css("color",corOption)
			
			$("#fundoSelect").click(function(){
				//$(".listSelect .option").removeClass("selectOn")
				//$(".listSelect .option").addClass("selectOff")
				$(".listSelect .option").css("background",fundoOption).css("color",corOption)
				if( $(".listSelect:visible").length > 0 )
				{
					idList = $(".listSelect:visible").attr("id")
					
					if( posicaoVetSelect(idList.replace("select_","")) < 0 )
					{
						posSelect = -1
						$(".inputSelect").val($("#"+idList).find(".option:eq(0)").text())	
					}
					else
					{
						//$("#"+idList).find(".option:eq("+ posSelect +")").removeClass("selectOff")
						//$("#"+idList).find(".option:eq("+ posSelect +")").addClass("selectOn")
						$("#"+idList).find(".option:eq("+ posSelect +")").css("background",fundoOptionHover).css("color",corOptionHover)
						$("#text_"+ idList ).val( $("#"+idList).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("select_",""))].posSelecao +")").text() )   
					}
				}
				$(".listSelect").slideUp("hide")												
				$("#fundoSelect").remove()
			})
			$(".listSelect").slideUp("hide")
			
			idList = $("#"+idList).attr("id")
			$("#"+idList).slideDown("hide",function(){  				
				$("#fundoSelect").animate({
					opacity:'show',				   
					height: dimensoesTela().split("x")[1],
					width: dimensoesTela().split("x")[0]
				}, 200)
			})	
			if( posicaoVetSelect(idList.replace("select_","")) < 0 )
			{
				posSelect = -1				
				$("#text_"+idList).val( $(".listSelect:visible").find(".option:eq(0)").text() )	
			}
			else
			{
				posSelect = vetSelect[posicaoVetSelect(idList.replace("select_",""))].posSelecao
				//$("#"+idList).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("select_",""))].posSelecao +")").removeClass("selectOff")
				//$("#"+idList).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("select_",""))].posSelecao +")").addClass("selectOn")
				$("#"+idList).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("select_",""))].posSelecao +")").css("background",fundoOptionHover).css("color",corOptionHover)
				$("#text_"+ idList ).val( $("#"+idList).find(".option:eq("+ vetSelect[posicaoVetSelect(idList.replace("select_",""))].posSelecao +")").text() )   
			}
			
							
			
		}
		else
		{
			$("#"+idList).slideUp("hide")
			$("#text_"+ idList ).val( $(".listSelect:visible").find(".option:eq(0)").text() )
			
		}		
		
	})
	$(".listSelect .option").click(function(){
		idSelect = $(".listSelect:visible").attr("id")
		
		
		for(i=0;i<$(".listSelect:visible").find(".option").length;i++)
		{
			if( $(".listSelect:visible").find(".option:eq("+ i +")").attr("id").split("_")[1]	==  $(this).attr("id").split("_")[1] )
			{
				posSelect = i				
				break
			}
		}
		
		for(i=0;i<$("#" + idSelect.replace("select_","")).find('option').length;i++)
		{
			
			if( $("#" + idSelect.replace("select_","")).find("option:eq(" + i + ")").val() == $(this).attr("id").split("_")[1] )
			{
				
				$("#" + idSelect.replace("select_","")).find("option:eq(" + i + ")").attr("selected","selected")	
				$("#"+idSelect).slideUp("hide")
				$("#text_"+idSelect).val( $(this).text() )
				$("#btn_"+idSelect).blur()
				$("#fundoSelect").remove()
				
				if( posicaoVetSelect(idSelect.replace("select_","")) < 0 )
				{
					vetSelect[vetSelect.length] = new selecao(idSelect.replace("select_",""),posSelect)				
				}
				else
				{
					
					vetSelect[posicaoVetSelect(idSelect.replace("select_",""))].posSelecao = posSelect	
				}
				controleSelecao = $(this).text()
				break					
			}
		}	
		
	})
}
function posicaoVetSelect(campo)
{
	
	if( vetSelect.length > 0 )
	{
		posVet = -1
		for(i=0;i<vetSelect.length;i++)
		{
			
			if( vetSelect[i].campo == campo )
			{
				posVet = i
				break		
			}
		}
		return posVet
	}
	else
	{
		return -1
	}
}

var data_auxR = new Date;
var whoraR = data_auxR.getHours()

$(document).ready(function(){
	//alert(whoraR);
	if(whoraR >= 0 && whoraR <= 11){
		$("#horaRestrito").text("Bom dia!");
	}else if(whoraR >= 12 && whoraR <= 17){
		$("#horaRestrito").text("Boa tarde!");
	}else if(whoraR >= 18 && whoraR <= 23){
		$("#horaRestrito").text("Boa noite!");
	}
});

function carregaUrlExterna()
{
	$(".novaJanela").click(function(){
		wurl = $(this).attr("href")
		janelaExterna(wurl)
		return false
	})
}

function trocaPessoa(nomeCampo, divNormal, divOculta){
	if($("#"+nomeCampo).val() == "F"){
		//alert("F");
		$("#"+divNormal).show();
		$("#"+divOculta).hide();
		$("#razaosocial").removeClass("obrigatorio");
		$("#fantasia").removeClass("obrigatorio");
		$("#cnpj").removeClass("obrigatorio");
		$("#nome").addClass("obrigatorio");
		$("#cpf").addClass("obrigatorio");
	}
	
	if($("#"+nomeCampo).val() == "J"){
		//alert("J");
		$("#"+divNormal).show();
		$("#"+divOculta).hide();
		$("#razaosocial").addClass("obrigatorio");
		$("#fantasia").addClass("obrigatorio");
		$("#cnpj").addClass("obrigatorio");
		$("#nome").removeClass("obrigatorio");
		$("#cpf").removeClass("obrigatorio");
	}
}

function ocultaBarra(id)
{	
	div_canais = document.getElementById(id);
	var aux_class = div_canais.style.display;
	
	if (aux_class == "block")
	{
		$("#"+id).slideUp("normal");		
	}
	
	if (aux_class == "none")
	{
		$("#"+id).slideDown("normal");
	}
	
}

function ocultaBarra2(id)
{
	var wvar = id.split("_");
	idMenu = wvar[0];
	idSub = wvar[1];
	
	div_canais = document.getElementById(idSub);
	var aux_class = div_canais.style.display;
	
	if (aux_class == "block")
	{
		$("#"+idSub).slideUp("normal");
		//$("#"+idMenu+".menu").css("background-image", "url(imagens/fd-menua.png)");
		$("#"+idMenu).addClass("menuN");
		$("#"+idMenu).removeClass("menuN2");
		//$("#"+idMenu).css("color", "#383838");
	}
	
	if (aux_class == "none")
	{
		//$("#"+idMenu+".menu").css("background-image", "url(imagens/fd-menub.png)");
		//$("#"+idMenu).css("color", "#ffffff");
		$("#"+idMenu).addClass("menuN2");
		$("#"+idMenu).removeClass("menuN");
		$("#"+idSub).slideDown("normal");
	}
	
}

function ocultaBarra3(id)
{	
	div_canais = document.getElementById(id);
	var aux_class = div_canais.style.display;
	
	if($("#"+id).is(":visible")){
		$("#"+id).hide("slow");
	}else{
		$("#"+id).show("slow");
	}
}

function ocultaFaq(id)
{
	id_conteudo = id.split("_")[1];

	if( $("#"+ id_conteudo).is(":hidden") == true )
	{
		$("#"+id_conteudo).slideDown("normal");
		$("#"+id.replace("titulo","img")).attr("src","imagens/icon_menos.png")
	}
	else
	{
		$("#"+id_conteudo).slideUp("normal");
		$("#"+id.replace("titulo","img")).attr("src","imagens/icon_mais.png")
	}
}

function manipulaGarantiaPeca(tipo,posicao)
{
	if( tipo == "+" )
	{
		if( $("#variacao_descricao_"+posicao).val() != "" && $("#variacao_qtd_"+posicao).val() != "" && $("#variacao_codigo_"+posicao).val() != "")
		{
			$("#vari_"+(parseInt(posicao)+1)).show()
			$("#adic_"+posicao).hide()
		}
		else
		{
			var campo = ""
			if( $("#variacao_codigo_"+posicao).val() == "")
			{
				objFocus = $("#variacao_codigo_"+posicao)
				campo = "Código"
			}
			else
			{
				if( $("#variacao_qtd_"+posicao).val() == "")
				{
					objFocus = $("#variacao_qtd_"+posicao)	
					campo = "Quantidade"
				}	
				else
				{
					objFocus = $("#variacao_descricao_"+posicao)
					campo = "Descrição"
				}
			}
			alert("Preencha o campo " + campo + " para adicionar.")
		}
	}
	else
	{
		$("#vari_"+posicao).hide()
		$("#adic_"+(parseInt(posicao)-1)).show()
		$("#vari_"+posicao + " input").val("")
	}
}

function manipulaGarantiaFoto(tipo,posicao)
{
	if( tipo == "+" )
	{
		if( $("#variacao_foto_"+posicao).val() != "")
		{
			$("#vari_foto_"+(parseInt(posicao)+1)).show()
			$("#adic_foto_"+posicao).hide()
		}
		else
		{
			var campo = ""
			if( $("#variacao_foto_"+posicao).val() == "")
			{
				objFocus = $("#variacao_foto_"+posicao)
				campo = "Foto"
			}
			else
			{
			}
			alert("Preencha o campo " + campo + " para adicionar.")
		}
	}
	else
	{
		$("#vari_foto_"+posicao).hide()
		$("#adic_foto_"+(parseInt(posicao)-1)).show()
		$("#vari_foto_"+posicao + " input").val("")
	}
}

function manipulaFilhos(tipo,posicao)
{
	if( tipo == "+" )
	{
		if( $("#variacao_nome_"+posicao).val() != "" && $("#variacao_nasc_"+posicao).val() != "")
		{
			$("#vari_"+(parseInt(posicao)+1)).show()
			$("#adic_"+posicao).hide()
		}
		else
		{
			var campo = ""
			if( $("#variacao_nome_"+posicao).val() == "")
			{
				objFocus = $("#variacao_nome_"+posicao)
				campo = "Nome Filho"
			}
			else
			{
				if( $("#variacao_nasc_"+posicao).val() == "")
				{
					objFocus = $("#variacao_nasc_"+posicao)	
					campo = "Data de Nascimento Filho"
				}	
				else
				{
				}
			}
			alert("Preencha o campo " + campo + " para adicionar.")
		}
	}
	else
	{
		$("#vari_"+posicao).hide()
		$("#adic_"+(parseInt(posicao)-1)).show()
		$("#vari_"+posicao + " input").val("")
	}
}


function mostraCampo(dive, divId){
	wdive = dive;
	wdiv = document.getElementById(divId);
	if(wdive == '4'){
		wdiv.style.display = 'block';
		$("#funcaoQual").addClass("obrigatorio");
	}else{
		wdiv.style.display = 'none';
		$("#funcaoQual").removeClass("obrigatorio");
	}
}

function mostraCampoGrau(dive, divId){
	wdive = dive;
	wdiv = document.getElementById(divId);
	if(wdive == '1' || wdive == '2' || wdive == '3' || wdive == '4'){
		document.getElementById(divId+"1").style.display = 'none';
		document.getElementById(divId+"2").style.display = 'none';
		document.getElementById(divId+"3").style.display = 'none';
		$("#grauQual1").removeClass("obrigatorio");
		$("#grauQual2").removeClass("obrigatorio");
		$("#grauQual3").removeClass("obrigatorio");
	}else{
		if(wdive == '5')
		{
			document.getElementById(divId+"1").style.display = 'block';
			document.getElementById(divId+"2").style.display = 'none';
			document.getElementById(divId+"3").style.display = 'none';
			$("#grauQual1").addClass("obrigatorio");
			$("#grauQual2").removeClass("obrigatorio");
			$("#grauQual3").removeClass("obrigatorio");
		}
		if(wdive == '6')
		{
			document.getElementById(divId+"2").style.display = 'block';
			document.getElementById(divId+"1").style.display = 'none';
			document.getElementById(divId+"3").style.display = 'none';
			$("#grauQual2").addClass("obrigatorio");
			$("#grauQual1").removeClass("obrigatorio");
			$("#grauQual3").removeClass("obrigatorio");
		}
		if(wdive == '7')
		{
			document.getElementById(divId+"3").style.display = 'block';
			document.getElementById(divId+"1").style.display = 'none';
			document.getElementById(divId+"2").style.display = 'none';	
			$("#grauQual3").addClass("obrigatorio");
			$("#grauQual1").removeClass("obrigatorio");
			$("#grauQual2").removeClass("obrigatorio");
		}
	}
}


