<?php
 $created_by=$_SESSION['ACGCompanyId'];
$url_cancel= "index.php?route=ToolPlants/Transaction/amc_entry_index".$rurl;
$url_add= "index.php?route=ToolPlants/Transaction/amc_entry".$rurl;





if(isset($_REQUEST['rid']))
{
	$recEdit=DB_fetch_array($s->GetRecordById('tpl_amc','id='.$_REQUEST['rid']));
	extract($recEdit);
}



if(isset($_REQUEST['update']))
{
	
	
	
	
									$data2['site']=$_REQUEST['requested_site'];	
									$data2['vendor_id']=$_REQUEST['vendor_id'];
									$data2['fin_year']= $_REQUEST['financial_year'];
									$data2['modified_date']=date('Y-m-d');	
									$cond="id='".$_REQUEST['rid']."'";
									$s->RecordEdit('tpl_amc', $data2, $cond);										
									$last_id=$_REQUEST['rid'];
	
									for($i=0;$i<count($_REQUEST['asset_code']);$i++)
										{
											$asset_id=$_REQUEST['asset_code'][$i];

											if($_REQUEST['tpldtl'][$i] !=''){												
												$data1['asset_id']=$asset_id;
												$data1['start_date']=FormatDateForSQL($_REQUEST['transfer_date'][$i]);
												$data1['end_date']=FormatDateForSQL($_REQUEST['return_date'][$i]);
												$data1['amount']=$_REQUEST['purpose1'][$i];
												$condtion="tpl_amc_id='".$_REQUEST['rid']."' and asset_id='".$asset_id."'";
												$s->RecordEdit('tpl_amc_dtls',$data1,$condtion);
											  }else{
												
												$data1['tpl_amc_id']=$last_id;
												$data1['asset_id']=$asset_id;												
												$data1['start_date']=FormatDateForSQL($_REQUEST['transfer_date'][$i]);
												$data1['end_date']=FormatDateForSQL($_REQUEST['return_date'][$i]);
												$data1['amount']=$_REQUEST['purpose1'][$i];												
												$s->RecordInsert('tpl_amc_dtls',$data1);
			  
			  }
			}
			echo "<script>location.href='$url_cancel'</script>";
		}
	//$_SESSION['success_msg']="Update Successfully";







?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div id="PickedItems" style="display:none"></div>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<div class="body_contain">
<div class="tab_div">
<h1>Transfer Request Add</h1>
<form name="" id="" method="post">
<fieldset><legend style="font-size:13px;"><strong>General Details</strong></legend>
<table width="100%" align="center" border="1" cellpadding="2" cellspacing="1" style="border:#808080 1px solid;">
  <tr>
    <th width="13%">Requested Branch<font style="color:#FF0000;">*</font></th>
    <td width="20%">
    <select name="requested_site" id="requested_site" style="width:100%;" disabled >
    	<option value="0">Select Branch</option>
	<?php
	$query4=DB_query("Select loccode,locationname from locations WHERE CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	while($row4=DB_fetch_array($query4))
	{
	$s2='';
	if($site==$row4['loccode'] )
	$s2="selected";
	?>
	<option value=<?php echo $row4['loccode'];?> <?php echo $s2;?>><?php echo $row4['locationname'];?></option>
	<?php }
	?>
	
	</select>     </td>
   <th>Auot Generate No</th>
	<td><input type="text" style="width:40%;" value="<?php   echo $slip_no;  ?>" readonly name="slip_no"/></td>
   
  </tr>
  <tr>
  	<th>Vendor Name</td>
	<td>
	
<?php 
	$SQLV="Select id,vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."'";
	$VDetails1=DB_query($SQLV,$db);?>
	<select name="vendor_id" id="vendor_id" style="width:100%;" disabled  >
	<option value="000">---Select---</option>
	<?php while($VDetails=DB_fetch_array($VDetails1)){
   $jj='';
   if($VDetails['id']==$vendor_id)
   	$jj="selected";

		?>
	<option value="<?php echo $VDetails['id'];?>" <?php echo $jj; ?> ><?php echo $VDetails['vendor_name'];?></option>
	<?php } ?>
	</select></td> 
		<th><strong>Financial Year</th>
	<td>
	<?php 
	$SQLV="SELECT id,year_start,year_end FROM company_financial_years";
	$VDetails1=DB_query($SQLV,$db);?>
	<select name="financial_year" id="financial_year" style="width:40%;" disabled>
	<option value="000">---Select---</option>
	<?php 
	       while($VDetails=DB_fetch_array($VDetails1))
	       	{
                  $year_start1=explode("-",$VDetails['year_start']);
                  $year_start=$year_start1[0];

                  $year_end1=explode("-",$VDetails['year_end']);
                  $year_end=$year_end1[0];
                  $fndate=$year_start."-".$year_end;
                  $tt='';
                  if($VDetails['id']==$fin_year)
                  	$tt="selected";

	       		?>
	<option value="<?php echo $VDetails['id'];?>" <?php echo $tt; ?> ><?php echo  $year_start."-".$year_end;?></option>
	<?php } ?>
</select>
	</td>
   
   
  </tr>
  <tr>
   
    
    </tr>
	
</table>
</fieldset>

<table width="100%" cellpadding="3" cellspacing="0" border="0">





<tr id="assetBtn">
	<td class="tabledata1" style="text-align:left;" colspan="4">
	<!--<input type="button" onClick="addRow1('dataTable')" value="Add Rows" id="addRow" accesskey="A" class="search" />&nbsp;-->
    
	
	</td>
</tr>

<tr>
	<td class="tabledata1" colspan="4">
	<fieldset><legend style="font-size:13px;"><strong>Machine Details</strong></legend>
	
	<table width="100%" border="1" cellpadding="2" cellspacing="1" style="border:#808080 1px solid;">
<tr class="row1">
	<td >Select</td>
	<td >&nbsp;</td>
	<td >Asset Code</td>
	<td >Asset Name</td>
	<td >Start date</td>
	<td >End date</td>	
	<td colspan="2">Amount</td>
</tr> 
   

<tbody id="dataTable"> 
 <?php 
 $i=1;
$sql=DB_query("select * from tpl_amc_dtls where tpl_amc_id='".$_REQUEST['rid']."'",$db);
while($row_tpl=DB_fetch_array($sql)) {

 $assetcode1=DB_fetch_array(DB_query("select code,name from  machine_center where id='".$row_tpl['asset_id']."'",$db));
	$assitcode=$assetcode1['code'];
	$assitname=$assetcode1['name'];
  ?>
 <tr>
 <td><input type="checkbox" name="select[]" id="select_<?php echo $i; ?>" onchange="checkdata(<?php echo $i; ?>)"disabled></td>
	<td style="width:1%"><input type="hidden" name="asset_code[]" id="assetid_<?php echo $i; ?>" value="<?php echo $row_tpl['asset_id']; ?>" disabled /></td>
	<td><input type="text" name="" id="assetcode_<?php echo $i; ?>" value="<?php  echo $assitcode;?>" style="width:100%;" readonly=""/></td>
	<td><input type="text" name="asset_name[]" id="assetname_<?php echo $i; ?>" value="<?php echo $assitname; ?>" style="width:100%;" readonly=""/></td>
	<td><input type="text" name="transfer_date[]" id="transferdate_<?php echo $i; ?>" class="datepicker" style="width:100%;" value="<?php  echo ConvertSQLDate($row_tpl['start_date']);?>" disabled/></td>
	<td><input type="text" name="return_date[]" id="returndate_<?php echo $i; ?>" class="datepicker" style="width:100%;" value="<?php  echo ConvertSQLDate($row_tpl['end_date']);?>" disabled/></td>
	<td><input type="text" name="purpose1[]" id="purpose1_<?php echo $i; ?>" style="width:100%;" value="<?php  echo $row_tpl['amount'];?>" disabled/></td>
	<td><input type="hidden" name="tpldtl[]" value="<?php echo $row_tpl['id'] ?>" disabled></td>
			</tr>
			<?php } ?>
</tbody>
<input type="text" name="hiditemcount" id="hiditemcount" value="<?php echo $i; ?>" style="display:none;" />
<input type="text" name="" value="<?php echo $i; ?>" id="edit_cnt" style="display:none;" />
<input type="text" name="" value="<?php echo $i; ?>" id="rowcount1" style="display:none;" />


</table>
</fieldset>
	</td>
</tr>
<tr>
	<td class="tabledata1" style="text-align:center;" colspan="4">

	</td>
</tr>
</table>
<?php

if($updateHead){?>

<script>
document.getElementById("requested_site").disabled=true;
document.getElementById("request_date").readOnly=true;
document.getElementById("requested_by").disabled=true;
document.getElementById("purpose").readOnly=true;
document.getElementById("returnable").disabled=true;
document.getElementById("remarks").readOnly=true;
document.getElementById("profile_popup1").disabled=true;
document.getElementById("profile_popup").disabled=true;
document.getElementById("addRow").disabled=true;
document.getElementById("delRow").disabled=true;


</script>

<?php }?>
<input type="hidden" name="updateHead" id="updateHead" value="<?php echo $updateHead;?>" />
</form>

<script language="JavaScript">
function open_items()
{
	window.open("amc_popup.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&reid=<?php echo $_REQUEST['rid']; ?>&action1=<?php echo $_REQUEST['action']; ?>","item_popup_window","height=500,width=700,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
	
function checkdata(str)
{	
if(document.getElementById("select_"+str).checked)
{	
document.getElementById("required_qty_"+str).removeAttribute('readOnly');	
}	
else
{
document.getElementById("required_qty_"+str).setAttribute('readOnly',true);		
}
}


function chkavailqty(val,id,read)
{
if(read !=''){
	var n=id.split("_");
	var i=n[2];
	var curElement;
	//alert(i);
	if(n.length>2){
		var reqqty=parseFloat(document.getElementById("required_qty_"+i).value);
		var availqty=parseFloat(document.getElementById("avail_qty_"+i).value);
		curElement = "required_qty_"+i;
		if(!document.getElementById("required_qty_"+i).value.match(/^\d+/))
		{
			alert("Only digits are allowed");
			document.getElementById("required_qty_"+i).value = 1;
		}
	}else{
		var reqqty=parseFloat(document.getElementById("required_qty").value);
		var availqty=parseFloat(document.getElementById("avail_qty").value);
		curElement = "required_qty";
		if(!document.getElementById("required_qty").value.match(/^\d+/))
		{
			alert("Only digits are allowed");
			document.getElementById("required_qty").value = 1;
		}
	}
	
	if(!isNaN(availqty) && reqqty>availqty)
	{
		alert("You can't Take Requested Greater Than Stock Qty");
		document.getElementById(curElement).value='';
		return false;
	}
}
	
}

function validate()
{
	if(document.getElementById("requested_site").value=='0')
	{
		alert("Please Select The Request Branch First");
		return false;
	}
	if(document.getElementById("financial_year").value=='0')
	{
		alert("Please Select The vendor name");
		return false;
	}
	if(document.getElementById("request_date").value=='')
	{
		alert("Please Select The Request Date First");
		return false;
	}
	
	if(document.getElementById("requested_by").value=='')
	{
		alert("Please Enter The Request By First");
		return false;
	}
	if(document.getElementById("purpose").value =='')
	{
		alert("Plaese Enter Purpose");
	}
	
	var assets = document.getElementsByName("asset_code[]");
	if(assets[0].value =='')
	{
		alert("Select at least 1 Asset");
		return false;
	}
	
}
/*function addRow(tableID) 
{
		
	var table = document.getElementById(tableID);
	var rowCount = table.rows.length;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rowCount;
	var row1=document.getElementById("rowcount1").value;
	var rr=parseInt(row1);
	document.getElementById("rowcount1").value=parseInt(rr)+1;
	document.getElementById("edit_cnt").value=parseInt(rr)+1;
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	//var newCount=parseInt(rowCount)+parseInt(edit_cnt)-1;
	var newCount=parseInt(rowCount);
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	//newcell.className='tabledata';
	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	break;
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id =nod_id[0]+'_'+rr;
	
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	
	
}
*/
$.noConflict();
$(document).ready(function(){	
		//var cnt=document.getElementById("count").value;
		$('input[name=profile_popup]').click(function(){
		var tt=this.id;
		var tt1=tt.split("_");
		var tt2=tt1[1];
	
		
		$("#PickedItems").dialog({
				title:'Item List',
				modal: true,
				resizable: false,
				width:900,
				height:400,
				closeText: 'fechar',
				draggable: true,
				show: 'fade',
				hide: 'fade',
				dialogClass: 'main-dialog-class',
				buttons: {
					Exit: function()
					{
						$(this).dialog("close");
					}
				}
				
			});
		GetitemListForDirectPO();
		});
	});

function GetitemListForDirectPO()
{
	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("PickedItems").innerHTML=xmlhttp.responseText;
	}
	}

	xmlhttp.open("GET","amc_popup.php",true);
	xmlhttp.send();
}

function getItemsList(id,code,name,group,type,units,model,vechile,meter,ctr,t1,t2,t3,work_loc)
{ 
	
	var dup='empty';
	var itemcount=parseInt(document.getElementById('hiditemcount').value)+1;
	
	var edit_cnt=document.getElementById('edit_cnt').value;
	//alert(edit_cnt);
	if(edit_cnt=='')
	{
		var counter=1;
	} 
	else if(edit_cnt>itemcount)
	{
		var counter=edit_cnt;
		var itemcount=parseFloat(counter)+parseFloat(itemcount);
	}
	else
	{
		var counter=edit_cnt;
	}
	
	//alert(counter);
//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************START HERE******************************************
	
	if(document.getElementById("row_id_"+ctr).checked==true)
	{

		
			 for(var j=0; j<itemcount; j++)
				{  
				if(document.getElementById('assetid_'+j))
				{
				if(document.getElementById('assetid_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					return false;
				}
			   }
		   }
		  
			for(var i=counter; i<=itemcount; i++)
			{	
				
				if(edit_cnt=='')
				{
					var counter=0;
				}
				
				if(document.getElementById('assetid'))
				{
				if(document.getElementById('assetid').value==id)
				{
					alert("Duplicate Value");
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(document.getElementById('assetid_'+i))
				{
				if(document.getElementById('assetid_'+i).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(dup=='empty')
				{
				if(!document.getElementById('assetid_'+i))
				{				
				var data= addRow('dataTable');	
				}
				
					if(document.getElementById('assetid_'+i).value=='')
					{	//var data= addRow('dataTable');
					document.getElementById('assetid_'+i).value = id;
					document.getElementById('assetcode_'+i).value =code;
					document.getElementById('assetname_'+i).value = name;
						
						break;
						break;
					}
					else
					{
						continue;
					}
				}
			}
		
	}
	
//IF WE CHECK THE CHECK BOX FOR SELECT ANY ITEM***********************END HERE******************************************


//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************START HERE******************************************
	else
	{
		
	
			for(var i=counter; i<itemcount; i++)
			{
				if(document.getElementById('assetid_'+i).value==document.getElementById("row_id_"+ctr).value)
				{
					document.getElementById('assetid_'+i).value = '';
					document.getElementById('assetcode_'+i).value = '';
					document.getElementById('assetname_'+i).value = '';
					
				}
			}
		
	}
//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
}
	

function addRow(tableID) 
{

	if(document)
	var table = document.getElementById(tableID);
	//var rowCount = table.rows.length;
	var rowCount = table.rows.length;
	//alert(rowCount);
	if(document.getElementById("hiditemcount").value=='')
	r =rowCount+1;
	else
	{
	var t=document.getElementById("edit_cnt").value;
	var t1=document.getElementById("hiditemcount").value;
	r=parseInt(t1);
	r1=parseInt(t1)+1;
	}
	var row1=document.getElementById("rowcount1").value;
	var rr=parseInt(row1)+1;
	document.getElementById("rowcount1").value=rr;
	var row = table.insertRow(rowCount);
	document.getElementById("hiditemcount").value=rr;
	document.getElementById("edit_cnt").value=rr;

	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {		
	var newcell = row.insertCell(i);
	//newcell.style.background='#e7e7e7';
	//newcell.className='tabledata';
	newcell.innerHTML = table.rows[0].cells[i].innerHTML;
	$('.datepicker').removeClass('hasDatepicker').datepicker({ dateFormat: 'dd/mm/yy',changeMonth: true, changeYear: true,yearRange: '-80:+20'});
	//alert(newcell.childNodes[0].type);
	switch(newcell.childNodes[0].type) 
	{
	case "text":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
    var nt=newcell.childNodes[0].name.split("]");
	    if(nt[1]=="")
		{
		var rr1=parseInt(rr)-1;
	    var nt5=nt[0].split("[");                   
	    var name=nt5[0]+'['+rr1+']';                 				
		newcell.childNodes[0].name = name;
		newcell.childNodes[0].name =newcell.childNodes[0].name;
		
	    }
	break;		
	case "hidden":
	newcell.childNodes[0].value = "";
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
    var nt=newcell.childNodes[0].name.split("]");
	    if(nt[1]=="")
		{
		var rr1=parseInt(rr)-1;
	    var nt5=nt[0].split("[");                   
	    var name=nt5[0]+'['+rr1+']';                 				
		newcell.childNodes[0].name = name;
		newcell.childNodes[0].name =newcell.childNodes[0].name;
		
	    }
	break;
	case "button":
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
	break;
	case "checkbox":
	newcell.childNodes[0].checked = false;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
    var nt=newcell.childNodes[0].name.split("]");
	    if(nt[1]=="")
		{
		var rr1=parseInt(rr)-1;
	    var nt5=nt[0].split("[");                   
	    var name=nt5[0]+'['+rr1+']';                 				
		newcell.childNodes[0].name = name;
		newcell.childNodes[0].name =newcell.childNodes[0].name;
		
	    }
	break;
	case "radio":	
	var nod_id = newcell.childNodes[0].id.split("_");
	var nt=newcell.childNodes[0].name.split("]");
	    if(nt[1]=="")
		{
		var rr1=parseInt(rr)-1;
	    var nt5=nt[0].split("[");                   
	    var name=nt5[0]+'['+rr1+']';                 				
		newcell.childNodes[0].name = name;
		newcell.childNodes[0].name =newcell.childNodes[0].name;
		
	    }
	    //alert(1);
	    $('.first1').attr('checked',true);
   	
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
    
    
	break;
	case "select-one":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id.split("_");
	if(!isNaN(nod_id[1]))
	newcell.childNodes[0].id = nod_id[0]+'_'+rr;
	else
	newcell.childNodes[0].id = nod_id[0]+'_'+nod_id[1]+'_'+rr;
    var nt=newcell.childNodes[0].name.split("]");
	    if(nt[1]=="")
		{
		var rr1=parseInt(rr)-1;
	    var nt5=nt[0].split("[");                   
	    var name=nt5[0]+'['+rr1+']';                 				
		newcell.childNodes[0].name = name;
		newcell.childNodes[0].name =newcell.childNodes[0].name;
		
	    }
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
		//document.getElementById(countid).innerHTML=rowCount;

	}
	
function deleteRow(tableID) 
{
		try 
		{
			var table = document.getElementById(tableID);
			//alert(table);
			var rowCount = table.rows.length;
			//alert(rowCount);
			for(var i=0; i<rowCount; i++) 
				{
					var row = table.rows[i];
					var chkbox = row.cells[0].childNodes[0];
					if(null != chkbox && true == chkbox.checked) 
					{
						if(rowCount <= 1) 
						{
							alert("Cannot delete all the rows.");
							break;
						}
					table.deleteRow(i);
					rowCount--;
					i--;
					}
					
				}
				
		document.getElementById("hiditemcount").value=parseInt(rowCount)-1;
		//document.getElementById("hiditemcount").value=parseInt(rowCount);		
		}
		catch(e) 
		{
			alert(e);
		}

}


function getEmployeeList(str){
if(str=="")
  {
  document.getElementById("requested_by").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("requested_by").innerHTML=xmlhttp.responseText;
	}
	}
	
	
	xmlhttp.open("GET","getEmpList.php?site="+str,true);
	xmlhttp.send();

}
var doc=null;
function ajax(){
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  doc=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  doc=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
function getSiteList(str){
var getCompany=document.getElementById('company_to').value;
var requested_site=document.getElementById('requested_site').value;

ajax();
     if(doc){
	doc.onreadystatechange=function()
	{
	if (doc.readyState==4 && doc.status==200)
	{  
	  //var data=doc.responseText.split("__");
	  //alert(doc.responseText);
	  document.getElementById("shwsite").innerHTML=doc.responseText;
	}
	}
	doc.open("GET","check_data_bsm.php?section=getSiteList&getCompany="+getCompany+"&requested_site="+requested_site,true);
	doc.send();
	}

}
</script>