//   vim:ft=javascript
//added by adr for double click functionality RFS 1182
var lwdtext = "";
var lwdviewerpop;
var timeid;
var sURL = document.location.href;
var idmUrl = 'http://pewebdic2.cw.idm.fr/display/wapopup.html';
// Dimensions of the dictionary popup
var iPopupWidth = 637;
var iPopupHeight = 475;
var nav4 = window.Event;

function asGetActive(e){
    var txt = '';
    var foundIn = '';
    if (window.getSelection)
    {
        txt = window.getSelection();
        foundIn = 'window.getSelection()';
    }
    else if (document.getSelection)
    {
        txt = document.getSelection();
        foundIn = 'document.getSelection()';
    }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
        foundIn = 'document.selection.createRange()';
    }
    else return;
    lwdtext = txt;

    if (lwdtext != null && lwdtext != "")
        lwdShowMain(idmUrl, lwdtext);
    
    return true;

}

function doSearch(lwdtext) {
    if (lwdtext != null && lwdtext != "")
        lwdShowMain(idmUrl, lwdtext);
}

function lwdShowMain(url, word) {
    var sURL = ''
    var sFeatures = 'dependent=no,z-lock=yes,titlebar=1,location=no,toolbar=yes,' +
        'directories=no,menubar=0,resizable=1,scrollbars=1,status=1,' +
        'width=' + iPopupWidth +',height=' + iPopupHeight;
    var winX = (screen.width/2-302);
    var winY = (screen.width/2-337);
    // Create centered window
    sFeatures +=  ",screenX=" + winX + ",left=" + winX + ",screenY=" + winY + ",top=" + winY ;
    // Put the search string in the URL, the form stuff won't work cross-domain
    // and does not significantly improve the security
    if (lwdviewerpop != null) {
        try    {
            lwdviewerpop.close();
        }
        catch (e) {}
        lwdviewerpop = null;

    }

    //    lwdviewerpop = window.open(url + "?search_str=" + word, 'ldoceonline', sFeatures);
    if (lwdviewerpop == null) {
        lwdviewerpop = window.open(url + "?search_str=" + word, 'ldoceonline', sFeatures);
    }

    //check if still null
    if (lwdviewerpop == null) {
        alert('We are sorry, popups seem to be disabled. Please enable popups and try again.') 
    }
    else {
        lwdviewerpop.focus();
    }
}

