//   get Props.js  
//  (Thanks to _Jumping_Javascript_ by Janice Winsor & Brian Freeman)
//
//  This file contains getProps() and its supporting functions.
//  It can be used to display the properties of an object in 
//  either an html page or an alert dialog.
//
//  getProps() takes 3 agruments and returns a string for display 
//  in either an HTML page or an alert dialog.  How it is formatted 
//  is controlled by the 3rd argument.  Passing in "true" formats 
//  the string for HTML.  "False" formates for an alert dialog.
//
//  The 1st argument is the object you want the properties on.  
//  The 2nd argument is a string you want to represent the object 
//  name in the output.

/*
** Utility functions
*/

//  Generate a new line
//
//  Arguments:
//  html if true, generate an HTML new line.
//
//  Return value:
//    A string representing a new line either in HTML or simply a 
//    string suitable for display in an alert dialog.

function newline(html) {
   var rvalue ="";
  
   if (html) {
     rvalue += "<BR>";
   }
   else { 
      // The Mac requires a carriage return
      if (navigator.appVersion.indexOf("Mac" != -1)) {
         rvalue += "\n\r";
      }
      else {
         rvalue += "\n";
      }
   }
   return rvalue;
}

//  Generate an indent
//
//  Arguments:
//  html if true, generate an HTML indentation.
//
//  Return value:
//    A string representing an indentation either in HTML or  
//    simply a string suitable for display in an alert dialog.

function indent(html) {
   var rvalue ="";
  
   if (html) {
     rvalue += "<DD>";
   }
   else { 
      // The Mac see,s to have problems with tab
      if (navigator.appVersion.indexOf("Mac" != -1)) {
         rvalue += "   ";
      }
      else {
         rvalue += "\t";
      }
   }
   return rvalue;
}


/*
** getProps
*/

//  Get the properties for the given object
//  Arguments:
//     obj      - obtain properties from this object
//     obj_name - a string representing the object name
//     html     - generate the output as html?
//
//  Return value
//     string of the form:
//       object_name.property = "value"
//       object_name.property = "value"
//       (same as above)
//

function getProps(obj, obj_name, html) {
   var rvalue = "";

   rvalue += newline(html);
   rvalue += "The properties of the object ";
   rvalue += obj_name + " are:";
   rvalue += newline(html);

   for (var i in obj) {
     rvalue += indent(html);
     rvalue += obj_name + "." + i;
     rvalue += " = " + obj[i];
     rvalue += newline(html);
   }
   rvalue += newline(html);

   return unescape(rvalue);
}








