// JavaScript Document
$(function (){

	/* envio do form */
	$("form[@title=Formulario]").submit(function() {
		var enviar_ok = true;
		var form_name = $(this).attr('name');

		$("#loading").show();

		/* checar campos */
		$('#'+form_name+' :input[@title=requerido] ').each(function(){
			if($.trim($("#"+this.id).val()) == ''){
				$("#"+this.id).css({ background: "#FF9F9F" });
				enviar_ok = false;
			} else {
				$("#"+this.id).css({ background: "#B8F5B1" });
			}
		});

		if(enviar_ok) {
			var options = {
				success: function(msg) {
					$("#loading").hide("slow");
					// sucesso no envio
					if(msg == "-1") {
						alert('E-mail enviado com sucesso. Em breve retornaremos. Obrigado!');
						$('#'+form_name).resetForm();
					} else {
						$("#resultado").html(msg);
					}
				}
			};
		
			$(this).ajaxSubmit(options);
			
			return false; // faz o submit normal
		} else {
			$("#loading").hide("slow");
			alert('Preencha os campos obrigatórios.');
			return false; //cancela submit normal
		}
	});
	
	$("img[@title=Votar]").click(function() {
		$("#resultado").html('');
		var string = $(this).attr('alt');
		var ponto = string.split(' ');
		var video = $('#txt_video').val();
		
		$("#loading").show();
		$.ajax({
			type: "post",
			url: "/ajax_processa.php",
			data: "act=votar&txt_ponto="+ponto[1]+"&txt_video="+video,
			success: function(msg){
				if(msg == "-1") {
					alert('Voto registrado com sucesso. Obrigado!');
					$("#loading").hide("slow");
				} else {
					$("#resultado").html(msg);
					$("#loading").hide("slow");
				}
			},
			error: function(obj, msg, exception){
				$("#resultado").html("<option value=''>Erro Carregando arquivo!</option>");
				$("#loading").hide("slow");
			}
		});
	});
	
	// redirecionar para endereco
	$("select[@title=abre_url_change]").change(function() {
		window.open($(this).val(),'_top');
	});
	
	// maximizar thumbs
	$('.bloquinho_video img').mouseover(function() {
		$(this).width(133);
		$(this).height(100);
		$(this).attr('z-index', 100);
		$(this).css("border", "1px groove black");
	});
	
	$('.bloquinho_video img').mouseout(function() {
		$(this).width(110);
		$(this).height(85);
		$(this).attr('z-index', 1);
		$(this).css("border", "0");
	});
	
	$('.video_foto img').mouseover(function() {
		$(this).width(133);
		$(this).height(100);
		$(this).attr('z-index', 100);
		$(this).css("border", "1px groove black");

	});
	
	$('.video_foto img').mouseout(function() {
		$(this).width(110);
		$(this).height(85);
		$(this).attr('z-index', 1);
		$(this).css("border", "0");
	});
	
});

/******** adicionar aos favoritos ********
* @uso onclick=javascript:addbookmark(); *
* create by Ariel Solutions              *
*****************************************/
function addbookmark() {
	var url      = document.location;
	var title    = document.title;

	if (window.sidebar) window.sidebar.addPanel(title, url,"");

	else if(window.opera && window.print){
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}
	else if(document.all) {
		window.external.AddFavorite(url, title);
	}
}

function popUp(aURL, aWidth, aHeight) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(aURL, '" + id + "', 'width=780,height=575,top=1,left=5,resizable=1,scrollbars=1');");

  winhandle = eval("page" + id);

  winhandle.focus();

}
