noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
scripts.js
Go to the documentation of this file.
00001 /*
00002  *   This file is part of NOALYSS.
00003  *
00004  *   NOALYSS is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   NOALYSS is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with NOALYSS; if not, write to the Free Software
00016  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 /* $Revision$ */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief javascript script, always added to every page
00024  *
00025  */
00026 var ask_reload = 0;
00027 var tag_choose = '';
00028 
00029 /**
00030  * callback function when we just need to update a hidden div with an info
00031  * message
00032  */
00033 function infodiv(req, json)
00034 {
00035     try
00036     {
00037         remove_waiting_box();
00038         var answer = req.responseXML;
00039         var a = answer.getElementsByTagName('ctl');
00040         var html = answer.getElementsByTagName('code');
00041         if (a.length === 0)
00042         {
00043             var rec = req.responseText;
00044             alert('erreur :' + rec);
00045         }
00046         var name_ctl = a[0].firstChild.nodeValue;
00047         var code_html = getNodeText(html[0]);
00048 
00049         code_html = unescape_xml(code_html);
00050         g(name_ctl + "info").innerHTML = code_html;
00051     }
00052     catch (e)
00053     {
00054         alert("success_box" + e.message);
00055     }
00056     try
00057     {
00058         code_html.evalScripts();
00059     }
00060     catch (e)
00061     {
00062         alert("answer_box Impossible executer script de la reponse\n" + e.message);
00063     }
00064 
00065 }
00066 /**
00067  *@brief delete a row from a table (tb) the input button send the this
00068  as second parameter
00069  */
00070 function deleteRow(tb, obj)
00071 {
00072     if (confirm('Confirmez effacement'))
00073     {
00074         var td = obj.parentNode;
00075         var tr = td.parentNode;
00076         var lidx = tr.rowIndex;
00077         g(tb).deleteRow(lidx);
00078     }
00079 }
00080 function deleteRowRec(tb, obj)
00081 {
00082     var td = obj.parentNode;
00083     var tr = td.parentNode;
00084     var lidx = tr.rowIndex;
00085     g(tb).deleteRow(lidx);
00086 }
00087 /*!\brief remove trailing and heading space
00088  * \param the string to modify
00089  * \return string without heading and trailing space
00090  */
00091 function trim(s)
00092 {
00093     return s.replace(/^\s+/, '').replace(/\s+$/, '');
00094 }
00095 
00096 /**
00097  * @brief retrieve an element thanks its ID
00098  * @param ID is a string
00099  * @return the found object of undefined if not found
00100  */
00101 function g(ID)
00102 {
00103     if (document.getElementById)
00104     {
00105         return this.document.getElementById(ID);
00106     }
00107     else if (document.all)
00108     {
00109         return document.all[ID];
00110     }
00111     else
00112     {
00113         return undefined;
00114     }
00115 }
00116 /**
00117  *@brief enable the type of periode
00118  */
00119 function enable_type_periode()
00120 {
00121     if ($("type_periode").options[$("type_periode").selectedIndex].value == 0)
00122     {
00123         $('from_periode').enable();
00124         $('to_periode').enable();
00125         $('from_date').disable();
00126         $('to_date').disable();
00127         $('p_step').enable();
00128     }
00129     else
00130     {
00131         $('from_periode').disable();
00132         $('to_periode').disable();
00133         $('from_date').enable();
00134         $('to_date').enable();
00135         $('p_step').disable();
00136     }
00137 }
00138 
00139 /**
00140  *@brief will reload the window but it is dangerous if we have submitted
00141  * a form with POST
00142  */
00143 function refresh_window()
00144 {
00145     window.location.reload();
00146 }
00147 
00148 /**
00149  *@fn encodeJSON(obj)
00150  *@brief we receive a json object as parameter and the function returns the string
00151  *       with the format variable=value&var2=val2...
00152  */
00153 function encodeJSON(obj)
00154 {
00155     if (typeof obj != 'object')
00156     {
00157         alert('encodeParameter  obj n\'est pas  un objet');
00158     }
00159     try
00160     {
00161         var str = '';
00162         var e = 0;
00163         for (i in obj)
00164         {
00165             if (e !== 0)
00166             {
00167                 str += '&';
00168             }
00169             else
00170             {
00171                 e = 1;
00172             }
00173             str += i;
00174             str += '=' + encodeURI(obj[i]);
00175         }
00176         return str;
00177     }
00178     catch (e)
00179     {
00180         alert('encodeParameter ' + e.message);
00181         return "";
00182     }
00183 }
00184 function  hide(p_param)
00185 {
00186     g(p_param).style.display = 'none';
00187 }
00188 function show(p_param)
00189 {
00190     g(p_param).style.display = 'block';
00191 }
00192 
00193 /**
00194  *@brief set the focus on the selected field
00195  *@param Field id of  the control
00196  *@param selectIt : the value selected in case of Field is a object select, numeric
00197  */
00198 function SetFocus(Field, SelectIt)
00199 {
00200     var elem = g(Field);
00201     if (elem)
00202     {
00203         elem.focus();
00204     }
00205     return true;
00206 }
00207 /**
00208  * @brief set a DOM id with a value in the parent window (the caller),
00209  @param p_ctl is the name of the control
00210  @param p_value is the value to set in
00211  @param p_add if we don't replace the current value but we add something
00212  */
00213 function set_inparent(p_ctl, p_value, p_add)
00214 {
00215     self.opener.set_value(p_ctl, p_value, p_add);
00216 }
00217 
00218 /**
00219  * @brief set a DOM id with a value, it will consider if it the attribute
00220  value or innerHTML has be used
00221  @param p_ctl is the name of the control
00222  @param p_value is the value to set in
00223  @param p_add if we don't replace the current value but we add something
00224  */
00225 function set_value(p_ctl, p_value, p_add)
00226 {
00227     if (g(p_ctl))
00228     {
00229         var g_ctrl = g(p_ctl);
00230         if (p_add != undefined && p_add === 1)
00231         {
00232             if (g_ctrl.value)
00233             {
00234                 p_value = g_ctrl.value + ',' + p_value;
00235             }
00236         }
00237         if (g_ctrl.tagName === 'INPUT')
00238         {
00239             g(p_ctl).value = p_value;
00240         }
00241         if (g_ctrl.tagName === 'SPAN')
00242         {
00243             g(p_ctl).innerHTML = p_value;
00244         }
00245         if (g_ctrl.tagName === 'SELECT')
00246         {
00247             g(p_ctl).value = p_value;
00248         }
00249     }
00250 }
00251 /**
00252  *@brief format the number change comma to point
00253  *@param HTML obj
00254  */
00255 function format_number(obj, p_prec)
00256 {
00257     var precision = 2;
00258     if (p_prec === undefined)
00259     {
00260         precision = 2;
00261     } else {
00262         precision = p_prec;
00263     }
00264     var value = obj.value;
00265     value = value.replace(/,/, '.');
00266     value = parseFloat(value);
00267     if (isNaN(value))
00268     {
00269         value = 0;
00270     }
00271     var arrondi = Math.pow(10, precision);
00272 
00273     value = Math.round(value * arrondi) / arrondi;
00274 
00275     $(obj).value = value;
00276 }
00277 /**
00278  *@brief check if the object is hidden or show and perform the opposite,
00279  * show the hidden obj or hide the shown one
00280  *@param name of the object
00281  */
00282 function toggleHideShow(p_obj, p_button)
00283 {
00284     var stat = g(p_obj).style.display;
00285     var str = g(p_button).value;
00286     if (stat === 'none')
00287     {
00288         show(p_obj);
00289         str = str.replace(/Afficher/, 'Cacher');
00290         g(p_button).value = str;
00291     }
00292     else
00293     {
00294         hide(p_obj);
00295         str = str.replace(/Cacher/, 'Afficher');
00296         g(p_button).value = str;
00297     }
00298 }
00299 /**
00300  *@brief open popup with the search windows
00301  *@param p_dossier the dossier where to search
00302  *@param p_style style of the detail value are E for expert or S for simple
00303  */
00304 function popup_recherche(p_dossier)
00305 {
00306     var w = window.open("recherche.php?gDossier=" + p_dossier + "&ac=SEARCH", '', 'statusbar=no,scrollbars=yes,toolbar=no');
00307     w.focus();
00308 }
00309 /**
00310  *@brief replace the special characters (><'") by their HTML representation
00311  *@return a string without the offending char.
00312  */
00313 function unescape_xml(code_html)
00314 {
00315     code_html = code_html.replace(/\&lt;/, '<');
00316     code_html = code_html.replace(/\&gt;/, '>');
00317     code_html = code_html.replace(/\&quot;/, '"');
00318     code_html = code_html.replace(/\&apos;/, "'");
00319     code_html = code_html.replace(/\&amp;/, '&');
00320     return code_html;
00321 }
00322 /**
00323  *@brief Firefox splits the XML into 4K chunk, so to retrieve everything we need
00324  * to get the different parts thanks textContent
00325  *@param xmlNode a node (result of var data = =answer.getElementsByTagName('code'))
00326  *@return all the content of the XML node
00327  */
00328 function getNodeText(xmlNode)
00329 {
00330     if (!xmlNode)
00331         return '';
00332     if (typeof (xmlNode.textContent) != "undefined")
00333     {
00334         return xmlNode.textContent;
00335     }
00336     if (xmlNode.firstChild && xmlNode.firstChild.nodeValue)
00337         return xmlNode.firstChild.nodeValue;
00338     return "";
00339 }
00340 /**
00341  *@brief change the periode in the calendar of the dashboard
00342  *@param object select
00343  */
00344 function change_month(obj)
00345 {
00346     var queryString = "gDossier=" + obj.gDossier + "&op=cal" + "&per=" + obj.value + "&t=" + obj.type_display;
00347     var action = new Ajax.Request(
00348             "ajax_misc.php", {method: 'get', parameters: queryString, onFailure: ajax_misc_failure, onSuccess: success_misc}
00349     );
00350 
00351 }
00352 /**
00353  *@brief basic answer to ajax on success, it will fill the DOMID code with
00354  * the code. In that case, you need to create the object before the Ajax.Request
00355  *The difference with success box is that
00356  *@see add_div removeDiv success_box is that the width and height are not changed ajax_misc.php
00357  *@parameter code is the ID of the object containing the html (div, button...)
00358  *@parameter value is the html code, with it you fill the ctl element
00359  */
00360 
00361 function success_misc(req)
00362 {
00363     try
00364     {
00365         var answer = req.responseXML;
00366         var html = answer.getElementsByTagName('code');
00367         if (html.length === 0)
00368         {
00369             var rec = req.responseText;
00370             alert('erreur :' + rec);
00371         }
00372         var nodeXml = html[0];
00373         var code_html = getNodeText(nodeXml);
00374         code_html = unescape_xml(code_html);
00375         $("user_cal").innerHTML = code_html;
00376     }
00377     catch (e)
00378     {
00379         alert(e.message);
00380     }
00381     try
00382     {
00383         code_html.evalScripts();
00384     }
00385     catch (e)
00386     {
00387         alert("Impossible executer script de la reponse\n" + e.message);
00388     }
00389 
00390 
00391 }
00392 function loading()
00393 {
00394     var str = '<h2> Un instant ...</h2>';
00395     str = str + '<image src="image/loading.gif" alt="chargement"></image>';
00396     return str;
00397 }
00398 
00399 function ajax_misc_failure()
00400 {
00401     alert('Ajax Misc failed');
00402 }
00403 /**
00404  *@brief remove a document_modele
00405  */
00406 function cat_doc_remove(p_dt_id, p_dossier)
00407 {
00408     var queryString = "gDossier=" + p_dossier + "&op=rem_cat_doc" + "&dt_id=" + p_dt_id;
00409     var action = new Ajax.Request(
00410             "ajax_misc.php", {method: 'get', parameters: queryString, onFailure: ajax_misc_failure, onSuccess: success_cat_doc_remove}
00411     );
00412 }
00413 /**
00414  *@brief change a document_modele
00415  */
00416 function cat_doc_change(p_dt_id, p_dossier)
00417 {
00418     var queryString = "gDossier=" + p_dossier + "&op=mod_cat_doc" + "&dt_id=" + p_dt_id;
00419     var nTop = calcy(posY);
00420     var nLeft = "200px";
00421     var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:50em;height:auto";
00422 
00423     removeDiv('change_doc_div');
00424     waiting_box();
00425     var action = new Ajax.Request(
00426             "ajax_misc.php",
00427             {
00428                 method: 'get', parameters: queryString,
00429                 onFailure: ajax_misc_failure,
00430                 onSuccess: function (req) {
00431                     remove_waiting_box();
00432                     add_div({id: 'change_doc_div', style: str_style, cssclass: 'inner_box', drag: "1"});
00433                     $('change_doc_div').innerHTML = req.responseText;
00434 
00435                 }
00436             }
00437     );
00438 }
00439 
00440 function success_cat_doc_remove(req)
00441 {
00442     try
00443     {
00444         var answer = req.responseXML;
00445         var html = answer.getElementsByTagName('dtid');
00446         if (html.length === 0)
00447         {
00448             var rec = req.responseText;
00449             alert('erreur :' + rec);
00450         }
00451         nodeXML = html[0];
00452         row_id = getNodeText(nodeXML);
00453         if (row_id === 'nok')
00454         {
00455             alert('Error');
00456             return;
00457         }
00458         $('row' + row_id).style.textDecoration = "line-through";
00459         $('X' + row_id).style.display = 'none';
00460     }
00461     catch (e)
00462     {
00463         alert(e.message);
00464     }
00465 }
00466 /**
00467  *@brief display the popup with vat and explanation
00468  *@param obj with 4 attributes gdossier, ctl,popup
00469  */
00470 function popup_select_tva(obj)
00471 {
00472     try
00473     {
00474         if ($('tva_select')) {
00475             removeDiv('tva_select');
00476         }
00477 
00478         var queryString = "gDossier=" + obj.gDossier + "&op=dsp_tva" + "&ctl=" + obj.ctl + '&popup=' + 'tva_select';
00479         if (obj.jcode)
00480             queryString += '&code=' + obj.jcode;
00481         if (obj.compute)
00482             queryString += '&compute=' + obj.compute;
00483 
00484         var action = new Ajax.Request(
00485                 "ajax_misc.php",
00486                 {method: 'get',
00487                     parameters: queryString,
00488                     onFailure: ajax_misc_failure,
00489                     onSuccess: function (req)
00490                     {
00491                         try
00492                         {
00493                             var answer = req.responseXML;
00494                             var popup = answer.getElementsByTagName('popup');
00495                             if (popup.length === 0)
00496                             {
00497                                 var rec = req.responseText;
00498                                 alert('erreur :' + rec);
00499                             }
00500                             var html = answer.getElementsByTagName('code');
00501 
00502                             var name_ctl = popup[0].firstChild.nodeValue;
00503                             var nodeXml = html[0];
00504                             var code_html = getNodeText(nodeXml);
00505                             code_html = unescape_xml(code_html);
00506 
00507                             var nTop = posY - 200;
00508                             var nLeft = "15%";
00509                             var str_style = "top:" + nTop + "px;left:" + nLeft + ";right:" + nLeft + ";width:55em;height:auto";
00510 
00511                             var popup = {'id': 'tva_select', 'cssclass': 'inner_box', 'style': str_style, 'html': code_html, 'drag': true};
00512                             add_div(popup);
00513 
00514                         }
00515                         catch (e)
00516                         {
00517                             alert("success_popup_select_tva " + e.message);
00518                         }
00519                     }
00520                 }
00521         );
00522     }
00523     catch (e)
00524     {
00525         alert("popup_select_tva " + e.message);
00526     }
00527 }
00528 /**
00529  *@brief display the popup with vat and explanations
00530  *@obsolete
00531  */
00532 function success_popup_select_tva_obsolete(req)
00533 {
00534 
00535 
00536 }
00537 
00538 /**
00539  *@brief display the popup with vat and explanation
00540  *@param obj with 4 attributes gdossier, ctl,popup
00541  */
00542 function set_tva_label(obj)
00543 {
00544     try
00545     {
00546         var queryString = "gDossier=" + obj.gDossier + "&op=label_tva" + "&id=" + obj.value;
00547         if (obj.jcode)
00548             queryString += '&code=' + obj.jcode;
00549         var action = new Ajax.Request(
00550                 "ajax_misc.php",
00551                 {method: 'get',
00552                     parameters: queryString,
00553                     onFailure: ajax_misc_failure,
00554                     onSuccess: success_set_tva_label
00555                 }
00556         );
00557     }
00558     catch (e)
00559     {
00560         alert("set_tva_label " + e.message);
00561     }
00562 }
00563 /**
00564  *@brief display the popup with vat and explanations
00565  */
00566 function success_set_tva_label(req)
00567 {
00568     try
00569     {
00570         var answer = req.responseXML;
00571         var code = answer.getElementsByTagName('code');
00572         var value = answer.getElementsByTagName('value');
00573 
00574         if (code.length === 0)
00575         {
00576             var rec = req.responseText;
00577             alert('erreur :' + rec);
00578         }
00579 
00580         var label_code = code[0].firstChild.nodeValue;
00581         var label_value = value[0].firstChild.nodeValue;
00582         set_value(label_code, label_value);
00583     }
00584     catch (e)
00585     {
00586         alert("success_set_tva_label " + e.message);
00587     }
00588 
00589 }
00590 /**
00591  *@brief set loading for waiting
00592  *@param name of ipopup
00593  *@see showIPopup
00594  *@obsolete
00595  */
00596 function set_wait_obsolete(name)
00597 {
00598     var content = name + "_content";
00599     $(content).innerHTML = 'Un instant...<image src="image/loading.gif" border="0" alt="Chargement...">';
00600 }
00601 /**
00602  *@brief add dynamically a object for AJAX
00603  *@param obj.
00604  * the attributes are
00605  *   - style to add style
00606  *   - id to add an id
00607  *   - cssclass to add a class
00608  *   - html is the content
00609  *   - drag is the div can be moved
00610  */
00611 function add_div(obj)
00612 {
00613     try
00614     {
00615         var top = document;
00616 
00617         if (!$(obj.id)) {
00618             var elt = top.createElement('div');
00619         }
00620         else {
00621             var elt = $(obj.id);
00622         }
00623         if (obj.id)
00624         {
00625             elt.setAttribute('id', obj.id);
00626         }
00627         if (obj.style)
00628         {
00629             if (elt.style.setAttribute)
00630             { /* IE7 bug */
00631                 elt.style.setAttribute('cssText', obj.style);
00632             }
00633             else
00634             { /* good Browser */
00635                 elt.setAttribute('style', obj.style);
00636             }
00637         }
00638         if (obj.cssclass)
00639         {
00640             elt.setAttribute('class', obj.cssclass);/* FF */
00641             elt.setAttribute('className', obj.cssclass); /* IE */
00642         }
00643         if (obj.html)
00644         {
00645             elt.innerHTML = obj.html;
00646         }
00647 
00648         var bottom_div = document.body;
00649         bottom_div.appendChild(elt);
00650         /* if ( obj.effect && obj.effect != 'none' ) { Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }
00651          else if ( ! obj.effect ){ Effect.Grow(obj.id,{direction:'top-right',duration:0.1}); }*/
00652         if (obj.drag)
00653         {
00654             new Draggable(obj.id, {starteffect: function ()
00655                 {
00656                     new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
00657                 }}
00658             );
00659         }
00660         /* elt.setStyle({visibility:'visible'}); */
00661         elt.style.visibility='visible';
00662     }
00663     catch (e)
00664     {
00665         alert("add_div " + e.message);
00666     }
00667 }
00668 /**
00669  * remove a object created with add_div
00670  * @param elt id of the elt
00671  */
00672 function removeDiv(elt)
00673 {
00674     if (g(elt))
00675     {
00676         document.body.removeChild(g(elt));
00677     }
00678     // if reloaded if asked the window will be reloaded when
00679     // the box is closed
00680     if (ask_reload === 1)
00681     {
00682         // avoid POST window.location = window.location.href;
00683         window.location.reload();
00684     }
00685 }
00686 /**
00687  *show a box while loading
00688  *must be remove when ajax is successfull
00689  * the id is wait_box
00690  */
00691 function waiting_box()
00692 {
00693     obj = {
00694         id: 'wait_box', html: '<h2 class="title">Chargement</h2>' + loading()
00695     };
00696     var y = fixed_position(10, 250)
00697     obj.style = y + ";width:20%;margin-left:40%;";
00698     if ($('wait_box')) {
00699         removeDiv('wait_box');
00700     }
00701     obj.effect = 'none';
00702     add_div(obj);
00703     $('info_div').innerHTML = 'Un instant';
00704     $('info_div').style.display = "block";
00705 
00706 }
00707 /**
00708  *@brief call add_div to add a DIV and after call the ajax
00709  * the queryString, the callback for function for success and error management
00710  * the method is always GET
00711  *@param obj, the mandatory attributes are
00712  *  - obj.qs querystring
00713  *  - obj.js_success callback function in javascript for handling the xml answer
00714  *  - obj.js_error callback function for error
00715  *  - obj.callback the php file to call
00716  *  - obj.fixed optional let you determine the position, otherwise works like IPopup
00717  *@see add_div IBox
00718  */
00719 function show_box(obj)
00720 {
00721     add_div(obj);
00722     if (!obj.fixed)
00723     {
00724         var sx = 0;
00725         if (window.scrollY)
00726         {
00727             sx = window.scrollY + 40;
00728         }
00729         else
00730         {
00731             sx = document.body.scrollTop + 40;
00732         }
00733         g(obj.id).style.top = sx + "px";
00734         show(obj.id);
00735     }
00736     else
00737     {
00738         show(obj.id);
00739     }
00740 
00741     var action = new Ajax.Request(
00742             obj.callback,
00743             {
00744                 method: 'GET',
00745                 parameters: obj.qs,
00746                 onFailure: eval(obj.js_error),
00747                 onSuccess: eval(obj.js_success)
00748             });
00749 }
00750 /**
00751  *@brief receive answer from ajax and just display it into the IBox
00752  * XML must contains at least 2 fields : ctl is the ID of the IBOX and
00753  * code is the HTML to put in it
00754  *@see fill_box
00755  */
00756 function success_box(req, json)
00757 {
00758     try
00759     {
00760         var answer = req.responseXML;
00761         var a = answer.getElementsByTagName('ctl');
00762         var html = answer.getElementsByTagName('code');
00763         if (a.length === 0)
00764         {
00765             var rec = req.responseText;
00766             alert('erreur :' + rec);
00767         }
00768         var name_ctl = a[0].firstChild.nodeValue;
00769         var code_html = getNodeText(html[0]);
00770 
00771         code_html = unescape_xml(code_html);
00772         g(name_ctl).innerHTML = code_html;
00773         g(name_ctl).style.height = 'auto';
00774 
00775         if (name_ctl == 'popup')
00776             g(name_ctl).style.width = 'auto';
00777     }
00778     catch (e)
00779     {
00780         alert("success_box" + e.message);
00781     }
00782     try
00783     {
00784         code_html.evalScripts();
00785     }
00786     catch (e)
00787     {
00788         alert("answer_box Impossible executer script de la reponse\n" + e.message);
00789     }
00790 }
00791 
00792 function error_box()
00793 {
00794     alert('[error_box] ajax not implemented');
00795 }
00796 /**
00797  * show the ledger choice
00798  */
00799 function show_ledger_choice(json_obj)
00800 {
00801     try
00802     {
00803         waiting_box();
00804         var i = 0;
00805         var query = "gDossier=" + json_obj.dossier + '&type=' + json_obj.type + '&div=' + json_obj.div + '&op=ledger_show';
00806         query = query + '&nbjrn=' + $(json_obj.div + 'nb_jrn').value;
00807         query = query + '&all_type=' + json_obj.all_type;
00808         for (i = 0; i < $(json_obj.div + 'nb_jrn').value; i++) {
00809             query = query + "&r_jrn[]=" + $(json_obj.div + 'r_jrn[' + i + ']').value;
00810         }
00811         var action = new Ajax.Request(
00812                 "ajax_misc.php",
00813                 {method: 'get',
00814                     parameters: query,
00815                     onFailure: ajax_misc_failure,
00816                     onSuccess: function (req, json) {
00817                         try {
00818                             var obj = {
00819                                 id: json_obj.div + 'jrn_search',
00820                                 cssclass: 'inner_box',
00821                                 style: ';position:absolute;width:60%;z-index:20;margin-left:20%',
00822                                 drag: 1
00823                             };
00824                             //var y=calcy(posY);
00825                             var y = posY;
00826                             if (json_obj.div != '')
00827                                 obj.cssclass = "";
00828                             obj.style = "top:" + y + 'px;' + obj.style;
00829                             /* if ( json_obj.class ) 
00830                              { 
00831                              obj.cssclass=json_obj.class;
00832                              }*/
00833                             add_div(obj);
00834 
00835 
00836                             var answer = req.responseXML;
00837                             var a = answer.getElementsByTagName('ctl');
00838                             var html = answer.getElementsByTagName('code');
00839                             if (a.length === 0) {
00840                                 var rec = req.responseText;
00841                                 alert('erreur :' + rec);
00842                             }
00843                             var name_ctl = a[0].firstChild.nodeValue;
00844                             var code_html = getNodeText(html[0]);
00845 
00846                             code_html = unescape_xml(code_html);
00847                             remove_waiting_box();
00848                             g(obj.id).innerHTML = code_html;
00849 
00850                         }
00851                         catch (e) {
00852                             alert("show_ledger_callback" + e.message);
00853                         }
00854                         try {
00855                             code_html.evalScripts();
00856                         }
00857                         catch (e) {
00858                             alert("answer_box Impossible executer script de la reponse\n" + e.message);
00859                         }
00860 
00861                     }
00862 
00863                 }
00864         );
00865     } catch (e) {
00866         alert('show_ledger_choice' + e.message);
00867     }
00868 }
00869 /**
00870  * hide the ledger choice
00871  */
00872 function hide_ledger_choice(p_frm_search)
00873 {
00874     try
00875     {
00876         var nb = $(p_frm_search).nb_jrn.value;
00877         var div = $(p_frm_search).div.value;
00878         var i = 0;
00879         var str = "";
00880         var name = "";
00881         var n_name = "";
00882         var sel = 0;
00883         for (i = 0; i < nb; i++) {
00884             n_name = div + "r_jrn[" + sel + "]";
00885             name = div + "r_jrn" + i;
00886             if ($(name).checked) {
00887                 str += '<input type="hidden" id="' + n_name + '" name="' + n_name + '" value="' + $(name).value + '">';
00888                 sel++;
00889             }
00890         }
00891         str += '<input type="hidden" name="' + div + 'nb_jrn" id="' + div + 'nb_jrn" value="' + sel + '">';
00892         $('ledger_id' + div).innerHTML = str;
00893         removeDiv(div + 'jrn_search');
00894         return false;
00895     } catch (e) {
00896         alert('hide_ledger_choice' + e.message);
00897         return false;
00898     }
00899 
00900 }
00901 /**
00902  * show the cat of ledger choice
00903  */
00904 function show_cat_choice()
00905 {
00906     g('div_cat').style.visibility = 'visible';
00907 }
00908 /**
00909  * hide the cat of ledger choice
00910  */
00911 function hide_cat_choice()
00912 {
00913     g('div_cat').style.visibility = 'hidden';
00914 }
00915 /**
00916  * add a row for the forecast item
00917  */
00918 function for_add_row(tableid)
00919 {
00920     style = 'class="input_text"';
00921     var mytable = g(tableid).tBodies[0];
00922     var nNumberRow = mytable.rows.length;
00923     var oRow = mytable.insertRow(nNumberRow);
00924     var rowToCopy = mytable.rows[1];
00925     var nNumberCell = rowToCopy.cells.length;
00926     var nb = g("nbrow");
00927     var oNewRow = mytable.insertRow(nNumberRow);
00928     for (var e = 0; e < nNumberCell; e++)
00929     {
00930         var newCell = oRow.insertCell(e);
00931         var tt = rowToCopy.cells[e].innerHTML;
00932         new_tt = tt.replace(/an_cat0/g, "an_cat" + nb.value);
00933         new_tt = new_tt.replace(/an_cat_acc0/g, "an_cat_acc" + nb.value);
00934         new_tt = new_tt.replace(/an_qc0/g, "an_qc" + nb.value);
00935         new_tt = new_tt.replace(/an_label0/g, "an_label" + nb.value);
00936         new_tt = new_tt.replace(/month0/g, "month" + nb.value);
00937         new_tt = new_tt.replace(/an_cat_amount0/g, "an_cat_amount" + nb.value);
00938         new_tt = new_tt.replace(/an_deb0/g, "an_deb" + nb.value);
00939         newCell.innerHTML = new_tt;
00940         new_tt.evalScripts();
00941     }
00942     $("an_cat_acc" + nb.value).value = "";
00943     $("an_qc" + nb.value).value = "";
00944     $("an_label" + nb.value).value = "";
00945     $("an_cat_amount" + nb.value).value = "0";
00946     nb.value++;
00947 }
00948 /**
00949  * toggle all the checkbox in a given form
00950  * @param form_id id of the form
00951  */
00952 function toggle_checkbox(form_id)
00953 {
00954     var form = g(form_id);
00955     for (var i = 0; i < form.length; i++)
00956     {
00957         var e = form.elements[i];
00958         if (e.type === 'checkbox')
00959         {
00960             if (e.checked === true)
00961             {
00962                 e.checked = false;
00963             }
00964             else
00965             {
00966                 e.checked = true;
00967             }
00968         }
00969     }
00970 }
00971 /**
00972  * select all the checkbox in a given form
00973  * @param form_id id of the form
00974  */
00975 function select_checkbox(form_id)
00976 {
00977     var form = $(form_id);
00978     for (var i = 0; i < form.length; i++)
00979     {
00980         var e = form.elements[i];
00981         if (e.type === 'checkbox')
00982         {
00983             e.checked = true;
00984         }
00985     }
00986 }
00987 /**
00988  * unselect all the checkbox in a given form
00989  * @param form_id id of the form
00990  */
00991 function unselect_checkbox(form_id)
00992 {
00993     var form = $(form_id);
00994     for (var i = 0; i < form.length; i++)
00995     {
00996         var e = form.elements[i];
00997         if (e.type === 'checkbox')
00998         {
00999             e.checked = false;
01000         }
01001     }
01002 }
01003 /**
01004  * show the calculator
01005  */
01006 function show_calc()
01007 {
01008     if (g('calc1'))
01009     {
01010         this.document.getElementById('inp').value = "";
01011         this.document.getElementById('inp').focus();
01012         return;
01013     }
01014     var sid = 'calc1';
01015     var shtml = '';
01016     shtml += '<div style="float:right;height:10px;display:block;margin-top:2px;margin-right:2px">       <a onclick="removeDiv(\'calc1\');" href="javascript:void(0)" id="close_div">Fermer</a></div>';
01017     shtml += '<div>   <h2 class="info">Calculatrice</h2></div>';
01018     shtml += '<form name="calc_line"  method="GET" onSubmit="cal();return false;" >Calculatrice simplifiée: écrivez simplement les opérations que vous voulez puis la touche retour. exemple : 1+2+3*(1/5) <input class="input_text" type="text" size="30" id="inp" name="calculator"> <input type="button" value="Efface tout" class="button" onClick="Clean();return false;" > <input type="button" class="button" value="Fermer" onClick="removeDiv(\'calc1\')" >';
01019     shtml += '</form><span id="result">  </span><br><span id="sub_total">  Taper une formule (ex 20*5.1) puis enter  </span><br><span id="listing"> </span>';
01020 
01021     var obj = {id: sid, html: shtml,
01022         drag: true, style: ''
01023     };
01024     add_div(obj);
01025     this.document.getElementById('inp').focus();
01026 }
01027 function display_periode(p_dossier, p_id)
01028 {
01029 
01030     try
01031     {
01032         var queryString = "gDossier=" + p_dossier + "&op=input_per" + "&p_id=" + p_id;
01033         var popup = {'id': 'mod_periode', 'cssclass': 'inner_box', 'html': loading(), 'style': 'width:30em', 'drag': true};
01034         if (!$('mod_periode')) {
01035             add_div(popup);
01036         }
01037         var action = new Ajax.Request(
01038                 "ajax_misc.php",
01039                 {method: 'get',
01040                     parameters: queryString,
01041                     onFailure: ajax_misc_failure,
01042                     onSuccess: success_display_periode
01043                 }
01044         );
01045         $('mod_periode').style.top = (posY - 70) + "px";
01046         $('mod_periode').style.left = (posX - 70) + "px";
01047     }
01048     catch (e)
01049     {
01050         alert("display_periode " + e.message);
01051     }
01052 
01053 }
01054 function success_display_periode(req)
01055 {
01056     try
01057     {
01058 
01059         var answer = req.responseXML;
01060         var html = answer.getElementsByTagName('data');
01061 
01062         if (html.length === 0)
01063         {
01064             var rec = req.responseText;
01065             alert('erreur :' + rec);
01066         }
01067 
01068         var code_html = getNodeText(html[0]);
01069         code_html = unescape_xml(code_html);
01070 
01071         $('mod_periode').innerHTML = code_html;
01072     }
01073     catch (e)
01074     {
01075         alert("success_display_periode".e.message);
01076     }
01077     try
01078     {
01079         code_html.evalScripts();
01080     }
01081     catch (e)
01082     {
01083         alert("success_display_periode Impossible executer script de la reponse\n" + e.message);
01084     }
01085 
01086 }
01087 function save_periode(obj)
01088 {
01089     try
01090     {
01091         var queryString = $(obj).serialize() + "&op=save_per";
01092 
01093         var action = new Ajax.Request(
01094                 "ajax_misc.php",
01095                 {method: 'post',
01096                     parameters: queryString,
01097                     onFailure: ajax_misc_failure,
01098                     onSuccess: success_display_periode
01099                 }
01100         );
01101 
01102     }
01103     catch (e)
01104     {
01105         alert("display_periode " + e.message);
01106     }
01107 
01108     return false;
01109 }
01110 /**
01111  *@brief basic answer to ajax on success, it will fill the ctl with
01112  * the code. In that case, you need to create the object before the Ajax.Request
01113  *The difference with success box is that
01114  *@see add_div removeDiv success_box is that the width and height are not changed
01115  *@parameter ctl is the ID of the object containing the html (div, button...)
01116  *@parameter code is the html code, with it you fill the ctl element
01117  */
01118 function fill_box(req)
01119 {
01120     try {
01121 
01122         remove_waiting_box();
01123 
01124         var answer = req.responseXML;
01125         var a = answer.getElementsByTagName('ctl');
01126         var html = answer.getElementsByTagName('code');
01127         if (a.length === 0) {
01128             var rec = req.responseText;
01129             alert('erreur :' + rec);
01130         }
01131         var name_ctl = a[0].firstChild.nodeValue;
01132         var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
01133         code_html = unescape_xml(code_html);
01134         $(name_ctl).innerHTML = code_html;
01135     }
01136     catch (e) {
01137         alert(e.message);
01138     }
01139     try {
01140         code_html.evalScripts();
01141     }
01142     catch (e) {
01143         alert("Impossible executer script de la reponse\n" + e.message);
01144     }
01145 
01146 
01147 }
01148 /**
01149  *display a popin to  let you modified a predefined operation
01150  *@param dossier_id
01151  *@param od_id from table op_predef
01152  */
01153 function mod_predf_op(dossier_id, od_id)
01154 {
01155     var target = "mod_predf_op";
01156     removeDiv(target);
01157     var sx = '20%';
01158     var sy = '10%';
01159     var str_style = "top:" + sx + ";left:" + sy + ";";
01160 
01161     var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
01162 
01163     add_div(div);
01164 
01165     var qs = "gDossier=" + dossier_id + '&op=mod_predf&id=' + od_id;
01166 
01167     var action = new Ajax.Request('ajax_misc.php',
01168             {
01169                 method: 'get',
01170                 parameters: qs,
01171                 onFailure: null,
01172                 onSuccess: fill_box
01173             }
01174     );
01175 
01176 }
01177 
01178 function save_predf_op(obj)
01179 {
01180     waiting_box();
01181     var querystring = $(obj).serialize() + '&op=save_predf';
01182     // Create a ajax request to get all the person
01183     var action = new Ajax.Request('ajax_misc.php',
01184             {
01185                 method: 'post',
01186                 parameters: querystring,
01187                 onFailure: null,
01188                 onSuccess: refresh_window
01189             }
01190     );
01191 
01192     return false;
01193 }
01194 
01195 /**
01196  *ctl_concern is the widget to update
01197  *amount_id is either a html obj. or an amount and the field tiers if given
01198  * @param {type} dossier
01199  * @param {type} ctl_concern
01200  * @param {type} amount_id
01201  * @param {type} ledger
01202  * @param {type} p_id_target
01203  * @returns {undefined}
01204  */
01205 function search_reconcile(dossier, ctl_concern, amount_id, ledger, p_id_target)
01206 {
01207     var dossier = g('gDossier').value;
01208     if (amount_id === undefined)
01209     {
01210         amount_id = 0;
01211     }
01212     else if ($(amount_id))
01213     {
01214         if ($(amount_id).value)
01215         {
01216             amount_id = $(amount_id).value;
01217         }
01218         else if
01219                 ($(amount_id).innerHTML) {
01220             amount_id = $(amount_id).innerHTML;
01221         }
01222     }
01223 
01224     var target = "search_op";
01225     removeDiv(target);
01226     var str_style = fixed_position(77, 99);
01227     str_style += ";width:92%;overflow:auto;";
01228     waiting_box();
01229 
01230     
01231     var target = {gDossier: dossier,
01232         ctlc: ctl_concern,
01233         op: 'search_op',
01234         ctl: target,
01235         ac: 'JSSEARCH',
01236         amount_id: amount_id,
01237         ledger: ledger,
01238         target: p_id_target};
01239 
01240     var qs = encodeJSON(target);
01241 
01242     var action = new Ajax.Request('ajax_misc.php',
01243             {
01244                 method: 'get',
01245                 parameters: qs,
01246                 onFailure: null,
01247                 onSuccess: function (req) {
01248                     remove_waiting_box();
01249                     var div = {id: 'search_op', cssclass: 'inner_box', style: str_style, drag: 1};
01250                     add_div(div);
01251                     $('search_op').innerHTML = req.responseText;
01252                     req.responseText.evalScripts();
01253                 }
01254             }
01255     );
01256 }
01257 /**
01258  * search in a popin obj if the object form
01259  */
01260 function search_operation(obj)
01261 {
01262     try {
01263         var dossier = g('gDossier').value;
01264         waiting_box();
01265         var target = "search_op";
01266         var qs = Form.serialize('search_form_ajx') + "&op=search_op&ctl=search_op";
01267         var action = new Ajax.Request('ajax_misc.php',
01268                 {
01269                     method: 'get',
01270                     parameters: qs,
01271                     onFailure: null,
01272                     onSuccess: function (req) {
01273                         remove_waiting_box();
01274                         $('search_op').innerHTML = req.responseText;
01275                         req.responseText.evalScripts();
01276                     }
01277                 }
01278         );
01279     } catch (e)
01280     {
01281         remove_waiting_box();
01282         alert(e.message);
01283     }
01284 }
01285 /**
01286  * Update the field e_concerned, from class_iconcerned
01287  * Value is the field where to put the quick-code but only if one checkbox has been
01288  * selected
01289  * @param {type} obj
01290  * @returns {undefined}
01291  */
01292 function set_reconcile(obj)
01293 {
01294 
01295     try
01296     {
01297         var ctlc = obj.elements['ctlc'];
01298         var target = obj.elements['target'].value;
01299         for (var e = 0; e < obj.elements.length; e++)
01300         {
01301 
01302             var elmt = obj.elements[e];
01303             if (elmt.type === "checkbox")
01304             {
01305                 if (elmt.checked === true)
01306                 {
01307                     var str_name = elmt.name;
01308                     var nValue = str_name.replace("jr_concerned", "");
01309                     if ($(ctlc.value).value != '') {
01310                         $(ctlc.value).value += ',';
01311 
01312                     } else {
01313                         if (target != "" && $(target).value == "") {
01314                             $(target).value = elmt.value;
01315                         }
01316                     }
01317                     $(ctlc.value).value += nValue;
01318                 }
01319             }
01320         }
01321         removeDiv('search_op');
01322     }
01323     catch (e)
01324     {
01325         alert(e.message)
01326     }
01327 }
01328 function remove_waiting_box()
01329 {
01330     removeDiv('wait_box');
01331     $('info_div').innerHTML = "";
01332     $('info_div').style.display = "none";
01333 }
01334 function get_profile_detail(gDossier, profile_id)
01335 {
01336     waiting_box();
01337     var qs = "op=display_profile&gDossier=" + gDossier + "&p_id=" + profile_id + "&ctl=detail_profile";
01338     var action = new Ajax.Request('ajax_misc.php',
01339             {
01340                 method: 'get',
01341                 parameters: qs,
01342                 onFailure: null,
01343                 onSuccess: function (req) {
01344                     remove_waiting_box();
01345                     $('detail_profile').innerHTML = req.responseText;
01346                     req.responseText.evalScripts();
01347                     $('detail_profile').show();
01348                     if (profile_id != "-1")
01349                         profile_show('profile_gen_div');
01350                 }
01351             }
01352     );
01353 }
01354 function get_profile_detail_success_obsolete(xml)
01355 {
01356     remove_waiting_box();
01357 
01358 }
01359 /**
01360  * @brief compute the string to position a div in a fixed way
01361  * @return string
01362  */
01363 function fixed_position(p_sx, p_sy)
01364 {
01365     var sx = p_sx;
01366     var sy = calcy(p_sy);
01367 
01368     var str_style = "top:" + sy + "px;left:" + sx + "px;position:absolute";
01369     return str_style;
01370 
01371 }
01372 /**
01373  *@brief compute Y even if the windows has scrolled down or up
01374  *@return the correct Y position
01375  */
01376 function calcy(p_sy)
01377 {
01378     var sy = p_sy;
01379     if (window.scrollY)
01380     {
01381         sy = window.scrollY + p_sy;
01382     }
01383     else
01384     {
01385         sy = document.body.scrollTop + p_sy;
01386     }
01387     return sy;
01388 
01389 }
01390 function mod_menu(gdossier, pm_id)
01391 {
01392     waiting_box();
01393     removeDiv('divdm' + pm_id);
01394     var qs = "op=det_menu&gDossier=" + gdossier + "&pm_id=" + pm_id + "&ctl=divdm" + pm_id;
01395     var pos = fixed_position(50, 250);
01396     var action = new Ajax.Request('ajax_misc.php',
01397             {
01398                 method: 'get',
01399                 parameters: qs,
01400                 onFailure: null,
01401                 onSuccess: function (req) {
01402                     try {
01403                         remove_waiting_box();
01404                         add_div({id: "divdm" + pm_id, drag: 1, cssclass: "inner_box", style: pos});
01405                         $('divdm' + pm_id).innerHTML = req.responseText;
01406                     } catch (e) {
01407                         alert(e.message);
01408                     }
01409                 }
01410             }
01411     );
01412 }
01413 function add_menu(obj)
01414 {
01415     var pdossier = obj.dossier;
01416     var p_id = obj.p_id;
01417     var p_type = obj.type;
01418     waiting_box();
01419     removeDiv('divdm' + p_id);
01420     var qs = "op=add_menu&gDossier=" + pdossier + "&p_id=" + p_id + "&ctl=divdm" + p_id + "&type=" + p_type;
01421     var pos = fixed_position(250, 150);
01422     var action = new Ajax.Request('ajax_misc.php',
01423             {
01424                 method: 'get',
01425                 parameters: qs,
01426                 onFailure: null,
01427                 onSuccess: function (req) {
01428                     try {
01429                         remove_waiting_box();
01430                         add_div({id: "divdm" + p_id, drag: 1, cssclass: "inner_box", style: pos});
01431                         $('divdm' + p_id).innerHTML = req.responseText;
01432                     } catch (e) {
01433                         alert(e.message);
01434                     }
01435                 }
01436             }
01437     );
01438 }
01439 function add_plugin(p_dossier)
01440 {
01441     waiting_box();
01442     removeDiv('divplugin');
01443     var qs = "op=add_plugin&gDossier=" + p_dossier + "&ctl=divplugin";
01444 
01445     var action = new Ajax.Request('ajax_misc.php',
01446             {
01447                 method: 'get',
01448                 parameters: qs,
01449                 onFailure: null,
01450                 onSuccess: function (req) {
01451                     try {
01452                         remove_waiting_box();
01453                         var pos = fixed_position(250, 150) + ";width:30%";
01454                         add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
01455                         $('divplugin').innerHTML = req.responseText;
01456                     } catch (e) {
01457                         alert(e.message);
01458                     }
01459                 }
01460             }
01461     );
01462 }
01463 function mod_plugin(p_dossier, me_code)
01464 {
01465     waiting_box();
01466     removeDiv('divplugin');
01467     var qs = "op=mod_plugin&gDossier=" + p_dossier + "&ctl=divplugin&me_code=" + me_code;
01468 
01469     var action = new Ajax.Request('ajax_misc.php',
01470             {
01471                 method: 'get',
01472                 parameters: qs,
01473                 onFailure: null,
01474                 onSuccess: function (req) {
01475                     try {
01476                         remove_waiting_box();
01477                         var pos = fixed_position(250, 150) + ";width:30%";
01478                         add_div({id: "divplugin", drag: 1, cssclass: "inner_box", style: pos});
01479                         $('divplugin').innerHTML = req.responseText;
01480 
01481                     } catch (e) {
01482                         alert(e.message);
01483                     }
01484                 }
01485             }
01486     );
01487 }
01488 function create_menu(p_dossier)
01489 {
01490     waiting_box();
01491     removeDiv('divmenu');
01492     var qs = "op=create_menu&gDossier=" + p_dossier + "&ctl=divmenu";
01493 
01494     var action = new Ajax.Request('ajax_misc.php',
01495             {
01496                 method: 'get',
01497                 parameters: qs,
01498                 onFailure: null,
01499                 onSuccess: function (req) {
01500                     try {
01501                         remove_waiting_box();
01502                         var pos = fixed_position(250, 150) + ";width:30%";
01503                         add_div({
01504                             id: "divmenu",
01505                             drag: 1,
01506                             cssclass: "inner_box",
01507                             style: pos
01508                         });
01509                         $('divmenu').innerHTML = req.responseText;
01510                     } catch (e) {
01511                         alert(e.message);
01512                     }
01513                 }
01514             }
01515     );
01516 }
01517 function modify_menu(p_dossier, me_code)
01518 {
01519     waiting_box();
01520     removeDiv('divmenu');
01521     var qs = "op=modify_menu&gDossier=" + p_dossier + "&ctl=divmenu&me_code=" + me_code;
01522 
01523     var action = new Ajax.Request('ajax_misc.php',
01524             {
01525                 method: 'get',
01526                 parameters: qs,
01527                 onFailure: null,
01528                 onSuccess: function (req) {
01529                     try {
01530                         remove_waiting_box();
01531                         var pos = fixed_position(250, 150) + ";width:30%";
01532                         add_div({
01533                             id: "divmenu",
01534                             drag: 1,
01535                             cssclass: "inner_box",
01536                             style: pos
01537                         });
01538                         $('divmenu').innerHTML = req.responseText;
01539 
01540                     } catch (e) {
01541                         alert(e.message);
01542                     }
01543                 }
01544             }
01545     );
01546 }
01547 function get_properties(obj)
01548 {
01549     var a_array = [];
01550     var s_type = "[" + typeof obj + "]";
01551     for (var m in obj)
01552     {
01553         a_array.push(m);
01554     }
01555     alert(s_type + a_array.join(","));
01556 }
01557 /**
01558  * @brief add a line in the form for the report
01559  * @param p_dossier dossier id to connect
01560  */
01561 function rapport_add_row(p_dossier)
01562 {
01563     style = 'style="border: 1px solid blue;"';
01564     var table = $("rap1");
01565     var line = table.rows.length;
01566 
01567     var row = table.insertRow(line);
01568     // left cell
01569     var cellPos = row.insertCell(0);
01570     cellPos.innerHTML = '<input type="text" ' + style + ' size="3" id="pos' + line + '" name="pos' + line + '" value="' + line + '">';
01571 
01572     // right cell
01573     var cellName = row.insertCell(1);
01574     cellName.innerHTML = '<input type="text" ' + style + ' size="40" id="text' + line + '" name="text' + line + '">';
01575 
01576     // button + formula
01577     var cellbutton = row.insertCell(2);
01578     var but_html = table.rows[1].cells[2].innerHTML;
01579     but_html = but_html.replace(/form0/g, "form" + line);
01580     cellbutton.innerHTML = but_html;
01581     but_html.evalScripts();
01582 
01583     g('form' + line).value = '';
01584 }
01585 /**
01586  * Search an action in an inner box
01587  */
01588 function search_action(dossier, ctl_concern)
01589 {
01590     try
01591     {
01592         var dossier = g('gDossier').value;
01593 
01594         var target = "search_action_div";
01595         removeDiv(target);
01596         var str_style = fixed_position(77, 99);
01597 
01598         var div = {id: target, cssclass: 'inner_box', style: str_style, html: loading(), drag: 1};
01599 
01600         add_div(div);
01601         var target = {gDossier: dossier,
01602             ctlc: ctl_concern,
01603             op: 'search_action',
01604             ctl: target
01605         };
01606 
01607         var qs = encodeJSON(target);
01608 
01609         var action = new Ajax.Request('ajax_misc.php',
01610                 {
01611                     method: 'get',
01612                     parameters: qs,
01613                     onFailure: null,
01614                     onSuccess: function (req) {
01615                         try {
01616                             remove_waiting_box();
01617                             $('search_action_div').innerHTML = req.responseText;
01618                             req.responseText.evalScripts();
01619                         } catch (e) {
01620                             alert(e.message);
01621                         }
01622                     }
01623                 }
01624         );
01625     } catch (e) {
01626         alert(e.message);
01627     }
01628 }
01629 
01630 function result_search_action(obj)
01631 {
01632     try
01633     {
01634         var queryString = $(obj).serialize() + "&op=search_action";
01635         var action = new Ajax.Request(
01636                 "ajax_misc.php",
01637                 {method: 'get',
01638                     parameters: queryString,
01639                     onFailure: ajax_misc_failure,
01640                     onSuccess: function (req) {
01641                         try {
01642                             remove_waiting_box();
01643                             $('search_action_div').innerHTML = req.responseText;
01644                             req.responseText.evalScripts();
01645                         } catch (e) {
01646                             alert(e.message);
01647                         }
01648                     }
01649                 }
01650         )
01651 
01652     }
01653     catch (e)
01654     {
01655         alert("display_periode " + e.message);
01656     }
01657 
01658     return false;
01659 }
01660 
01661 function set_action_related(p_obj)
01662 {
01663 
01664     try
01665     {
01666         var obj = $(p_obj);
01667         var ctlc = obj.elements['ctlc'];
01668 
01669         for (var e = 0; e < obj.elements.length; e++)
01670         {
01671 
01672             var elmt = obj.elements[e];
01673             if (elmt.type === "checkbox")
01674             {
01675                 if (elmt.checked === true)
01676                 {
01677                     var str_name = elmt.name;
01678                     var nValue = elmt.value;
01679                     if ($(ctlc.value).value != '') {
01680                         $(ctlc.value).value += ',';
01681                     }
01682                     $(ctlc.value).value += nValue;
01683                 }
01684             }
01685         }
01686         removeDiv('search_action_div');
01687         return false;
01688     }
01689     catch (e)
01690     {
01691         alert(e.message);
01692         return false;
01693     }
01694 }
01695 /**
01696  *@brief change a document_modele
01697  */
01698 function stock_repo_change(p_dossier, r_id)
01699 {
01700     var queryString = "gDossier=" + p_dossier + "&op=mod_stock_repo" + "&r_id=" + r_id;
01701     var nTop = calcy(posY);
01702     var nLeft = "200px";
01703     var str_style = "top:" + nTop + "px;left:" + nLeft + ";height:auto";
01704 
01705     removeDiv('change_stock_repo_div');
01706     waiting_box();
01707     var action = new Ajax.Request(
01708             "ajax_misc.php",
01709             {
01710                 method: 'get', parameters: queryString,
01711                 onFailure: ajax_misc_failure,
01712                 onSuccess: function (req) {
01713                     remove_waiting_box();
01714                     add_div({id: 'change_stock_repo_div', style: str_style, cssclass: 'inner_box', drag: "1"});
01715                     $('change_stock_repo_div').innerHTML = req.responseText;
01716 
01717                 }
01718             }
01719     );
01720 }
01721 function stock_inv_detail(p_dossier, p_id)
01722 {
01723     var queryString = "gDossier=" + p_dossier + "&op=view_mod_stock" + "&c_id=" + p_id + "&ctl=view_mod_stock_div";
01724     var nTop = calcy(posY);
01725     var nLeft = "10%";
01726     var str_style = "top:" + nTop + "px;left:" + nLeft + ";width:80%;";
01727 
01728     removeDiv('view_mod_stock_div');
01729     waiting_box();
01730     var action = new Ajax.Request(
01731             "ajax_misc.php",
01732             {
01733                 method: 'get', parameters: queryString,
01734                 onFailure: ajax_misc_failure,
01735                 onSuccess: function (req) {
01736                     remove_waiting_box();
01737                     add_div({id: 'view_mod_stock_div', style: str_style, cssclass: 'inner_box', drag: "1"});
01738                     $('view_mod_stock_div').innerHTML = req.responseText;
01739                     req.responseText.evalScripts();
01740                 }
01741             }
01742     );
01743 }
01744 function show_fin_chdate(obj_id)
01745 {
01746     try
01747     {
01748         var ch = $(obj_id).options[$(obj_id).selectedIndex].value;
01749         if (ch == 2) {
01750             $('chdate_ext').hide();
01751             $('thdate').show();
01752         }
01753         if (ch == 1) {
01754             $('chdate_ext').show();
01755             $('thdate').hide();
01756         }
01757         var nb = $('nb_item').value;
01758         for (i = 0; i < nb; i++) {
01759             if ($('tdchdate' + i)) {
01760                 if (ch == 2) {
01761                     $('tdchdate' + i).show();
01762                 }
01763                 if (ch == 1) {
01764                     $('tdchdate' + i).hide();
01765 
01766                 }
01767             }
01768         }
01769     } catch (e) {
01770         alert(e.message);
01771     }
01772 }
01773 /**
01774  * tab menu for the profile parameter
01775  */
01776 function profile_show(p_div)
01777 {
01778     try {
01779         var div = ['profile_gen_div', 'profile_menu_div', 'profile_print_div', 'profile_gestion_div', 'profile_repo_div'];
01780         for (var r = 0; r < div.length; r++) {
01781             $(div[r]).hide();
01782         }
01783         $(p_div).show();
01784     } catch (e)
01785     {
01786         alert(e.message)
01787     }
01788 }
01789 function detail_category_show(p_div, p_dossier, p_id)
01790 {
01791     $(p_div).show();
01792     waiting_box();
01793     $('detail_category_div').innerHTML = "";
01794     var queryString = "gDossier=" + p_dossier + "&id=" + p_id + "&op=fddetail";
01795     var action = new Ajax.Request(
01796             "ajax_misc.php",
01797             {
01798                 method: 'get', parameters: queryString,
01799                 onFailure: ajax_misc_failure,
01800                 onSuccess: function (req) {
01801                     remove_waiting_box();
01802                     $('list_cat_div').hide();
01803                     $('detail_category_div').innerHTML = req.responseText;
01804                     $('detail_category_div').show();
01805                     req.responseText.evalScripts();
01806                 }
01807             }
01808     );
01809 }
01810 /**
01811  * @brief check if the parameter is a valid a valid date or not, returns true if it is valid otherwise
01812  * false
01813  * @parameter p_str_date the string of the date (format DD.MM.YYYY)
01814  */
01815 function check_date(p_str_date)
01816 {
01817     var format = /^\d{2}\.\d{2}\.\d{4}$/;
01818     if (!format.test(p_str_date)) {
01819         return false;
01820     }
01821     else {
01822         var date_temp = p_str_date.split('.');
01823         var nMonth = parseFloat(date_temp[1]) - 1;
01824         var ma_date = new Date(date_temp[2], nMonth, date_temp[0]);
01825         if (ma_date.getFullYear() == date_temp[2] && ma_date.getMonth() == nMonth && ma_date.getDate() == date_temp[0]) {
01826             return true;
01827         }
01828         else {
01829             return false;
01830         }
01831     }
01832 
01833 }
01834 /**
01835  * @brief get the string in the id and check if the date is valid
01836  * @parameter p_id_date is the id of the element to check
01837  * @return true if the date is valid
01838  * @see check_date
01839  */
01840 function check_date_id(p_id_date)
01841 {
01842     var str_date = $(p_id_date).value;
01843     return check_date(str_date);
01844 }
01845 /**
01846  *
01847  * @param ag_id to view
01848  * @param dossier is the folder
01849  * @param modify : show the modify button values : 0 for no 1 for yes
01850  */
01851 function view_action(ag_id, dossier, modify)
01852 {
01853     waiting_box();
01854     layer++;
01855     id = 'action' + layer;
01856 
01857     querystring = 'gDossier=' + dossier + '&op=vw_action&ag_id=' + ag_id + '&div=' + id + '&mod=' + modify;
01858     var action = new Ajax.Request(
01859             "ajax_misc.php",
01860             {
01861                 method: 'get',
01862                 parameters: querystring,
01863                 onFailure: error_box,
01864                 onSuccess: function (req) {
01865                     try {
01866                         remove_waiting_box();
01867                         var answer = req.responseXML;
01868                         var html = answer.getElementsByTagName('code');
01869                         if (html.length === 0)
01870                         {
01871                             var rec = req.responseText;
01872                             alert('erreur :' + rec);
01873                         }
01874                         var code_html = getNodeText(html[0]);
01875                         code_html = unescape_xml(code_html);
01876                         var pos = fixed_position(0, 50) + ";width:90%;left:5%;";
01877                         add_div({
01878                             id: id,
01879                             drag: 1,
01880                             cssclass: "inner_box",
01881                             style: pos
01882                         });
01883                         $(id).innerHTML = code_html;
01884                         compute_all_ledger();
01885                     } catch (e) {
01886                         alert('view_action' + e.message);
01887                     }
01888                 }
01889             }
01890     );
01891 }
01892 /**
01893  * @brief filter quickly a table
01894  * @param  phrase : phrase to seach
01895  * @param  _id : id of the table
01896  * @param  colnr : string containing the column number where you're searching separated by a comma
01897  * @param start_row : first row (1 if you have table header)
01898  * @returns nothing
01899  * @see HtmlInput::filter_table
01900  */
01901 function filter_table(phrase, _id, colnr, start_row) {
01902     $('info_div').innerHTML = "Un instant";
01903     $('info_div').style.display = "block";
01904     var words = $(phrase).value.toLowerCase();
01905     var table = document.getElementById(_id);
01906 
01907     // if colnr contains a comma then check several columns
01908     var aCol = new Array();
01909     if (colnr.indexOf(',') >= 0) {
01910         aCol = colnr.split(',');
01911     } else {
01912         aCol[0] = colnr;
01913     }
01914     var ele;
01915     var tot_found = 0;
01916 
01917     for (var r = start_row; r < table.rows.length; r++) {
01918         var found = 0;
01919         for (var col = 0; col < aCol.length; col++)
01920         {
01921             var idx = aCol[col];
01922             if (table.rows[r].cells[idx])
01923             {
01924                 ele = table.rows[r].cells[idx].innerHTML.replace(/<[^>]+>/g, "");
01925                 //var displayStyle = 'none';
01926                 if (ele.toLowerCase().indexOf(words) >= 0) {
01927                     found = 1;
01928                 }
01929             }
01930 
01931         }
01932         if (found === 1) {
01933             tot_found++;
01934             table.rows[r].style.display = '';
01935         } else {
01936             table.rows[r].style.display = 'none';
01937         }
01938         $('info_div').style.display = "none";
01939         $('info_div').innerHTML = "";
01940     }
01941     if (tot_found == 0) {
01942         if ($('info_' + _id)) {
01943             $('info_' + _id).innerHTML = " Aucun résultat ";
01944         }
01945     } else {
01946         if ($('info_' + _id)) {
01947             $('info_' + _id).innerHTML = "  ";
01948         }
01949     }
01950 }
01951 /**
01952  * @brief
01953  * Display the task late or for today in dashboard
01954  */
01955 function display_task(p_id)
01956 {
01957     new Draggable(p_id, {starteffect: function ()
01958         {
01959             new Effect.Highlight(obj.id, {scroll: window, queue: 'end'});
01960         }}
01961     );
01962     $(p_id).style.top = posY + 'px';
01963     $(p_id).style.left = "10%";
01964     $(p_id).style.width = "80%";
01965     $(p_id).style.display = 'block';
01966 
01967 }
01968 /**
01969  * @brief
01970  * Set a message in the info
01971  */
01972 function info_message(p_message)
01973 {
01974     $('info_div').innerHTML = p_message;
01975     $('info_div').style.display = "block";
01976 }
01977 /**
01978  * @brief hide the info box
01979  */
01980 function info_hide()
01981 {
01982     $('info_div').style.display = "none";
01983 }
01984 /**
01985  * Show the navigator in a internal window
01986  * @returns {undefined}
01987  */
01988 function ask_navigator(p_dossier) {
01989     try {
01990         waiting_box();
01991         removeDiv('navi_div')
01992         var queryString = "gDossier=" + p_dossier + "&op=navigator";
01993         var action = new Ajax.Request(
01994                 "ajax_misc.php",
01995                 {
01996                     method: 'get', parameters: queryString,
01997                     onFailure: ajax_misc_failure,
01998                     onSuccess: function (req) {
01999                         remove_waiting_box();
02000                         add_div({id: 'navi_div', style: 'top:2em;left:2em;width:90%', cssclass: 'inner_box'});
02001                         $('navi_div').innerHTML = req.responseText;
02002                         try
02003                         {
02004                             req.responseText.evalScripts();
02005                             sorttable.makeSortable($("navi_tb"));
02006                         }
02007                         catch (e)
02008                         {
02009                             alert("answer_box Impossible executer script de la reponse\n" + e.message);
02010                         }
02011 
02012                     }
02013                 }
02014         );
02015     } catch (e) {
02016         info_message(e.getMessage);
02017     }
02018 
02019 }
02020 /**
02021  * @brief Display an internal windows to set the user's preference
02022  * 
02023  */
02024 function set_preference(p_dossier) {
02025     try {
02026         waiting_box();
02027         removeDiv('preference_div')
02028         var queryString = "gDossier=" + p_dossier + "&op=preference";
02029         var action = new Ajax.Request(
02030                 "ajax_misc.php",
02031                 {
02032                     method: 'get', parameters: queryString,
02033                     onFailure: ajax_misc_failure,
02034                     onSuccess: function (req) {
02035                         remove_waiting_box();
02036                         add_div({id: 'preference_div', drag: 1});
02037                         $('preference_div').innerHTML = req.responseText;
02038                         try
02039                         {
02040                             req.responseText.evalScripts();
02041                         }
02042                         catch (e)
02043                         {
02044                             alert("answer_box Impossible executer script de la reponse\n" + e.message);
02045                         }
02046 
02047                     }
02048                 }
02049         );
02050     } catch (e) {
02051         info_message(e.getMessage);
02052     }
02053 
02054 }
02055 /**
02056  * @brief Display user's bookmark
02057  * 
02058  */
02059 function show_bookmark(p_dossier) {
02060     try {
02061         waiting_box();
02062         removeDiv('bookmark_div');
02063         var param = window.location.search;
02064         param = param.gsub('?', '');
02065         var queryString = "gDossier=" + p_dossier + "&op=bookmark&" + param;
02066         var action = new Ajax.Request(
02067                 "ajax_misc.php",
02068                 {
02069                     method: 'get', parameters: queryString,
02070                     onFailure: ajax_misc_failure,
02071                     onSuccess: function (req) {
02072                         remove_waiting_box();
02073                         add_div({id: 'bookmark_div', cssclass: 'inner_box', drag: 1});
02074                         $('bookmark_div').innerHTML = req.responseText;
02075                         try
02076                         {
02077                             req.responseText.evalScripts();
02078                         }
02079                         catch (e)
02080                         {
02081                             alert("answer_box Impossible executer script de la reponse\n" + e.message);
02082                         }
02083 
02084                     }
02085                 }
02086         );
02087     } catch (e) {
02088         info_message(e.getMessage);
02089     }
02090 
02091 }
02092 /**
02093  * @brief save the bookmark
02094  */
02095 function save_bookmark() {
02096     try {
02097         waiting_box();
02098         var queryString = "op=bookmark&" + $("bookmark_frm").serialize();
02099         var action = new Ajax.Request(
02100                 "ajax_misc.php",
02101                 {
02102                     method: 'get', parameters: queryString,
02103                     onFailure: ajax_misc_failure,
02104                     onSuccess: function (req) {
02105                         remove_waiting_box();
02106                         // removeDiv('bookmark_div');
02107                         // 
02108                         $('bookmark_div').innerHTML = req.responseText;
02109                         try
02110                         {
02111                             req.responseText.evalScripts();
02112                         }
02113                         catch (e)
02114                         {
02115                             alert("answer_box Impossible executer script de la reponse\n" + e.message);
02116                         }
02117 
02118                     }
02119                 }
02120         );
02121     } catch (e) {
02122         info_message(e.getMessage);
02123     }
02124 
02125 }
02126 /**
02127  * @brief remove selected bookmark
02128  */
02129 function remove_bookmark() {
02130     try {
02131         waiting_box();
02132         var queryString = "op=bookmark&" + $("bookmark_del_frm").serialize();
02133         var action = new Ajax.Request(
02134                 "ajax_misc.php",
02135                 {
02136                     method: 'get', parameters: queryString,
02137                     onFailure: ajax_misc_failure,
02138                     onSuccess: function (req) {
02139                         remove_waiting_box();
02140                         $('bookmark_div').innerHTML = req.responseText;
02141                         try
02142                         {
02143                             req.responseText.evalScripts();
02144                         }
02145                         catch (e)
02146                         {
02147                             alert("answer_box Impossible executer script de la reponse\n" + e.message);
02148                         }
02149 
02150                     }
02151                 }
02152         );
02153     } catch (e) {
02154         error_message(e.getMessage);
02155     }
02156 
02157 }
02158 /**
02159  *@brief display the error message into the div error_content_div (included into error_div)
02160  *@param message message to display
02161  *@note there is no protection
02162  */
02163 function error_message(message)
02164 {
02165     $('error_content_div').innerHTML = message;
02166     $('error_div').style.visibility = 'visible';
02167 }
02168 /**
02169  * @brief show the detail of a tag and propose to save it
02170  */
02171 function show_tag(p_dossier, p_ac, p_tag_id, p_post)
02172 {
02173     try {
02174         waiting_box();
02175         var queryString = "op=tag_detail&tag=" + p_tag_id + "&gDossier=" + p_dossier + "&ac=" + p_ac + '&form=' + p_post;
02176         var action = new Ajax.Request(
02177                 "ajax_misc.php",
02178                 {
02179                     method: 'get', parameters: queryString,
02180                     onFailure: ajax_misc_failure,
02181                     onSuccess: function (req) {
02182                         var answer = req.responseXML;
02183                         var html = answer.getElementsByTagName('code');
02184                         if (html.length === 0)
02185                         {
02186                             var rec = req.responseText;
02187                             alert('erreur :' + rec);
02188                         }
02189                         var code_html = getNodeText(html[0]);
02190                         code_html = unescape_xml(code_html);
02191                         remove_waiting_box();
02192                         add_div({id: 'tag_div', cssclass: 'inner_box', drag: 1});
02193                         $('tag_div').innerHTML = code_html;
02194                         try
02195                         {
02196                             code_html.evalScripts();
02197                         }
02198                         catch (e)
02199                         {
02200                             alert("answer_box Impossible executer script de la reponse\n" + e.message);
02201                         }
02202 
02203                     }
02204                 }
02205         );
02206     } catch (e) {
02207         error_message(e.getMessage);
02208     }
02209 }
02210 
02211 /** 
02212  * @brief save the modified tag
02213  */
02214 function save_tag()
02215 {
02216     try {
02217         waiting_box();
02218         var queryString = "op=tag_save&" + $("tag_detail_frm").serialize();
02219         var action = new Ajax.Request(
02220                 "ajax_misc.php",
02221                 {
02222                     method: 'get',
02223                     parameters: queryString,
02224                     onFailure: ajax_misc_failure,
02225                     onSuccess: function (req, j) {
02226                         remove_waiting_box();
02227                         removeDiv('tag_div');
02228                     }
02229                 }
02230         );
02231     } catch (e) {
02232         error_message(e.getMessage);
02233         return false;
02234     }
02235     return false;
02236 
02237 }
02238 /**
02239  * Show a list of tag which can be added to the current followup document
02240  * @param {type} p_dossier
02241  * @param {type} ag_id
02242  * @returns {undefined}
02243  */
02244 function action_tag_select(p_dossier, ag_id)
02245 {
02246     try {
02247         waiting_box();
02248         var queryString = "ag_id=" + ag_id + "&op=tag_list&gDossier=" + p_dossier;
02249         var action = new Ajax.Request(
02250                 "ajax_misc.php",
02251                 {
02252                     method: 'get', parameters: queryString,
02253                     onFailure: ajax_misc_failure,
02254                     onSuccess: function (req, j) {
02255                         var answer = req.responseXML;
02256                         var html = answer.getElementsByTagName('code');
02257                         if (html.length === 0)
02258                         {
02259                             var rec = unescape_xml(req.responseText);
02260                             error_message('erreur :' + rec);
02261                         }
02262                         var code_html = getNodeText(html[0]);
02263                         code_html = unescape_xml(code_html);
02264                         pos = fixed_position(35, 229);
02265                         add_div({id: 'tag_div', style: pos, cssclass: 'inner_box tag', drag: 1});
02266 
02267                         remove_waiting_box();
02268                         $('tag_div').innerHTML = code_html;
02269                     }
02270                 }
02271         );
02272     } catch (e) {
02273         error_message(e.getMessage);
02274     }
02275 }
02276 /**
02277  * @brief Add the current tag to the current ag_id
02278  * @param {type} p_dossier
02279  * @param {type} ag_id
02280  * @returns {undefined}
02281  */
02282 function action_tag_add(p_dossier, ag_id, t_id)
02283 {
02284     try {
02285         waiting_box();
02286         var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_add&gDossier=" + p_dossier;
02287         var action = new Ajax.Request(
02288                 "ajax_misc.php",
02289                 {
02290                     method: 'get', parameters: queryString,
02291                     onFailure: ajax_misc_failure,
02292                     onSuccess: function (req, j) {
02293                         var answer = req.responseXML;
02294                         var html = answer.getElementsByTagName('code');
02295                         if (html.length === 0)
02296                         {
02297                             var rec = unescape_xml(req.responseText);
02298                             error_message('erreur :' + rec);
02299                         }
02300                         var code_html = getNodeText(html[0]);
02301                         code_html = unescape_xml(code_html);
02302                         remove_waiting_box();
02303                         $('action_tag_td').innerHTML = code_html;
02304                         removeDiv('tag_div');
02305                     }
02306                 }
02307         );
02308     } catch (e) {
02309         error_message(e.getMessage);
02310     }
02311 }
02312 /**
02313  * @brief remove the current tag to the current ag_id
02314  * @param {type} p_dossier
02315  * @param {type} ag_id
02316  * @returns {undefined}
02317  */
02318 function action_tag_remove(p_dossier, ag_id, t_id)
02319 {
02320     if (confirm('Enlevez ce tags ?') === false)
02321         return;
02322     try {
02323         waiting_box();
02324         var queryString = "t_id=" + t_id + "&ag_id=" + ag_id + "&op=tag_remove&gDossier=" + p_dossier;
02325         var action = new Ajax.Request(
02326                 "ajax_misc.php",
02327                 {
02328                     method: 'get', parameters: queryString,
02329                     onFailure: ajax_misc_failure,
02330                     onSuccess: function (req, j) {
02331                         var answer = req.responseXML;
02332                         var html = answer.getElementsByTagName('code');
02333                         if (html.length === 0)
02334                         {
02335                             var rec = unescape_xml(req.responseText);
02336                             error_message('erreur :' + rec);
02337                         }
02338                         var code_html = getNodeText(html[0]);
02339                         code_html = unescape_xml(code_html);
02340                         remove_waiting_box();
02341                         $('action_tag_td').innerHTML = code_html;
02342 
02343                     }
02344                 }
02345         );
02346     } catch (e) {
02347         error_message(e.getMessage);
02348     }
02349 }
02350 
02351 
02352 /**
02353  * Display a div with available tags, this div can update the cell
02354  * tag_choose_td
02355  * @param {type} p_dossier
02356  * @returns {undefined}
02357  */
02358 function search_display_tag(p_dossier, p_prefix)
02359 {
02360     try {
02361         waiting_box();
02362         var queryString = "op=search_display_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
02363         var action = new Ajax.Request(
02364                 "ajax_misc.php",
02365                 {
02366                     method: 'get', parameters: queryString,
02367                     onFailure: ajax_misc_failure,
02368                     onSuccess: function (req, j) {
02369                         var answer = req.responseXML;
02370                         var html = answer.getElementsByTagName('code');
02371                         if (html.length === 0)
02372                         {
02373                             var rec = unescape_xml(req.responseText);
02374                             error_message('erreur :' + rec);
02375                         }
02376                         var code_html = getNodeText(html[0]);
02377                         code_html = unescape_xml(code_html);
02378                         remove_waiting_box();
02379                         add_div({id: p_prefix + 'tag_div', style: '', cssclass: 'inner_box', drag: 1});
02380                         $(p_prefix + 'tag_div').style.top = posY - 80 + "px";
02381                         $(p_prefix + 'tag_div').style.left = posX - 200 + "px";
02382                         remove_waiting_box();
02383                         $(p_prefix + 'tag_div').innerHTML = code_html;
02384 
02385                     }
02386                 }
02387         );
02388     } catch (e) {
02389         error_message(e.getMessage);
02390     }
02391 }
02392 /**
02393  * @brief Add the selected tag (p_tag_id) to the cell of tag_choose_td in the search screen
02394  * in the search screen
02395  * @param {type} p_dossier
02396  * @param {type} p_tag_id
02397  */
02398 function search_add_tag(p_dossier, p_tag_id, p_prefix)
02399 {
02400     try {
02401         var clear_button = 0;
02402         if (tag_choose === '' && p_prefix === 'search') {
02403             tag_choose = $(p_prefix + 'tag_choose_td').innerHTML;
02404             clear_button = 1;
02405         }
02406         waiting_box();
02407         var queryString = "op=search_add_tag&gDossier=" + p_dossier + "&id=" + p_tag_id + "&clear=" + clear_button + '&pref=' + p_prefix;
02408         var action = new Ajax.Request(
02409                 "ajax_misc.php",
02410                 {
02411                     method: 'get', parameters: queryString,
02412                     onFailure: ajax_misc_failure,
02413                     onSuccess: function (req, j) {
02414                         var answer = req.responseXML;
02415                         var html = answer.getElementsByTagName('html');
02416                         if (html.length === 0)
02417                         {
02418                             var rec = unescape_xml(req.responseText);
02419                             error_message('erreur :' + rec);
02420                         }
02421                         var code_html = getNodeText(html[0]);
02422                         code_html = unescape_xml(code_html);
02423                         remove_waiting_box();
02424                         $(p_prefix + 'tag_choose_td').innerHTML = $(p_prefix + 'tag_choose_td').innerHTML + code_html;
02425                         removeDiv(p_prefix + 'tag_div');
02426                     }
02427                 }
02428         );
02429     } catch (e) {
02430         error_message(e.getMessage);
02431     }
02432 }
02433 /**
02434  * Clear the tags in the cell tag_choose_td of the search screen
02435  * @returns {undefined}
02436  */
02437 function search_clear_tag(p_dossier, p_prefix)
02438 {
02439     if (p_prefix != 'search') {
02440         $(p_prefix + 'tag_choose_td').innerHTML = "";
02441         return;
02442     }
02443     try {
02444         var queryString = "op=search_clear_tag&gDossier=" + p_dossier + "&pref=" + p_prefix;
02445         var action = new Ajax.Request(
02446                 "ajax_misc.php",
02447                 {
02448                     method: 'get', parameters: queryString,
02449                     onFailure: ajax_misc_failure,
02450                     onSuccess: function (req, j) {
02451                         var answer = req.responseXML;
02452                         var html = answer.getElementsByTagName('html');
02453                         if (html.length === 0)
02454                         {
02455                             var rec = unescape_xml(req.responseText);
02456                             error_message('erreur :' + rec);
02457                         }
02458                         var code_html = getNodeText(html[0]);
02459                         code_html = unescape_xml(code_html);
02460                         $(p_prefix + 'tag_choose_td').innerHTML = code_html;
02461                         tag_choose = "";
02462                     }
02463                 }
02464         );
02465     } catch (e) {
02466         error_message(e.getMessage);
02467     }
02468 }
02469 function action_show_checkbox()
02470 {
02471     var a = document.getElementsByName('ag_id_td');
02472     for (var i = 0; i < a.length; i++) {
02473         a[i].style.display = 'block';
02474     }
02475 }
02476 function action_hide_checkbox()
02477 {
02478     var a = document.getElementsByName('ag_id_td');
02479     for (var i = 0; i < a.length; i++) {
02480         a[i].style.display = 'none';
02481     }
02482 }
02483 /**
02484  * 
02485  * @param {type} obj
02486  * object attribute : g
02487  *   - Dossier dossier_id, 
02488  *   - invalue DOM Element where you can find the periode to zoom
02489  *   - outdiv  ID of the target (DIV)
02490  *   
02491  */
02492 function calendar_zoom(obj)
02493 {
02494     try {
02495 
02496         var query = "";
02497         query = "op=calendar_zoom&gDossier=" + obj.gDossier + "&in=" + $(obj.invalue).value + '&out=' + obj.outdiv;
02498         waiting_box();
02499         var action = new Ajax.Request(
02500                 "ajax_misc.php",
02501                 {
02502                     method: 'get', parameters: query,
02503                     onFailure: ajax_misc_failure,
02504                     onSuccess: function (req, j) {
02505                         var answer = req.responseXML;
02506                         var html = answer.getElementsByTagName('html');
02507                         if (html.length === 0)
02508                         {
02509                             var rec = unescape_xml(req.responseText);
02510                             error_message('erreur :' + rec);
02511                         }
02512                         var code_html = getNodeText(html[0]);
02513                         code_html = unescape_xml(code_html);
02514 
02515                         // if the target doesn't exist 
02516                         // then create it
02517                         if (obj.outdiv === undefined) {
02518                             obj.outdiv = 'calendar_zoom_div';
02519                         }
02520                         if ($(obj.outdiv) == undefined) {
02521                             var str_style = fixed_position(0, 20);
02522                             add_div({id: obj.outdiv, style: 'margin-left:3%;width:94%;height:94%;' + str_style, cssclass: "inner_box", drag: 1});
02523                         }
02524                         remove_waiting_box();
02525                         $(obj.outdiv).innerHTML = code_html;
02526                         $(obj.outdiv).show();
02527                     }
02528                 }
02529         );
02530     } catch (e) {
02531         error_message('calendar_zoom ' + e.getMessage);
02532     }
02533 
02534 
02535 }
02536 /**
02537  * @brief add a line in the form for the stock
02538  */
02539 function stock_add_row()
02540 {
02541     try {
02542         style = 'class="input_text"';
02543         var mytable = g("stock_tb").tBodies[0];
02544         var ofirstRow = mytable.rows[1];
02545         var line = mytable.rows.length;
02546         var nCell = mytable.rows[1].cells.length;
02547         var row = mytable.insertRow(line);
02548         var nb = g("row");
02549         for (var e = 0; e < nCell; e++)
02550         {
02551             var newCell = row.insertCell(e);
02552             if (mytable.rows[1].cells[e].hasClassName('num')) {
02553                 newCell.addClassName("num");
02554             }
02555 
02556             var tt = ofirstRow.cells[e].innerHTML;
02557             var new_tt = tt.replace(/sg_code0/g, "sg_code" + nb.value);
02558             new_tt = new_tt.replace(/sg_quantity0/g, "sg_quantity" + nb.value);
02559             new_tt = new_tt.replace(/label0/g, "label" + nb.value);
02560             newCell.innerHTML = new_tt;
02561             new_tt.evalScripts();
02562         }
02563 
02564         g("sg_code" + nb.value).innerHTML = '&nbsp;';
02565         g("sg_code" + nb.value).value = '';
02566         g("label" + nb.value).innerHTML = '';
02567         g("sg_quantity" + nb.value).value = '0';
02568 
02569         nb.value++;
02570 
02571         new_tt.evalScripts();
02572     } catch (e) {
02573         alert(e.message);
02574     }
02575 
02576 }
02577 function show_description(p_id)
02578 {
02579     $('print_desc' + p_id).hide();
02580     $('input_desc' + p_id).show();
02581 
02582 }
02583 /**
02584  * Hightlight the row we select and restore previous one
02585  * @param {type} x
02586  * @returns {undefined}
02587  */
02588 var old_class = null;
02589 var old_select = null;
02590 
02591 function select_cat(x)
02592 {
02593     if (old_select != null)
02594     {
02595         $(old_select).className = old_class;
02596     }
02597     old_select = $('select_cat_row_' + x);
02598     old_class = old_select.className;
02599     $(old_select).className = "highlight";
02600     $('fd_id').value = x;
02601 }
02602 /**
02603  * Show the DIV and hide the other, the array of possible DIV are
02604  * in a_tabs, 
02605  * @param {array} a_tabs name of possible tabs
02606  * @param {strng} p_display_tab tab to display
02607  */
02608 function show_tabs(a_tabs, p_display_tab)
02609 {
02610     try
02611     {
02612         if (a_tabs.length == 0)
02613             trow('a_tabs in empty');
02614         var i = 0;
02615         for (i = 0; i < a_tabs.length; i++) {
02616             $(a_tabs[i]).hide();
02617         }
02618         $(p_display_tab).show();
02619     } catch (e) {
02620         alert(e.message);
02621     }
02622 
02623 }
02624 /**
02625  * Change the class of all the "LI" element of a UL or OL
02626  * @param node of ul (this)
02627  */
02628 function unselect_other_tab(p_tab)
02629 {
02630     try {
02631         var other = p_tab.getElementsByTagName("li");
02632         var i = 0;
02633         var tab = null;
02634         for (i = 0; i < other.length; i++) {
02635             tab = other[i];
02636             tab.className = "tabs";
02637         }
02638     } catch (e) {
02639         if (console)
02640             console.log(e.message);
02641     }
02642 }
02643 /**
02644  * logout function call from ajax
02645  * @see ajax_disconnected
02646  * @returns {undefined}
02647  */
02648 function logout()
02649 {
02650     var tmp_place = window.location.href
02651     var tmp_b = tmp_place.split('/')
02652     var tmp_last = tmp_b.length - 1
02653     var place_logout = tmp_place.replace(tmp_b[tmp_last], 'logout.php');
02654     window.location.href = place_logout;
02655 }
 All Data Structures Namespaces Files Functions Variables Enumerations