function AbrePagina(perfil, tamx, tamy, yn) {
	window.open(perfil,"","resizable=no,toolbar=no,status=no,menubar=no,top="+((screen.availHeight - tamy) * 0.5)+",left="+((screen.availWidth - tamy) * 0.5)+",scrollbars=" + yn + ",width=" + tamx + ",height=" + tamy)
}

/* JavaScript que muda a cor da linha da tabela quando a mesma eh selecionada */
function mOvr(src,clrOver) { 
	if (event.srcElement.tagName=='TR') {
	//if (!src.contains(event.fromElement)) {  
		src.style.cursor = 'hand';
  		src.bgColor = clrOver; 
	}
}

function mOut(src,clrIn) { 
	if (!src.contains(event.toElement)) {  
		src.style.cursor = 'default';  
		src.bgColor = clrIn; 
	}
}

function mClk(src) { 
	if(event.srcElement.tagName=='TD') {  
		src.children.tags('a')[0].click(); 
	}
}

//validando logon
function validaLogon(theForm) {
	if(theForm.numero.value=="" || theForm.numero.value.length < 3 || theForm.senha.value=="" || theForm.senha.value.length < 3) {
		alert("Você deve inserir seu número e senha corretamente!");
		return false;
	}
	return true;
}

//validando troca de senha
function validaSenha(theForm) {
	msg = new Array();
	if(theForm.antiga.value == "" || theForm.antiga.value.length==0) { msg[msg.length] = " - Senha Antiga"; }
	if(theForm.senha1.value == "" || theForm.senha1.value.length==0) { msg[msg.length] = " - Digite a Senha Nova"; }
	if(theForm.senha2.value == "" || theForm.senha2.value.length==0) { msg[msg.length] = " - Repita a Senha Nova"; }
	if(theForm.senha1.value != theForm.senha2.value) { msg[msg.length] = "\nOBS: 'Digite a Senha Nova' deve conter o mesmo valor que 'Repita a Senha Nova'"; }
	if(msg.length > 0) {
		texto = "Você deve preencher corretamente os campos abaixo: \n";
		for(i=0;i<msg.length;i++) {
			texto+= msg[i]+"\n";
		}
		alert(texto);
		return false;
	} 
	return true;
}

//validando contato
function validaContato(theForm) {
	msg = new Array();
	if(theForm.nome.value == "" || theForm.nome.value.length==0) { msg[msg.length] = " - Nome"; }
	if(theForm.email.value == "" || theForm.email.value.length==0) { msg[msg.length] = " - E-mail"; }
	if(theForm.mensagem.value == "" || theForm.mensagem.value.length==0) { msg[msg.length] = " - Mensagem"; }
	if(msg.length > 0) {
		texto = "Você deve preencher corretamente os campos abaixo: \n";
		for(i=0;i<msg.length;i++) {
			texto+= msg[i]+"\n";
		}
		alert(texto);
		return false;
	} 
	return true;
}

function validaForm(theForm,numForm) {
	i = 0;
	campos = new Array();
	if (numForm == 0) {
		if (theForm.razao_social.value == "") { campos[i] = " - Razão Social"; i++; }
		if (theForm.nome_fantasia.value == "") { campos[i] = " - Nome Fantasia"; i++; }
		if (theForm.endereco.value == "") { campos[i] = " - Endereço"; i++; }
		if (theForm.cep.value == "") { campos[i] = " - CEP"; i++; }
		if (theForm.bairro.value == "") { campos[i] = " - Bairro"; i++; }
		if (theForm.cidade.value == "") { campos[i] = " - Cidade"; i++; }
		if (theForm.estado.value == "") { campos[i] = " - Estado"; i++; }
		if (theForm.ramo_atividade.value == "") { campos[i] = " - Ramo de Atividade"; i++; }
		if (theForm.telefone.value == "") { campos[i] = " - Telefone"; i++; }
		if (theForm.pessoa_contato.value == "") { campos[i] = " - Pessoa de Contato"; i++; }
		if (theForm.cgc_cnpj.value == "") { campos[i] = " - CGC/CNPJ"; i++; }
		if (theForm.inscricao_estadual.value == "") { campos[i] = " - Insc. Estadual ou Munic."; i++; }
		if (theForm.comissao.value == "") { campos[i] = " - Comissão"; i++; }
		if (theForm.prazo.value == "") { campos[i] = " - Prazo"; i++; }
		if (theForm.banco.value == "") { campos[i] = " - Conta"; i++; }
		if (theForm.agencia.value == "") { campos[i] = " - Agência"; i++; }
		if (theForm.conta_corrente.value == "") { campos[i] = " - Conta Corrente"; i++; }
		if (theForm.nome1.value == "") { campos[i] = " - Nome Propietário 1"; i++; }
		if (theForm.cpf1.value == "") { campos[i] = " - CPF Propietário 1"; i++; }
		if (theForm.data_nascimento1.value == "") { campos[i] = " - Data de Nascimento Propietário 1"; i++; }
		}
	if (numForm == 1) {
		//Pessoal
		if (theForm.nome_pessoal.value == "") { campos[i] = theForm.nome_pessoal.id; i++; }
		if (theForm.sexo_pessoal.value == "") { campos[i] = theForm.sexo_pessoal.id; i++; }
		if (theForm.estado_civil_pessoal.value == "") { campos[i] = theForm.estado_civil_pessoal.id; i++; }
		if (theForm.cpf_pessoal.value == "") { campos[i] = theForm.cpf_pessoal.id; i++; }		
		if (theForm.dependete_pessoal.value == "") { campos[i] = theForm.dependete_pessoal.id; i++; }		
		if (theForm.data_nascimento_pessoal.value == "") { campos[i] = theForm.data_nascimento_pessoal.id; i++; }
		if (theForm.nome_cartao.value == "") { campos[i] = theForm.nome_cartao.id; i++; }
		if (theForm.identidade_pessoal.value == "") { campos[i] = theForm.identidade_pessoal.id; i++; }
		if (theForm.orgao_emaissor_pessoal.value == "") { campos[i] = theForm.orgao_emaissor_pessoal.id; i++; }
		if (theForm.naturalidade_pessoal.value == "") { campos[i] = theForm.naturalidade_pessoal.id; i++; }
		if (theForm.estado_pessoal.value == "") { campos[i] = theForm.estado_pessoal.id; i++; }
		if (theForm.nome_pai_pessoal.value == "") { campos[i] = theForm.nome_pai_pessoal.id; i++; }
		if (theForm.nome_mae_pessoal.value == "") { campos[i] = theForm.nome_mae_pessoal.id; i++; }
		if (theForm.data_vencimento.value == "") { campos[i] = theForm.data_vencimento.id; i++; }
		
		//Residencial
		if (theForm.rua_residencial.value == "") { campos[i] = theForm.rua_residencial.id; i++; }
		if (theForm.numero_residencial.value == "") { campos[i] = theForm.numero_residencial.id; i++; }
		if (theForm.cep_residencial.value == "") { campos[i] = theForm.cep_residencial.id; i++; }
		if (theForm.bairro_residencial.value == "") { campos[i] = theForm.bairro_residencial.id; i++; }
		if (theForm.cidade_residencial.value == "") { campos[i] = theForm.cidade_residencial.id; i++; }
		if (theForm.estado_residencial.value == "") { campos[i] = theForm.estado_residencial.id; i++; }
		if (theForm.telefone_residencial.value == "") { campos[i] = theForm.telefone_residencial.id; i++; }
		if (theForm.tipo_telefone_residencial.value == "") { campos[i] = theForm.tipo_telefone_residencial.id; i++; }
		if (theForm.imovel_residencial.value == "") { campos[i] = theForm.imovel_residencial.id; i++; }
		if (theForm.imovel_residencial.value == "alugado") {
			if (theForm.aluguel_valor_residencial.value == "") { campos[i] = theForm.aluguel_valor_residencial.id; i++; }
		}
		if (theForm.aluguel_ano_residencial.value == "") { campos[i] = theForm.aluguel_ano_residencial.id; i++; }
		if (theForm.aluguel_mes_residencial.value == "") { campos[i] = theForm.aluguel_mes_residencial.id; i++; }		
		
		//Profissional
		if (theForm.trabalha_profissional.value == "") { campos[i] = theForm.trabalha_profissional.id; i++; }
		if (theForm.atividade_profissional.value == "") { campos[i] = theForm.atividade_profissional.id; i++; }
		if (theForm.empregador_profissional.value == "") { campos[i] = theForm.empregador_profissional.id; i++; }
		if (theForm.rua_profissional.value == "") { campos[i] = theForm.rua_profissional.id; i++; }
		if (theForm.numero_profissional.value == "") { campos[i] = theForm.numero_profissional.id; i++; }
		if (theForm.cep_profissional.value == "") { campos[i] = theForm.cep_profissional.id; i++; }
		if (theForm.bairro_profissional.value == "") { campos[i] = theForm.bairro_profissional.id; i++; }
		if (theForm.cidade_profissional.value == "") { campos[i] = theForm.cidade_profissional.id; i++; }
		if (theForm.estado_profissional.value == "") { campos[i] = theForm.estado_profissional.id; i++; }
		if (theForm.telefone_profissional.value == "") { campos[i] = theForm.telefone_profissional.id; i++; }
		if (theForm.tempo_ano_profissional.value == "") { campos[i] = theForm.tempo_ano_profissional.id; i++; }
		if (theForm.tempo_mes_profissional.value == "") { campos[i] = theForm.tempo_mes_profissional.id; i++; }
		if (theForm.funcao_profissional.value == "") { campos[i] = theForm.funcao_profissional.id; i++; }
		if (theForm.salario_profissional.value == "") { campos[i] = theForm.salario_profissional.id; i++; }
		if (theForm.referencia_pessoal1.value == "") { campos[i] = theForm.referencia_pessoal1.id; i++; }
		if (theForm.referencia_pessoal2.value == "") { campos[i] = theForm.referencia_pessoal2.id; i++; }
		if (theForm.telefone_referencia_pessoal1.value == "") { campos[i] = theForm.telefone_referencia_pessoal1.id; i++; }
		if (theForm.telefone_referencia_pessoal2.value == "") { campos[i] = theForm.telefone_referencia_pessoal2.id; i++; }
		if (theForm.referencia_comercial1.value == "") { campos[i] = theForm.referencia_comercial1.id; i++; }
		if (theForm.referencia_comercial2.value == "") { campos[i] = theForm.referencia_comercial2.id; i++; }
		if (theForm.telefone_referencia_comercial1.value == "") { campos[i] = theForm.telefone_referencia_comercial1.id; i++; }
		if (theForm.telefone_referencia_comercial2.value == "") { campos[i] = theForm.telefone_referencia_comercial2.id; i++; }
		if (theForm.outros_cartoes.value == "") { campos[i] = theForm.outros_cartoes.id; i++; }
		if (theForm.outros_cartoes.value == "sim") { 
		  if (theForm.qual_outros_cartoes.value == "") { campos[i] = theForm.qual_outros_cartoes.id; i++; }
		}
		if (theForm.conta_corrente_autorizacao.value == "") { campos[i] = theForm.conta_corrente_autorizacao.id; i++; }
		if (theForm.descontos_saude.value == "") { campos[i] = theForm.descontos_saude.id; i++; }
	}
	size = campos.length;
	if (size > 0) {
		mensagem = "Você deve preencher os seguintes campos: \n";
		for (x=0;x<size;x++) {
			mensagem += campos[x]+"\n";
		}
		alert(mensagem);
		return false;
	}
	return true;
}

function SomenteNumeros() {
	if ( (event.keyCode >= 48) && (event.keyCode <= 57)) {
		return true
	} else {
		if (event.keyCode != 8) {
			event.keyCode = 0
			return false
		}
	}
}

function txtBoxFormat(objForm, 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;
	}
	
	sValue = objForm[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( " ", "" );
	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) == " "))

		if (bolMask) {
			sCod += sMask.charAt(i);
			mskLen++; 
		} else {
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}

	objForm[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;
	}
}

//funcao que limpa acentos
function limpaAcentos(palavra) {
	var txt = '';
	palavra = palavra.toUpperCase();
	for(i=0;i<palavra.length;i++) {
		switch(palavra.substring(i,i+1)) {
			//Agudo
			case 'Á' : pl = 'A'; break;
			case 'É' : pl = 'E'; break;
			case 'Í' : pl = 'I'; break;
			case 'Ó' : pl = 'O'; break;
			case 'Ú' : pl = 'U'; break;
			//Circunflexo
			case 'Â' : pl = 'A'; break;
			case 'Ê' : pl = 'E'; break;
			case 'Î' : pl = 'I'; break;
			case 'Ô' : pl = 'O'; break;
			case 'Û' : pl = 'U'; break;
			//Til
			case 'Ã' : pl = 'A'; break;
			case 'Õ' : pl = 'O'; break;
			case 'Ñ' : pl = 'N'; break;
			//Trema
			case 'Ä' : pl = 'A'; break;
			case 'Ë' : pl = 'E'; break;
			case 'Ï' : pl = 'I'; break;
			case 'Ö' : pl = 'O'; break;
			case 'Ü' : pl = 'U'; break;
			//Crase
			case 'À' : pl = 'A'; break;
			case 'È' : pl = 'E'; break;
			case 'Ì' : pl = 'I'; break;
			case 'Ò' : pl = 'O'; break;
			case 'Ù' : pl = 'U'; break;
			//Cedilha
			case 'Ç' : pl = 'C'; break;
			default : pl = palavra.substring(i,i+1); break;
		}
		txt+= pl;
	}
	return txt;
}

function MarcaCheckBox()
{
	
	var i, qtd;
	qtd = document.frmAlterarValorTicket.contador.value;	
	   
    for ( i = 1; i <= qtd; i++ )
	{   
		if (document.frmAlterarValorTicket.elements[i].checked)
		{
			document.frmAlterarValorTicket.elements[i].checked = false;
		}
		else
		{
			document.frmAlterarValorTicket.elements[i].checked = true;
		}

    }   
       
/*	
	var aChk = document.getElementsByName("Item");   
  
	for (var i=0;i<aChk.lenght;i++){   
     if (aChk[i].checked == true){   
           aChk[i].checked = false;
     } else
	 {
		 aChk[i].checked = true;
	 }
}
	
	var total, i, qtd;
	qtd = document.frmAlterarValorTicket.contador.value;
	total = 0;
	for (i=0;i<qtd;i++)
	{
			
		total += (document.frmAlterarValorTicket.elements[i].value*1);
	}
	document.formulario.tot.value = "R$ "+(total)+",00"; */
}