<?php
if($_REQUEST['submit']!='')
{	

if($_REQUEST['item']!=''){
				$itemArray=$_REQUEST['item'];
				$itemIds=implode(",",$itemArray);
				}else{
				$itemIds='';
				}

	 $sql = "INSERT INTO suppliers set  
				 vendor_code='".$_REQUEST['vendor_code']."',
				 vendor_name='".$_REQUEST['vendor_name']."',    
				 category='".$_REQUEST['category']."',    
				 account_group ='".$_REQUEST['account_group']."',   
				 vendor_type='".$_REQUEST['vendor_type']."',    
				 site='".$_REQUEST['site']."',      
				 short_name ='".$_REQUEST['short_name']."',   
				 adrress1='".$_REQUEST['adrress1']."',    
				 adrress2='".$_REQUEST['adrress2']."',    
				 address3='".$_REQUEST['address3']."',   
				 country='".$_REQUEST['country']."',    
				 state='".$_REQUEST['state']."',     
				 city='".$_REQUEST['city']."',      
				 pincode='".$_REQUEST['pincode']."',    
				 extension='".$_REQUEST['extension']."',    
				 phone1='".$_REQUEST['phone1']."',    
				 phone2='".$_REQUEST['phone2']."',    
				 mobile ='".$_REQUEST['mobile']."',   
				 fax='".$_REQUEST['fax']."',       
				 email='".$_REQUEST['email']."',     
				 pan_no ='".$_REQUEST['pan_no']."',   
				 tin_no='".$_REQUEST['tin_no']."',    
				 lst_no ='".$_REQUEST['lst_no']."',   
				 cst_no ='".$_REQUEST['cst_no']."',   
				 excise_no='".$_REQUEST['excise_no']."',    
				 payterms='".$_REQUEST['payterms']."',    
				 tax_group='".$_REQUEST['tax_group']."',  
				 sup_range='".$_REQUEST['sup_range']."',    
				 sup_division='".$_REQUEST['sup_division']."',
				 tds_selection='".$_REQUEST['tds_selection']."'
				,assigned_items='".$itemIds."',
				CompanyId='".$_SESSION['ACGCompanyId']."'";
				
				 
				 //tds_percentage='".$_REQUEST['tds_percentage']."'"; 
	$result = DB_query($sql,$db);
	$lastid=DB_Last_Insert_ID($db,'suppliers','id');
	if($lastid!=''){


$data['AccountName']=$_REQUEST['vendor_name'];
$data['vender_client']=$lastid;
$data['UnderGroup']=$_REQUEST['account_group'];
$data['CompanyId']=1;
$data['ledgertype']='vendor';
$rowinsert= $s->RecordInsert('accountledger', $data);

	for($ctr=1;$ctr<$_REQUEST['counter'];$ctr++)
	{
		$contact_sql="Insert into contact_information_master set
							master_code='".$lastid."',  
							master_prefix='S',  
							person='".$_REQUEST['person'][$ctr]."',   
							designation= '".$_REQUEST['designation'][$ctr]."',  
							phone='".$_REQUEST['phone'][$ctr]."',    
							email= '".$_REQUEST['contact_email'][$ctr]."' ";
		$contact_res=DB_query($contact_sql,$db);
	}}
echo "<script>location.href='index.php?route=Supplier_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
if($_REQUEST['ID']!='')
{
	$sql=DB_query("Select * from suppliers where id='".$_REQUEST['ID']."'",$db);
	$myrow=DB_fetch_array($sql);
	
	$vendor_code = stripcslashes($myrow['vendor_code']);
	$vendor_name = stripcslashes($myrow['vendor_name']);
	$category = stripcslashes($myrow['category']);							
	$account_group = stripcslashes($myrow['account_group']);									
	$vendor_type = stripcslashes($myrow['vendor_type']);
	$site = stripcslashes($myrow['site']);
	$short_name = stripcslashes($myrow['short_name']);
	$adrress1 = stripcslashes($myrow['adrress1']);
	$adrress2 = stripcslashes($myrow['adrress2']);
	$address3 = stripcslashes($myrow['address3']);
	$country = stripcslashes($myrow['country']);
	$state = stripcslashes($myrow['state']);
	$city = stripcslashes($myrow['city']);
	$pincode = stripcslashes($myrow['pincode']);
	$extension = stripcslashes($myrow['extension']);
	$phone1 = stripcslashes($myrow['phone1']);
	$phone2 = stripcslashes($myrow['phone2']);
	$mobile = stripcslashes($myrow['mobile']); 
	$fax = stripcslashes($myrow['fax']);
	$email = stripcslashes($myrow['email']);
	$pan_no = stripcslashes($myrow['pan_no']);
	$tin_no = stripcslashes($myrow['tin_no']);
	$lst_no = stripcslashes($myrow['lst_no']);
	$cst_no = stripcslashes($myrow['cst_no']);
	$excise_no = stripcslashes($myrow['excise_no']);
	$payterms = stripcslashes($myrow['payterms']);
	$tax_group = stripcslashes($myrow['tax_group']);
	$sup_range = $myrow['sup_range'];
	$sup_division = $myrow['sup_division'];
	$tds_selection = $myrow['tds_selection'];
	$assigned_items =$myrow['assigned_items'];
		//$tds_percentage = $myrow['tds_percentage'];
	
	$get_contact="select * from contact_information_master where master_code='".$_REQUEST['ID']."' and master_prefix='S' ";
	$contact_res=DB_query($get_contact,$db);
		$j=1;
		while($contact_row=DB_fetch_array($contact_res))
		{
			$row_id[$j]=$contact_row['id'];
			$person[$j]=$contact_row['person'];
			$designation[$j]=$contact_row['designation'];
			$phone[$j]=$contact_row['phone'];
			$contact_email[$j]=$contact_row['email'];
			$j++;
		}	
}
else 
{
	$vendor_code = $_REQUEST['vendor_code'];
	$vendor_name = $_REQUEST['vendor_name'];
	$category = $_REQUEST['category'];							
	$account_group = $_REQUEST['account_group'];									
	$vendor_type = $_REQUEST['vendor_type'];
	$site = $_REQUEST['site'];
	$short_name = $_REQUEST['short_name'];
	$adrress1 = $_REQUEST['adrress1'];
	$adrress2 = $_REQUEST['adrress2'];
	$address3 = $_REQUEST['address3'];
	$country = $_REQUEST['country'];
	$state = $_REQUEST['state'];
	$city = $_REQUEST['city'];
	$pincode = $_REQUEST['pincode'];
	$extension = $_REQUEST['extension'];
	$phone1 = $_REQUEST['phone1'];
	$phone2 = $_REQUEST['phone2'];
	$mobile = $_REQUEST['mobile']; 
	$fax = $_REQUEST['fax'];
	$email = $_REQUEST['email'];
	$pan_no = $_REQUEST['pan_no'];
	$tin_no = $_REQUEST['tin_no'];
	$lst_no = $_REQUEST['lst_no'];
	$cst_no = $_REQUEST['cst_no'];
	$excise_no = $_REQUEST['excise_no'];
	$payterms = $_REQUEST['payterms'];
	$tax_group = $_REQUEST['tax_group'];
	$sup_range = $_REQUEST['sup_range'];
	$sup_division = $_REQUEST['sup_division'];
	$tds_selection = $_REQUEST['tds_selection'];
	$assigned_items =$row['assigned_items'];
	//$tds_percentage = $_REQUEST['tds_percentage'];
	
	for($j=1;$j<$_REQUEST['counter'];$j++)
		{
			$person[$j]=$_REQUEST['person'];
			$designation[$j]=$_REQUEST['designation'];
			$phone[$j]=$_REQUEST['phone'];
			$contact_email[$j]=$_REQUEST['email'];
			$j++;
		}
}
if($_REQUEST['Update']!='')
{


$data['AccountName']=$_REQUEST['vendor_name'];
$data['UnderGroup']=$_REQUEST['account_group'];
$data['CompanyId']=1;
$data['ledgertype']='vendor';
$data['vender_client']=$_GET['id'];

	
$chkledgerExist=DB_query("select * from accountledger where AccountName='".$_REQUEST['vendor_name']."' and UnderGroup='".$_REQUEST['account_group']."' and ledgertype='vendor'",$db);
if(DB_num_rows($chkledgerExist)==0)
{
 	$rowinsert= $s->RecordInsert('accountledger', $data);
 }
else
{
    $cond="AccountName='".$_REQUEST['vendor_name']."'";
 	$rowinsert= $s->RecordEdit('accountledger', $data, $cond);
}
		
	
	if($_REQUEST['item']!=''){
				$itemArray=$_REQUEST['item'];
				$itemIds=implode(",",$itemArray);
				}else{
				$itemIds='';
				}
	
	
	
	 $Updatesql = "UPDATE suppliers SET vendor_code = '".$_REQUEST['vendor_code']."' ,  
				 vendor_name= '".$_REQUEST['vendor_name']."' ,  
				 category= '".$_REQUEST['category']."' ,  
				 account_group = '".$_REQUEST['account_group']."' , 
				 vendor_type= '".$_REQUEST['vendor_type']."' ,  
				 site= '".$_REQUEST['site']."' ,    
				 short_name = '".$_REQUEST['short_name']."' , 
				 adrress1= '".$_REQUEST['adrress1']."' ,  
				 adrress2= '".$_REQUEST['adrress2']."' ,  
				 address3= '".$_REQUEST['address3']."' , 
				 country= '".$_REQUEST['country']."' ,  
				 state= '".$_REQUEST['state']."' ,   
				 city= '".$_REQUEST['city']."' ,    
				 pincode= '".$_REQUEST['pincode']."' ,  
				 extension= '".$_REQUEST['extension']."' ,  
				 phone1= '".$_REQUEST['phone1']."' ,  
				 phone2= '".$_REQUEST['phone2']."' ,  
				 mobile = '".$_REQUEST['mobile']."' , 
				 fax= '".$_REQUEST['fax']."' ,     
				 email= '".$_REQUEST['email']."' ,   
				 pan_no = '".$_REQUEST['pan_no']."' , 
				 tin_no= '".$_REQUEST['tin_no']."' ,  
				 lst_no = '".$_REQUEST['lst_no']."' , 
				 cst_no = '".$_REQUEST['cst_no']."' , 
				 excise_no= '".$_REQUEST['excise_no']."' ,  
				 payterms= '".$_REQUEST['payterms']."' ,  
				 tax_group= '".$_REQUEST['tax_group']."', 
				 sup_range ='" . $_REQUEST['sup_range'] . "',
				 sup_division ='" . $_REQUEST['sup_division'] ."',
				 tds_selection='".$_REQUEST['tds_selection']."',
				 assigned_items='".$itemIds."',CompanyId='".$_SESSION['ACGCompanyId']."'
				 WHERE id = '".$_REQUEST['ID']."'"; 
				
				 ///				 tds_percentage='".$_REQUEST['tds_percentage']."'
	$updateresult=DB_query($Updatesql,$db);
	
	for($m=1;$m<$_REQUEST['counter'];$m++)	
	{					
		$update_sql="Update contact_information_master set
						person='".$_REQUEST['person'][$m]."', 
						designation= '".$_REQUEST['designation'][$m]."',  
						phone='".$_REQUEST['phone'][$m]."',    
						email='".$_REQUEST['contact_email'][$m]."' 
						where id='".$_REQUEST['row_id'][$m]."'";
		//echo "<pre>";
		//print_r($update_sql);
		$update_res=DB_query($update_sql,$db);
	}
echo "<script>location.href='index.php?route=Supplier_list&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";
}
?>
<script src="js/function-ajax.js" language="javascript"></script>

<script language="JavaScript" type="text/javascript">
function search_state(str)
{
	//alert(str);
if (str.length==0)
  {
  document.getElementById("searchstate").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("searchstate").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_state1.php?country="+str,true);
xmlhttp.send();
}

 function search_city(str)
{
	//alert(str);
	var country = document.getElementById("country").value;
	//alert("country="+country);
	if (str.length==0)
  {
  document.getElementById("searchcity").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("searchcity").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_city1.php?state="+str+"&country="+country,true);
xmlhttp.send();
}
</script><head>
<script src="js/function-ajax.js" language="javascript"></script>

<h2 align="center">New Vendor</h2></head>
<input type='hidden' name='New' value='Yes'>
<form action="" method="post">
<table width="70%" align="center" border="0">
	<tr>
		<td>
			<table width="100%" align="center" border="0" cellpadding="2" cellspacing="2">
			<tr><th colspan="4"><p align="center">General Details</p></th></tr>
			<tr>
			<th>Vendor Name</th>
			<td><input name="vendor_name" type="text" class="cap" value="<?php echo $vendor_name;?>" size="30" onblur="ShowDiv(this.value,'hid-SupplierID','suppliercode.php')"></td>
			<th>*Category</th>
	   		<td>
	   			<select name="category" class="cap" ><!--onChange="VendorCodeGenerator(this.value)"-->
	  			<option value="000">Select Category</option>
	 			<?php
	 			$get_category=DB_query("Select * from category_master",$db);
	 			while($cat_res=DB_fetch_array($get_category))
	 			{
	 			?>
	 			<option value="<?php echo $cat_res['id'];?>"<?php echo($category==$cat_res['id']?'selected':'')?>><?php echo $cat_res['name'];?></option>
	 			<?php } ?>
	 			</select>
			</td>
			</tr>
			<tr>
			<th>*Vendor Code</th>
	   		<td><div id="hid-SupplierID"><input type="text" name="vendor_code" class="cap" value="<?php echo $vendor_code;?>" size="30"></div></td>
			
			<th>*Account Group</th>
			<td>
  			<?php 
  			$acc_sql="Select GroupId from accountgroupmaster where GroupName = 'creditor'";
  			$acc_res=DB_query($acc_sql,$db);
  			$acc_row=DB_fetch_array($acc_res);
  			$AccountId=$acc_row['GroupId'];
  
 			$ledger_sql=DB_query("Select GroupId, GroupName from accountgroupmaster where MainGroupId='".$AccountId."'",$db);
   			?>
	 		<select name="account_group" class="cap">
			<?php while($ledger_row=DB_fetch_array($ledger_sql)) 
			{?>
 			<option Value="<?php echo $ledger_row['GroupId'];?>" <?php echo ($account_group==$ledger_row['GroupId']?'selected':'');?>><?php echo $ledger_row['GroupName'];?></option>
  			<?php }	?>  
        	</select></td>	
			</tr>
			
			<tr>
			<th>*Short Name</th>
			<td><input type="text" name="short_name" class="cap" value="<?php echo $short_name;?>" size="30"></td>	
			<th>*Vendor Type</th>
			<td>
			<select name="vendor_type" class="cap">
            <option Value="Manufacturer" <?php echo ($vendor_type=='Manufacturer'?'selected':'');?>>Manufacturer</option>
			<option Value="Distributer" <?php echo ($vendor_type=='Distributer'?'selected':'');?>>Distributer</option>
			<option Value="Dealer" <?php echo ($vendor_type=='Dealer'?'selected':'');?>>Dealer</option>
			<option Value="Transporter" <?php echo ($vendor_type=='Transporter'?'selected':'');?>>Transporter</option>
			<option Value="Others" <?php echo ($vendor_type=='Others'?'selected':'');?>>Others</option>
            </select></td>
			</tr>
			<tr>
			<td></td><td></td>
			<th>Branch</th>
	   		<td><select name="site" class="cap">
	   		<?php
	   		$result=DB_query("SELECT locationname, loccode FROM locations where CompanyId='".$_SESSION['ACGCompanyId']."'
    and loccode in('".$_SESSION['AssignedBranch']."')", $db);
			while($myrow = DB_fetch_array($result))
	 		{
	 		$p='';
			if($site==$myrow['loccode'])
			$p="selected";
	 		?>
			<option VALUE="<?php echo $myrow['loccode'];?>"<?php echo $p;?>><?php echo $myrow['locationname'];?></option>
			<?php }?> 
			</select></td>	
			</tr>	
			</table>
		</td>
	</tr>
	
	<tr>
		<td>
			<table width="100%" cellpadding="2" cellspacing="2" align="center">
				<tr><th colspan="4"><p align="center">Address</p></th></tr>
			<tr>
			<th rowspan="3" width="19%">*Address</th>
			<td><input type="text" name="adrress1" class="cap" value="<?php echo $adrress1;?>" size="30"></td>
			<th width="21%">*Pin Code</th>
			<td><input type="text" name="pincode" class="cap" value="<?php echo $pincode;?>"size="30"></td>
			</tr>	
			<tr>
			<td><input type="text" name="adrress2" class="cap" value="<?php echo $adrress2;?>" size="30"></td>
			<th>Extension</th>
	   		<td><input type="text" name="extension" value="<?php echo $extension;?>"size="30"></td>
			</tr>
			<tr>
			<td><input type="text" name="address3" class="cap" value="<?php echo $address3;?>" size="30"></td>
			<th>*Phone1</th>
			<td><input type="text" name="phone1" value="<?php echo $phone1;?>"size="30"></td>
			</tr>
			<tr>
			<th>*Country</th>
			<td><select name="country" class="cap"  id="country" onchange="search_state(this.value)">
	   		<option value="000">---Select Country---</option>
	   		<?php
	   		$country_sql = "select * from country_master";
	   		$c_result = DB_query($country_sql,$db);
	   		while($c_row = DB_fetch_array($c_result))
	   		{ 	$p='';
	   		if($country==$c_row['id'])
			$p="selected";
	   
	   		?>
      	<option value="<?php echo $c_row['id']; ?>"<?php echo $p;?>><?php echo $c_row['country']; ?></option>
		<?php } ?>
		</select></td>
		<th>Phone2</th>
		<td><input type="text" name="phone2" value="<?php echo $phone2;?>"size="30"></td>
		</tr>
		<tr>
		<th>*State</th>
	   	<td><div id="searchstate">
	   		<select name="state" class="cap" onchange="search_city(this.value)">
        <option value="000">---Select State---</option>
		<?php 
	    $sql = "select * from state_master where country = '".$country."' ";
		$result=DB_query($sql,$db);
		while($myrow=DB_fetch_array($result))
		{ 
			$p='';
			if($state==$myrow['id'])
			$p="selected";
		?>
		<option value="<?php echo $myrow['id'];?>"<?php echo $p;?>><?php echo $myrow['state']; ?></option>
		<?php }
	   ?>
          </select></div></td>
		  <th>*Mobile</th>
		  <td><input type="text" name="mobile" value="<?php echo $mobile;?>"size="30"></td>
		  </tr>
		<tr>
		<th>*City</th>
	   <td><div id="searchcity"><select name="city" class="cap">
	   <option value="000">---Select City---</option>
	     <?php 
	   $sql = "select * from city_master where country='".$country."' and state='".$state."'";
	   $result = DB_query($sql,$db);
	   while($city_row = DB_fetch_array($result))
	   {
	   		$p='';
			if($city==$city_row['id'])
			$p="selected";
	   ?>
	  <option value="<?php echo $city_row['id']; ?>" <?php echo $p;?>><?php echo $city_row['city']; ?></option>
	   <?php }?>
            </select></div></td>
           <th>Fax</th><td><input type="text" name="fax" value="<?php echo $fax;?>"></td> 
            </tr>
			<tr>
				<td></td><td></td>
		<th>E-mail</th>
	   <td><input name="email" type="text" value="<?php echo $email;?>" size="30"/></td>
	   </tr>
			</table>
		</td>
	</tr>
<tr>
<td>
<table width="100%" cellpadding="2" cellspacing="2" align="center">
<tr><th colspan="4"><p align="center">Others</p></th></tr>
<tr>
<th width="19%">PAN No.</th>
<td><input type="text" name="pan_no" class="cap" value="<?php echo $pan_no;?>"size="30"></td>
<th width="21%">Pay Terms</th>
	   <td><select name="payterms" class="cap">
	   <?php 
	   $result=DB_query('SELECT terms, termsindicator FROM paymentterms', $db);
	while ($myrow = DB_fetch_array($result)) 
	{	$p='';
		if($payterms==$myrow['termsindicator'])
		$p="selected";	
	?>
		<option VALUE="<?php echo $myrow['termsindicator'];?>"<?php echo $p;?>><?php echo $myrow['terms']; ?></option>
	<?php } ?>
	</option></select></td>
</tr>
<tr>
<th>*TIN No.</th>
<td><input type="text" name="tin_no" class="cap" value="<?php echo $tin_no;?>"size="30"></td>	
<th>Tax Group</th>
	     <td><select name="tax_group" class="cap">
             <?php 
	   $sql='SELECT salestax_id,tax_code FROM sales_tax_master';
	   $result=DB_query($sql,$db);
	   while($myrow = DB_fetch_array($result))
		   {
		   		$p='';
				if($tax_group==$myrow['salestax_id'])
				$p="selected";
		   ?>
             <option value="<?php echo $myrow['salestax_id'];?>"<?php echo $p;?>><?php echo $myrow['tax_code'];?></option>
             <?php  } ?>
         </select></td>
</tr>
<tr>
<th>LST No.</th>
<td><input type="text" name="lst_no" class="cap" value="<?php echo $lst_no;?>"size="30"></td>
<th>Range</th>
<td><input type="text" name="sup_range" id="sup_range" value="<?php echo $sup_range;?>" size="30"/></td>
</tr>
<tr>
<th>CST No.</th>
<td><input type="text" name="cst_no" class="cap" value="<?php echo $cst_no;?>"size="30"></td>
<th>Division</th>
<td><input type="text" name="sup_division" id="sup_division" value="<?php echo $sup_division;?>" size="30"/></td>
</tr>
<tr>
<th>Excise No.</th>
<td><input type="text" name="excise_no" class="cap" value="<?php echo $excise_no;?>"size="30"></td>
<th>TDS Section</th>
<td>

<select name="tds_selection" class="cap" >
	  			<option value="000">Select Tax section</option>
	 			<?php
	 			$get_category=DB_query("Select * from tds_classification where parentid=0",$db);
				if(DB_num_rows($get_category)>0){
	 			while($cat_res=DB_fetch_array($get_category))
	 			{
	 			?>
	 			<option value="<?php echo $cat_res['id'];?>"<?php echo($tds_selection==$cat_res['id']?'selected':'')?>><?php echo $cat_res['TaxTitle'];?></option>
	 			<?php } }?>
	 			</select>
				
 </td>
</tr>

<!--<tr>
<td></td><td></td>
<th>TDS Percentage:</th>
<td><input name="tds_percentage" type="text" id="tds_percentage" value="<?php echo $tds_percentage;?>" size="5" />
%</td>
</tr>-->
</table>	
</td>	
</tr>

</table>
<table width="100%" cellpadding="2" cellspacing="2">
<tr>
      <td style="text-align:center; border-bottom:1px solid #cccccc; padding:2px 0px 2px 0px; border-top:1px solid #cccccc;" colspan="5" ><div align="center"><strong><font color="black" size="2">ASSIGN ITEMS</font></strong></div></td>
	  
    </tr>
    <tr><td><strong>
    	Enter Part Name Of Item
    	</strong></td>
    	<td colspan="4"><input type="text" name="itemName" value="" onkeyup="showItems(this.value)" /></td>
    </tr>
    <tr>
    <td><strong>Items</strong></td>
    <td colspan="4"><div id="itemid">
	<div style="overflow:auto; height:150px; width:500px; border:1px solid; " >
	<?php 
	$items=explode(",",$assigned_items);
	//print_r($items);
	$item_sql=DB_query("select id,StockID,item_name from item_master ",$db);
	$c3=0;
	while($row3=DB_fetch_array($item_sql))
	{ 
		$checked='';
		for($x=0;$x<count($items);$x++)
		{	
			 if($items[$x]==$row3['id'])
			 $checked="checked";
		}
		
		
	?>
	<input type="checkbox" name="item[<?php echo $c3;?>]" id="item_<?php echo $c3;?>" value="<?php echo $row3['id'];?>" <?php echo $checked;?>/><?php echo $row3['StockID']." - ".$row3['item_name'];?><br />
	<?php 	
	$c3++;
	}
	?>
	</div>
		
	</div></td>
  </tr>	
	
	
	
</table>
<table width="100%" cellpadding="2" cellspacing="2">
<tr><th colspan="8"><p align="center">Contact Details</p></th></tr>
<?php 
	for($i=1;$i<4;$i++)
	{
	?>
	   <tr><input type="hidden" name="row_id[<?php echo $i;?>]" value="<?php echo $row_id[$i];?>" />
	   <th>*Contact Person <?php echo $i;?></th>
	   <td><input name="person[<?php echo $i;?>]" type="text" class="cap"  value="<?php echo $person[$i];?>"></td>
	   <th>*Designation</th>
	   <td><input type="text" name="designation[<?php echo $i;?>]" class="cap" value="<?php echo $designation[$i];?>"></td>
	   <th>*Phone No.</th>
	   <td><input name="phone[<?php echo $i;?>]" type="text" class="cap" value="<?php echo $phone[$i];?>" size="15"></td>
	   <th>*Email Id</th>
	   <td><input type="text" name="contact_email[<?php echo $i;?>]" class="cap" value="<?php echo $contact_email[$i];?>"></td>
	  </tr>
	  <?php } ?>
	  <input type="hidden" name="counter" value="<?php echo $i;?>" /> 	
</table>
<p align="center"><?php if($_REQUEST['ID']!=''){?><input type='Submit' name='Update' value="Update"><?php } else{?><input type='Submit' name='submit' value="Save"><?php }?></p>
</form>
<script language="JavaScript">

function showItems(str)
{
	if(str=="")
  {
  document.getElementById("itemid").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("itemid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_category.php?partName="+str,true);
xmlhttp.send();
}
</script>
