﻿// JScript File
function valideLogin()
{
    var str ="ctl00_wuc_loginparticipante1_";
    var msg = "";
    
     if(document.getElementById(str+'email').value == '' || document.getElementById(str+'email').value == 'SEU E-MAIL')
        msg += 'É necessário informar seu e-mail! \n';
     else
     {
        if(validaEmail(document.getElementById(str+'email').value))
            msg += 'O e-mail está no formato incorreto! \n';
     }
     if(document.getElementById(str+'senha').value == '' || document.getElementById(str+'senha').value == '****')
        msg += 'É necessário informar sua senha! \n';
      
      if(msg != "")
      {
        alert(msg);
        return false;
      }
      else
      {
        document.getElementById('logar').value = 'ok';
        return true;
      }
}
function valideFormInscricao()
{
    var str ="ctl00_ContentPlaceHolder1_WucFormInscrevase1_"
    var msg = "";
    if(document.getElementById(str+'nome').value == '' || document.getElementById(str+'nome').value == 'Nome:')
        msg += 'É necessário informar seu nome! \n';
   
    if(document.getElementById(str+'sobreNome').value == '' || document.getElementById(str+'sobreNome').value == 'Último nome:')
        msg += 'É necessário informar seu Último Nome! \n';
   
   if(document.getElementById(str+'sexo').value == '' )
        msg += 'É necessário informar seu Sexo! \n';
        
    if(document.getElementById(str+'dataNascimento').value == '' || document.getElementById(str+'dataNascimento').value == 'Data de Nascimento:')
        msg += 'É necessário informar sua Data de nascimento! \n';
    else
    {
        var d = parseDate(document.getElementById(str+'dataNascimento').value);
        if(d == null)
          msg += 'Data de nascimento no formato inválido ! \n';
    }  
    if(document.getElementById(str+'telefone').value == '' || document.getElementById(str+'telefone').value == 'Telefone:')
        msg += 'É necessário informar seu telefone! \n';   
    /*if(document.getElementById(str+'celular').value == '' || document.getElementById(str+'celular').value == 'Celular:')
        msg += 'É necessário informar seu Celular! \n';     */
    if(document.getElementById(str+'endereco').value == '' || document.getElementById(str+'endereco').value == 'Endereço Completo:')
        msg += 'É necessário informar seu Endereço! \n';  
     if(document.getElementById(str+'bairro').value == '' || document.getElementById(str+'bairro').value == 'Bairro:')
        msg += 'É necessário informar seu Bairro! \n';         
        
     if(document.getElementById(str+'estado').value == '' )
        msg += 'É necessário informar seu Estado! \n';   
    if(document.getElementById(str+'cidade').value == '' || document.getElementById(str+'cidade').value == 'Cidade:')
        msg += 'É necessário informar sua Cidade! \n';  
    if(document.getElementById(str+'email').value == '' )
        msg += 'É necessário informar seu Email! \n';
     else
     {
        if(validaEmail(document.getElementById(str+'email').value))
            msg += 'O e-mail está no formato incorreto! \n';
            else
            {
                if(document.getElementById(str+'email').value != document.getElementById(str+'confirmeEmail').value)
                {
                     msg += 'O E-mail e a confirmação de E-mail devem serem iguais! \n';
                }
            }
     }  
      if(document.getElementById(str+'senha').value == '' )
        msg += 'É necessário informar seu Senha! \n';
        else
            {
                if(document.getElementById(str+'senha').value != document.getElementById(str+'confirmeSenha').value)
                {
                     msg += 'A senha e a confirmação de senha devem serem iguais! \n';
                }
            }
      
           
    if(msg != '')
        alert(msg);
        else
        {
            document.getElementById('foi').value = 'ok';
            document.forms[0].submit();
        }
    //alert(document.getElementById(str+'nome').value);
}

function valideLembreSenha()
{
    var msg = "";
    if(document.getElementById('txtEmail').value == '' )
        msg += 'É necessário informar seu Email! \n';
     else
     {
        if(validaEmail(document.getElementById('txtEmail').value))
            msg += 'O e-mail está no formato incorreto! \n';
           
     }  
    if(msg != '')
    {
        alert(msg);
        return false;
    }
        else
        {
            return true;
        }
}
function valideFormInscricao2()
{
    var str ="ctl00_ContentPlaceHolder1_wucDadosProducao_"
    var msg = "";
    if(document.getElementById(str+'razaoSocial').value == '' || document.getElementById(str+'razaoSocial').value == 'Razão social:')
        msg += 'É necessário informar a Razão Social! \n';
   
    if(document.getElementById(str+'nomeFantasia').value == '' || document.getElementById(str+'nomeFantasia').value == 'Nome de fantasia:')
        msg += 'É necessário informar o Nome de fantasia! \n';
	 if(document.getElementById(str+'endereco').value == '' || document.getElementById(str+'endereco').value == 'Endereço completo:')
        msg += 'É necessário informar o Endereço completo! \n';
   
   if(document.getElementById(str+'cnpj').value == '' || document.getElementById(str+'cnpj').value == 'CNPJ:')
        msg += 'É necessário informar o CNPJ! \n';
    else
    {
	   var m = validaCNPJ(document.getElementById(str+'cnpj').value); 
       if(m != '')
		{
			 msg += 'CNPJ inválido!! ! \n';
		}  
	}
    if(document.getElementById(str+'responsavel').value == '' || document.getElementById(str+'responsavel').value == 'Nome do responsável:')
        msg += 'É necessário informar o Nome do Responsável! \n';
      
	if(document.getElementById(str+'cpf').value == '' || document.getElementById(str+'cpf').value == 'CPF:')
        msg += 'É necessário informar o CPF! \n';
    else
    {
       if(!validacpf(document.getElementById(str+'cpf').value))
		{
			  msg += 'CPF inválido!! ! \n';
		}  
	}
	
    if(document.getElementById(str+'ano').value == '' || document.getElementById(str+'ano').value == 'Ano de criação da unidade:')
        msg += 'É necessário informar o Ano de criação da unidade! \n';
    else
    {
       if(!isNumerico(document.getElementById(str+'ano').value))
          msg += 'Ano de criação da unidade deverá ser um ano válido ! \n';
    }  

	if(document.getElementById(str+'colaboradores').value == '' || document.getElementById(str+'ano').value == 'Número de colaboradores:')
        msg += 'É necessário informar o Número de colaboradores! \n';
    else
    {
       if(!isNumerico(document.getElementById(str+'colaboradores').value))
          msg += 'O número de colaboradores deverá ser um número válido ! \n';
    }  


	if(document.getElementById(str+'simTemSite').checked)
    {
		if(document.getElementById(str+'url').value == '' || document.getElementById(str+'url').value == 'Endereço do site:')
			msg += 'É necessário informar o Endereço do site! \n';
	}

	if(document.getElementById(str+'produto01').value == '' || document.getElementById(str+'produto01').value == 'Nome do Produto'||document.getElementById(str+'produto02').value == '' || document.getElementById(str+'produto02').value == 'Nome do Produto' || document.getElementById(str+'produto03').value == '' || document.getElementById(str+'produto03').value == 'Nome do Produto')
        msg += 'É necessário todos os Principais produtos! \n';
	if(document.getElementById(str+'volume01').value == '' || document.getElementById(str+'volume01').value == 'Volume mensal'||document.getElementById(str+'volume02').value == '' || document.getElementById(str+'volume02').value == 'Volume mensal' || document.getElementById(str+'volume03').value == '' || document.getElementById(str+'volume03').value == 'Volume mensal')
        msg += 'É necessário informar o volume de produção mensal de cada produto! \n';
   
    if(document.getElementById(str+'volumeMensal').value == '' || document.getElementById(str+'volumeMensal').value == 'R$')
        msg += 'É necessário informar o Volume médio de vendas mensal ! \n';
    else
    {
       if(!isGrana(document.getElementById(str+'volumeMensal').value))
          msg += 'Volume médio de vendas mensal de estar no formato monetário, valor e centavos! \n';
    }  

	if(document.getElementById(str+'volumeAnual').value == '' || document.getElementById(str+'volumeAnual').value == 'R$')
        msg += 'É necessário informar o Volume médio de vendas anual ! \n';
    else
    {
       if(!isGrana(document.getElementById(str+'volumeAnual').value) )
          msg += 'Volume estimado de vendas anual de estar no formato monetário, valor e centavos! \n';
    }  

	if(document.getElementById(str+'local').value == '')
        msg += 'É necessário a porcentagem local do mercado comprador ! \n';
    else
    {
       if(!isNumerico(document.getElementById(str+'local').value))
          msg += 'A porcentagem local do mercado comprador deverá está no formato numérico! \n';
    }
	
	if(document.getElementById(str+'regional').value == '')
        msg += 'É necessário a porcentagem regional do mercado comprador ! \n';
    else
    {
       if(!isNumerico(document.getElementById(str+'regional').value))
          msg += 'A porcentagem regional do mercado comprador deverá está no formato numérico! \n';
    }

	if(document.getElementById(str+'regional').value == '' )
        msg += 'É necessário a porcentagem regional do mercado comprador ! \n';
    else
    {
       if(!isNumerico(document.getElementById(str+'nacional').value))
          msg += 'A porcentagem nacional do mercado comprador deverá está no formato numérico! \n';
    }

	if(document.getElementById(str+'internacional').value == '' )
        msg += 'É necessário a porcentagem internacional do mercado comprador ! \n';
    else
    {
       if(!isNumerico(document.getElementById(str+'internacional').value))
          msg += 'A porcentagem internacional do mercado comprador deverá está no formato numérico! \n';
    }
    
    var total = 0;
    
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_internacional').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_internacional').value);
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_nacional').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_nacional').value);
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_regional').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_regional').value);
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_local').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_local').value);
    }
    
    if(total != 100)
    {
        msg += 'Os valores do mercado comprador devem somar 100%! \n';
    }

    if(msg != '')
    alert(msg);
    else
    {
		document.getElementById('foiDadosProducao').value = 'ok';
        document.forms[0].submit();
    }
    //alert(document.getElementById(str+'nome').value);
}

function valideFormQuestionario()
{
	document.getElementById('envioQuest').value = 'ok';	
	document.forms[0].submit();
}

function valideFormArquivo()
{
    var qFotos = 0;
                               //ctl00_ContentPlaceHolder1_wucArquivo_wucFoto1_arquivo
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto1_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto2_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto3_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto4_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto5_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto6_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto7_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto8_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto9_arquivo').value != '')
    {
        qFotos++;
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucArquivo_wucFoto10_arquivo').value != '')
    {
        qFotos++;
    }
    
    if (qFotos <5)
    {
        alert('Por favor, selecione no mínimo 5 fotos.');
    }
    else
    {
	    document.getElementById('enviaFotos').value = 'ok';	
	    document.forms[0].submit();
	}
}

function validaEmail(str) 
{ 
	if(str.length > 0)
	{
 		if (str.search(/^([a-zA-Z0-9\.\_\-])+@([a-zA-Z0-9\_\-])+\.([a-zA-Z0-9\.\_\-])+([a-zA-Z])$/)) 
 		{
 			return true;
 		}	 
 		else 
 		{	
 			return false; 
		}
	}
	else
	{
		return false;
	}
}

function validaclickCampo(obj,v)
{
    if(obj.value == v)
    {
        obj.value = '';
    }
}

function validablur(obj,v)
{
     if(obj.value == '')
    {
        obj.value = v;
    }
}

function isNumerico(pVal)
{
	var reDigits = /^\d+$/;
	return reDigits.test(pVal);
}

function isGrana(pVal)
{
	var reDigits = /^[+-]?((\d+|\d{1,3}(\.\d{3})+)(\,\d*)?|\,\d+)$/;
	return reDigits.test(pVal);
}

function valida100(control)
{
    var total = 0;
    
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_internacional').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_internacional').value);
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_nacional').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_nacional').value);
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_regional').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_regional').value);
    }
    if (document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_local').value!='')
    {
        total  = total + parseFloat(document.getElementById('ctl00_ContentPlaceHolder1_wucDadosProducao_local').value);
    }
     
     
        
    if (total > 100)
    {
        
        control.value = '';
        alert('Os valores do mercado comprador não podem somar mais de 100%');
        control.focus();
        return false;
    }           
}