var resp=2;
function init_fb_events() {
	FB.Event.subscribe('edge.create', function(response) {
		$.ajax({ url: "/liked.php?url="+response, context: document.body, success: function() {}});
	});
}
$(function() {
   	$('#b_enc').click(function() {
		resp++;
		$('#enc_respuestas').append('<div class="rf" id="resp'+resp+'"><label>Respuesta '+resp+'</label> <input name="respuesta'+resp+'" type="text" class="crear_resp" /></div>');
		$('#resp'+resp).slideUp(0);
		$('#resp'+resp).slideDown(500);
	});
	
	var elements=$('ul.simbolos li');
	for(var i=0;i<elements.length;i++) {
		$(elements[i]).click(function() {
			var tit=$(this).parent().attr("title");
			if(tit!=null&&tit!='') {
				var o=$('input[name='+tit+']');
				//o.attr('value',o.attr('value')+$(this).html());
				o.insertAtCaret($(this).html());
			}
		});
	}
});

$.fn.insertAtCaret = function (myValue) {
        return this.each(function(){
                //IE support
                if (document.selection) {
                        this.focus();
                        sel = document.selection.createRange();
                        sel.text = myValue;
                        this.focus();
                }
                //MOZILLA/NETSCAPE support
                else if (this.selectionStart || this.selectionStart == '0') {
                        var startPos = this.selectionStart;
                        var endPos = this.selectionEnd;
                        var scrollTop = this.scrollTop;
                        this.value = this.value.substring(0, startPos)
                                      + myValue
                              + this.value.substring(endPos, this.value.length);
                        this.focus();
                        this.selectionStart = startPos + myValue.length;
                        this.selectionEnd = startPos + myValue.length;
                        this.scrollTop = scrollTop;
                } else {
                        this.value += myValue;
                        this.focus();
                }
        });

};