File: form.js

package info (click to toggle)
virtuoso-opensource 7.2.5.1%2Bdfsg1-0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 285,240 kB
  • sloc: ansic: 641,220; sql: 490,413; xml: 269,570; java: 83,893; javascript: 79,900; cpp: 36,927; sh: 31,653; cs: 25,702; php: 12,690; yacc: 10,227; lex: 7,601; makefile: 7,129; jsp: 4,523; awk: 1,697; perl: 1,013; ruby: 1,003; python: 326
file content (364 lines) | stat: -rw-r--r-- 8,725 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
 *  $Id$
 *
 *  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 *  project.
 *
 *  Copyright (C) 1998-2018 OpenLink Software
 *
 *  This project is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; only version 2 of the License, dated June 1991.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

var sflag = false;
var def_btn = null;

function checkPageLeaveExt (form, func)
{
  try
  {
    func ();
  }
  catch (e) 
  {
  }
  return checkPageLeave (form);
}

function checkPageLeave (form)
{
  var dirty = false;
  var ret = true;
  var btn = def_btn;
  var i;
  if (sflag == true || btn == null || btn == '' || form.__submit_func.value != '' || form.__event_initiator.value != '')
    return true;
  for (i = 0; i < form.elements.length; i++)
    {
      if (form.elements[i] != null)
        {
          var ctrl = form.elements[i];
          if (!ctrl || !ctrl.type)
            continue;
          if (ctrl.type.indexOf ('select') != -1)
            {
              var j, selections = 0;
    	  for (j = 0; j < ctrl.length; j ++)
    	    {
                  var opt = ctrl.options[j];
    	      if (opt.defaultSelected == true)
    		selections ++;
                  if (opt.defaultSelected != opt.selected)
                    {
                      dirty = true;
                    }
            }
    	  if (selections == 0 && ctrl.selectedIndex == 0)
    	    dirty = false;
    	  if (dirty == true)
    	    {
    	      //alert (ctrl.name+' value=['+ctrl.value+'] default=['+ctrl.defaultValue+']');
    	      break;
    	    }
            }
          else if ((ctrl.type.indexOf ('text') != -1 || ctrl.type == 'password') && ctrl.defaultValue != ctrl.value)
            {
    	      //alert (ctrl.name+' value=['+ctrl.value+'] default=['+ctrl.defaultValue+']');
              dirty = true;
       	      break;
            }
          else if ((ctrl.type == 'checkbox' || ctrl.type == 'radio') &&
    	  ctrl.defaultChecked != ctrl.checked
    	)
            {
    	  //alert (ctrl.name+' value=['+ctrl.checked+'] default=['+ctrl.defaultChecked+']');
              dirty = true;
              break;
            }
        }
    }
  if (dirty == true)
    {
      ret =
confirm ('You are about to leave the page, but there is changed data which is not saved.\r\nDo you wish to save changes ?');
        if (ret == true)
          {
            form.__submit_func.value = '__submit__';
            form.__submit_func.name = btn;
            form.submit ();
          }
    }
   return ret;
}

function getFileName(form, from, to)
{
  var S = from.value;
  var N;
  var fname;
  if (S.lastIndexOf('\\') > 0)
    N = S.lastIndexOf('\\')+1;
  else
    N = S.lastIndexOf('/')+1;
  fname = S.substr(N,S.length);
  to.value = fname;
}


function checkSelected (form, txt, selectionMsq) {
  if ((form != null) && (txt != null)) {
    for (var i = 0; i < form.elements.length; i++) {
      var obj = form.elements[i];
      if (obj != null && obj.type == "checkbox" && obj.name.indexOf (txt) != -1 && obj.checked)
        return true;
    }
    if (selectionMsq != null)
      alert(selectionMsq);
    return false;
  }
  return true;
}


//Bookmark on del.icio.us
function dbt_bookmark(title, tags) {
  //URL of this document
  var loc=location.href;
  //Strip out any anchors
  var apos=loc.indexOf('&sid');
  loc=(apos>0?loc.substring(0,apos):loc);
  //Redirect to del.icio.us
  var ref = 'http://del.icio.us/post?v=2&url='
      + encodeURIComponent(loc)
      +'&title='
      + encodeURIComponent(title);
  location.href = ref;
  //Return false so the link won't be activated. 
  return false;
}

function toggle_comment (id)
{
  if (!document.getElementById)
    return;
  var div = document.getElementById ('msg_' + id);
  var img = document.getElementById ('img_' + id);
  var visb = div.style.visibility;

  if (!div)
    return;

  if (div.style.visibility.indexOf ("hidden") == -1)
    {
      div.style.visibility = "hidden"; 
      img.src = "/weblog/public/images/plus.gif"
    }
  else
    {
      div.style.visibility = "visible";
      img.src = "/weblog/public/images/minus.gif"
    }
}

var ns6 = (document.getElementById)? true:false;

function displayComment (id)
{
      var obj;
      if (!ns6) return;
      obj = document.getElementById ('ct_'+id);
      obj.style.visibility = "visible";
}

function hideComment (id)
{
      var obj;
      if (!ns6) return;
      obj = document.getElementById ('ct_'+id);
      obj.style.visibility = "hidden";
}

/*
  JavaScript functions from the pages
*/

function selectAllCheckboxes (form, btn, txt)
{
  var i;
  for (i =0; i < form.elements.length; i++)
    {
      var contr = form.elements[i];
      if (contr != null && contr.type == "checkbox" && contr.name.indexOf (txt) != -1)
        {
    contr.focus();
    if (btn.value == 'Select All')
      contr.checked = true;
    else
            contr.checked = false;
  }
    }
  if (btn.value == 'Select All')
    btn.value = 'Unselect All';
  else
    btn.value = 'Select All';
  btn.focus();
}

function selectAllCheckboxes2 (form, btn, txt, txt2)
{
  var i;
  for (i =0; i < form.elements.length; i++)
    {
      var contr = form.elements[i];
      if (contr != null && contr.type == "checkbox" && contr.name.indexOf (txt)  != -1 && contr.name.indexOf(txt2) != -1)
        {
    contr.focus();
    if (btn.value == 'Select All')
      contr.checked = true;
    else
            contr.checked = false;
  }
    }
  if (btn.value == 'Select All')
    btn.value = 'Unselect All';
  else
    btn.value = 'Select All';
  btn.focus();
}


function
getActiveStyleSheet ()
{
  var i, a;

  for (i=0; (a = document.getElementsByTagName ("link")[i]); i++)
    {
      if (a.getAttribute ("rel").indexOf ("style") != -1
          && a.getAttribute ("title")
          && !a.disabled)
        return a.getAttribute("title");
    }

  return null;
}

function setSelectedStyle()
{
  var a;
  a = document.getElementsByName("style_selector")[0];
  if (a)
  {
    for (i=0; (b=a.options[i]); i++)
    {
      if (b.text==getActiveStyleSheet())
      a.options[i].selected=true;
    }
  }
}

function
setActiveStyleSheet (title, save_cookie)
{
  if (save_cookie == 0)
  {
    var j, b;
    for (j = 0; (b = document.getElementsByName ('save_sticky')[j]); j++)
    {
      if (b.checked == true)
      {
        save_cookie = 1;
    }
    }
  }
  var i, a, main, isset;
  isset = 0;
  for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++)
  {
    if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("title"))
    {
      a.disabled = true;
      if (a.getAttribute ("title") == title)
      {
        isset = 1;
        a.disabled = false;
        if (save_cookie)
        {
          createCookie ("style", title, 365);
        }
      }
    }
  }
  if (isset == 0)
  {
    for (i = 0; (a = document.getElementsByTagName ("link")[i]); i++)
    {
      if (a.getAttribute ("rel").indexOf ("style") != -1 && a.getAttribute ("title"))
      {
        a.disabled = false;
        setSelectedStyle();
        return null;
      }
    }
  }
  else
    setSelectedStyle();
}

function getPreferredStyleSheet ()
{
  var i, a;

  for (i=0; (a = document.getElementsByTagName ("link")[i]); i++)
    {
      if(a.getAttribute ("rel").indexOf ("style") != -1
         && a.getAttribute ("rel").indexOf ("alt") == -1
         && a.getAttribute ("title"))
        return a.getAttribute ("title");
    }

  return null;
}

function createCookie (name, value, days)
{
  if (days)
    {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
    }
  else expires = "";

  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split (';');
  for(var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring (1, c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring (nameEQ.length,
c.length);
  }
  return null;
}

function makeSSMenu ()
{
  var x = document.getElementByID ('ss_menu_ctr');
  var ssElems = getSSElems ();
}