phpDocumentor updates
[squirrelmail.git] / templates / default / js / default.js
1 /**
2 * This array is used to remember mark status of rows in browse mode
3 *
4 * @copyright © 2005 The SquirrelMail Project Team
5 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
6 * @version $Id$
7 */
8 var marked_row = new Array;
9 var orig_row_colors = new Array();
10
11
12 /*
13 * (un)Checks checkbox for the row that the current table cell is in
14 * when it gets clicked.
15 *
16 * @param string the name of the checkbox that should be (un)checked
17 */
18 function row_click(chkboxName) {
19 chkbox = document.getElementById(chkboxName);
20 if (chkbox) {
21 // initialize orig_row_color if not defined already
22 if (!orig_row_colors[chkboxName]) {
23 orig_row_colors[chkboxName] = chkbox.parentNode.getAttribute('bgcolor');
24 }
25 chkbox.checked = (chkbox.checked ? false : true);
26 }
27 }
28 /*
29 * This function is used to initialize the orig_row_color array so we do not
30 * need to predefine the entire array
31 */
32 function rowOver(chkboxName, overColor, clickedColor) {
33 chkbox = document.getElementById(chkboxName);
34 if (chkbox) {
35 if (!orig_row_colors[chkboxName]) {
36 bgColor = chkbox.parentNode.getAttribute('bgcolor');
37 orig_row_colors[chkboxName] = bgColor;
38 } else {
39 bgColor = orig_row_colors[chkboxName];
40 }
41 j = chkbox.name.length - 1
42 setPointer(chkbox.parentNode.parentNode, j,'over' , bgColor, overColor, clickedColor);
43 }
44 }
45
46 /*
47 * (un)Checks all checkboxes for the message list from a specific form
48 * when it gets clicked.
49 *
50 * @param string the id of the form where all checkboxes should be (un)checked
51 * @param boolean use fancy row coloring when a checkbox is checked
52 * @param string new color of the checked rows
53 */
54 function toggle_all(formname, fancy, clickedColor) {
55 TargetForm = document.getElementById(formname);
56 j = 0;
57 for (var i = 0; i < TargetForm.elements.length; i++) {
58 if (TargetForm.elements[i].type == 'checkbox' && TargetForm.elements[i].name.substring(0,3) == 'msg') {
59 if (fancy) {
60 array_key = TargetForm.elements[i].getAttribute('id');
61 if (TargetForm.elements[i].checked == false) {
62 // initialize orig_row_color if not defined already
63 if (!orig_row_colors[array_key]) {
64 orig_row_colors[array_key] = TargetForm.elements[i].parentNode.getAttribute('bgcolor');
65 }
66 }
67 origColor = orig_row_colors[array_key];
68 setPointer(TargetForm.elements[i].parentNode.parentNode, j,'click' , origColor, origColor, clickedColor);
69 j++
70 }
71 TargetForm.elements[i].checked = !(TargetForm.elements[i].checked);
72 }
73 }
74 }
75
76 /*
77 * Sets/unsets the pointer and marker in browse mode
78 *
79 * @param object the table row
80 * @param integer the row number
81 * @param string the action calling this script (over, out or click)
82 * @param string the default background color
83 * @param string the color to use for mouseover
84 * @param string the color to use for marking a row
85 *
86 * @return boolean whether pointer is set or not
87 */
88 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
89 {
90 var theCells = null;
91
92 // 1. Pointer and mark feature are disabled or the browser can't get the
93 // row -> exits
94 if ((thePointerColor == '' && theMarkColor == '')
95 || typeof(theRow.style) == 'undefined') {
96 return false;
97 }
98
99 // 2. Gets the current row and exits if the browser can't get it
100 if (typeof(document.getElementsByTagName) != 'undefined') {
101 theCells = theRow.getElementsByTagName('td');
102 }
103 else if (typeof(theRow.cells) != 'undefined') {
104 theCells = theRow.cells;
105 }
106 else {
107 return false;
108 }
109
110 // 3. Gets the current color...
111 var rowCellsCnt = theCells.length;
112 var domDetect = null;
113 var currentColor = null;
114 var newColor = null;
115 // 3.1 ... with DOM compatible browsers except Opera that does not return
116 // valid values with "getAttribute"
117 if (typeof(window.opera) == 'undefined'
118 && typeof(theCells[0].getAttribute) != 'undefined') {
119 currentColor = theCells[0].getAttribute('bgcolor');
120 domDetect = true;
121 }
122 // 3.2 ... with other browsers
123 else {
124 currentColor = theCells[0].style.backgroundColor;
125 domDetect = false;
126 } // end 3
127
128 // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
129 if (currentColor.indexOf("rgb") >= 0)
130 {
131 var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
132 currentColor.indexOf(')'));
133 var rgbValues = rgbStr.split(",");
134 currentColor = "#";
135 var hexChars = "0123456789ABCDEF";
136 for (var i = 0; i < 3; i++)
137 {
138 var v = rgbValues[i].valueOf();
139 currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
140 }
141 }
142
143 // 4. Defines the new color
144 // 4.1 Current color is the default one
145 if (currentColor == ''
146 || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
147 if (theAction == 'over' && thePointerColor != '') {
148 newColor = thePointerColor;
149 }
150 else if (theAction == 'click' && theMarkColor != '') {
151 newColor = theMarkColor;
152 marked_row[theRowNum] = true;
153 // deactivated onclick marking of the checkbox because it's also executed
154 // when an action (clicking on the checkbox itself) on a single item is
155 // performed. Then the checkbox would get deactived, even though we need
156 // it activated. Maybe there is a way to detect if the row was clicked,
157 // and not an item therein...
158 //document.getElementById('msg[' + theRowNum + ']').checked = true;
159 }
160 }
161 // 4.1.2 Current color is the pointer one
162 else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
163 && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
164 if (theAction == 'out') {
165 newColor = theDefaultColor;
166 }
167 else if (theAction == 'click' && theMarkColor != '') {
168 newColor = theMarkColor;
169 marked_row[theRowNum] = true;
170 //document.getElementById('msg[' + theRowNum + ']').checked = true;
171 }
172 }
173 // 4.1.3 Current color is the marker one
174 else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
175 if (theAction == 'click') {
176 newColor = (thePointerColor != '')
177 ? thePointerColor
178 : theDefaultColor;
179 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
180 ? true
181 : null;
182 //document.getElementById('msg[' + theRowNum + ']').checked = false;
183 }
184 } // end 4
185
186 // 5. Sets the new color...
187 if (newColor) {
188 var c = null;
189 // 5.1 ... with DOM compatible browsers except Opera
190 if (domDetect) {
191 for (c = 0; c < rowCellsCnt; c++) {
192 theCells[c].setAttribute('bgcolor', newColor, 0);
193 } // end for
194 }
195 // 5.2 ... with other browsers
196 else {
197 for (c = 0; c < rowCellsCnt; c++) {
198 theCells[c].style.backgroundColor = newColor;
199 }
200 }
201 } // end 5
202
203 return true;
204 } // end of the 'setPointer()' function
205
206 function comp_in_new_form(comp_uri, button, myform, iWidth, iHeight) {
207 comp_uri += "&" + button.name + "=1";
208 for ( var i=0; i < myform.elements.length; i++ ) {
209 if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked )
210 comp_uri += "&" + myform.elements[i].name + "=1";
211 }
212 if (!iWidth) iWidth = 640;
213 if (!iHeight) iHeight = 550;
214 sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes";
215 var newwin = window.open(comp_uri, "_blank", sArg);
216 }
217
218 function comp_in_new(comp_uri, iWidth, iHeight) {
219 if (!iWidth) iWidth = 640;
220 if (!iHeight) iHeight = 550;
221 sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes";
222 var newwin = window.open(comp_uri , "_blank", sArg);
223 }
224
225 /*
226 * Reload the read_body screen on sending an mdn receipt
227 */
228 function sendMDN() {
229 mdnuri=window.location+'&sendreceipt=1';
230 var newwin = window.open(mdnuri,'right');
231 }
232
233 var alreadyFocused = false;
234 function checkForm(smaction) {
235
236 if (alreadyFocused) return;
237
238 /*
239 * this part is used for setting the focus in the compose screen
240 */
241 if (smaction) {
242 if (smaction == "select") {
243 document.forms['compose'].body.select();
244 } else if (smaction == "focus") {
245 document.forms['compose'].body.focus();
246 }
247 } else {
248 /*
249 * All other forms that need to set the focus
250 */
251 var f = document.forms.length;
252 var i = 0;
253 var pos = -1;
254 while( pos == -1 && i < f ) {
255 var e = document.forms[i].elements.length;
256 var j = 0;
257 while( pos == -1 && j < e ) {
258 if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' ) {
259 pos = j;
260 }
261 j++;
262 }
263 i++;
264 }
265 if( pos >= 0 ) {
266 document.forms[i-1].elements[pos].focus();
267 }
268 }
269 }