﻿$(function() {
/*
if($(window).width() < 1298)
	$("#divConteinerGeral").width($(window).width());*/
	var total = 140;
	$('textarea').keydown(function(e){ 
	//console.log(e);
		var atual = parseInt($('#counter').text());
		if(e.keyCode == 8 || e.keyCode == 46) {
			if((atual+1) > total) return false;
			$('#counter').text(this.value.length == total ? 1 : (total - (this.value.length-1)));
		}
		else if(atual > 0) {
			$('#counter').text(total - (this.value.length+1));
		}
		else return false;
	}); 
	
	$('textarea').keyup(function(e){ 
		if(this.value.length == 0) $('#counter').text(total);
	}); 
	
	$("span.checkbox").click(function(e) {
		e.preventDefault();
		$(this).toggleClass("on");
		if ($("input[type=checkbox]", this).is(":checked")) {
            $("input[type=checkbox]", this).removeAttr("checked");
            ret = false;
        }
        else {
            $("input[type=checkbox]", this).attr("checked", true);
            ret = true;
        }
	});
	
	$("a.btRegulamento").click(function(e) {
		e.preventDefault();
		$(".divOverlay").show();
			$("#divLightboxRegulamento").slideDown(function() {
			
				$("#divLightboxRegulamento .divFechar a").unbind("click").click(function(f) {
					f.preventDefault();
					$("#divLightboxRegulamento").slideUp(function() {
						$(".divOverlay").hide();
					});
				});

				$(".scroll").jScrollPane({
					scrollbarWidth: 15,
					scrollbarMargin: 0,
					showArrows: true,
					dragMinHeight: 46,
					dragMaxHeight: 46
				});
			});
	});
	
});

function verificaCitacao() {
	var texto = $('textarea').val().toLowerCase();
	//console.log( RegExp(/([\s]#audigiftday [\s]?\b)|(^#audigiftday[\s]?\b)/).test(texto) );
	//console.log( RegExp(/([\s]@audibr[\s]?\b)|(^@audibr[\s]?\b)/).test(texto) );
	if(	!RegExp(/([\s]#audigiftday[\s]?\b)|(^#audigiftday[\s]?\b)/).test(texto) ) {
		alert("Por favor, cite #AudiGiftDay em sua mensagem");
		return false;
	}

	if(	!RegExp(/([\s]@audibr[\s]?\b)|(^@audibr[\s]?\b)/).test(texto) ) {
		alert("Por favor, cite @audibr em sua mensagem");
		return false;
	}
	
	if(	$("input[type=checkbox]",$(".checkbox")).not(":checked").length > 0) {
		alert("Por favor, você deve concordar com o regulamento antes de enviar sua mensagem.");
		return false;
	}

	pageTracker._trackEvent('audigiftday#3', 'sendtweet');
}

function trackFollow() {
	pageTracker._trackEvent('audigiftday#3', 'follow');
}

function openPop(url) {
	window.open(url, "twitterWindow","width=800,height=400,left=150,top=100,scrollbar=no,resize=no");
}; 