	var pid = new Array();
	var pname = new Array();
	var attribute = new Array();
	var attributeid = new Array();
	var quantity = new Array();
	var taxrate = new Array();
	var qtyleft = new Array();
	var price = new Array();
	var taxtotal = 0;
	var subtotal = 0;
	var intotal = 0;

	function additem(a_pid,a_name,a_price,a_attribute,a_attributeid,a_qtyleft,a_taxrate)
	{
		pid.push(a_pid);
		pname.push(a_name);
		price.push(a_price);
		quantity.push(1);
		attribute.push(a_attribute);
		attributeid.push(a_attributeid);
		qtyleft.push(a_qtyleft);
		taxrate.push(a_taxrate);
		
		refreshtbl();
		
	}
	
	function refreshtbl()
	{
		var showname = '';
		var showqty = '';
		var showatt = '';
		var showprice = '';
		var showtotal = '';
		var showremove = '';
		
		for (i=0;i<pid.length;i++)
		{
			if(pid[i] != ''){
				showname = showname +'<br/>'+pname[i];
				showatt = showatt +'<br/>'+attribute[i];
				if(quantity[i]>qtyleft[i]){
					showqty = showqty +'<br/><font color=red><b>'+quantity[i]+'</b></font>&nbsp;&nbsp;<a href="#" onclick="addqty('+i+');return false;">[+]</a>&nbsp;<a href="#"onclick="subqty('+i+');return false;">[-]</a>';
				}else{
					showqty = showqty +'<br/>'+quantity[i]+'&nbsp;&nbsp;<a href="#" onclick="addqty('+i+');return false;">[+]</a>&nbsp;<a href="#"onclick="subqty('+i+');return false;">[-]</a>';
				}
				showprice = showprice+'<br/>'+price[i]+''+currencysymbol;
				showremove = showremove +'<br/><a href="#" onclick="removeproduct('+i+');return false;">Remove</a>';
				showtotal = showtotal +'<br/>'+(price[i]*quantity[i])+''+currencysymbol;
			}
		}
		document.getElementById('pnameshow').innerHTML = showname;
		document.getElementById('pattshow').innerHTML = showatt;
		document.getElementById('pqtyshow').innerHTML = showqty;
		document.getElementById('premoveshow').innerHTML = showremove;
		document.getElementById('ppriceshow').innerHTML = showprice;
		document.getElementById('ptotalshow').innerHTML = showtotal;
		document.getElementById('cusname').innerHTML = 'In-Store Customer';
		updatesubtotal()
		updateprice();
	}
	
	function updatesubtotal()
	{
		subtotal = 0;
	
		for (i=0;i<pid.length;i++)
		{
			subtotal = eval(subtotal + eval(price[i]*quantity[i]));
		}
	}
	
	function updateprice()
	{
		intotal = eval(subtotal)
		document.getElementById('invoicetotal').innerHTML = intotal;
		//document.getElementById('finalprice').innerHTML = intotal;
	}
	
	function updatechange()
	{
	try{
		var recieve = document.getElementById('recievedcash').value;
		var change = recieve-intotal;
		change = change.toFixed(2);
		if(change<0)
		{
			change = "<font color=red>"+change+"</font>";
		}	
		document.getElementById('changetotal').innerHTML = change;
	}catch(err){}
	}
	
	function addqty(count)
	{
		
		quantity[count] = quantity[count]+1;
		refreshtbl()
	}
	
	function subqty(count)
	{
		if(quantity[count]>0){
			quantity[count] = quantity[count]-1;
			refreshtbl()
		}
	}
	
	function removeproduct(count)
	{	
		pid[count] = '';
		pname[count] = '';
		attribute[count] = '';
		attributeid[count] = '';
		qtyleft[count] = '';
		quantity[count] = '';
		price[count] = '';
		taxrate[count] = '';
		refreshtbl();
	}
	
	function clearall()
	{
			document.getElementById('discount').value = 0;
			pid = [];
			pname = [];
			attribute = [];
			attributeid = [];
			quantity = [];
			price = [];
			subtotal = 0;
			intotal = 0;
			refreshtbl();
			
	}
	
	function processall()
	{
		var xcor = screen.width/2;
		var ycor = screen.height/2;
	
		document.getElementById('finalprice').innerHTML = document.getElementById('invoicetotal').innerHTML;
		document.getElementById('complete').style.display = 'block';
		document.getElementById('complete').style.left = xcor-150;
		document.getElementById('complete').style.top = ycor-200;
		document.getElementById('mainbody').style.opacity = '0.2';
		document.getElementById('mainbody').style.filter = 'alpha(opacity=20)';
		document.getElementById('recievedcash').focus();
	}

	
	function submitorder()
	{
		var pidsender = '';
		var namesender = '';
		var attsender = '';
		var taxsender = '';
		var qtysender = '';
		var pricesender = '';
		
		updatechange();
		
		for (i=0;i<pid.length;i++)
		{
			if(pid[i] != ''){
				pidsender = pidsender + ';' + pid[i];
				attsender = attsender + ';' + attributeid[i];
				qtysender = qtysender + ';' + quantity[i];
				pricesender = pricesender + ';' + price[i];
				taxsender = taxsender + ';' + taxrate[i];
				if(pid[i] != 'NI'){
					namesender = namesender + ';-';
				}else{
					namesender = namesender + ';' + pname[i];
				}
			}
		}
		
		document.datasender.pidlist.value = pidsender.substring(1);
		document.datasender.attlist.value = attsender.substring(1);
		document.datasender.qtylist.value = qtysender.substring(1);
		document.datasender.pricelist.value = pricesender.substring(1);
		document.datasender.namelist.value = namesender.substring(1);
		
		document.datasender.commentsend.value = document.getElementById('admincomments').value;
		document.datasender.cashrecieved.value = document.getElementById('recievedcash').value;
		document.datasender.orderstatus.value = document.getElementById('statuslist').value;
		if(document.getElementById('posdefaultstatus').checked){
			document.datasender.setstatus.value = 'on';
		}else{
			document.datasender.setstatus.value = 'off';
		}
		
		//document.datasender.customer.value = '0';
		
		var recieve = document.getElementById('recievedcash').value;

		if(document.getElementById('recievedcash').value ==''){
			var r=confirm("Available Points is Empty, proceed with 0 points recieved ?");
			if (r==true){
				document.datasender.submit();
				resetformnow();
			}
		}else if(eval(recieve - intotal)<0){
			var r=confirm("Available Points is less that the total order points, proceed ?");
			if (r==true){
				document.datasender.submit();
				resetformnow();
			}
		}else{
			document.datasender.submit();
			resetformnow();
		}
		
		if(print == '1')
		{
			alert('need to print');
		}
	}
	function cancelsubmit()
	{

		document.getElementById('complete').style.display = 'none';
		document.getElementById('mainbody').style.opacity = '1';
		document.getElementById('mainbody').style.filter = 'alpha(opacity=100)';
	}
	
	function addnoninvshow()
	{
		var xcor = screen.width/2;
		var ycor = screen.height/2;
		document.getElementById('niname').value = '';
		document.getElementById('niprice').value = '';
		document.getElementById('adhocproduct').style.display = 'block';
		document.getElementById('adhocproduct').style.left = xcor-200;
		document.getElementById('adhocproduct').style.top = ycor-250;
		document.getElementById('mainbody').style.opacity = '0.2';
		document.getElementById('mainbody').style.filter = 'alpha(opacity=20)';
	}
	function addnoninvc()
	{
		document.getElementById('adhocproduct').style.display = 'none';
		document.getElementById('mainbody').style.opacity = '1';
		document.getElementById('mainbody').style.filter = 'alpha(opacity=100)';
	}

	function addnoninv()
	{
		//Validation
		if(validation())
		{
			pid.push("NI");
			pname.push(document.getElementById('niname').value);
			price.push(document.getElementById('niprice').value);
			quantity.push(1);
			attribute.push('-');
			taxrate.push(0);
			attributeid.push('[NA]');
			qtyleft.push('9999');
			refreshtbl();
			addnoninvc();
		}
	}
	
	function validation()
	{
		if(document.getElementById('niname').value == '' 
				|| document.getElementById('niprice').value == ''
		){
				alert("Empty fields found");
				return false;
		}else{
			var niproduct = document.getElementById('niname').value;
			var niprice = document.getElementById('niprice').value;
			if(!validatefield(niprice,1)){
				alert("Price should contain decimal numbers only");
				return false;
			}
			if(!validatefield(niproduct,2)){
				alert("Special characters !@#$%^&*()+=-[]\';,./{}|\":<>? not allowed in product name");
				return false;
			}
		}
		return true;
	}
	
	function validatefield(sText,type)
	{
		var ValidChars = "";
		if(type ==1){
			ValidChars = "0123456789.";
		}else if(type ==2){
			ValidChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";
		}
		var returnname=true;
		var Char;
		for (i = 0; i < sText.length && returnname == true; i++) 
		{ 
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1 && type==1) 
			{
				returnname = false;
			}else if(ValidChars.indexOf(Char) != -1 && type==2){
				returnname = false;
			} 
		}
		return returnname;
   }
   
	function customerlistshow()
	{
		var xcor = screen.width/2;
		var ycor = screen.height/2;
		document.getElementById('customerframe').src = 'pos_customer_points.php';
		document.getElementById('customerselect').style.display = 'block';
		document.getElementById('customerselect').style.left = xcor-300;
		document.getElementById('customerselect').style.top = ycor-350;
		document.getElementById('mainbody').style.opacity = '0.2';
		document.getElementById('mainbody').style.filter = 'alpha(opacity=20)';
	}
	
	function customerlistc()
	{
		document.getElementById('customerselect').style.display = 'none';
		document.getElementById('mainbody').style.opacity = '1';
		document.getElementById('mainbody').style.filter = 'alpha(opacity=100)';
	}
	
	function customerchange(type,cid,pname,cpoint)
	{
		if(type=='dd')
		{
			document.datasender.customer.value = document.getElementById('customerlist').value;
			var w = document.getElementById('customerlist').selectedIndex;
			document.getElementById('cusname').innerHTML = document.getElementById('customerlist').options[w].text;
		}else if(type=='search'){

			document.datasender.customer.value = cid;
			document.getElementById('cusname').innerHTML = pname;
			document.getElementById('recievedcash').value = cpoint
			document.getElementById('cashrecieved').value = cpoint
		}
		customerlistc();
	}
	
	function resetformnow()
	{
		document.getElementById('cusname').innerHTML = "In-Store Customer";
		document.getElementById('customer').value = 0;
		document.getElementById('recievedcash').value = 0;
		document.getElementById('_iframe').src ="";
		document.getElementById('productsearch').value = "";
		pid = [];
		pname = [];
		attribute = [];
		attributeid = [];
		quantity = [];
		price = [];
		taxrate = [];
		qtyleft = [];
		subtotal = 0;
		intotal = 0;
		
		refreshtbl();
	}
