// JavaScript Document
///for add runtime tags like meta

function ShowTemprature(admission_id,from,dept_id,ward_id,currYear,currMonth,currDay)
{
	retrieveURL("ajaxindex.php?view=showtemprature&admission_id="+admission_id+"&from="+from+"&dept_id="+dept_id+"&ward_id="+ward_id+"&currYear="+currYear+"&currMonth="+currMonth+"&currDay="+currDay,'inputForm');
}
function ShowSaveTemprature()
{	
	retrieveURL("ajaxindex.php?view=actshowtemprature",'frmtemprature');
}

function ShowBp(admission_id,from,dept_id,ward_id,currYear,currMonth,currDay)
{
	retrieveURL("ajaxindex.php?view=showbp&admission_id="+admission_id+"&from="+from+"&dept_id="+dept_id+"&ward_id="+ward_id+"&currYear="+currYear+"&currMonth="+currMonth+"&currDay="+currDay,'inputForm');
}
function ShowSaveBp()
{	
	retrieveURL("ajaxindex.php?view=actshowbp",'frmbp');
}

function ShowDietplan(admission_id,from,dept_id,ward_id,currYear,currMonth,currDay)
{
	retrieveURL("ajaxindex.php?view=showdietplan&admission_id="+admission_id+"&from="+from+"&dept_id="+dept_id+"&ward_id="+ward_id+"&currYear="+currYear+"&currMonth="+currMonth+"&currDay="+currDay,'inputForm');
}
function ShowSaveDietplan()
{	
	retrieveURL("ajaxindex.php?view=actshowdietplan",'frmdietplan');
}

function moveitemtoporder(newitemid,quantity)
{
			
	
	
	var n = document.frmpharmapurchaseorder.totalcount.value;
	var i ;
	var idarr = new Array();
	var qtyarr = new Array();
	var bool ;
	var txtqty = 'itemqty';
	var txtid = 'itemid';
	
	if(!n)
	{
		idarr[0] =  newitemid;
		qtyarr[0] =  quantity;
	
	}
	else
	{
		
for(i=0;i<n;i++)
	{
		alert(i);
		if(document.getElementById(txtid+i).value == newitemid)
		{
			
			bool =  false;	
			break;
		}
		else
		{
			
				idarr[i] = document.getElementById(txtid+i).value;
				qtyarr[i] = document.getElementById(txtqty+i).value;
		
		}
		
	
	}	
	
	
	if(bool == false)
		{
		alert('this item is already added in your list');
		return false;
		}
	
	idarr[n] =  newitemid;
	qtyarr[n] =  quantity;
	
	
	}
	
	

	
	
	
	var http = getHTTPObject(); // We create the HTTP Object
			var poststr;
			subject_id = 'porderlist';
			http.open("POST", "ajaxindex.php?view=actpharmapurchaseorder&move=1" , true);
			http.onreadystatechange = function () {
		if (http.readyState == 4) {
			if (subject_id != '') {
								
						var varredirect=http.responseText.indexOf('Session_Expire'); 

						if (varredirect!= -1 ) { 
						window.location.href = 	window.location.href;
						} 
						else
						{
						



document.getElementById(subject_id).innerHTML =   http.responseText; 
						
						}


//alert(document.getElementById(subject_id).innerHTML);
				}
		}
	};
	
				
				
		var idstr = idarr.join();
		var qtystr= qtyarr.join();				
				
		
		alert(idstr);
		
poststr = "idstr="+idstr+"&qtystr="+qtystr;
	        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send(poststr);
}

function removeitemfromporder(newitemid)
{
			
			
var n = document.frmpharmapurchaseorder.totalcount.value;
	var i ;
	var idarr = new Array();
	var qtyarr = new Array();
	var bool ;
	var txtqty = 'itemqty';
	var txtid = 'itemid';
	
	for(i=0;i<n;i++)
	{
		
				
				idarr[i] = document.getElementById(txtid+i).value;
				qtyarr[i] = document.getElementById(txtqty+i).value;
	}			
			
			var http = getHTTPObject(); // We create the HTTP Object
			var poststr;
			subject_id = 'porderlist';
			http.open("POST", "ajaxindex.php?view=actpharmapurchaseorder&move=1" , true);
			http.onreadystatechange = function () {
		if (http.readyState == 4) {
			if (subject_id != '') {
								
						var varredirect=http.responseText.indexOf('Session_Expire'); 

						if (varredirect!= -1 ) { 
						window.location.href = 	window.location.href;
						} 
						else
						{
						

document.getElementById(subject_id).innerHTML =  http.responseText; 
						
						}


//alert(document.getElementById(subject_id).innerHTML);
				}
		}
	};
	
				
			
				var idx_of_id = idarr.indexOf(newitemid);
				
				idarr.splice(idx_of_id,1);
				qtyarr.splice(idx_of_id,1);

		var idstr = idarr.join();
		var qtystr= qtyarr.join();				
				
				
					
poststr = "idstr="+idstr+"&qtystr="+qtystr;
	        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send(poststr);
}


function moveitemtorecorder(newitemid,quantity)
{
			
		var n = document.frmpharmareceivedorder.totalcount.value;

	var i ;
	var idarr = new Array();
	var qtyarr = new Array();
	var pricearr = new Array();
	var batchnoarr = new Array();

	var bool ;
	var txtqty = 'itemqty';
	var txtid = 'itemid';
	var txtprice = 'itemprice';
	var txtbatchno = 'itembatchno';

	if(!n)
	{
		idarr[0] =  newitemid;
		qtyarr[0] =  10;
//		pricearr[i] = 10;
		pricearr[0] = 10;
		batchnoarr[0] = '';

	}
	else
	{
		
for(i=0;i<n;i++)
	{
		alert(i);
		if(document.getElementById(txtid+i).value == newitemid)
		{
			
			bool =  false;	
			break;
		}
		else
		{
				
				idarr[i] = document.getElementById(txtid+i).value;
				qtyarr[i] = document.getElementById(txtqty+i).value;
				pricearr[i] = document.getElementById(txtprice+i).value;
				batchnoarr[i] = document.getElementById(txtbatchno+i).value;
				alert(pricearr[i]);
				alert(batchnoarr[i]);
		
		}
		
	
	}	
	
	
	if(bool == false)
		{
		alert('this item is already added in your list');
		return false;
		}
	
	idarr[n] =  newitemid;
	qtyarr[n] =  10;
	pricearr[n] =  10;
	batchnoarr[n] =  '';

	}
	
	

	
	
	
	var http = getHTTPObject(); // We create the HTTP Object
			var poststr;
			subject_id = 'porderlist';
			http.open("POST", "ajaxindex.php?view=actpharmareceiveorder&move=1" , true);
			http.onreadystatechange = function () {
		if (http.readyState == 4) {
			if (subject_id != '') {
								
						var varredirect=http.responseText.indexOf('Session_Expire'); 

						if (varredirect!= -1 ) { 
						window.location.href = 	window.location.href;
						} 
						else
						{
						

						alert(http.responseText);
document.getElementById(subject_id).innerHTML =   http.responseText; 
						
						}


//alert(document.getElementById(subject_id).innerHTML);
				}
		}
	};
	
				
				
		var idstr = idarr.join();
		var qtystr= qtyarr.join();				
		var pricestr= pricearr.join();				
		var batchnostr= batchnoarr.join();
		
					
poststr = "idstr="+idstr+"&qtystr="+qtystr+"&pricestr="+pricestr+"&batchnostr="+batchnostr;
	        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send(poststr);
}

function removeitemfromrecorder(newitemid)
{
			
			
var n = document.frmpharmareceivedorder.totalcount.value;
	var i ;
	var idarr = new Array();
	var qtyarr = new Array();
	var pricearr = new Array();
	var batchnoarr = new Array();

	var bool ;
	var txtqty = 'itemqty';
	var txtid = 'itemid';
	var txtprice = 'itemprice';
	var txtbatchno = 'itembatchno';

	for(i=0;i<n;i++)
	{
		
				
				idarr[i] = document.getElementById(txtid+i).value;
				qtyarr[i] = document.getElementById(txtqty+i).value;
				pricearr[i] = document.getElementById(txtprice+i).value;
				batchnoarr[i] = document.getElementById(txtbatchno+i).value;
	}			
			
			var http = getHTTPObject(); // We create the HTTP Object
			var poststr;
			subject_id = 'porderlist';
			http.open("POST", "ajaxindex.php?view=actpharmareceiveorder&move=1" , true);
			http.onreadystatechange = function () {
		if (http.readyState == 4) {
			if (subject_id != '') {
								
						var varredirect=http.responseText.indexOf('Session_Expire'); 

						if (varredirect!= -1 ) { 
						window.location.href = 	window.location.href;
						} 
						else
						{

document.getElementById(subject_id).innerHTML =  http.responseText; 
						
						}


//alert(document.getElementById(subject_id).innerHTML);
				}
		}
	};
	
				
			
				var idx_of_id = idarr.indexOf(newitemid);
				
				idarr.splice(idx_of_id,1);
				qtyarr.splice(idx_of_id,1);
				pricearr.splice(idx_of_id,1);
				batchnoarr.splice(idx_of_id,1);

		var idstr = idarr.join();
		var qtystr= qtyarr.join();				
		var pricestr= pricearr.join();				
		var batchnostr= batchnoarr.join();				

				
					
poststr = "idstr="+idstr+"&qtystr="+qtystr+"&pricestr="+pricestr+"&batchnostr="+batchnostr;
	        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send(poststr);
}


function searchcatalog(deptid,page)
{
	
	alert('hh');
	var view;
	if(page == 'receive')
			view = 'actpharmareceiveorder'; 
	else
			view = 'actpharmapurchaseorder'; 
	
	var http = getHTTPObject(); // We create the HTTP Object
			var poststr;
			subject_id = 'searchresult';
			http.open("POST", "ajaxindex.php?view="+view+"&searchcatalog=1" , true);
			http.onreadystatechange = function () {
		if (http.readyState == 4) {
			if (subject_id != '') {
								
						var varredirect=http.responseText.indexOf('Session_Expire'); 

						if (varredirect!= -1 ) { 
						window.location.href = 	window.location.href;
						} 
						else
						{
						

document.getElementById(subject_id).innerHTML =  http.responseText; 
						
						}


//alert(document.getElementById(subject_id).innerHTML);
				}
		}
	};
	
poststr = "deptid="+deptid+"&searchvalue="+document.getElementById('txtsearch').value;
	        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.send(poststr);
	
}