
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
var ie = (navigator.userAgent.indexOf('MSIE 8.0') != -1);
var specialcase = ((navigator.userAgent.indexOf('Mac') != -1) || document.all) && !ie;
var flag = 0;
var msg = "Copyright image - all rights reserved";
var x,y,x1,y1,copyAttempt;

function init()
{
    if (!(document.getElementById || document.all || document.layers)) return;
    if (specialcase && document.layers)
	{
            document.captureEvents(Event.MOUSEMOVE);
            document.onmousemove = special;
	}
    for (i=0;i<document.images.length;i++)
	{
            document.images[i].onmousedown = checkIt;
            document.images[i].onmouseup = function() {return false};
		if (specialcase)
                    {
			document.images[i].onmousemove = special;
			document.images[i].onclick = clearIt;
                    }
	}
}

function checkIt(e)
{
    copyAttempt = 0;
    if (window.Event)
       	{
		if(ie)   //Added 12-22-2009: IE 8 object names are event and event.button
		{
		    x = event.screenX;
		    y = event.screenY;
		    theButton = (event.button == 2);
		}
		else
		{
		    x = e.screenX;
		    y = e.screenY;
		    theButton = (e.which == 3);
		}
	}
    else
	{
            x = window.event.clientX;
            y = window.event.clientY;
            theButton = (window.event.button == 2);
	}
    if (theButton)
	{
            copyAttempt = 1;
            flag = 0;
            alert(msg);
            return false; // NN4 only
	}
    if (specialcase) flag = 1;
    return false;
}

function special(e)
{
    theObj = '';
    if (window.Event)
	{
            x1 = e.screenX;
            y1 = e.screenY;
            if (e.target.parentNode) theObj = e.target.parentNode.tagName;
	}
    else
	{
            x1 = window.event.clientX;
            y1 = window.event.clientY;
            theObj = window.event.srcElement.parentElement.tagName;
	}
    var isLink = (theObj == 'A');
    if (flag && (!isLink || ((Math.abs(x-x1) > 10) || (Math.abs(y-y1) > 10))))
	{
            copyAttempt = 1;
            flag = 0;
            alert(msg);
            return false;
	}
}

function clearIt()
{
    flag = 0;
    if (copyAttempt)
	{
            copyAttempt = 0;
            return false;
	}
}

/*
function right(e) {
    var msg = "Copyright image - all rights reserved";
    if (navigator.appName == 'Netscape' && e.which == 3) {
        alert(msg);
        return false;
    }
    
    
    if (navigator.appName == 'Microsoft Internet Explorer') {
        alert('is IE');
        alert(navigator.userAgent);
        if (navigator.userAgent.indexOf('Mac') != -1) {

            alert('button: ' + event.button);
            alert('ctrl: ' + event.ctrlKey);
            alert('alt: ' + event.altKey);
            alert('shift: ' + event.shiftKey);            
            if (event.button==1 && event.ctrlKey) {
                alert(msg);
                return false;
            }
        }
        else if (event.button==2) {
            alert(msg);
            return false;
        }        
    }
    else return true;
}

function trap() 
  {
  if(document.images)
    {
    for(i=0;i<document.images.length;i++)
      {
      document.images[i].onmousedown = right;
      document.images[i].onmouseup = right;
      }
    }
  }

*/

 function getSelected() {
     
     var txt = '';
     
     if (window.getSelection) txt = window.getSelection();
     else if (document.getSelection) txt = document.getSelection();
     else if (document.selection != null) txt = document.selection.createRange().text;
     return txt;
 }

function printCitationDate() {
  var citation_date;
  var months = new Array("Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec" );
  var date = new Date();
  var day  = date.getDate();
  var month = date.getMonth();
  var yy = date.getYear();
  var year = (yy < 1000) ? yy + 1900 : yy;

  citation_date = day + " " +  months[month] + " "  + year;
  return citation_date;

}

function writeSeealsoLink(url, headword) {
  document.write('<a href="' + url + generateBackstack() + '" target="_top">' + headword + '</a>');
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return('');
}


function goSubHead(subhead) {

  if(top.location.href.indexOf('/view/article/') != -1) {
    /* This is a static page */
    top.main.location.href= '/articles/${dir}/${param.articleid}-article.html#' + subhead;
  }
  else if (top.location.href.indexOf('/browse/getalife/') != -1) {
    /* This is Get a Life */
    top.main.location.href= '/articles/${dir}/${param.articleid}-article.html#' + subhead;
  }
  else {
   /* This is dynamic */
    top.main.location.href= '/templates/articleHL.jsp?articleid=${param.articleid}#' + subhead;
  }
} 

function goPubSubHead(id, subhead) {
   var ref = '/public/articles/' + id + '-article.html#' + subhead;
   top.main.location.href = ref;
}

