/**
 * ExpressÃµes regulares usadas em todo o site.
 */
var regexEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;

/**
 *
 */
String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function validaRegistro()
{
	var campoEmail 			= document.getElementById( "campoRegEmail" );
	var campoSenha 			= document.getElementById( "campoRegSenha" );
	var campoSenhaConf 		= document.getElementById( "campoRegSenhaConf" );
	var registroMensagem 	= document.getElementById( "registroMensagem" );

	if (
		campoEmail == null ||
		campoSenha == null ||
		campoSenhaConf == null ||
		registroMensagem == null ) return false;
	else
	{
		var email 		= campoEmail.value.trim();
		var senha 		= campoSenha.value.trim();
		var senhaconf 	= campoSenhaConf.value.trim();
		var mensagem 	= "";

		/**
		 * Validando e-mail.
		 */
		if ( email.length == 0 )
			mensagem += "E-mail deve ser preenchido.<br/>";
		else if ( !regexEmail.test( email ) )
			mensagem += "E-mail nÃ£o Ã© vÃ¡lido.<br/>";

		if ( senha.length == 0 )
			mensagem += "Senha deve ser preenchida.<br/>";
		else if ( senha != senhaconf )
			mensagem += "A senha nÃ£o confere.<br/>";

		/**
		 * Se o preenchimento estiver correto envia o formulï¿½rio.
		 */
		if ( mensagem.length == 0 )
		{
			registroMensagem.className = "mensagem";
			registroMensagem.innerHTML = "";
			
			return true;
		}
		else
		{
			registroMensagem.innerHTML = mensagem;
			registroMensagem.style.display = "block";
			registroMensagem.className = "mensagem ym-Aviso";
			 
			return false;
		}
	}
}
function mostraVideo( caminhoPlayer, caminhoVideo, anuncioTitulo, anuncioCaminho, width, height )
{


	width = 
		 width != null ? 
		 	width : 236;
	
	height = 
		 height != null ? 
		 	height : 190;

	var destaqueVideo = document.getElementById( "destaqueVideo" );
	var videoTitulo = document.getElementById( "divVideoTitulo" );

	if ( destaqueVideo != null )
	{
//		destaqueVideo.innerHTML =
//			"<div class=\"Video\">" +
//			"	<object type=\"application/x-shockwave-flash\" data=\"" + caminhoPlayer + "\" " +
//			"        width=\"" + width + "\" height=\"" + height + "\" id=\"FlowPlayer\">" +
//			"        <param name=\"allowScriptAccess\" value=\"sameDomain\" />" +
//			"        <param name=\"movie\" value=\"" + caminhoPlayer + "\" />" +
//			"        <param name=\"quality\" value=\"high\" />" +
//			"        <param name=\"scale\" value=\"noScale\" />" +
//			"        <param name=\"wmode\" value=\"transparent\" />" +
//			"        <param name=\"flashvars\" value=\"config={videoFile: '" + caminhoVideo + "',autoPlay:false}\" />" +
//			"	</object>" +
//			"</div>";// +
			//"<div class=\"VideoTitulo\" id=\"divVideoTitulo\"><h4>" + anuncioTitulo + "</h4></div>";
			
		caminhoThumbnail = 
			caminhoVideo.replace( ".flv", ".jpg" );
			
		destaqueVideo.innerHTML =
			"<a class=\"flowplayer\" href=\"" + caminhoVideo + "\">" +
			"	<img width=\"" + width + "\" height=\"" + height + "\" src=\"" + caminhoThumbnail + "\" />"
			"</a>";

		if ( videoTitulo != null )
		{
			if ( anuncioCaminho.length == 0 )
				videoTitulo.innerHTML = "<h4>" + anuncioTitulo + "</h4>";

			else
				videoTitulo.innerHTML = "<h4><a href=\"" + anuncioCaminho + "\">" + anuncioTitulo + "</a></h4>";
		}
		
		goEmbed();
	}
}
function mostraImagem( caminho, caminhoLightbox )
{
	var destaqueImagem = document.getElementById( "destaqueImagem" );

	var destaqueLightbox = 
		caminhoLightbox.length != 0 ? 
			"style=\"cursor: pointer\" onclick=\"ampliaImagem('" + caminhoLightbox + "');\"" : "";

	if ( destaqueImagem != null )
		destaqueImagem.innerHTML = "<img src=\"" + caminho + "\" " + destaqueLightbox + " />";
}
function mostraTipos( tipo, imagem ) { }
function novaProposta( anuncioChave ) { }
function indiqueAnuncio( anuncioChave ) { }
function recuperarSenha()
{
	var campoEmail = document.getElementById( "campoEmail" );
	var loginMensagem = document.getElementById( "loginMensagem" );
	var campoRecuperarSenha = document.getElementById( "campoRecuperarSenha" );
	var formLogin = document.getElementById( "formLogin" );

	if ( campoEmail != null && loginMensagem != null )
	{
		if ( campoEmail.value.length == 0 )
		{
			loginMensagem.style.display = "block";
			loginMensagem.innerHTML = "Preencha o e-mail para receber uma nova senha.";
		}
		else
		{
			campoRecuperarSenha.value = "OK";
			formLogin.submit();
		}
	}
}
function enviaAoTopo()
{
	if (document.documentElement && document.documentElement.scrollTop)
		document.documentElement.scrollTop = 0;

	else if (document.body)
		theTop = document.body.scrollTop = 0;

}
function ampliaImagem()
{

}
function generateCityListBox( stateListBox, url, cityListBoxName )
{
	var state = $( stateListBox ).val();

	$( '#' + cityListBoxName ).attr( "disabled", true); 

	$.post(
		url, 
		{ state: state },
  		function(json)
  		{
  			$('#' + cityListBoxName + ' option').remove();
  			
  			var html = '';
  			
  			/**
  			 * O modelo abaixo não funciona igualmente no IE e mozilla
  			 * A solução ideal seria como a primeira para todos os navegadores.
  			 */
  			if ( $.browser.msie )
  			{
	  			for( i=0; i<json.cities.length; i++ )
				{
					var option = document.createElement( 'option' );
					option.value = json.cities[ i ];
					option.innerHTML = json.cities[ i ];
				
					document.getElementById( cityListBoxName ).appendChild( option );
				}
  			}
  			else
  			{ 
	  			for( i=0; i<json.cities.length; i++ )
					html += '<option value="' + json.cities[ i ] + '">' + json.cities[ i ] + '</option>';
					
				document.getElementById( cityListBoxName ).innerHTML = html;
			}
  			
			
			$( '#' + cityListBoxName ).removeAttr("disabled");   
    	}, 
    	"json" );
}
function addSearhFilter( listbox, url )
{
	var state = $( listbox ).val();
	
	location.href = url + '&cp=av&uf=' + state; 
}




