function JanelaProduto(JanelaProduto){
window.open("minhas_compras-adiciona.php?codigo_produto="+JanelaProduto,"JanelaProduto","top=" + parseInt((screen.availHeight/2) - (563/2))+ " , left=" + parseInt((screen.availWidth/2) - (750/2)) + " directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, width=150, height=100");
}
function JanelaFornecedor(JanelaFornecedor){
window.open("minhas_compras-adiciona-fornecedor.php?novo_codigo_fornecedor="+JanelaFornecedor,"JanelaProduto","top=" + parseInt((screen.availHeight/2) - (563/2))+ " , left=" + parseInt((screen.availWidth/2) - (750/2)) + " directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, width=150, height=100");
}
function JanelaQtde(JanelaQtde){
window.open("minhas_compras-qtde.php?codigo_carrinho="+JanelaQtde,"JanelaQtde","top=" + parseInt((screen.availHeight/2) - (563/2))+ " , left=" + parseInt((screen.availWidth/2) - (750/2)) + " directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, width=300, height=200");
}
function JanelaExcluir(JanelaExcluir){
window.open("minhas_compras-excluir.php?codigo_carrinho="+JanelaExcluir,"JanelaExcluir","top=" + parseInt((screen.availHeight/2) - (563/2))+ " , left=" + parseInt((screen.availWidth/2) - (750/2)) + " directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, width=150, height=100");
}
function PedidoImprimir(CodigoPedido,CodigoFornecedor,CodigoCliente,CodigoVendedor,Data){
window.open("pedidos-imprimir.php?metodo=&unica=1-"+CodigoPedido+",2-"+CodigoFornecedor+",3-"+CodigoCliente+",4-"+CodigoVendedor+",5-"+Data,"PedidoImprimir","top=" + parseInt((screen.availHeight/2) - (563/2))+ " , left=" + parseInt((screen.availWidth/2) - (750/2)) + " directories=no, location=no, menubar=yes, resizable=yes, scrollbars=yes, status=no, titlebar=yes, toolbar=yes, width=730, height=400");
}


function EnviarContato(){

var erro = "0";
var nome = document.FormContato.nome.value;
var assunto = document.FormContato.assunto.value;
var mensagem = document.FormContato.mensagem.value;
var msg_erro = "";



if (nome == ""){
erro = "1";
msg_erro = msg_erro + "O preenchimento do NOME é obrigatório \n\n";
}

if (assunto == ""){
erro = "1";
msg_erro = msg_erro + "O preenchimento do ASSUNTO é obrigatório \n\n";
}

if (mensagem == ""){
erro = "1";
msg_erro = msg_erro + "O preenchimento do MENSAGEM é obrigatório \n\n";
}


if (erro != 0){
alert(msg_erro);
} else {
document.FormContato.submit();
}


}


function ValidaLogin(){

var erro = "0";
var cnpj = document.form.cnpj.value;
var senha = document.form.senha.value;
var msg_erro = "";

if(cnpj.length != 14){
erro = "1";
msg_erro = msg_erro + "Preencha o CNPJ corretamente \n\n";
} else {
		valida = Calc_CNPJ(cnpj);			
		if(!valida){
		erro = "1";
		msg_erro = msg_erro + "Preencha o CNPJ corretamente \n\n";
		}
}

if (senha == "" || senha.length < 4){
erro = "1";
msg_erro = msg_erro + "A senha deve ter no mínimo 4 caracteres \n\n";
}


if (erro != 0){
alert(msg_erro);
} else {
document.form.submit();
}


}



function ValidaCNPJ(){

var erro = "0";
var cnpj = document.form.cnpj.value;
var msg_erro = "";

if(cnpj.length != 14){
erro = "1";
msg_erro = msg_erro + "Preencha o CNPJ corretamente \n\n";
} else {
		valida = Calc_CNPJ(cnpj);			
		if(!valida){
		erro = "1";
		msg_erro = msg_erro + "Preencha o CNPJ corretamente \n\n";
		}
}

if (erro != 0){
alert(msg_erro);
} else {
document.form.submit();
}

}



function ValidaCadastroSenha(){

var erro = "0";
var senha = document.form.senha.value;
var conf_senha = document.form.conf_senha.value;
var msg_erro = "";

if (senha == "" || senha.length < 4){
erro = "1";
msg_erro = msg_erro + "A senha deve ter no mínimo 6 caracteres \n\n";
}

if (senha != conf_senha){
erro = "1";
msg_erro = msg_erro + "O campo SENHA e CONFIRMAÇÃO DE SENHA deve ter a mesma senha \n\n";
}

if (erro != 0){
alert(msg_erro);
} else {
document.form.submit();
}

}




function CalculaValorQtde(){

var qtde = document.form.qtde.value;
var valor_unitario = document.form.valor_unitario.value;
var valor_total = (qtde*valor_unitario);
valor_total = valor_total + ".00";
var partes = valor_total.split(".");
var valor1 = partes[0];
digitos = partes[1].substring(0,2);
if (digitos.length == 1){ digitos += "0"; }
valor_formatado = valor1 + "." + digitos;
document.form.valor_total.value = valor_formatado;

}



function ValidaQtde(){

var erro = "0";
var qtde = document.form.qtde.value;
var msg_erro = "";

if (qtde == "" || qtde <= 0){
erro = "1";
msg_erro = msg_erro + "Preencha a QUANTIDADE corretamente \n\n";
}

if (erro != 0){
alert(msg_erro);
} else {
document.form.submit();
}

}





function evita_letra(tecla) {
//	alert(tecla.keyCode );
	if ((tecla.keyCode < 48 || tecla.keyCode > 57)){
	tecla.returnValue = false;
	}
}



function FormataValor(tammax,teclapres, tf) {
// formata os campos com a máscara valor

	var tecla = teclapres.keyCode;

	vr = tf.value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){
	tam = vr.length + 1 ;
	}

	if (tecla == 8 ){
	tam = tam - 1 ;
	}

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){

		if ( tam <= 2 ){
 		tf.value = vr ;
		 }

 		if ( (tam > 2) && (tam <= 5) ){
		tf.value = vr.substr( 0, tam - 2 ) + '.' + vr.substr( tam - 2, tam ) ;
		}

	 	if ( (tam >= 6) && (tam <= 8) ){
 		tf.value = vr.substr( 0, tam - 5 ) + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ;
		}

	 	if ( (tam >= 9) && (tam <= 11) ){
 		tf.value = vr.substr( 0, tam - 8 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ;
		}

	 	if ( (tam >= 12) && (tam <= 14) ){
 		tf.value = vr.substr( 0, tam - 11 ) + vr.substr( tam - 11, 3 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ;
		}

	 	if ( (tam >= 15) && (tam <= 17) ){
		tf.value = vr.substr( 0, tam - 14 ) + vr.substr( tam - 14, 3 ) + vr.substr( tam - 11, 3 ) + vr.substr( tam - 8, 3 ) + vr.substr( tam - 5, 3 ) + '.' + vr.substr( tam - 2, tam ) ;
		}
	}
}





//Função para varificar o CNPJ ***************************************************************************
function Calc_CNPJ(Valor){
var Mult1 = '';
var Mult2 = '';
var dig1 = 0;
var dig2 = 0;
var Y;
var retorno = true;
Mult1 = '543298765432';
Mult2 = '6543298765432';
	

   if((Valor.indexOf('111111111') >= 0)||(Valor=='')||(Valor.substring(0,3)==Valor.substring(4,7))){
		retorno = false;
   }
   else{
		Y=0;
		for(X=0;X<=11;X++){
			Y++;
		    dig1 += Valor.substring(X, Y) * Mult1.substring(X, Y);
		}

		Y=0;
		for(X=0;X<=12;X++){
			Y++;
			dig2 += Valor.substring(X, Y) * Mult2.substring(X, Y);
		}

		dig1 = (dig1 * 10) % 11;
		dig2 = (dig2 * 10) % 11;

		if(dig1 == 10) { dig1 = 0 }
		if(dig2 == 10) { dig2 = 0 }

		if(dig1 != Valor.substring(12, 13)) { retorno = false }
		if(dig2 != Valor.substring(13, 14)) { retorno = false }
   }

return retorno;
}
//Fim *********************************************************************************************