function Validarform(theForm)
{
   if (theForm.nome.value.length == "")
  {
    alert("Por favor preencha o campo \"Nome da Loja\" corretamente.");
    theForm.nome.focus();
    return (false);
  }
      if (theForm.endereco.value == "")
  {
    alert("Por favor preencha o campo \"Endereço\".");
    theForm.endereco.focus();
    return (false);
  }
      if (theForm.bairro.value == "")
  {
    alert("Por favor preencha o campo \"Bairro\".");
    theForm.bairro.focus();
    return (false);
  }
    if (theForm.cidade.value == "")
  {
    alert("Por favor preencha o campo \"Cidade\".");
    theForm.cidade.focus();
    return (false);
  }
      if (theForm.uf.value == "")
  {
    alert("Por favor preencha o campo \"UF\".");
    theForm.uf.focus();
    return (false);
  }
   if (theForm.cep.value.length == "")
  {
    alert("Por favor preencha o campo \"CEP\" corretamente.");
    theForm.cep.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.fone1.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Por favor entre apenas com dígitos no campo \"Telefone\".");
    theForm.fone1.focus();
    return (false);
  }

     if (theForm.fone1.value == "")
  {
    alert("Por favor preencha o campo \"Telefone\".");
    theForm.fone1.focus();
    return (false);
  }
  var checkOK = "0123456789";
  var checkStr = theForm.fone2.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Por favor entre apenas com dígitos no campo \"Celular\".");
    theForm.fone2.focus();
    return (false);
  }

     if (theForm.fone2.value == "")
  {
    alert("Por favor preencha o campo \"Celular\".");
    theForm.fone2.focus();
    return (false);
  }
   if (theForm.cnpj.value.length == "")
  {
    alert("Por favor preencha o campo \"CNPJ\" corretamente.");
    theForm.cnpj.focus();
    return (false);
  }
  
	CNPJ = document.lojas.cnpj.value;
	erro = new String;
	if (CNPJ.length < 14) erro += "É necessário preencher corretamente o numero do CNPJ! \n\n";
	var nonNumbers = /\D/;
	if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";	
	var a = [];
	var b = new Number;
	var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	for (i=0; i<12; i++){
		a[i] = CNPJ.charAt(i);
		b += a[i] * c[i+1];
	}
	if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	b = 0;
	for (y=0; y<13; y++) {
		b += (a[y] * c[y]); 
	}
	if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
		erro +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		erro +="CNPJ incorreto. Digite um CNPJ válido!";
		alert(erro);
		return false;
	} 
		
	if (theForm.email.value == "")
  {
    alert("Por favor preencha o campo \"E-mail\".");
    theForm.email.focus();
    return (false);
  }
  
  function ChecaEmail(mail)
{
	if (mail.value.lastIndexOf("@") == -1 || mail.value.lastIndexOf(".") == -1)
		{
			alert("Formato ilegal para E-mail.");
    		mail.focus();
			return (false);
      	} 
	return (true);
}

	if (!ChecaEmail(theForm.email))
		return (false);

      if (theForm.quantidade.value == "")
  {
    alert("Por favor, informe a \"Quantidade\" de veículos em sua loja.");
    theForm.quantidade.focus();
    return (false);
  }
return (true);
}

function Numero(campo,e) 
{
	var cod="";
	if(document.all) {cod=event.keyCode;} else {cod=e.which;}
	if(cod == 08) return;
	if (cod < 48 || cod > 57)
	{
		if (cod < 45 || cod > 57) alert("Digite somente Caracteres Numéricos!");
		cod=0;
	campo.focus();
	return false;
	}
}

function FunTrtVlr() {
	if ((!((event.keyCode >= 48) && (window.event.keyCode <= 57))) && (event.keyCode != 13)) 
	{
		event.returnValue = false;
		return false;
	}
	return true;
}
	/*function validaCNPJ() {
		CNPJ = document.lojas.cnpj.value;
		erro = new String;
		if (CNPJ.length < 18) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
		if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
			if (erro.length == 0) erro += "E' necessarios preencher corretamente o numero do CNPJ! \n\n";
		}
		//substituir os caracteres que nao sao numeros
		if(document.layers && parseInt(navigator.appVersion) == 4){
			x = CNPJ.substring(0,2);
			x += CNPJ.substring(3,6);
			x += CNPJ.substring(7,10);
			x += CNPJ.substring(11,15);
			x += CNPJ.substring(16,18);
			CNPJ = x;	
		} else {
			CNPJ = CNPJ.replace(".","");
			CNPJ = CNPJ.replace(".","");
			CNPJ = CNPJ.replace("-","");
			CNPJ = CNPJ.replace("/","");
		}
		var nonNumbers = /\D/;
		if (nonNumbers.test(CNPJ)) erro += "A verificacao de CNPJ suporta apenas numeros! \n\n";	
		var a = [];
		var b = new Number;
		var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
		for (i=0; i<12; i++){
			a[i] = CNPJ.charAt(i);
			b += a[i] * c[i+1];
		}
		if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
		b = 0;
		for (y=0; y<13; y++) {
			b += (a[y] * c[y]); 
		}
		if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
		if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
			erro +="Digito verificador com problema!";
		}
		if (erro.length > 0){
			alert(erro);
			return false;
		} else {
			alert("CNPJ valido!");
		}
		return true;
	}*/
