// JavaScript Document DIGITRUM

//FUNÇAO DE POP-UP
function abrirPOPUP(theURL,winName,features) 
	{
		window.open(theURL,winName,features);
	}

// Função para dar reload nas paginas levando a variavel que voce precisa
function MM_jumpMenu(targ,selObj,restore)
	{ //v3.0 
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
		if (restore) selObj.selectedIndex=0; 
	}

//Funcao AJAX para consultar codigo promocional
$(document).ready(function() {
	$('#codPromocaoLoading').hide();
	$('#botaoPromocao').click(function(){
	  $('#codPromocaoLoading').show();
      $.get("detalhes/check.cfm", {
        codPromocao: $('#codPromocao').val()
      }, function(response){
        $('#codPromocaoResult').fadeOut();
        setTimeout("finishAjax('codPromocaoResult', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});

function finishAjax(id, response) 
	{
		$('#codPromocaoLoading').hide();
		$('#'+id).html(unescape(response));
		$('#'+id).fadeIn();
	} //finishAjax

//Funcao AJAX para selecionar Planos
$(document).ready(function() {
	$('#codPlanosLoading').hide();
	$('#tecnologia').change(function(){
	  $('#codPlanosLoading').show();
      $.get("detalhes/busca_planos.cfm", {
        opcao: $('#tecnologia').val()
      }, function(response){
        $('#codPlanosResult').fadeOut();
        setTimeout("finishAjaxPlanos('codPlanosResult', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});

function finishAjaxPlanos(id, response) 
	{
		$('#codPlanosLoading').hide();
		$('#'+id).html(unescape(response));
		$('#'+id).fadeIn();
	} //finishAjax2

//Funcao AJAX para consultar CPF
$(document).ready(function() {
	$('#cpfLoading').hide();
	$('#cpf').change(function(){
	  $('#cpfLoading').show();
      $.get("detalhes/validar_cpf.cfm", {
        opcao: $('#cpf').val()
      }, function(response){
        $('#cpfResult').fadeOut();
        setTimeout("finishAjaxCPF('cpfResult', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});

function finishAjaxCPF(id, response) 
	{
		$('#cpfLoading').hide();
		$('#'+id).html(unescape(response));
		$('#'+id).fadeIn();
	}

//Funcao AJAX para consultar CNPJ
$(document).ready(function() {
	$('#cnpjLoading').hide();
	$('#cnpj').change(function(){
	  $('#cnpjLoading').show();
      $.get("detalhes/validar_cnpj.cfm", {
        opcao: $('#cnpj').val()
      }, function(response){
        $('#cnpjResult').fadeOut();
        setTimeout("finishAjaxCNPJ('cnpjResult', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});

function finishAjaxCNPJ(id, response) 
	{
		$('#cnpjLoading').hide();
		$('#'+id).html(unescape(response));
		$('#'+id).fadeIn();
	}


//Funcao Habilitar Empresa
function habilitarEmpresa(tipo_cadastro)
	{
		if(tipo_cadastro == 1)
		{
			/*document.getElementById("razao_social").disabled = false;
			document.getElementById("nome_fantasia").disabled = false;
			document.getElementById("cnpj").disabled = false;*/
			document.getElementById('dadosEmpresa').style.display='';//exibindo a div
		} 
		else
		{
			/*document.getElementById("razao_social").disabled = true;
			document.getElementById("nome_fantasia").disabled = true;
			document.getElementById("cnpj").disabled = true;*/
			document.getElementById('dadosEmpresa').style.display='none';//sumindo com a div
		}
	}
//Funcao Habilitar Servicos Adicionais
function habilitarAdicionais(valor)
	{
		if (valor == "1")
			{
				document.getElementById(servAdicionais).style.display = '';
			}
		else
			{
				document.getElementById(servAdicionais).style.display = 'none';
			}
	}

//Funcao Habilitar Submit apos aceitar o contrato
function habilitarDesabilitarBtn()
	{
		if(document.getElementById('aceitar_contrato').checked == true)
			{
				document.getElementById('btn_cadastro').disabled = ""
			}
		
		if(document.getElementById('aceitar_contrato').checked == false)
			{
				document.getElementById('btn_cadastro').disabled = "disabled"
			}
	}
// funcoes relativas ao login e senha
function charSenha(e,id_element){
	var key
	if(window.event) {
	// Atenter o IE
		key = e.keyCode;  
		if (( key == 37 )||( 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) {
	//Atender NetScape.
		key = e.which;
		if (( key == 37 )||( key == 39 )||( key == 59 )||( key == 34 )||( key == 126)||( key == 96)||( key == 38)||( key == 36)) {
				alert('Carácter inválido');
				e.preventDefault();
				return ; 
		}		
	}

}

function chkLogin(val){
	var senha=document.cad1.senha.value;
	if (senha!=''){
		if(val.toUpperCase()==senha.toUpperCase()){	
			document.cad1.login.value='';
			val='';
			alert('A senha deve ser diferente do login');
			$('senha').focus();
		}
	}
}
function chkSenha(val){
	var login=document.cad1.login.value;
	if (login!=''){
		if(val.toUpperCase()==login.toUpperCase()){	
			document.cad1.senha.value='';
			val='';
			alert('A senha deve ser diferente do login');
			return document.cad1.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.cad1.login.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
	//$('debugar').innerHTML=''+val+'<br>'+login+'';
	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&eacute;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'
			}
		}
	}
}
//diversas funcoes
function somenteNumero(e,id_element){
	var key
	if(window.event){
		// Atenter o IE
		key=e.keyCode; 
		if((key<47)||( key>58)){
			window.event.returnValue = null; 
			return;
		}		
	}else if(e.which){
	//Atender NetScape.
	key = e.which;
	if((key<47)||(key>58)){
		e.preventDefault();
		return ; 
	}		
	}
}
function fncMultiplica(id,vl,m){
	var totalFtp;
	totalFtp=parseFloat(vl*m);
	totalFtp=totalFtp.toString().replace('.',',');
	totalFtp=trataCasaDecimal(totalFtp);
	$(id).innerHTML=totalFtp.toString();
	calculaResumo();
}

function calculaResumo(){
}
function trataCasaDecimal(str){
	tam=str.length;	
	if (str.charAt(tam-2)==','){
		str+='0';
	}
	tam=str.length;	
	if (str.charAt(tam-3)!=','){
		str+=',00';
	}
	//fazer rotina para tratar milhar 0.000,00
	//Casas a esquerda
	pM=str.indexOf('.');
	if(pM<=0){
		cEsq=str.indexOf(',');
		if(cEsq>3){
			str=str.substring(0,(cEsq-3))+'.'+str.substring(cEsq-3,cEsq)+str.substring(cEsq,str.length);
		}
	}
	return str;
}


function fncCheckBox(id,vl){
	if(vl>0){
		$(id).checked=true;
	}else{
		$(id).checked=false;
	}
}