
// Initialise the publications list

if (recent) {
   for (var i=0; i<recent.length; i++) {
     selectedById[recent[i]] = 1;
   }
 }

// No longer need to display details in js
// displayDetails();


// *** Updated version...
 if (mode != "publish") {
   display();
 }


 if (!readonly) { // publist && publist.length > 0) {
   document.getElementById('selectid').style.display='block';
   // document.getElementById('deletespan').style.display='inline';
 }

 if (mode != "publish") {
   editControls();
 }

function initDisplay() {
  updateTags();
  updateAuthors();
  countSelected();
}

setTimeout(initDisplay, 10);
 
 var fcount = 0;
 var cb = false;
 var prevexp = false;
 var prevvalid = false;
 var prevpublink = false;
 var prevuptodate = uptodate;
 
 function updateStatus(exp, valid, publink, uptodate) {
   // alert("updatestat cb "+uptodate);
   if (exp != prevexp || valid != prevvalid || publink != prevpublink || uptodate != prevuptodate) {

	 var pubimglink = document.getElementById("publishimgid");
	 var pubtxtlink = document.getElementById("publishtxtid");
	 var pubimg = document.getElementById("publishid");

     if (uptodate) {
       document.getElementById('uptodate').style.display = "block";
       document.getElementById('outofdate').style.display = "none";

	   pubimg.src = rootpath + "publish.png";
	   pubtxtlink.style.color = "";
	   pubimglink.title = "Publish your list on the web";
	   pubtxtlink.title = "Publish your list on the web";
     }
     else {
       document.getElementById('uptodate').style.display = "none";
       document.getElementById('outofdate').style.display = "block";
	   
	   pubimg.src = rootpath + "publish-green.png";
	   pubtxtlink.style.color = "green";
	   pubimglink.title = "Latest edits not yet published - publish now";
	   pubtxtlink.title = "Latest edits not yet published - publish now";
     }
     prevexp = exp;
     prevvalid = valid;
     prevpublink = publink;
     prevuptodate = uptodate;
   }
   cb = false;
 }

 var accountinfoid = -1;
 function focusCheck() {
   fcount ++;
   if (accountinfoid==-1) {
     accountinfoid = document.getElementById("accountinfo");
   }
   if (accountinfoid) {
     //alert("doing focus check");
     var fcount = new Date().getTime();
     var txt = fetchURL("ping.php?u="+userid+"&f="+fcount);
     eval(txt);
   }
 }
 function focusCheckCb() {
   if (!cb) {
     cb = setTimeout(focusCheck, 1000);
   }
 }

window.onfocus = focusCheckCb;

 // Check if logged in... 
 function addEditLink() {
   var txt = fetchURL(rootpath+"php/loginping.php?f="+fcount);
   // alert("got "+txt);
   var bits = txt.split(" ");
   if (bits[0] == "OK") {
     if (bits[1] == userid) {
       document.getElementById("editlink").innerHTML = "<a style='text-decoration:none; color:#d0d0d0' href='"+rootpath+"php/publist.php' title='You are logged on as "+userid+"'>[edit]</a>";
     }
   }
 }

 if (mode=='publish') {
   setTimeout(addEditLink, 50);
 }

