| 1 | /** |
| 2 | * This array is used to remember mark status of rows in browse mode |
| 3 | * |
| 4 | * @copyright © 2005-2006 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 | * (un)Checks checkbox for the row that the current table cell is in |
| 13 | * when it gets clicked. |
| 14 | * |
| 15 | * @param string The (internal) name of the checkbox |
| 16 | * that should be (un)checked |
| 17 | * @param JavaScript event object The JavaScript event associated |
| 18 | * with this mouse click |
| 19 | * @param string The name of the encapsulating form |
| 20 | * @param string The (real) name of the checkbox |
| 21 | * that should be (un)checked |
| 22 | * @param string Any extra JavaScript (that will |
| 23 | * be executed herein if non-empty); |
| 24 | * must be valid JavaScript expression(s) |
| 25 | */ |
| 26 | function row_click(chkboxName, event, formName, checkboxRealName, extra) { |
| 27 | var chkbox = document.getElementById(chkboxName); |
| 28 | if (chkbox) { |
| 29 | // initialize orig_row_color if not defined already |
| 30 | if (!orig_row_colors[chkboxName]) { |
| 31 | orig_row_colors[chkboxName] = chkbox.parentNode.getAttribute('bgcolor'); |
| 32 | if (orig_row_colors[chkboxName].indexOf("clicked_") == 0) |
| 33 | orig_row_colors[chkboxName] = orig_row_colors[chkboxName].substring(8, orig_row_colors[chkboxName].length); |
| 34 | } |
| 35 | chkbox.checked = (chkbox.checked ? false : true); |
| 36 | |
| 37 | if (extra != '') eval(extra); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * Gets the current class of the requested row. This is a browser specific function. |
| 43 | * Code shamelessly ripped from setPointer() below. |
| 44 | */ |
| 45 | function getCSSClass (theRow) |
| 46 | { |
| 47 | var rowClass; |
| 48 | // 3.1 ... with DOM compatible browsers except Opera that does not return |
| 49 | // valid values with "getAttribute" |
| 50 | if (typeof(window.opera) == 'undefined' |
| 51 | && typeof(theRow.getAttribute) != 'undefined' |
| 52 | && theRow.getAttribute('className') ) { |
| 53 | rowClass = theRow.getAttribute('className'); |
| 54 | } |
| 55 | // 3.2 ... with other browsers |
| 56 | else { |
| 57 | rowClass = theRow.className; |
| 58 | } |
| 59 | |
| 60 | return rowClass; |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Sets a new CSS class for the given row. Browser-specific. |
| 65 | */ |
| 66 | function setCSSClass (obj, newClass) { |
| 67 | if (typeof(window.opera) == 'undefined' && typeof(obj.getAttribute) != 'undefined' && obj.getAttribute('className') ) { |
| 68 | obj.setAttribute('className', newClass, 0); |
| 69 | } |
| 70 | else { |
| 71 | obj.className = newClass; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * This function is used to initialize the orig_row_color array so we do not |
| 77 | * need to predefine the entire array |
| 78 | */ |
| 79 | function rowOver(chkboxName) { |
| 80 | var chkbox = document.getElementById(chkboxName); |
| 81 | var rowClass, rowNum, overClass, clickedClass; |
| 82 | if (chkbox) { |
| 83 | if (!orig_row_colors[chkboxName]) { |
| 84 | rowClass = getCSSClass(chkbox.parentNode.parentNode); |
| 85 | if (rowClass.indexOf("clicked_") == 0) |
| 86 | rowClass = rowClass.substring(8, rowClass.length); |
| 87 | orig_row_colors[chkboxName] = rowClass; |
| 88 | } else { |
| 89 | rowClass = orig_row_colors[chkboxName]; |
| 90 | } |
| 91 | rowNum = chkboxName.substring(chkboxName.length - 1, chkboxName.length); |
| 92 | |
| 93 | /* |
| 94 | * The mouseover and clicked CSS classes are always the same name! |
| 95 | */ |
| 96 | overClass = 'mouse_over'; |
| 97 | clickedClass = 'clicked'; |
| 98 | setPointer(chkbox.parentNode.parentNode, rowNum, 'over' , rowClass, overClass, clickedClass); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | * (un)Checks all checkboxes for the message list from a specific form |
| 104 | * when it gets clicked. |
| 105 | * |
| 106 | * @param string the id of the form where all checkboxes should be (un)checked |
| 107 | * @param string the first three characters of target checkboxes, if any |
| 108 | * @param boolean use fancy row coloring when a checkbox is checked |
| 109 | * @param string new color of the checked rows |
| 110 | */ |
| 111 | function toggle_all(formname, name_prefix, fancy) { |
| 112 | var TargetForm = document.getElementById(formname); |
| 113 | var j = 0; |
| 114 | for (var i = 0; i < TargetForm.elements.length; i++) { |
| 115 | if (TargetForm.elements[i].type == 'checkbox' && (name_prefix == '' || TargetForm.elements[i].name.substring(0,3) == name_prefix)) { |
| 116 | if (fancy) { |
| 117 | array_key = TargetForm.elements[i].getAttribute('id'); |
| 118 | // initialize orig_row_color if not defined already |
| 119 | if (!orig_row_colors[array_key]) { |
| 120 | rowClass = getCSSClass(TargetForm.elements[i].parentNode.parentNode); |
| 121 | if (rowClass.indexOf("clicked_") == 0) |
| 122 | rowClass = rowClass.substring(8, rowClass.length); |
| 123 | orig_row_colors[array_key] = rowClass; |
| 124 | } |
| 125 | origClass = orig_row_colors[array_key]; |
| 126 | clickedClass = 'clicked'; |
| 127 | setPointer(TargetForm.elements[i].parentNode.parentNode, j,'click' , origClass, origClass, clickedClass); |
| 128 | j++ |
| 129 | } |
| 130 | TargetForm.elements[i].checked = !(TargetForm.elements[i].checked); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Sets/unsets the pointer and marker in browse mode |
| 137 | * |
| 138 | * @param object theRow the table row |
| 139 | * @param integer theRowNum the row number |
| 140 | * @param string theAction the action calling this script (over, out or click) |
| 141 | * @param string defaultClass the default background CSS class |
| 142 | * @param string mouseoverClass the CSS class to use for mouseover |
| 143 | * @param string clickedClass the CSS class to use for marking a row |
| 144 | * |
| 145 | * @return boolean whether pointer is set or not |
| 146 | */ |
| 147 | function setPointer(theRow, theRowNum, theAction, defaultClass, mouseoverClass, clickedClass) |
| 148 | { |
| 149 | // 1. Pointer and mark feature are disabled or the browser can't get the |
| 150 | // row -> exits |
| 151 | if ((mouseoverClass == '' && clickedClass == '') |
| 152 | || typeof(theRow.className) == 'undefined') { |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | // 2. Verify we can get the current row or exit |
| 157 | if (typeof(document.getElementsByTagName) != 'undefined') { |
| 158 | // We are ok |
| 159 | } |
| 160 | else if (typeof(theRow) != 'undefined') { |
| 161 | // We are ok |
| 162 | } |
| 163 | else { |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | // 3. Gets the current CSS class... |
| 168 | var newClass = null; |
| 169 | var currentClass = getCSSClass(theRow); |
| 170 | if (currentClass.indexOf("clicked_") == 0) |
| 171 | currentClass = 'clicked'; |
| 172 | |
| 173 | // 4. Defines the new class |
| 174 | // 4.1 Current class is the default one |
| 175 | if (currentClass == '' |
| 176 | || currentClass.toLowerCase() == defaultClass.toLowerCase()) { |
| 177 | if (theAction == 'over' && mouseoverClass != '') { |
| 178 | newClass = mouseoverClass; |
| 179 | } |
| 180 | else if (theAction == 'click' && clickedClass != '') { |
| 181 | newClass = clickedClass; |
| 182 | marked_row[theRowNum] = true; |
| 183 | // deactivated onclick marking of the checkbox because it's also executed |
| 184 | // when an action (clicking on the checkbox itself) on a single item is |
| 185 | // performed. Then the checkbox would get deactived, even though we need |
| 186 | // it activated. Maybe there is a way to detect if the row was clicked, |
| 187 | // and not an item therein... |
| 188 | //document.getElementById('msg[' + theRowNum + ']').checked = true; |
| 189 | } |
| 190 | } |
| 191 | // 4.1.2 Current class is the mouseover one |
| 192 | else if (currentClass.toLowerCase() == mouseoverClass.toLowerCase() |
| 193 | && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) { |
| 194 | if (theAction == 'out') { |
| 195 | newClass = defaultClass; |
| 196 | } |
| 197 | else if (theAction == 'click' && clickedClass != '') { |
| 198 | newClass = clickedClass; |
| 199 | marked_row[theRowNum] = true; |
| 200 | //document.getElementById('msg[' + theRowNum + ']').checked = true; |
| 201 | } |
| 202 | } |
| 203 | // 4.1.3 Current color is the clicked one |
| 204 | else if (currentClass.toLowerCase() == clickedClass.toLowerCase()) { |
| 205 | if (theAction == 'click') { |
| 206 | newClass = (mouseoverClass != '') |
| 207 | ? mouseoverClass |
| 208 | : defaultClass; |
| 209 | marked_row[theRowNum] = false; |
| 210 | //document.getElementById('msg[' + theRowNum + ']').checked = false; |
| 211 | } |
| 212 | } // end 4 |
| 213 | |
| 214 | // 5. Sets the new color... |
| 215 | if (newClass) { |
| 216 | setCSSClass(theRow, newClass); |
| 217 | } |
| 218 | |
| 219 | return true; |
| 220 | } // end of the 'setPointer()' function |
| 221 | |
| 222 | function comp_in_new_form(comp_uri, button, myform, iWidth, iHeight) { |
| 223 | comp_uri += "&" + button.name + "=1"; |
| 224 | for ( var i=0; i < myform.elements.length; i++ ) { |
| 225 | if ( myform.elements[i].type == "checkbox" && myform.elements[i].checked ) |
| 226 | comp_uri += "&" + myform.elements[i].name + "=1"; |
| 227 | } |
| 228 | if (!iWidth) iWidth = 640; |
| 229 | if (!iHeight) iHeight = 550; |
| 230 | var sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes"; |
| 231 | var newwin = window.open(comp_uri, "_blank", sArg); |
| 232 | } |
| 233 | |
| 234 | function comp_in_new(comp_uri, iWidth, iHeight) { |
| 235 | if (!iWidth) iWidth = 640; |
| 236 | if (!iHeight) iHeight = 550; |
| 237 | sArg = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,resizable=yes,status=yes"; |
| 238 | var newwin = window.open(comp_uri , "_blank", sArg); |
| 239 | } |
| 240 | |
| 241 | /* |
| 242 | * Reload the read_body screen on sending an mdn receipt |
| 243 | */ |
| 244 | function sendMDN() { |
| 245 | var mdnuri=window.location+'&sendreceipt=1'; |
| 246 | window.location = mdnuri; |
| 247 | } |
| 248 | |
| 249 | var alreadyFocused = false; |
| 250 | function checkForm(smaction) { |
| 251 | |
| 252 | if (alreadyFocused) return; |
| 253 | |
| 254 | /* |
| 255 | * this part is used for setting the focus in the compose screen |
| 256 | */ |
| 257 | if (smaction) { |
| 258 | if (smaction == "select") { |
| 259 | document.forms['compose'].body.select(); |
| 260 | } else if (smaction == "focus") { |
| 261 | document.forms['compose'].body.focus(); |
| 262 | } |
| 263 | } else { |
| 264 | /* |
| 265 | * All other forms that need to set the focus |
| 266 | */ |
| 267 | var f = document.forms.length; |
| 268 | var i = 0; |
| 269 | var pos = -1; |
| 270 | while( pos == -1 && i < f ) { |
| 271 | var e = document.forms[i].elements.length; |
| 272 | var j = 0; |
| 273 | while( pos == -1 && j < e ) { |
| 274 | if ( document.forms[i].elements[j].type == 'text' || document.forms[i].elements[j].type == 'password' ) { |
| 275 | pos = j; |
| 276 | } |
| 277 | j++; |
| 278 | } |
| 279 | i++; |
| 280 | } |
| 281 | if( pos >= 0 ) { |
| 282 | document.forms[i-1].elements[pos].focus(); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | function printThis() |
| 288 | { |
| 289 | parent.frames['right'].focus(); |
| 290 | parent.frames['right'].print(); |
| 291 | } |
| 292 | |
| 293 | /* JS implementation of more/less links in To/CC. Could later be extended |
| 294 | * show/hide other interface items */ |
| 295 | function showhide (item, txtmore, txtless) { |
| 296 | var oTemp=document.getElementById("recpt_tail_" + item); |
| 297 | var oClick=document.getElementById("toggle_" + item); |
| 298 | if (oTemp.style.display=="inline") { |
| 299 | oTemp.style.display="none"; |
| 300 | oClick.innerHTML=txtmore; |
| 301 | } else { |
| 302 | oTemp.style.display="inline"; |
| 303 | oClick.innerHTML=txtless; |
| 304 | } |
| 305 | } |