// JavaScript utils
// Copyright 2001, J. Donald Tillman

// Fix Netscape 4.x bug where the clowns forgot to update half the stuff 
// when the page is resized.
//
// Also aware of the Netscape 4.08 bug where the clowns send off too 
// many resizes.
//
//
// To use, do a:
//     <script language=JavaScript type="text/javascript">
//       till_reloadPage(true);
//     </script>
//
// For regular pages, do this in the head of the page.
// For frames, do this in the head of the page with the framesets.
// Or you can just call till_reloadPage() to do an immediate reload.

function till_reloadPage(init) {
    if (true == init) {
	if (('Netscape' == navigator.appName) && (4 == parseInt(navigator.appVersion))) {
	    onresize = till_reloadPage;
	    till_origWidth = innerWidth;
	    till_origHeight = innerHeight
	}
    } else {
	if ((till_origWidth != innerWidth) || (till_origHeight != innerHeight)) {
	    var frameCount = top.frames.length;
	    if (0 == frameCount) {
		location.reload();
	    } else {
		for (var i = 0; i < frameCount; i++) {
		    top.frames[i].location.reload();
		}
	    }
	}
    }
}

// Use this function to hide email addresses from those godawful spammers.
// (No longer used.)
function till_email(name, site) {
    document.write('<a href="mailto:' + name + '@' + site + '">' + name + '@' + site + '</a>');
}

// Patent links are ridiculously hairy. 
// Do it this way and we can easily deal with any changes.
function usptoLink(patentNumber) {
  document.writeln('<a target=_blank href="http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&amp;Sect2=HITOFF&amp;d=PALL&amp;p=1&amp;u=/netahtml/srchnum.htm&amp;r=1&amp;f=G&amp;l=50&amp;s1=\'' + patentNumber + '\'.WKU.&amp;OS=PN/' + patentNumber + '&amp;RS=PN/' + patentNumber + '">US ' + patentNumber + ' at the USPTO\</a><br>');
}

// I *think* the suffix should be 'A' for patents before 2001, 'B' for patents after.
//
// I'm not using this anymore because EspaceNets' inline pdf's work badly in Safari.
function espacenetLink(patentNumber, suffix) {
  var pn=patentNumber.replace(/,/g, '');
  document.writeln('<a target=_blank href="http://l2.espacenet.com/espacenet/bnsviewer?CY=gb&amp;LG=en&amp;DB=EPD&amp;PN=US' + pn + '&amp;ID=US+++' + pn + suffix + '1+I+">US ' + patentNumber + ' at the EPO EspaceNet\</a><br>');
}

// Better to use pat2pdf.org
function pat2pdfLink(patentNumber) {
  document.writeln('<a target=_blank href="http://www.pat2pdf.org/pat2pdf/foo.pl?number=' + patentNumber + '"> US ' + patentNumber + ' from pat2pdf.org\</a><br>');
}

