minor fix to previous CDR engine report improvement
[openemr.git] / library / ajax / payment_ajax_jav.inc.php
blob2058bf5d1876beff2d4b87a2c76f71cddfe389b2
1 <?php
2 // +-----------------------------------------------------------------------------+
3 // Copyright (C) 2010 Z&H Consultancy Services Private Limited <sam@zhservices.com>
4 //
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
18 // A copy of the GNU General Public License is included along with this program:
19 // openemr/interface/login/GnuGPL.html
20 // For more information write to the Free Software
21 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 //
23 // Author: Eldho Chacko <eldho@zhservices.com>
24 // Paul Simon K <paul@zhservices.com>
26 // +------------------------------------------------------------------------------+
27 //===============================================================================
28 //This section handles ajax functions for insurance,patient and for encounters.
29 //===============================================================================
31 <script type="text/javascript">
32 $(document).ready(function(){
33 $("#type_code").keyup(function(e){
34 if (e.which == 9 || e.which == 13)
35 {//tab key,enter key.Prevent ajax activity.
36 return false;
38 else
39 {//Both insurance or patient can come.The drop down value in 'type_name' decides which one to process.
40 ajaxFunction('non','Simple',document.getElementById('type_code'));
41 return;
43 });
44 $("#patient_code").keyup(function(e){
45 if (e.which == 9 || e.which == 13)
46 {//tab key,enter key.Prevent ajax activity.
47 return false;
49 else
51 ajaxFunction('patient','Submit',document.getElementById('patient_code'));
52 return;
54 });
55 $("#form_pt_name").keyup(function(e){
56 if (e.which == 9 || e.which == 13)
57 {//tab key,enter key.Prevent ajax activity.
58 return false;
60 else
62 ajaxFunction('patient','Simple',document.getElementById('form_pt_name'));
63 return;
65 });
66 $("#encounter_no").keyup(function(e){
67 if (e.which == 9 || e.which == 13)
68 {//tab key,enter key.Prevent ajax activity.
69 return false;
71 else
73 ajaxFunction('encounter');
74 return;
76 });
77 function ajaxFunction(Source,SubmitOrSimple,SourceObject) {
78 if(Source=='encounter')
80 document.getElementById('ajax_mode').value='encounter';
82 else if(Source=='patient')
84 if(SourceObject.value.length<3)
85 return false;
86 document.getElementById('ajax_mode').value='set_patient';
88 //For the below two cases, same text box is used for both insurance and patient.
89 else if(document.getElementById('type_name') && document.getElementById('type_name').options[document.getElementById('type_name').selectedIndex].value=='patient')
90 {//Patient
91 if(document.getElementById('type_code').value.length<3)
92 return false;
93 document.getElementById('ajax_mode').value='set_patient';
95 else
96 {//Insurance
97 if(document.getElementById('type_code').value.length<3)
98 return false;
99 document.getElementById('ajax_mode').value='set';
101 //Send ajax request
102 $.ajax({
103 type: "POST",
104 url: "../../library/ajax/payment_ajax.php",
105 dataType: "html",
106 data: {
107 ajax_mode: document.getElementById('ajax_mode').value,
108 patient_code: Source=='patient' ? SourceObject.value : '',
109 insurance_text_ajax: document.getElementById('type_code') ? document.getElementById('type_code').value : '',
110 encounter_patient_code:Source=='encounter' ? document.getElementById('hidden_patient_code').value : '',
111 submit_or_simple_type:SubmitOrSimple
113 //async: false,
114 success: function(thedata){
115 if(Source=='encounter')
119 else
121 ThedataArray=thedata.split('~`~`');
122 thedata=ThedataArray[1];
123 if(Source=='patient')
125 if(ThedataArray[0]!=SourceObject.value.length)
127 return;//To deal with speedy typing.
130 else
132 if(ThedataArray[0]!=document.getElementById('type_code').value.length)
134 return;//To deal with speedy typing.
138 document.getElementById('ajax_mode').value='';
139 if(Source=='encounter')
141 if(document.getElementById('SelFacility'))
143 document.getElementById('SelFacility').style.display='none';//In Internet explorer this drop down comes over the ajax listing.
145 $("#ajax_div_encounter_error").empty();
146 $("#ajax_div_encounter").empty();
147 $("#ajax_div_encounter").html(thedata);
148 $("#ajax_div_encounter").show();
150 else if(Source=='patient')
152 if(document.getElementById('SelFacility'))
154 document.getElementById('SelFacility').style.display='none';//In Internet explorer this drop down comes over the ajax listing.
156 $("#ajax_div_patient_error").empty();
157 $("#ajax_div_patient").empty();
158 $("#ajax_div_insurance_error").empty();
159 $("#ajax_div_insurance").empty();
160 $("#ajax_div_patient").html(thedata);
161 $("#ajax_div_patient").show();
163 else
164 {//Patient or Insurance
165 $("#ajax_div_patient_error").empty();
166 $("#ajax_div_patient").empty();
167 $("#ajax_div_insurance_error").empty();
168 $("#ajax_div_insurance").empty();
169 $("#ajax_div_insurance").html(thedata);
170 $("#ajax_div_insurance").show();
172 if(document.getElementById('anchor_insurance_code_1'))
173 document.getElementById('anchor_insurance_code_1').focus();
174 if(document.getElementById('tr_insurance_1'))
175 document.getElementById('tr_insurance_1').bgColor='#94D6E7'//selected color
177 error:function(){
180 return;
183 //==============================================================================================================================================
184 //Following functions are needed for other tasks related to ajax.
185 //Html retured from the ajax above, contains list of either insurance,patient or encounter.
186 //On click or 'enter key' press over any one item the listing vanishes and the clicked one gets listed in the parent page's text box.
187 //List of functions starts
188 //===========================================================
189 function PutTheValuesClick(Code,Name)
190 {//Used while -->CLICK<-- over list in the insurance/patient portion.
191 document.getElementById('type_code').value=Name;
192 document.getElementById('hidden_ajax_close_value').value=Name;
193 document.getElementById('description').value=Name;
194 document.getElementById('hidden_type_code').value=Code;
195 document.getElementById('div_insurance_or_patient').innerHTML=Code;
196 document.getElementById('ajax_div_insurance').style.display='none';
197 $("#ajax_div_patient_error").empty();
198 $("#ajax_div_patient").empty();
199 $("#ajax_div_insurance_error").empty();
200 $("#ajax_div_insurance").empty();
201 document.getElementById('type_code').focus();
203 function PutTheValuesClickDistribute(Code,Name)
204 {//Used while -->CLICK<-- over list in the patient portion before the start of distribution of amount.
205 if(document.getElementById('SelFacility'))
207 document.getElementById('SelFacility').style.display='';//In Internet explorer this drop down comes over the ajax listing.
209 document.getElementById('patient_code').value=Name;
210 document.getElementById('hidden_ajax_patient_close_value').value=Name;
211 document.getElementById('hidden_patient_code').value=Code;
212 document.getElementById('patient_name').innerHTML=Code;
213 document.getElementById('ajax_div_patient').style.display='none';
214 document.getElementById('patient_name').focus();
215 document.getElementById('mode').value='search';
216 top.restoreSession();
217 document.forms[0].submit();
219 function PutTheValuesClickPatient(Code,Name)//Non submission patient ajax.
221 document.getElementById('form_pt_name').value=Name;
222 document.getElementById('hidden_ajax_patient_close_value').value=Name;
223 document.getElementById('hidden_patient_code').value=Code;
224 document.getElementById('ajax_div_patient').style.display='none';
225 document.getElementById('form_pt_code').innerHTML=Code;
226 document.getElementById('form_pt_name').focus();
228 function PutTheValuesClickEncounter(Code,Name)
229 {//Used while -->CLICK<-- over list in the encounter portion.
230 if(document.getElementById('SelFacility'))
232 document.getElementById('SelFacility').style.display='';//In Internet explorer this drop down comes over the ajax listing.
234 document.getElementById('encounter_no').value=Code;
235 document.getElementById('hidden_ajax_encounter_close_value').value=Code;
236 document.getElementById('hidden_encounter_no').value=Code;
237 document.getElementById('encounter_date').innerHTML=Name;
238 document.getElementById('ajax_div_encounter').style.display='none';
239 document.getElementById('encounter_date').focus();
240 document.getElementById('mode').value='search_encounter';
241 top.restoreSession();
242 document.forms[0].submit();
244 function PlaceValues(evt,Code,Name)
245 {//Used while -->KEY PRESS<-- over list in the insurance/patient portion.
246 evt = (evt) ? evt : window.event;
247 var charCode = (evt.which) ? evt.which : evt.keyCode;
248 if (charCode == 13)//enter key
249 {//Vanish the list and populate the parent text box
250 PutTheValuesClick(Code,Name);
251 PreventIt(evt) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
253 else if(!((charCode == 38) || (charCode == 40)))
254 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
255 document.getElementById('type_code').focus();
258 function PlaceValuesDistribute(evt,Code,Name)
259 {//Used while -->KEY PRESS<-- over list in the patient portion before the start of distribution of amount.
260 evt = (evt) ? evt : window.event;
261 var charCode = (evt.which) ? evt.which : evt.keyCode;
262 if (charCode == 13)//enter key
263 {//Vanish the list and populate the parent text box
264 PutTheValuesClickDistribute(Code,Name);
265 PreventIt(evt) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
267 else if(!((charCode == 38) || (charCode == 40)))
268 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
269 document.getElementById('patient_code').focus();
272 function PlaceValuesPatient(evt,Code,Name)
274 evt = (evt) ? evt : window.event;
275 var charCode = (evt.which) ? evt.which : evt.keyCode;
276 if (charCode == 13)//enter key
277 {//Vanish the list and populate the parent text box
278 PutTheValuesClickPatient(Code,Name);
279 PreventIt(evt) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
281 else if(!((charCode == 38) || (charCode == 40)))
282 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
283 document.getElementById('form_pt_name').focus();
286 function PlaceValuesEncounter(evt,Code,Name)
287 {//Used while -->KEY PRESS<-- over list in the encounter portion.
288 evt = (evt) ? evt : window.event;
289 var charCode = (evt.which) ? evt.which : evt.keyCode;
290 if (charCode == 13)//enter key
291 {//Vanish the list and populate the parent text box
292 PutTheValuesClickEncounter(Code,Name);
293 PreventIt(evt) //For browser chorome.It gets submitted,to prevent it the PreventIt(evt) is written
295 else if(!((charCode == 38) || (charCode == 40)))
296 {//if non arrow keys, focus on the parent text box(ie he again types and wants ajax to activate)
297 document.getElementById('encounter_no').focus();
300 function ProcessKeyForColoring(evt,Location)
301 {//Shows the navigation in the listing by change of colors and focus.Happens when down or up arrow is pressed.
302 evt = (evt) ? evt : window.event;
303 var charCode = (evt.which) ? evt.which : evt.keyCode;
304 if (charCode == 38)//Up key press
306 Location--;
307 if(document.getElementById('tr_insurance_' + (Location)))
309 //restore color in below row
310 if((Location+1)%2==1)
312 document.getElementById('tr_insurance_' + (Location+1)).bgColor='#ddddff';
314 else
316 document.getElementById('tr_insurance_' + (Location+1)).bgColor='#ffdddd';
318 document.getElementById('tr_insurance_' + (Location)).bgColor='#94D6E7';
319 document.getElementById('anchor_insurance_code_' + (Location)).focus();
322 else if (charCode == 40)//Down key press
324 Location++;
325 if(document.getElementById('tr_insurance_' + (Location)))
327 //restore color in above row
328 if((Location-1)%2==1)
330 document.getElementById('tr_insurance_' + (Location-1)).bgColor='#ddddff';
332 else
334 document.getElementById('tr_insurance_' + (Location-1)).bgColor='#ffdddd';
336 document.getElementById('tr_insurance_' + (Location)).bgColor='#94D6E7';
337 document.getElementById('anchor_insurance_code_' + (Location)).focus();
341 function HideTheAjaxDivs()
342 {//Starts working when clicking on the body.Hides the ajax and restores the codes back, as he may have changed it in the text box.
343 if(document.getElementById('ajax_div_insurance'))
345 if(document.getElementById('ajax_div_insurance').style.display!='none')
347 document.getElementById('type_code').value=document.getElementById('hidden_ajax_close_value').value;
348 $("#ajax_div_patient_error").empty();
349 $("#ajax_div_patient").empty();
350 $("#ajax_div_insurance_error").empty();
351 $("#ajax_div_insurance").empty();
352 $("#ajax_div_insurance").hide();
355 if(document.getElementById('ajax_div_patient'))
357 if(document.getElementById('ajax_div_patient').style.display!='none')
359 if(document.getElementById('SelFacility'))
361 document.getElementById('SelFacility').style.display='';//In Internet explorer this drop down comes over the ajax listing.
363 if(document.getElementById('patient_code'))
364 document.getElementById('patient_code').value=document.getElementById('hidden_ajax_patient_close_value').value;
365 else if(document.getElementById('form_pt_name'))
366 document.getElementById('form_pt_name').value=document.getElementById('hidden_ajax_patient_close_value').value;
367 $("#ajax_div_patient_error").empty();
368 $("#ajax_div_patient").empty();
369 $("#ajax_div_insurance_error").empty();
370 $("#ajax_div_insurance").empty();
371 $("#ajax_div_patient").hide();
374 if(document.getElementById('ajax_div_encounter'))
376 if(document.getElementById('ajax_div_encounter').style.display!='none')
378 if(document.getElementById('SelFacility'))
380 document.getElementById('SelFacility').style.display='';//In Internet explorer this drop down comes over the ajax listing.
382 document.getElementById('encounter_no').value=document.getElementById('hidden_ajax_encounter_close_value').value;
383 $("#ajax_div_encounter_error").empty();
384 $("#ajax_div_encounter").empty();
385 $("#ajax_div_encounter").hide();
389 //===========================================================
390 //List of functions ends
391 //==============================================================================================================================================
392 </script>