function preventSelection(element){
var preventSelection = false;
function removeSelection(){
if (window.getSelection){
window.getSelection().removeAllRanges();
}else if (document.selection && document.selection.clear){
document.selection.clear();
}
}
function killCtrlA(event){
if (event.target.tagName.match(/INPUT|TEXTAREA/i)){
return;
}
var key = event.keyCode || event.which;
if (event.ctrlKey && key == 'A'.charCodeAt(0)){
removeSelection();
event.preventDefault();
}
}
Event.add(element, "mousemove", function(){
if(preventSelection){
removeSelection();
}
});
Event.add(element, "mousedown", function(e){
preventSelection = !e.target.tagName.match(/INPUT|TEXTAREA/i);
});
Event.add(element, "mouseup", function(){
if(preventSelection){
removeSelection();
preventSelection = false;
}
});
Event.add(element, "keydown", killCtrlA);
Event.add(element, "keyup", killCtrlA);
}