Initial commit
[clearscm.git] / maps / JavaScript / MAPSUtils.js
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File:        $RCSFile$
4 // Revision:    $Revision: 1.1 $
5 // Description: JavaScript routine to fix an IE bug regarding the user of
6 //              tables in <div>'s that are not flush right
7 // Author:      Andrew@DeFaria.com
8 // Created:     Wed May 12 13:47:39 PDT 2004
9 // Modified:    $Date: 2013/06/12 14:05:47 $
10 // Language:    JavaScript
11 //
12 // (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 //
14 ////////////////////////////////////////////////////////////////////////////////
15 function AdjustTableWidth (table_name, width_percentage, margins) {
16   // This function fixes the problem with IE and tables. When a table
17   // is set to say 100% but is in a div that is not flush with the
18   // left side of the browser window, IE does not take into account
19   // the width of the div on the left. This function must be called
20   // after the close of the div that the table is contained in. It
21   // should also be called in the body tag for the onResize event in
22   // case the browser window is resized.
23
24   // If the browser is not IE and 5 or greater then return
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 == "" || width_percentage == null) {
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 == "" || margins == null) {
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   // Get the width of the left portion. Note this is hardcoded to the
53   // value of "leftbar" for the MAPS application
54   var sidebar_width = document.getElementById ("leftbar").clientWidth;
55
56   // Now compute the new table width by subtracting off the sizes of
57   // the sidebar_width and margins then multiply by the
58   // width_percentage
59   table.style.width = 
60     (body_width - sidebar_width - margins) * width_percentage;
61 ;} // AdjustTableWidth