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