
/* sccs id = "@(#)varsel.js 32.1.19    02/11/08"; */

function getButtons()
{
   var program = 1; // default
   if ( typeof top.currentProgram != "undefined" )
   {
      program = top.currentProgram;
   }
   var buttons = '';

   if ( program == 1 )  // tables
   {
      buttons += top.RowB;
      buttons += top.ColB;
      buttons += top.ConB;
      buttons += top.FilterB;
   }
   else if ( program == 2 ) // means
   {
      buttons += top.DepB;
      buttons += top.RowB;
      buttons += top.ColB;
      buttons += top.ConB;
      buttons += top.FilterB;
   }
   else if ( program == 3 ) // corrtab
   {
      buttons += top.Var1B;
      buttons += top.Var2B;
      buttons += top.RowB;
      buttons += top.ColB;
      buttons += top.ConB;
      buttons += top.FilterB;
   }
   else if ( program == 4 ) // correl
   {
      buttons += top.VarsCorrelB;
      buttons += top.FilterB;
   }
   else if ( (program == 5) || (program == 6) ) // regress or logit
   {
      buttons += top.RegDepB;
      buttons += top.RegIndepB;
      buttons += top.FilterB;
   }
   else if ( program == 7 ) // listcase
   {
      buttons += top.VarsListcaseB;
      buttons += top.FilterB;
   }
   else if ( program == 8 ) // recode
   {
      buttons += top.RecVar1B;
      buttons += top.RecVar2B;
      buttons += top.RecVar3B;
      buttons += '<br>';
      buttons += top.RecVar4B;
      buttons += top.RecVar5B;
      buttons += top.RecVar6B;
   }
   else if ( program == 9 ) // compute
   {
      buttons += top.CompExprB;
   }
   else if ( program == 21 ) // subset
   {
      buttons += top.SubVarsB;
      buttons += top.FilterB;
   }

   return buttons;
}

function buttonsPromptCellContents()
{
   var contents = '<strong>';
   contents += top.strCopyto;
   contents += ': </strong>';
   contents += '</td>';

   return contents;
}

function fieldButtonsAdd()
{
   var retstring = '';

   var buttons = getButtons();
   if ( buttons.length > 0 )
   {
      var promptcell = '<td id="buttonspromptcell" nowrap>';
      promptcell += buttonsPromptCellContents();

      var buttoncell = '<td id="buttonscell">' + buttons + '</td>';

      var retstring = '<tr>' + promptcell + buttoncell + '</tr>';
   }
   return retstring;
}

function modePromptCellContents()
{
   var contents = '<strong>';
   contents += top.strMode;
   contents += ': </strong>';

   return contents;
}

function modePromptCell()
{
   var cell = '<td id="modepromptcell" nowrap>';
   cell += modePromptCellContents();
   cell += '</td>';

   return cell;
}

function modeOptionsCellContents()
{	
   var contents = '<input type="radio" name="editmode" value="append">';
   contents += top.strAppend;
   contents += '<input type="radio" checked name="editmode" value="replace">';
   contents += top.strReplace;

   return contents;
}

function modeOptionsCell()
{
   cell = '<td id="modeoptionscell" nowrap>';
   cell += modeOptionsCellContents();
   cell += '</td>';

   return cell;
}

function modeAdd()
{
   var program = 1; // default
   if ( typeof top.currentProgram != "undefined" )
   {
      program = top.currentProgram;
   }

   var mode = '';

   if ( (program == 1) || (program == 2) || (program == 3) ) 
   {
      mode += '<tr style="font-size: smaller;">';

      mode += modePromptCell();
      mode += modeOptionsCell();

      mode += '</tr>';
   }
   return mode;	
}

function isBlank( val )
{
   if( (val == null) || (val.length == 0) )
   {
      return true;
   }

   for( var i = 0; i < val.length; i++ )
   {
      var c = val.charAt(i);
      if ((c != " ") && (c != "\n") && (c != "\t") && (c != "\r"))
      {
         return false;
      }
   }
   return true;
}

function sendToNextEmptyField( fieldname, varname )
{
   if ( top.frames["tblform"].document.forms.length > 0 )
   {
      var TForm = top.frames["tblform"].document.forms[0];
      for (i = 0; i < TForm.length; i++)
      {
         var field = TForm.elements[i];

         if ( (field.type == "text") &&
              (field.name == fieldname) &&
              isBlank(field.value) )
         {
            field.focus();
            field.value = varname;
            
            break;
         }
      }
   }
}

function replaceVar( fieldname, varname )
{
   var field = top.frames["tblform"].document.forms[0].elements[fieldname];
   if ( field != null )
   {
      field.focus();
      field.value = varname;
   }
}

function appendVar( fieldname, varname )
{
   var field = top.frames["tblform"].document.forms[0].elements[fieldname];
   if ( field != null )
   {
      field.focus();
      field.value += varname + ' ';
   }
}

function sendVar( fieldname, varname )
{
   var sendname = varname;
   var field;

   // First handle special cases
   if ( fieldname == "var1" )
   {
      field = top.frames["tblform"].document.forms[0].xvar;
   }
   else if ( fieldname == "var2" )
   {
      field = top.frames["tblform"].document.forms[0].yvar;
   }
   else if ( fieldname == "filters" )
   {
      sendname += "()";
      field = top.frames["tblform"].document.forms[0].filters;
   }
   else  // all other cases, where fieldname == element name
   {
      field = top.frames["tblform"].document.forms[0].elements[fieldname];
   }

   if ( document.varSelect.editmode != null &&
        document.varSelect.editmode[0].checked )
   {
      if ( ! isBlank( field.value ) )
      {
         field.focus();
         field.value += " " + sendname;
      }
      else
      {
         field.focus();
         field.value = sendname;
      }
   }
   else
   {
      field.focus();
      field.value = sendname;
   }
}

function searchAdd()
{
   var contents = '';

   if ( top.searchurl != null )
   {
      contents += '<form name="srchform" style="margin: 0; padding: 0;" method=get action=';
      contents += '"javascript:void showSearch(document.srchform.query.value)" '; 
      contents += ' onsubmit="return doCheckLuceneQueryValue(document.srchform.query.value)"';
      contents += '>';

      contents += '<div nowrap ';
      contents += 'style="background-color: #e4ecf6; margin: 0px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px">';

      contents += '<strong>Search:</strong>';
      contents += ' <input type=hidden name="searchtype" value="var">';
      contents += ' <input type="text" id="query" name="query" size="25" maxlength="380">';
      contents += ' <input type="submit" value="Go" onSubmit="return false" >'; 

      contents += '</div>';

      contents += '</form>';
   }
   return contents;
}

