// JavaScript Document

	function dadospedido(id){
		opcao = 'op'+id
		if (document.getElementById(id).style.display=='none') {
			document.getElementById(id).style.display = "" ;
			document.getElementById(opcao).style.display = "none" ;
		}else
		{
			document.getElementById(id).style.display = "none" ;
			document.getElementById(opcao).style.display = "" ;
		}
	}
	function logar(){	
		usuario = document.getElementById('usuario').value; 
		senha = document.getElementById('senha').value; 
		ajaxHTML('meusdados','includes/login.asp?acao=login&usuario='+usuario+'&senha='+senha);	
		window.location.href = window.location.pathname;
	}
	
	function detalhes(id){	
		ajaxHTML('listaproduto','includes/detalheproduto.asp?id='+id);	
	}	
	
	function logout(){
		ajaxHTML('meusdados','includes/login.asp?acao=logout');
		window.location.href='index.asp';
	}
	

//Formata campos formulário
function txtBoxFormat(strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode; 
	}
	else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	} 
	else if(document.getElementById) { // FireFox
		nTecla = evtKeyPress.which;
	}
	
	if ((nTecla != 8) && (nTecla != 0)){ 
	
	sValue = document.getElementById(strField).value;
	
	// Limpa todos os caracteres de formatação que
	// já 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( ":", "" );
	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) == "/"))
	bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
	bolMask = bolMask || (sMask.charAt(i) == ":")
	
	if (bolMask) {
	sCod += sMask.charAt(i);
	mskLen++; }
	else {
	sCod += sValue.charAt(nCount);
	nCount++;
	}
	
	i++;
	}
	
	//objForm[strField].value = sCod;
	document.getElementById(strField).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 TestaSenha(valor) {
  	var d = document.getElementById('seguranca');
  	ERaz = /[a-z]/;
  	ERAZ = /[A-Z]/;
  	ER09 = /[0-9]/;
  	ERxx = /[@!#$%&*+=?|-]/;
  
  	if(valor.length == ''){
  		d.innerHTML = 'For&ccedil;a da Senha: ';
		document.getElementById('barrasenha').style.backgroundColor= "#CCC";
  	} else {
  		if(valor.length < 5){
  			d.innerHTML = 'For&ccedil;a da Senha:<font color=\'red\'> Baixa</font>';
			document.getElementById('barrasenha').style.backgroundColor= "#F00";
  		} else {
  			if(valor.length > 7 && valor.search(ERaz) != -1 && valor.search(ERAZ)
			  != -1 && valor.search(ER09) != -1 || valor.length > 7 &&
			  valor.search(ERaz) != -1 && valor.search(ERAZ) != -1 &&
			  valor.search(ERxx) || valor.length > 7 && valor.search(ERaz) != -1 &&
			  valor.search(ERxx) != -1 && valor.search(ER09) || valor.length > 7  &&
			  valor.search(ERxx) != -1 && valor.search(ERAZ) != -1 &&
			  valor.search(ER09)){
  				d.innerHTML = 'For&ccedil;a da Senha:<font color=\'green\'> Relevante</font>';
				document.getElementById('barrasenha').style.backgroundColor= "#090";
  			} else {
  				if(valor.search(ERaz) != -1 && valor.search(ERAZ) != -1 ||
				  valor.search(ERaz) != -1 && valor.search(ER09) != -1 ||
				  valor.search(ERaz) != -1 && valor.search(ERxx) != -1
				  ||valor.search(ERAZ) != -1 && valor.search(ER09) != -1
				  ||valor.search(ERAZ) != -1 && valor.search(ERxx) != -1
				  ||valor.search(ER09) != -1 && valor.search(ERxx) != -1){
  					d.innerHTML = 'For&ccedil;a da Senha:<font color=\'orange\'> Média</font>';
					document.getElementById('barrasenha').style.backgroundColor= "#F90";
  				} else {
  					d.innerHTML = 'For&ccedil;a da Senha:<font color=\'red\'> Baixa</font>';
					document.getElementById('barrasenha').style.backgroundColor= "#F00";					
  				}
  			}
  		}
  	}
  }

			function Entrar() {
				//document.frLogin.action = "http://lssistemas.no-ip.org/owagenda/checklogin.asp";
				//document.frLogin.method = "post";
				document.frLogin.submit();
			}
			
			/*function KeyPress() {
				var key = window.event.keyCode;
				
				if (key == 13) {
					Entrar();
				}
			}*/
//////////////////////////////////////////////////////////////////////////
function MascaraNSerie(keypress, objeto) {
	campo = eval(objeto);
	caracteres = '01234567890';
	
	if (caracteres.indexOf(String.fromCharCode(keypress)) != -1) {
		if (campo.value.length == 6)
			campo.value = campo.value + '-';
	}
	else
		event.returnValue = false;
					
}

function MascaraCPF(keypress, objeto) {
	campo = eval(objeto);
	caracteres = '01234567890';
		
	if (caracteres.indexOf(String.fromCharCode(keypress)) != -1) {
		if ((campo.value.length == 3) || (campo.value.length == 7))
			campo.value = campo.value + '.';
		else if (campo.value.length == 11)
			campo.value = campo.value + '-';
	}
	else
		event.returnValue = false;
}

function MascaraCEP (keypress, objeto) {
	campo= eval(objeto);
	caracteres = '01234567890';
	separacoes = 1;
	separacao1 = '-';
	conjuntos = 2;
	conjunto1 = 5;
	conjunto2 = 3;
	if ((caracteres.indexOf(String.fromCharCode (keypress))!=-1) && campo.value.length < (conjunto1 + conjunto2 + 1)) {
		if (campo.value.length == conjunto1) 
		   campo.value = campo.value + separacao1;
	}
	else 
		event.returnValue = false;
}

function MascaraCNPJ(keypress, objeto) {
	campo = eval(objeto);
	caracteres = '01234567890';
		
	if (caracteres.indexOf(String.fromCharCode(keypress)) != -1) {
		if ((campo.value.length == 2) || (campo.value.length == 6))
			campo.value = campo.value + '.';
		else if (campo.value.length == 10)
			campo.value = campo.value + '\\';
		else if (campo.value.length == 15)
			campo.value = campo.value + '-';
	}
	else
		event.returnValue = false;
}
function MascaraNumeroReal(keypress, objeto) {
	campo = eval(objeto);
	caracteres = '0123456789';
	separadores = '.,';
		
	var ch = String.fromCharCode(keypress);
				
	if (ch == '.') {
		ch = ',';
		event.keyCode = 44;
	}
		
	if (ch == ',') {
		if ((campo.value.length == 0) ||
			(campo.value.indexOf(',') != -1))
			event.returnValue = false;
	}
	else {
		if (caracteres.indexOf(ch) == -1)
			event.returnValue = false;
	}
}
function MascaraNumero(keypress, objeto) {
	campo = eval(objeto);
	caracteres = '0123456789';
	
	if (caracteres.indexOf(String.fromCharCode(keypress)) == -1)
		event.returnValue = false;		
}

function ValidaNumeroReal(objeto, numero_casas_decimais) {
	campo = eval(objeto);
	x = campo.value;
		
	i = x.indexOf(',');
		
	if (i != -1) {
		s = x.substring(i+1, x.length)
			
		// verifica se o número de casas decimais é entre 1 e 2
		if (s.length > numero_casas_decimais) {
			alert('Valor inválido. Número de casas decimais ultrapassou o limite de [' + numero_casas_decimais + ']');
			event.srcElement.focus();
			event.srcElement.select();
		}	
		else if (s.length < 1) {
			alert('Valor inválido. O número possui vírgula porém não possui casas decimais.');
			event.srcElement.focus();
			event.srcElement.select();
		}
	}
}
function checaCNPJ(strCampo) {		
	Campo = eval(strCampo);
		
	strValor = Campo.value;
	
	if (strValor.length == 0)
		return true;
			
	strValor = strValor.replace('.', '');
	strValor = strValor.replace('.', '');
	strValor = strValor.replace('\\', '');
	strValor = strValor.replace('-', '');
	
	if (strValor.length != 14 || strValor == "00000000000000" || strValor == "11111111111111" ||
		strValor == "22222222222222" ||	strValor == "33333333333333" || strValor == "44444444444444" ||
		strValor == "55555555555555" || strValor == "66666666666666" || strValor == "77777777777777" ||
		strValor == "88888888888888" || strValor == "99999999999999") {
		alert('CNPJ inválido.');
		Campo.focus();
		return false;
	}
			
	strResult = "";
	intBase = 12;
  
	for(intDvs = 0; intDvs < 2; intDvs++) {
		intDv = 0;
		intMult = intBase - 7;
	  
		for(intInd = 0; intInd < intBase; intInd++) {
			intDv += parseInt(strValor.charAt(intInd)) * intMult;
	    
			if (intMult == 2)
				intMult = 9;
			else
				intMult--;
		}
	  
		intDv = 11 - (intDv % 11);
		if (intDv > 9)
			intDv = 0;
	  
		strResult += intDv;
		intBase = 13;
	}
	
	if (strResult != strValor.substr(12, 2)) {
		alert('CNPJ inválido.');
		Campo.focus();
		return false;
	}
	
	return true;	
}

function checaCPF(strCampo) {		
	
	Campo = eval(strCampo);
		
	strValor = Campo.value;
	
	if (strValor.length == 0)
		return true;
			
	strValor = strValor.replace('.', '');
	strValor = strValor.replace('.', '');
	strValor = strValor.replace('-', '');
		
	if (strValor.length != 11 || strValor == "00000000000" || strValor == "11111111111" ||
		strValor == "22222222222" ||	strValor == "33333333333" || strValor == "44444444444" ||
		strValor == "55555555555" || strValor == "66666666666" || strValor == "77777777777" ||
		strValor == "88888888888" || strValor == "99999999999") {
		alert('CPF inválido.');
		Campo.focus();
		return false;
	}
			
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(strValor.charAt(i)) * (10 - i);
		
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
		
	if (resto != parseInt(strValor.charAt(9))) {
		alert('CPF inválido.');
		Campo.focus();
		return false;
	}
		
	soma = 0;
		
	for (i = 0; i < 10; i ++)
		soma += parseInt(strValor.charAt(i)) * (11 - i);
		
	resto = 11 - (soma % 11);
		
	if (resto == 10 || resto == 11)
		resto = 0;
		
	if (resto != parseInt(strValor.charAt(10))) {
		alert('CPF inválido.');
		Campo.focus();
		return false;
	} 
		
	return true;
}