noalyss  Version-9
scripts.js
Go to the documentation of this file.
1 /*
2  * This file is part of NOALYSS.
3  *
4  * NOALYSS is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * NOALYSS is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with NOALYSS; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 /* $Revision$ */
19 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /*!\file
23  * \brief javascript script, always added to every page
24  *
25  */
26 var ask_reload = 0;
27 // tag_choose Element which contains all the selected tags
28 var tag_choose = '';
29 var aDraggableElement = new Array();
30 
31 // document.viewport depends of prototype.js
32 var viewport = document.viewport.getDimensions(); // Gets the viewport as an object literal
33 var width = viewport.width; // Usable window width
34 var height = viewport.height;
35  /**
36  * return undefined if nothing is found , otherwise return the DOM elemnt
37  * @param {type} p_name_dom
38  * @param {type} name_child
39  * @returns {undefined}
40  */
41 function in_child(p_element,name_child) {
42  var element=p_element
43  if ( typeof p_element !== "object" ) {
44  element=document.getElementById(p_element);
45 
46  }
47  if ( ! element ) return undefined;
48  for ( var e=0; e < element.childElementCount;e++) {
49  if ( element.childNodes[e].id == name_child) {
50  return element.childNodes[e];
51  }
52  }
53 }
54 /**
55  * callback function when we just need to update a hidden div with an info
56  * message
57  */
58 function infodiv(req, json)
59 {
60  try
61  {
62  remove_waiting_box();
63  var answer = req.responseXML;
64  var a = answer.getElementsByTagName('ctl');
65  var html = answer.getElementsByTagName('code');
66  if (a.length === 0)
67  {
68  var rec = req.responseText;
69  alert_box('erreur :' + rec);
70  }
71  var name_ctl = a[0].firstChild.nodeValue;
72  var code_html = getNodeText(html[0]);
73 
74  code_html = unescape_xml(code_html);
75  g(name_ctl + "info").innerHTML = code_html;
76  } catch (e)
77  {
78  alert_box("success_box" + e.message);
79  }
80  try
81  {
82  code_html.evalScripts();
83  } catch (e)
84  {
85  alert_box(content[53] + "\n" + e.message);
86  }
87 
88 }
89 /**
90  *@brief delete a row from a table (tb) the input button send the this
91  as second parameter
92  */
93 function deleteRow(tb, obj)
94 {
95  smoke.confirm(content[50], function (e)
96  {
97  if (e) {
98  var td = obj.parentNode;
99  var tr = td.parentNode;
100  var lidx = tr.rowIndex;
101  g(tb).deleteRow(lidx);
102 
103  } else {
104  return;
105  }
106  });
107 }
108 function deleteRowRec(tb, obj)
109 {
110  var tr = obj;
111  var lidx = tr.rowIndex;
112  g(tb).deleteRow(lidx);
113 }
114 /*!\brief remove trailing and heading space
115  * \param the string to modify
116  * \return string without heading and trailing space
117  */
118 function trim(s)
119 {
120  return s.replace(/^\s+/, '').replace(/\s+$/, '');
121 }
122 
123 /**
124  * @brief retrieve an element thanks its ID
125  * @param ID is a string
126  * @return the found object of undefined if not found
127  */
128 function g(ID)
129 {
130  if (document.getElementById)
131  {
132  return this.document.getElementById(ID);
133  } else if (document.all)
134  {
135  return document.all[ID];
136  } else
137  {
138  return undefined;
139  }
140 }
141 /**
142  *@brief enable the type of periode
143  */
144 function enable_type_periode()
145 {
146  if ($("type_periode").options[$("type_periode").selectedIndex].value == 0)
147  {
148  $('from_periode').enable();
149  $('to_periode').enable();
150  $('from_date').disable();
151  $('to_date').disable();
152  $('p_step').enable();
153  } else
154  {
155  $('from_periode').disable();
156  $('to_periode').disable();
157  $('from_date').enable();
158  $('to_date').enable();
159  $('p_step').disable();
160  }
161 }
162 
163 /**
164  *@brief will reload the window but it is dangerous if we have submitted
165  * a form with POST
166  */
167 function refresh_window()
168 {
169  window.location.reload();
170 }
171 
172 /**
173  *@fn encodeJSON(obj)
174  *@brief we receive a json object as parameter and the function returns the string
175  * with the format variable=value&var2=val2...
176  */
177 function encodeJSON(obj)
178 {
179  if (typeof obj != 'object')
180  {
181  alert_box('encodeParameter obj n\'est pas un objet');
182  }
183  try
184  {
185  var str = '';
186  var e = 0;
187  for (var i in obj)
188  {
189  if (e !== 0)
190  {
191  str += '&';
192  } else
193  {
194  e = 1;
195  }
196  str += i;
197  str += '=' + encodeURI(obj[i]);
198  }
199  return str;
200  } catch (e)
201  {
202  alert_box('encodeParameter ' + e.message);
203  return "";
204  }
205 }
206 function hide(p_param)
207 {
208  g(p_param).style.display = 'none';
209 }
210 function show(p_param)
211 {
212  g(p_param).style.display = 'block';
213 }
214 
215 /**
216  *@brief set the focus on the selected field
217  *@param Field id of the control
218  *@param selectIt : the value selected in case of Field is a object select, numeric
219  */
220 function SetFocus(Field, SelectIt)
221 {
222  var elem = g(Field);
223  if (elem)
224  {
225  elem.focus();
226  }
227  return true;
228 }
229 /**
230  * @brief set a DOM id with a value in the parent window (the caller),
231  @param p_ctl is the name of the control
232  @param p_value is the value to set in
233  @param p_add if we don't replace the current value but we add something
234  */
235 function set_inparent(p_ctl, p_value, p_add)
236 {
237  self.opener.set_value(p_ctl, p_value, p_add);
238 }
239 
240 /**
241  * @brief set a DOM id with a value, it will consider if it the attribute
242  value or innerHTML has be used
243  @param p_ctl is the name of the control
244  @param p_value is the value to set in
245  @param p_add if we don't replace the current value but we add something
246  */
247 function set_value(p_ctl, p_value, p_add)
248 {
249  if (g(p_ctl))
250  {
251  var g_ctrl = g(p_ctl);
252  if (p_add != undefined && p_add === 1)
253  {
254  if (g_ctrl.value)
255  {
256  p_value = g_ctrl.value + ',' + p_value;
257  }
258  }
259  if (g_ctrl.tagName === 'INPUT')
260  {
261  g(p_ctl).value = p_value;
262  }
263  if (g_ctrl.tagName === 'SPAN')
264  {
265  g(p_ctl).innerHTML = p_value;
266  }
267  if (g_ctrl.tagName === 'SELECT')
268  {
269  g(p_ctl).value = p_value;
270  }
271  }
272 }
273 /**
274  * @brief compute small math in numeric cells
275  * @param string value
276  * @returns float
277  */
278 function compute_number(value)
279 {
280  var retval = 0;
281 
282  var exp = new RegExp("^[0-9/*+-.()]+$", "g");
283  /*pour éviter un eval() mal intentionné*/
284  var res = exp.test(value);
285  if (res)
286  {
287  /*pour gérer un nombre non valide comme 5..36 ou 5.3.6
288  parce qu'il est possible d'entrer plusieurs
289  points dans le nombre et eval() lève une exception*/
290  try
291  {
292  console.debug("value = "+value);
293  retval = eval(value);
294  } catch (e)
295  {
296  return parseFloat(value);
297  }
298  /*pour gérer les divisions par 0*/
299  if (retval == Infinity)
300  {
301  return 0;
302  } else
303  {
304  return retval;
305  }
306  } else {
307  return 0;
308  }
309 }
310 /**
311  *@brief format the number change comma to point
312  *@param HTML obj
313  */
314 function format_number(obj, p_prec)
315 {
316  var precision = 2;
317  if (p_prec === undefined)
318  {
319  precision = 2;
320  } else {
321  precision = p_prec;
322  }
323  var value = obj.value;
324  value = value.replace(/,/g, '.');
325 
326  value=compute_number(value);
327 
328  value = parseFloat(value);
329  if (isNaN(value))
330  {
331  value = 0;
332  }
333  var arrondi = Math.pow(10, precision);
334 
335  value = Math.round(value * arrondi) / arrondi;
336 
337  $(obj).value = value;
338 }
339 
340 /**
341  * Replace slash and minus by dot
342  * @param p_object
343  */
344 function format_date(p_object)
345 {
346  p_object.value=p_object.value.replace(/\//g,'.');
347  p_object.value=p_object.value.replace(/-/g,'.');
348 }
349 /**
350  *@brief check if the object is hidden or show and perform the opposite,
351  * show the hidden obj or hide the shown one
352  *@param name of the object
353  */
354 function toggleHideShow(p_obj, p_button)
355 {
356  var stat = g(p_obj).style.display;
357  var str = g(p_button).value;
358  if (stat === 'none')
359  {
360  show(p_obj);
361  str = str.replace(/Afficher/, content[62]);
362  g(p_button).value = str;
363  } else
364  {
365  hide(p_obj);
366  str = str.replace(/Cacher/, content[63]);
367  g(p_button).value = str;
368  }
369 }
370 /**
371  *@brief open popup with the search windows
372  *@param p_dossier the dossier where to search
373  *@param p_style style of the detail value are E for expert or S for simple
374  */
375 function popup_recherche(p_dossier)
376 {
377  var w = window.open("recherche.php?gDossier=" + p_dossier + "&ac=SEARCH", '', 'statusbar=no,scrollbars=yes,toolbar=no');
378  w.focus();
379 }
380 /**
381  *@brief replace the special characters (><'") by their HTML representation
382  *@return a string without the offending char.
383  */
384 function unescape_xml(code_html)
385 {
386  code_html = code_html.replace(/\&lt;/, '<');
387  code_html = code_html.replace(/\&gt;/, '>');
388  code_html = code_html.replace(/\&quot;/, '"');
389  code_html = code_html.replace(/\&apos;/, "'");
390  code_html = code_html.replace(/\&amp;/, '&');
391  return code_html;
392 }
393 /**
394  *@brief Firefox splits the XML into 4K chunk, so to retrieve everything we need
395  * to get the different parts thanks textContent
396  *@param xmlNode a node (result of var data = =answer.getElementsByTagName('code'))
397  *@return all the content of the XML node
398  */
399 function getNodeText(xmlNode)
400 {
401  if (!xmlNode)
402  return '';
403  if (typeof (xmlNode.textContent) != "undefined")
404  {
405  return xmlNode.textContent;
406  }
407  if (xmlNode.firstChild && xmlNode.firstChild.nodeValue)
408  return xmlNode.firstChild.nodeValue;
409  return "";
410 }
411 /**
412  *@brief change the periode in the calendar of the dashboard
413  *@param object select
414  */
415 function change_month(obj)
416 {
417  var action = new Ajax.Request(
418  "ajax_misc.php",
419  {
420  method: 'get',
421  parameters: {gDossier: obj.gDossier, op: 'cal', "per": obj.value, t: obj.type_display, notitle: obj.notitle},
422  onFailure: ajax_misc_failure,
423  onSuccess: success_misc
424  }
425  );
426 
427 }
428 /**
429  *@brief basic answer to ajax on success, it will fill the DOMID code with
430  * the code. In that case, you need to create the object before the Ajax.Request
431  *The difference with success box is that
432  *@see add_div removeDiv success_box is that the width and height are not changed ajax_misc.php
433  *@param code is the ID of the object containing the html (div, button...)
434  *@param value is the html code, with it you fill the ctl element
435  */
436 
437 function success_misc(req)
438 {
439  try
440  {
441  var answer = req.responseXML;
442  var html = answer.getElementsByTagName('code');
443  if (html.length === 0)
444  {
445  var rec = req.responseText;
446  alert_box('erreur :' + rec);
447  }
448  var nodeXml = html[0];
449  var code_html = getNodeText(nodeXml);
450  code_html = unescape_xml(code_html);
451  $("user_cal").innerHTML = code_html;
452  } catch (e)
453  {
454  alert_box(e.message);
455  }
456  try
457  {
458  code_html.evalScripts();
459  } catch (e)
460  {
461  alert_box(content[53] + "\n" + e.message);
462  }
463 
464 
465 }
466 function loading()
467 {
468  var str = '<p>' + content[64] + '</p>';
469  str = str + '<image src="image/loading.gif" alt="chargement"></image>';
470  return str;
471 }
472 
473 function ajax_misc_failure()
474 {
475  alert_box(content[53]);
476 }
477 /**
478  *@brief remove a document_modele
479  */
480 function cat_doc_remove(p_dt_id, p_dossier)
481 {
482  var queryString = "gDossier=" + p_dossier + "&op=rem_cat_doc" + "&dt_id=" + p_dt_id;
483  var action = new Ajax.Request(
484  "ajax_misc.php", {method: 'get',
485  parameters: queryString,
486  onFailure: ajax_misc_failure,
487  onSuccess: function (req)
488  {
489  try
490  {
491  var answer = req.responseXML;
492  var html = answer.getElementsByTagName('dtid');
493  if (html.length === 0)
494  {
495  var rec = req.responseText;
496  alert_box('erreur <br>' + rec);
497  return;
498  }
499  var nodeXML = html[0];
500  var row_id = getNodeText(nodeXML);
501  if (row_id === 'nok')
502  {
503  var message_node = answer.getElementsByTagName('message');
504  var message_text = getNodeText(message_node[0]);
505  alert_box('erreur <br>' + message_text);
506  return;
507  }
508  $('row' + row_id).style.textDecoration = "line-through";
509  $('X' + row_id).style.display = 'none';
510  $('M' + row_id).style.display = 'none';
511  } catch (e)
512  {
513  alert_box(e.message);
514  }
515  }
516  }
517  );
518 }
519 /**
520  *@brief change a document_modele
521  */
522 function cat_doc_change(p_dt_id, p_dossier)
523 {
524  var queryString = "gDossier=" + p_dossier + "&op=mod_cat_doc" + "&dt_id=" + p_dt_id;
525  var nTop = calcy(posY);
526  var nLeft = "200px";
527  var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto";
528 
529  removeDiv('change_doc_div');
530  waiting_box();
531  var action = new Ajax.Request(
532  "ajax_misc.php",
533  {
534  method: 'get', parameters: queryString,
535  onFailure: ajax_misc_failure,
536  onSuccess: function (req) {
537  remove_waiting_box();
538  add_div({id: 'change_doc_div', style: str_style, cssclass: 'inner_box', drag: "1"});
539  $('change_doc_div').innerHTML = req.responseText;
540 
541  }
542  }
543  );
544 }
545 
546 /**
547  *@brief display the popup with vat and explanation
548  *@param obj with 4 attributes gdossier, ctl,popup
549  */
550 function popup_select_tva(obj)
551 {
552  try
553  {
554  if ($('tva_select')) {
555  removeDiv('tva_select');
556  }
557 
558  var queryString = "gDossier=" + obj.gDossier + "&op=dsp_tva" + "&ctl=" + obj.ctl + '&popup=' + 'tva_select';
559  if (obj.jcode)
560  queryString += '&code=' + obj.jcode;
561  if (obj.compute)
562  queryString += '&compute=' + obj.compute;
563  if (obj.filter)
564  queryString += '&filter=' + obj.filter;
565 
566  var action = new Ajax.Request(
567  "ajax_misc.php",
568  {method: 'get',
569  parameters: queryString,
570  onFailure: ajax_misc_failure,
571  onSuccess: function (req)
572  {
573  try
574  {
575  var answer = req.responseXML;
576  var popup = answer.getElementsByTagName('popup');
577  if (popup.length === 0)
578  {
579  var rec = req.responseText;
580  alert_box('erreur :' + rec);
581  }
582  var html = answer.getElementsByTagName('code');
583 
584  var name_ctl = popup[0].firstChild.nodeValue;
585  var nodeXml = html[0];
586  var code_html = getNodeText(nodeXml);
587  code_html = unescape_xml(code_html);
588 
589  var nTop = posY - 200;
590  var nLeft = "15%";
591  var str_style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto";
592 
593  var popup = {'id': 'tva_select', 'cssclass': 'inner_box', 'style': str_style, 'html': code_html, 'drag': false};
594  add_div(popup);
595  $('lk_tva_select_table').focus();
596  } catch (e)
597  {
598  alert_box("success_popup_select_tva " + e.message);
599  }
600  }
601  }
602  );
603  } catch (e)
604  {
605  alert_box("popup_select_tva " + e.message);
606  }
607 }
608 
609 
610 /**
611  *@brief display the popup with vat and explanation
612  *@param obj with 4 attributes gdossier, ctl,popup
613  */
614 function set_tva_label(obj)
615 {
616  try
617  {
618  var queryString = "gDossier=" + obj.gDossier + "&op=label_tva" + "&id=" + obj.value;
619  if (obj.jcode)
620  queryString += '&code=' + obj.jcode;
621  var action = new Ajax.Request(
622  "ajax_misc.php",
623  {method: 'get',
624  parameters: queryString,
625  onFailure: ajax_misc_failure,
626  onSuccess: success_set_tva_label
627  }
628  );
629  } catch (e)
630  {
631  alert_box("set_tva_label " + e.message);
632  }
633 }
634 /**
635  *@brief display the popup with vat and explanations
636  *@param string req answer from ajax
637  */
638 function success_set_tva_label(req)
639 {
640  try
641  {
642  var answer = req.responseXML;
643  var code = answer.getElementsByTagName('code');
644  var value = answer.getElementsByTagName('value');
645 
646  if (code.length === 0)
647  {
648  var rec = req.responseText;
649  alert_box('erreur :' + rec);
650  }
651 
652  var label_code = code[0].firstChild.nodeValue;
653  var label_value = value[0].firstChild.nodeValue;
654  set_value(label_code, label_value);
655  } catch (e)
656  {
657  alert_box("success_set_tva_label " + e.message);
658  }
659 
660 }
661 
662 /**
663  * Create a div without showing it
664  * @param {type} obj
665  * the attributes are
666  * - style to add style
667  * - id to add an id
668  * - cssclass to add a class
669  * - html is the content
670  * - drag is the div can be moved
671  * @returns html dom element
672  * @see add_div
673  */
674 function create_div(obj)
675 {
676  try
677  {
678  var top = document;
679  var elt = null;
680  if (!$(obj.id)) {
681  elt = top.createElement('div');
682  } else {
683  elt = $(obj.id);
684  }
685  if (obj.id)
686  {
687  elt.setAttribute('id', obj.id);
688  }
689  if (obj.style)
690  {
691  if (elt.style.setAttribute)
692  { /* IE7 bug */
693  elt.style.setAttribute('cssText', obj.style);
694  } else
695  { /* good Browser */
696  elt.setAttribute('style', obj.style);
697  }
698  }
699  if (obj.cssclass)
700  {
701  elt.setAttribute('class', obj.cssclass); /* FF */
702  elt.setAttribute('className', obj.cssclass); /* IE */
703  }
704  if (obj.html)
705  {
706  elt.innerHTML = obj.html;
707  }
708 
709  var bottom_div = document.body;
710  elt.hide();
711  bottom_div.appendChild(elt);
712 
713  /* if ( obj.effect && obj.effect != 'none' ) { Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }
714  else if ( ! obj.effect ){ Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }*/
715  if (obj.drag)
716  {
717  aDraggableElement[obj.id] = new Draggable(obj.id, {starteffect: function ()
718  {
719  new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
720  }}
721  );
722 
723 
724  }
725  return elt;
726  } catch (e)
727  {
728  error_message("create_div " + e.message);
729  }
730 }
731 /**
732  *@brief add dynamically a object for AJAX
733  *@param obj.
734  * the attributes are
735  * - style to add style
736  * - id to add an id
737  * - cssclass to add a class
738  * - html is the content
739  * - drag is the div can be moved
740  */
741 function add_div(obj)
742 {
743  try {
744  var elt = create_div(obj);
745  /* elt.setStyle({visibility:'visible'}); */
746  elt.style.visibility = 'visible';
747  elt.show();
748  return elt;
749  } catch (e)
750  {
751  alert_box("add_div " + e.message);
752  }
753 }
754 /**
755  * remove a object created with add_div
756  * @param elt id of the elt
757  */
758 function removeDiv(elt)
759 {
760  if (g(elt))
761  {
762  document.body.removeChild(g(elt));
763  }
764  // if reloaded if asked the window will be reloaded when
765  // the box is closed
766  if (ask_reload === 1)
767  {
768  // avoid POST window.location = window.location.href;
769  window.location.reload();
770  }
771 }
772 function waiting_node()
773 {
774  $('info_div').innerHTML = 'Un instant';
775  $('info_div').style.display = "block";
776 }
777 /**
778  *show a box while loading
779  *must be remove when ajax is successfull
780  * the id is wait_box
781  */
782 function waiting_box()
783 {
784  var obj = {
785  id: 'wait_box', html: '<h2 class="title">' + content[65] + '</h2>' + loading()
786  };
787  var y = fixed_position(10, 250)
788  obj.style = y + ";width:20%;margin-left:40%;";
789  if ($('wait_box')) {
790  removeDiv('wait_box');
791  }
792  waiting_node();
793  add_div(obj);
794 
795 
796 }
797 /**
798  *@brief call add_div to add a DIV and after call the ajax
799  * the queryString, the callback for function for success and error management
800  * the method is always GET
801  *@param obj, the mandatory attributes are
802  * - obj.qs querystring
803  * - obj.js_success callback function in javascript for handling the xml answer
804  * - obj.js_error callback function for error
805  * - obj.callback the php file to call
806  * - obj.fixed optional let you determine the position, otherwise works like IPopup
807  *@see add_div IBox
808  */
809 function show_box(obj)
810 {
811  add_div(obj);
812  if (!obj.fixed)
813  {
814  g(obj.id).style.top = calcy(40) + "px";
815  show(obj.id);
816  } else
817  {
818  show(obj.id);
819  }
820 
821  var action = new Ajax.Request(
822  obj.callback,
823  {
824  method: 'GET',
825  parameters: obj.qs,
826  onFailure: eval(obj.js_error),
827  onSuccess: eval(obj.js_success)
828  });
829 }
830 /**
831  *@brief receive answer from ajax and just display it into the IBox
832  * XML must contains at least 2 fields : ctl is the ID of the IBOX and
833  * code is the HTML to put in it
834  *@see fill_box
835  */
836 function success_box(req, json)
837 {
838  try
839  {
840  var answer = req.responseXML;
841  var a = answer.getElementsByTagName('ctl');
842  var html = answer.getElementsByTagName('code');
843  if (a.length === 0)
844  {
845  var rec = req.responseText;
846  alert_box(content[48] + rec);
847  }
848  var name_ctl = a[0].firstChild.nodeValue;
849  var code_html = getNodeText(html[0]);
850 
851  code_html = unescape_xml(code_html);
852  g(name_ctl).innerHTML = code_html;
853  g(name_ctl).style.height = 'auto';
854 
855  if (name_ctl == 'popup')
856  g(name_ctl).style.width = 'auto';
857  } catch (e)
858  {
859  alert_box("success_box" + e.message);
860  }
861  try
862  {
863  code_html.evalScripts();
864  } catch (e)
865  {
866  alert_box(content[53] + "\n" + e.message);
867  }
868 }
869 
870 function error_box()
871 {
872  alert_box(content[53]);
873 }
874 /**
875  * show the ledger choice
876  */
877 function show_ledger_choice(json_obj)
878 {
879  try
880  {
881  waiting_box();
882  var i = 0;
883  var query = "gDossier=" + json_obj.dossier + '&type=' + json_obj.type + '&div=' + json_obj.div + '&op=ledger_show';
884  query = query + '&nbjrn=' + $(json_obj.div + 'nb_jrn').value;
885  query = query + '&all_type=' + json_obj.all_type;
886  for (i = 0; i < $(json_obj.div + 'nb_jrn').value; i++) {
887  query = query + "&r_jrn[]=" + $(json_obj.div + 'r_jrn[' + i + ']').value;
888  }
889  query = encodeURI(query);
890  var action = new Ajax.Request(
891  "ajax_misc.php",
892  {method: 'get',
893  parameters: query,
894  onFailure: ajax_misc_failure,
895  onSuccess: function (req, json) {
896  try {
897  var obj = {
898  id: json_obj.div + 'jrn_search',
899  cssclass: 'inner_box',
900  style: ';position:absolute;width:auto;z-index:20;margin-left:20%',
901  drag: 1
902  };
903  //var y=calcy(posY);
904  var y = posY;
905 
906  obj.style = "top:" + y + 'px;' + obj.style;
907  /* if ( json_obj.class )
908  {
909  obj.cssclass=json_obj.class;
910  }*/
911  add_div(obj);
912 
913 
914  var answer = req.responseXML;
915  var a = answer.getElementsByTagName('ctl');
916  var html = answer.getElementsByTagName('code');
917  if (a.length === 0) {
918  var rec = req.responseText;
919  alert_box('erreur :' + rec);
920  }
921  var name_ctl = a[0].firstChild.nodeValue;
922  var code_html = getNodeText(html[0]);
923 
924  code_html = unescape_xml(code_html);
925  remove_waiting_box();
926  g(obj.id).innerHTML = code_html;
927 
928  } catch (e) {
929  alert_box("show_ledger_callback" + e.message);
930  }
931  try {
932  code_html.evalScripts();
933  } catch (e) {
934  alert_box(content[53] + "\n" + e.message);
935  }
936 
937  }
938 
939  }
940  );
941  } catch (e) {
942  alert_box('show_ledger_choice' + e.message);
943  }
944 }
945 /**
946  * hide the ledger choice
947  */
948 function hide_ledger_choice(p_frm_search)
949 {
950  try
951  {
952  var nb = $(p_frm_search).nb_jrn.value;
953  var div = "";
954  if ($(p_frm_search).div) {
955  div = $(p_frm_search).div.value;
956  }
957  var i = 0;
958  var str = "";
959  var name = "";
960  var n_name = "";
961  var sel = 0;
962  for (i = 0; i < nb; i++) {
963  n_name = div + "r_jrn[" + sel + "]";
964  name = div + "r_jrn" + i;
965  if ($(name).checked) {
966  str += '<input type="hidden" id="' + n_name + '" name="' + n_name + '" value="' + $(name).value + '">';
967  sel++;
968  }
969  }
970  str += '<input type="hidden" name="' + div + 'nb_jrn" id="' + div + 'nb_jrn" value="' + sel + '">';
971  $('ledger_id' + div).innerHTML = str;
972  removeDiv(div + 'jrn_search');
973  return false;
974  } catch (e) {
975  alert_box('hide_ledger_choice' + e.message);
976  return false;
977  }
978 
979 }
980 /**
981  * show the cat of ledger choice
982  */
983 function show_cat_choice()
984 {
985  g('div_cat').style.visibility = 'visible';
986 }
987 /**
988  * hide the cat of ledger choice
989  */
990 function hide_cat_choice()
991 {
992  g('div_cat').style.visibility = 'hidden';
993 }
994 /**
995  * add a row for the forecast item
996  */
997 function for_add_row(tableid)
998 {
999  style = 'class="input_text"';
1000  var mytable = g(tableid).tBodies[0];
1001  var nNumberRow = mytable.rows.length;
1002  var oRow = mytable.insertRow(nNumberRow);
1003  var rowToCopy = mytable.rows[1];
1004  var nNumberCell = rowToCopy.cells.length;
1005  var nb = g("nbrow");
1006  var oNewRow = mytable.insertRow(nNumberRow);
1007  for (var e = 0; e < nNumberCell; e++)
1008  {
1009  var newCell = oRow.insertCell(e);
1010  var tt = rowToCopy.cells[e].innerHTML;
1011  new_tt = tt.replace(/an_cat0/g, "an_cat" + nb.value);
1012  new_tt = new_tt.replace(/an_cat_acc0/g, "an_cat_acc" + nb.value);
1013  new_tt = new_tt.replace(/an_qc0/g, "an_qc" + nb.value);
1014  new_tt = new_tt.replace(/an_label0/g, "an_label" + nb.value);
1015  new_tt = new_tt.replace(/month0/g, "month" + nb.value);
1016  new_tt = new_tt.replace(/an_cat_amount0/g, "an_cat_amount" + nb.value);
1017  new_tt = new_tt.replace(/an_deb0/g, "an_deb" + nb.value);
1018  newCell.innerHTML = new_tt;
1019  new_tt.evalScripts();
1020  }
1021  $("an_cat_acc" + nb.value).value = "";
1022  $("an_qc" + nb.value).value = "";
1023  $("an_label" + nb.value).value = "";
1024  $("an_cat_amount" + nb.value).value = "0";
1025  nb.value++;
1026 }
1027 /**
1028  * toggle all the checkbox in a given form
1029  * @param form_id id of the form
1030  */
1031 function toggle_checkbox(form_id)
1032 {
1033  var form = g(form_id);
1034  for (var i = 0; i < form.length; i++)
1035  {
1036  var e = form.elements[i];
1037  if (e.type === 'checkbox')
1038  {
1039  if (e.checked === true)
1040  {
1041  e.checked = false;
1042  } else
1043  {
1044  e.checked = true;
1045  }
1046  }
1047  }
1048 }
1049 /**
1050  * select all the checkbox in a given form
1051  * @param form_id id of the form
1052  */
1053 function select_checkbox(form_id)
1054 {
1055  var form = $(form_id);
1056  for (var i = 0; i < form.length; i++)
1057  {
1058  var e = form.elements[i];
1059  if (e.type === 'checkbox')
1060  {
1061  e.checked = true;
1062  }
1063  }
1064 }
1065 /**
1066  * select all the checkbox in a given form if the specific attribute
1067  * has the given value
1068  * @param form_id id of the form
1069  * @param attribute name
1070  * @param attribute value
1071  */
1072 function select_checkbox_attribute(form_id, p_attribute_name, p_attribute_value)
1073 {
1074  var form = $(form_id);
1075  for (var i = 0; i < form.length; i++)
1076  {
1077  var e = form.elements[i];
1078  if (e.type === 'checkbox' && e.getAttribute(p_attribute_name) == p_attribute_value)
1079  {
1080  e.checked = true;
1081  }
1082  }
1083 }
1084 /**
1085  * unselect all the checkbox in a given form
1086  * @param form_id id of the form
1087  */
1088 function unselect_checkbox(form_id)
1089 {
1090  var form = $(form_id);
1091  for (var i = 0; i < form.length; i++)
1092  {
1093  var e = form.elements[i];
1094  if (e.type === 'checkbox')
1095  {
1096  e.checked = false;
1097  }
1098  }
1099 }
1100 /**
1101  * show the calculator
1102  */
1103 function show_calc()
1104 {
1105  if (g('calc1'))
1106  {
1107  this.document.getElementById('inp').value = "";
1108  this.document.getElementById('inp').focus();
1109  return;
1110  }
1111  var sid = 'calc1';
1112  var shtml = '';
1113  shtml += "<div class=\"bxbutton\">";
1114  shtml += '<a class="icon" onclick="pin(\'calc1\')" id="pin_calc1">&#xf047;</a> <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" title="" class="icon">&#10761;</a>';
1115  shtml += "</div>";
1116  shtml += ' <h2 class="title">' + content[66] + '</h2>';
1117  shtml += '<form name="calc_line" method="GET" onSubmit="cal();return false;" >' + content[68] + '<input class="input_text" type="text" id="inp" name="calculator"> <input type="button" value="Efface" class="button" onClick="Clean();return false;" > <input type="button" value="Efface historique" class="button" onClick="CleanHistory();return false;" > <input type="button" class="button" value="Fermer" onClick="removeDiv(\'calc1\')" >';
1118  shtml += '</form><span class="highligth" style="display:block" id="sub_total"> ' + content[67] + ' </span><span style="display:block" id="listing"> </span>';
1119 
1120  var obj = {id: sid, html: shtml,
1121  drag: false, style: 'z-index:98'
1122  };
1123  add_div(obj);
1124  this.document.getElementById('inp').focus();
1125 }
1126 function display_periode(p_dossier, p_id)
1127 {
1128 
1129  try
1130  {
1131  var queryString = "gDossier=" + p_dossier + "&op=input_per" + "&p_id=" + p_id;
1132  var popup = {'id': 'mod_periode', 'cssclass': 'inner_box', 'html': loading(), 'style': 'width:30em', 'drag': true};
1133  if (!$('mod_periode')) {
1134  add_div(popup);
1135  }
1136  var action = new Ajax.Request(
1137  "ajax_misc.php",
1138  {method: 'get',
1139  parameters: queryString,
1140  onFailure: ajax_misc_failure,
1141  onSuccess: success_display_periode
1142  }
1143  );
1144  $('mod_periode').style.top = (posY - 70) + "px";
1145  $('mod_periode').style.left = (posX - 70) + "px";
1146  } catch (e)
1147  {
1148  alert_box("display_periode " + e.message);
1149  }
1150 
1151 }
1152 function success_display_periode(req)
1153 {
1154  try
1155  {
1156 
1157  var answer = req.responseXML;
1158  var html = answer.getElementsByTagName('data');
1159 
1160  if (html.length === 0)
1161  {
1162  var rec = req.responseText;
1163  alert_box('erreur :' + rec);
1164  }
1165 
1166  var code_html = getNodeText(html[0]);
1167  code_html = unescape_xml(code_html);
1168 
1169  $('mod_periode').innerHTML = code_html;
1170  } catch (e)
1171  {
1172  alert_box("success_display_periode".e.message);
1173  }
1174  try
1175  {
1176  code_html.evalScripts();
1177  } catch (e)
1178  {
1179  alert_box(content[53] + "\n" + e.message);
1180  }
1181 
1182 }
1183 function save_periode(obj)
1184 {
1185  try
1186  {
1187  var queryString = $(obj).serialize() + "&op=save_per";
1188 
1189  var action = new Ajax.Request(
1190  "ajax_misc.php",
1191  {method: 'post',
1192  parameters: queryString,
1193  onFailure: ajax_misc_failure,
1194  onSuccess: success_display_periode
1195  }
1196  );
1197 
1198  } catch (e)
1199  {
1200  alert_box("display_periode " + e.message);
1201  }
1202 
1203  return false;
1204 }
1205 /**
1206  *@brief basic answer to ajax on success, it will fill the ctl with
1207  * the code. In that case, you need to create the object before the Ajax.Request
1208  *The difference with success box is that
1209  *@see add_div removeDiv success_box is that the width and height are not changed
1210  *@param ctl is the ID of the object containing the html (div, button...)
1211  *@param code is the html code, with it you fill the ctl element
1212  */
1213 function fill_box(req)
1214 {
1215  try {
1216 
1217  remove_waiting_box();
1218 
1219  var answer = req.responseXML;
1220  var a = answer.getElementsByTagName('ctl');
1221  var html = answer.getElementsByTagName('code');
1222  if (a.length === 0) {
1223  var rec = req.responseText;
1224  alert_box('erreur :' + rec);
1225  }
1226  var name_ctl = a[0].firstChild.nodeValue;
1227  var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
1228  code_html = unescape_xml(code_html);
1229  $(name_ctl).innerHTML = code_html;
1230  } catch (e) {
1231  alert_box(e.message);
1232  if (console) {
1233  console.error(e);
1234  console.error("log answer = " + req.responseText);
1235  }
1236  }
1237  try {
1238  code_html.evalScripts();
1239  } catch (e) {
1240  if (console) {
1241  console.error(e);
1242  console.error("log answer = " + req.responseText);
1243  }
1244  alert_box(content[53] + "\n" + e.message);
1245  }
1246 
1247 
1248 }
1249 /**
1250  *display a popin to let you modified a predefined operation
1251  *@param dossier_id
1252  *@param od_id from table op_predef
1253  */
1254 function mod_predf_op(dossier_id, od_id,p_ledger)
1255 {
1256  var target = "mod_predf_op";
1257  removeDiv(target);
1258  var str_style = "top:10%;left:2%;width:96%";
1259 
1260  var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1261 
1262  add_div(div);
1263 
1264  var qs = "gDossier=" + dossier_id + '&op=mod_predf&id=' + od_id+'&ledger_id='+p_ledger;
1265 
1266  var action = new Ajax.Request('ajax_misc.php',
1267  {
1268  method: 'get',
1269  parameters: qs,
1270  onFailure: null,
1271  onSuccess: fill_box
1272  }
1273  );
1274 
1275 }
1276 
1277 function save_predf_op(obj)
1278 {
1279  waiting_box();
1280  var querystring = $(obj).serialize() + '&op=save_predf';
1281  // Create a ajax request to get all the person
1282  var action = new Ajax.Request('ajax_misc.php',
1283  {
1284  method: 'post',
1285  parameters: querystring,
1286  onFailure: null,
1287  onSuccess: refresh_window
1288  }
1289  );
1290 
1291  return false;
1292 }
1293 
1294 /**
1295  *ctl_concern is the widget to update
1296  *amount_id is either a html obj. or an amount and the field tiers if given
1297  * @param {type} dossier
1298  * @param {type} ctl_concern
1299  * @param {float or string} amount_id Amount or DOM Id of the element containing the amount
1300  * @param {float} ledger
1301  * @param {type} p_id_targetDom Element (div) where to display the search result
1302  * @param p_tiers id of the Tiers
1303  * @returns {undefined}
1304  */
1305 function search_reconcile(dossier, ctl_concern, amount_id, ledger, p_id_target, p_tiers)
1306 {
1307  if (amount_id === undefined)
1308  {
1309  amount_id = 0;
1310  } else if ($(amount_id))
1311  {
1312  if ($(amount_id).value)
1313  {
1314  amount_id = $(amount_id).value;
1315  } else if
1316  ($(amount_id).innerHTML) {
1317  amount_id = $(amount_id).innerHTML;
1318  }
1319  }
1320  var tiers = "";
1321  if (p_tiers)
1322  tiers = p_tiers;
1323  var target = "";
1324  if (p_id_target != "") {
1325  target = p_id_target;
1326  } else {
1327  target = "search" + layer;
1328  removeDiv(target);
1329  }
1330  var str_style = fixed_position(77, 99);
1331  str_style += ";width:92%;overflow:auto;";
1332  waiting_box();
1333  var hide_operation = $(ctl_concern).getAttribute("hide_operation");
1334  var single_operation = $(ctl_concern).getAttribute("single_operation");
1335 
1336  var param_send = {gDossier: dossier,
1337  ctlc: ctl_concern,
1338  op: 'search_op',
1339  ac: 'JSSEARCH',
1340  amount_id: amount_id,
1341  ledger: ledger,
1342  target: target,
1343  tiers: tiers,
1344  hide_operation: hide_operation,
1345  single_operation:single_operation
1346  };
1347 
1348  var qs = encodeJSON(param_send);
1349 
1350  var action = new Ajax.Request('ajax_misc.php',
1351  {
1352  method: 'get',
1353  parameters: qs,
1354  onFailure: null,
1355  onSuccess: function (req) {
1356  remove_waiting_box();
1357  var div = {id: target, cssclass: 'inner_box', style: str_style, drag: 0};
1358  add_div(div);
1359  $(target).innerHTML = req.responseText;
1360  req.responseText.evalScripts();
1361  }
1362  }
1363  );
1364 }
1365 /**
1366  * search in a popin obj if the object form
1367  */
1368 function search_operation(obj)
1369 {
1370  try {
1371  var dossier = g('gDossier').value;
1372  waiting_box();
1373  var target = "search" + layer;
1374  if ($(obj)["target"]) {
1375  target = $(obj)["target"].value;
1376  }
1377  var qs = Form.serialize('search_form_ajx') + "&op=search_op";
1378  var action = new Ajax.Request('ajax_misc.php',
1379  {
1380  method: 'get',
1381  parameters: qs,
1382  onFailure: null,
1383  onSuccess: function (req) {
1384  remove_waiting_box();
1385  $(target).innerHTML = req.responseText;
1386  req.responseText.evalScripts();
1387  }
1388  }
1389  );
1390  } catch (e)
1391  {
1392  remove_waiting_box();
1393  alert_box(e.message);
1394  }
1395 }
1396 /**
1397  * Update the field e_concerned, from class_iconcerned
1398  * Value is the field where to put the quick-code but only if one checkbox has been
1399  * selected
1400  * @param {type} obj
1401  * @returns {undefined}
1402  */
1403 function set_reconcile(obj)
1404 {
1405 
1406  try
1407  {
1408  var ctlc = obj.elements['ctlc'];
1409  var tiers = obj.elements['tiers'];
1410  if (!obj.elements['target'])
1411  return;
1412  var target = obj.elements['target'].value;
1413  var single_operation = obj.elements['single_operation'].value;
1414  for (var e = 0; e < obj.elements.length; e++)
1415  {
1416 
1417  var elmt = obj.elements[e];
1418  if (elmt.type === "checkbox")
1419  {
1420  if (elmt.checked === true)
1421  {
1422  var str_name = elmt.name;
1423  var nValue = str_name.replace("jr_concerned", "");
1424  if ($(ctlc.value).value != '') {
1425  $(ctlc.value).value += ',';
1426 
1427  } else {
1428 
1429  if (tiers && tiers.value != "") {
1430  $(tiers.value).value = elmt.value;
1431  /* set the name */
1432  new Ajax.Request("fid.php",{
1433  method:"get",
1434  parameters:{gDossier:obj.elements['gDossier'].value,"FID":elmt.value},
1435  onSuccess:function(req){
1436  // find the row number
1437  //tiers.value = e_othern
1438  var tiers_card=new String(tiers.value);
1439  var num=tiers_card.replace("e_other","");
1440  var tiers_name_id="e_other"+"_name"+num;
1441  var answer = req.responseText.evalJSON();
1442  $(tiers_name_id).value=answer["name"];
1443  }
1444  });
1445  }
1446  }
1447  if (single_operation==0) {
1448  $(ctlc.value).value += nValue;
1449  } else {
1450  $(ctlc.value).value = nValue;
1451 
1452  }
1453  }
1454  }
1455  }
1456  removeDiv(obj.elements['target'].value);
1457  } catch (e)
1458  {
1459  alert_box(e.message)
1460  }
1461 }
1462 function remove_waiting_node()
1463 {
1464  $('info_div').innerHTML = "";
1465  $('info_div').style.display = "none";
1466 
1467 }
1468 function remove_waiting_box()
1469 {
1470  if ($('wait_box')) {
1471  Effect.Fade('wait_box', {duration: 0.6});
1472  }
1473 
1474  remove_waiting_node();
1475 }
1476 /**
1477  * Show all the detail of a profile : Menu, Management, Repository and
1478  * let the user to modify it
1479  * @param {type} gDossier
1480  * @param {type} profile_id
1481  * @returns {undefined}
1482  */
1483 function get_profile_detail(gDossier, profile_id)
1484 {
1485  waiting_box();
1486  var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile_id + "&ctl=detail_profile";
1487  var action = new Ajax.Request('ajax_misc.php',
1488  {
1489  method: 'get',
1490  parameters: qs,
1491  onFailure: null,
1492  onSuccess: function (req) {
1493  remove_waiting_box();
1494  $('list_profile').hide();
1495  $('detail_profile').innerHTML = req.responseText;
1496  req.responseText.evalScripts();
1497  $('detail_profile').show();
1498  if (profile_id != "-1")
1499  profile_show('profile_gen_div');
1500  }
1501  }
1502  );
1503 }
1504 function get_profile_detail_success_obsolete(xml)
1505 {
1506  remove_waiting_box();
1507 
1508 }
1509 /**
1510  * @brief compute the string to position a div in a fixed way
1511  * @return string
1512  */
1513 function fixed_position(p_sx, p_sy)
1514 {
1515  var sx = p_sx;
1516  var sy = calcy(p_sy);
1517 
1518  var str_style = "top:" + sy + "px;left:" + sx + "px;position:absolute";
1519  return str_style;
1520 
1521 }
1522 /**
1523  *@brief compute Y even if the windows has scrolled down or up
1524  *@return the correct Y position
1525  */
1526 function calcy(p_sy)
1527 {
1528  var sy = p_sy;
1529  if (window.pageYOffset)
1530  {
1531  sy = window.pageYOffset + p_sy;
1532  } else
1533  {
1534  sy = document.documentElement.scrollTop + p_sy;
1535  }
1536 
1537  return sy;
1538 
1539 }
1540 /**
1541  * @brief display a box with the menu option
1542  * @param {type} gdossier
1543  * @param {type} pm_id
1544  * @returns {undefined}
1545  */
1546 function mod_menu(gdossier, pm_id)
1547 {
1548  waiting_box();
1549  removeDiv('divdm' + pm_id);
1550  var qs = "op=det_menu&gDossier=" + gdossier + "&pm_id=" + pm_id + "&ctl=divdm" + pm_id;
1551  var pos = fixed_position(50, 250);
1552  var action = new Ajax.Request('ajax_misc.php',
1553  {
1554  method: 'get',
1555  parameters: qs,
1556  onFailure: null,
1557  onSuccess: function (req) {
1558  try {
1559  remove_waiting_box();
1560  add_div({id: "divdm" + pm_id, drag: 1, cssclass: "inner_box", style: pos});
1561  $('divdm' + pm_id).innerHTML = req.responseText;
1562  } catch (e) {
1563  alert_box(e.message);
1564  }
1565  }
1566  }
1567  );
1568 }
1569 /**
1570  * Display the submenu of a menu or a module, used in setting the menu
1571  *
1572  * @param {type} p_dossier
1573  * @param {type} p_profile
1574  * @param {type} p_dep
1575  * @returns {undefined}
1576  */
1577 function display_sub_menu(p_dossier, p_profile, p_dep, p_level)
1578 {
1579  waiting_box();
1580  new Ajax.Request('ajax_misc.php',
1581  {
1582  method: 'get',
1583  parameters: {op: 'display_submenu',
1584  gDossier: p_dossier,
1585  dep: p_dep,
1586  p_profile: p_profile,
1587  p_level: p_level
1588  },
1589  onSuccess: function (req) {
1590  try {
1591  remove_waiting_box();
1592  if ($('menu_table').rows.length > p_level) {
1593  $('menu_table').rows[1].remove();
1594  }
1595  $('sub' + p_dep).addClassName("selectedmenu");
1596  var new_row = document.createElement('TR');
1597  new_row.innerHTML = req.responseText;
1598  $('menu_table').appendChild(new_row);
1599  } catch (e) {
1600  alert_box(e.message);
1601  }
1602  }
1603  })
1604 }
1605 /**
1606  * in CFGPRO, ask to confirm before removing a submenu and its children
1607  * @param {type} p_dossier
1608  * @param {type} profile_menu_id
1609  * @returns {undefined}
1610  */
1611 function remove_sub_menu(p_dossier, profile_menu_id)
1612 {
1613  confirm_box(null, content[47],
1614  function () {
1615  waiting_box();
1616  new Ajax.Request('ajax_misc.php',
1617  {
1618  method: 'get',
1619  parameters: {op: 'remove_submenu', gDossier: p_dossier,
1620  p_profile_menu_id: profile_menu_id},
1621  onSuccess: function (req) {
1622  try {
1623  remove_waiting_box();
1624  $('sub' + profile_menu_id).remove();
1625  if ($('menu_table').rows.length > 1) {
1626  $('menu_table').rows[1].remove();
1627  }
1628 
1629  } catch (e)
1630  {
1631  alert_box(e.message);
1632  }
1633  }
1634  }
1635  )
1636  });
1637 
1638 }
1639 /**
1640  * @brief add a menu to a profile, propose only the available menu
1641  * @param obj json object
1642  * - dossier : ,
1643  * - p_id : profile id ,
1644  * - type : Type of menu are "pr" for Printing "me" for plain menu
1645  * - p_level : level of menu (0 -> module,1-> top menu, 2->submenu)
1646  * - dep : the parent menu id (pm_id)
1647  *
1648  */
1649 function add_menu(obj)
1650 {
1651  var pdossier = obj.dossier;
1652  var p_id = obj.p_id;
1653  var p_type = obj.type;
1654 
1655  waiting_box();
1656  removeDiv('divdm' + p_id);
1657  var pos = fixed_position(250, 150) + ";width:50%;";
1658  var action = new Ajax.Request('ajax_misc.php',
1659  {
1660  method: 'get',
1661  parameters: {op: 'add_menu',
1662  'gDossier': pdossier,
1663  'p_id': p_id,
1664  'ctl': 'divdm' + p_id,
1665  'type': p_type,
1666  'dep': obj.dep,
1667  'p_level': obj.p_level},
1668  onFailure: null,
1669  onSuccess: function (req) {
1670  try {
1671  remove_waiting_box();
1672  add_div({id: "divdm" + p_id, drag: 1, "cssclass": "inner_box", "style": pos});
1673  $('divdm' + p_id).innerHTML = req.responseText;
1674  } catch (e) {
1675  alert_box(e.message);
1676  }
1677  }
1678  }
1679  );
1680 }
1681 /**
1682  * @brief Display a box to enter data for adding a new plugin from
1683  * the CFGMENU
1684  * @param {type} p_dossier
1685  * @returns {undefined}
1686  */
1687 function add_plugin(p_dossier)
1688 {
1689  waiting_box();
1690  removeDiv('divplugin');
1691  var qs = "op=add_plugin&gDossier=" + p_dossier + "&ctl=divplugin";
1692 
1693  var action = new Ajax.Request('ajax_misc.php',
1694  {
1695  method: 'get',
1696  parameters: qs,
1697  onFailure: null,
1698  onSuccess: function (req) {
1699  try {
1700  remove_waiting_box();
1701  var pos = fixed_position(250, 150) + ";width:30%";
1702  add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1703  $('divplugin').innerHTML = req.responseText;
1704  } catch (e) {
1705  alert_box(e.message);
1706  }
1707  }
1708  }
1709  );
1710 }
1711 /**
1712  * Modify a menu
1713  * @param {type} p_dossier
1714  * @param {type} me_code
1715  * @returns {undefined}
1716  */
1717 function mod_plugin(p_dossier, me_code)
1718 {
1719  waiting_box();
1720  removeDiv('divplugin');
1721  var qs = "op=mod_plugin&gDossier=" + p_dossier + "&ctl=divplugin&me_code=" + me_code;
1722 
1723  var action = new Ajax.Request('ajax_misc.php',
1724  {
1725  method: 'get',
1726  parameters: qs,
1727  onFailure: null,
1728  onSuccess: function (req) {
1729  try {
1730  remove_waiting_box();
1731  var pos = fixed_position(250, 150) + ";width:30%";
1732  add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
1733  $('divplugin').innerHTML = req.responseText;
1734 
1735  } catch (e) {
1736  alert_box(e.message);
1737  }
1738  }
1739  }
1740  );
1741 }
1742 function create_menu(p_dossier)
1743 {
1744  waiting_box();
1745  removeDiv('divmenu');
1746  var qs = "op=create_menu&gDossier=" + p_dossier + "&ctl=divmenu";
1747 
1748  var action = new Ajax.Request('ajax_misc.php',
1749  {
1750  method: 'get',
1751  parameters: qs,
1752  onFailure: null,
1753  onSuccess: function (req) {
1754  try {
1755  remove_waiting_box();
1756  var pos = fixed_position(250, 150) + ";width:30%";
1757  add_div({
1758  id: "divmenu",
1759  drag: 1,
1760  cssclass: "inner_box",
1761  style: pos
1762  });
1763  $('divmenu').innerHTML = req.responseText;
1764  } catch (e) {
1765  alert_box(e.message);
1766  }
1767  }
1768  }
1769  );
1770 }
1771 function modify_menu(p_dossier, me_code)
1772 {
1773  waiting_box();
1774  removeDiv('divmenu');
1775  var qs = "op=modify_menu&gDossier=" + p_dossier + "&ctl=divmenu&me_code=" + me_code;
1776 
1777  var action = new Ajax.Request('ajax_misc.php',
1778  {
1779  method: 'get',
1780  parameters: qs,
1781  onFailure: null,
1782  onSuccess: function (req) {
1783  try {
1784  remove_waiting_box();
1785  var pos = fixed_position(250, 150) + ";width:30%";
1786  add_div({
1787  id: "divmenu",
1788  drag: 1,
1789  cssclass: "inner_box",
1790  style: pos
1791  });
1792  $('divmenu').innerHTML = req.responseText;
1793 
1794  } catch (e) {
1795  alert_box(e.message);
1796  }
1797  }
1798  }
1799  );
1800 }
1801 function get_properties(obj)
1802 {
1803  var a_array = [];
1804  var s_type = "[" + typeof obj + "]";
1805  for (var m in obj)
1806  {
1807  a_array.push(m);
1808  }
1809  alert_box(s_type + a_array.join(","));
1810 }
1811 /**
1812  * @brief add a line in the form for the report
1813  * @param p_dossier dossier id to connect
1814  */
1815 function rapport_add_row(p_dossier)
1816 {
1817  style = 'style="border: 1px solid blue;"';
1818  var table = $("rap1");
1819  var line = table.rows.length;
1820 
1821  var row = table.insertRow(line);
1822  // left cell
1823  var cellPos = row.insertCell(0);
1824  cellPos.innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">';
1825 
1826  // right cell
1827  var cellName = row.insertCell(1);
1828  cellName.innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">';
1829 
1830  // button + formula
1831  var cellbutton = row.insertCell(2);
1832  var but_html = table.rows[1].cells[2].innerHTML;
1833  but_html = but_html.replace(/form0/g, "form" + line);
1834  cellbutton.innerHTML = but_html;
1835  but_html.evalScripts();
1836 
1837  g('form' + line).value = '';
1838 }
1839 /**
1840  * Search an action in an inner box
1841  */
1842 function search_action(dossier, ctl_concern)
1843 {
1844  try
1845  {
1846  waiting_box();
1847  var dossier = g('gDossier').value;
1848 
1849  var target = "search_action_div";
1850  removeDiv(target);
1851  var str_style = fixed_position(77, 99);
1852 
1853  var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
1854 
1855 
1856  var target = {gDossier: dossier,
1857  ctlc: ctl_concern,
1858  op: 'search_action',
1859  ctl: target
1860  };
1861 
1862  var qs = encodeJSON(target);
1863 
1864  var action = new Ajax.Request('ajax_misc.php',
1865  {
1866  method: 'get',
1867  parameters: qs,
1868  onFailure: null,
1869  onSuccess: function (req) {
1870  try {
1871  remove_waiting_box();
1872  add_div(div);
1873  $('search_action_div').innerHTML = req.responseText;
1874  req.responseText.evalScripts();
1875  } catch (e) {
1876  alert_box(e.message);
1877  }
1878  }
1879  }
1880  );
1881  } catch (e) {
1882  alert_box(e.message);
1883  }
1884 }
1885 
1886 function result_search_action(obj)
1887 {
1888  try
1889  {
1890  var queryString = $(obj).serialize() + "&op=search_action";
1891  var action = new Ajax.Request(
1892  "ajax_misc.php",
1893  {method: 'get',
1894  parameters: queryString,
1895  onFailure: ajax_misc_failure,
1896  onSuccess: function (req) {
1897  try {
1898  remove_waiting_box();
1899  $('search_action_div').innerHTML = req.responseText;
1900  req.responseText.evalScripts();
1901  } catch (e) {
1902  alert_box(e.message);
1903  }
1904  }
1905  }
1906  )
1907 
1908  } catch (e)
1909  {
1910  alert_box("display_periode " + e.message);
1911  }
1912 
1913  return false;
1914 }
1915 
1916 function set_action_related(p_obj)
1917 {
1918 
1919  try
1920  {
1921  var obj = $(p_obj);
1922  var ctlc = obj.elements['ctlc'];
1923 
1924  for (var e = 0; e < obj.elements.length; e++)
1925  {
1926 
1927  var elmt = obj.elements[e];
1928  if (elmt.type === "checkbox")
1929  {
1930  if (elmt.checked === true)
1931  {
1932  var str_name = elmt.name;
1933  var nValue = elmt.value;
1934  if ($(ctlc.value).value != '') {
1935  $(ctlc.value).value += ',';
1936  }
1937  $(ctlc.value).value += nValue;
1938  }
1939  }
1940  }
1941  removeDiv('search_action_div');
1942  return false;
1943  } catch (e)
1944  {
1945  alert_box(e.message);
1946  return false;
1947  }
1948 }
1949 /**
1950  *@brief Show a form to modify or add a new repository
1951  *@param p_dossier
1952  *@param r_id : repository id
1953  */
1954 function stock_repo_change(p_dossier, r_id)
1955 {
1956  var queryString = "gDossier=" + p_dossier + "&op=mod_stock_repo" + "&r_id=" + r_id;
1957  var nTop = calcy(posY);
1958  var nLeft = "10.1562%";
1959  var str_style = "top:" + nTop + "px;left:" + nLeft + ";height:auto;width:auto";
1960 
1961  removeDiv('change_stock_repo_div');
1962  waiting_box();
1963  var action = new Ajax.Request(
1964  "ajax_misc.php",
1965  {
1966  method: 'get', parameters: queryString,
1967  onFailure: ajax_misc_failure,
1968  onSuccess: function (req) {
1969  remove_waiting_box();
1970  add_div({id: 'change_stock_repo_div', style: str_style, cssclass: 'inner_box', drag: "1"});
1971  $('change_stock_repo_div').innerHTML = req.responseText;
1972 
1973  }
1974  }
1975  );
1976 }
1977 function stock_inv_detail(p_dossier, p_id)
1978 {
1979  var queryString = "gDossier=" + p_dossier + "&op=view_mod_stock" + "&c_id=" + p_id + "&ctl=view_mod_stock_div";
1980  var nTop = calcy(posY);
1981  var nLeft = "10%";
1982  var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;";
1983 
1984  removeDiv('view_mod_stock_div');
1985  waiting_box();
1986  var action = new Ajax.Request(
1987  "ajax_misc.php",
1988  {
1989  method: 'get', parameters: queryString,
1990  onFailure: ajax_misc_failure,
1991  onSuccess: function (req) {
1992  remove_waiting_box();
1993  add_div({id: 'view_mod_stock_div', style: str_style, cssclass: 'inner_box', drag: "1"});
1994  $('view_mod_stock_div').innerHTML = req.responseText;
1995  req.responseText.evalScripts();
1996  }
1997  }
1998  );
1999 }
2000 function show_fin_chdate(obj_id)
2001 {
2002  try
2003  {
2004  var ch = $(obj_id).options[$(obj_id).selectedIndex].value;
2005  if (ch == 2) {
2006  $('chdate_ext').hide();
2007  $('thdate').show();
2008  }
2009  if (ch == 1) {
2010  $('chdate_ext').show();
2011  $('thdate').hide();
2012  }
2013  var nb = $('nb_item').value;
2014  for (i = 0; i < nb; i++) {
2015  if ($('tdchdate' + i)) {
2016  if (ch == 2) {
2017  $('tdchdate' + i).show();
2018  }
2019  if (ch == 1) {
2020  $('tdchdate' + i).hide();
2021 
2022  }
2023  }
2024  }
2025  } catch (e) {
2026  alert_box(e.message);
2027  }
2028 }
2029 /**
2030  * tab menu for the profile parameter
2031  */
2032 function profile_show(p_div)
2033 {
2034  try {
2035  var div = ['profile_gen_div', 'profile_menu_div', 'profile_print_div', 'profile_gestion_div', 'profile_repo_div'];
2036  for (var r = 0; r < div.length; r++) {
2037  $(div[r]).hide();
2038  }
2039  $(p_div).show();
2040  } catch (e)
2041  {
2042  alert_box(e.message);
2043  }
2044 }
2045 function detail_category_show(p_div, p_dossier, p_id)
2046 {
2047  $(p_div).show();
2048  waiting_box();
2049  $('detail_category_div').innerHTML = "";
2050  var queryString = "gDossier=" + p_dossier + "&id=" + p_id + "&op=fddetail";
2051  var action = new Ajax.Request(
2052  "ajax_misc.php",
2053  {
2054  method: 'get', parameters: queryString,
2055  onFailure: ajax_misc_failure,
2056  onSuccess: function (req) {
2057  remove_waiting_box();
2058  $('list_cat_div').hide();
2059  $('detail_category_div').innerHTML = req.responseText;
2060  $('detail_category_div').show();
2061  req.responseText.evalScripts();
2062  }
2063  }
2064  );
2065 }
2066 /**
2067  * @brief check if the parameter is a valid a valid date or not, returns true if it is valid otherwise
2068  * false
2069  * @param p_str_date the string of the date (format DD.MM.YYYY)
2070  */
2071 function check_date(p_str_date)
2072 {
2073  var format = /^\d{2}\.\d{2}\.\d{4}$/;
2074  if (!format.test(p_str_date)) {
2075  return false;
2076  } else {
2077  var date_temp = p_str_date.split('.');
2078  var nMonth = parseFloat(date_temp[1]) - 1;
2079  var ma_date = new Date(date_temp[2], nMonth, date_temp[0]);
2080  if (ma_date.getFullYear() == date_temp[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == date_temp[0]) {
2081  return true;
2082  } else {
2083  return false;
2084  }
2085  }
2086 
2087 }
2088 /**
2089  * @brief get the string in the id and check if the date is valid
2090  * @param p_id_date is the id of the element to check
2091  * @return true if the date is valid
2092  * @see check_date
2093  */
2094 function check_date_id(p_id_date)
2095 {
2096  var str_date = $(p_id_date).value;
2097  return check_date(str_date);
2098 }
2099 /**
2100  *
2101  * @param ag_id to view
2102  * @param dossier is the folder
2103  * @param modify : show the modify button values : 0 for no 1 for yes
2104  */
2105 function view_action(ag_id, dossier, modify)
2106 {
2107  waiting_box();
2108  layer++;
2109  id = 'action' + layer;
2110 
2111  querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag_id + '&div=' + id + '&mod=' + modify;
2112  var action = new Ajax.Request(
2113  "ajax_misc.php",
2114  {
2115  method: 'get',
2116  parameters: querystring,
2117  onFailure: error_box,
2118  onSuccess: function (req) {
2119  try {
2120  remove_waiting_box();
2121  var answer = req.responseXML;
2122  var ctl = answer.getElementsByTagName('ctl');
2123  if (ctl.length == 0) {
2124  throw 'ajax failed ctl view_action';
2125  }
2126  var ctl_txt = getNodeText(ctl[0]);
2127  var html = answer.getElementsByTagName('code');
2128  if (html.length === 0)
2129  {
2130  var rec = req.responseText;
2131  throw 'ajax failed html view_action';
2132  }
2133  var code_html = getNodeText(html[0]);
2134  code_html = unescape_xml(code_html);
2135  var pos = fixed_position(0, 50) + ";width:90%;left:5%;";
2136  add_div({
2137  id: id,
2138  cssclass: "inner_box",
2139  style: pos
2140  });
2141  $(id).innerHTML = code_html;
2142  if (ctl_txt == 'ok') {
2143  // compute detail
2144  var detail=in_child(id,"follow_up_detail");
2145  if (detail) {
2146  compute_all_ledger();
2147  }
2148 
2149 
2150  }
2151  code_html.evalScripts();
2152  } catch (e) {
2153  alert_box('view_action' + e.message);
2154  }
2155  }
2156  }
2157  );
2158 }
2159 /**
2160  * @brief filter quickly a table
2161  * @param phrase : phrase to seach
2162  * @param _id : id of the table
2163  * @param colnr : string containing the column number where you're searching separated by a comma
2164  * @param start_row : first row (1 if you have table header)
2165  * @returns nothing
2166  * @see HtmlInput::filter_table
2167  */
2168 function filter_table(phrase, _id, colnr, start_row) {
2169  $('info_div').innerHTML = content[65];
2170  $('info_div').style.display = "block";
2171  var words = $(phrase).value.toLowerCase();
2172  var table = document.getElementById(_id);
2173 
2174  // if colnr contains a comma then check several columns
2175  var aCol = new Array();
2176  if (colnr.indexOf(',') >= 0) {
2177  aCol = colnr.split(',');
2178  } else {
2179  aCol[0] = colnr;
2180  }
2181  var ele;
2182  var tot_found = 0;
2183 
2184  for (var r = start_row; r < table.rows.length; r++) {
2185  var found = 0;
2186  for (var col = 0; col < aCol.length; col++)
2187  {
2188  var idx = aCol[col];
2189  if (table.rows[r].cells[idx])
2190  {
2191  ele = table.rows[r].cells[idx].innerHTML.replace(/<[^>]+>/g, "");
2192  //var displayStyle = 'none';
2193  if (ele.toLowerCase().indexOf(words) >= 0) {
2194  found = 1;
2195  }
2196  }
2197 
2198  }
2199  if (found === 1) {
2200  tot_found++;
2201  table.rows[r].style.display = '';
2202  } else {
2203  table.rows[r].style.display = 'none';
2204  }
2205  $('info_div').style.display = "none";
2206  $('info_div').innerHTML = "";
2207  }
2208  if (tot_found == 0) {
2209  if ($('info_' + _id)) {
2210  $('info_' + _id).innerHTML = content[69];
2211  }
2212  } else {
2213  if ($('info_' + _id)) {
2214  $('info_' + _id).innerHTML = " ";
2215  }
2216  }
2217 }
2218 /**
2219  * @brief filter quickly a list
2220  * @param phrase : DOM id of the input text where we find the word to seach
2221  * @param _id : id of the list
2222  * @returns nothing
2223  * @see HtmlInput::filter_list
2224  */
2225 function filter_list(phrase, _id) {
2226  $('info_div').innerHTML = content[65];
2227  $('info_div').style.display = "block";
2228  var words = $(phrase).value.toLowerCase();
2229  var l_list = document.getElementById(_id);
2230 
2231  var ele;
2232  var tot_found = 0;
2233 
2234  for (var r = 0; r < l_list.childNodes.length; r++) {
2235  var found = 0;
2236  if (l_list.childNodes[r].nodeType != 1 ){
2237  continue;
2238  }
2239  if (l_list.childNodes[r].childElementCount == 0)
2240  {
2241  ele = l_list.childNodes[r].innerHTML;
2242  } else {
2243  ele = l_list.childNodes[r].childNodes[0].innerHTML;
2244  }
2245  if (ele.toLowerCase().indexOf(words) >= 0) {
2246  tot_found++;
2247  l_list.childNodes[r].style.display = 'block';
2248  } else {
2249  l_list.childNodes[r].style.display = 'none';
2250  }
2251  $('info_div').style.display = "none";
2252  $('info_div').innerHTML = "";
2253  }
2254  if (tot_found == 0) {
2255  if ($('info_' + _id)) {
2256  $('info_' + _id).innerHTML = content[69];
2257  }
2258  } else {
2259  if ($('info_' + _id)) {
2260  $('info_' + _id).innerHTML = " ";
2261  }
2262  }
2263 }
2264 
2265 /**
2266  * @brief filter quickly a select
2267  * @param phrase : DOM id of the input text where we find the word to seach
2268  * @param _id : id of the list
2269  * @returns nothing
2270  * @see HtmlInput::filter_list
2271  */
2272 function filter_multiselect(phrase, _id) {
2273  $('info_div').innerHTML = content[65];
2274  $('info_div').style.display = "block";
2275  var words = $(phrase).value.toLowerCase();
2276  var l_list = document.getElementById(_id);
2277 
2278  var tot_found = 0;
2279 
2280  for (var r = 0; r < l_list.options.length; r++) {
2281  var found = 0;
2282  var ele = l_list.options[r].text;
2283 
2284  if (ele.toLowerCase().indexOf(words) >= 0) {
2285  tot_found++;
2286  l_list.options[r].style.display = 'block';
2287  } else {
2288  l_list.options[r].style.display = 'none';
2289  }
2290  $('info_div').style.display = "none";
2291  $('info_div').innerHTML = "";
2292  }
2293  if (tot_found == 0) {
2294  if ($('info_' + _id)) {
2295  $('info_' + _id).innerHTML = content[69];
2296  }
2297  } else {
2298  if ($('info_' + _id)) {
2299  $('info_' + _id).innerHTML = " ";
2300  }
2301  }
2302 }
2303 /**
2304  * @brief
2305  * Display the task late or for today in dashboard
2306  */
2307 function display_task(p_id)
2308 {
2309 
2310  $(p_id).style.top = posY + 'px';
2311  $(p_id).style.left = "10%";
2312  $(p_id).style.width = "80%";
2313  $(p_id).style.display = 'block';
2314 
2315 }
2316 /**
2317  * @brief
2318  * Set a message in the info
2319  */
2320 function info_message(p_message)
2321 {
2322  $('info_div').innerHTML = p_message;
2323  $('info_div').style.display = "block";
2324 }
2325 /**
2326  * @brief hide the info box
2327  */
2328 function info_hide()
2329 {
2330  $('info_div').style.display = "none";
2331 }
2332 /**
2333  * Show the navigator in a internal window
2334  * @returns {undefined}
2335  */
2336 function ask_navigator(p_dossier) {
2337  try {
2338  waiting_box();
2339  removeDiv('navi_div')
2340  var queryString = "gDossier=" + p_dossier + "&op=navigator";
2341  var action = new Ajax.Request(
2342  "ajax_misc.php",
2343  {
2344  method: 'get', parameters: queryString,
2345  onFailure: ajax_misc_failure,
2346  onSuccess: function (req) {
2347  remove_waiting_box();
2348  add_div({id: 'navi_div', style: 'top:2em;', cssclass: 'inner_box'});
2349  $('navi_div').innerHTML = req.responseText;
2350  try
2351  {
2352  req.responseText.evalScripts();
2353  sorttable.makeSortable($("navi_tb"));
2354  } catch (e)
2355  {
2356  alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2357  }
2358 
2359  }
2360  }
2361  );
2362  } catch (e) {
2363  info_message(e.message);
2364  }
2365 
2366 }
2367 /**
2368  * @brief Display an internal windows to set the user's preference
2369  *
2370  */
2371 function set_preference(p_dossier) {
2372  try {
2373  waiting_box();
2374  removeDiv('preference_div')
2375  var queryString = "gDossier=" + p_dossier + "&op=preference";
2376  var action = new Ajax.Request(
2377  "ajax_misc.php",
2378  {
2379  method: 'get', parameters: queryString,
2380  onFailure: ajax_misc_failure,
2381  onSuccess: function (req) {
2382  remove_waiting_box();
2383  add_div({id: 'preference_div', drag: 1});
2384  $('preference_div').innerHTML = req.responseText;
2385  try
2386  {
2387  req.responseText.evalScripts();
2388  } catch (e)
2389  {
2390  alert_box("answer_box Impossible executer script de la reponse\n" + e.message);
2391  }
2392 
2393  }
2394  }
2395  );
2396  } catch (e) {
2397  info_message(e.message);
2398  }
2399 
2400 }
2401 /**
2402  * @brief Display user's bookmark
2403  *
2404  */
2405 function show_bookmark(p_dossier) {
2406  try {
2407  waiting_box();
2408  removeDiv('bookmark_div');
2409  var param = window.location.search;
2410  param = param.gsub('?', '');
2411  var queryString = "gDossier=" + p_dossier + "&op=bookmark&" + param;
2412  var action = new Ajax.Request(
2413  "ajax_misc.php",
2414  {
2415  method: 'get', parameters: queryString,
2416  onFailure: ajax_misc_failure,
2417  onSuccess: function (req) {
2418  remove_waiting_box();
2419  add_div({id: 'bookmark_div', cssclass: 'inner_box', drag: 1});
2420  $('bookmark_div').innerHTML = req.responseText;
2421  try
2422  {
2423  req.responseText.evalScripts();
2424  } catch (e)
2425  {
2426  alert_box(content[53] + "\n" + e.message);
2427  }
2428 
2429  }
2430  }
2431  );
2432  } catch (e) {
2433  info_message(e.message);
2434  }
2435 
2436 }
2437 /**
2438  * @brief save the bookmark
2439  */
2440 function save_bookmark() {
2441  try {
2442  waiting_box();
2443  var queryString = "op=bookmark&" + $("bookmark_frm").serialize();
2444  var action = new Ajax.Request(
2445  "ajax_misc.php",
2446  {
2447  method: 'get', parameters: queryString,
2448  onFailure: ajax_misc_failure,
2449  onSuccess: function (req) {
2450  remove_waiting_box();
2451  // removeDiv('bookmark_div');
2452  //
2453  $('bookmark_div').innerHTML = req.responseText;
2454  try
2455  {
2456  req.responseText.evalScripts();
2457  } catch (e)
2458  {
2459  alert_box(content[53] + "\n" + e.message);
2460  }
2461 
2462  }
2463  }
2464  );
2465  } catch (e) {
2466  info_message(e.message);
2467  }
2468 
2469 }
2470 /**
2471  * @brief remove selected bookmark
2472  */
2473 function remove_bookmark() {
2474  try {
2475  waiting_box();
2476  var queryString = "op=bookmark&" + $("bookmark_del_frm").serialize();
2477  var action = new Ajax.Request(
2478  "ajax_misc.php",
2479  {
2480  method: 'get', parameters: queryString,
2481  onFailure: ajax_misc_failure,
2482  onSuccess: function (req) {
2483  remove_waiting_box();
2484  $('bookmark_div').innerHTML = req.responseText;
2485  try
2486  {
2487  req.responseText.evalScripts();
2488  } catch (e)
2489  {
2490  alert_box(content[53] + "\n" + e.message);
2491  }
2492 
2493  }
2494  }
2495  );
2496  } catch (e) {
2497  error_message(e.message);
2498  }
2499 
2500 }
2501 /**
2502  *@brief display the error message into the div error_content_div (included into error_div)
2503  *@param message message to display
2504  *@note there is no protection
2505  */
2506 function error_message(message)
2507 {
2508  $('error_content_div').innerHTML = message;
2509  $('error_div').style.visibility = 'visible';
2510 }
2511 /**
2512  * @brief show the detail of a tag and propose to save it
2513  */
2514 function show_tag(p_dossier, p_ac, p_tag_id, p_post)
2515 {
2516  try {
2517  waiting_box();
2518  var queryString = "op=tag_detail&tag=" + p_tag_id + "&gDossier=" + p_dossier + "&ac=" + p_ac + '&form=' + p_post;
2519  var action = new Ajax.Request(
2520  "ajax_misc.php",
2521  {
2522  method: 'get', parameters: queryString,
2523  onFailure: ajax_misc_failure,
2524  onSuccess: function (req) {
2525  var answer = req.responseXML;
2526  var html = answer.getElementsByTagName('code');
2527  if (html.length === 0)
2528  {
2529  var rec = req.responseText;
2530  alert_box('erreur :' + rec);
2531  }
2532  var code_html = getNodeText(html[0]);
2533  code_html = unescape_xml(code_html);
2534  remove_waiting_box();
2535  var posy = calcy(250);
2536  add_div({id: 'tag_div', cssclass: 'inner_box', drag: 0, style: "position:fixed;top:15%;"});
2537  $('tag_div').innerHTML = code_html;
2538  try
2539  {
2540  code_html.evalScripts();
2541  } catch (e)
2542  {
2543  alert_box(content[53] + "\n" + e.message);
2544  }
2545 
2546  }
2547  }
2548  );
2549  } catch (e) {
2550  error_message(e.message);
2551  }
2552 }
2553 
2554 /**
2555  * @brief save the modified tag
2556  */
2557 function save_tag()
2558 {
2559  try {
2560  waiting_box();
2561  var queryString = "op=tag_save&" + $("tag_detail_frm").serialize();
2562  var action = new Ajax.Request(
2563  "ajax_misc.php",
2564  {
2565  method: 'get',
2566  parameters: queryString,
2567  onFailure: ajax_misc_failure,
2568  onSuccess: function (req, j) {
2569  remove_waiting_box();
2570  removeDiv('tag_div');
2571  }
2572  }
2573  );
2574  } catch (e) {
2575  error_message(e.message);
2576  return false;
2577  }
2578  return false;
2579 
2580 }
2581 /**
2582  * Show a list of tag which can be added to the current followup document
2583  * @param {type} p_dossier
2584  * @param {type} ag_id
2585  * @returns {undefined}
2586  */
2587 function action_tag_select(p_dossier, ag_id)
2588 {
2589  try {
2590  waiting_box();
2591  var queryString = "ag_id=" + ag_id + "&op=tag_list&gDossier=" + p_dossier;
2592  var action = new Ajax.Request(
2593  "ajax_misc.php",
2594  {
2595  method: 'get', parameters: queryString,
2596  onFailure: ajax_misc_failure,
2597  onSuccess: function (req, j) {
2598  var answer = req.responseXML;
2599  var html = answer.getElementsByTagName('code');
2600  if (html.length === 0)
2601  {
2602  var rec = unescape_xml(req.responseText);
2603  error_message('erreur :' + rec);
2604  }
2605  var code_html = getNodeText(html[0]);
2606  code_html = unescape_xml(code_html);
2607  var pos = fixed_position(35, 229);
2608  add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
2609 
2610  remove_waiting_box();
2611  $('tag_div').innerHTML = code_html;
2612  }
2613  }
2614  );
2615  } catch (e) {
2616  error_message(e.message);
2617  }
2618 }
2619 /**
2620  * @brief Add the current tag to the current ag_id
2621  * @param {type} p_dossier
2622  * @param {type} ag_id
2623  * @param p_isgroup g it is a group , t is a single tag
2624  * @returns {undefined}
2625  */
2626 function action_tag_add(p_dossier, ag_id, t_id,p_isgroup)
2627 {
2628  try {
2629  waiting_box();
2630  var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_add&gDossier=" + p_dossier+"&isgroup="+p_isgroup;
2631  var action = new Ajax.Request(
2632  "ajax_misc.php",
2633  {
2634  method: 'get', parameters: queryString,
2635  onFailure: ajax_misc_failure,
2636  onSuccess: function (req, j) {
2637  var answer = req.responseXML;
2638  var html = answer.getElementsByTagName('code');
2639  if (html.length === 0)
2640  {
2641  var rec = unescape_xml(req.responseText);
2642  error_message('erreur :' + rec);
2643  }
2644  var code_html = getNodeText(html[0]);
2645  code_html = unescape_xml(code_html);
2646  remove_waiting_box();
2647  $('action_tag_td').innerHTML = code_html;
2648  removeDiv('tag_div');
2649  }
2650  }
2651  );
2652  } catch (e) {
2653  error_message(e.message);
2654  }
2655 }
2656 /**
2657  * @brief remove the current tag to the current ag_id
2658  * @param {type} p_dossier
2659  * @param {type} ag_id
2660  * @returns {undefined}
2661  */
2662 function action_tag_remove(p_dossier, ag_id, t_id)
2663 {
2664  confirm_box(null, content[50], function () {
2665  try {
2666  waiting_box();
2667  var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_remove&gDossier=" + p_dossier;
2668  var action = new Ajax.Request(
2669  "ajax_misc.php",
2670  {
2671  method: 'get', parameters: queryString,
2672  onFailure: ajax_misc_failure,
2673  onSuccess: function (req) {
2674  var answer = req.responseXML;
2675  var html = answer.getElementsByTagName('code');
2676  if (html.length === 0)
2677  {
2678  var rec = unescape_xml(req.responseText);
2679  error_message('erreur :' + rec);
2680  }
2681  var code_html = getNodeText(html[0]);
2682  code_html = unescape_xml(code_html);
2683  remove_waiting_box();
2684  $('action_tag_td').innerHTML = code_html;
2685 
2686  }
2687  }
2688  );
2689  } catch (e) {
2690  error_message(e.message);
2691  }
2692  });
2693 }
2694 
2695 /**
2696  * Activate a tag
2697  * @param int p_dossier
2698  * @param int p_tag_id
2699  */
2700 function activate_tag(p_dossier, p_tag_id) {
2701  waiting_box();
2702  new Ajax.Request("ajax_misc.php",
2703  {
2704  method: "get",
2705  parameters: {gDossier: p_dossier, op: 'tag_activate', t_id: p_tag_id},
2706  onSuccess: function (req) {
2707  remove_waiting_box();
2708  var answer = req.responseText.evalJSON();
2709  var tagId = "tag_onoff" + p_tag_id;
2710  $(tagId).update(answer.code);
2711  $(tagId).setStyle(answer.style);
2712  remove_waiting_box();
2713  }
2714  })
2715 }
2716 /**
2717  * Display a div with available tags, this div can update the cell
2718  * tag_choose_td
2719  * @param {type} p_dossier
2720  * @param {string} p_prefix is the prefix of the div
2721  * @param {string} Calling object either Tag_Operation or Tag_Action
2722  * @returns {undefined}
2723  *
2724  */
2725 function search_display_tag(p_dossier, p_prefix,p_object)
2726 {
2727  try {
2728  waiting_box();
2729  var queryString = { op : "search_display_tag",gDossier:p_dossier,pref:p_prefix,caller_obj:p_object};
2730  var action = new Ajax.Request(
2731  "ajax_misc.php",
2732  {
2733  method: 'get', parameters: queryString,
2734  onFailure: ajax_misc_failure,
2735  onSuccess: function (req, j) {
2736  var answer = req.responseXML;
2737  var html = answer.getElementsByTagName('code');
2738  if (html.length === 0)
2739  {
2740  var rec = unescape_xml(req.responseText);
2741  error_message('erreur :' + rec);
2742  }
2743  var code_html = getNodeText(html[0]);
2744  code_html = unescape_xml(code_html);
2745  remove_waiting_box();
2746  add_div({id: p_prefix + 'tag_div', style: 'left:10%;width:70%', cssclass: 'inner_box', drag: 1});
2747  $(p_prefix + 'tag_div').style.top = calcy(200)+"px"
2748  $(p_prefix + 'tag_div').style.left = 20+ "%";
2749  remove_waiting_box();
2750  $(p_prefix + 'tag_div').innerHTML = code_html;
2751  code_html.evalScripts();
2752  }
2753  }
2754  );
2755  } catch (e) {
2756  error_message(e.message);
2757  }
2758 }
2759 /**
2760  * @brief Add the selected tag (p_tag_id) to the cell of tag_choose_td in the search screen
2761  * in the search screen
2762  * @param {type} p_dossier
2763  * @param {type} p_tag_id
2764  * @param p_prefix is the prefix of the widget
2765  * @param p_obj is either g for group of tag or t for a single tag
2766  */
2767 function search_add_tag(p_dossier, p_tag_id, p_prefix,p_obj)
2768 {
2769  try {
2770  var clear_button = 0;
2771  if (tag_choose === '' && p_prefix === 'search') {
2772  tag_choose = $(p_prefix + 'tag_choose_td').innerHTML;
2773  clear_button = 1;
2774  }
2775  waiting_box();
2776  var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix+"&obj="+p_obj;
2777  var action = new Ajax.Request(
2778  "ajax_misc.php",
2779  {
2780  method: 'get', parameters: queryString,
2781  onFailure: ajax_misc_failure,
2782  onSuccess: function (req, j) {
2783  var answer = req.responseXML;
2784  var html = answer.getElementsByTagName('html');
2785  if (html.length === 0)
2786  {
2787  var rec = unescape_xml(req.responseText);
2788  error_message('erreur :' + rec);
2789  }
2790  var code_html = getNodeText(html[0]);
2791  code_html = unescape_xml(code_html);
2792  remove_waiting_box();
2793  $(p_prefix + 'tag_choose_td').innerHTML = $(p_prefix + 'tag_choose_td').innerHTML + code_html;
2794  removeDiv(p_prefix + 'tag_div');
2795  }
2796  }
2797  );
2798  } catch (e) {
2799  error_message(e.message);
2800  }
2801 }
2802 /**
2803  * Clear the tags in the cell tag_choose_td of the search screen
2804  * @returns {undefined}
2805  */
2806 function search_clear_tag(p_dossier, p_prefix)
2807 {
2808  if (p_prefix != 'search') {
2809  $(p_prefix + 'tag_choose_td').innerHTML = "";
2810  return;
2811  }
2812  try {
2813  var queryString = "op=search_clear_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
2814  var action = new Ajax.Request(
2815  "ajax_misc.php",
2816  {
2817  method: 'get', parameters: queryString,
2818  onFailure: ajax_misc_failure,
2819  onSuccess: function (req, j) {
2820  var answer = req.responseXML;
2821  var html = answer.getElementsByTagName('html');
2822  if (html.length === 0)
2823  {
2824  var rec = unescape_xml(req.responseText);
2825  error_message('erreur :' + rec);
2826  }
2827  var code_html = getNodeText(html[0]);
2828  code_html = unescape_xml(code_html);
2829  $(p_prefix + 'tag_choose_td').innerHTML = code_html;
2830  tag_choose = "";
2831  }
2832  }
2833  );
2834  } catch (e) {
2835  error_message(e.message);
2836  }
2837 }
2838 function action_show_checkbox()
2839 {
2840  var a = document.getElementsByName('ag_id_td');
2841  for (var i = 0; i < a.length; i++) {
2842  a[i].style.display = 'block';
2843  }
2844 }
2845 function action_hide_checkbox()
2846 {
2847  var a = document.getElementsByName('ag_id_td');
2848  for (var i = 0; i < a.length; i++) {
2849  a[i].style.display = 'none';
2850  }
2851 }
2852 /**
2853  *
2854  * @param {type} obj
2855  * object attribute : g
2856  * - Dossier dossier_id,
2857  * - invalue DOM Element where you can find the periode to zoom
2858  * - outdiv ID of the target (DIV)
2859  *
2860  */
2861 function calendar_zoom(obj)
2862 {
2863  try {
2864  waiting_box();
2865  var per_periode = null;
2866  var notitle = 0;
2867  var from = 0;
2868  if ($(obj.invalue)) {
2869  per_periode = $(obj.invalue).value;
2870  }
2871  if (obj.notitle && obj.notitle == 1) {
2872  notitle = 1;
2873  }
2874  var action = new Ajax.Request(
2875  "ajax_misc.php",
2876  {
2877  method: 'get',
2878  parameters: {"notitle": notitle, "op": 'calendar_zoom', 'from': from, 'gDossier': obj.gDossier, 'in': per_periode, 'out': obj.outdiv, 'distype': obj.distype},
2879  onFailure: ajax_misc_failure,
2880  onSuccess: function (req, j) {
2881  var answer = req.responseXML;
2882  var html = answer.getElementsByTagName('html');
2883  if (html.length === 0)
2884  {
2885  var rec = unescape_xml(req.responseText);
2886  error_message('erreur :' + rec);
2887  }
2888  var code_html = getNodeText(html[0]);
2889  code_html = unescape_xml(code_html);
2890 
2891  // if the target doesn't exist
2892  // then create it
2893  if (obj.outdiv === undefined) {
2894  obj.outdiv = 'calendar_zoom_div';
2895  }
2896  if ($(obj.outdiv) == undefined) {
2897  var str_style = 'top:10%;margin-left:2%;';
2898 // var str_style = fixed_position(0, 120);
2899  add_div({id: obj.outdiv, style: 'margin-left:3%;width:94%;' + str_style, cssclass: "inner_box", drag: 0});
2900  }
2901  remove_waiting_box();
2902  $(obj.outdiv).innerHTML = code_html;
2903  $(obj.outdiv).show();
2904  }
2905  }
2906  );
2907  } catch (e) {
2908  error_message('calendar_zoom ' + e.message);
2909  }
2910 
2911 
2912 }
2913 /**
2914  * @brief add a line in the form for the stock
2915  */
2916 function stock_add_row()
2917 {
2918  try {
2919  style = 'class="input_text"';
2920  var mytable = g("stock_tb").tBodies[0];
2921  var ofirstRow = mytable.rows[1];
2922  var line = mytable.rows.length;
2923  var nCell = mytable.rows[1].cells.length;
2924  var row = mytable.insertRow(line);
2925  var nb = g("row");
2926  for (var e = 0; e < nCell; e++)
2927  {
2928  var newCell = row.insertCell(e);
2929  if (mytable.rows[1].cells[e].hasClassName('num')) {
2930  newCell.addClassName("num");
2931  }
2932 
2933  var tt = ofirstRow.cells[e].innerHTML;
2934  var new_tt = tt.replace(/sg_code0/g, "sg_code" + nb.value);
2935  new_tt = new_tt.replace(/sg_quantity0/g, "sg_quantity" + nb.value);
2936  new_tt = new_tt.replace(/label0/g, "label" + nb.value);
2937  newCell.innerHTML = new_tt;
2938  new_tt.evalScripts();
2939  }
2940 
2941  g("sg_code" + nb.value).innerHTML = '&nbsp;';
2942  g("sg_code" + nb.value).value = '';
2943  g("label" + nb.value).innerHTML = '';
2944  g("sg_quantity" + nb.value).value = '0';
2945 
2946  nb.value++;
2947 
2948  new_tt.evalScripts();
2949  } catch (e) {
2950  alert_box(e.message);
2951  }
2952 
2953 }
2954 function show_description(p_id)
2955 {
2956  $('print_desc' + p_id).hide();
2957  $('input_desc' + p_id).show();
2958 
2959 }
2960 /**
2961  * Display an empty card to fill , with the right card category
2962  * @param pn_fiche_card_id : fiche_def.fd_id
2963  * @param pn_dossier_id
2964  */
2965 function select_cat(pn_fiche_card_id, pn_dossier_id, ps_element_id)
2966 {
2967  dis_blank_card({"ctl": "div_new_card", "fd_id": pn_fiche_card_id, "op2": "bc", "op": "card", gDossier: pn_dossier_id, "elementId": ps_element_id});
2968  removeDiv('select_card_div');
2969 }
2970 /**
2971  * Show the DIV and hide the other, the array of possible DIV are
2972  * in a_tabs,
2973  * @param {array} a_tabs name of possible tabs
2974  * @param {strng} p_display_tab tab to display
2975  */
2976 function show_tabs(a_tabs, p_display_tab)
2977 {
2978  try
2979  {
2980  if (a_tabs.length == 0) {
2981  console.error('a_tabs in empty');
2982  throw ("a_tabs empty");
2983  return;
2984  }
2985  var i = 0;
2986  for (i = 0; i < a_tabs.length; i++) {
2987  $(a_tabs[i]).hide();
2988  }
2989  $(p_display_tab).show();
2990  } catch (e) {
2991  alert_box(e.message);
2992  }
2993 
2994 }
2995 /**
2996  * Change the class of all the "LI" element of a UL or OL
2997  * @param node of ul (this)
2998  */
2999 function unselect_other_tab(p_tab)
3000 {
3001  try {
3002  var other = p_tab.getElementsByTagName("li");
3003  var i = 0;
3004  var tab = null;
3005  for (i = 0; i < other.length; i++) {
3006  tab = other[i];
3007  tab.className = "tabs";
3008  }
3009  } catch (e) {
3010  if (console)
3011  console.log(e.message);
3012  alert_box('unselect_other_tab ' + e.message);
3013  }
3014 }
3015 /**
3016  * logout function call from ajax
3017  * @see ajax_disconnected
3018  * @returns {undefined}
3019  */
3020 function logout()
3021 {
3022  var tmp_place = window.location.href
3023  var tmp_b = tmp_place.split('/')
3024  var tmp_last = tmp_b.length - 1
3025  var place_logout = tmp_place.replace(tmp_b[tmp_last], 'logout.php');
3026  window.location.href = place_logout;
3027 }
3028 /**
3029  * Create a div which can be used in a anchor
3030  * @returns {undefined}
3031  */
3032 function create_anchor_up()
3033 {
3034  if (document.getElementById('up_top'))
3035  return;
3036 
3037  var newElt = document.createElement('div');
3038  newElt.setAttribute('id', 'up_top');
3039  newElt.innerHTML = '<a id="up_top"></a>';
3040 
3041  var parent = $('info_div').parentNode;
3042  parent.insertBefore(newElt, $('info_div'));
3043 
3044 }
3045 /**
3046  * Initialize the window to show the button "UP" if the window is scrolled
3047  * vertically
3048  * @returns {undefined}
3049  */
3050 function init_scroll()
3051 {
3052  var up = new Element('div', {"class": "inner_box",
3053  "style": "padding:5px;left:auto;width:auto;height: auto;display:none;position:fixed;bottom:30%;right:50px;text-align:center;font-size:20px",
3054  id: "go_up"
3055  });
3056  up.innerHTML = '<a class="icon" onclick="document.getElementById(\'go_up\').hide()" style="float:right;font-size:70%">&#xe816;</a> <a class="icon" href="#up_top" >&#xe81a;</a><a href="javascript:show_calc()" class="icon">&#xf1ec;</a>';
3057  document.body.appendChild(up);
3058  window.onscroll = function () {
3059  if ( document.getElementById("select_box_content") )
3060  { document.getElementById("select_box_content").setStyle({display:"none"})};
3061  if (document.viewport.getScrollOffsets().top > 0) {
3062  if ($('go_up').visible() == false) {
3063  $('go_up').setOpacity(0.65);
3064  $('go_up').show();
3065  $('go_up').style.zIndex = 99;
3066  }
3067  } else {
3068  $('go_up').hide();
3069  }
3070  }
3071 
3072 }
3073 /**
3074  * Confirm a form thanks a modal dialog Box, it returns true if we agree otherwise
3075  * false
3076  * @code
3077  <form onsubmit="return confirm_box(this,'message')">
3078  </form>
3079  * @endcode
3080  * @param p_obj form element (object) or element id (string)
3081  * @param p_message message to display
3082  * @returns true or false
3083  */
3084 function confirm_box(p_obj, p_message, p_callback_true)
3085 {
3086  waiting_box();
3087  try {
3088  // Find id of the end
3089  var name = "";
3090  if (p_obj != null)
3091  {
3092  if (typeof (p_obj) === "object") {
3093  name = p_obj.id;
3094  } else {
3095  name = p_obj;
3096  }
3097  }
3098 
3099  // execute the callback function or submit the form
3100  if (p_callback_true == undefined || p_callback_true == null)
3101  {
3102  smoke.confirm(p_message, function (e) {
3103  if (e) {
3104  $(name).submit();
3105  }
3106  });
3107  } else {
3108  smoke.confirm(p_message, function (e)
3109  {
3110  if (e) {
3111  p_callback_true.apply();
3112  }
3113  });
3114  }
3115  } catch (e) {
3116  alert_box(e.message);
3117  }
3118  remove_waiting_box();
3119  return false;
3120 }
3121 /**
3122  * Alert box in CSS and HTML to replace the common javascript alert
3123  * @param p_message message to display
3124  * @returns void
3125  */
3126 function alert_box(p_message)
3127 {
3128  smoke.alert(p_message, undefined, {ok: 'ok', classname: "inner_box"});
3129 }
3130 
3131 
3132 /**
3133  * @brief Colorize the rows of the table
3134  * @param string p_table id of the table
3135  */
3136 function alternate_row_color(p_table)
3137 {
3138  var table_colored=$(p_table);
3139  if (! table_colored.tBodies[0] ) return;
3140 
3141  var len = table_colored.tBodies[0].rows.length;
3142  var i = 0;
3143  var localClass = "";
3144  for (i = 1; i < len; i++) {
3145  localClass = (i % 2 == 0) ? "even" : "odd";
3146  if ( table_colored.tBodies[0].rows[i].hasClassName("odd"))
3147  {
3148  table_colored.tBodies[0].rows[i].removeClassName("odd");
3149  }
3150  if (table_colored.tBodies[0].rows[i].hasClassName("even"))
3151  {
3152  table_colored.tBodies[0].rows[i].removeClassName("even");
3153  }
3154  table_colored.tBodies[0].rows[i].addClassName(localClass);
3155  }
3156 
3157 }
3158 /**
3159  * Make an DOM element draggable or not
3160  * @param object_id DOM id
3161  */
3162 function pin(object_id) {
3163  if (aDraggableElement[object_id]) {
3164  aDraggableElement[object_id].destroy();
3165  aDraggableElement[object_id] = undefined;
3166  $('pin_' + object_id).innerHTML = "&#xf047;";
3167  } else {
3168  aDraggableElement[object_id] = new Draggable(object_id, {starteffect: function ()
3169  {
3170  new Effect.Highlight(object_id, {scroll: window, queue: 'end'});
3171  }}
3172  );
3173  $('pin_' + object_id).innerHTML = "&#xe809;";
3174  }
3175 }
3176 /**
3177  * Show only the rows into the table (p_table_id) with the attribute (p_attribute_name) and if this attribute
3178  * has the value of (attribut_value)
3179  * @param p_table_id table id
3180  * @param p_attribute_name the name of the attribute
3181  * @param p_attribute_value the value of the attribute we want to show
3182  */
3183 function show_only_row(p_table_id, p_attribute_name, p_attribute_value)
3184 {
3185  if (!$(p_table_id)) {
3186  throw "Invalide table id"
3187  }
3188  var mTable = $(p_table_id);
3189  var ncount = mTable.rows.length
3190  for (var i = 0; i < ncount; i++) {
3191  var mRow = mTable.rows[i];
3192  if (mRow.getAttribute(p_attribute_name) != undefined && mRow.getAttribute(p_attribute_name) != p_attribute_value) {
3193  mRow.hide();
3194  } else {
3195  mRow.show();
3196  }
3197  }
3198 }
3199 /**
3200  * Show all the rows into the table (p_table_id)
3201  * @param p_table_id table id
3202  */
3203 function show_all_row(p_table_id)
3204 {
3205  if (!$(p_table_id)) {
3206  throw "Invalide table id"
3207  }
3208  var mTable = $(p_table_id);
3209  var ncount = mTable.rows.length
3210  for (var i = 0; i < ncount; i++) {
3211  var mRow = mTable.rows[i];
3212  mRow.show();
3213  }
3214 
3215 }
3216 /**
3217  * @class
3218  * Periode handling
3219  * Variables :
3220  * - id of the row of the periode row_per_(p_periode_id) , attribute exercice =per_exercice,periode_id=p_id
3221  * - (this.dialog)
3222  * - id of the table with the rows : periode_tbl
3223  *
3224  * Members :
3225  * - periode_id the concerned Periode , 0 none
3226  * - p_ledger : the id of ledger (jrn_def.jrn_def_id), 0 for global
3227  * - pcallback : default ajax_misc.php (this.callback) with the parameter { op:'periode',gDossier,[action:display,remove,save],p_id:p_periode_id}
3228  * - dossier
3229  * - js_obj_name : name of the js object (this.js_obj_name)
3230  * - ajax_test : file to include for debugging
3231  * - dialog : id of the dialog box (update / add ) periode_box
3232  *
3233  */
3234 var Periode = function (p_ledger) {
3235  this.periode_id = 0;
3236  this.p_ledger = p_ledger;
3237  this.dialog = 'periode_box';
3238  this.pcallback = 'ajax_misc.php';
3239  this.dossier = 0;
3240  this.js_obj_name = "";
3241  this.ajax_test = "";
3242  this.set_callback = function (p_phpfile) {
3243  this.pcallback = p_phpfile;
3244  };
3245  this.set_dossier = function (p_dosid) {
3246  this.dossier = p_dosid;
3247  };
3248  /**
3249  * set_js_obj_name (p_js_obj_name)
3250  * We need to know the javascript variable name , to pass it to ajax and
3251  * create a HTML containing the right variable
3252  * @param p_js_obj_name name of the variable js we use on caller side
3253  */
3254  this.set_js_obj_name = function (p_js_obj_name) {
3255  this.js_obj_name = p_js_obj_name;
3256  };
3257 
3258  /**
3259  * Remove the periode , so call new Ajax and hide the row if successful
3260  * otherwise show dialog box.
3261  * @parameter p_periode_id is the id of periode
3262  */
3263  this.remove = function (p_periode_id) {
3264 
3265  var js_param = {"gDossier": this.dossier,
3266  "op": "periode",
3267  "act": "remove",
3268  "p_id": p_periode_id,
3269  "ledger_id": 0,
3270  "js_var": this.js_obj_name};
3271  if (this.ajax_test != "") {
3272  js_param["TestAjaxFile"] = this.ajax_test;
3273  }
3274  here = this;
3275  smoke.confirm("Confirmer ?", function (e) {
3276  if (e) {
3277  waiting_box();
3278  new Ajax.Request(here.pcallback,
3279  {
3280  method: "POST",
3281  parameters: js_param,
3282  onSuccess: function (req) {
3283  var answer = req.responseText.evalJSON();
3284  remove_waiting_box();
3285  if (answer.status == "OK")
3286  {
3287  $("row_per_" + p_periode_id).remove();
3288  alternate_row_color("periode_tbl");
3289  } else {
3290  smoke.alert(answer.content);
3291  }
3292  }
3293  });
3294  }
3295  });
3296  };
3297 
3298  /**
3299  * display a dialog box to update a periode, call save either display
3300  * an error box or update the row.
3301  * the name of variable is requested
3302  * to build the right button , javascript in the html of answer
3303  * @parameter p_periode_id is the id of periode
3304  */
3305  this.box_display = function (p_periode_id) {
3306  if (this.js_obj_name == "") {
3307  smoke.alert("ERROR BOX_ADD")
3308  }
3309 
3310  var js_param = {"gDossier": this.dossier,
3311  "op": "periode",
3312  "act": "show",
3313  "p_id": p_periode_id,
3314  "ledger_id": this.p_ledger,
3315  "js_var": this.js_obj_name};
3316  if (this.ajax_test != "") {
3317  js_param["TestAjaxFile"] = this.ajax_test;
3318  }
3319  var here = this;
3320  new Ajax.Request(here.pcallback,
3321  {
3322  method: "POST",
3323  parameters: js_param,
3324  onSuccess: function (req) {
3325  remove_waiting_box();
3326  var json = req.responseText.evalJSON();
3327  var y = calcy(100);
3328  add_div({"id": "mod_periode", "style": "position:fixed;top:" + y + "px;width:50%", "cssclass": "inner_box", 'html': "wait"});
3329  $('mod_periode').update(json.content);
3330  }
3331  });
3332  };
3333  /**
3334  * close the periode, call ajax and receive a json object with the attribute
3335  * status, content
3336  * @parameter p_periode_id is the id of periode
3337  */
3338  this.close_periode = function (p_periode_id) {
3339  if (this.js_obj_name == "") {
3340  smoke.alert("ERROR BOX_ADD")
3341  }
3342 
3343  if (this.ajax_test != "") {
3344  js_param["TestAjaxFile"] = this.ajax_test;
3345  }
3346  var here = this;
3347  smoke.confirm("Confirmer ?", function (e) {
3348  if (e) {
3349  here._close(p_periode_id);
3350  }
3351  });
3352  };
3353  /**
3354  * Internal function to close without confirming
3355  * @param {type} p_periode_id
3356  * @returns {undefined}
3357  */
3358  this._close = function (p_periode_id) {
3359  if (this.js_obj_name == "") {
3360  smoke.alert("ERROR BOX_ADD")
3361  }
3362  var js_param = {"gDossier": this.dossier,
3363  "op": "periode",
3364  "act": "close",
3365  "ledger_id": this.p_ledger,
3366  "p_id": p_periode_id,
3367  "js_var": this.js_obj_name
3368  };
3369  if (this.ajax_test != "") {
3370  js_param["TestAjaxFile"] = this.ajax_test;
3371  }
3372  var here = this;
3373  waiting_box();
3374  new Ajax.Request(here.pcallback,
3375  {
3376  method: "POST",
3377  parameters: js_param,
3378  onSuccess: function (req) {
3379  remove_waiting_box();
3380  var json = req.responseText.evalJSON();
3381  if (json.status == 'OK')
3382  {
3383  $('row_per_' + p_periode_id).update(json.content);
3384  new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3385  } else {
3386  smoke.alert(json.content);
3387  }
3388  }
3389  });
3390  };
3391  /**
3392  * reopen the periode
3393  * @parameter p_periode_id is the SQL id of parm_periode or the id of
3394  * jrn_periode
3395  */
3396  this.open_periode = function (p_periode_id) {
3397  if (this.js_obj_name == "") {
3398  smoke.alert("ERROR BOX_ADD")
3399  }
3400  var js_param = {"gDossier": this.dossier,
3401  "op": "periode",
3402  "act": "reopen",
3403  "ledger_id": this.p_ledger,
3404  "p_id": p_periode_id,
3405  "js_var": this.js_obj_name
3406  };
3407  if (this.ajax_test != "") {
3408  js_param["TestAjaxFile"] = this.ajax_test;
3409  }
3410  var here = this;
3411  smoke.confirm("Confirmer ?", function (e) {
3412  if (e) {
3413  waiting_box();
3414  new Ajax.Request(here.pcallback,
3415  {
3416  method: "POST",
3417  parameters: js_param,
3418  onSuccess: function (req) {
3419  remove_waiting_box();
3420  var json = req.responseText.evalJSON();
3421  if (json.status == 'OK')
3422  {
3423  $('row_per_' + p_periode_id).update(json.content);
3424  new Effect.Highlight('row_per_' + p_periode_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3425  } else {
3426  smoke.alert(json.content);
3427  }
3428  }
3429  });
3430  }
3431  });
3432  };
3433  /**
3434  * This DOMID of the DIV containing the form is mod_periode
3435  * @param {type} p_frm
3436  * @returns {Boolean}
3437  */
3438  this.save = function (p_frm) {
3439  var js_param = $(p_frm).serialize(true);
3440  waiting_box();
3441  js_param["js_var"] = this.js_obj_name;
3442  js_param["act"] = "save";
3443  js_param["op"] = "periode";
3444  var here = this;
3445  new Ajax.Request(this.pcallback, {
3446  method: "POST",
3447  parameters: js_param,
3448  onSuccess: function (req) {
3449 
3450  var answer = req.responseText.evalJSON();
3451  remove_waiting_box();
3452  if (answer.status == "OK") {
3453  $('row_per_' + js_param['periode_id']).update(answer.content);
3454  removeDiv('mod_periode');
3455  new Effect.Highlight('row_per_' + js_param['periode_id'], {startcolor: '#FAD4D4', endcolor: '#F78082'});
3456  } else {
3457  smoke.alert(answer.content);
3458  }
3459  }
3460  });
3461  return false;
3462  };
3463  /**
3464  * Thanks the object DOMID sel_per_closed[] the selected periodes are
3465  * closed
3466  * @see Periode._close
3467  */
3468  this.close_selected = function () {
3469  var here = this;
3470  var a_selected = document.getElementsByName('sel_per_close[]');
3471  var count = 0;
3472  var i = 0;
3473  for (i = 0; i < a_selected.length; i++) {
3474  if (a_selected[i].checked == true) {
3475  // Close the selected periode
3476  count++;
3477  }
3478  }
3479  if (count == 0) {
3480  smoke.signal("Sélectionner au moins une période", function () {}, {duration: 1500});
3481  return;
3482  }
3483  smoke.confirm("Confirmer fermeture de " + count + " periode", function (e) {
3484  if (e) {
3485  var a_selected = document.getElementsByName('sel_per_close[]');
3486  var i = 0;
3487  for (i = 0; i < a_selected.length; i++) {
3488  if (a_selected[i].checked == true) {
3489  // Close the selected periode
3490  here._close(a_selected[i].value);
3491  }
3492  }
3493  }
3494  }
3495  );
3496  };
3497  /**
3498  * @brief Insert a periode into the list, always at the bottom !
3499  * DomId :
3500  * # FORM id :insert_periode_frm
3501  * # DIV id = periode_add
3502  * # table id = periode_tbl
3503  */
3504  this.insert_periode = function () {
3505  var p_frm = 'insert_periode_frm';
3506  var js_param = $(p_frm).serialize(true);
3507  waiting_box();
3508  js_param["js_var"] = this.js_obj_name;
3509  js_param["act"] = "insert_periode";
3510  js_param["op"] = "periode";
3511  js_param["p_id"] = "-1";
3512  js_param["ledger_id"] = "0";
3513  var here = this;
3514  new Ajax.Request(this.pcallback, {
3515  method: "POST",
3516  parameters: js_param,
3517  onSuccess: function (req) {
3518  var answer = req.responseText.evalJSON();
3519  remove_waiting_box();
3520  if (answer.status == "OK") {
3521  var new_row = document.createElement("tr");
3522  $('periode_tbl').append(new_row);
3523  new_row.replace(answer.content);
3524 
3525  // hide the form
3526  $('periode_add').hide();
3527  new Effect.Highlight('row_per_' + answer.p_id, {startcolor: '#FAD4D4', endcolor: '#F78082'});
3528  alternate_row_color('periode_tbl');
3529  } else {
3530  smoke.alert(answer.content);
3531  }
3532  }
3533  });
3534  return false;
3535  }
3536 
3537 }
3538 /**
3539  * Show the periodes from the exercice contained into the id (p_exercice_sel)
3540  * @param p_table_id DOM ID of the table
3541  */
3542 Periode.filter_exercice = function (p_table_id) {
3543  var rows = $(p_table_id).rows;
3544  var selected_value = $('p_exercice_sel').value;
3545  for (var i = 1; i < rows.length; i++) {
3546  var exercice = rows[i].getAttribute("per_exercice");
3547  if (selected_value == -1) {
3548  rows[i].show();
3549  } else if (selected_value == exercice) {
3550  rows[i].show();
3551  } else {
3552  rows[i].hide();
3553  }
3554 
3555  }
3556 };
3557 
3558 // keep track of progress bar
3559 var progressBar = [];
3560 // idx of progress bar
3561 var progressIdx = 0;
3562 
3563 /**
3564  * Start the progress bar
3565  * @param {string} p_taskid id to monitor
3566  * @param {int} p_message
3567  */
3568 function progress_bar_start(p_taskid, p_message)
3569 {
3570  try {
3571  progressIdx++;
3572  // block the window
3573 
3574  var message = '<p>' + content[70] + '</p>';
3575  if (p_message) {
3576  message = p_message;
3577  }
3578 
3579  add_div({id: "blocking" + progressIdx, cssclass: "smoke-base smoke-visible "});
3580 
3581  add_div({id: "message" + progressIdx, cssclass: "inner_box", style: "z-index:1000;position:fixed;top:30%;width:40%;left:30%"});
3582  $("message" + progressIdx).update('<h3>' + content[65] + '</h3>' + message);
3583  // Create a div
3584  add_div({id: "progressDiv" + progressIdx, cssclass: "progressbar", html: '<span id="progressValue">0</span>'});
3585  // Check status every sec.
3586  progressBar[progressIdx] = setInterval(progress_bar_check.bind(null, progressIdx, p_taskid), 1000);
3587  } catch (e) {
3588  console.error(e.message);
3589  }
3590 }
3591 
3592 /**
3593  * Check every second the status
3594  * @param {integer} p_idx idx of progressbar
3595  * @param {string} p_taskid id to monitor
3596  */
3597 function progress_bar_check(p_idx, p_taskid)
3598 {
3599  try {
3600 
3601  new Ajax.Request("ajax_misc.php", {
3602  parameters: {gDossier: 0, task_id: p_taskid, op: "progressBar"},
3603  method: "get",
3604  onSuccess: function (req) {
3605  try
3606  {
3607  var answer = req.responseText.evalJSON();
3608  var progress_div = $("progressDiv" + progressIdx);
3609  var a_child = progress_div.childNodes;
3610  var i = 0;
3611  for (i = 0; i < a_child.length; i++) {
3612  if (a_child[i].id = "progressValue") {
3613  var progressValue = a_child[i];
3614  }
3615  }
3616  var progress = parseFloat(progressValue.innerHTML);
3617  if (answer.value <= progress) {
3618  return;
3619  }
3620 
3621  progressValue.innerHTML = answer.value;
3622  progressValue.setStyle("width:" + answer.value + "%");
3623  if (answer.value == 100) {
3624  clearInterval(progressBar[p_idx]);
3625  progressValue.innerHTML = "Success";
3626  Effect.BlindUp("progressDiv" + p_idx, {duration: 1.0, scaleContent: false})
3627  $("message" + p_idx).remove();
3628  $("blocking" + p_idx).remove();
3629  setTimeout(function () {
3630  $("progressDiv" + progressIdx).remove
3631  }, 1100);
3632  }
3633  } catch (e) {
3634  clearInterval(progressBar[p_idx]);
3635  document.getElementById("progressValue").innerHTML = req.responseText;
3636  console.error(e.message);
3637  }
3638  }
3639  });
3640  } catch (e) {
3641  clearInterval(progressBar[p_idx]);
3642  console.error(e.message);
3643  }
3644 }
3645 
3646 /**
3647  * In the user's setting box, update the period list with the choosen exercice
3648  * @param {int} p_dossier
3649  */
3650 function updatePeriodePreference(p_dossier)
3651 {
3652  waiting_box();
3653  var exercice = $('exercice_setting').value;
3654  new Ajax.Updater('setting_period', "ajax_misc.php", {method: "get", parameters: {"op": "pref_exercice", "gDossier": p_dossier, "exercice": exercice}});
3655  remove_waiting_box();
3656 }
3657 /**
3658  * Update the from and to periode list when changing the exercice
3659  * @param {int} p_dossier
3660  * @param {string} p_exercice id of the exercice
3661  * @param {type} p_periode_from id of the starting periode
3662  * @param {type} p_periode_to id of the ending periode
3663  * @param {type} p_last possible value = 1 to show last periode or 0 the first
3664  */
3665 function updatePeriode(p_dossier, p_exercice, p_periode_from, p_periode_to, p_last)
3666 {
3667  waiting_box();
3668  var exercice = $(p_exercice).value;
3669  new Ajax.Updater(p_periode_from, "ajax_misc.php", {method: "get", parameters: {op: "periode_change", "gDossier": p_dossier, "exercice": exercice, field: p_periode_from, "type": "from", "last": p_last}});
3670  new Ajax.Updater(p_periode_to, "ajax_misc.php", {method: "get", parameters: {op: "periode_change", "gDossier": p_dossier, "exercice": exercice, field: p_periode_to, "type": "to", "last": p_last}});
3671  remove_waiting_box();
3672 }
3673 /**
3674  *
3675  * @param {string} p_domid DOM id of the span containing the padlock icon
3676  * @returns none
3677  */
3678 function toggle_lock(p_domid)
3679 {
3680  var padlock = document.getElementById(p_domid);
3681  if (padlock == null) {
3682  console.error("domid invalid");
3683  }
3684  var status = padlock.getAttribute("is_locked");
3685  if (status == 1) {
3686  padlock.innerHTML = "&#xe832;";
3687  padlock.setAttribute("is_locked", 0);
3688  } else if (status == 0) {
3689  padlock.innerHTML = "&#xe831;";
3690  padlock.setAttribute("is_locked", 1);
3691  } else {
3692  throw "toggle_lock failed";
3693  }
3694 
3695 
3696 }
3697 /**
3698  *
3699  * @returns {undefined}
3700  */
3701 function show_ledger_fin_currency()
3702 {
3703  var ledger=$('p_jrn').value;
3704  var dossier=$('gDossier').value;
3705  // $('ledger_currency').
3706  var a=new Ajax.Updater("ledger_currency",
3707  "ajax_misc.php",
3708  {
3709  parameters: {"op":"currencyCode","gDossier":dossier,"ledger":ledger}
3710  });
3711 }
3712 
3713 /***
3714  * Update Preference, applied the new CSS
3715  */
3716 function updatePreference()
3717 {
3718  try {
3719  waiting_box();
3720  var param = $('preference_frm').serialize() + "&op=preference&action=save";
3721 
3722  new Ajax.Request("ajax_misc.php", {
3723  method: "post",
3724  parameters: param,
3725  onSuccess: function (req) {
3726  var style = req.responseText.evalJSON();
3727  // $('pagestyle').setAttribute('href', style.style);
3728  removeDiv('preference_div');
3729  }
3730  });
3731  } catch (e)
3732  {
3733  smoke.alert(content[48] + e.message);
3734  }
3735  remove_waiting_box();
3736 
3737 }
3738 
3739 /**
3740  * turn on or off , set an domElement to 1 or 0 and change the icon
3741  * @param string icon_domid : id of the domElement which must be changed
3742  * @param string p_value_domid : id of domElement containing 1 or 0
3743  * @see param_jrn.php
3744  */
3745 function toggle_onoff(icon_domid, p_value_domid)
3746 {
3747  if ($(p_value_domid).value == 0) {
3748  $(p_value_domid).value = 1;
3749  $(icon_domid).innerHTML = '&#xf205;';
3750  $(icon_domid).style = 'color:green';
3751  } else {
3752  $(p_value_domid).value = 0;
3753  $(icon_domid).innerHTML = '&#xf204;';
3754  $(icon_domid).style = 'color:red';
3755  }
3756 }
3757 /**
3758  * turn on or off , set an domElement to 1 or 0 and change the icon
3759  * @param string icon_domid : id of the domElement which must be changed
3760  * @param string p_value_domid : id of domElement containing 1 or 0
3761  * @see param_jrn.php
3762  */
3763 function toggle_checkbox_onoff(icon_domid, p_value_domid)
3764 {
3765  console.log("toggle_checkbox_onoff");
3766  console.log("icon_domid"+icon_domid);
3767  console.log("p_value_domid"+p_value_domid);
3768 
3769  if ($(p_value_domid).value == 0) {
3770  $(p_value_domid).value = 1;
3771  $(icon_domid).innerHTML = '&#xe741;';
3772  } else {
3773  $(p_value_domid).value = 0;
3774  $(icon_domid).innerHTML = '&#xf096;';
3775  }
3776 }
3777 /**
3778  * in CFGLED show or hide the row depending if the warning is enable or not
3779  *
3780  * @param {type} p_enable
3781  * @param {type} p_row
3782  * @returns {undefined}
3783  */
3784 function toggle_row_warning_enable(p_enable, p_row)
3785 {
3786  if ($(p_enable).value == 1) {
3787  $(p_row).show();
3788  } else {
3789  $(p_row).hide();
3790  }
3791 }
3792 
3793 /**
3794  * return a json object which is the merge of the 2 json objects
3795  * from 2015 : Object.assign(obj1, obj2);
3796  * @param p_json1 object 1 to merge
3797  * @param p_json2 object 2 to merge
3798  * @returns new json object
3799  */
3800 function json_concat(p_json1,p_json2)
3801 {
3802 
3803  var result = {};
3804  for (var key in p_json1) {
3805  result[key] = p_json1[key];
3806  }
3807  for (var key in p_json2) {
3808  result[key] = p_json2[key];
3809  }
3810  return result;
3811 
3812 }
3813 
3814 /**
3815  * return a json object which is the merge of the 2 json objects
3816  * from 2015 : Object.assign(obj1, obj2);
3817  * @param p_json1 object 1 to merge
3818  * @param p_json2 object 2 to merge
3819  * @returns new json object
3820  */
3821 function json_concat(p_json1,p_json2)
3822 {
3823 
3824  var result = {};
3825  for (var key in p_json1) {
3826  result[key] = p_json1[key];
3827  }
3828  for (var key in p_json2) {
3829  result[key] = p_json2[key];
3830  }
3831  return result;
3832 
3833 }
3834 /**
3835  * this function unchecks other checkbox , it mimics the way a radio behaves
3836  * @param string p_click is the DOM id of the checkbox you clicked
3837  * @param string p_name is the name of all the checkbox to uncheck
3838  */
3839 function uncheck_other(p_click,p_name)
3840 {
3841  var aCheckbox=document.getElementsByName(p_name);
3842  if (aCheckbox.length == 0) return;
3843  var i=0;
3844  for (i=0;i<aCheckbox.length;i++) {
3845  aCheckbox[i].checked=false;
3846  }
3847  p_click.checked=true;
3848 }
3849 /**
3850  * Manage the tag with operations
3851  * @returns {undefined}
3852  */
3853 var operation_tag = function (p_div)
3854 {
3855  this.ctl = p_div;
3856  console.log("ctl "+p_div);
3857  /**
3858  * Show a list of tag which can be added to the current followup document
3859  * @param {type} p_dossier
3860  * @param {type} jrn_id
3861  * @returns {undefined}
3862  */
3863  this.select = function (p_dossier, p_jrn_id)
3864  {
3865  try {
3866  waiting_box();
3867  var queryString = {jrn_id:p_jrn_id,op:"operation_tag_select",gDossier:p_dossier,ctl:this.ctl};
3868  var action = new Ajax.Request(
3869  "ajax_misc.php",
3870  {
3871  method: 'get',
3872  parameters: queryString,
3873  onFailure: ajax_misc_failure,
3874  onSuccess: function (req, j) {
3875  remove_waiting_box();
3876 
3877  var answer = req.responseXML;
3878  var html = answer.getElementsByTagName('code');
3879  if (html.length === 0)
3880  {
3881  var rec = unescape_xml(req.responseText);
3882  error_message('erreur :' + rec);
3883  }
3884  var code_html = getNodeText(html[0]);
3885  code_html = unescape_xml(code_html);
3886  var pos = fixed_position(35, 229);
3887  add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 0});
3888 
3889  remove_waiting_box();
3890  $('tag_div').innerHTML = code_html;
3891  }
3892  }
3893  );
3894  } catch (e) {
3895  error_message(e.message);
3896  }
3897  };
3898 
3899  /**
3900  * @brief Add the current tag to the current ag_id
3901  * @param {type} p_dossier
3902  * @param {type} ag_id
3903  * @param p_isgroup g it is a group , t is a single tag
3904  * @returns {undefined}
3905  */
3906  this.add = function (p_dossier, p_jrn_id, t_id, p_isgroup)
3907  {
3908  try {
3909  waiting_box();
3910  var queryString = {t_id:t_id,jrn_id:p_jrn_id,op:"operation_tag_add",
3911  gDossier:p_dossier,ctl:this.ctl,isgroup:p_isgroup};
3912  var ctl=this.ctl;
3913  var action = new Ajax.Request(
3914  "ajax_misc.php",
3915  {
3916  method: 'get', parameters: queryString,
3917  onFailure: ajax_misc_failure,
3918  onSuccess: function (req, j) {
3919  var answer = req.responseXML;
3920  console.log("1-ctl "+ctl);
3921  var html = answer.getElementsByTagName('code');
3922  if (html.length === 0)
3923  {
3924  var rec = unescape_xml(req.responseText);
3925  error_message('erreur :' + rec);
3926  }
3927  var code_html = getNodeText(html[0]);
3928  code_html = unescape_xml(code_html);
3929  remove_waiting_box();
3930  $('operation_tag_td'+ctl).innerHTML = code_html;
3931  removeDiv('tag_div');
3932  }
3933  }
3934  );
3935  } catch (e) {
3936  error_message(e.message);
3937  }
3938  };
3939  /**
3940  * @brief remove the current tag to the current ag_id
3941  * @param {type} p_dossier
3942  * @param {type} ag_id
3943  * @returns {undefined}
3944  */
3945  this.remove = function (p_dossier, p_jrn_id, t_id)
3946  {
3947  var ctl=this.ctl;
3948  console.log("remove-1.ctl "+ctl);
3949  confirm_box(null, content[50], function () {
3950  try {
3951  waiting_box();
3952  var queryString = {t_id:t_id,jrn_id:p_jrn_id,op:"operation_tag_remove",gDossier:p_dossier,ctl:ctl};
3953  var action = new Ajax.Request(
3954  "ajax_misc.php",
3955  {
3956  method: 'get',
3957  parameters: queryString,
3958  onFailure: ajax_misc_failure,
3959  onSuccess: function (req, j) {
3960  var answer = req.responseXML;
3961  var html = answer.getElementsByTagName('code');
3962  if (html.length === 0)
3963  {
3964  var rec = unescape_xml(req.responseText);
3965  error_message('erreur :' + rec);
3966  }
3967  var code_html = getNodeText(html[0]);
3968  code_html = unescape_xml(code_html);
3969  remove_waiting_box();
3970  console.log("remove-2.ctl "+ctl);
3971  $('operation_tag_td'+ctl).innerHTML = code_html;
3972 
3973  }
3974  }
3975  );
3976  } catch (e) {
3977  error_message(e.message);
3978  }
3979  });
3980  };
3981 };
3982 
3983 /**
3984  * Check the sum of size of all the FILES to upload
3985  * @param p_object the form DOM object,
3986  * @param p_max_size MAX_FILE_SIZE constant (see config.inc.php or constant.php)
3987  * @returns true if the sum of filesize is greater than the limit
3988  */
3989 function check_file_size(p_object,p_max_size)
3990 {
3991  var sum_file=0;
3992  for(var i=0;i<p_object.elements.length;i++) {
3993  var a=p_object.elements[i];
3994  if ( p_object.elements[i].getAttribute('type')=="file" )
3995  {
3996  if( p_object.elements[i].files[0]){
3997 
3998  sum_file+=p_object.elements[i].files[0].size;
3999  }
4000  }
4001  }
4002  if ( sum_file > p_max_size) {alert_box(content[78]);return false;}
4003  return true;
4004 }
4005 
4006 /**
4007  * Check that the receipt file is not too big
4008  * @see ajax_ledger.php , ledger_detail_file
4009  * @param int p_max_size maximum size
4010  * @param p_info name of the waiting box
4011  * @returns true if file size is less than the maximum
4012  */
4013 function check_receipt_size(p_max_size,p_info)
4014 {
4015  document.getElementById(p_info).style.display="inline";
4016  console.debug ("param p_max_file_size"+p_max_size);
4017  var f=document.getElementById("receipt_id");
4018  if ( f && f.files[0] && f.files[0].size > parseFloat(p_max_size)) {
4019  document.getElementById("receipt_info_id").innerHTML=content[78];
4020  document.getElementById(p_info).style.display="none";
4021  return false;
4022  }
4023  document.getElementById("receipt_info_id").innerHTML="";
4024  document.getElementById("form_file").submit();
4025  return true;
4026 }
4027 /**
4028  * @brief toggle size of a div : fullsize or normal
4029  *
4030  */
4031 function full_size(p_div) {
4032  div_dom=document.getElementById(p_div);
4033  if ( ! div_dom ) return;
4034  if ( div_dom.hasClassName('fullsize')) {
4035  div_dom.removeClassName('fullsize');$('size_'+p_div).innerHTML='&#xe80a;';
4036  } else {
4037  div_dom.addClassName('fullsize');$('size_'+p_div).innerHTML='&#xe83d;';
4038  }
4039 
4040 }
4041 
4042 /**
4043  * @brief download a document from an url
4044  */
4045 function download_document(p_url)
4046 {
4047  waiting_box();
4048  document.location=p_url;
4049  remove_waiting_box();
4050 }
4051 /**
4052  * @brief download a document from a form
4053  */
4054 function download_document_form(p_form_id)
4055 {
4056  waiting_box();
4057  var url="export.php?"+$(p_form_id).serialize();
4058  document.location=url;
4059  remove_waiting_box();
4060  return false;
4061 }
4062 /**
4063  * Search an account or an analytic account or a card, used in REPORT
4064  * @param {json} p_obj ,
4065  * property : - op for ajax_misc ,
4066  * - gDossier,
4067  * - target DOM element to update with the result
4068  * - query for the search
4069  * @returns {void}
4070  */
4071 function search_account_card(p_obj)
4072 {
4073  p_obj['op']=p_obj['op']||"search_account_card";
4074  var query=p_obj;
4075  if (p_obj.tagName && p_obj.tagName=='FORM') {
4076  query=p_obj.serialize(true);
4077  }
4078 
4079  waiting_box();
4080  new Ajax.Request("ajax_misc.php",{method:"get",parameters:query,
4081  onSuccess: function (req){
4082 
4083  var pos=calcy(50);
4084  var obj={id:"search_account_div",cssclass:"inner_box",style:"top:"+pos+"px",
4085  html:req.responseText};
4086  add_div(obj);
4087  remove_waiting_box();
4088  }
4089  });
4090  return false;
4091 }