// JavaScript Document

//Páginas: novoUsuarioIncrementha.asp

//Fábio Gonçalves Teixeira



//Funções Globais - usadas em mais de uma página --------------------------------------------------------------------------------



//Variáveis Globais

var intervalo

var contador = 0;



//-------------------------------------------------------------------------------------------------------------------------------

//Conceitos Ajax

try{

	xmlhttp = new XMLHttpRequest();

}catch(ee){

	try{

		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	}catch(e){

		try{

			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		}catch(E){

			xmlhttp = false;

		}

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function ajuda()

//Função que abre um tutorial com os tópicos de ajuda

function ajuda(){

	//alert('ajuda');

}



//-------------------------------------------------------------------------------------------------------------------------------

//function mudaCor(id, titulo, acao)

//Função que muda a cor da linha ao passar o mouse em cima

function mudaCor(id, valor, acao){

	

	var linha = document.getElementById(id);

	

	if(acao == 'acende'){

		linha.style.background = '#C8C8C8';

	}else if(acao == 'apaga'){

		

		if(parseInt(valor/2)*2 == valor){

			linha.style.background = '#EDEDED';

		}else{

			linha.style.background = '#FAFAFA';

		}

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function abreDoc(path)

//Função que abre o doc da idéia

function abreDoc(path){

	window.open(path,'','width=800,height=600,top=5,left=5,scrollbars=NO,Resizable=YES,statusbar=NO,menubar=NO');void(0);

}



//-------------------------------------------------------------------------------------------------------------------------------

//function isEmpty(pStrText)

//Função que verifica se uma variável passada por parâmetro está vazia. Incluindo espaços em branco

function isEmpty(pStrText){

	/*

	Fucntion: isEmpty

	Retorno : true se a string estiver vazia

	*/



	var len = pStrText.length;

	var pos;

	var vStrnewtext = "";

	

	for (pos=0; pos<len; pos++){

		if (pStrText.substring(pos, (pos+1)) != " ") vStrnewtext = vStrnewtext + pStrText.substring(pos, (pos+1));

	}

	

	if (vStrnewtext.length > 0)

		return false;

	else

		return true;

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaForm(frm)

//Função que valida os "textBox" de um formulário

function validaForm(frm, tipo){



	var inputs =  frm.getElementsByTagName('input');

	

	if(tipo == 'faleconosco'){

		

		for(var i=0; i < inputs.length; i++){

			if (inputs[i].value == '' && inputs[i].type == 'text' && inputs[i].id != 'empresa' && inputs[i].id != 'cargo' && inputs[i].id != 'interesse'){

				

				alert('O campo "'+ inputs[i].title +'" é de caracter obrigatório!');

				inputs[i].focus();

				return false;

				

			} else if(inputs[i].id != '' && inputs[i].id == 'DDDTelefone' || inputs[i].id == 'telefone'){

				if(!isNumeric(inputs[i])) return false;

			} else if (inputs[i].id == 'email'){

				if(!validaEmail(inputs[i])) return false;

			}



		}	

		

		if(frm.comentario.value == ''){

			alert('O campo Comentário é de caracter obrigatório!');

			frm.comentario.focus();

			return false;

		}



	}else if(tipo == 'novaRevenda'){

		

		for(var i=0; i < inputs.length; i++){

			if (inputs[i].value == '' && inputs[i].type == 'text' && inputs[i].id != 'DDDFax' && inputs[i].id != 'fax' && inputs[i].id != 'empresa1' && inputs[i].id != 'empresa2' && inputs[i].id != 'empresa3' && inputs[i].id != 'obs'){

				

				alert('O campo "'+ inputs[i].title +'" é de caracter obrigatório!');

				inputs[i].focus();

				return false;

				

			} else if (inputs[i].id == 'cnpj'){

				if(!validaCNPJ(inputs[i])) return false;

			} else if(inputs[i].id != '' && inputs[i].id == 'n' || inputs[i].id == 'DDDTelefone' || inputs[i].id == 'telefone' || inputs[i].id == 'DDDFax' || inputs[i].id == 'fax' || inputs[i].id == 'cep'  || inputs[i].id == 'DDDTelefoneDptoFinanceiro' || inputs[i].id == 'telefoneDptoFinanceiro' ){

				if(!isNumeric(inputs[i])) return false;

			} else if (inputs[i].id == 'email'){

				if(!validaEmail(inputs[i])) return false;

			}

		}

		

	}else if(tipo == 'RMA'){

		

		for(var i=0; i < inputs.length; i++){

			if (inputs[i].value == '' && inputs[i].type == 'text'){

				

				alert('O campo "'+ inputs[i].title +'" é de caracter obrigatório!');

				inputs[i].focus();

				return false;

				

			} else if (inputs[i].id == 'cnpj'){

				if(!validaCNPJ(inputs[i])) return false;

			} else if(inputs[i].id == 'n' || inputs[i].id == 'DDDTelefone' || inputs[i].id == 'telefone'){

				if(!isNumeric(inputs[i])) return false;

			} else if (inputs[i].id == 'email'){

				if(!validaEmail(inputs[i])) return false;

			} else if (inputs[i].id == 'inputNumProdutos'){

				if(!isNumeric(inputs[i])) return false;

			}

		}

	}else if(tipo == 'trabalheConosco'){

		for(var i=0; i < inputs.length; i++){

			if (inputs[i].value == '' && inputs[i].type == 'text'){

				

				alert('O campo "'+ inputs[i].title +'" é de caracter obrigatório!');

				inputs[i].focus();

				return false;

				

			}else if(inputs[i].id == 'DDDTelefone' || inputs[i].id == 'telefone'){

				if(!isNumeric(inputs[i])) return false;

			}

		}

	}else if(tipo == 'duvidaTecnica'){

		for(var i=0; i < inputs.length; i++){

			if (inputs[i].value == '' && inputs[i].type == 'text' && inputs[i].id != 'DDDFax' && inputs[i].id != 'fax' ){

				

				alert('O campo "'+ inputs[i].title +'" é de caracter obrigatório!');

				inputs[i].focus();

				return false;

				

			} else if(inputs[i].value != '' && inputs[i].id == 'DDDTelefone' || inputs[i].id == 'telefone' || inputs[i].id == 'DDDFax' || inputs[i].id == 'fax'){

				if(!isNumeric(inputs[i])) return false;

			} else if (inputs[i].id == 'email'){

				if(!validaEmail(inputs[i])) return false;

			} 

		}

		

		if(frm.duvidas.value == ''){

			alert('O campo "Duvidas" é de caracter obrigatório!');

			return false;

		}

		

	}else if(tipo == 'download'){

		for(var i=0; i < inputs.length; i++){

			if (inputs[i].value == '' && (inputs[i].type == 'text' || inputs[i].type == 'password')){

				

				alert('O campo "'+ inputs[i].title +'" é de caracter obrigatório!');

				inputs[i].focus();

				return false;

				

			}

		}

		

		frm.status.value = 'logon';

	}

	

	frm.form_enviado.value = true;

	return true;

}



//-------------------------------------------------------------------------------------------------------------------------------

//function valida(frm)

//Função que valida os "textBox" de um formulário

function valida(frm){

	

	var inputs =  frm.getElementsByTagName('input');

	

	for(var i=0; i < inputs.length; i++){

	

		if (inputs[i].value == '' && inputs[i].id != 'obs' && (inputs[i].type == 'text' || inputs[i].type == 'password')){

			alert('O campo "'+ inputs[i].title +'" é de caracter obrigatório!');

			inputs[i].focus();

			inputs[i].select();

			return false;

		}

    }

	

	//Se for "Parceiro" verifica se o campo "confirma senha" esta igual ao campo "senha"

	if(document.getElementById('tipo').value == 'parceiro'){

		if(document.getElementById('senha').value != document.getElementById('confirmaSenha').value){

			alert('Confirmação de Senha incorreta!\nDigite valores iguais nos campos "Senha" e "Confirme a Senha".');

			document.getElementById('confirmaSenha').focus();

			document.getElementById('confirmaSenha').select();

			return false;

		}

		

	//Se for "download" verifica 

	}else if(document.getElementById('tipo').value == 'download'){

		if(frm.arquivo.value == '' || frm.arquivo.value.indexOf(".") < 1){

			alert('O campo "Arquivo" esta em branco ou inválido!');

			frm.arquivo.focus();

			frm.arquivo.select();

			return false;

		}

	}

	

	document.getElementById('divFormulario').style.display = 'none';

	document.getElementById('divAguarde').style.display = 'block';

	

	frm.form_enviado.value = true;

	return true;

	

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaArquivo(frm)

//

function validaArquivo(frm){

	

	if(frm.arquivo.value == ''){

		alert('O campo "Arquivo" é de caracter obrigatório!');

		frm.arquivo.focus();

		return false;

	}



	document.getElementById('divFormulario').style.display = 'none';

	document.getElementById('divAguarde').style.display = 'block';

	

	frm.form_enviado.value = true;

	

	return true;

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaArquivo(frm)

//

function cancela(arq){

	

	if(arq > 0){

		document.getElementById('divArquivo').style.display = 'block';

		document.getElementById('divArquivoNone').style.display = 'none';

		document.getElementById('arquivo').value = '';

		document.getElementById('arquivo').style.display = 'none';

		document.getElementById('labelArquivo').style.display = 'block';

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaImg(this)

//Função que valida os "textBox" de um formulário

function validaImg(img, formulario){

	var valor = img.value.toLowerCase();

		

	if(valor.indexOf('.jpg') < 0 && valor.indexOf('.gif') < 0){

		alert('Coloque uma imagem com extensão .jpg ou .gif!');

		document.getElementById('Esquerda').disabled = true;

		document.getElementById('Direita').disabled = true;

		img.value = '';

		img.focus();

		return false;

	}else if(formulario == 'cadastro'){

		document.getElementById('Esquerda').disabled = false;

		document.getElementById('Esquerda').checked = true;

		document.getElementById('Direita').disabled = false;

		return true;

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function alinhaImg(id, tipo, lado)

//Função alinha a imagem

function alinhaImg(id, tipo, lado){

	/* Chama o arquivo ASP, passando os parametros pela URL */

	xmlhttp.open("GET", "../../funcao/asp/ras/fAlinhaImagem.asp?id="+id+"&tipo="+tipo+"&lado="+lado, true);

	xmlhttp.send(null);

	

	document.getElementById('imagem').className = 'img'+lado;

	document.getElementById('hiddenAlinhamentoImg').value = lado;

}



//-------------------------------------------------------------------------------------------------------------------------------

//function deleteImg(id, tipo)

//Função deleta a imagem

function deleteImg(id, tipo){

	if(intervalo == null){

		if(confirm('Deseja realmente remover esta imagem?')){

			xmlhttp.open("GET", "../../funcao/asp/ras/fManipulaImg.asp?id="+id+"&tipo="+tipo+"&acao=excluir", true);

			xmlhttp.send(null);

			

			intervalo = window.setInterval(fDeleteImg, 500);

			

			document.getElementById('divFormulario').style.display = 'none';

			document.getElementById('divAguarde').style.display = 'block';

		}

	}

}



function fDeleteImg(){

	

	contador++;

	

	if(xmlhttp.readyState == 4){

		clearInterval(intervalo);

		intervalo = null;

		

		var valorRetorno = xmlhttp.responseText;

		document.getElementById('Esquerda').disabled = true;

		document.getElementById('Direita').disabled = true;

		document.getElementById('imagem').style.display = 'none';

		document.getElementById('deleteImg').style.display = 'none';

		document.getElementById('addImg').style.display = 'block';



		document.getElementById('divFormulario').style.display = 'block';

		document.getElementById('divAguarde').style.display = 'none';

		

	}else if(contador >= 30){

		clearInterval(intervalo);

		intervalo = null;

		

		alert('Erro ao deletar a imagem!');

		contador = 0;

		document.getElementById('divFormulario').style.display = 'block';

		document.getElementById('divAguarde').style.display = 'none';

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function apareceInput()

//Função muda o display

function displayCampo(id){

	

	var display = document.getElementById(id).style.display;

	

	if(display == 'block'){

		document.getElementById(id).style.display = 'none'

	}else if(display == 'none'){	

		document.getElementById(id).style.display = 'block'

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function mudaStatus()

function mudaStatus(campo){



	if(campo.innerHTML == 'Adicionar Imagem'){

		campo.innerHTML = 'Cancelar';

				

	}else if(campo.innerHTML == 'Cancelar'){

		campo.innerHTML = 'Adicionar Imagem';

		document.getElementById('img').value = '';

		document.getElementById('Esquerda').disabled = true;

		document.getElementById('Direita').disabled = true;

	}

	

}



//-------------------------------------------------------------------------------------------------------------------------------

//function excluir(idUsuario, tipo, idLinha)

//Função que exclui um registro

function excluir(id, tipo, idLinha){

	var tabela;

	var msg;

	

	//Se o tipo for igual a "linha" muda msg

	if(tipo == 'linha'){

		msg = 'Todos os Produtos e Itens de produto desta Linha também serão excluidos!\nDeseja realmente excluir esta Linha?'

	}

	//Senão, se tipo for igual a "produto" muda msg

	else if(tipo == 'produto'){

		msg = 'Todos os Itens deste Produto também serão excluídos!\nDeseja realmente excluir este Produto?';

	}

	//Senão, se tipo for igual a "item" muda msg

	else if(tipo == 'item'){

		msg = 'Deseja realmente excluir este Item?';

	}

	//Senão, se tipo for igual a "parceiro" muda msg

	else if(tipo == 'parceiro'){

		msg = 'Deseja realmente excluir este Parceiro?';

	}

	//Senão, se tipo for igual a "download" muda msg

	else if(tipo == 'download'){

		msg = 'Deseja realmente excluir este Download?';

	}

	

	//Se o usuário confirmar a exclusão exclui

	if(confirm(msg)){

		

		/* Chama o arquivo ASP, passando os parametros pela URL */

		xmlhttp.open("GET", "../../funcao/asp/ras/fManipulaDados.asp?acao=excluir&tipo="+tipo+"&id="+id, true);

		xmlhttp.send(null);

		

		document.getElementById(idLinha).style.display = 'none';

		document.getElementById('nRegistros').value --;

		

		if(document.getElementById('nRegistros').value < 0){

			document.getElementById('tabela').innerHTML = '<tr><td><label class="labelCampos">Nenhum registro encontrado</label></td></tr>';

		}

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function alteraCampo(x, campo, tipo)

//

function alteraCampo(x, campo, tipo){

	

	var idLabel;

	var idInput;

	var valorLabel;

	

	if(tipo == 'linha'){

		if(campo == 'nome'){

			idLabel = 'labelLinhaNome'+x;

			idInput = 'inputValorNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelLinhaObs'+x;

			idInput = 'inputValorObs'+x;

		}else if(campo == 'descr'){

			idLabel = 'labelLinhaDescr'+x;

			idInput = 'inputValorDescr'+x;

		}

	}else if(tipo == 'produto'){

		if(campo == 'nome'){

			idLabel = 'labelProdNome'+x;

			idInput = 'inputValorNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelProdObs'+x;

			idInput = 'inputValorObs'+x;

		}else if(campo == 'descr'){

			idLabel = 'labelProdDescr'+x;

			idInput = 'inputValorDescr'+x;

		}

	}else if(tipo == 'item'){

		if(campo == 'nome'){

			idLabel = 'labelItemNome'+x;

			idInput = 'inputValorNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelItemObs'+x;

			idInput = 'inputValorObs'+x;

		}else if(campo == 'descr'){

			idLabel = 'labelItemDescr'+x;

			idInput = 'inputValorDescr'+x;

		}

	}else if(tipo == 'parceiro'){

		if(campo == 'nome'){

			idLabel = 'labelNome'+x;

			idInput = 'inputNome'+x;

		}else if(campo == 'login'){

			idLabel = 'labelLogin'+x;

			idInput = 'inputLogin'+x;

		}else if(campo == 'senha'){

			idLabel = 'labelSenha'+x;

			idInput = 'inputSenha'+x;

		}

	}else if(tipo == 'download'){

		if(campo == 'nome'){

			idLabel = 'labelNome'+x;

			idInput = 'inputNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelObs'+x;

			idInput = 'inputObs'+x;

		}else if(campo == 'arquivo'){

			

			idLabel = 'labelArquivo'+x;

			idInput = 'arquivo'+x;

			

			document.getElementById('divArquivo').style.display = 'none';

			document.getElementById('divArquivoNone').style.display = 'block';

			

		}else if(campo == 'descr'){

			idLabel = 'labelDescr'+x;

			idInput = 'inputDescr'+x;

		}

	}



	document.getElementById(idLabel).style.display = 'none';

	document.getElementById(idInput).style.display = 'block';

	document.getElementById(idInput).style.background = '#FFF';

	document.getElementById(idInput).select();

	document.getElementById(idInput).focus();

}



//-------------------------------------------------------------------------------------------------------------------------------

//function updValor(id, campo, tipo, x)

//

function updValor(id, campo, tipo, x){

	var idLabel;

	var idInput;

	var valorInput;

	var img;

	var InsereEnters;

	

	if(tipo == 'linha'){

		if(campo == 'nome'){

			idLabel = 'labelLinhaNome'+x;

			idInput = 'inputValorNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelLinhaObs'+x;

			idInput = 'inputValorObs'+x;

		}else if(campo == 'descr'){

			idLabel = 'labelLinhaDescr'+x;

			idInput = 'inputValorDescr'+x;

		}

	}else if(tipo == 'produto'){

		if(campo == 'nome'){

			idLabel = 'labelProdNome'+x;

			idInput = 'inputValorNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelProdObs'+x;

			idInput = 'inputValorObs'+x;

		}else if(campo == 'descr'){

			idLabel = 'labelProdDescr'+x;

			idInput = 'inputValorDescr'+x;

		}

	}else if(tipo == 'item'){

		if(campo == 'nome'){

			idLabel = 'labelItemNome'+x;

			idInput = 'inputValorNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelItemObs'+x;

			idInput = 'inputValorObs'+x;

		}else if(campo == 'descr'){

			idLabel = 'labelItemDescr'+x;

			idInput = 'inputValorDescr'+x;

		}

	}else if(tipo == 'parceiro'){

		if(campo == 'nome'){

			idLabel = 'labelNome'+x;

			idInput = 'inputNome'+x;

		}else if(campo == 'login'){

			idLabel = 'labelLogin'+x;

			idInput = 'inputLogin'+x;

		}else if(campo == 'senha'){

			idLabel = 'labelSenha'+x;

			idInput = 'inputSenha'+x;

		}

	}else if(tipo == 'download'){

		if(campo == 'nome'){

			idLabel = 'labelNome'+x;

			idInput = 'inputNome'+x;

		}else if(campo == 'obs'){

			idLabel = 'labelObs'+x;

			idInput = 'inputObs'+x;

		}else if(campo == 'descr'){

			idLabel = 'labelDescr'+x;

			idInput = 'inputDescr'+x;

		}

	}

	

	valorInput = document.getElementById(idInput).value;

	

	if(valorInput != ''){

		

		if(!document.all){

			//alert("Este browser não é Internet Explorer");

			InsereEnters = valorInput.replace(/\r|\n/g, "\r\n");

			valorInput = InsereEnters.replace(/\r\n/g, "<br />");

		}else{

			//alert("Este browser é Internet Explorer");

			valorInput = valorInput.replace(/\r\n/g, "<br />");

		}

		

		/* Chama o arquivo ASP, passando os parametros pela URL */

		xmlhttp.open("GET", "../../funcao/asp/ras/fManipulaDados.asp?acao=alterar&id="+id+"&valor="+valorInput+"&tipo="+tipo+"&campo="+campo, true);

		xmlhttp.send(null);

		

		if(tipo != 'parceiro' && tipo != 'download'){

			img = document.getElementById('hiddenImg').value;

			alinhamentoImg = document.getElementById('hiddenAlinhamentoImg').value;

			

			if(campo != 'nome' && img != '' && campo != 'obs'){

				valorInput = '<img src="/imagens/linhas/'+img+'" alt="Imagem"  id="imagem" class="img'+alinhamentoImg+'" />' + valorInput;

			}

		}

		

		if(campo == 'nome') document.getElementById('labelTextoInformativo').innerHTML = 'Detalhes do ' + tipo + ' ' + valorInput;

		document.getElementById(idLabel).innerHTML = valorInput;

	}else{

		alert('O valor não pode estar em branco!')

	}

	document.getElementById(idInput).style.display = 'none';

	document.getElementById(idLabel).style.display = 'block';

}



//-------------------------------------------------------------------------------------------------------------------------------

//function preencheSelectProdutos(selectLinhas)

//

function preencheSelectProdutos(selectCampo, pagina, tipo){

	if(intervalo == null){

		var id = selectCampo.value;

		document.getElementById('idLinha').value = id;

		document.getElementById('tdSelectProdutos').innerHTML = '<select id="selectProdutos" class="selectCampos"><option id="carregando" value="carregando">Carregando...</option></select>';

		

		if(pagina == 'download'){

			document.getElementById('radioLinha').checked = true;

			document.getElementById('tdSelectItens').innerHTML = '<select id="selectItens" class="selectCampos" disabled="disabled"><option id="item_0" value="0">Selecione um Produto</option></select>';

		}

		

		// Chama o arquivo ASP, passando os parametros pela URL

		xmlhttp.open("GET", "../../funcao/asp/ras/fPreencheSelect.asp?id="+id+"&pagina="+pagina+"&tipo="+tipo, true);

		xmlhttp.send(null);

		

		intervalo = window.setInterval(fPreencheSelectProdutos, 500);

	}

}



function fPreencheSelectProdutos(){

	if(xmlhttp.readyState == 4){

		clearInterval(intervalo);

		intervalo = null;

		

		var valorRetorno = xmlhttp.responseText;

		document.getElementById('tdSelectProdutos').innerHTML = valorRetorno;

		

		if(document.getElementById('tipo').value == 'download') habilita('linha');

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function preencheSelectProdutos(selectLinhas)

//

function preencheSelectItens(selectCampo, pagina, tipo){

	if(intervalo == null){

		var id = selectCampo.value;

		document.getElementById('idProduto').value = id;

		document.getElementById('tdSelectItens').innerHTML = '<select id="selectItens" class="selectCampos" disabled="disabled"><option id="carregando" value="carregando">Carregando...</option></select>';

		

		// Chama o arquivo ASP, passando os parametros pela URL

		xmlhttp.open("GET", "../../funcao/asp/ras/fPreencheSelect.asp?id="+id+"&pagina="+pagina+"&tipo="+tipo, true);

		xmlhttp.send(null);

		

		intervalo = window.setInterval(fPreencheSelectItens, 500);

	}

}



function fPreencheSelectItens(){

	if(xmlhttp.readyState == 4){

		clearInterval(intervalo);

		intervalo = null;

		

		var valorRetorno = xmlhttp.responseText;

		document.getElementById('tdSelectItens').innerHTML = valorRetorno;

		

		if(document.getElementById('tipo').value == 'download'){

			habilita('produto');

			document.getElementById('radioProduto').checked = true;

		}

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function addProdutoDefeituoso()

//Função que adiciona uma linha aos produtos defeituosos

function addProdutoDefeituoso(){

	

	var inputNumProdutos = document.getElementById('inputNumProdutos').value;

	var nProdutos = document.getElementById('nProdutos').value;

	

	if(inputNumProdutos != nProdutos){



		document.getElementById('nProdutos').value = inputNumProdutos;

		

		var conteudoTable = '';

		var i;

		

		if(inputNumProdutos == '' || isNaN(inputNumProdutos) || inputNumProdutos <= 0){

			

			alert('Valor inválido! Digite um número maior do que 0!');

			document.getElementById('inputNumProdutos').value = '1';

			document.getElementById('inputNumProdutos').focus();

			document.getElementById('inputNumProdutos').select();

			return;

			

		}else if(confirm('Todos as informações da tabela serão descartadas!\nDeseja realmente mudar o número de produtos?')){

			

			conteudoTable = 	'<table class="tabelaRMAProdutos" cellspacing="1" border="0">'+

								'	<tr class="tr">'+

								'		<td><label>Item</label></td>'+

								'		<td><label for="notaFiscal1">Nota Fiscal</label></td>'+

								'		<td><label for="dataNF1">Data NF</label></td>'+

								'		<td><label for="NSPeca1">N/S Da peça</label></td>'+

								'		<td><label for="defeito1">Defeito Apresentado</label></td>'+

								'	</tr>';

				

			for(i=0; i<inputNumProdutos; i++){

				

				conteudoTable +='	<tr class="tr">'+

								'		<td><label>'+(i+1)+'</label></td>'+

								'		<td><input type="text" name="notaFiscal'+(i+1)+'" id="notaFiscal'+(i+1)+'" title="Nota Fiscal '+(i+1)+'" class="inputRma" /></td>'+

								'		<td><input type="text" name="dataNF'+(i+1)+'" id="dataNF'+(i+1)+'" title="Data N/F '+(i+1)+'" class="inputRma" /></td>'+

								'		<td><input type="text" name="NSPeca'+(i+1)+'" id="NSPeca'+(i+1)+'" title="NS da Peça '+(i+1)+'" class="inputRma" /></td>'+

								'		<td><input type="text" name="defeito'+(i+1)+'" id="defeito'+(i+1)+'" title="Defeito do Produto '+(i+1)+'" class="inputRma" /></td>'+

								'	</tr>';

			}

			

			conteudoTable +=	'</table>';

			

			document.getElementById('divTableProdutos').innerHTML = conteudoTable;

		}

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaCNPJ(valor)

//Função que valida o cnpj informado

function validaCNPJ(campo) {

	CNPJ = campo.value;

	erro = new String;

	

	//Verifica se o campo tem valor

	if(campo.value.length != 0){

	

		//Verifica se o campo tem menos que 18 caracteres

		if (CNPJ.length < 18) erro += "Preencha corretamente o numero do CNPJ!\n Ex.:99.999.999/9999-99 \n\n";

		

		//Verifica se esta preenchido corretamente com os pontos, barra e hífen

		if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){

			if (erro.length == 0) erro += "Preencha corretamente o numero do CNPJ!\n Ex.:99.999.999/9999-99 \n\n";

		}

		

		//substituir os caracteres que nao sao numeros

		if(document.layers && parseInt(navigator.appVersion) == 4){

			x = CNPJ.substring(0,2);

			x += CNPJ.substring(3,6);

			x += CNPJ.substring(7,10);

			x += CNPJ.substring(11,15);

			x += CNPJ.substring(16,18);

			CNPJ = x;

		} else {

			CNPJ = CNPJ.replace(".","");

			CNPJ = CNPJ.replace(".","");

			CNPJ = CNPJ.replace("-","");

			CNPJ = CNPJ.replace("/","");

		}

		

		var nonNumbers = /\D/;

		

		if (nonNumbers.test(CNPJ)) erro += "O CNPJ deve conter apenas numeros! \n\n";

		

		var a = [];

		var b = new Number;

		var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];

		

		for (i=0; i<12; i++){

			a[i] = CNPJ.charAt(i);

			b += a[i] * c[i+1];

		}

	

		if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }

		

		b = 0;

			

		for (y=0; y<13; y++) {

			b += (a[y] * c[y]);

		}

		

		if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }

		

		if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){

			erro +="Digito verificador inválido!";

		}

	

		if (erro.length > 0){

			alert(erro);

			campo.focus();

			campo.select();

			return false;

		}

		

		return true;

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaEmail(campo)

//Função que valida o e-mail informado

function validaEmail(campo) {

	//A = @

	var A 					= campo.value.indexOf('@');

	var AA 					= campo.value.indexOf('@', A + 1) != -1;

	var ponto 				= campo.value.indexOf(".") < 1;

	var espaco 				= campo.value.indexOf(" ") != -1;

	var xxx 				= campo.value.indexOf("zipmeil.com") > 0;

	var xxx2 				= campo.value.indexOf("hotmeil.com") > 0;

	var pontoAntesDoA 		= campo.value.indexOf(".@") > 0;

	var pontoDepoisDoA 		= campo.value.indexOf("@.") > 0;

	var pontoDepoisDoBr 	= campo.value.indexOf(".com.br.") > 0;

	var barra 				= campo.value.indexOf("/") > 0;

	var abreColchete 		= campo.value.indexOf("[") > 0;

	var fechaColchete 		= campo.value.indexOf("]") > 0;

	var abreParentese 		= campo.value.indexOf("(") > 0;

	var fechaParentese 		= campo.value.indexOf(")") > 0;

	var pontoConsecutivo 	= campo.value.indexOf("..") > 0;

	var aspas				= campo.value.indexOf('"') > 0;

	

	if(A < 2 || AA || ponto || espaco || pontoAntesDoA || pontoDepoisDoA || pontoDepoisDoBr || barra || abreColchete || fechaColchete || abreParentese || fechaParentese || pontoConsecutivo || aspas) {

		alert("Preencha corretamente o E-mail!\nEx.: nome@provedor.com.br");

		campo.focus();

		campo.select();

		return false;

	}

	

	return true;

}



//-------------------------------------------------------------------------------------------------------------------------------

//function isNumeric(campo)

//Verifica se o valor do campo é numérico

function isNumeric(campo){

	

	if(isNaN(campo.value) || campo.value.indexOf("-") > -1 || campo.value.indexOf("+") > -1) {

		alert('O campo "'+campo.title+'" esta incorreto!\nDigite apenas números.' )

		campo.focus();

		campo.select();

		return false;

	}



	return true;

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaEmail(campo)

//Função que valida o e-mail informado

function habilita(tipo){

	if(tipo == 'nenhum'){

		document.getElementById('selectLinhas').disabled = true;

		document.getElementById('selectProdutos').disabled = true;

		document.getElementById('selectItens').disabled = true;

		document.getElementById('idLinha').value = 0;

	}else if(tipo == 'linha'){

		document.getElementById('selectLinhas').disabled = false;

		document.getElementById('selectProdutos').disabled = true;

		document.getElementById('selectItens').disabled = true;

		document.getElementById('idLinha').value = document.getElementById('selectLinhas').value;

	}else if(tipo == 'produto'){

		document.getElementById('selectProdutos').disabled = false;

		document.getElementById('selectItens').disabled = true;

		document.getElementById('idProduto').value = document.getElementById('selectProdutos').value;

	}else if(tipo == 'item'){

		document.getElementById('selectProdutos').disabled = false;

		document.getElementById('selectItens').disabled = false;

		document.getElementById('idItem').value = document.getElementById('selectItens').value;

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function validaEmail(campo)

//Função que valida o e-mail informado

function download(arquivo){

	if(arquivo.length > 0) document.location.href = "/versao/pt/areaTecnica/arquivos/" + arquivo;

}



//-------------------------------------------------------------------------------------------------------------------------------

//function buscar(valor)

//Função busca uma palavra no site e no bd

function buscar(valor){

	if(intervalo == null){

		document.getElementById('conteudoMeio').style.visibility = 'hidden';

		document.getElementById('meio').innerHTML += '<img src="/imagens/aguarde.gif" alt="" id="aguarde" style="position:absolute; top:155px; left:255px; opacity:1; filter:alpha(opacity=100); z-index:50;" />';

												

		// Chama o arquivo ASP, passando os parametros pela URL

		xmlhttp.open("GET", "/fBuscar.asp?valorBuscar="+valor, true);

		xmlhttp.send(null);

		

		intervalo = window.setInterval(fPreencheConteudo, 500);

	}

}



//-------------------------------------------------------------------------------------------------------------------------------

//function mudaVisibilidade(c)

//???

function mudaVisibilidade(c){

	document.getElementById(c).style.visibility = (document.getElementById(c).style.visibility == 'hidden') ? 'visible' : 'hidden';

}



//-------------------------------------------------------------------------------------------------------------------------------

//

//

function conteudo(pagina){

	if(intervalo == null){

		var path;

	

		document.getElementById('conteudoMeio').style.visibility = 'hidden';

		document.getElementById('meio').innerHTML += '<img src="/imagens/aguarde.gif" alt="" id="aguarde" style="position:absolute; top:155px; left:255px; opacity:1; filter:alpha(opacity=100); z-index:50;" />';

	

		if(pagina == 'perfil' || pagina == 'trabalheConosco' || pagina == 'parceria'){

			path = '/versao/pt/sobre/conteudo.asp?pagina='+pagina;

		}else if(pagina == 'novaRevenda' || pagina == 'rma' || pagina == 'duvidaTecnica' || pagina == 'download'){

			path = '/versao/pt/areaTecnica/conteudo.asp?pagina='+pagina;

		}else if(pagina == 'home' || pagina == 'mapa' || pagina == 'faleConosco'){

			path = '/conteudo.asp?pagina='+pagina;

		}

	

		// Chama o arquivo ASP, passando os parametros pela URL

		xmlhttp.open("GET", path, true);

		xmlhttp.setRequestHeader("encoding", "ISO-8859-1"); 

		xmlhttp.send(null);

		intervalo = window.setInterval(fPreencheConteudo, 500);

	}

}



function conteudoLinha(tipo, idLinha){

	if(intervalo == null){

		var path;

		

		document.getElementById('conteudoMeio').style.visibility = 'hidden';

		document.getElementById('meio').innerHTML += '<img src="/imagens/aguarde.gif" alt="" id="aguarde" style="position:absolute; top:155px; left:255px; opacity:1; filter:alpha(opacity=100); z-index:50;" />';

		

		// Chama o arquivo ASP, passando os parametros pela URL

		xmlhttp.open("GET", '/versao/pt/Produtos/conteudo.asp?tipo='+tipo+'&idLinha='+idLinha, true);

		xmlhttp.setRequestHeader("encoding", "ISO-8859-1"); 

		xmlhttp.send(null);

		intervalo = window.setInterval(fPreencheConteudo, 500);

	}

}



function conteudoProduto(tipo, idLinha, idProduto){

	if(intervalo == null){

		var path;

		

		document.getElementById('conteudoMeio').style.visibility = 'hidden';

		document.getElementById('meio').innerHTML += '<img src="/imagens/aguarde.gif" alt="" id="aguarde" style="position:absolute; top:155px; left:255px; opacity:1; filter:alpha(opacity=100); z-index:50;" />';

		

		// Chama o arquivo ASP, passando os parametros pela URL

		xmlhttp.open("GET", '/versao/pt/Produtos/conteudo.asp?tipo='+tipo+'&idLinha='+idLinha+'&idProduto='+idProduto, true);

		xmlhttp.setRequestHeader("encoding", "ISO-8859-1"); 

		xmlhttp.send(null);

		intervalo = window.setInterval(fPreencheConteudo, 500);

	}

}



function conteudoItem(tipo, idLinha, idProduto, idItem){

	if(intervalo == null){

		var path;

		

		document.getElementById('conteudoMeio').style.visibility = 'hidden';

		document.getElementById('meio').innerHTML += '<img src="/imagens/aguarde.gif" alt="" id="aguarde" style="position:absolute; top:155px; left:255px; opacity:1; filter:alpha(opacity=100); z-index:50;" />';

		

		// Chama o arquivo ASP, passando os parametros pela URL

		xmlhttp.open("GET", '/versao/pt/Produtos/conteudo.asp?tipo='+tipo+'&idLinha='+idLinha+'&idProduto='+idProduto+'&idItem='+idItem, true);

		xmlhttp.setRequestHeader("encoding", "ISO-8859-1"); 

		xmlhttp.send(null);

		intervalo = window.setInterval(fPreencheConteudo, 500);

	}

}





function fPreencheConteudo(){

	if(xmlhttp.readyState == 4){

		clearInterval(intervalo);

		intervalo = null;

		var valorRetorno = xmlhttp.responseText;

		document.getElementById('meio').innerHTML = '<div id="conteudoMeio">'+valorRetorno+'</div>';

	}

}



function txtBoxFormat(objeto, sMask, evtKeyPress) {

	var nTecla;

		

	if(document.all){

		nTecla = evtKeyPress.keyCode;

	}else if(document.layers){

		nTecla = evtKeyPress.which;

	}

	

	sValue = objeto.value;

	

	// Limpa todos os caracteres de formatacao que ja estiverem no campo.

	sValue = sValue.toString().replace( "-", "" );

	sValue = sValue.toString().replace( "-", "" );

	sValue = sValue.toString().replace( ".", "" );

	sValue = sValue.toString().replace( ".", "" );

	sValue = sValue.toString().replace( "/", "" );

	sValue = sValue.toString().replace( "/", "" );

	sValue = sValue.toString().replace( ":", "" );

	sValue = sValue.toString().replace( ":", "" );

	sValue = sValue.toString().replace( "(", "" );

	sValue = sValue.toString().replace( "(", "" );

	sValue = sValue.toString().replace( ")", "" );

	sValue = sValue.toString().replace( ")", "" );

	sValue = sValue.toString().replace( " ", "" );

	sValue = sValue.toString().replace( " ", "" );

	

	fldLen = sValue.length;

	mskLen = sMask.length;

	i = 0;

	nCount = 0;

	sCod = "";

	mskLen = fldLen;

	

	while (i <= mskLen) {

		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))

		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

	

		if (bolMask){

			sCod += sMask.charAt(i);

			mskLen++; 

		}else{

			sCod += sValue.charAt(nCount);

			nCount++;

		}

		

		i++;

	}

	

	objeto.value = sCod;

	

	if (nTecla != 8) { // backspace

		if (sMask.charAt(i-1) == "9") { // apenas números...

			return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9

		else { // qualquer caracter...

			return true;

		}

	}else{

		return true;

	}

}



function validaNoticia(frm){

	var msg = 'Preencha corretamente os campos obrigatórios\n';

	var erro = false;

	

	if(frm.titulo.value == ''){

		msg += ' - Título da notícia\n';

		if(!erro){

			erro = true;

			frm.titulo.focus();

		}

	}

	if(frm.reportagem.value == ''){

		msg += ' - Texto da reportagem\n';

		if(!erro){

			erro = true;

			frm.reportagem.focus();

		}

	}

	if(frm.imagem.value != ''){

		var extensao = frm.imagem.value;

		// paramos aqui

		msg += ' - Texto da reportagem\n';

		if(!erro){

			erro = true;

			frm.reportagem.focus();

		}

	}



	if(erro){

		alert(msg);

		return false;

	}else{

		return true;

	 }



}

//function updNoticias(idNoticias)

function updNoticias(idNoticia){

	document.getElementById('acao').value = 'alterarNoticias';

	document.getElementById('idNoticia').value = idNoticia;

	document.form.submit();

}



//function delNoticias(idNews)

function delNoticias(idNoticias){

	if(confirm('Deseja realmente excluir esta notícia?')){

		document.getElementById('acao').value = 'deletarNoticias';

		document.getElementById('idNoticia').value = idNoticias;

		document.form.action = 'procDados.asp';

		document.form.submit();

	}	

}


