/* scripts for Irish Glossaries project
*/

onload = init;
function init() {
   fixContainerHeight();
}

// for IE6: workaround for CSS frame 
function fixContainerHeight() {
   var IE6 = document.all;
   if (IE6) {
      var h = document.body.offsetHeight;
      if (document.getElementById('contentHolder')) document.getElementById('contentHolder').style.height = (h - 42) + 'px';
      document.body.onresize = fixContainerHeight;
   }
}

// dropdown in nav
var ddClosing = false;
function ddOn() {
   document.getElementById('dropDown').style.display = 'block';
   ddClosing = false;
}
function ddOff() {
   ddClosing = true;
   setTimeout('ddHide();', 1500);
}
function ddHide() {
   if (ddClosing) document.getElementById('dropDown').style.display = 'none';
}

// track mouse position
var mX, mY;
var IE = document.all ? true : false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
function getMouseXY(e) {
   if (IE) { // grab the x-y pos.s if browser is IE
      mX = event.clientX + document.body.scrollLeft;
      mY = event.clientY + document.body.scrollTop;
   }
   else {  // grab the x-y pos.s if browser is NS
      mX = e.pageX;
      mY = e.pageY;
   }  
   return true;
}

// tool tip
var ttOn = false;
var ttTitle = '';
function tt(link) {
   var el = document.getElementById('toolTip');
   var tipText = '';
   if (! ttOn) {
      ttOn = true;
      // some titles are abbreviated 
      if (link.title == 'Link to Perseus') tipText = 'Click to look up this <b>Latin word</b> in the Perseus Latin Morphology Tool.<br/>(Note: Rarer words, non-Classical spellings and scribal corruptions may not be recognised.)';
      else if (link.title == 'Link to DIL') tipText = 'Click to look up this word in <b><i>DIL</i></b> (simple search).';
      else if (link.title == 'Link to DIL headword') tipText = 'Click to consult the relevant headword in <b><i>DIL</i></b>.';
      else tipText = link.title;
      el.innerHTML = tipText;
      el.style.left = (mX + 4) + 'px';
      el.style.top = (mY + 18) + 'px';
      el.style.display = 'block';
      ttTitle = link.title;
      link.title = '';     // remove link title to avoid overlap on tool tip 
   } else {
      ttOn = false;
      el.style.display = 'none';
      link.title = ttTitle;   // restore title
   }
   return false;
}

// search: advance options switcher
function toggleAdvOptions(advSwitch) {
   var showOptions = '<p><a href="#" onclick="toggleAdvOptions(\'on\'); ">More options</a></p>';
   var hideOptions = '<p><a href="#" onclick="toggleAdvOptions(\'off\'); ">Hide other options</a></p>';
   if (advSwitch == 'on') {
      document.getElementById('advOptions').style.display = 'block';
      document.getElementById('advOptionsSwitcher').innerHTML = hideOptions;
   }
   else {
      document.getElementById('advOptions').style.display = 'none';
      document.getElementById('advOptionsSwitcher').innerHTML = showOptions;
   }
}

function search_longestVersions() {
   search_clearAllVersions();
   with (document.forms['search']) {
      elements['sVer_9'].checked = true;
      elements['sVer_1'].checked = true;
      elements['sVer_2'].checked = true;
      elements['sVer_10'].checked = true;
      elements['sVer_6'].checked = true;
      elements['sVer_17'].checked = true;
   }
}
function search_clearAllVersions() {
   for (var n = 0; n < document.forms['search'].length; n ++ ) {
      if (document.forms['search'].elements[n].name.substr(0,5) == 'sVer_') document.forms['search'].elements[n].checked = false; 
   }
}
function search_clearAllLangs() {
   for (var n = 0; n < document.forms['search'].length; n ++ ) {
      if (document.forms['search'].elements[n].name.substr(0,6) == 'sLang_') document.forms['search'].elements[n].checked = false; 
   }
}



// Ajax scripts
/*
var xmlHttp;
function retrieveRows(url) { 
   xmlHttp = GetXmlHttpObject();
   if (xmlHttp == null) {
      alert("Browser does not support HTTP Request");
      return;
   }
   url += "&sid = " + Math.random();
   xmlHttp.onreadystatechange = stateChanged; 
   xmlHttp.open("GET", url, true);
   xmlHttp.send(null);
}

function stateChanged() { 
   if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") { 
      document.getElementById("newRows_after").innerHTML = xmlHttp.responseText; 
   } 
}

function GetXmlHttpObject() {
   var xmlHttp = null;
   try {
      // Firefox, Opera 8.0 + , Safari
      xmlHttp = new XMLHttpRequest();
   }
   catch (e) {
      //Internet Explorer
      try {
         xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
   }
   return xmlHttp;
}

// DIL Link
function DIL_link(lemma) {
   document.forms.dil_search.mText.value = lemma + ',,';
   document.forms.dil_search.submit();
}


*/

