// validação dos outros campos	   
	   
function FormValidator(theForm){
	
	var emailID=document.form1.txt_email
	
	
	if (form1.txt_cpf.value==""){
		alert("CPF Inválido!");
		form1.txt_cpf.focus();
		return (false);
	}
	
	if (form1.txt_nome.value==""){
		alert("Qual é o seu nome/loja?");
		form1.txt_nome.focus();
		return (false);
	}
	
	if (form1.txt_email.value==""){
		alert("Qual é o seu e-mail?");
		form1.txt_email.focus();
		return (false);
	}
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Qual é o seu e-mail?")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	
	//if (form1.txt_dddtelefone.value==""){
	//alert("Qual é o DDD do seu telefone?");
	//form1.txt_dddtelefone.focus();
	//return (false);
	//	}
	
	//	if (form1.txt_telefone.value==""){
	//		alert("Qual é o seu telefone?");
	//		form1.txt_telefone.focus();
	//		return (false);
	//	}
	
	//	if (form1.txt_dddcelular.value==""){
	//		alert("Qual é o DDD do seu celular?");
	//		form1.txt_dddcelular.focus();
	//		return (false);
	//	}
	
	//	if (form1.txt_celular.value==""){
	//		alert("Qual é o seu celular?");
	//		form1.txt_celular.focus();
	//		return (false);
	//	}
	
	if (form1.txt_bairro.value==""){
		alert("Qual é o seu bairro?");
		form1.txt_bairro.focus();
		return (false);
	}
	
	if (form1.txt_cidade.value==""){
		alert("Qual é a sua cidade?");
		form1.txt_cidade.focus();
		return (false);
	}
	
	if (form1.txt_estado.value==""){
		alert("Qual é o seu estado?");
		form1.txt_estado.focus();
		return (false);
	}
	
	if (form1.txt_estadocarro.value==""){
		alert("Qual é o estado do carro?");
		form1.txt_estadocarro.focus();
		return (false);
	}
	
	if (form1.txt_marca.value==""){
		alert("Qual é a marca do carro?");
		form1.txt_marca.focus();
		return (false);
	}
	
	if (form1.txt_modelo.value==""){
		alert("Qual é o modelo do carro?");
		form1.txt_modelo.focus();
		return (false);
	}
	
	
	if (form1.txt_ano.value==""){
		alert("Qual é o ano do carro?");
		form1.txt_ano.focus();
		return (false);
	}
	
	if (form1.txt_mod_fab.value==""){
		alert("Qual é o modelo de fabricação do carro?");
		form1.txt_mod_fab.focus();
		return (false);
	}
	
	
	if (form1.txt_versao.value==""){
		alert("Qual é a versão do carro?");
		form1.txt_versao.focus();
		return (false);
	}
	
	if (form1.txt_km.value==""){
		alert("Qual é a kilometragem do carro?");
		form1.txt_km.focus();
		return (false);
	}
	
	if (form1.txt_placa.value==""){
		alert("Qual é a placa do carro?");
		form1.txt_placa.focus();
		return (false);
	}
	
	
	if (form1.txt_cambio.value==""){
		alert("Qual é o tipo de câmbio do carro?");
		form1.txt_cambio.focus();
		return (false);
	}
	
	if (form1.txt_portas.value==""){
		alert("Quantas portas tem o carro?");
		form1.txt_portas.focus();
		return (false);
	}
	
		
	if (form1.txt_cor.value==""){
		alert("Qual é a cor do carro?");
		form1.txt_cor.focus();
		return (false);
	}
	
	
	if (form1.txt_combustivel.value==""){
		alert("Qual é o combustível do carro?");
		form1.txt_combustivel.focus();
		return (false);
	}
		
	if (form1.txt_valor.value==""){
		alert("Qual é o valor do carro?");
		form1.txt_valor.focus();
		return (false);
	}
	
	
	
var txt_obs="";
function js_textarea(){
	txt_obs=form1.txt_obs.value;
	form1.txt_obs.value=form1.txt_obs.value.length+1;
	if(form1.txt_obs.value.length>200){
		form1.txt_obs.value=txt_obs.substring(0,200);
		form1.txt_obs.value=form1.txt_obs.value.length+1;
	}
}
	
   
return (true);
}





// fim da validação dos outros campos

//*******************************************************************************************

// Validação do e-mail

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("E-mail inválido!")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("E-mail inválido!")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("E-mail inválido!")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("E-mail inválido!")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("E-mail inválido!")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("E-mail inválido!")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("E-mail inválido!")
		    return false
		 }

 		 return true					
	}

 
 
// Somente números

function numbersonly(txt_dddtelefone,txt_telefone,txt_dddcelular,txt_celular, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   txt_dddtelefone.form1.elements[dec].focus();
   txt_telefone.form1.elements[dec].focus();
   txt_dddcelular.form1.elements[dec].focus();
   txt_celular.form1.elements[dec].focus();
   return false;
   }
else
   return false;
}



// Fim somente números



//******************************************************
//******************VALIDAÇÃO DE CPF********************
//******************************************************
//Verificação de CPF
function check_cpf (txt_cpf)
{
StrCPF = "";
//if (tipcpf == 1) StrCPF = document.C.t_cpf.value;
StrCPF = txt_cpf.value
x = 0;
soma = 0;
dig1 = 0;
dig2 = 0;
texto = "";
StrCPF1="";
len = StrCPF.length;
x = len -1;
for (var i=0; i <= len - 3; i++)
{
	y = StrCPF.substring(i,i+1);
	soma = soma + ( y * x);
	x = x - 1;
	texto = texto + y;
}
dig1 = 11 - (soma % 11);
if (dig1 == 10) dig1=0 ;
if (dig1 == 11) dig1=0 ;
StrCPF1 = StrCPF.substring(0,len - 2) + dig1 ;
x = 11; soma=0;
for (var i=0; i <= len - 2; i++)
{
	soma = soma + (StrCPF1.substring(i,i+1) * x);
	x = x - 1;
}
dig2= 11 - (soma % 11);
if (dig2 == 10) dig2=0;
if (dig2 == 11) dig2=0;
if ((dig1 + "" + dig2) == StrCPF.substring(len,len-2))
{
	return true;
}
	alert ("Número do CPF Inválido!");
	//if (tipcpf == 1)  document.C.t_cpf.focus();
	txt_cpf.focus()
  return false;
}
// Fim da validaçõ do CPF



function formatar_moeda(campo, separador_milhar, separador_decimal, tecla) {
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? tecla.which : tecla.keyCode;

	if (whichCode == 13) return true; // Tecla Enter
	if (whichCode == 8) return true; // Tecla Delete
	key = String.fromCharCode(whichCode); // Pegando o valor digitado
	if (strCheck.indexOf(key) == -1) return false; // Valor inválido (não inteiro)
	len = campo.value.length;
	for(i = 0; i < len; i++)
	if ((campo.value.charAt(i) != '0') && (campo.value.charAt(i) != separador_decimal)) break;
	aux = '';
	for(; i < len; i++)
	if (strCheck.indexOf(campo.value.charAt(i))!=-1) aux += campo.value.charAt(i);
	aux += key;
	len = aux.length;
	if (len == 0) campo.value = '';
	if (len == 1) campo.value = '0'+ separador_decimal + '0' + aux;
	if (len == 2) campo.value = '0'+ separador_decimal + aux;

	if (len > 2) {
		aux2 = '';

		for (j = 0, i = len - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += separador_milhar;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}

		campo.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		campo.value += aux2.charAt(i);
		campo.value += separador_decimal + aux.substr(len - 2, len);
	}

	return false;
}

