/* ****************************************************************************/
/*                                                                            */
/*              Arquivo de funções javascript - Sistema Meimberg              */
/*                  Desenvolvimento  -  Agência Studio iMAXIS                 */
/*                                                                            */
/* ************************************************************************** */

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function Confirma(){ 
 if (confirm('Deseja realmente excluir estes registros ?')){
	 return true; 
	 document.Form_Lst.submit();	 
	 }
 else 
     return false;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ValidaCadastro()
{	
	/*if (document.Form_Cad.cpfValido.value == 1){
		alert("CPF já Cadastrado.");
		document.Form_Cad.cpf.focus();
		return false;
	}*/
	//alert("teste");
	if (document.Form_Cad.termos.checked == false){
	alert("É preciso aceitar os termos de uso para efetuar seu cadastro.");
	return false;
	}

	if (document.Form_Cad.nome.value == ""){
		alert("Favor! Informe o Nome.");
		document.Form_Cad.nome.focus();
		return false;
	}
	
	if(document.Form_Cad.tp[0].checked==true){
		/*if (document.Form_Cad.cpf.value == ""){
			alert("Favor! Informe o CPF.");
			document.Form_Cad.cpf.focus();
			return false;
		}*/
	/*	if (document.Form_Cad.rg.value == ""){
			alert("Favor! Informe o RG.");
			document.Form_Cad.rg.focus();
			return false;
		}*/
		if (document.Form_Cad.nascDia.value == ""){
			alert("Favor! Informe o Dia de Nascimento.");
			document.Form_Cad.nascDia.focus();
			return false;
		}
		if (document.Form_Cad.nascMes.value == ""){
			alert("Favor! Informe o Mês de Nascimento.");
			document.Form_Cad.nascMes.focus();
			return false;
		}
		if (document.Form_Cad.nascAno.value == ""){
			alert("Favor! Informe o Ano de Nascimento.");
			document.Form_Cad.nascAno.focus();
			return false;
		}
		if (document.Form_Cad.sexo.value == ""){
			alert("Favor! Selecione o Sexo.");
			document.Form_Cad.sexo.focus();
			return false;
		}
	}
	
	
	if(document.Form_Cad.tp[1].checked==true)
	{
		/*if (document.Form_Cad.cpf.value == ""){
			alert("Favor! Informe o CNPJ.");
			document.Form_Cad.cpf.focus();
			return false;
		}*/
		if (document.Form_Cad.nascDia.value == ""){
			alert("Favor! Informe o Dia de Fundação.");
			document.Form_Cad.nascDia.focus();
			return false;
		}
		if (document.Form_Cad.nascMes.value == ""){
			alert("Favor! Informe o Mês de Fundação.");
			document.Form_Cad.nascMes.focus();
			return false;
		}
		if (document.Form_Cad.nascAno.value == ""){
			alert("Favor! Informe o Ano de Fundação.");
			document.Form_Cad.nascAno.focus();
			return false;
		}
		if (document.Form_Cad.licencas.value == ""){
			alert("Favor! Selecione o Total de Computadores.");
			document.Form_Cad.licencas.focus();
			return false;
		}
	}
	
	
	if (document.Form_Cad.email.value == ""){
		alert("Favor! Informe o Email.");
		document.Form_Cad.email.focus();
		return false;
	}
	
	if (document.Form_Cad.cep.value == ""){
		alert("Favor! Informe o Cep.");
		document.Form_Cad.cep.focus();
		return false;
	}
	
	if (document.Form_Cad.cep02.value == ""){
		alert("Favor! Informe o Cep.");
		document.Form_Cad.cep02.focus();
		return false;
	}
	
	if (document.Form_Cad.endereco.value == ""){
		alert("Favor! Informe o Endereço.");
		document.Form_Cad.endereco.focus();
		return false;
	}
	
	if (document.Form_Cad.bairro.value == ""){
		alert("Favor! Informe o Bairro.");
		document.Form_Cad.bairro.focus();
		return false;
	}
	
	if (document.Form_Cad.cidade.value == ""){
		alert("Favor! Informe a Cidade.");
		document.Form_Cad.cidade.focus();
		return false;
	}
	
	if (document.Form_Cad.estado.value == ""){
		alert("Favor! Selecione o Estado.");
		document.Form_Cad.estado.focus();
		return false;
	}
	
	if (document.Form_Cad.telDDD.value == ""){
		alert("Favor! Informe o Telefone.");
		document.Form_Cad.telDDD.focus();
		return false;
	}
	
	if (document.Form_Cad.telPrefixo.value == ""){
		alert("Favor! Informe o Telefone.");
		document.Form_Cad.telPrefixo.focus();
		return false;
	}
	
	if (document.Form_Cad.telNumero.value == ""){
		alert("Favor! Informe o Telefone.");
		document.Form_Cad.telNumero.focus();
		return false;
	}
	
/*	if ((document.Form_Cad.contratos.value == "" || document.Form_Cad.contratos.value == " ") && (document.Form_Cad.graficoTipo[1].checked == true)){
		alert("Favor! Informe o Número de Contratos.");
		document.Form_Cad.contratos.focus();
		return false;
	}
	
	if ((document.Form_Cad.objetivo.value == "" || document.Form_Cad.objetivo.value == "---") && (document.Form_Cad.graficoTipo[1].checked == true)){
		alert("Favor! Informe o Objetivo de Pontos por Dia.");
		document.Form_Cad.objetivo.focus();
		return false;
	}*/
	
	if (document.Form_Cad.login.value == ""){
		alert("Favor! Informe o Login.");
		document.Form_Cad.login.focus();
		return false;
	}
	
	if (document.Form_Cad.senha.value == ""){
		alert("Favor! Informe a Senha.");
		document.Form_Cad.senha.focus();
		return false;
	}
	
	if (document.Form_Cad.senha.value != document.Form_Cad.confSenha.value){
		alert("Favor! Senha Não Confere.");
		document.Form_Cad.senha.focus();
		return false;
	}
	if (document.Form_Cad.GraficoNormal.checked == false && document.Form_Cad.GraficoSwing.checked == false && document.Form_Cad.GraficoFigura.checked == false){
		alert("É preciso selecionar o tipo gráfico desejado.\nÉ possível selecionar mais de um gráfico.");
		return false;
	}	
	
	
}


function VerificaContato()
{	
	if (document.Form_Cad.nome.value == ""){
		alert("Favor! Informe o Nome.");
		document.Form_Cad.nome.focus();
		return false;
	}
	
	
	if (document.Form_Cad.email.value == ""){
		alert("Favor! Informe o Email.");
		document.Form_Cad.email.focus();
		return false;
	}
	
	
	if (document.Form_Cad.cidade.value == ""){
		alert("Favor! Informe a Cidade.");
		document.Form_Cad.cidade.focus();
		return false;
	}
	
	if (document.Form_Cad.estado.value == ""){
		alert("Favor! Selecione o Estado.");
		document.Form_Cad.estado.focus();
		return false;
	}
	
	if (document.Form_Cad.telDDD.value == ""){
		alert("Favor! Informe o Telefone.");
		document.Form_Cad.telDDD.focus();
		return false;
	}
	
	if (document.Form_Cad.telPrefixo.value == ""){
		alert("Favor! Informe o Telefone.");
		document.Form_Cad.telPrefixo.focus();
		return false;
	}
	
	if (document.Form_Cad.telNumero.value == ""){
		alert("Favor! Informe o Telefone.");
		document.Form_Cad.telNumero.focus();
		return false;
	}
}

function VerificaCadastro()
{	
	
	if (document.Form_Login.login.value == ""){
		alert("Favor! Informe o Login.");
		document.Form_Login.login.focus();
		return false;
	}
	if (document.Form_Login.senha.value == ""){
		alert("Favor! Informe a Senha.");
		document.Form_Login.senha.focus();
		return false;
	}
}

function VerificaBuscaIntervalo()
{	
	dia = document.Form_Busca.dia.value;
	mes = document.Form_Busca.mes.value;
	ano = document.Form_Busca.ano.value;
	document.Form_Busca.Prm.value = "|Data="+ano+"-"+mes+"-"+dia;
}


function validaForm()
{
  if(document.Form_Reg.txtNome.value=="")
  {
	alert("Favor! Informe o Nome do Registro a Ser Adicionado.");
	document.Form_Reg.txtNome.focus();
	return false;
  }
}


function numeros()
	{
		tecla = event.keyCode;
		if (tecla >= 48 && tecla <= 57)
			{
				return true;
			}
		else
			{
			alert("Favor! Preencha este campo somente com Números!.");
		   	return false;
			}
	}


function GerarSWF($arquivo,$altura,$largura,$id, $clId, $local){
    document.writeln('    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + $largura + '" height="' + $altura + '" id="' + $id + '">');
    document.writeln('        <param name="movie" value="' + $arquivo + '" />');
    document.writeln('        <param name="FlashVars" value="loc=en_US&htmlApp=false&idCliente='+ $clId +'&url='+ $local +'"/>');
    document.writeln('        <param name="bgcolor" value="#ffffff" />');
    document.writeln('        <param name="menu" value="false" />');
    document.writeln('        <param name="quality" value="high" />');
    document.writeln('        <param name="salign" value="tl" />');
    document.writeln('        <param name="scale" value="noscale" />');
    document.writeln('        <param name="wmode" value="transparent" />');
    document.writeln('        <embed name="'+ $id +'" src="' + $arquivo + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" flashvars="loc=en_US&htmlApp=false&idCliente='+ $clId +'&url='+ $local +'" bgcolor="#ffffff" menu="false" quality="high" salign="tl" scale="noscale" width="' + $largura + '" height="' + $altura + '"></embed>');
    document.writeln('    </object>');
}

function buscaClientes()
{
  if (document.form_lcn.Busca.value == "")
  {
	alert("Favor! Selecione o Tipo de Busca!.");
	document.form_lcn.Busca.focus();
	return false;
  }
  var busca = document.form_lcn.Busca.value;
  var termo = document.form_lcn.TextoBusca.value;
  url = "../view/?Lc=Clientes&Md=Lista&Prm=|Busca="+busca+"|TextoBusca="+termo;
  //alert(document.location.href);
  window.location.href=url;
}



function verificaCadastro(local, valor)
{
	url = "verificaCadastro.php?Lc="+local+"&Valor="+valor;
	if(local == "Codigo"){
		if(valor=="")
		document.getElementById("msgCodigo").innerHTML = "";
		else{
			document.getElementById("msgCodigo").innerHTML = "Verificando Código...";	
			req = conecta();
			req.open("GET", url, true);
			req.onreadystatechange = function(){
				if(req.readyState == 4){
					if(req.status == 200){
					var conteudo = req.responseText
					var conteudo = unescape(conteudo).replace(/\+/g,' ')
						if(conteudo == "true"){
						  document.getElementById("msgCodigo").innerHTML = "<b>Código Aceito.</b>";
						  document.Form_Cad.codigoValido.value = 0;
						}
						else{
						  document.getElementById("msgCodigo").innerHTML = "<b>Código não encontrado. Por Favor, tente novamente.</b>";	
						  document.Form_Cad.codigoValido.value = 1;
					   }
				   }
			   }
		   }
	   }
	}
	
	if(local == "CPF"){
		document.getElementById("msgCPF").innerHTML = "Verificando CPF...";	
		req = conecta();
		req.open("GET", url, true);
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if(req.status == 200){
				var conteudo = req.responseText
				var conteudo = unescape(conteudo).replace(/\+/g,' ')
				if(conteudo == "true"){
					   document.getElementById("msgCPF").innerHTML = "CPF Aceito.";	
					   document.Form_Cad.cpfValido.value = 0;
					}
					else{
					  document.getElementById("msgCPF").innerHTML = "CPF Já Cadastrado.";	
					  document.Form_Cad.cpfValido.value = 1;
					}
				}
			}
		}
	}
	
	if((local == "Login") && (valor != "")){
		document.getElementById("msgLogin").innerHTML = "Verificando Login...";	
		req = conecta();
		req.open("GET", url, true);
		req.onreadystatechange = function(){
			if(req.readyState == 4){
				if(req.status == 200){
				var conteudo = req.responseText
				var conteudo = unescape(conteudo).replace(/\+/g,' ')
					if(conteudo == "true"){
					  document.getElementById("msgLogin").innerHTML = "<b>Login Aceito.</b>";
					  document.Form_Cad.loginValido.value = 0;
					}
					else{
					  document.getElementById("msgLogin").innerHTML = "<b>Login já cadastrado. Por Favor, tente novamente.</b>";	
					  document.Form_Cad.loginValido.value = 1;
					}
				}
			}
		}
	}
	
	req.send(null);
}


function editarCadastro(local)
{
	if(local == "dadosPessoais"){
	  document.getElementById("dadosPessoais").style.display = "none";	
	  document.getElementById("dadosPessoaisEditar").style.display = "";	
	}
	
	if(local == "endereco"){
	  document.getElementById("endereco").style.display = "none";	
	  document.getElementById("enderecoEditar").style.display = "";	
	}
	
	if(local == "dadosBancarios"){
	  document.getElementById("dadosBancarios").style.display = "none";	
	  document.getElementById("dadosBancariosEditar").style.display = "";	
	}
}

function mudaTipo(tipo)
{
   //alert(tipo);
   if(tipo == "J"){
	  document.getElementById("divNome").innerHTML = "Razão Social:";
	  document.getElementById("divCPF").innerHTML = "CNPJ:";
	  document.getElementById("divRG").innerHTML = "Insc. Est:";
	  document.getElementById("divSexo").style.display = "none";
	  document.getElementById("divFantasia").style.display = "";
	  document.getElementById("divNascimento").innerHTML = "Data de Fundação:";
	  document.getElementById("divIndicado").style.display = "none";
	  document.getElementById("divLicencas").style.display = "";
   }
   else{
	  document.getElementById("divNome").innerHTML = "Nome:";
	  document.getElementById("divCPF").innerHTML = "CPF:";
	  document.getElementById("divRG").innerHTML = "R.G:";
	  document.getElementById("divSexo").style.display = "";
	  document.getElementById("divFantasia").style.display = "none";
	  document.getElementById("divNascimento").innerHTML = "Data de Nascimento:";
	  document.getElementById("divIndicado").style.display = "";
	 // document.getElementById("divLicencas").style.display = "none";
   }
}

function mudaTipoSenha(tipo)
{
   //alert(tipo);
   if(tipo == "C"){
	  document.getElementById("email").style.display = "none";
	  document.getElementById("codigo").style.display = "";
   }
   else{
	  document.getElementById("email").style.display = "";
	  document.getElementById("codigo").style.display = "none";
   }
}

function bloqueiaCampos(){
    if(document.Form_Cad.graficoTipo[0].checked == true){
		document.Form_Cad.radio.disabled = false;
		document.Form_Cad.indicadores.disabled = false;	
		document.Form_Cad.conferencias.disabled = false;  
		document.Form_Cad.potenciais.disabled = false;  
		document.Form_Cad.ferramentas.disabled = false;
		document.Form_Cad.cursoFigurasDown.disabled = false;
		document.Form_Cad.cursoFigurasConf.disabled = false;
		document.Form_Cad.cursoLinhasDown.disabled = false;
		document.Form_Cad.cursoLinhasConf.disabled = false;
		document.Form_Cad.cursoGapsDown.disabled = false;
		document.Form_Cad.cursoGapsConf.disabled = false;
		document.Form_Cad.cursoCanaisDown.disabled = false;
		document.Form_Cad.cursoCanaisConf.disabled = false;
		document.getElementById("termosDiamante").style.display = "none";
	}
	if(document.Form_Cad.graficoTipo[1].checked == true){
		// ||
	   // document.Form_Cad.graficoTipo[2].checked == true ||
	   // document.Form_Cad.graficoTipo[3].checked == true ||
	   // document.Form_Cad.graficoTipo[4].checked == true){
		document.Form_Cad.radio.disabled = true;
		document.Form_Cad.indicadores.disabled = true;	
		document.Form_Cad.conferencias.disabled = true;  
		document.Form_Cad.potenciais.disabled = true;  
		document.Form_Cad.ferramentas.disabled = true;
	//	document.Form_Cad.cursoFigurasDown.disabled = true;
	//	document.Form_Cad.cursoFigurasConf.disabled = true;
	//	document.Form_Cad.cursoLinhasDown.disabled = true;
	//	document.Form_Cad.cursoLinhasConf.disabled = true;
	//	document.Form_Cad.cursoGapsDown.disabled = true;
	//	document.Form_Cad.cursoGapsConf.disabled = true;
	//	document.Form_Cad.cursoCanaisDown.disabled = true;
	//	document.Form_Cad.cursoCanaisConf.disabled = true;
		document.getElementById("termosDiamante").style.display = "";
  }
}