Okey, so here is the answer (SharePoint works properly with both old and new Office clients without version detection, so there must be a solution)
try {
var g = new ActiveXObject("SharePoint.OpenDocuments.5");
alert('Office 2013 installed');
window.open('ms-word:ofe|u|http://server.com/12.docx');
}
catch (h) {
alert('Office 2010/older installed');
var g = new ActiveXObject("SharePoint.OpenDocuments");
g.EditDocument('http://server.com/12.docx');
}
The only problem left is document opening in 'Protected View' while SharePoint opens them in regular view.