function mascara(o,f){  
    v_obj=o  
    v_fun=f  
    setTimeout("execmascara()",1)  
}  
  
function execmascara(){  
    v_obj.value=v_fun(v_obj.value)  
}  
   
function leech(v){  
    v=v.replace(/o/gi,"0")  
    v=v.replace(/i/gi,"1")  
    v=v.replace(/z/gi,"2")  
    v=v.replace(/e/gi,"3")  
    v=v.replace(/a/gi,"4")  
    v=v.replace(/s/gi,"5")  
    v=v.replace(/t/gi,"7")  
    return v  
}  
  
function soNumeros(v){  
    return v.replace(/\D/g,"")  
}
 
function VerificaLogin() {
	// Sintaxe de utilização: onSubmit="return VerificaLogin()"
    var campo1 = AchaObj('txtUsuario'),campo2 = AchaObj('pwdSenha');
	if (campo1.value == '') {
		campo1.focus();
		alert('Informe o LOGIN e SENHA');
		return false;
	}else if (campo1.value.indexOf('@') < 1 || campo1.value.indexOf('@') == campo1.value.length-1) {
		alert('Você deve informar um e-mail válido');
		campo1.focus();
		return false; 
	} else if (campo2.value == '') {
		campo2.focus();
		alert('Informe a senha');
		return false;
	} else {
		return true;
	}
}

function StatusBar(msgStr) { //v1.0
  status=msgStr;
  document.ReturnValue = true;
}

function AchaObj(n, d) {
  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=AchaObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function soNumero(e) {
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if (tecla == 44) // backspace
					return true;
				else
					return false;
			}

}

function valida_cgc_cpf(campo) {
         thefield = AchaObj(campo)

         if (thefield.value.length == 12)
             {
               vtipopessoa = 'F';
             } else if (thefield.value.length == 15)
             {
               vtipopessoa = 'J';
             } else 
             {
               vtipopessoa = '-'; 
             }
         
         
         if (vtipopessoa == "")
         {
            vtipopessoa = '-';
         }

         num = thefield.value;
         num = num.toString().replace(/\-|\/|\./g,'');
         thefield.value = num;

         if (thefield.value.length == 0)
            { return false; }


         if (isNaN(thefield.value))
             {
              alert("o CPF/CNPJ ( "+thefield.value+" ) contém caracteres inválidos, informe somente números !") ;
              thefield.value = "";
              thefield.focus();
              return false;
             }
         if (thefield.value.length != 11 && thefield.value.length != 14)
             {
               alert( "O CPF/CNPJ ( "+thefield.value+" ) informado não é válido !" );
               thefield.value = "";
               thefield.focus();
               return false;
             }
         if ( (thefield.value.length == 11 && vtipopessoa == "J") || (thefield.value.length == 14 && vtipopessoa == "F") )
             {
               if (vtipopessoa=="J") {
                  alert( "O CNPJ ( "+thefield.value+" ) informado não é valido !" );
               } else {
                  if (vtipopessoa=="F") {
                     alert( "O CPF ( "+thefield.value+" ) informado não é valido !" );
                  } else {
                     alert( "O CPF/CNPJ ( "+thefield.value+" ) informado não é valido !" );
                  }
               }
               thefield.value = "";
               thefield.focus();
               return false;
             }
         if (thefield.value.length == 14) {
             if (checa_cgc( thefield.value ) == 0)
                {
                   thefield.focus();
                   return false;
                }
               Monta_Mascara_CGC(thefield);
              }

         if (thefield.value.length == 11) {
             if (checa_cpf( thefield.value ) == 0)
                {
                   thefield.focus();
                   return false;
                }
              Monta_Mascara_CPF(thefield);
             }

         return ;
      }
      
      function inteiro( wValor )
        {
           wResult = "" ;
           wString = ""+wValor ;
           for ( wfor = 0 ; wfor < wString.length ; ++wfor )
              {
                  if (wString.substr(wfor,1) == "." )
                     wfor = wString.length + 1;
                  else
                     wResult += wString.substr(wfor,1);
              }
           return parseInt( wResult ) ;
        }
        
    function checa_cgc(vcgc)
      {

         d=new Array(12);
         i=0;
         df2=0;
         df3=0;
         resto1=0;
         resto2=0;
         temp=0;
         for( i=0 ; i < 12 ; i++ )
            {
               temp = vcgc.substr(i,1) ;
               temp = parseInt(temp) ;
               d[i] = temp ;
            }

         df1  = 5 * d [0];
         df1 += 4 * d [1];
         df1 += 3 * d [2];
         df1 += 2 * d [3];
         df1 += 9 * d [4];
         df1 += 8 * d [5];
         df1 += 7 * d [6];
         df1 += 6 * d [7];
         df1 += 5 * d [8];
         df1 += 4 * d [9];
         df1 += 3 * d [10];
         df1 += 2 * d [11];

         df2 = df1 / 11 ;
         df2 = inteiro( df2 ) ;
         df3 = df2 * 11 ;
         resto1 = df1 - df3 ;

         if ( resto1 == 1 || resto1 == 0 ) pridig = 0 ;
         else                              pridig = 11 - resto1;

        df1  = 6 * d [0];
        df1 += 5 * d [1];
        df1 += 4 * d [2];
        df1 += 3 * d [3];
        df1 += 2 * d [4];
        df1 += 9 * d [5];
        df1 += 8 * d [6];
        df1 += 7 * d [7];
        df1 += 6 * d [8];
        df1 += 5 * d [9];
        df1 += 4 * d [10];
        df1 += 3 * d [11];
        df1 += 2 * pridig ;

        df2 = df1 / 11 ;
        df2 = inteiro( df2 ) ;
        df3 = df2 * 11 ;
        resto2 = df1 - df3 ;

        if (resto2 == 0 || resto2 == 1) segdig = 0 ;
        else                            segdig = 11 - resto2 ;

        resto1 = parseInt(vcgc.substr(12,1)) ;
        resto2 = parseInt(vcgc.substr(13,1)) ;

        if (pridig == resto1 && segdig == resto2 )
           { return (1) ; }
        else
           { alert( "O número do CNPJ é inválido") ;
             thefield.value = "";
             thefield.focus();
             return (0) ; }
      }

    function checa_cpf(vcpf)
      {

         wSx1 = 0 ;
         wCpfDigit = 0 ;
         y = 0 ;
         temp = 0 ;
         temp2= 0 ;

         wCpfCalc = vcpf.substr(0,9) ;
         wSomaCpf = 0 ;

         for( wsx1 = 1 ; wsx1 < 10 ; wsx1++ )
             {
                temp = vcpf.substr(wsx1-1,1);
                temp = parseInt(temp) ;
                temp = temp * ( 11 - wsx1 ) ;
                wSomaCpf += temp ;
             }

         temp = wSomaCpf%11 ;
         wCpfDigit = 11 - temp ;

         if ( wCpfDigit == 10 || wCpfDigit == 11 )
              wCpfCalc += "0" ;
         else
              wCpfCalc += wCpfDigit ;

         wSomaCpf = 0 ;
         for ( wsx1=1 ; wsx1 < 11 ; wsx1++ )
            {
                temp = vcpf.substr(wsx1-1,1);
                temp = parseInt(temp) ;
                temp = temp * ( 12-wsx1 ) ;
                wSomaCpf += temp ;
            }

         temp = wSomaCpf%11 ;
         wCpfDigit = 11 - temp ;

         if ( wCpfDigit == 10 || wCpfDigit == 11 )
             wCpfCalc += "0" ;
         else
             wCpfCalc += wCpfDigit ;

         if ( vcpf != wCpfCalc )
            {
                alert("O número do CPF e invalido !") ;
                thefield.value = "";
                thefield.focus();
                return (0) ;
            }
      }

function Monta_Mascara_CPF(theField)
{

spCGC = theField.value;
spMascara = ""

if (spCGC != "")
{

nLen = spCGC.length;
nIndex = 0;
sValor = "";

while ( nIndex < nLen )
        {
        sDigito = spCGC.substring(nIndex,nIndex+1)
        if ( sDigito >= '0' && sDigito <= '9' )
                {
                sValor = sValor + sDigito
                }
        nIndex++;
        }
spCGC = sValor;

bOk = 1
sNum = ""
if( spCGC == '0' )
        {
        bOk = 0
        }
else
        {
        spCGC = '00000000' + spCGC
        spCGC = spCGC.substring( spCGC.length - 11,( spCGC.length - 11 ) + 11 )
        nQtd_Pos = spCGC.length
        if ( nQtd_Pos > 11 )
                {
                spMascara = '0'
                }
        else
                {
                sDigito2 = spCGC.substring( (nQtd_Pos - 2), (nQtd_Pos - 2) + 2)
                nI = 1
                while ( nQtd_Pos - (nI + 2) >= 0 )
                        {
                        if ( ( nI == 4  ) || ( nI == 7 ) )
                                {
                                sNum = '.' + sNum
                                }
                        sNum = spCGC.substring((nQtd_Pos - (nI + 2)), (nQtd_Pos - (nI + 2)) + 1) + sNum
                        nI = nI + 1
                        }
                spMascara = sNum + '-' + sDigito2
  }             }

  //frmCadastro.dfCPF.value = spMascara
  theField.value = spMascara
}
return true
}
function Monta_Mascara_CGC( theField)
{
spCGC = theField.value;
spMascara = ""

if ( spCGC != "" )

{

nLen = spCGC.length;
nIndex = 0;
sValor = "";

while ( nIndex < nLen )
	{
	sDigito = spCGC.substring(nIndex,nIndex+1)
	if ( sDigito >= '0' && sDigito <= '9' )
		{
		sValor = sValor + sDigito
		}
	nIndex++;
	}
spCGC = sValor;

bOk = 1
sNum = ""
if( spCGC == '0' )
	{
	bOk = 0
	}
else
	{
	spCGC = '00000000000000' + spCGC
	spCGC = spCGC.substring( spCGC.length - 14,( spCGC.length - 14 ) + 14 )
	nQtd_Pos = spCGC.length


	if ( ( nQtd_Pos < 7 ) || ( nQtd_Pos > 14 ) )
		{
		spMascara = '0'
		}
	else
		{
		sDigito2 = spCGC.substring( (nQtd_Pos - 2), (nQtd_Pos - 2) + 2)
		sDigito4 = spCGC.substring( (nQtd_Pos - 6), (nQtd_Pos - 6) + 4)
		sNumero_CGC = spCGC.substring( 0, (nQtd_Pos - 6) )

		nI = 1
		while ( nQtd_Pos - (nI + 6) >= 0 )
			{
			if ( ( nI == 4  ) || ( nI == 7 ) )
				{
				sNum = '.' + sNum
				}
			sNum = spCGC.substring((nQtd_Pos - (nI + 6)), (nQtd_Pos - (nI + 6)) + 1) + sNum
			nI = nI + 1
			}
		spMascara = sNum + '/' + sDigito4 + '-' + sDigito2

    }		}

  theField.value = spMascara
}
return true
}



function VerificaRepresentante() {
	// Sintaxe de utilização: onSubmit="return VerificaLiberacao()"
    var campo2 = AchaObj('razaosocial_nome');
    var campo4 = AchaObj('cpfcnpj');
    var campo7 = AchaObj('nomecontato');
    var campo8 = AchaObj('ddd');
    var campo9 = AchaObj('telefone');
    var campo10 = AchaObj('email');
    var campo11 = AchaObj('cidade');
    var campo12 = AchaObj('estado');
    var campo13 = AchaObj('comoconheceu');
    var campo14 = AchaObj('jafoirepresentante');
    var campo16 = AchaObj('quantospontosvenda');
    var campo17 = AchaObj('regioesatua');
    var campo18 = AchaObj('regioesinteresse');
    var campo19 = AchaObj('nichos');
    var campo20 = AchaObj('expectativavenda');
    var campo21 = AchaObj('conheceuoutros');
    var campo22 = AchaObj('jafoirepresentantequais');
    var campo23 = AchaObj('jafoirepresentantetempo');
    var campo24 = AchaObj('nichosquais');
	if (campo2.value == '') {
		campo2.focus();
		alert('Informe Razão Social ou Nome para prosseguir!');
		return false;
	} else if (campo4.value == '') {
		campo4.focus();
		alert('Informe o CPF ou CNPJ para prosseguir!');
		return false;		
	} else if (campo7.value == '') {
		campo7.focus();
		alert('Informe o Nome do Contato para prosseguir!');
		return false;	
	} else if (campo8.value == '') {
		campo8.focus();
		alert('Informe o DDD para prosseguir!');
		return false;				
	} else if (campo9.value == '') {
		campo9.focus();
		alert('Informe o Telefone para prosseguir!');
		return false;	
	} else if (campo10.value == '') {
		campo10.focus();
		alert('Informe o E-mail para prosseguir!');
		return false;	
	} else if (campo11.value == '') {
		campo11.focus();
		alert('Informe a Cidade para prosseguir!');
		return false;	
	} else if (campo12.value == '') {
		campo12.focus();
		alert('Informe o Estado para prosseguir!');
		return false;
	} else if (campo12.value == '-1') {
		campo12.focus();
		alert('Informe o Estado para prosseguir!');
		return false;
	} else if (campo13.value == '-1') {
		campo13.focus();
		alert('Informe como você conheceu ITD');
		return false;	
	} else if (campo16.value == '') {
		campo16.focus();
		alert('Informe em quantos pontos de venda você atua!');
		return false;		
	} else if (campo17.value == '') {
		campo17.focus();
		alert('Informe em quais regiões você atua!');
		return false;
	} else if (campo18.value == '') {
		campo18.focus();
		alert('Informe em quais regiões você tem interesse de atuar!');
		return false;	
	} else if (campo19.value == 'sim') {
		if (campo22.value == '') {
		campo21.focus();
		alert('Informe quais os Nichos!');
		return false;
		}
	} else if (campo20.value == '') {
		campo20.focus();
		alert('Informe sua expectativa de vendas!');
		return false;
	} else {
		return true;
	}
}


function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' deve ser válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' deve ser preenchido somente com números.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' é necessário preenchimento.\n'; }
  } if (errors) alert('Ocorreram os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function AbreTeSesamo(imageType,imageName,imageWidth,imageHeight,alt,posLeft,posTop) {  // v4.01
newWindow = window.open("","newWindow","width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+posLeft+",top="+posTop);
newWindow.document.open();
newWindow.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
{
newWindow.document.write('<img src=\"'+imageName+'\" width='+imageWidth+' height='+imageHeight+' alt=\"'+alt+'\">'); 	}
newWindow.document.write('</body></html>');
newWindow.document.close();
newWindow.focus();
}


function countChars(form) {

var text1 = document.postar.Mensagem.value

document.postar.totalChars.value = text1.length
document.postar.msg_total.value = text1
document.postar.totalCounter.value = 1500 - text1.length;


if (document.postar.totalCounter.value < 1) {
	//document.postar.Mensagem.value='';
	document.postar.adicionarmensagem.disabled=true;
	alert ("Atenção, sua mensagem não deve ter mais de 1500 caracteres")
}

if (document.postar.totalCounter.value >= 1) {
	//document.postar.Mensagem.value='';
	document.postar.adicionarmensagem.disabled=false;
}
}

function ordena(acao,item,qtd){
	var opcao = AchaObj(item); 
	if (opcao.selectedIndex == -1) {
		alert('Selecione um item');
	} else {
	    if (acao == 'sobe') {
		    if (opcao[qtd].value != opcao[opcao.selectedIndex].value) {
			    var textosobe = opcao[opcao.selectedIndex].text;
			    var valorsobe = opcao[opcao.selectedIndex].value;
			    var textodesce = opcao[opcao.selectedIndex-1].text;
			    var valordesce = opcao[opcao.selectedIndex-1].value;
    		
			    opcao[opcao.selectedIndex-1].text = textosobe;
			    opcao[opcao.selectedIndex-1].value = valorsobe;
			    opcao[opcao.selectedIndex].text = textodesce;
			    opcao[opcao.selectedIndex].value = valordesce;

			    opcao.selectedIndex = opcao.selectedIndex-1;
		    }
	    } 
	    if (acao == 'desce') {
		    if (opcao[qtd].value != opcao[opcao.selectedIndex].value) {
			    var textodesce = opcao[opcao.selectedIndex].text;
			    var valordesce = opcao[opcao.selectedIndex].value;
			    var textosobe = opcao[opcao.selectedIndex+1].text;
			    var valorsobe = opcao[opcao.selectedIndex+1].value;
    		
			    opcao[opcao.selectedIndex+1].text = textodesce;
			    opcao[opcao.selectedIndex+1].value = valordesce;
			    opcao[opcao.selectedIndex].text = textosobe;
			    opcao[opcao.selectedIndex].value = valorsobe;
    		
			    opcao.selectedIndex = opcao.selectedIndex+1;
		    }
	    }
	}
	document.resposta = false;
}

function VerificaOrdenar(campo){
	var campo = AchaObj(campo);
    for (i=0;i<campo.length;i++) {
	    campo[i].selected = true;
    }
    document.resposta = true;
}

function OpenWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

