Fix AJAX :
[platal.git] / htdocs / javascript / flyspray.js
1 /***************************************************************************
2 * Copyright (C) 2003-2006 Polytechnique.org *
3 * http://opensource.polytechnique.org/ *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., *
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 ***************************************************************************/
20
21 function send_bug() {
22 var h = windowHeight();
23 var y = getScrollY();
24 y += (h - 470) /2;
25 document.getElementById('flyspray_report').style.display = 'block';
26 document.getElementById('flyspray_report').style.top = y+'px';
27 return false;
28 }
29
30 function getScrollY() {
31 var scrOfX = 0, scrOfY = 0;
32 if( typeof( window.pageYOffset ) == 'number' ) {
33 //Netscape compliant
34 scrOfY = window.pageYOffset;
35 } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
36 //DOM compliant
37 scrOfY = document.body.scrollTop;
38 } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
39 //IE6 standards compliant mode
40 scrOfY = document.documentElement.scrollTop;
41 }
42 return scrOfY;
43 }
44 function windowHeight() {
45 if( typeof( window.innerWidth ) == 'number' ) {
46 //Non-IE
47 return window.innerHeight;
48 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
49 return document.documentElement.clientHeight;
50 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
51 //IE 4 compatible
52 return document.body.clientHeight;
53 }
54 return 0;
55 }
56
57 function close_bug(f,send) {
58 var detail = document.getElementById('flyspray_detail');
59 detail.value = utf8(detail.value);
60 var title = document.getElementById('flyspray_title');
61 title.value = utf8(title.value);
62 if (send) {
63 f.target = '_blank';
64 f.submit();
65 }
66 f.reset();
67 document.getElementById('flyspray_report').style.display = 'none';
68 }
69
70 function utf8(isotext)
71 {
72 var utf8text = "";
73 for ( i=0; i<isotext.length; i++ )
74 {
75 unicodchar = isotext.charCodeAt(i);
76
77 if(unicodchar < 128){
78 utf8text += String.fromCharCode(unicodchar);
79 } else if(unicodchar < 0x800) {
80 var val1 = 0xC0 + (unicodchar & 0x7C0) / 0x40; // 0011111000000
81 var val2 = 0x80 + (unicodchar & 0x3F); // 0000000111111
82 utf8text += String.fromCharCode(val1,val2);
83 } else if(unicodchar < 0x10000) {
84 var val1 = 0xE0 + (unicodchar & 0xF000) / 0x1000; // 001111000000000000
85 var val2 = 0x80 + (unicodchar & 0xFC0) / 0x40; // 000000111111000000
86 var val3 = 0x80 + (unicodchar & 0x3F); // 000000000000111111
87 utf8text += String.fromCharCode(val1,val2, val3);
88 } else if(unicodchar < 0x200000){
89 var val4 = 0x80 + (unicodchar & 0x1C0000) / 0x40000;// 00111000000000000000000
90 var val2 = 0x80 + (unicodchar & 0x3F000) / 0x1000; // 00000111111000000000000
91 var val3 = 0x80 + (unicodchar & 0xFC0) / 0x40; // 00000000000111111000000
92 var val4 = 0x80 + (unicodchar & 0x3F); // 00000000000000000111111
93 utf8text += String.fromCharCode(val1,val2, val3, val4);
94 }
95 }
96 return utf8text;
97 }