/*

  Script copyrighted Cambridge university press 2000
  Do *not* modify without written permission to do so..

   Usage of script :

   * Place dictionary.js in the directory on your website
   * Add following to your html file(s)
     <script language="javascript1.2" src="dictionary.js" ></script>

  When a people doubleclick on a word that word will be looked up in our
  online dictionary.

*/

var NS = (navigator.appName == "Netscape") ? 1 : 0;
 if (NS) document.captureEvents(Event.DBLCLICK);
 document.ondblclick = dict;

var dictvar;
function dict() {
    if (NS) {
        t = document.getSelection();
        pass_to_dictionary(t);
    } else {
        t = document.selection.createRange();
        if(document.selection.type == 'Text' && t.text != '') {
            document.selection.empty();
            pass_to_dictionary(t.text);
        }
   }
}

function pass_to_dictionary(text) {
    //clean the lookup string
    text = text.replace(/[\.\*\?;!()\+,\[:\]<>^_`\[\]{}~\\\/\"\'=\uFEFF]/g, " "); //remove invalid characters (included "FEFF", the unicode character "Zero width no-break space")
    text = text.replace(/\s+/g, " ");
    //launch a search with the lookup string
    if (text != null && text.replace("/\s/g", "").length > 0)
        location.href = "/results.asp?searchword="+text;
}

function toggleCloudOverflow(anchor) {
    var overflowContainer = document.getElementById("overflow_container");
    if (!overflowContainer)
        return;
    var anchorText;
    if (overflowContainer.className == "hide_overflow_more") {
        overflowContainer.className = "";
        anchorText = "<< View Less";
    } else {
        overflowContainer.className = "hide_overflow_more"
        anchorText = "View More >>";
    }
    anchor.firstChild.nodeValue = anchorText;
}
