function EnviarSenha()
{
	ok = 1;
  	if ( ( document.EnviaSenha.EnvEmail.value == "" ) && ( document.EnviaSenha.EnvLogin.value == "" ) )
	{
    	ok = 0;
    	alert( "É preciso preencher um e-mail ou um Login..." );
    	document.EnviaSenha.EnvLogin.focus();
    	return -1;
  	}
	
  	if ( ok == 1 )
  	{
    	document.EnviaSenha.action = "perdeu_senha.php";
    	document.EnviaSenha.submit();
  	}
}

function Alterar( fig, leg, ID, Name )
{
	Elem = document.getElementById( ID );
    Elem.innerHTML = leg;
    Elem = document.getElementById( Name );
    Elem.src = fig;
}

function enviaMenu( x )
{
	document.Menu.action = "index.php";
  	switch ( x )
	{
    	case 1:
        	document.Menu.opcaoMenu.value = "1";
        	break;
    	case 2:
        	document.Menu.opcaoMenu.value = "2";
        	break;
    	case 3:
        	document.Menu.opcaoMenu.value = "3";
        	break;
    	case 4:
        	document.Menu.opcaoMenu.value = "4";
        	break;
    	case 5:
        	document.Menu.opcaoMenu.value = "5";
        	break;
    	case 6:
        	document.Menu.opcaoMenu.value = "6";
        	break;
    	case 7:
        	document.Menu.opcaoMenu.value = "7";
        	break;
    	default:
        	document.Menu.opcaoMenu.value = "0";
  	}
  	document.Menu.submit();
}

function ValidaMsg()
{
	ok = 1;
  	if ( document.quadroMensagens.mensagem.value == "" || document.quadroMensagens.mensagem.value == "Digite aqui a sua mensagem" )
	{
    	ok = 0;
    	alert( "É preciso preencher o campo acima..." );
    	document.quadroMensagens.mensagem.focus();
    	return -1;
  	}
	
  	if ( ok == 1 )
  	{
    	document.quadroMensagens.submit();
  	}
}

function DeleteDefaultMessage()
{
	if ( document.quadroMensagens.mensagem.value == "Digite aqui a sua mensagem" )
	{
		document.quadroMensagens.mensagem.value = '';
	}
}

function VerificaAltCadastro()
{
	ok = 1;
  	if ( document.alteraCadastro.altCadNome.value == "" )
  	{
    	ok = 0;
    	alert( "O campo Nome precisa ser preenchido.");
	    document.alteraCadastro.altCadNome.focus();
    	return -1;
  	}
  
  	if ( document.alteraCadastro.altCadEmail.value == "" )
  	{
    	ok = 0;
    	alert( "O campo Email precisa ser preenchido.");
	    document.alteraCadastro.altCadEmail.focus();
    	return -1;
  	}
  
  	if ( document.alteraCadastro.altCadNasc != undefined )
  	{
  		if ( document.alteraCadastro.altCadNasc.value == "" )
  		{
    		ok = 0;
    		alert( "O campo Data de Nascimento precisa ser preenchido.");
	    	document.alteraCadastro.altCadNasc.focus();
    		return -1;
  		}
  		else
  		{
			if ( document.alteraCadastro.altCadNasc.value.length < 10 )
	  		{
				ok = 0;
		  		alert( "A Data de Nascimento está incompleta" );
			  	document.alteraCadastro.altCadNasc.focus();
			  	return -1;
	  		}
 		}
  	}
  
  	if ( document.alteraCadastro.ChangePassword.checked )
	{
		if ( document.alteraCadastro.altCadSenha != undefined && document.alteraCadastro.altCadSenha2 != undefined )
		{
			if ( document.alteraCadastro.altCadSenha.value == "" )
			{
				ok = 0;
				alert ( "O campo Senha precisa ser preenchido." );
				document.alteraCadastro.altCadSenha.focus();
				return -1;
			}
			
			if ( document.alteraCadastro.altCadSenha2.value == "" )
			{
				ok = 0;
				alert ( "O campo de Confirmação de Senha precisa ser preenchido." );
				document.alteraCadastro.altCadSenha2.focus();
				return -1;
			}
		
			if ( document.alteraCadastro.altCadSenha.value != document.alteraCadastro.altCadSenha2.value )
			{
				ok = 0;
				alert ( "A senha e a confirmação estão diferentes..." );
				document.alteraCadastro.altCadSenha.focus();
				return -1;
			}
		}
	}
	
	if ( document.alteraCadastro.ChangePhoto.checked )
	{
		if ( document.alteraCadastro.alt_foto != undefined )
		{
			if ( document.alteraCadastro.alt_foto.value != "" )
			{
				PhotoPath = document.alteraCadastro.alt_foto.value;
				Ext = PhotoPath.substring( PhotoPath.length - 3, PhotoPath.length );
				ExtFile = Ext.toUpperCase();
				if ( ExtFile != "PNG" && ExtFile != "JPG" )
				{
					ok = 0;
					alert( "A Foto deve ter uma extensão jpg ou png." );
					document.alteraCadastro.alt_foto.focus()
					return -1;
				}
			}
			else
			{
				ok = 0;
				alert( "O campo Foto deve ser preenchido." );
				document.alteraCadastro.alt_foto.focus()
				return -1;
			}
		}
	}
	
  	if ( ok == 1 )
  	{
    	document.alteraCadastro.action="alterar_cadastro.php";
    	document.alteraCadastro.submit();
  	}
}

function validaEntrada(){
  if (document.login.Login.value == "" || document.login.Login.value == "Seu Apelido")
  {
    alert ("Campo Login precisa ser preenchido corretamente.");
    document.login.Login.focus();
    return -1;
  }
  if ( document.login.Senha.value == "" )
  {
    alert ( "O campo Senha precisa ser preenchido corretamente" );
    document.login.Senha.focus();
    return -1;
  }
  document.login.submit();
}


function Contador(field,MaxLength) {
  obj = document.all(field);
  if (MaxLength > 300) {
    MaxLength=300;
  }
  if (MaxLength !=0) {
    if (obj.value.length > MaxLength) {
      obj.value = obj.value.substring(0, MaxLength);
    }
  }
  document.escreva.contador.value = obj.value.length + '/'+MaxLength;
}

function VerificaCadastro()
{
  ok = true;
  if ( document.cadastro.cadNome.value == "" )
  {
	ok = false;
    alert ("O campo Nome precisa ser preenchido.");
    document.cadastro.cadNome.focus();
    return -1;
  }
  if ( document.cadastro.cadEmail.value == "" )
  {
	ok = false;
    alert ( "Precisa ter um E-mail para acessar o site." );
    document.cadastro.cadEmail.focus();
	return -1;
  }
    
  if ( document.cadastro.cadLogin.value == "" )
  {
	ok = false;
    alert( "Você precisa de um Apelido(Login) para acessar o site." );
    document.cadastro.cadLogin.focus();
    return -1;
  }
  
  if ( document.cadastro.cadSenha.value == "" )
  {
	  ok = false;
	  alert( "O campo Senha precisa ser preenchido." );
	  document.cadastro.cadSenha.focus();
	  return -1;
  }
  else
  {
	  if ( document.cadastro.cadSenha.value.length < 6 )
	  {
		  ok = false;
		  alert( "A Senha deve ter pelo menos 6 digitos." );
		  document.cadastro.cadSenha.focus();
		  return -1;
	  }
  }
  
  if ( document.cadastro.cadSenhaConf.value == "" )
  {
	  ok = false;
	  alert( "O campo Senha (confirmação) precisa ser preenchido." );
	  document.cadastro.cadSenhaConf.focus();
	  return -1;
  }
  
  if ( document.cadastro.cadSenha.value != document.cadastro.cadSenhaConf.value )
  {
	  ok = false;
	  alert( "A Senha e a Confirmação de Senha estão diferentes." );
	  document.cadastro.cadSenhaConf.focus();
	  return -1;
  }
  
  if ( document.cadastro.cadNascimento.value == "" )
  {
	ok = false;
    alert( "O campo Data da Nascimento precisa ser preenchido.");
    document.cadastro.cadNascimento.focus();
    return -1;
  }
  else
  {
	if ( document.cadastro.cadNascimento.value.length < 10 )
	{
		ok = false;
		alert( "A Data de Nascimento está incompleta." );
		document.cadastro.cadNascimento.focus();
		return -1;
	}
  }
  
  if ( document.cadastro.cadFoto.value != "" )
  {
	  PathPhoto = document.cadastro.cadFoto.value;
	  Ext = PathPhoto.substring( PathPhoto.length - 3, PathPhoto.length );
	  ExtFile = Ext.toUpperCase();
	  if ( ExtFile != "PNG" && ExtFile != "JPG" )
	  {
		  ok = false;
	  	  alert( "A Foto deve ter uma extensão jpg ou png" );
		  document.cadastro.cadFoto.focus()
		  return -1;
	  }
  }
  
  if ( ok == true )
  {
    document.cadastro.action="cadastro.php";
    document.cadastro.submit();
  }
}

function VerificaFormClass()
{
	if ( document.cad_class.txt_titulo != undefined )
	{
		if ( document.cad_class.txt_titulo.value == "" )
		{
			alert( "O campo Título deve ser preenchido." );
			document.cad_class.txt_titulo.focus();
			return false;
		}
	}
	
	if ( document.cad_class.txt_descricao.value == "" )
	{
		alert( "O campo Descrição deve ser preenchido." );
		document.cad_class.txt_descricao.focus();
		return false;
	}
	
	if ( document.cad_class.txt_valor.value == "" )
	{
		alert( "O campo Valor deve ser preenchido." );
		document.cad_class.txt_valor.focus();
		return false;
	}
	
	if ( document.cad_class.txt_contato.value == "" )
	{
		alert( "O campo Contato deve ser preenchido." );
		document.cad_class.txt_contato.focus();
		return false;
	}
	
	if ( document.cad_class.txt_arquivo != undefined )
	{
		if ( document.cad_class.txt_arquivo.value == "" )
		{
			alert( "O campo Foto deve ser preenchido." );
			document.cad_class.txt_arquivo.focus();
			return false;
		}
		else
		{
			Ext = document.cad_class.txt_arquivo.value.substring( document.cad_class.txt_arquivo.value.length - 3, document.cad_class.txt_arquivo.value.length );
			ExtFile = Ext.toUpperCase();
			if ( ExtFile != "PNG" && ExtFile != "JPG" && ExtFile != "GIF" )
			{
				alert( "A Foto deve ter uma extensão png, jpg ou gif." );
				document.cad_class.txt_arquivo.focus();
				return false;
			}
		}
	}
	
	if ( document.cad_class.chk_concordo.checked == false )
	{
		alert( "Você deve concordar com os termos e condições de uso para continuar" );
		return false;
	}
	
	document.cad_class.action="meu_classificado.php";
	document.cad_class.submit();
}

function VerificaEscreva()
{
	fo = document.escreva;
	MsgError = "";
	Count = 0;
	if ( fo.textoNome.value == "" )
  	{
		MsgError += "O campo Nome precisa ser preenchido.\n";
		Count++;
	}
	
	if ( fo.textoEmail.value == "" )
	{
		MsgError += "O campo Email precisa ser preenchido.\n";
		Count++;
	}
	else if ( fo.textoEmail.value.indexOf("@") == -1 || fo.textoEmail.value.indexOf(".") == -1 || fo.textoEmail.value.length <= 6 )
	{
		MsgError += "O E-mail não é válido.\n";
		Count++;
	}
	
	if ( fo.textoTitulo.value == "" )
	{
		MsgError += "O campo Assunto precisa ser preenchido.\n";
		Count++;
	}
	
  	if ( fo.textoEscreva.value == "" )
  	{
    	MsgError += "O campo Mensagem precisa ser preenchido.\n";
		Count++;
	}
	
	if ( MsgError == "" )
	{
		fo.action="fale_conosco.php";
		fo.submit();
		return true;
	}
	else
	{
		if ( Count == 4 )
		{
			alert( "Os campos precisam ser preenchidos." );
		}
		else
		{
			alert( MsgError );
		}
		return false;
	}
}


function BuscaSenha()
{
  ok=1;
  if (( document.senha.pwNome.value == "" )&&( document.senha.pwEmail.value == "" )&&( document.senha.pwLogin.value == "" ))
  {
    ok=0;
    alert("Você precisa preencher pelo menos algum dos campos.");
    return false;
  }
  if ( ok == 1 )
  {
    alert ("Falta enviar por e-mail!");
    document.senha.action="senha.php";
    document.senha.submit();
  }
}

function avisa()
{
  alert("Você precisa se logar primeiro");
}

function novaJanela(pagina,nomepagina, parametros)
{
  win=window.open(pagina,nomepagina, parametros);
}

function correctPNG()
{
   for(var i=0; i<document.images.length; i++)
   {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	  {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
		 img.outerHTML = strNewHTML
		 i = i-1
	  }
   }
}
   
if(document.all)
{
	window.attachEvent("onload", correctPNG)
}

function ValidAdmin()
{
	fo = document.form;
	error = "";
	if ( fo.user.value == "" )
	{
		error += "O campo Usuário deve ser preenchido.\n";
	}
	
	if ( fo.pass.value == "" )
	{
		error += "O campo Senha deve ser preenchido.\n";
	}
	
	if ( error != "" )
	{
		alert( error );
		return false;
	}
	fo.submit();
}

function CheckDelClassif()
{
    fo = document.exc_class;
  	ItemSelected = false;
	
	if ( fo.CID != undefined )
	{
		if ( fo.CID.length != undefined )
		{
			for ( i = 0; i < fo.CID.length; i++ )
  			{
  				if ( fo.CID[i].checked )
				{
    				ItemSelected = true;
					break;
				}
    		}
		}
		else
		{
			ItemSelected = fo.CID.checked;
		}
	}
	
  	if ( ItemSelected == true )
	{
		fo.action = "meu_classificado.php";
    	fo.submit();
	}
  	else
	{
    	alert( "Nenhum item do classificado selecionado para exclusão" );
  	}
}

function DateValidate( objeto, e )
{
	if ( navigator.userAgent.indexOf( "IE" ) != -1 )
	{
		if ( window.event.keyCode > 47 && window.event.keyCode < 58 && objeto.value.length < 13 )
		{
			if ( objeto.value.length == 2 )
			{
			   objeto.value = objeto.value + "/";
			}
			else if ( objeto.value.length == 5 )
			{
			   objeto.value = objeto.value + "/";
			}
		}
		else
		{
			event.returnValue = false;
		}
	}
}

function HoraValidate( objeto, e )
{
	if ( navigator.userAgent.indexOf( "IE" ) != -1 )
	{
		if ( window.event.keyCode > 47 && window.event.keyCode < 58 && objeto.value.length < 13 )
		{
			if ( objeto.value.length == 2 )
			{
			   objeto.value = objeto.value + ":";
			}
		}
		else
		{
			event.returnValue = false;
		}
	}
}

function MaxCharCount()
{
	var Max = 300;
	if ( document.quadroMensagens.mensagem.value.length > Max )
	{
		document.quadroMensagens.total_char.value = "0";
		document.quadroMensagens.mensagem.value = document.quadroMensagens.mensagem.value.substring( 0, Max );
	}
	else
	{
		document.quadroMensagens.total_char.value = Max - document.quadroMensagens.mensagem.value.length;
	}
}

function MaxFaleConoscoCount()
{
	var MaxFaleConosco = 300;
	if ( document.escreva.textoEscreva.value.length > MaxFaleConosco )
	{
		document.escreva.total_allowed.value = "0";
		document.escreva.textoEscreva.value = document.escreva.textoEscreva.value.substring( 0, MaxFaleConosco );
	}
	else
	{
		document.escreva.total_allowed.value = MaxFaleConosco - document.escreva.textoEscreva.value.length;
	}
}

function QuestionMaxCharCount()
{
	var MaxQuestion = 200;
	if ( document.class_question.text_question.value.length > MaxQuestion )
	{
		document.class_question.total_char.value = "0";
		document.class_question.text_question.value = document.class_question.text_question.value.substring( 0, MaxQuestion );
	}
	else
	{
		document.class_question.total_char.value = MaxQuestion - document.class_question.text_question.value.length;
	}
}

function AnswerMaxCharCount()
{
	var MaxAnswer = 200;
	if ( document.class_answer.text_answer.value.length > MaxAnswer )
	{
		document.class_answer.total_char.value = "0";
		document.class_answer.text_answer.value = document.class_answer.text_answer.value.substring( 0, MaxAnswer );
	}
	else
	{
		document.class_answer.total_char.value = MaxAnswer - document.class_answer.text_answer.value.length;
	}
}

function VerificaCadPedalLegal()
{
	var Ok = 1;
	if ( document.cad_pedal_legal.txt_destino.value == "" )
	{
		alert( 'O campo Destino deve ser preenchido.' );
		document.cad_pedal_legal.txt_destino.focus();
		Ok = 0;
		return false;
	}
	
	if ( document.cad_pedal_legal.txt_descricao.value == "" )
	{
		alert( 'O campo Descrição deve ser preenchido.' );
		document.cad_pedal_legal.txt_descricao.focus();
		Ok = 0;
		return false;
	}
	
	if ( document.cad_pedal_legal.txt_local.value == "" )
	{
		alert( 'O campo Local deve ser preenchido.' );
		document.cad_pedal_legal.txt_local.focus();
		Ok = 0;
		return false;
	}
	
	if ( document.cad_pedal_legal.txt_data.value == "" )
	{
		alert( 'O campo Data deve ser preenchido.' );
		document.cad_pedal_legal.txt_data.focus();
		Ok = 0;
		return false;
	}
	
	if ( document.cad_pedal_legal.txt_hora.value == "" )
	{
		alert( 'O campo Hora deve ser preenchido.' );
		document.cad_pedal_legal.txt_hora.focus();
		Ok = 0;
		return false;
	}
	
	if ( Ok == 1 )
	{
		document.cad_pedal_legal.action="meu_pedal_legal.php";
    	document.cad_pedal_legal.submit();
	}
}

function CheckDelPedalLegal()
{
    fo = document.exc_pedal;
  	ItemSelected = false;
	
	if ( fo.PID != undefined )
	{
		if ( fo.PID.length != undefined )
		{
			for ( i = 0; i < fo.PID.length; i++ )
  			{
  				if ( fo.PID[i].checked )
				{
    				ItemSelected = true;
					break;
				}
    		}
		}
		else
		{
			ItemSelected = fo.PID.checked;
		}
	}
	
  	if ( ItemSelected == true )
	{
		fo.action = "meu_pedal_legal.php";
    	fo.submit();
	}
  	else
	{
    	alert( "Nenhum item do pedal legal selecionado para exclusão" );
  	}
}

function SendClassifiedQuestion()
{
	if ( document.class_question.text_question.value == "" )
	{
		alert( 'O campo de Pergunta deve ser preenchido.' );
		document.class_question.text_question.focus();
		return false;
	}
    document.class_question.submit();
}

function SendClassifiedAnswer()
{
	if ( document.class_answer.text_answer.value == "" )
	{
		alert( 'O campo Resposta deve ser preenchido.' );
		document.class_answer.text_answer.focus();
		return false;
	}
    document.class_answer.submit();
}