function CompareHits(a, b) {
  return b.cnt-a.cnt;
}

function ShowHits(n) {
  if ( n > 200 )
    n = 200;
  var arStopWords = new Array(
  "about", "after", "all", "also", "an", "and", "another", "any", "are", "as",
  "at", "be", "because", "been", "before", "being", "between", "both", "but",
  "by", "came", "can", "come", "could", "did", "do", "does", "each", "for", "from",
  "get", "got", "had", "has", "have", "he", "her", "here", "him", "himself",
  "his", "how", "if", "in", "into", "is", "it", "like", "make", "many", "me",
  "might", "more", "most", "much", "must", "my", "never", "now", "of", "on",
  "only", "or", "other", "our", "out", "over", "same", "see", "should",
  "since", "some", "still", "such", "take", "than", "that", "the", "their",
  "them", "then", "there", "these", "they", "this", "those", "through", "to",
  "too", "under", "up", "very", "was", "way", "we", "well", "were", "what",
  "where", "which", "while", "who", "with", "would", "you", "your");
  var StopWords = new Object();
  var suff = "ed|s|es|ing";
  var ref = document.referrer;
  if ( ref == null )
    return;
  var qm = ref.indexOf("?");
  if ( qm < 0 )
    return;
  var ww = ref.substr(qm+1).split(/&+/);
  var re = new RegExp("^(.+)(" + suff + ")$","i");
  var s = "";
  var i;

  for ( i = 0 ; i < arStopWords.length ; ++i ) {
    StopWords[arStopWords[i]] = true;
  }

  for ( i = 0 ; i < ww.length ; ++i ) {
    var eq = ww[i].indexOf("=");
    if ( eq >= 0 )
      s += ww[i].substr(eq);
  }

  ww = s.split(/[^a-z0-9]+/i);
  s = "";
  for ( i = 0 ; i < ww.length ; ++i ) {
    var w = ww[i];
    var m = re.exec(w);
    var wNorm = m==null ? w : m[1];
    if ( w.length>=3 && StopWords[w.toLowerCase()]==null && StopWords[wNorm.toLowerCase()]==null )
      s += "|" + wNorm ;
  }

  if ( s.length <= 1 )
    return;
  re = new RegExp("\\b(" + s.substr(1) + ")(" + suff + ")?\\b", "ig");
  var arShow = new Array();
  for ( i = 0 ; i < n ; ++i ) {
    var d = document.getElementById("d" + i);
    RegExp.lastIndex = 0;
    var txt = d.innerText;
    var m = re.exec(txt);
    if ( m != null ) {
      var hitCount = 1;
      while ( re.exec(txt) != null )
        ++hitCount;
      var toShow = new Object();
      toShow.cnt = hitCount;
      toShow.el = d;
      arShow[arShow.length] = toShow;
    }
  }
  
  arShow.sort(CompareHits);

  var maxToShow = 4;
  for ( i = 0 ; i < Math.min(maxToShow,arShow.length) ; ++i ) {
    arShow[i].el.className="hit";
  }
}


function GoAid () {
	var http = "http://" ;
	var www = "" ;
	var kna = "search.opinionarchives" ;
	var com = "com" ;
	var vd  = "AmerSpec_Web";
	var base = http + www + kna + "." + com + "/" + vd + "/" ;
	var target = base + "DigitalArchive.aspx" ;
	var params = "" ;
	if ( AID ) {
		params = "?panes=1&aid=" + AID ;
		if ( AID.length < 10 ) params = "" ;
	} else params = "" ;
	location.href = target + params ;
}

function GoMenu ( text ) {
	var http = "http://" ;
	var www = "" ;
	var kna = "search.opinionarchives" ;
	var com = "com" ;
	var vd  = "AmerSpec_Web";
	var base = http + www + kna + "." + com + "/" + vd + "/" ;
	var target ;
	if ( text == "ARCHIVE" ) target = base + "DigitalArchive.aspx" ;
	else if ( text == "ABOUT US" ) target = "http://opinionarchives.com/aboutus.html";
	else if ( text == "SUBSCRIBE" ) target = "https://search.opinionarchives.com/CDBOnlineSubscr/IndTrial.aspx?ReferrerUrl=http://search.opinionarchives.com/AmerSpec_Web"; //base + "sanity.aspx" ;
	else if ( text == "DONATE" ) target = base;
	else if ( text == "HOME" ) target = base ;
	else target = base;
	location.href = target ;
}

function DoMouseOver ( obj ) {
	obj.style.color = "#993300" ;
	obj.style.cursor = "hand" ;
}

function DoMouseOut ( obj ) {
	obj.style.color = "#FFFFFF" ;
	obj.style.cursor = "default" ;
}

function MakeMenu ( Command , Separator , Content ) {
	var s = "" ;
	if ( Content == null ) Content = Command ;
  s += '<td class="grayMenu" onclick="GoMenu(\'' + Command + '\');" ' ;
  s += 'onmouseover="DoMouseOver(this);" ' ;
  s += 'onmouseout="DoMouseOut(this);"   ' ;
  s += '>' + Content + '</td>' ;
  if ( Separator != null && Separator != '' )
  	s += '<td class=menuSeparator>' + Separator + '</td>' ;

	return s ;
}

function MakeHeader () {
	var s = "" ;

	s += 	'<TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" id=tblMenus>' ;
	s += 	'<tr class="grayMenu">' ;
	s += 	'<td>' ;
	s += 		'<table WIDTH="780" BORDER="0" CELLPADDING="0" CELLSPACING="0">' ;
	s += 		'<tr>' ;
	s += 		MakeMenu ( 'ARCHIVE' , '' ,
						'<img src="ArchiveLogo.gif" WIDTH="228" HEIGHT="24" border="0">'); 
	s += 		'<td align="right">' ;
	s += 			'<table border="0" cellpadding="0" cellspacing="0" height="24">' ;
	s += 			'<tr>' ;
	s += 			MakeMenu ( 'ABOUT US' 	, '|' ) ;
	s += 			MakeMenu ( 'SUBSCRIBE' 	, '|' ) ;
//	s += 			MakeMenu ( 'DONATE' 		, '|' ) ;
	s += 			MakeMenu ( 'HOME' ) ;
	s += 			'</tr></table>' ;
	s += 		'</td></tr></table>' ;
	s += 	'</td></tr></table>' ;
	
	return s ;
}

function GenPreText () {
	var s = "" ;
	
	s += MakeHeader () ;
	s += "<p>" ;
	s += "<p class=archive_big_header>" ;
	if ( typeof ( AID ) != 'undefined' && AID.length == 10 ) {
		s += "<span class=blue_archive_big_header " ;
		s += "onclick=\"GoAid( AID );\" " ;
		s += ">Click here</span> to read the full text of this article in the " ;
	} else {
		s += "Enter the " ;
	}
	s += "<span class=blue_archive_big_header " ;
	s += "onclick=\"GoMenu('ARCHIVE');\" >" ;
	s += "<span class=blue_archive_big_header_com>American Spectator</span>" ;
	s += " Digital Archive</span>" ;
	s += "</p>" ;
	
	
	document.write ( s ) ;
}

function GenPostText () {
	var s = "" ;
	s += "<p></p>" ;
	document.write ( s ) ;
}

function GenCopyright () {
	var s = "" ;
	s += "<SMALL STYLE='color:#666666;'>" ;
	s += "Copyright &copy;2004, American Spectator. All rights reserved.<BR>" ;
	s += "Unauthorized redistribution is prohibited.</SMALL>" ;
	s += "" ;
	document.write ( s ) ;
}

function GoKanda () {
	var http = "http://" ;
	var www = "www" ;
	var kna = "kandasoft" ;
	var com = "com" ;
	var target = http + www + "." + kna + "." + com ;
	location.href = target ;
}
