function testavalor(foto,campo,flag)
{  
      if(foto.checked == 0 && campo.value != ''){alert("Foto não permitida pois o campo FOTO? não está selecionado!");return false;}
	  if(foto.checked == 1 && campo.value == ''){alert("Procure a imagem para ser vinculada ao anúncio");return false;}
	 
      return true;	  
}


function preco(texto, fot, foto, countfield, semana) {

if(semana.value == '0'){semana.value=1;}
if (fot.checked == 0) 
		countfield.value = parseFloat(texto.value) * parseFloat(semana.value);
else 
		countfield.value = (parseFloat(foto.value) + parseFloat(texto.value)) * parseFloat(semana.value);
}



/*function ContarCampo(formu, Campo, limite) {
var Elemento, Len, Array
    Elemento = formu.elements;
	Len = Elemento.length;
	Array = Campos.split( '?' , Len*2 );
   
if (Elemento[1].value.length > limite)
		Elemento[1].value = Elemento[1].value.substring(0, limite);	
else 
		Elemento[2].value = limite - Elemento[2].value.length;

}*/



function ContarCampo(campo, contador, limite) {
if (campo.value.length > limite)
		campo.value = campo.value.substring(0, limite);	
else 
		contador.value = limite - contador.value.length;
}

<!--

// Valida o formulario antes de envia-lo 
// Verifica Campos Nulos e suas Formatacoes(Tipo)
// Tipo E-Mail - Tipo texto - Tipo Numerico - Tipo AlfaNumerico
// VFrom = formulario a ser verificado
// Objs = nomes de objetos do form que nao sao necessarios
function ValidForm( VForm , Objs )
	{
	var Array, Msg, Len, Element, i, ix
	Msg = '';
	Element = VForm.elements;
	
	Len = Element.length;
	Array = Objs.split( '?' , Len*2 );
	for(ix=0; ix < Array.length ;ix++)
		for(i=0; i < Len ;i++)
			if( Array[ix] == Element[i].name )
				switch( Element[i].id )
					{
					case 'text' :
						if( Element[i].value == '' || IsLetter(Element[i].value) != -1 )
							{
							Element[i].select();
							Element[i].focus();

							Msg = 'Preencha o campo ' + Element[i].param;
							i	= Len;
							ix	= Array.length;
							}
						break;
              
              case 'cpf'	:
                 if (! checaCPF(Element[i].value)){
                     Msg = Element[i].param;
							Element[i].select();
							Element[i].focus();
                 }
                 break;
               
   			   case 'alfa' :
						if( Element[i].value == '' || IsAlfaNum(Element[i].value) != -1 )
							{
								Element[i].select();
								Element[i].focus();
								Msg = 'Preencha o campo ' + Element[i].param;
								i	= Len;
								ix	= Array.length;
							}
						break;
					case 'user' :
						if( Element[i].value == '' || IsUser(Element[i].value) != -1 )
							{
								Element[i].select();
								Element[i].focus();
								Msg = 'Preencha o campo ' + Element[i].param;
								i	= Len;
								ix	= Array.length;
							}
						break;
					case 'num' :
						if( Element[i].value == '' || IsNumber(Element[i].value) != -1 )
								{
							Element[i].select();
							Element[i].focus();
							Msg = 'Preencha o campo '+ Element[i].param;
							i	= Len;
							ix	= Array.length;
							}
						break;
	 				   
					case 'dinh' :
          if( Element[i].value == '')
           {
            Element[i].value = '0';
           }
						if( Element[i].value == '' || IsGrana(Element[i].value) != -1 )
								{
							Element[i].select();
							Element[i].focus();
							Msg = 'Preencha o campo '+ Element[i].param;
							i	= Len;
							ix	= Array.length;
							}
						break;
	
					case 'data' :
						if( Element[i].value == '' || IsData(Element[i].value) != -1 || Verificadata(Element[i].value) != -1)
							{
							Element[i].select();
							Element[i].focus();
							Msg = 'Preencha o campo '+ Element[i].param +' corretamente!';
							i	= Len;
							ix	= Array.length;
							}
						break;
						
					case 'mail' :
						if(! IsValidEmail(Element[i].value))
							{
							Element[i].select();
							Element[i].focus();
							Msg = 'E-Mail inválido.';
							i	= Len;
							ix	= Array.length;
							}
						break;
					case 'pswd2' :
						if( Element[i].value == '' )
							{
							Element[i].select();
							Element[i].focus();
							Msg = 'Preencha o campo senha.';
							i	= Len;
							ix	= Array.length;
							}
						break;
					case 'pswd' :
						if((Element[i].value != Element[i+1].value && Element[i+1].type == 'password') )					
//						if( Element[i].value == '' || (Element[i].value != Element[i+1].value && Element[i+1].type == 'password') )
							{
							Element[i+1].value = '';
							Element[i].select();
							Element[i].focus();
							Msg = 'Senha e Confirmação de Senha não conferem.';
							i	= Len;
							ix	= Array.length;
							}
						break;
					case 'null' :
						if( Element[i].value == '' )
							{
							Element[i].select();
							Element[i].focus();
							Msg = 'Preencha o campo '+ Element[i].param;
							i	= Len;
							ix	= Array.length;
							}
						break;
					case 'sel' :
						if( Element[i].value == '' || Element[i].value == 'XX' )
							{
							Element[i].focus();
							Msg = 'Selecione uma opção.';
							i	= Len;
							ix	= Array.length;
							}
						break;

					default :
							i	= Len;
					}

	if( Msg != '' )
		{
		alert(Msg);
		return false;
		}
	return true;
	}

// A cada tecla solta verifica o campo ativo
function SeeKeys()
	{
	var Obj, KeyCode, Point, Indx, Str
	KeyCode = window.event.keyCode;
	Obj = event.srcElement;

	if( KeyCode == 13 )
		{
		blnGerarTab = true;
		window.event.returnValue = false;
		return false
		}
	else if( KeyCode > 47 )
		switch( Obj.id )
			{
			case 'text' :
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsLetter(Obj.value);
					if( Point != -1 )
						Obj.value = CutCharPoint( Obj.value , Point );
					}
				break;

			case 'num'	:
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsNumber(Obj.value);
					if( Point != -1 )
						Obj.value = CutCharPoint( Obj.value , Point );
					}
				break;

			case 'dinh'	:
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsGrana(Obj.value);
					if( Point != -1 )
						Obj.value = CutCharPoint( Obj.value , Point );
					}
  			    break;

			case 'user'	:
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsUser(Obj.value);
					if( Point != -1 )
						Obj.value = CutCharPoint( Obj.value , Point );
					}
				break;
			case 'data'	:
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsData(Obj.value);
					
					if( Point != -1 ){
						Obj.value = CutCharPoint( Obj.value , Point );}
					else
					{
					   if (Str.length == 2) 
					   { 
     						 Str = Str + '/'; 
						     Obj.value = Str; 
   						} 
						if (Str.length == 5) 
						{ 
						      Str = Str + '/'; 
						      Obj.value = Str; 
	 				    } 
					}
				}	
				break;

			case 'alfa'	:
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsAlfaNum(Obj.value);
					if( Point != -1 )
						Obj.value = CutCharPoint( Obj.value , Point );
					}
				break;
            
         case 'cpf' :
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsNumber(Obj.value);
					if( Point != -1 )
						Obj.value = CutCharPoint( Obj.value , Point );
					}

			case 'mail' :
				Str		= Obj.value;
				for(Indx=0; Indx < Str.length ;Indx++)
					{
					Point	= IsEmail(Obj.value);
					if( Point != -1 )
						Obj.value = CutCharPoint( Obj.value , Point );
					}
				break;
			}
	}

// Verifica formatação a@b.c
// Não permite caracteres especiais
// Retorna true se o Obj for um E-Mail
// Retorna false se o Obj nao for um E-Mail
function IsValidEmail( Value )
	{
	var i, Current, Tmp
	var Array = Value.split( '@' , 3 );
   
	
	// Se tiver mais ou menos que 1 Arroba ou nao tiver nada antes ou apos o Arroba
	if( Array.length != 2 || Array[0] == '' || Array[1] == '' )
		return false;

	Tmp = Array[0];
	// Se contiver caracteres especiais antes do Arroba
	for(i=0; i < Tmp.length ;i++)
		{
		Current =  Tmp.charAt(i);
		if( (Current == ' ') && (Current < '0' || Current > '9') && (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && Current != '_' && Current != '-' && Current != '.' )
			return false;
		}

	Tmp = Array[1];
	// Se contiver caracteres especiais depois do Arroba
	for(i=0; i < Tmp.length ;i++)
		{
		Current =  Tmp.charAt(i);
		if( (Current < '0' || Current > '9') && (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && Current != '.' )
			return false;
		}
	
	Tmp = Tmp.split( '.' , 4 );
	// Se depois do arroba existir menos de 2 ou mais de 3 pontos
	if( Tmp.length != 2 && Tmp.length != 3 )
		return false;

	// Se depois do arroba existir menos de 2 ou mais de 3 pontos
	if( Tmp.length == 2 && (Tmp[0] == '' || Tmp[1] == '') )
		return false;

	// Se depois do arroba existir menos de 2 ou mais de 3 pontos
	if( Tmp.length == 3 && (Tmp[0] == '' || Tmp[1] == '' || Tmp[2] == '') )
		return false;

	return true
	}

// Procura por "Chars" em "Str"
// Retorna -1 se nao encontar os "Chars"
// Retorna a posicao do Chars em Str se o encontar
function LookChars( Str, Chars )
	{
	var Count, Indx
	for(Count=0; Count < Str.length ;Count++)
		for(Indx=0; Indx < Chars.length ;Indx++)
			if( Str.charAt(Count) == Chars.charAt(Indx) )
				return Count;

	return -1
	}

// Remove de Str o caracter localizado na posicao Pnt
// Retorna o Str sem o caracter apontado por Pnt
function CutCharPoint( Str, Pnt )
	{
	var Count, Result
	Result = '';
	for(Count=0; Count < Str.length ;Count++)
		if( Count != Pnt )
			Result = Result + Str.charAt(Count);

	return Result
	}

// Verifica se Str contem caracteres invalidos em E-Mails
// Retorna -1 se nao contiver
// Retorna Posicao do Caracter Invalido em Str
function IsEmail( Str )
	{
	var Count, Current
	for(Count=0; Count < Str.length ;Count++)
		{
		Current =  Str.charAt(Count);
		if( (Current < '0' || Current > '9') && (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && Current != '_' && Current != '-' && Current != '.' && Current != '@' )
			return Count
		}

	return -1
	}

// Verifica se Str contem caracteres invalidos para User name
// Retorna -1 se nao contiver
// Retorna Posicao do Caracter Invalido em Str
function IsUser( Str )
	{
	var Count, Current
	for(Count=0; Count < Str.length ;Count++)
		{
		Current =  Str.charAt(Count);
		if((Current < '0' || Current > '9') && (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && Current != '_' && Current != '-' && Current != '.' && Current != '@' )
			return Count
		}

	return -1
	}

	
	
// Verifica se Str contem apenas Letras entre A e Z
// Retorna -1 se Str contiver apenas Letras entre A-Z
// Retorna Posicao do Caracter que for uma Letra entre A-Z
function IsLetter( Str )
	{
	var Count, Current
	for(Count=0; Count < Str.length ;Count++)
		{
		Current =  Str.charAt(Count);
		if( (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && IsNotAcent(Current) )
			return Count
		}

	return -1
	}

// Verifica se o Chr é acentuado
// Retorna true se o Chr nao for acentuado
// Retorna false se o Chr for acentuado
function IsNotAcent( Chr )
	{
	if( Chr=='á' || Chr=='é' || Chr=='í' || Chr=='ó' || Chr=='ú' || Chr=='Á' || Chr=='É' || Chr=='Í' || Chr=='Ó' || Chr=='Ú' )
		return false;
	if( Chr=='à' || Chr=='è' || Chr=='ì' || Chr=='ò' || Chr=='ù' || Chr=='À' || Chr=='È' || Chr=='Ì' || Chr=='Ò' || Chr=='Ù' )
		return false;
	if( Chr=='â' || Chr=='ê' || Chr=='î' || Chr=='ô' || Chr=='û' || Chr=='Â' || Chr=='Ê' || Chr=='Î' || Chr=='Ô' || Chr=='Û' )
		return false;
	if( Chr=='ä' || Chr=='ë' || Chr=='ï' || Chr=='ö' || Chr=='ü' || Chr=='Ä' || Chr=='Ë' || Chr=='Ï' || Chr=='Ö' || Chr=='Ü' )
		return false;
	if( Chr=='ã' || Chr=='õ' || Chr=='Ã' || Chr=='Õ' || Chr=='ñ' || Chr=='Ñ' || Chr=='ç' || Chr=='Ç' || Chr==' ')
		return false;

	return true;	
	}

// Verifica se Num contem apenas Numeros entre 0 e 9
// Retorna -1 se o Num contiver apenas Numeros entre 0 e 9
// Retorna Posicao do Caracter nao Numerico se o encontrar
function IsNumber( Num )
	{
	var Count, Current
	for(Count=0; Count < Num.length ;Count++)
		{
		Current = Num.charAt(Count);
		if(( Current < '0' || Current > '9' ))
			return Count
		}

	return -1
	}



// Verifica se Num contem apenas Numeros entre 0 e 9 e ','
// Retorna -1 se o Num contiver apenas Numeros entre 0 e 9  e ','
// Retorna Posicao do Caracter nao Numerico se o encontrar
function IsGrana( din )
	{
	var Count, Current, virg
	virg = 0
	for(Count=0; Count < din.length ;Count++)
		{
		Current = din.charAt(Count);

		if(( Current < '0' || Current > '9') && Current != ',' ){
			return Count
			}
		else{
			if(Current ==  ','){virg = virg+1;}
			if(virg > 1){return -1;}
	        }
		}
	return -1
	}
	
	
//  Verifica data aceitando barra
	function IsData( Num )
	{
	var Count, Current
	for(Count=0; Count < Num.length ;Count++)
		{
		Current = Num.charAt(Count);
		if((Current < '0' || Current > '9') && Current != '/')
			return Count

		}

	return -1
	}

	
// Verifica se Str contem contem caracteres AlfaNumericos
// Retorna -1 se Str contiver apenas caracteres AlfaNumericos
// Retorna Posicao do Caracter nao AlfaNumerico
function IsAlfaNum( Str )
	{
	var Count, Current
	for(Count=0; Count < Str.length ;Count++)
		{
		Current =  Str.charAt(Count);
		if( (Current < '0' || Current > '9') && (Current < 'A' || Current > 'Z') && (Current < 'a' || Current > 'z') && IsNotAcent(Current) && Current != '_' && Current != '-' && Current != '.' )
			return Count
		}

	return -1
	}
	
	
function Verificadata(data){
var Date = new String(data);
    Dia = "";
    Mes = "";
    Ano = "";
    i = 0;

    for (i=0;(i<Date.length) && (Date.charAt(i) != '/');i++)
           Dia = Dia + Date.charAt(i);
    i++;

   for (;(i<Date.length) && (Date.charAt(i) != '/');i++)
        Mes = Mes + Date.charAt(i);
   i++;

   for (;(i<Date.length);i++)
      Ano = Ano + Date.charAt(i);
	  
	  
   if (eval(Mes) > 12){
		 return 0}
		 
   if (eval(Dia) > 31){
        return 0}
		
    if(eval(Ano) < 1850) {
        return 0;}
		
	if((eval(Mes)==2) && (eval(Dia)>29)){
	    return 0}	
		
return -1
}

function checaCPF (CPF) {
   if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
	  CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
     CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
     CPF == "88888888888" || CPF == "99999999999")
     return false;
   soma = 0;
   for (i=0; i < 9; i ++)
     soma += parseInt(CPF.charAt(i)) * (10 - i);

   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11)
      resto = 0;
  
  if (resto != parseInt(CPF.charAt(9)))
     return false;

  soma = 0;
  
  for (i = 0; i < 10; i ++)
     soma += parseInt(CPF.charAt(i)) * (11 - i);
  resto = 11 - (soma % 11);

  if (resto == 10 || resto == 11)
     resto = 0;
  
  if (resto != parseInt(CPF.charAt(10)))
    return false;
  
  return true;
} 

//POr JHC
//function mascara_data_local(data,campo) { 
function mascara_data_local(data) { 
   var mydata = '';
   mydata = mydata + data; 
   if (mydata.length == 2) { 
      mydata = mydata + '/'; 
//      document.forms[0].elements[campo].value = mydata; 
      document.Frm_Cad.nascimento.value = mydata; 
   } 
   if (mydata.length == 5) { 
      mydata = mydata + '/'; 
      document.Frm_Cad.nascimento.value = mydata; 
   } 
} 
   function Fis_Jur() {
      if (document.Frm_Cad.fis_jur.value=="F") {
         document.getElementById("TRFis").style.display = "";
         document.getElementById("TRJur").style.display = "none";
      }
      else {
         document.getElementById("TRJur").style.display = "";
         document.getElementById("TRFis").style.display = "none";
      }
   }

   function ChecaForm() {
      if ( (document.Frm_Cad.fname.value=="") || (document.Frm_Cad.email.value=="") || (document.Frm_Cad.senha.value=="") || (document.Frm_Cad.lname.value=="") || (document.Frm_Cad.username.value=="")) {
         alert("Por favor, preencha os campos marcados com (*).");
         return false;
      }
      else {
        // Validando Email
         if (IsValidEmail(document.Frm_Cad.email.value)==false) {
            alert('O email digitado é inválido.');
            document.Frm_Cad.email.focus();
            return false;
         }
       
        document.getElementById("TRSubmit").style.display = "none";
        document.getElementById("TRWait").style.display = "";
        
      }
   }
   
   function validaCPF() {
      cpf = document.Frm_Cad.cpf.value;
      erro = new String;
      if (cpf.length < 11) { 
         erro = "O CPF deve conter 11 dígitos. "; 
      }
      var nonNumbers = /\D/;
      if (nonNumbers.test(cpf)) {
         erro += "O CPF deve conter apenas números. ";
      }
      if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
         erro += "Numero de CPF inválido. "
      }
      var a = [];
      var b = new Number;
      var c = 11;
      for (i=0; i<11; i++){
         a[i] = cpf.charAt(i);
         if (i < 9) b += (a[i] * --c);
      }
      if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
      b = 0;
      c = 11;
      for (y=0; y<10; y++) b += (a[y] * c--); 
      if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
      if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
         erro += "Dígito verificador do CPF inválido. ";
      }
      if (erro.length > 0) {
         return false;
      } else {
         return true;
      }
   }
       
   function validaCNPJ() {
      CNPJ = document.Frm_Cad.cnpj.value;
      erro = new String;
      if (CNPJ.length < 14) erro += "O CNPJ deve conter 14 dígitos. "; 
      var nonNumbers = /\D/;
      if (nonNumbers.test(CNPJ)) erro += "O CNPJ deve conter apenas números. "; 
      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 +="Dígito verificador do CNPJ inválido. ";
      }
      if (erro.length > 0) {
         return false;
      } else {
         return true;
      }
   }
   
//Por Jhc