Initial add of defaria.com
[clearscm.git] / defaria.com / JavaScript / TableFix.js
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File:        TableFix.js
4 // Description: JavaScript routine to fix an IE bug regarding the user of
5 //              tables in <div>'s that are not flush right
6 // Author:      Andrew@DeFaria.com
7 // Created:     Wed May 12 13:47:39 PDT 2004
8 // Modified:
9 // Language:    JavaScript
10 //
11 // (c) Copyright 2003, Andrew@DeFaria.com, all rights reserved.
12 // 
13 ////////////////////////////////////////////////////////////////////////////////
14 function AdjustTableWidth (table_name, width_percentage, margins) {
15   // This function fixes the problem with IE and tables. When a table
16   // is set to say 100% but is in a div that is not flush with the
17   // left side of the browser window, IE does not take into account
18   // the width of the div on the left. This function must be called
19   // after the close of the div that the table is contained in. It
20   // should also be called in the body tag for the onResize event in
21   // case the browser window is resized.
22
23   // If the browser is not IE and 5 or greater then return
24   alert ("enter AdjustTableWidth");
25   if (navigator.userAgent.indexOf ("MSIE") == -1 ||
26       parseInt (navigator.appVersion) >= 5) {
27     return;
28   } // if
29
30   // If width_percentage was not passed in then set it to 100%
31   if (width_percentage == null || width_percentage == "") {
32     width_percentage = 1;
33   } else {
34     width_percentage = width_percentage / 100;
35   } // if
36
37   // If margins were not set then use 15 pixels
38   if (margins == null || margins == "") {
39     margins = 15;
40   } // if
41
42   // Get table name
43   var table = document.getElementById (table_name);
44
45   if (table == null) {
46     return; // no table, nothing to do!
47   } // if
48
49   // Get the width of the page in the browser
50   var body_width = document.body.clientWidth;
51  
52   alert ("Locating 'leftbar'...");
53   // Get the width of the left portion. Note this is hardcoded to the
54   // value of "leftbar" for the MAPS application
55   var sidebar_width = document.getElementByClass ("leftbar").clientWidth;
56   alert ("got it");
57
58   // Now compute the new table width by subtracting off the sizes of
59   // the sidebar_width and margins then multiply by the
60   // width_percentage
61   table.style.width = 
62     (body_width - sidebar_width - margins) * width_percentage;
63 ;} // AdjustTableWidth