<!--all form ajax-->
$(document).ready(function() {
  	$('.ajax_submit').click(function(){
		
		var id = $(this).closest('form').attr('id');
		
		$(this).closest('form').attr('onsubmit','return false');
		
		var image='<img src="../images/loading.gif" />';
		
		/*var url=document.location.href;
		
		var url2 = url.split('?');
		var url = url2[0];*/
		
			
			
		$.ajax({
		type: "POST",
		url: "ajax.php",
		data: $("#"+id).serialize(),
		beforeSend: function(){
			
			$('#result_'+id).html(image);
		},
		success: function(data){
			
			var n = data.search("Error"); 
			if(n==0)
			{
				$('#result_'+id).html(data).css('color','red');
				$("html, body").scrollTop(0);
				
				//window.setTimeout(function(){location.reload()},2000);
			}
			else
			{
				
				/*$('#result_'+id).html(data).css('color','green');
				window.setTimeout(function(){location.reload()},2000);*/
				window.location.href = data;
				
				
			}
			 
		}
	});
    });
});

<!--add new basic info of patient form ajax-->
$(document).ready(function() {
  	$('.ajax_submit_patient').click(function(){
		
		var id = $(this).closest('form').attr('id');
		
		$(this).closest('form').attr('onsubmit','return false');
		
		var image='<img src="../images/loading.gif" />';
		
		/*var url=document.location.href;
		
		var url2 = url.split('?');
		var url = url2[0];*/
		
			
			
		$.ajax({
		type: "POST",
		url: "ajax.php",
		data: $("#"+id).serialize(),
		beforeSend: function(){
			
			$('#result_'+id).html(image);
		},
		success: function(data){
			
			var n = data.search("Error"); 
			if(n==0)
			{
				$('#result_'+id).html(data).css('color','red');
				$("html, body").scrollTop(0);
			}
			else
			{
				
				var values_array = data.split('&');
				
				$("#patient_name").html(values_array[0]);
				$("#patient_id").val(values_array[1]);
				
				$('#mask,.add_patient-popup').fadeOut(300 , function() {
					  
					$('#mask').remove();  
				});  
				
				
			}
			 
		}
	});
    });
});

<!--receive items ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".packing_type").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
				
	
	});
	
	$(".packing_qty").keyup(function(){
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
		
		
	
	});
	
	$(".discount").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
		
	
	});
	
	function calculate_item(id)
	{
		var data = id.split('_');
		
		var packing_type = document.getElementById('packing_type_'+data[2]).value;
		var prod_id = document.getElementById('product_id_'+data[2]).value;
		var packing_qty = document.getElementById('packing_qty_'+data[2]).value;
		var discount = document.getElementById('discount_prod_'+data[2]).value;
		var recitems_id = document.getElementById('recitems_id_'+data[2]).value;
		var expiry_date = document.getElementById('expiry_date_'+data[2]).value;
		
		
		var url="ajax.php?receive_items=yes&packing_type="+packing_type+"&prod_id="+prod_id+"&packing_qty="+packing_qty+"&discount="+discount+"&recitems_id="+recitems_id+"&expiry_date="+expiry_date;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var values_array = xmlhttp.responseText.split('&');
			//alert(values_array);
			$('#price_disable_'+data[2]).val(values_array[0]);
			$('#price_'+data[2]).val(values_array[0]);
			
			$('#total_'+data[2]).val(values_array[1]);
			$('#total_hidden_'+data[2]).val(values_array[1]);
			
			$('#net_total_'+data[2]).html(values_array[2]);
			
			$('#expiry_date_'+data[2]).html(values_array[3]);
			
			$('#invoice_amount').html(values_array[4]);
			
			$('#amount_payable').html(values_array[5]);
			
			$('#amount_payable_form').val(values_array[5]);
			
			$('#result').html('');
		}
		
	}
	
	$(".invoice_discount").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var invoice_discount = document.getElementById('invoice_discount').value;
		
		var url="ajax.php?invoice_discount="+invoice_discount;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var url=document.location.href;
		
			var url2 = url.split('?');
			var url = url2[0];
			window.location.href = url;
		}
	});
	
	
});

<!--sale items ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".sale_packing_type").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_saleitem(this.id);
				
	
	});
	
	$(".sale_packing_qty").keyup(function(){
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_saleitem(this.id);
		
		
	
	});
	
	$(".sale_discount").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_saleitem(this.id);
		
	
	});
	
	function calculate_saleitem(id)
	{
		var data = id.split('_');
		
		var packing_type = document.getElementById('packing_type_'+data[2]).value;
		var prod_id = document.getElementById('product_id_'+data[2]).value;
		var packing_qty = document.getElementById('packing_qty_'+data[2]).value;
		var discount = document.getElementById('discount_prod_'+data[2]).value;
		var saleitems_id = document.getElementById('saleitems_id_'+data[2]).value;
		
		
		var url="ajax.php?sale_items=yes&packing_type="+packing_type+"&prod_id="+prod_id+"&packing_qty="+packing_qty+"&discount="+discount+"&saleitems_id="+saleitems_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var values_array = xmlhttp.responseText.split('&');
			//alert(values_array);
			$('#price_disable_'+data[2]).val(values_array[0]);
			$('#price_'+data[2]).val(values_array[0]);
			
			$('#total_'+data[2]).val(values_array[1]);
			$('#total_hidden_'+data[2]).val(values_array[1]);
			
			$('#net_total_'+data[2]).html(values_array[2]);
			
			$('#expiry_date_'+data[2]).html(values_array[3]);
			
			$('#invoice_amount').html(values_array[4]);
			
			$('#amount_payable').html(values_array[5]);
			
			$('#amount_payable_form').val(values_array[5]);
			
			$('#result').html('');
		}
		
	}
	
	$(".sale_invoice_discount").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var invoice_discount = document.getElementById('invoice_discount').value;
		
		var url="ajax.php?sale_invoice_discount="+invoice_discount;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var url=document.location.href;
		
			var url2 = url.split('?');
			var url = url2[0];
			window.location.href = url;
		}
	});
	
	
});


<!--set retail prices of products-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".boxretailprice").keyup(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var id = this.id;
		var data= id.split('_');
	
		boxretailprice = document.getElementById("boxretailprice_"+data[1]).value;
		
		boxqty = document.getElementById("boxqty_"+data[1]).value;
		leafqtybox = document.getElementById("leafqtybox_"+data[1]).value;
		unitqtybox = document.getElementById("unitqtybox_"+data[1]).value;
		
		leafretailprice = boxretailprice/leafqtybox;
		unitretailprice = boxretailprice/unitqtybox;
		
		$("#leafretailprice_"+data[1]).val(leafretailprice);
		$("#unitretailprice_"+data[1]).val(unitretailprice);
		
		$("#box_retailprice_"+data[1]).val(boxretailprice);
		$("#leaf_retailprice_"+data[1]).val(leafretailprice);
		$("#unit_retailprice_"+data[1]).val(unitretailprice);
		
		var url="ajax.php?box_retailprice="+box_retailprice+"&leaf_retailprice="+leaf_retailprice+"&unit_retailprice="+unit_retailprice+"&product_id="+product_id+"&location_id="+location_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var url=document.location.href;
		
			var url2 = url.split('?');
			var url = url2[0];
			window.location.href = url;
		}
	});
	
	
});


<!--search patient through ajax-->
$(document).ready(function() {
  	$('#patient_search').click(function(){
		
		var id = $(this).closest('form').attr('id');
		$(this).closest('form').attr('onsubmit','return false');
		
		var image='<img src="../images/loading.gif" />';
		
		$.ajax({
		type: "POST",
		url: "ajax.php",
		data: $("#"+id).serialize(),
		beforeSend: function(){
			
			$('#result_'+id).html(image);
		},
		success: function(data){
			
			var n = data.search("Error"); 
			if(n==0)
			{
				$('#result_'+id).html(data).css('color','red');
				$("html, body").scrollTop(0);
			}
			else
			{
				$('#by_name').val('');
				$('#by_id').val('');
				$('#by_phone').val('');
				$('#default_body').html(data);
				
			}
			 
		}
	});
    });
	
	$("#view_all_patients").click(function() {
		
		var refferer = $(this).attr("href");
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		if(refferer=='mgmtbeds')
		{
			var url="ajax.php?view_all_patients=yes&refferer="+refferer;
		}
		else
		{
			var url="ajax.php?view_all_patients=yes";
		}
		
		
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			$('#default_body').html(xmlhttp.responseText);
		}
		return false;
	});
});

<!--search appointments through ajax-->
$(document).ready(function() {
	
  	$('#app_search').click(function(){
		
		var id = $(this).closest('form').attr('id');
		$(this).closest('form').attr('onsubmit','return false');
		
		var image='<img src="../images/loading.gif" />';
		
		$.ajax({
		type: "POST",
		url: "ajax.php",
		data: $("#"+id).serialize(),
		beforeSend: function(){
			
			$('#result_'+id).html(image);
		},
		success: function(data){
			
			var n = data.search("Error"); 
			if(n==0)
			{
				$('#result_'+id).html(data).css('color','red');
				$("html, body").scrollTop(0);
			}
			else
			{
				$('#by_name').val('');
				$('#by_id').val('');
				$('#by_phone').val('');
				$('#default_app_body').html(data);
				
			}
			 
		}
	});
    });
	
	$(".select_appointments").click(function() {
	
	
		var xmlhttp=null;
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		
		var doctor_id = document.getElementById('app_doctor_id').value;
		var app_date = document.getElementById('datepicker').value;
		
		var url="ajax.php?search_appointments=Search&doctor_id="+doctor_id+"&app_date="+app_date;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			$('#by_name').val('');
			$('#by_id').val('');
			$('#by_phone').val('');
			$('#default_app_body').html(xmlhttp.responseText);
		}
		
		
				
	
	});
});

<!--product closing items ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".closing_packing_qty").keyup(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
				
	
	});
	
	$(".closing_packing_type").change(function(){
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
		
		
	
	});
	
	
	
	function calculate_item(id)
	{
		var data = id.split('_');
		
		var closing_packing_type = document.getElementById('closing_packing_type_'+data[3]).value;
		var product_id = document.getElementById('product_id_'+data[3]).value;
		var closing_packing_qty = document.getElementById('closing_packing_qty_'+data[3]).value;
		
		var url="ajax.php?prod_closing=yes&closing_packing_type="+closing_packing_type+"&product_id="+product_id+"&closing_packing_qty="+closing_packing_qty;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var values_array = xmlhttp.responseText.split('&');
			//alert(values_array);
			
			$('#unit_phy_qtyinstock_'+data[3]).html(values_array[0]);
			$('#unit_per_pack_'+data[3]).html(values_array[1]);
			
			$('#result').html('');
		}
		
	}
	
	
	
	
});


<!--refund receive items ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".refund_qty").blur(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
				
	
	});
	
	function calculate_item(id)
	{
		var data = id.split('_');
		var prod_id = document.getElementById('product_id_'+data[2]).value;
		var refund_qty = document.getElementById('refund_qty_'+data[2]).value;
		var recitems_id = document.getElementById('recitems_id_'+data[2]).value;
		
		var url="ajax.php?refund_receive_items=yes&prod_id="+prod_id+"&refund_qty="+refund_qty+"&recitems_id="+recitems_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var values_array = xmlhttp.responseText.split('&');
			//alert(values_array);
			
			
			$('#refund_total_'+data[2]).html(values_array[0]);
			
			$('#refund_net_total_'+data[2]).html(values_array[1]);
			
			$('#invoice_amount_static').html(values_array[2]);
			$('#invoice_amount').val(values_array[2]);
			
			$('#amount_payable').html(values_array[3]);
			
			$('#amount_payable_form').val(values_array[3]);
			
			$('#result').html('');
		}
		
	}
	

	
	
});

<!--refund sale items ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".patient_refund_qty").blur(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
				
	
	});
	
	function calculate_item(id)
	{
		var data = id.split('_');
		var prod_id = document.getElementById('product_id_'+data[3]).value;
		var refund_qty = document.getElementById('patient_refund_qty_'+data[3]).value;
		var saleitems_id = document.getElementById('saleitems_id_'+data[3]).value;
		
		var url="ajax.php?refund_sale_items=yes&prod_id="+prod_id+"&refund_qty="+refund_qty+"&saleitems_id="+saleitems_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var values_array = xmlhttp.responseText.split('&');
			//alert(values_array);
			
			
			$('#refund_total_'+data[3]).html(values_array[0]);
			
			$('#refund_net_total_'+data[3]).html(values_array[1]);
			
			$('#invoice_amount').val(values_array[2]);
			
			$('#amount_payable').html(values_array[3]);
			
			$('#result').html('');
		}
		
	}
	

	
	
});


<!--diagnostic items ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".diag_discount").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_diagitem(this.id);
		
	
	});
	
	$(".specimen_no").blur(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_diagitem(this.id);
		
	
	});
	
	function calculate_diagitem(id)
	{
		var data = id.split('_');
		
		var discount = document.getElementById('discount_diag_'+data[2]).value;
		var specimen_no = document.getElementById('specimen_no_'+data[2]).value;
		var diagitems_id = document.getElementById('diagitems_id_'+data[2]).value;
		
		
		var url="ajax.php?diag_items=yes&discount="+discount+"&specimen_no="+specimen_no+"&diagitems_id="+diagitems_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var values_array = xmlhttp.responseText.split('&');
			//alert(values_array);
			//$('#price_'+data[2]).val(values_array[0]);
			$('#net_total_'+data[2]).html(values_array[0]);
			$('#invoice_amount').html(values_array[1]);
			$('#amount_payable').html(values_array[2]);
			$('#amount_payable_form').val(values_array[2]);
			
			$('#result').html('');
		}
		
	}
	
	$(".diag_invoice_discount").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var invoice_discount = document.getElementById('invoice_discount').value;
		
		var url="ajax.php?diag_invoice_discount="+invoice_discount;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var url=document.location.href;
		
			var url2 = url.split('?');
			var url = url2[0];
			window.location.href = url;
		}
	});
	
	$("#reffered_by").blur(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var reffered_by = document.getElementById('reffered_by').value;
		var diaginvoice_id = document.getElementById('diaginvoice_id').value;
		
		var url="ajax.php?r&reffered_by="+reffered_by+"&diaginvoice_id="+diaginvoice_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			$('#result').html('');
		}
		
	
	});
	
	$("#reffered_to").blur(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var reffered_to = document.getElementById('reffered_to').value;
		var diaginvoice_id = document.getElementById('diaginvoice_id').value;
		
		var url="ajax.php?r&reffered_to="+reffered_to+"&diaginvoice_id="+diaginvoice_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			$('#result').html('');
		}
		
	
	});
	
	
});

<!--refund diagnostic items ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".diag_item_refund").click(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		calculate_item(this.id);
				
	
	});
	
	function calculate_item(id)
	{
		var data = id.split('_');
		var diagitems_id = document.getElementById('diagitems_id_'+data[3]).value;
		
		var url="ajax.php?refund_diagnostic_items=yes&diagitems_id="+diagitems_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var values_array = xmlhttp.responseText.split('&');
			//alert(values_array);
			
			$('#invoice_amount').html(values_array[0]);
			
			$('#amount_payable').html(values_array[1]);
			
			$('#result').html('');
			
			$("#diag_item_refund_"+data[3]).css('display','none');
			$("#check_refund_"+data[3]).html('refunded');
		}
		
	}
	

	
	
});

<!--ajax image upload form-->
$(document).ready(function() {
  	$('.ajax_image_submit').click(function(){
		
		var id = $(this).closest('form').attr('id');
		var formElement = document.getElementById(id);
		var formdata = new FormData(formElement);
		
		$(this).closest('form').attr('onsubmit','return false');
		
		var image='<img src="../images/loading.gif" />';
		
		/*var url=document.location.href;
		
		var url2 = url.split('?');
		var url = url2[0];*/
		
			
			
		$.ajax({
		type: "POST",
		url: "ajax.php",
		data:  formdata,
		contentType: false,
    	cache: false,
		processData:false,
		beforeSend: function(){
			
			$('#result_'+id).html(image);
		},
		success: function(data){
			
			var n = data.search("Error"); 
			if(n==0)
			{
				$('#result_'+id).html(data).css('color','red');
				$("html, body").scrollTop(0);
			}
			else
			{
				
				/*$('#result_'+id).html(data).css('color','green');
				window.setTimeout(function(){location.reload()},2000);*/
				
				window.location.href = data;
				
			}
			 
		}
	});
    });
});

<!--retrieve group labtest through ajax-->
$(document).ready(function() {
  
	$(".select_group_tests-window").change(function() {
		
		var group_id = $(".select_group_tests-window").val();
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		var url="ajax.php?group_id="+group_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			$('#default_body_groups').html(xmlhttp.responseText);
		}
		return false;
	});
	
	
});

<!--change visit medical issue ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$(".change_med_issue").change(function() {
	
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest(); 
	}
	else
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	calculate_item(this.id);
	
	});
	
	function calculate_item(id)
	{
		var data = id.split('_');
		var visit_id = document.getElementById('visit_id_'+data[3]).value;
		var med_issue_id = document.getElementById('med_issue_id_'+data[3]).value;
		
		var url="ajax.php?change_visit_medissue=yes&visit_id="+visit_id+"&med_issue_id="+med_issue_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			$('#result').html('');
		}
	}
});


<!--change visit medical issue ajax-->
$(document).ready(function() {
	var xmlhttp=null;
	
	$("#ajax_ward_id").change(function() {
	
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest(); 
	}
	else
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	var ajax_ward_id = $("#ajax_ward_id").val();
	var url="ajax.php?showwardbeds=yes&ajax_ward_id="+ajax_ward_id;
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	
	$('#ajax_bed_id').html(xmlhttp.responseText);
	
	
});
	
	
});


<!--select all through jquery-->
$(document).ready(function() {
    $('#selecctall').click(function(event) {  //on click
        if(this.checked) { // check select status
            $('.checkboxes').each(function() { //loop through each checkbox
                this.checked = true;  //select all checkboxes with class "checkbox1"              
            });
        }else{
            $('.checkboxes').each(function() { //loop through each checkbox
                this.checked = false; //deselect all checkboxes with class "checkbox1"                      
            });        
        }
    });
   
});

$(document).ready(function() {
	$(".ipd_invoice_discount").change(function() {
	
		if (window.XMLHttpRequest)
		{
		  // code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest(); 
		}
		else
		{
		  // code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		var ipd_invoice_discount = document.getElementById('ipd_invoice_discount').value;
		var ipd_bed_allotment_id = document.getElementById('ipd_bed_allotment_id').value;
		
		var url="ajax.php?ipd_invoice_discount="+ipd_invoice_discount+"&ipd_bed_allotment_id="+ipd_bed_allotment_id;
		xmlhttp.open("GET",url,false);
		xmlhttp.send(null);
		
		var n = xmlhttp.responseText.search("Error"); 
		if(n==0)
		{
			$('#result').html(xmlhttp.responseText).css('color','red');
			$("html, body").scrollTop(0);
		}
		else
		{
			var url=document.location.href;
		
			var url2 = url.split('?');
			var url = url2[0];
			window.location.href = url;
		}
	});
});