function checkrepeat(a)
{
	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)
	{
	if( xmlhttp.responseText ==0 ){
	document.getElementById('showerror').innerHTML = '';
	}
	if( xmlhttp.responseText ==1 ){
	// alert("Entered GC-Number Already taken,Please  try again");
	document.getElementById('customer_mobile').value='';
	document.getElementById('customer_mobile').select();
	document.getElementById('customer_mobile').focus();
	document.getElementById("showerror").innerHTML = '<span style="color:red;font-size:17px;font-weight:bold;text-decoration:blink">Already Customer Exist</span>';
	}
	}
	}
	var mobile=document.getElementById(a).value;
	xmlhttp.open("GET","check_no.php?mobileno="+mobile,true);
	xmlhttp.send();
}
function checkvehicle(a)
{
	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)
	{
	if(xmlhttp.responseText ==0 ){
	document.getElementById('vehicleno').innerHTML = '<input type="text" name="vehicle_number" id="vehicle_number" value"">';
	}
	else
	{
	var s=xmlhttp.responseText.split('|');
	document.getElementById('vehicleno').innerHTML='';
	document.getElementById('vehicleno').innerHTML=s['0'];
	document.getElementById('customer_name').value=s['1'];
	document.getElementById('customerid').value=s['2'];
	document.getElementById('customeriddiv').innerHTML=s['2'];
	document.getElementById('vehicle_make').value=s['3'];
	document.getElementById('customer_address').value=s['4'];
	document.getElementById('phonenumber').value=s['5'];
	document.getElementById('mailid').value=s['6'];
	}
	}
	}
	var mobile=document.getElementById(a).value;
	xmlhttp.open("GET","check_vehicle.php?mobileno="+mobile,true);
	xmlhttp.send();
}
function check_register_cutomer(a)
{
var radios = document.getElementsByName(a);
	for (var i = 0, length = radios.length; i < length; i++) {
		if (radios[i].checked) {
			// do whatever you want with the checked radio
			val=radios[i].value;
			// only one radio can be logically checked, don't check the rest
			break;
		}
		else
		{
		val='';
		}
	}
	if(val=='new')
	{
	document.register.action='customer_entrynew.php';
	}
	if(val=='existing')
	{
	document.register.action='customer_entryexist.php';
	}
	if(val =='')
	{
	alert('Please select the role');
	return false;
	}
	else{
	document.register.submit();
	}
}
function check_exsitingcustomer(a)
{
	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)
	{
		if(xmlhttp.responseText ==0 ){
		document.getElementById('showerror').innerHTML = '';
		}
		else{
		//alert(xmlhttp.responseText);
		var s=xmlhttp.responseText.split('|');
		document.getElementById('customer_name').value=s['0'];
		document.getElementById('customerid').value=s['1'];
		document.getElementById('customeriddiv').innerHTML=s['1'];
		document.getElementById('vehicle_number').value=s['2'];
		document.getElementById('vehicle_make').value=s['3'];
		document.getElementById('customer_address').value=s['4'];
		document.getElementById('phonenumber').value=s['5'];
		document.getElementById('mailid').value=s['6'];
		}
	}
	}
	var mobile=document.getElementById(a).value;
	xmlhttp.open("GET","check_existing.php?mobileno="+mobile,true);
	xmlhttp.send();
}

function append_row()
{
//alert('calling');
var grand_total=0;
var count = document.getElementById('purchaseditems').rows.length;
var table = document.getElementById("purchaseditems");
var row = table.insertRow(count);
row.id='purchase_row'+count;
var cell1 = row.insertCell(0);
cell1.innerHTML=count;
var cell2 = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'item_name[]';
el.id = 'item_name' + count;
el.setAttribute("size", "100");
el.setAttribute("align", "center");
cell2.appendChild(el);
var cell3 = row.insertCell(2);
var e2 = document.createElement('input');
e2.type = 'text';
e2.name = 'item_price[]';
e2.id = 'item_price' + count;
cell3.appendChild(e2);
count++;
}

var $count=1;
//var $grand_total1=0;
function calculateamount($price,$qty,$tax,$was,$stock,tot)
{
//alert('calling');
var $grand_total=0;
var $count = document.getElementById('purchaseditems').rows.length;
if($qty=="")
{
alert("Enter Quantity...");
document.getElementById('purchase_item_qty').focus();
}
else
{
$total=$qty*$price;
if($tax !='')
{
$taxvalue=$total/$tax;
$total=$total+$taxvalue;
}
//alert($total);
$grand_total=$total;
$grand_total1=document.getElementById('grand').value;
if($grand_total1 =='')
{
$grand_total1=0;
}
$grand_total1=parseInt($grand_total1)+parseInt($total);
//alert(tot);
document.getElementById(tot).value=$total;
document.getElementById('grand').value=$grand_total1;
$count++;
}
}

function delete_row(page,id)
{
if(page=="bom")
	{
		tot=document.getElementById("item_total"+id).value;
		$grand_total=document.getElementById('grand').value;
		$grand_total=$grand_total-tot;
		document.getElementById('grand').value=$grand_total;
		var a=document.getElementById("purchaseditems");
		document.getElementById("purchase_row"+id).innerHTML='';
	}
}
function typefunc(a)
{
	var val=document.getElementById(a).value;
	if(val =='Invoice')
	{
		document.getElementById('discounttr').style.display='';
		document.getElementById('needtopaytr').style.display='';
		document.getElementById('duetr').style.display='';
		document.getElementById('balancetr').style.display='';
	}
	else
	{
		document.getElementById('discounttr').style.display='none';
		document.getElementById('needtopaytr').style.display='none';
		document.getElementById('duetr').style.display='none';
		document.getElementById('balancetr').style.display='none';
	}
}
function totalvalue(a)
{
	var count = document.getElementById('purchaseditems').rows.length;
	var total=0;
	var val=0;
	for(i=1;i<count;i++)
	{
		//alert(i);
		val=document.getElementById('item_price'+i).value;
		//alert(val);
		if(val!='')
		{
		total+=parseInt(val);
		}
	}
	document.getElementById(a).value=total;
}
function discountcal(a,b,c)
{
	var dis=document.getElementById(a).value;
	var tot=document.getElementById(b).value;
	var v;
	if(dis!='' && dis!=0)
	{
		x=parseInt(tot) / 100;
		v=parseInt(x) * dis;
		to=parseInt(tot) - v;
		//alert(to);
		document.getElementById(c).value=to;
	}
	else
	{
		document.getElementById(c).value=tot;
	}	
}
function duebalance(a,b,c)
{
	var due=document.getElementById(a).value;
	var need=document.getElementById(b).value;
	var v;
	if(due!='' && due!=0)
	{
		to=parseInt(need) - due;
		document.getElementById(c).value=to;
	}
	else
	{
		document.getElementById(c).value=need;
	}
	
}
function saveform()
{
document.register.submit('');
}
// new
function editform(a)
{
document.editformname.userid.value=a;
document.editformname.submit();
}
function editform1(a)
{
document.editformname.cid.value=a;
document.editformname.submit();
}
function deleteform(a)
{
document.deleteformname.cid.value=a;
document.deleteformname.submit();
}
function editform3(a)
{
document.editformname.tid.value=a;
document.editformname.submit();
}
function deleteform3(a)
{
document.deleteformname.tid.value=a;
document.deleteformname.submit();
}