$().ready(function(){
	$().keypress(function (e) {
		if ((e.which == 13 || e.which == 10) && e.ctrlKey == true) {
			show_send_spell_window(get_selected_text());
		}
	});
});


$().ready(function() {
	  var options = { 
	  	target: "#rezult",
	    timeout: 3000,
	    success: function() {
			$('#preloader').hide();
			$('#rezult').show();
	  }
	  };
	    
		$("#form_send_spell").bind('submit',function() {
			$('#preloader').show();
			$(this).ajaxSubmit(options);
		    return false;
		});
		
});


function get_selected_text() {
    var selText = "";
    if (document.getSelection)  { // Mozilla
        selText = document.getSelection();
    } else if (document.selection) { // IE
        selText = document.selection.createRange().text;
    } else if (window.getSelection){ // Safari
        selText = window.getSelection();
    }
    if(selText) {
       return selText;
    }
}

function show_send_spell_window(spell_text) {
	$("#send_spell_window").css("display", "block");
	$("#spell_text").text(spell_text);
	$("#loc_href").val(location.href);
	$("#spell_info").val(spell_text);
	$("#spell_reply").val("");
}

function hide_send_spell_window() {
	$("#send_spell_window").css("display", "none");
	$("#loc_href").val("");
	$("#spell_info").val("");
	$("#spell_reply").text("");
	$('#rezult').hide();
}
