<html>
  <head>

<SCRIPT LANGUAGE="JavaScript1.2">
// Init main window
Sash.WindowApp.MainWindow.TitleText =
 "Folding at Home Wrapper";
Sash.WindowApp.MainWindow.Visible = true;
var FahPath="/home/foldathome/downloads";

// Action triggered by the click of Choose button
// on 1st window
// Pick a folder in the local file system
// Requires: Dependency FileSystem (to be
// specified in WDF Editor)

function chooseDirBtn(str) {
  var dirBox = document.getElementById("dirBox");
  FahPath = Sash.Linux.FileDialog(dirBox.value);
  return true;
}


// Action triggered by click of "Check Process"
// button in 1st window.
function chkProcBtn(str) { 
  // Name of temp file
  var TmpRes = Sash.FileSystem.GetTempName();
  // Puts a list of FAH processes in temp file
  var cmdtoexec =
    "ps -e | grep -i fah | grep -v grep > "
      + TmpRes;
  var command = new Array("sh", "-c", cmdtoexec);
  Sash.Core.Process.Create(command);
  // If temp file is empty, FAH is not running
  var f =  new Sash.FileSystem.File(TmpRes);
  var sz = f.Size;
  if (sz > 0) { // FAH proc not running  
    // Asking whether to start the process
    var ans = 
    Sash.Core.UI.MessageBox(
      "The FAH process is not running. Start it?",
      "Process startup", Sash.Core.UI.MB_YESNO);
    if (ans == IDYES) {  // Launch the process
      cmdtoexec = FahPath +
        "/FAH3Console-Linux.exe";
      command = new Array("sh", "-c", cmdtoexec);
      Sash.Core.Process.Create(command);
    } // end if ans
  } else { // FAH proc already running
    Sash.Core.UI.MessageBox(
       "FAH process is already running",
       "Info", Sash.Core.UI.MB_OK);
  }  // end if sz

  // Remove temp file
  f.Delete(false);
  return true;
} // end function


// Action triggered by the click of "View Status
// button in 1st window.
function viewStatBtn(str) { 
  Sash.Core.ExecDefaultWebBrowser("file://"
    + FahPath + "/MyFolding.html");
  return true;
} // end function
</SCRIPT>

<body>
<!-- Actual HTMLshown by browser -->
<P>Enter the directory where FAH is installed:

  <SCRIPT>document.write(
    "<input size=60 id='dirBox' value='" + FahPath
    + "'>");
  </SCRIPT>
<input type="submit" value="Choose..."
  onclick="chooseDirBtn()">
 <BR>
 <CENTER>
<input type="submit" value=" Check Process "
  onclick="chkProcBtn()">
<input type="submit" value=" View Status "
  onclick="viewStatBtn()">
 </CENTER>
</body>
</html>