// My App Javascript file. Contains common global utility functions for this application
// LIST ALL SHOW/HIDE ELEMENT IDS HERE

function disable(button){
{button.disabled=true}
}

function enable(button){
{button.disabled=false}
}


function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  /*if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));*/
}

function highlightTableRows(tableId) {
    var previousClass = null;
    var table = document.getElementById(tableId); 
    var tbody = table.getElementsByTagName("tbody")[0];
    var rows = tbody.getElementsByTagName("tr");
    // add event handlers so rows light up and are clickable
    for (i=0; i < rows.length; i++) {
        rows[i].onmouseover = function() { previousClass=this.className;this.className+=' over' };
        rows[i].onmouseout = function() { this.className=previousClass };
        rows[i].onclick = function() {
            var cell = this.getElementsByTagName("td")[0];
            if (cell.getElementsByTagName("a").length > 0) {
                var link = cell.getElementsByTagName("a")[0];
                if (link.onclick) {
                    call = link.getAttributeValue("onclick");
                    // this will not work for links with onclick handlers that return false                    
                    eval(call);
                } else {
                  location.href = link.getAttribute("href");
                }
                this.style.cursor="wait";
            }
        }
    }
}

// Show the document's title on the status bar
window.defaultStatus=document.title;


/*Function to copy URL of opened window to clipboard. Adopted from gamedev.net*/
function copy_clip()
{
    var urlToCopied = location.href;
     // the IE-way
    
	if (window.clipboardData) 
	{
       window.clipboardData.setData("Text", urlToCopied);
   }
   // Probabely not the best way to detect netscape/mozilla.
   // I am unsure from what version this is supported
   
   else if (window.netscape) 
   { 
   // This is importent but it's not noted anywhere
   
       netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   // create interface to the clipboard
   
   var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
// create a transferable

   var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   // specify the data we wish to handle. Plaintext in this case.
   
   trans.addDataFlavor('text/unicode');
   // To get the data from the transferable we need two new objects
   
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=urlToCopied;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   alert("Following URL was copied to your clipboard:\n\n" + urlToCopied);
   return false;
}
