function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function abrir_janela_popup(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function abreFotos(evento,pasta)
{
window.open('frame.php?grupo=fotos/'+pasta+'/','pasta','resizable=yes,scrollbars=yes,width=780,height=500,top=0,left=0');

}

function abreFotos2(evento,pasta)
{
window.open('galeria.php?grupo=fotos/'+pasta+'/','pasta','resizable=yes,scrollbars=yes,width=780,height=500,top=0,left=0');

}

function ampliada(foto,legenda,tipo){
	myWindow=window.open('fotoshow.php?cod=HJNSOI2398FDKJH3487FDJH430945JLK98&imagem='+foto+'&tp='+tipo+'&id=sdflkj23897fsdkjh23487kjh45987dfgjkh','foto','scrollbar=no, resize=no,width=200,height=130,left=100,top=100');
	myWindow.focus()
}



function validarLogin()
{
	msgErros = '';
	cntErros = 0;
	with (document.formLogin)
	{
		if (login.value.length < 5)
		{
			msgErros += "-> Login\n";
			cntErros++;
		} 
		
		if (senha.value.length < 5)
		{
			msgErros += "-> Senha\n";
			cntErros++;
		} 

		
	
		if (cntErros > 0)
		{
			alert(msgErros);
			return false;
		}
		else
		{
		
				action = "classicficados_autenticar.php";
				return true;
				submit();
		}
	}

}


function validarAnuncio()
{
	msgErros = '';
	cntErros = 0;
	with (document.formAnuncio)
	{
		if (nome.value.length < 3)
		{
			msgErros += "-> Nome\n";
			cntErros++;
		}
		
		if ((telefone.value.length < 8) && (celular.value.length < 8))
		{
			msgErros += "-> Informe o telefone ou o celular\n";
			cntErros++;
		}
		
		
		if (email.value.length < 6)
		{
			msgErros += "-> E-mail\n";
			cntErros++;
		}
		else
		{
			if (email.value.indexOf('@',0)==-1 ||
				email.value.indexOf('@',0)== 0 ||
				email.value.indexOf('.',0)==-1)
      	{
            msgErros += "-> E-mail (inválido)\n";
				cntErros++;
      	}
		}
		
		
		if (marca.value.length < 2)
		{
			msgErros += "-> Marca\n";
			cntErros++;
		}
		
		if (modelo.value.length < 2)
		{
			msgErros += "-> Modelo\n";
			cntErros++;
		}
		
		if (ano.value.length < 4)
		{
			msgErros += "-> Ano do carro\n";
			cntErros++;
		}
		
		if (fab.value.length < 4)
		{
			msgErros += "-> Ano de fabricação\n";
			cntErros++;
		}
		
		if (placa.value.length < 6)
		{
			msgErros += "-> Placa\n";
			cntErros++;
		}
		
		if (km.value.length < 2)
		{
			msgErros += "-> Kilometragem\n";
			cntErros++;
		}
		
		if (valor.value.length < 5)
		{
			msgErros += "-> Valor\n";
			cntErros++;
		}
		
		
		
		if (descricao.value.length < 5)
		{
			msgErros += "-> Descrição\n";
			cntErros++;
		}
	
		if (cntErros > 0)
		{
			alert("Você precisa preencher corretamente o(s) campo(s)\n abaixo para poder enviar o anúncio\n" + msgErros);
			return false;
		}
		else
		{
			action = "classicficados_cadastra.php";
			return true;
			submit();

		}
	}

}


function comprova_extensao(arquivo) { 
   extensoes_permitidas = new Array(".jpg",".JPG"); 
   meuerro = ""; 
   if (!arquivo) { 
      //Se não tenho arquivo, é porque não se selecionou um arquivo no formulário. 
       return 'vazio';
   }else{ 
      //recupero a extensão deste nome de arquivo 
      extensao = (arquivo.substring(arquivo.lastIndexOf("."))).toLowerCase(); 
      //alert (extensao); 
      //comprovo se a extensão está entre as permitidas 
      permitida = false; 
      for (var i = 0; i < extensoes_permitidas.length; i++) { 
         if (extensoes_permitidas[i] == extensao) { 
         permitida = true; 
         break; 
         } 
      } 
      if (!permitida) { 
         meuerro = "Somente são permitidos arquivos com extensões: " + extensoes_permitidas.join(); 
		return 'erro';
       }
   } 
   //se estou aqui é porque não se pode submeter 
   return 'ok'; 
}

function enviarfoto() {

	retorno = '';

	msgErros = '';
	cntErros = 0;
	with (document.form1)
	{
		

		
		if (arquivo.value.length < 3)
		{
			msgErros += "-> Selecione o arquivo\n";
			cntErros++;
		}
		else
		{
			retorno = comprova_extensao(arquivo.value);
			
			if (retorno == 'erro') {
				msgErros += "-> Somente arquivo JPG é aceito\n";
				cntErros++;
			}
			if (retorno == 'vazio') {
				msgErros += "-> Selecione o arquivo\n";
				cntErros++;
			}
			
			
			
		}
		
		
		if (cntErros > 0)
		{
			alert(msgErros);
		}
		else
		{
			action = "classicficados_enviafoto.php";
			submit();
		}
	}


}
