//  FormDisplay.js
//  Written:  2001-03-02 by James Alarie <jalarie@umich.edu>
//    http://spruce.flint.umich.edu/~jalarie/

        function FormDisplay(Which,Detail) {
          FD_f1=Which;
          FD_Detail=Detail;
          FD_Len=FD_f1.length;
          FD_Now=new Date();
          
          FD_W=screen.width;
          FD_H=screen.height;
          FD_Opts='scrollbars,resizable';
//          FD_Opts=FD_Opts+',width='+FD_W+',height='+FD_H;  // full-screen
          FD_popup1=window.open('','FormDisplay',FD_Opts);
          
//  header:
          FD_O ='';
          FD_O+='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n';
          FD_O+='  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
          FD_O+='\n';
          FD_O+='<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">\n';
          FD_O+='  <head>\n    <title>Form Display<\/title>\n';
          FD_O+='    <meta http-equiv="Content-Script-Type" content="text\/javascript" \/>\n';
          FD_O+='    <meta http-equiv="Content-Style-Type" content="text\/css" \/>\n';
          FD_O+='    <meta http-equiv="PICS-Label" content=\'(PICS-1.1 "http:\/\/www.classify.org\/safesurf\/" l gen true for "http:\/\/spruce.flint.umich.edu\/~jalarie\/" r (SS~~000 1))\' \/>\n';
          FD_O+='    <meta http-equiv="pics-Label" content=\'(pics-1.1 "http://www.icra.org/pics/vocabularyv03/" l gen true for "http://spruce.flint.umich.edu/~jalarie" r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 0)  gen true for "http://www.spruce.flint.umich.edu/~jalarie" r (n 0 s 0 v 0 l 0 oa 0 ob 0 oc 0 od 0 oe 0 of 0 og 0 oh 0 c 0))\' />\n';
          FD_O+='    <link rel="meta" href="http://spruce.flint.umich.edu/~jalarie/labels.rdf" type="application/rdf+xml" title="ICRA labels" />\n';
          FD_O+='    <link href="style1.css" rel="stylesheet" type="text\/css" \/>\n';
          FD_O+='  <\/head>\n';
            FD_popup1.document.write(FD_O);
          FD_O ='';
          FD_O+='  <body class="body1">\n';
          FD_O+='  <div id="body">\n';
          FD_O+='   <div id="header">\n';
          FD_O+='    <div class="center"><h1>Form Display<\/h1><\/div>\n';
          FD_O+='    &quot;And all things, whatsoever ye shall ask in prayer, believing, ye shall receive.&quot;&nbsp; \n';
          FD_O+='    Matthew&nbsp;21:22.\n';
          FD_O+='    <hr \/><br \/>\n';
          FD_O+='   <\/div>\n';
          FD_O+='   <div id="content">\n';
          FD_O+='    <div class="center">\n';
          FD_O+='      <b>'+FD_Now+'<\/b><br \/><br \/>\n';
            FD_popup1.document.write(FD_O);
//  main form characteristics:
          FD_O ='';
          FD_O+='      <table border="1" cellspacing="2" cellpadding="2" class="table1">\n';
          FD_O+='        <thead>\n';
          FD_O+='          <tr>\n';
          FD_O+='            <th colspan="2">Form Characteristics <\/th>\n';
          FD_O+='          <\/tr>\n';
          FD_O+='          <tr>\n';
          FD_O+='            <th>Name <\/th>\n';
          FD_O+='            <th>Value <\/th>\n';
          FD_O+='          <\/tr>\n';
          FD_O+='        <\/thead>\n';
          FD_O+='        <tbody>\n';
            FD_popup1.document.write(FD_O);
          
          FD_A=new Array(
            'name','length','method','action','enctype','target',
            'id','accept','onsubmit','onreset','accept-charset'
          )
          for (FD_ix1=0; FD_ix1<FD_A.length; FD_ix1++) {
            FD_O ='';
            FD_A1=FD_A[FD_ix1];
            FD_W1=String(Which[FD_A1]).substring(0,1);
            if ((Which[FD_A1]) && (FD_W1 != '<') && (FD_W1 != '[')) {
              FD_O+='          <tr>\n';
              FD_O+='            <td align="left">'+FD_A1+' <\/td>\n';
              FD_O+='            <td align="left">'+Which[FD_A1]+' <\/td>\n';
              FD_O+='          <\/tr>\n';
            }
              FD_popup1.document.write(FD_O);
          }
          FD_O ='';
          FD_O+='        <\/tbody>\n';
          FD_O+='      <\/table>\n';
          FD_O+='      <br \/>\n';
            FD_popup1.document.write(FD_O);
//  fields:
          FD_O ='';
          FD_O+='      <table border="1" cellspacing="2" cellpadding="2" class="table1">\n';
          FD_O+='        <thead>\n';
          FD_O+='          <tr>\n';
          if (FD_Detail) {
            FD_O+='            <th colspan="7">The Form Contains '+FD_Len+' Items <\/th>\n';
          } else {
            FD_O+='            <th colspan="6">The Form Contains '+FD_Len+' Items <\/th>\n';
          }
          FD_O+='          <\/tr>\n';
          FD_O+='          <tr>\n';
          FD_O+='            <th># <\/th>\n';
          FD_O+='            <th>Type <\/th>\n';
          FD_O+='            <th>Field Name <\/th>\n';
          FD_O+='            <th>Field ID <\/th>\n';
          FD_O+='            <th>Value <\/th>\n';
          FD_O+='            <th>Success <\/th>\n';
          if (FD_Detail) {
            FD_O+='            <th>Details <\/th>\n';
          }
          FD_O+='          <\/tr>\n';
          FD_O+='        <\/thead>\n';
          FD_O+='        <tbody>\n';
            FD_popup1.document.write(FD_O);
          for (FD_ix1=0; FD_ix1<FD_Len; FD_ix1++) {
            FD_O ='';
            FD_Item=FD_f1[FD_ix1];
            FD_Type=FD_Item.type;
            FD_Processed='no';
//  Types recognized: checkbox, file, hidden, password, radio, reset, 
//    select-one/multiple, submit, text, textarea.
//  Types not processed: button, image, isindex.
            if (FD_Type == 'checkbox') {            // checkbox
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.checked;
              if (FD_Item.checked) { FD_Success='yes'; } else { FD_Success='no'; }
              FormDisplaySub();
            }
            if (FD_Type == 'file') {                // file
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              FD_Success='yes';
              FormDisplaySub();
            }
            if (FD_Type == 'hidden') {              // hidden
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              FD_Success='yes';
              FormDisplaySub();
            }
            if (FD_Type == 'password') {            // password
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              FD_Success='yes';
              FormDisplaySub();
            }
            if (FD_Type == 'radio') {               // radio
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              if (FD_Item.checked) { FD_Success='yes'; } else { FD_Success='no'; }
              FormDisplaySub();
            }
            if (FD_Type == 'reset') {               // reset
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              FD_Success='no';                      // reset is never successful
              FormDisplaySub();
            }
            if (FD_Type == 'select-one') {          // select-one
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Index=FD_Item.selectedIndex;
              FD_Value=FD_Item.options[FD_Index].value;
              FD_Success='yes';                     // always sucessful
              FormDisplaySub();
            }
            if (FD_Type == 'select-multiple') {     // select-multiple
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Length=FD_Item.length;
              FD_Value='';
              for (var ix2=0; ix2<FD_Length; ix2++) {
                if (FD_Item.options[ix2].selected) {
                  var Val=FD_Item.options[ix2].value;
                  if (!Val) { Val=FD_Item.options[ix2].text; }
                  if (FD_Value) { FD_Value=FD_Value+'\n'+Val; }
                  else          { FD_Value=              Val; }
                }
              }
              if (FD_Value) { FD_Success='yes'; } else { FD_Success='no'; }
              FormDisplaySub();
            }
            if (FD_Type == 'submit') {              // submit
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              if (FD_Item.checked) { FD_Success='yes'; } else { FD_Success='no'; }
              FormDisplaySub();
            }
            if (FD_Type == 'text') {                // text
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              FD_Success='yes';
              FormDisplaySub();
            }
            if (FD_Type == 'textarea') {            // textarea
              FD_Name=FD_Item.name;
              FD_ID=FD_Item.id;
              FD_Value=FD_Item.value;
              FD_Success='yes';
              FormDisplaySub();
            }
            if (FD_Processed == 'no') {             // unprocessed item
              var FDI=FormDisplayEsc();
              FD_O+='          <tr>\n';
              FD_O+='            <td align="right">'+FD_ix1+' <\/td>\n';
              FD_O+='            <td align="left">'+FD_Type+' <\/td>\n';
              if (FD_Detail) {
                FD_O+='            <td align="center" colspan="4">- - not processed - - <\/td>\n';
                FD_O+='            <td align="left">'+FDI+' <\/td>\n';
              } else {
                FD_O+='            <td colspan="4" align="left">'+FDI+' <\/td>\n';
              }
              FD_O+='          <\/tr>\n';
            }
              FD_popup1.document.write(FD_O);
          }
          FD_O ='';
          FD_O+='          <tr class="totals">\n';
          if (FD_Detail) {
            FD_O+='            <td colspan="7" align="center">Only named, successful fields are sent to the server. <\/td>\n';
          } else {
            FD_O+='            <td colspan="6" align="center">Only named, successful fields are sent to the server. <\/td>\n';
          }
          FD_O+='          <\/tr>\n';
          FD_O+='        <\/tbody>\n';
          FD_O+='      <\/table>\n';
          FD_O+='      <br \/>\n';
          FD_O+='      [<a href="javascript:void(0);" onclick="window.print();" title="print">Print<\/a>] \n';
          FD_O+='      [<a href="javascript:void(0);" onclick="window.close();" title="close">Close<\/a>] \n';
          FD_O+='    <\/div><!\-\- center \-\->\n';
          FD_O+='   <\/div>\n';
            FD_popup1.document.write(FD_O);
//  footer:
          FD_O ='';
          FD_O+='   <div id="footer">\n';
          FD_O+='    <br \/><hr \/>\n';
//          FD_O+='    Written on March 2, 2001, by <a href="mailto:jalarie@umich.edu" title="e-mail">James Alarie<\/a>.\n';
          FD_O+='    Written on March 2, 2001, by <a href="jaa_e.htm" title="E-mail / Guestbook">James Alarie<\/a>.\n';
          FD_O+='   <\/div>\n';
          FD_O+='  <\/div>\n';
          FD_O+='  <\/body>\n<\/html>\n';
            FD_popup1.document.write(FD_O);

          FD_popup1.document.close();
//          FD_popup1.window.moveTo(0,0);             // move to top-left corner
          return true;
        } // FormDisplay
        function FormDisplaySub() {
          var S=FD_Success;
          if (S == 'yes') {
            if (FD_Value) {
              FD_Value=String(FD_Value);
              LThan=new RegExp('<','g');
              FD_Value=FD_Value.replace(LThan,'&lt;');
              FD_Value=FD_Value.replace(/\>/g,'&gt;');
              FD_Value=FD_Value.replace(/\"/g,'&quot;');
              FD_Value=FD_Value.replace(/\n/g,'<br \/>');
            }
            else { S='yes - null'; }
            if (!FD_Name)  { S='yes - unnamed'; }
          }
          FD_O+='          <tr>\n';
          FD_O+='            <td align="right" valign="top">'+FD_ix1+' <\/td>\n';
          FD_O+='            <td align="left" valign="top">'+FD_Type+' <\/td>\n';
          FD_O+='            <td align="left" valign="top">'+FD_Name+'&nbsp;<\/td>\n';
          FD_O+='            <td align="left" valign="top">'+FD_ID+'&nbsp;<\/td>\n';
          FD_O+='            <td align="left" valign="top">'+FD_Value+'&nbsp;<\/td>\n';
          FD_O+='            <td align="left" valign="top">'+S+' <\/td>\n';
          if (FD_Detail) {
            var FDI=FormDisplayEsc();
            FD_O+='            <td align="left">'+FDI+' <\/td>\n';
          }
          FD_O+='          <\/tr>\n';
          FD_Processed='yes';
          return true;
        } // FormDisplaySub
        function FormDisplayEsc() {
          var FDI=String(FD_Item);
          LThan=new RegExp('<','g');
          FDI=FDI.replace(LThan,'&lt;');
          FDI=FDI.replace(/\>/g,'&gt;');
          FDI=FDI.replace(/\"/g,'&quot;');
          FDI=FDI.replace(/\n/g,'<br \/>');
          return FDI;
        } // FormDisplayEsc
