//IF YOU CAN SEE THIS, YOU HAVE AN OLD BROWSER
//USE http://www.ics.uci.edu/~pazzani/Publications/OldPublications.html

var Configuration = new Array()
Configuration["MostFrequent"] = 1
Configuration["Association"] = 1
Configuration["Cites"] = 1
Configuration["Cited"] = 1
Configuration["Similarity"] = 1
Configuration["Automatic"] = -1
Configuration["Down"] = 1
Configuration["New"] = 1
Configuration["ML"] = 1
Configuration["Bayes"] = 1
Configuration["FOL"] = 1
Configuration["KI"] = 1
Configuration["Psych"] = 1
Configuration["Wire"] = 1
Configuration["Time"] = 1
Configuration["Med"] = 1
Configuration["Apps"] = 1
Configuration["KBS"] = 1
Configuration["NLP"] = 1
Configuration["IA"] = 1
Configuration["NN"] = 1
Configuration["Th"] = 1
Configuration["MM"] = 1

var ButtonTitle = new Array()
ButtonTitle['MostFrequent'] = "Use Frequency Agent"
ButtonTitle['Association'] = "Use Association Agent"
ButtonTitle['Cites'] = "Use Cites Agent"
ButtonTitle['Cited'] = "Use Cited-by Agent"
ButtonTitle['Similarity'] = "Use Similarity Agent"
ButtonTitle['Automatic'] = "Suggest when idle"
ButtonTitle['New'] = "Suggest new papers"
ButtonTitle['Down'] = "Suggest after download"
ButtonTitle['ML'] = "Machine Learning"
ButtonTitle['Bayes'] = "Bayesian Classifiers"
ButtonTitle['FOL'] = "First Order Logic"
ButtonTitle['KI'] = "Explanation-based Learning"
ButtonTitle['Psych'] = "Psychology"
ButtonTitle['Time'] = "Time Series"
ButtonTitle['Wire'] = "Wireless"
ButtonTitle['Med'] = "Medicine"
ButtonTitle['Apps'] = "Applications"
ButtonTitle['KBS'] = "Expert Systems"
ButtonTitle['NLP'] = "Natural Language"
ButtonTitle['IA'] = "Intelligent Agents"
ButtonTitle['NN'] = "Neural Nets"
ButtonTitle['Th'] = "Theory"
ButtonTitle['MM'] = "Multiple Models"



var Latest = "first"
var paperDir = "http://www.ics.uci.edu/~pazzani/Publications"
var Visited = new Array()
var Abstracts = new Array()
var Considered = new Array()
var useAgent = 0
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // 1 year from now 
var s = GetCookie("Visited")
if (s != null) {	
   Visited = s.split(",")}
s = GetCookie("Abstracts")
if (s != null) {	
   Abstracts = s.split(",")}
s = GetCookie("Latest")
if (s != null) {	
   Latest = s}
s = GetCookie("Configuration")
if (s != null) {	
   restoreObject(Configuration,s)}


function writeCookie() {
	SetCookie("Latest", document.forms[0].name, expdate)
	SetCookie("Visited", arrayToString(Visited), expdate)
	SetCookie("Abstracts", arrayToString(Abstracts), expdate)
	SetCookie("Configuration", objectToString(Configuration), expdate)
}	

function activate( ){
	if (IE == 1) { 
          loadAssistant()
	  Agent = Assistant}
	  else {Agent = document.Assistant}
   	Agent.Active(true,5)
	useAgent = 1
   	Agent.Play(0X0000600b,0x2400,"Welcome!")
   	Agent.MoveTo(0x00002001,0,0,325)
   	Agent.Play(0X00009021 ,0x2400, "I can recommend articles to you that I think you'll like")
   	Agent.Play(0X00009039,0x2400, "Just click on Suggest")
   	Agent.Play(0X00009025,0x2400, "or click on Stop to shut me up")
	resetAgent()
	}

var onFocusCode = false
function onFocusFunction() {
	if (onFocusCode) {
		var f = onFocusCode
		onFocusCode = false
		eval(f)
	}
}

var LastDownload = false
function downloadPaper(paper, e){
var ext = e
resetAgent()
if (ext == "opdf") {
	paper += "-Slides"
	ext = "pdf"}
if (ext == "ohtml") {
	paper += "-Slides"
	ext = "html"}

var URL = paperDir + "/" + paper + "." + ext
open(URL)
if ((e == "pdf") || (e == "ps") || (e == "html")) {
	if (paper == LastSuggest) {reinforce(LastSuggest, LastReason, LastWhen)}
	else if (LastSuggest) {penalize(LastSuggest, LastReason, LastWhen)}
	else if (paper == LastAbstract) {reinforce(LastSuggest, LastReason, LastWhen)}
	else if (LastAbstract) {penalize(LastAbstract, false, false)} 
	LastDownload = paper
	LastReason = false
	LastWhen = false
	if (ArrayFind(Visited, paper) == -1){
		Visited[Visited.length] = paper
	SetCookie("Visited", arrayToString(Visited), expdate)
	SetCookie("Latest", document.forms[0].name, expdate)
	}
	if (Configuration["Down"] > 0) {
	if (onFocusCode) {downloadSuggest(paper)}  //i.e., if browser has failed at this
		else {onFocusCode =	"downloadSuggest(\'" + paper + "\')"}}
}
	LastAbstract = false
}

var LastAbstract = false
function showAbstract(paper){
resetAgent()
var URL = paperDir + "/" + paper + "-Abstract.html"
LastAbstract = paper
open(URL)
if (ArrayFind(Abstracts, paper) == -1){
	Abstracts[Abstracts.length] = paper
	SetCookie("Abstracts", arrayToString(Abstracts), expdate)
	}
}

function shutup() {
	if (useAgent) {
		useAgent = 0
		Agent.Stop(1)
		}
}




function whichAgentDown(MFs,Cs,CBs,Ss, As, title) {
	var total = 0
        var MFst, Ast, CBst, Cst, Sst
	if ((As != -1) && (Configuration["Association"] > 0))
	   {Ast = Configuration["Association"] * 0.5
		total += Ast }
	if ((MFs != -1) && (Configuration["MostFrequent"] > 0))
	   { MFst = Configuration["MostFrequent"] * (Accesses[MFs] / Accesses["maximum"])
		total += MFst}
        if ((Cs != -1) && (Configuration["Cites"] > 0))
           {Cst = Configuration["Cites"] * (Cited[Cs] / Cited["maximum"])
		total += Cst}
        if ((CBs != -1) && (Configuration["Cited"] > 0))
           {CBst = Configuration["Cited"] * (Accesses[CBs] / Accesses["maximum"])
		total += CBst }
        if ((Ss != -1) && (Configuration["Similarity"] > 0))
           {Sst = Configuration["Similarity"] * (sim[title + "_" + Ss] / sim["maximum"])
		total += Sst }
	if (total > 0) {
		var r = Math.random()*total
		 if ((MFs != -1) && (Configuration["MostFrequent"] > 0)) {
			if (r < MFst) {
				return "MostFrequent"}
			else {r = r - MFst}}
                 if ((As != -1) && (Configuration["Association"] > 0)) {
                        if (r < Ast) {
                                return "Association"}
			else {r = r - Ast}}
                 if ((Cs != -1) && (Configuration["Cites"] > 0)) {
                        if (r < Cst) {
                                return "Cites"}
			else {r = r - Configuration["Association"]}}
                 if ((CBs != -1) && (Configuration["Cited"] > 0)) {
                        if (r < CBst) {
                                return "Cited"}
                        else {r = r - CBst}}
	        if ((Ss != -1) && (Configuration["Similarity"] > 0))
		           {return "Similarity"}	
	}}

			
		   


function whichAgent() {
	if  ((Configuration["Cites"] == Configuration["MostFrequent"])) {
		if (Math.random() > 0.5)
		   {return "MostFrequent"}
		    else  {return "Cites"} }
	if (Configuration["Cites"] < Configuration["MostFrequent"])
	   {return "MostFrequent"}
	else {return "Cites"}
}


function suggest(when) {
	resetAgent()
	var w = false
	if ((Configuration["New"] > 0) && (Latest != "first") &&
	    (Latest != document.forms[0].name)) {
		w = recommendNew()
		if (w != false) {
			Latest = document.forms[0].name
			scrollIt(w, "New", when)}
	    }
	 if (w == false) {w=whichAgent()
	if (w == "MostFrequent") {
		scrollIt(mostUnreadofTopic(Accesses),  w, when)}
	if (w == "Cites") {
		scrollIt(mostUnreadofTopic(Cited),  w, when)}}
}

function downloadSuggest(title) {
	resetAgent()

	var MFs = mostUnreadofTopicCited(Accesses, Citations[title])
	var Cs = mostUnreadofTopicCited(Cited, Citations[title])
	var CBs = mostUnreadofTopicCited(Accesses, CitedBy[title])
	var Ss = mostSimilarUnread(title)
	var As = mostAssociated(Associated[title])
	var w=whichAgentDown(MFs,Cs,CBs,Ss, As, title)
	if (w == "MostFrequent") {
	scrollIt(MFs,  w, "Down")}
	if (w == "Cites") {
	scrollIt(Cs,  w, "Down")}
	if (w == "Cited") {
	scrollIt(CBs,  w, "Down")}
	if (w == "Similarity") {
	scrollIt(Ss,  w, "Down")}
	if (w == "Association") {
	scrollIt(As,  w, "Down")}
}

function scrollToName(name) {
   document.location = "APubs.html#" + name
}

var LastSuggest = false
var LastReason = false
var LastWhen = false
function scrollIt(title, reason, when) {
   if (title != -1) {
   var name =  shortname(Titles[title])
   scrollToName(title)
   Considered[Considered.length] = title
   LastSuggest = title
   LastReason = reason
   LastWhen = when
   if (useAgent) {Agent.MoveTo(0x00002001,0,100,160)}
   Output(0X00009038, "I recommend: \"" + name + 
	"\", because ", reason, title, when)
   if (useAgent) {
	Agent.MoveTo(0x00002001,0,0,325);
        Agent.Play(0x0000901c, 0x2410, "")	}
}
}

function shortname(name) {
   var	i = name.indexOf(':')
   if ((name.length > 50) && i > 20)
	{name = name.substring(0, i)}
	return name}

var messageFrameColor =	 1
function changeColor(Frame) {
	
	Frame.bgcolor = color
}

function Output(motion, string, reason, title, when) {
	if (reason == "MostFrequent")
	    {string += "it is the most frequently downloaded article that you have not considered"}
	else if (reason == "Cites")
	     {string += "it is the most frequently cited article that you have not considered"}
	else if (reason == "Cited")
	     {string += "it is the most frequently downloaded article that you have not considered"}
	else if (reason == "Similarity")
	     {string += "it is the article that you have not considered most"}
	else if (reason == "Association")
	     {string += "it is the article that you have not considered most frequently"}
	else if (reason == "New")
		{string += "it is the most frequently downloaded article added to this page since your last visit"
			if (RelatedTo)
			{string += " cited by " + shortname(Titles[RelatedTo])}}
	if (when == "Down") {
		if (reason == "Cited")
                     {string += " cited by " }
		else if (reason == "Cites")
		      {string += " that cites " }  
		else if (reason == "Association")
		      {string += " downloaded by others who downloaded " }  
		else {string += " related to " }
		string += "the paper just retrieved.  "}
	else {string += ".  "}
	if (useAgent)
	    {Agent.Play(motion, 0x2400, string)}
	 if (MessageFrame)
	    {writeMessageToFrame(MessageFrame, string, title, reason, when )}
	}


function writeMessageToFrame(f, s, title, reason, when) {
	var color
	if (messageFrameColor > 0)
		{color = "skyblue"}
		else {color = "pink"}
	 messageFrameColor *= -1
	msg = "<html><head>"
	if (title) {
	  msg += "<script language=\"JavaScript1.1\">"
	  msg += "var PublicationFrame = parent.Pubs"
	  msg += "</scr" + "ipt>"
	}
	msg += "</head><body   onFocus=\"PublicationFrame.onFocusFunction()\" bgcolor="
	msg += color
	msg += "><form>"
	msg += s
        if (UnderWin32p) {
          msg += "   <input type =\"button\" "
	  msg += "onClick=\"location=\'empty.html\';PublicationFrame.penalize(\'" + title + "\', \'" + reason + "\', \'" + when + "\')\" Value=\"No Thanks\">"
	if (title) {
	   msg += "  <input type =\"button\" onClick=\"location=\'empty.html\';PublicationFrame.downloadPaper(\'"
	   msg +=  title 
	   msg += "\', \'pdf\')\" Value=\"Download PDF\">"
      	   if (when != "User"){ msg += makeCheckbox(when)}
	   msg += makeCheckbox(reason)
	   msg += makeSubjectBoxes(title)}}
	msg += "</form></body></html>"
	writeStringToFrame(f, msg)
}

function  makeSubjectBoxes(title) {
	var s = ""
        var found = 0
	var Subs = Subjects[title]
	var l = Subs.length
        for (var i = 0; i < l; i++) {
		found = 0
		for (var j = 0; j < i; j++) {
	                if (Subs[j] == Subs[i]) {
				found = 1}}
		if ((found == 0) && (Configuration[Subs[i]] > 0)) {
			s += makeCheckbox(Subs[i])}
	}
	return s
}


function writeStringToFrame(frame, string) {
	frame.document.open()	
	frame.document.write(string)
	frame.document.close()	
}

function writeArray(a) {
  var msg_str   = ""
  
  // build up the contents for the window
  msg_str += "<HTML>"
  msg_str += "<HEAD>"
  msg_str += "<TITLE> Window"
  msg_str += "</TITLE>"
  msg_str += "</HEAD>"
  msg_str += "<BODY>"

    msg_str += "<P>The array's elements are:<BR>"
    for (var i = 0; i < a.length; i++) {
       msg_str += "element[" + i + "] = " + a[i] + "<BR>"    }
  msg_str += "</BODY>"
  msg_str += "</HTML>"

    

  props_win = open("", "propsWindow",
    "width=500,height=550,scrollbars=1,resizable=1")

  // write the contents into the window
  props_win.document.open()
  props_win.document.write(msg_str)
  props_win.document.close()
}



function writeString(s1) {
  var msg_str   = ""
  
  // build up the contents for the window
  msg_str += "<HTML>"
  msg_str += "<HEAD>"
  msg_str += "<TITLE> Window"
  msg_str += "</TITLE>"
  msg_str += "</HEAD>"
  msg_str += "<BODY>"

  msg_str += s1 

  
  msg_str += "</BODY>"
  msg_str += "</HTML>"

    

  props_win = open("", "StringWindow",
    "width=500,height=150,scrollbars=1,resizable=1")

  // write the contents into the window
  props_win.document.open()
  props_win.document.write(msg_str)
  props_win.document.close()
}



function arrayToString(a) {
  var str   = ""
  if (a.length > 0) {
    for (var i = 0; i < a.length-1; i++) {
       str += a[i] + ","    }
       str += a[a.length-1] }
    return str
}


function objectToString(a) {
    var str   = ""
    for (var i in a) {
       str += i + ":" + a[i] + ","    }
    return str
}

function restoreObject(Object, string) {
	var a = string.split(",")
	var index
	var first
	var last
	for (var i = 0; i < a.length-1; i++) {
		index = a[i].indexOf(':')
		first = a[i].substring(0,index)
		last =  parseFloat(a[i].substring(index+1, a[i].length))
		Object[first] = last
	}
}	
	


// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function ArrayFind(Array, String) {
	for (var i = 0; i < Array.length; i++) {
		if (Array[i] == String) {
			return(i)}}
	return(-1)
}

function FormFind(Array, String) {
	for (var i = 0; i < Array.length; i++) {
		if (Array[i].name == String) {
			return(Array[i])}}
	return(-1)
}

function writeProps(obj) {
  var msg_str   = ""
  
  // build up the contents for the window
  msg_str += "<HTML>"
  msg_str += "<HEAD>"
  msg_str += "<TITLE> Window"
  msg_str += "</TITLE>"
  msg_str += "</HEAD>"
  msg_str += "<BODY>"
          for (var i in obj) {
	msg_str +=  i + " = " + obj[i] + "<br>"}
  msg_str += "</BODY>"
  msg_str += "</HTML>"

    

  props_win = open("", "propsWindow",
    "width=500,height=550,scrollbars=1,resizable=1")

  // write the contents into the window
  props_win.document.open()
  props_win.document.write(msg_str)
  props_win.document.close()
}

function mostPopularUnread() {
	var max = -1
	var winner = -1
       for (var i in Accesses) {
	if ((Accesses[i] > max) &&
	    ((ArrayFind(Visited, i))== -1) &&
	    ((ArrayFind(Abstracts, i)) == -1) &&
	    ((ArrayFind(Considered, i)) == -1) &&
	    (FormFind(document.forms, i) != -1)) {
	max = Accesses[i]
	winner = i
		}
	}
	return(winner)
}

function AcceptableTopic(article) { 
	var a = Subjects[article]
	for (var topic in a) {
		if (Configuration[a[topic]] > 0.5) {return true}}
	return false}





function mostUnreadofTopic(a) {
	var max = -1
	var winner = -1
       for (var i in a) {
	if ((a[i] > max) &&
 	   ((ArrayFind(Visited, i))== -1) &&
	   ((ArrayFind(Abstracts, i)) == -1) &&
	   ((ArrayFind(Considered, i)) == -1) &&
	   (AcceptableTopic(i)) &&
	   (FormFind(document.forms, i) != -1)) {
    	 max = a[i]
 	 winner = i
	}}
	return(winner)
}



function mostUnreadofTopic(a) {
	var max = -1
	var winner = -1
       for (var i in a) {
	if ((a[i] > max) &&
 	   ((ArrayFind(Visited, i))== -1) &&
	   ((ArrayFind(Abstracts, i)) == -1) &&
	   ((ArrayFind(Considered, i)) == -1) &&
	   (AcceptableTopic(i)) &&
	   (FormFind(document.forms, i) != -1)) {
    	 max = a[i]
 	 winner = i
	}}
	return(winner)
}


function mostSimilarUnread(title) {
	var a = Titles
	var index = ""
	var max = -1
	var winner = -1
       for (var i in a) {
	index = title + "_" + i
	if (sim[index]){
		if ((sim[index] > max) &&
	    		((ArrayFind(Visited, i))== -1) &&
	    		((ArrayFind(Abstracts, i)) == -1) &&
	    		((ArrayFind(Considered, i)) == -1) &&
	    		 (AcceptableTopic(i)) &&
	    		 (FormFind(document.forms, i) != -1)) {
				max = sim[index]
				winner = i
				}
		}
	}
	return(winner)
}


function mostAssociated(titles) {
	var title
       for (var i in titles) {
	title = titles[i]
	if ( ((ArrayFind(Visited, title))== -1) &&
	    ((ArrayFind(Abstracts, title)) == -1) &&
	    ((ArrayFind(Considered, title)) == -1) &&
	     (AcceptableTopic(title)) &&
	     (FormFind(document.forms, title) != -1)) {

		return(title)
		}
	}
	return(-1)
  }


var RelatedTo = false
function recommendNew() {
	var max = 0
	var title
	var r
	var winner = false
	RelatedTo = false
       for (var i = 0; document.forms[i].name != Latest; i++) {
	Title = document.forms[i].name
	r = cited(Title, Visited)
	if ((( r && !RelatedTo) ||
	    ((r || !RelatedTo) && (Accesses[Title] > max))) &&
	    ((ArrayFind(Visited, Title))== -1) &&
	    ((ArrayFind(Abstracts, Title)) == -1) &&
	    ((ArrayFind(Considered, Title)) == -1) &&
	    (AcceptableTopic(Title))) {
	
	max = Accesses[Title]
	winner = Title
	RelatedTo = r
		}
	}
	return(winner)
}


function cited(title, Visited) {
	for (var i = 0; i < Visited.length; i++) {
		if (Citations[Visited[i]]) {
		for (var j = 0; j < Citations[Visited[i]].length; j++) {
			if (Citations[Visited[i]][j] == title) {
				return Visited[i]}
		}}
	}
	return false
}

function mostUnreadofTopicCited(a, from) {
	var max = 0
	var winner = -1
	var i = 0
        if (from) {
       for (var j in from) {
	i = from[j]
	if ((a[i] > max) &&
	    ((ArrayFind(Visited, i))== -1) &&
	    ((ArrayFind(Abstracts, i)) == -1) &&
	    ((ArrayFind(Considered, i)) == -1) &&
	    (AcceptableTopic(i)) &&
	    (FormFind(document.forms, i) != -1)) {
	max = a[i]
	winner = i
		}
	}}
	return(winner)
}



function makeCheckbox(n) {
	var s = "<input type =checkbox name =\"" 
	s += n + "\""
	if (Configuration[n] > 0) {s +=  " checked=yes"}
	s += " onclick= \"PublicationFrame.Configuration['" + n + "'] = - PublicationFrame.Configuration['" + n  + "']\""
        s += ">" + ButtonTitle[n] + " "
	return(s)
	}
	         
function setAgents(v) {
	setv(v, "MostFrequent")
	setv(v, "Association")
	setv(v, "Cites")
	setv(v, "Cited")
	setv(v, "Similarity")
	setv(v, "Automatic")
	setv(v, "New")
	setv(v, "Down")
	ConfigureAgents()
}

function setTopics(v) {
	setv(v, "ML")
	setv(v, "Bayes")
	setv(v, "FOL")
	setv(v, "KI")
	setv(v, "Psych")
	setv(v, "Wire")
	setv(v, "Time")
	setv(v, "Med")
	setv(v, "Apps")
	setv(v, "KBS")
	setv(v, "NLP")
	setv(v, "IA")
	setv(v, "NN")
	setv(v, "Th")
	setv(v, "MM")
        ConfigureTopics()
}


function setv(v, c) {
	if (v > 0)
	{if (Configuration[c] < 0) 
		{Configuration[c] = -Configuration[c]}}
	else {if (Configuration[c] > 0) 
		{Configuration[c] = -Configuration[c]}}
	SetCookie("Configuration", objectToString(Configuration), expdate)
}

function ConfigureAgents() {

  if (!UnderWin32p) {
     void alert("Sorry this only works on windows. The defaults aren\'t so bad. You\'ll have to live with them") }
     else {
	

  var msg_str   = ""  
  // build up the contents for the window
  msg_str += "<HTML>"
  msg_str += "<HEAD>"
  msg_str += "<script language=\"JavaScript1.1\">"
  msg_str += "var PublicationFrame = parent.Pubs"
  msg_str += "</scr" + "ipt>"
  msg_str += "<TITLE> Window"
  msg_str += "</TITLE>"
  msg_str += "</HEAD>"
  msg_str += "<BODY   onFocus=\"PublicationFrame.onFocusFunction()\" bgcolor=lightgreen> <font size=-1>"
  msg_str += "<form name=AgentControls>"
  msg_str += "<input type =\"button\" "
  msg_str += "onclick= \"location=\'empty.html\'\" Value=\"Done\">"
  msg_str += "<input type =\"button\" "
  msg_str += "onclick= \"PublicationFrame.setAgents(1)\" Value=\"Check All\">"
  msg_str += "<input type =\"button\" "
  msg_str += "onclick= \"PublicationFrame.setAgents(-1)\" Value=\"UnCheck All\">"
  msg_str +=  makeCheckbox('Automatic')
  msg_str +=  makeCheckbox('New')
  msg_str +=  makeCheckbox('Down')
  msg_str += makeCheckbox('MostFrequent')
  msg_str += makeCheckbox('Association')
  msg_str +=  makeCheckbox('Cites')
  msg_str +=  makeCheckbox('Cited')
  msg_str +=  makeCheckbox('Similarity')



  msg_str += "</form></font>"

  msg_str += "</BODY>"
  msg_str += "</HTML>"
  resetAgent()    
  writeStringToFrame(MessageFrame, msg_str)
}}

function ConfigureTopics() {
  if (!UnderWin32p) {
     void alert("Sorry this only works on windows. The defaults aren\'t so bad. You\'ll have to live with them") }
     else {

  var msg_str   = ""
  
  // build up the contents for the window
  msg_str += "<HTML>"
  msg_str += "<HEAD>"
  msg_str += "<script language=\"JavaScript1.1\">"
  msg_str += "var PublicationFrame = parent.Pubs"
  msg_str += "</scr" + "ipt>"
  msg_str += "<TITLE> Window"
  msg_str += "</TITLE>"
  msg_str += "</HEAD>"
  msg_str += "<BODY   onFocus=\"PublicationFrame.onFocusFunction()\" bgcolor=lightgreen> <font size=-1>"
  msg_str += "<form name=AgentControls>"
  msg_str += "<input type =\"button\" "
  msg_str += "onclick= \"location=\'empty.html\'\" Value=\"Done\">"

  msg_str += "<input type =\"button\" "
  msg_str += "onclick= \"PublicationFrame.setTopics(1)\" Value=\"Check All\">"
  msg_str += "<input type =\"button\" "
  msg_str += "onclick= \"PublicationFrame.setTopics(-1)\" Value=\"UnCheck All\">"

  msg_str +=   makeCheckbox('ML')
  msg_str +=   makeCheckbox('Bayes')
  msg_str +=   makeCheckbox('FOL')
  msg_str +=   makeCheckbox('KI')
  msg_str +=   makeCheckbox('Psych')
  msg_str +=   makeCheckbox('Time')
  msg_str +=   makeCheckbox('Wire')
  msg_str +=   makeCheckbox('Med')
  msg_str +=   makeCheckbox('Apps')
  msg_str +=   makeCheckbox('KBS')
  msg_str +=   makeCheckbox('NLP')
  msg_str +=   makeCheckbox('IA')
  msg_str +=   makeCheckbox('NN')
  msg_str +=   makeCheckbox('Th')
  msg_str +=   makeCheckbox('MM')
  msg_str += "</form></font>"

  msg_str += "</BODY>"
  msg_str += "</HTML>"
  resetAgent()    
  writeStringToFrame(MessageFrame, msg_str)
}}

var maxSuggest = 3
var Suggests = 0
function countSuggest() {
	Suggests += 1
	if (Suggests > maxSuggest)
		{Configuration["Automatic"] = -1}
	else suggest("Automatic")
}

var timeout = null

function resetAgent() {
	if (timeout)
		{clearTimeout(timeout)}
	if (Configuration["Automatic"] == 1)
		{timeout = setTimeout("countSuggest()", 100000)}
}

var cookieClick = 0
function cookie() {
	var msg 
	if (cookieClick > 0) {
		msg = "Click on OK to delete the cookie and not receive intelligent help from the agent, or Cancel to retain this information"
		if (confirm(msg)){
			DeleteCookie("Visited")
			DeleteCookie("Latest")
			DeleteCookie("Abstracts")
			DeleteCookie("Configuration")
			}
		}
	else {
	msg = "This agent uses a cookie to keep track of the abstracts and papers that have been downloaded, the papers that have been recommended, and your settings for the agent\'s configuration.  This information is used to help recommend additional papers to you. "
	msg += "The cookie is stored on your computer and never transmitted on the network or to a server. "
	msg += "Click on the cookie again to delete the cookie."
	alert(msg)
	cookieClick = 1
	}	
		
}




function penalize(title, reason, when) {
	if (reason) {Configuration[reason] *= .875}
	if (when) {Configuration[when] *= .875}
	var Subs = Subjects[title]
	var l = Subs.length
        for (var i = 0; i < l; i++) {
	     Configuration[Subs[i]] *= .875
	}
	SetCookie("Configuration", objectToString(Configuration), expdate)
	LastSuggest = false
}
function reinforce(title, reason, when) {
	if (reason) {Configuration[reason] *= 1.075}
	if (when) {Configuration[when] *= 1.075}
	var Subs = Subjects[title]
	var l = Subs.length
        for (var i = 0; i < l; i++) {
	     Configuration[Subs[i]] *= 1.075
	}
	SetCookie("Configuration", objectToString(Configuration), expdate)
}