<!-- Begin

function open_window (file,width,height,toolbar) {
  // note: toolbar = yes to allow printing of pop-up window
  if (!toolbar) { toolbar = "no"; }  
  winopt = "toolbar=" + toolbar + ",location=no,directories=no,menubar=yes,";
  winopt += "resizable=no,scrollbars=yes";
  if (width && height) { winopt += ",width=" + width + ",height=" + height; }
  newWin=window.open(file,"dummy",winopt);
}

function required_fields(which) {
  // checks if all required fields are filled in
  // do not change the rest of this function
  // adapted from script by wsabstract.com posted at 
  // The JavaScript Source!! http://javascript.internet.com

  var pass = true;
  var msg = "Please make sure that \n";
  var num = 0; 
 
  if (document.images) {
    for (i="0"; i<which.length; i++) {
      var tempobj=which.elements[i];
      for (j = 0; j < required.length; j++) {
        if (tempobj.name==required[j]) {
          if (((tempobj.type=="password" || tempobj.type=="text" ||
            tempobj.type=="textarea")&&tempobj.value=='') ||
            (tempobj.type.toString().charAt(0)=="s" && 
             tempobj.selectedIndex=="0")) {
            pass=false;
            num += 1;
            msg += "  * " + required_text[j] + "\n";
          }
        } 
      }
    }
  }  
 
  if (!pass) {
    if (num > 1) { msg += "are properly completed.\n"; }
    else { msg += "is properly completed.\n"; }
    alert(msg);
    return false;
  }
  else { return true; }
}

function performance_measures(form) {
  var msg = "Please provide information for ";
  msg += "at least one of the preformance measures.\n";
  var pm1 = eval('document.' + form + '.performance_measure1').value;
  var pm2 = eval('document.' + form + '.performance_measure2').value;
  var pm3 = eval('document.' + form + '.performance_measure3').value;
  if (!pm1 && !pm2 && !pm3) { alert(msg); return false; }
  else { return true; }
}

function LimitAttach(fig,file) {
  allowSubmit = false;
  if (!file) { return false; }
  while (file.indexOf("\\") != -1)
    file = file.slice(file.indexOf("\\") + 1);
    ext = file.slice(file.indexOf(".")).toLowerCase();
    for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) { allowSubmit = true; break; }
  }
  if (allowSubmit) { return true; }
  else {
    alert("Only figures with these extensions:\n  " 
    + (extArray.join("\n  ")) + "\nmay be included in this report.\n"
    + "\n\nPlease select a new file for " + fig + " and resubmit.");
    return false;
  }
}

function showFig(fig,file,legend) {
  var winopt, html;
  html = "<HTML>\n<HEAD>\n";
  html += "<TITLE>" + fig + "</TITLE>\n";
  html += "</HEAD>\n";
  html += "<BODY BGCOLOR=\"#FFFFFF\" onblur=window.close()>\n";
  html += "<CENTER>\n";
  html += "<IMG SRC=\"file://" + file + "\" ALT=\"" + fig + "\">\n";
  html += "<H3>\n" + fig + ". " + legend + "\n<H3>\n";
  html += "<FORM>\n";
  html += "<INPUT TYPE=\"Button\" value=\"Close Window\" ";
  html += "onClick=\"window.close();\"><BR>\n";
  html += "</FORM>\n";
  html += "</CENTER>\n";
  html += "</BODY>\n";
  html += "</HTML>\n";
  // note: toolbar = yes to allow printing of pop-up window
  winopt = "toolbar=no,location=no,directories=no,menubar=no,resizable=no,";
  winopt += "scrollbars=yes";
  newWin=window.open("","dummy",winopt);
  newWin.document.write(html);
  newWin.document.close();
  return;
}
 
function getFile(fig,file,legend) {
  if (!file) {
    alert("You did not select a file for " + fig + ".  \n"  
    + "\n\nPlease use the 'Browse...' button to select a file for " 
    + fig + " and resubmit.");
    return;
  }
  if (!legend) {
    alert("You did not provide a legend for " + fig + ".  \n"  
    + "\n\nPlease provide this information and resubmit.");
    return;
  }

  var flag = LimitAttach(fig,file);
  if (flag) { 
    //window.location= file;
    //window.open(file,'fig');
    showFig(fig,file,legend);
  }
}

function countit(field, countfield, blurflag, degreefield) {
  // blurflag - spacing between lines - done onBlue
  var formcontent = field.value; 
  var  nn = 0;
  var lines = new Array(); 
  var txt = '';
  // need to step through string character by character since
  // MSIE only splits at first occurance of expression using
  // formcontent = formcontent.split("\n");
  for (var i = 0; i < formcontent.length; i++) {  
    var ch = formcontent.substring(i, i + 1); 
    if (ch == '\r' || ch == '\n') {
       nn++; ch = '';
    } 
    else { 
      if (!lines[nn]) { lines[nn] = ch; }
      else { lines[nn] += ch; } 
    }
  }
  // set line spacing - default is 1, must use 2 for double
  if (blurflag == '2') { var ll = '\n\n'; }
  else { ll = '\n'; }
  nn = 0;
  for (var pp in lines) { // get rid of just returns (\r or \n)
    if (lines[pp]) { 
      txt += lines[pp];
      if (pp < lines.length - 1) { txt += ll; }
      nn++;
    }
  }
  countfield.value = nn;
  if (blurflag) { // called by onBlur
    field.value = txt;
  }
  if (degreefield) { 
    nn = 0;
    for (var pp in lines) {  
      formcontent = lines[pp].toLowerCase(); 
      // check for degree awarde to increment (leave of final d to get onKeyUp/Down to increment)
      formcontent = formcontent.split("degree awarde");
      if (formcontent[1]) { nn++; }
    }
    degreefield.value = nn;
  }
}
//  End -->

