function qh_hideElement( elmID, overDiv ) {
if(document.all) {
	for(i = 0; i < document.all.tags( elmID ).length; i++) {
	  obj = document.all.tags( elmID )[i];
	  if(!obj || !obj.offsetParent) continue;

	  objLeft   = obj.offsetLeft;
	  objTop    = obj.offsetTop;
	  objParent = jQuery(obj).parent()[0];

	  while(objParent.tagName.toUpperCase() != 'BODY') {
		objLeft  += objParent.offsetLeft;
		objTop   += objParent.offsetTop;
		objParent = jQuery(objParent).parent()[0];
	  }

	  objHeight = obj.offsetHeight;
	  objWidth  = obj.offsetWidth;

	  if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
	  else if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
	  else if(overDiv.offsetTop >= (objTop + objHeight));
	  else if(overDiv.offsetLeft >= (objLeft + objWidth));
	  else {
		obj.style.visibility = 'hidden';
	  }
	}
  }
}
	
function qh_showElement(elmID) {
if(document.all) {
	for(i = 0; i < document.all.tags( elmID ).length; i++) {
	  obj = document.all.tags(elmID)[i];
	  if(!obj || !obj.offsetParent) continue;
	  obj.style.visibility = '';
	}
  }
}

function valida_senha(campo) { 
	campo=$('senha');
	
	if(campo.value.length == 0){
		alert('O campo senha é obrigatório.');
		campo.focus(); 
		return false; 
	}
	
	loginEscolhido = document.form.loginEscolhido.value;
	campo_senha = campo.value.toLowerCase();
	
	if (campo.value.length<6){
		alert('A senha deve possuir no mínimo 6 caracteres!'); 
		campo.focus(); 
		return false; 
	 } 
	 
	if (campo_senha.indexOf(loginEscolhido.toLowerCase())>=0){
		alert('A senha não pode conter o login.'); 
		campo.focus(); 
		return false; 
	 } 
	 return true; 
} 

function verifica_mail(mail) {
mail=$('email');
  if (mail.value.length > 0) {
	if (!/^([a-zA-Z0-9_\-\\+\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/.test(mail.value)) {
		alert('E-mail incorreto.'); 
		mail.focus();
		return false;
	}
	return true;
  }
}

	
function valida_rg(){
	rg = document.form.rg;
	if (rg.value.length == 0){
		alert('RG é um campo obrigatório!');
		rg.focus();
		boolClicado = false;
		return false;
	}
	return true;
}

function charSenha(e,id_element){
	var key
	if(window.event) {
		key = e.keyCode;  
		if (( key == 39 )||( key == 59 )||( key == 34 )||( key == 126)||( key == 96)||( key == 38)||( key == 36)) {
				alert('Carácter inválido');
				window.event.returnValue = null; 
				return;
		}		
	}
	else if (e.which) {
		key = e.which;
		if (( key == 39 )||( key == 59 )||( key == 34 )||( key == 126)||( key == 96)||( key == 38)||( key == 36)) {
				alert('Carácter inválido');
				e.preventDefault();
				return ; 
		}		
	}

}

function dados_juridicos(){
	if ($("juridica").checked){
  	  $("pj").style.display = '';
   }else{
	  $("pj").style.display = 'none';
	}
}


function chkLogin(val){
	var senha=document.form.senha.value;
	if (senha!=''){
		if(val.toUpperCase()==senha.toUpperCase()){	
			document.form.loginEscolhido.value='';
			val='';
			alert('A senha deve ser diferente do login');
			$('loginEscolhido').focus();
		}
	}
}
function chkSenha(val){
	var login=document.form.loginEscolhido.value;
	if (login!=''){
		if(val.toUpperCase()==login.toUpperCase()){	
			document.form.senha.value='';
			val='';
			alert('A senha deve ser diferente do login');
			$('senha').focus();
		}
	}
}

function Security(val, tamanho) {
	document.getElementById('mensagemSenha').innerHTML = "";
	document.getElementById('senha1').style.width='0%'
	document.getElementById('senha1').style.backgroundColor='#ffffff'
	document.getElementById('senha2').style.width='100%'
	document.getElementById('senha2').style.backgroundColor='#e0e0e0'
	var login=document.form.loginEscolhido.value;

	var lc = /[a-z]{1}/; // lowercase letters
	var uc = /[A-Z]{1}/; // uppercase letters
	var nm = /[0-9]{1}/; // numbers
	var un = /[^A-Za-z0-9]{1}/; // upper- and lower-case letters and numbers
	var ec = /[@%*-./:]/; //caracteres especiais
	if(   val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1 
		||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[@%*-./:]/) 
		||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@%*-./:]/) != -1 && val.search(/[0-9]/) 
		||val.length >= tamanho  && val.search(/[@%*-./:]/) != -1 && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) )
		{
			document.getElementById('mensagemSenha').innerHTML = "forte";
			document.getElementById('senha1').style.width='100%'
			document.getElementById('senha1').style.backgroundColor='green'
			document.getElementById('senha2').style.width='0%'
			document.getElementById('senha2').style.backgroundColor='#e0e0e0'
	} 
	else{
		if(   val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[A-Z]/) != -1 
			||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[0-9]/) != -1 
			||val.length >= tamanho && val.search(/[a-z]/) != -1 && val.search(/[@%*-./:]/) != -1
			||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[0-9]/) != -1
			||val.length >= tamanho && val.search(/[A-Z]/) != -1 && val.search(/[@%*-./:]/) != -1
			||val.length >= tamanho && val.search(/[0-9]/) != -1 && val.search(/[@%*-./:]/) != -1){

			document.getElementById('mensagemSenha').innerHTML = "média";
			document.getElementById('senha1').style.width='60%'
			document.getElementById('senha1').style.backgroundColor='orange'
			document.getElementById('senha2').style.width='40%'
			document.getElementById('senha2').style.backgroundColor='#e0e0e0'
				
		} 
		else {
			if(val.length >= tamanho)
			{
				document.getElementById('mensagemSenha').innerHTML = "fraca";
				document.getElementById('senha1').style.width='30%'
				document.getElementById('senha1').style.backgroundColor='red'
				document.getElementById('senha2').style.width='70%'
				document.getElementById('senha2').style.backgroundColor='#e0e0e0'
			}
		}
	}
}
				  
function enviaform(){
	erro='';
	focar='';
	bln_fnc=1; 
	formulario=document.form;
	tamx=formulario.tipo_pessoa;
	for (x=0; x<tamx.length;x++){
		if(document.form.tipo_pessoa[x].checked==true){
			var tpPessoa=document.form.tipo_pessoa[x].value;
		}
	}
	
	if(document.form.dominio.value==''){
		erro+='Domínio (obrigatório)\n';
		if(focar==''){focar='dominio'};
	}
	
	if(document.form.responsavel.value==''){
		erro+='Responsável (obrigatório)\n';
		if(focar==''){focar='responsavel'};
	}


	if( (document.form.rg.value=='')){
		erro+='RG (obrigatório)\n';
		if(focar==''){focar='rg'};
	}else{
		rgFull=document.form.rg.value;
		if(!(rgFull)){
			bln_fnc=0;
			if(focar==''){focar='rg'};
		}
	}	

	if( (document.form.cpf.value=='') ){
		erro+='CPF (obrigatório)\n';
		if(focar==''){focar='cpf'};
	}

	if( (document.form.cep.value=='') ){
		erro+='CEP (obrigatório)\n';
		if(focar==''){focar='cep'};
	}

	if(document.form.logradouro.value==''){
		erro+='Endereço (obrigatório)\n';
		if(focar==''){focar='logradouro'};
	}
	if (!/^[\w\@\ ÁÀÃÂÄÇÉÈÊËÍÌÏÓÒÔÕÖÚÙÜÑáàãâäçéèêëíìïóòôõöúùüñ\-\_\@\/\\\&\!\?\.\%\*\(\)\[\]\{\}\:\,\=\#\+\$\°\ª\º\^\~\|\=]{0,250}$/.test(document.form.logradouro.value)) { 
		erro+='Endereço (caracter inválido)\n';
		if(focar==''){focar='logradouro'};
	}	

	if(document.form.txt_numero.value==''){
		erro+='Número (obrigatório)\n'
		if(focar==''){focar='txt_numero'};
	}

	if(document.form.cidade.value==''){
		erro+='Cidade (obrigatório)\n';
			if(focar==''){focar='cidade'};	
	}
	
	if(document.form.sigla_estado.value==''){
		erro+='Estado (obrigatório)\n';
			if(focar==''){focar='sigla_estado'};
	}
	
	if(document.form.telefone.value==''){
		erro+='Telefone (DDD obrigatório)\n';
		if(focar==''){focar='telefone'};
	}
	
	if(document.form.email.value==''){
		erro+='E-mail (obrigatório)\n';
		if(focar==''){focar='email'};
	}
	
	if(document.form.loginEscolhido.value==''){
		erro+='Login (obrigatório)\n';
		if(focar==''){focar='loginEscolhido'};
	}
	
	if (erro!=''){
		alert('Favor preencher corretamente os seguintes campos : \n\n'+erro);
		nFoco=$(focar);
		nFoco.focus();
	}

	else{
		shErro=0;
		if(shErro==0){	
			if( (document.form.cep.value.length<10) ){
				alert('CEP (inválido)');
				shErro=1;		
				bln_fnc=0;
				document.form.cep.focus();
				return false;	
			}	
		}
		if(shErro==0){
			cpfFull=document.form.cpf.value;
			
		}
		
		if(shErro==0){
				mail=document.form.email.value;
				if(!verifica_mail(mail)){
					bln_fnc=0;
					shErro=1;
					return false;
				}
		}

		formulario.submit();
		
	
		if(bln_fnc==1){
			cpfReg = document.form.cpf.value;
			if ($('pj').style.display == ''){
				cnpjReg = document.form.cnpj.value;
			} else {
				cnpjReg = 0;
			}
	   }else{
	   }
		 
	}	
}
dados_juridicos();