// procs used by sectionPlus.htm
//=================

function changeNameDisplay(athis) {
alert(athis);
return 1;
}

//=====================================
// toggle display of a div. If no argument, div is 'actionHistory'
function toggleDisplay(aa,todo,dohow) {
var a,ia,mm;
  if (arguments.length<1) aa='actionHistory';
  if (arguments.length<2) todo=-1 ;
  if (arguments.length<3) dohow='block' ;
  aa=getWord(aa);

 for (var mm=0;mm<aa.length;mm++) {
  a=aa[mm];

  var ia=document.getElementById(a);
  if (!ia) alert('no such id: '+a);
  if (typeof(toggleDisplayStatus[a])=='undefined') toggleDisplayStatus[a]=0;  // assume start undisplayed

  if (todo==-1) {                               // not explicit. Lookup in global array
      if (toggleDisplayStatus[a]==0) {                  // toggle!
           todo=1 ;     
      } else {
          todo=0;
      }
  }
  toggleDisplayStatus[a]=todo ;
  if (todo==0) {                             
         ia.style.display='none' ;
   } else {
         ia.style.display=dohow ;
   }

  }
  return false ;
}

// =======================
// shows a list of currently defined instruments (in a div)
function showInstList(amess) {
var atable,m,mm,tt,aname,wasproj,aproj,aproj0;
var instList2=[];
var projList={};

if (arguments.length<1) amess='';

if (typeof(instList)=='undefined') {
   updateStatus('Wait a moment for list of instruments to load ... ');
   return 0;
}
atable='<b>List of currently available instruments...</b>';
atable=atable+'<table border="1">';

// parse out projects and names from list of instrument files
for (m=0 ;m<instList.length;m++) {
  instList2[m]=[];
  ainst=strip(instList[m]);
  instList2[m]=extractProjectName(ainst)
  if (instList2[m][1]!=='') projList[instList2[m][1]]=1;
}
wasproj='';
mct=0;
//for (m=0 ;m<instList.length;m=m+6) {
for (m=0 ;m<instList.length;m++) {
  mct++;
  ainst=strip(instList[m]);
  aname=instList2[m][0];
  aproj=instList2[m][1];

  if (mct==7 || aproj!==wasproj) {
        atable=atable+'</tr> ';
        mct=1;
        wasproj=aproj;
  }
  aproj0=aproj;
  if (aproj0=='') aproj0='(none)';
  if (mct==1) atable=atable+'<tr><td style="background-color:#dedede"><tt>'+'<a title="Click to use this project" href="#" onClick="writeTo1wordB(\''+aproj+'\'); return false">'+aproj0+'</a></tt> ';

  tt='<a href="#" title="click to chose this instrument" onClick="writeTo1word(\''+ainst+'\',\''+amess+'\'); return false">'+aname+'</a> ';
  atable=atable+'<td>'+tt+'</td>';
}
atable=atable+'</tr> \n ';
atable=atable+'</table> ';


dd=document.getElementById('instListShow') ;  
dd.innerHTML=atable;
toggleDisplay('instListShow',1);
return 1 ;


}

//==========
function writeTo1word(aword,amess) { 
 var ii,uu ;
  if (arguments.length<2) amess='Click to create section+: '; 
 
 ii=document.getElementById("afterSelecting" );
 uu=makeProjName(aword);
 ii.value=amess+uu ;

 ii=document.getElementById('existName');
 if (ii) {
     uu=extractProjectName(aword);
     ii.value=uu[0] ;
     writeTo1wordB(uu[1]) ;
  }
 return 1;
}

//==========
function writeTo1wordB(awordb) { 
 var ii ;
 ii=document.getElementById('existProject');
 if (ii) ii.value=awordb ;
return 1;
}


//==================
// update the status area 
function updateStatus(amessage,ialert) {
if (arguments.length<2) ialert=0;
 var ici;

   ici=document.getElementById('statusRecent');  
   if (ici) ici.innerHTML=amessage ;

   ici=document.getElementById('statusCount');  
   if (ici)   ici.innerHTML=parseInt(ici.innerHTML)+1 ;


   ici=document.getElementById('actionHistory');  
   ici.innerHTML=ici.innerHTML+'<div class="history1">'+amessage+'</div> \n ';

   return 1;
}

//=====================================
// add something to create results
function addActionHistory(header,content,includeTime) {
var ia,afoo;
  if (arguments.length<2) content='';
  if (arguments.length<3) includeTime=0;

  ia=document.getElementById('actionHistory');

  if (!ia) return 1 ;           // no actionHistory, so don't bother writing info there

  afoo='';
  if (includeTime==1)  afoo='<div class="resultsT">'+ svy_currentTime(2,2)+'</div> /n ';
  afoo=afoo+'\n <div class="results0">'+header+'</div> \n ';
  if (content!=='')   afoo=afoo+' <div class="results1">'+content+'</div> \n ';

  ia.innerHTML=ia.innerHTML+'\n '+afoo ;
  return 1 ;
}

//=====================================
// toggle display of a div. If no argument, div is 'actionHistory'
function toggleDisplay(aa,todo,dohow) {
var a,ia,mm;
  if (arguments.length<1) aa='actionHistory';
  if (arguments.length<2) todo=-1 ;
  if (arguments.length<3) dohow='block' ;
  aa=getWord(aa);

 for (var mm=0;mm<aa.length;mm++) {
  a=aa[mm];

  var ia=document.getElementById(a);
  if (!ia) alert('no such id: '+a);
  if (typeof(toggleDisplayStatus[a])=='undefined') toggleDisplayStatus[a]=0;  // assume start undisplayed

  if (todo==-1) {                               // not explicit. Lookup in global array
      if (toggleDisplayStatus[a]==0) {                  // toggle!
           todo=1 ;     
      } else {
          todo=0;
      }
  }
  toggleDisplayStatus[a]=todo ;
  if (todo==0) {                             
         ia.style.display='none' ;
   } else {
         ia.style.display=dohow ;
   }

  }
  return false ;
}

