<?php

$prefixcode="ISS";
$year=date('y');
$year_after=$year+1;
$site_code=substr($_GET['site'],0,3);
	  $sql="select * from addissue where site = '".$_GET['site']."'";
	  $result = DB_query($sql,$db);
	  $numrows = DB_num_rows($result);
	  $sqldata=DB_query("select locationname from locations where loccode='".$_GET['site']."'",$db);
	  $sqltext=DB_fetch_array($sqldata);
	  $sitename=$sqltext['locationname'];
	  $siteCode = $sitename;
	 if($numrows>0)
	 {
			 $i=0;
			 $strmax = "";
			 $myrow=DB_Fetch_array($result);
			 
		 if($siteCode!='')
				//$val1= substr($myrow['issue_slipno'],0,18);
				//$strChar1 = substr($myrow['issue_slipno'],0,9);
				//$strChar = $strChar1."/".ucwords(substr($siteCode,0,1))."/";  
			
			if($numrows>0)
			{ 
				$maxval = $numrows;
			}
			else
			{
				$maxval=0;
			}
		{
			$strChar = $site_code."/".$prefixcode."/".$year.$year_after."/";
		}
	  }
	  else
	  {
	  	$strChar = $site_code."/".$prefixcode."/".$year.$year_after."/";
	  }
	  
	 $strFinal = $maxval+1;
	 $strBothFinal = $strChar.str_pad($strFinal,6,"0",STR_PAD_LEFT); 
?>


<h2 align="center"><strong>Material Issue</strong></h2>
<form name="form1" action="" method="post" >


<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
    <th><strong>Branch</strong></th>
    <td style="width:250px;">
	<?php
	if($_SESSION['AssignedSites']!='0')
	  { 
		 $sql = "SELECT loccode, locationname FROM locations  where company='".$_SESSION['ACGCompanyId']."' and loccode in (".$_SESSION['AssignedSites'].")"; 
		$resultStkLocs = DB_query($sql,$db);
		}
		 else
	  {
		 $sql="Select loccode,locationname from locations where company='".$_SESSION['ACGCompanyId']."'";
		$resultStkLocs = DB_query($sql,$db);
	  }		
		?>
	<select name="sitecode" style="width:100%" id="sitecode"  onchange="showsitename158(this.value)">
	 <option value="0">Select</option>
      <?php 
			while ($myrow=DB_fetch_array($resultStkLocs))
				{
				  $p='';
				 if($myrow['loccode']==$site)
				 $p='selected';
				
				?>
      <option value="<?php echo $myrow['loccode']; ?>"  <?php  echo $p;?>><?php echo $myrow['locationname'];?></option>
      <?  }	?>
    </select></td>
    <th>Godown</th>
    <td style="width: 250px;"><div id='hid-Godown-div'>
    	<?php
		      $sql_store12 ="select  id, StoreCode, StoreName from storetype  ";
		 $resultStkLocs12 = DB_query($sql_store12,$db);
		?>
    	<select name="store" style="width:100%" id="store"  >
	<option value="0">Select</option>
      
      <option value="0" >Select</option>
    </select></div>
	</td>
</tr>

<tr> <th><strong>Issue No.</strong></th>
    <td>
      <input name="issue_slipno" type="text" id="issue_slipno" size="20" style="width:100%" readonly="readonly" value="Auto Generate" />
       	 
	</td>
    <th>Issue Date</th>
    <td><input name="issue_slipno" type="text" id="issue_slipno"  style="width:100%"  class="datepicker" />
	</td>
</tr>

<tr>
    <th><strong>Dept.</strong></th>
    <td style="width:250px;">	
	<select name="dept1" style="width:100%" id="dept1" onchange="showdept(this.value)">
	<option value="0">Select</option>
		<?php 
	$floor1_sql=DB_query("Select * from deptmaster",$db);
	while($floor_row1=DB_fetch_array($floor1_sql))
	{?>
	<option value="<?php echo $floor_row1['deptcode'];?>"><?php echo $floor_row1['deptname'];?></option>
	<?php 	}	?>	
    </select></td>
    <th>Emp Name</th>
    <td style="width:250px;">
    	<div id="dept">
    	<select name="received_by" style="width:100%" id="received_by" onchange="Get_Employee(this.value)" >
	<option value="0">Select</option>
	<?php 
	$floor_sql=DB_query("Select * from empmaster",$db);
	while($floor_row=DB_fetch_array($floor_sql))
	{
			     $p='';
				 if($floor_row['id']==$received_by)
				 $p='selected';	
	
	?>
	<option value="<?php echo $floor_row['id'];?>"<?php echo $received_by==$floor_row['id']?'selected':''; ?>><?php echo $floor_row['emp_name'];?></option>
	<?php 	
	}
	?>
    </select></div>
	</td>
</tr>

<tr>
    <th><strong>Contractor Name</strong></th>
    <td style="width:250px;">
    	<select name="issueto" id="issueto" style="width:100%" onchange="Get_contractor(this.value)"  >
	<option value="0">Select</option>
	<?php 
	$floor_sql=DB_query("Select * from contractor_master",$db);
	while($floor_row=DB_fetch_array($floor_sql))
	{?>
	
     <option value="<?php echo $floor_row['id'];?>"<?php echo $issueto==$floor_row['id']?'selected':''; ?>><?php echo $floor_row['contractor_name'];?></option>
	<?php 	
	}
	?>
    </select></td>
    <th>Issue Req No.</th>
    <td> <input name="issue_req_no" type="text" id="issue_req_no"  style="width:100%"  value="" />
	</td>
</tr>

<tr>
    <th><strong>Work Order No</strong></th>
    <td style="width:250px;">
	
	<input name="work_order_no" type="text" id="work_order_no"  style="width:100%"  value="" /></td>
    <th>Cost Centre</th>
    <td> <input name="cost_center" type="text" id="cost_center"  style="width:100%"  value="" />
	</td>
</tr>
    
 
</table> 
	
<p align="left" style="padding-left:10px;">
  <input type="button" name="Add" value="Add"  onclick="addRow('dataTable')"/>
  <input type="button" name="profile_popup" value="Pick Items" id="profile_popup"  onclick="checkdata()" class="search" />
                      
  <input type="button" value="Cancel" name="Delete" /></a>    
</p>




  <div style="overflow:auto; width:825px; height:auto">
 	<div id="itemdata">
 	<table width="100%" border="1" cellpadding="3" cellspacing="0">
            <tr>
              <th><strong>S. No.</strong></th>
              <th><strong>Item Code</strong></th>
              <th><strong>Item Name</strong></th>
              <th><strong>UOM</strong></th>
              <th><strong>Req Qty</strong></th>
              <th><strong>Issued Qty</strong></th>
              <th><strong>Stock</strong></th>
            </tr>
             <tbody id="dataTable">
            <tr bgcolor="#FFFFFF">
            <td><input name="delitem[]" type="checkbox" value="<?php echo $item_row['id'];?>" />
            	<input type="text" value="" tabindex=""  readonly=""  id="itemid"  name="itemid[]" /></td>
             <td><input type="text" value="" tabindex=""  readonly="" id="itemcode" name="itemcode[]"size="20"   /></td>
              <td> <input type="text" name="desc[]"  id="desc" size="25"  value=""/></td>
              <td><input type="text" name="uomname[]" id="uomname" readonly/>
              	 <input type="text" name="uom[]" id="uom" value="" readonly /></td>
               <td><input onmousedown="chkbalance(<?php echo $i; ?>)" type="text" name="receive[]"  id="receive" size="30" onchange="chkbalance(<?php echo $i; ?>)"  value=""/></td>
               <td><input onmousedown="chkbalance(<?php echo $i; ?>)" type="text" name="issueqty[]"  id="issueqty" size="30" onchange="chkbalance(<?php echo $i; ?>)"  value=""/></td>
              <td><input type="text" name="Stockbalance[]"  id="Stockbalance"  size="10"  value=" <?php  echo $stockbalance;	?>" readonly/></td>
             
              
            </tr>
            </tbody>
     
    </table>
    
    </div>
  </div>
  <input type="hidden" name="hiditemcount" id="hiditemcount" value="" />
  <input type="hidden" name="" value="" id="edit_cnt" />

<table width="100%" border="1" cellpadding="3" cellspacing="0">
<tr>
<th><strong>Remarks </strong></th>
<td colspan="3"><textarea name="remarks"  style="width:100%" id="remark"></textarea></td>
</tr>

<tr>
<th><strong>Material Recd by</strong></th>
<td style="width:150px;">&nbsp;</td>
<th><strong>Material Issued by</strong></th>
<td style="width:150px;">&nbsp;</td>
</tr>



</table>
<p align="center">
  <input type="submit" name="Submit" value="Save"  onclick="return validate()"/>
  <input type="submit" name="reset" value="View" />
  <input type="button" value="Cancel" name="Back" /></a>
  
  
  
</p>
</form>

<script language="javascript" type="text/javascript">


 
 var xmlHttp

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}

function getsitename(str)
{
if (str.length==0)
  {
  document.getElementById("txtsite").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("txtsite").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_sitename.php?site="+str,true);
xmlhttp.send();
}
function getsitename22(str)
{
if (str.length==0)
  {
  document.getElementById("txtsite22").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("txtsite22").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_sitename.php?q2="+str,true);
xmlhttp.send();
}
function Get_issuedetails(str)
{
  if (str.length==0)
  {
  document.getElementById("issueid").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("issueid").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssueDetails.php?q="+str,true);
xmlhttp.send();
}

function getpartyname(str)
{
	//alert(str);
	var hidparty=document.getElementById("hidden_party").value;
	//alert(hidparty);
	if (str.length==0)
  {
  document.getElementById("pname").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("pname").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssuePartyName.php?name="+str+"&partytype="+hidparty,true);
xmlhttp.send();
}
	

function get_referredby(str)
{
	if (str.length==0)
  {
  document.getElementById("rname").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("rname").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_IssueEmployeeName.php?q="+str,true);
xmlhttp.send();
}

 var xmlHttp
function requisition_detail(str)
{ 
   //alert(str);
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="reqdetail.php";
	url=url+"?req_number="+str;
	
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=changedetail;
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function changedetail() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   var responsestr = xmlHttp.responseText;
	   resstr = responsestr.split("@@##@");
	   document.getElementById("reqdate").value=resstr[0];
	   document.getElementById("txtdetail").innerHTML=resstr[1];
	  
	}
}
function calculateTotalAmount(str)
{
	var str_BRK=str.split('_');
	if(str_BRK[1]==undefined)
	{
		var issue=document.getElementById("issueqty").value;
		var average=document.getElementById("averageamt").value;
		var TOTAL=issue*average;
		document.getElementById("totalamount").value=TOTAL.toFixed(2);
	}
	else
	{
		var issue=document.getElementById("issueqty_"+str_BRK[1]).value;
		var average=document.getElementById("averageamt_"+str_BRK[1]).value;
		var TOTAL=issue*average;
		document.getElementById("totalamount_"+str_BRK[1]).value=TOTAL.toFixed(2);
	}
}
function Get_departmentdetails(str)
{

if (str=="")
  {
  document.getElementById("department").innerHTML="";
  return;
  }
var xmlhttp;
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("department").value=xmlhttp.responseText;
	
    }
  }
  //alert(str);
xmlhttp.open("GET","get_department.php?department="+str,true);
xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

}

function showdept(str)
{
if (str=="")
  {
  document.getElementById("dept").innerHTML="";
  return;
  }
var xmlhttp;
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)
    {
    	alert(xmlhttp.responseText);
	document.getElementById("dept").innerHTML=xmlhttp.responseText;
	
    }
  }
  
xmlhttp.open("GET","get_empdata.php?department="+str,true);
xmlhttp.send();	
	
	
}
function calTotal1(str)
{	
var k=parseFloat(document.getElementById('issueqty_'+str).value);
var j=parseFloat(document.getElementById('Stockbalance_'+str).value);
if(j<k)
{
alert("Issue Qty Not Grater then Stock Balance");
document.getElementById('issueqty_'+str).focus();
}	
}
function calTotal(obj)
{
	//var rowCount = document.getElementById('dataTable').rows.length;
	//var arr = obj.id.split("_");
	//var rowx1=0;
	//if (arr[1]==undefined)
	//var nm='';
	//else
	//var nm='_'+arr[1];
	//for(var i=1;i<rowCount;i++)
	//{
		
		// if(parseInt(document.getElementById('reqiredbalance'+nm).value) <= document.getElementById('issuebalanc'+nm).value))
		//  {
		//	  alert('Please Enter Less then value In Required Quantity');
		//	  document.getElementById('issuebalanc'+nm).focus();
		//	  return false;
	  //}else{	
			//  rowx1=parseInt(document.getElementById('Stockblance'+nm).value) - parseInt(document.getElementById('issuebalanc'+nm).value);
			//if(isNaN(rowx1))
			//{
			//	document.getElementById('remaningbalance'+nm).value=parseInt(0);
		//	}
		//	else
		//	 {
		//		document.getElementById('remaningbalance'+nm).value=rowx1;
		//	 }
		//}
	//}
	
	var k=parseFloat(document.getElementById('issueqty_'+obj).value);
var j=parseFloat(document.getElementById('Stockbalance_'+obj).value);
if(j<k)
{
alert("Issue Qty Not Grater then Stock Balance");
document.getElementById('issueqty_'+obj).focus();
}
	
}
function Get_contractor(str)
{	
	//alert(str);
	if(str!='')
	{
		var element=document.getElementById("received_by");
		element.style.display = "none";
	}
	else
	{
		var element=document.getElementById("received_by");
		element.style.display = "";
	}
	
}
function Get_Employee(str)
{
		
	if(str!=0)
	{
		var element=document.getElementById("issueto");
		element.style.display = "none";
	}
	else
	{
		var element=document.getElementById("issueto");
		element.style.display = "";
	}
	
}
function chkbalance(str)
{
	//alert(str);
	var k=parseFloat(document.getElementById('Stockbalance_'+str).value);
	
	var j=parseFloat(document.getElementById('issueqty_'+str).value);
	
	
	//alert(document.getElementById('Stockbalance_0').value);
	if(isNaN(document.getElementById('issueqty_'+str).value))
	{
	alert("String Not Allowed");
	document.getElementById('issueqty_'+str).value='';
	return false;	
	}
	
	if(j > k)
	{
	alert("Issue Qty Not Grater then Stock Balance");
	document.getElementById('issueqty_'+str).value='';
	document.getElementById('issueqty_'+str).focus();
	}
	
	
}

function validate()
{  
	var rowCount = document.getElementById('countdata').value;
	
	if(document.getElementById("sitecode").value=='0')
	{
	alert("Must Select Branch Name");
	return false;	
	}
	if(document.getElementById("issueto").value=='')
   {
var count=0;	
}
if(document.getElementById("received_by").value=='0')
{
var count=0;	
}
if(document.getElementById("issueto").value!='' || document.getElementById("received_by").value!='0' )
{
var count=1;	
}
if(count==0)
{
alert("Must Select Contractor Name /Employee Name");
return false;	
}
	
	if(rowCount=="undefined")
	{
	alert("Must Select Items");
	return false;	
	}	
	for(var i=0;i<rowCount;i++)
	{
	var issueqty=parseFloat(document.getElementById("issueqty_"+i).value);	
	var stockqty=parseFloat(document.getElementById("Stockbalance_"+i).value);
	if(isNaN(document.getElementById("issueqty_"+i).value))
	{
	alert("String Not Allowed");
	document.getElementById('issueqty_'+i).value='';
	document.getElementById('issueqty_'+i).focus();
	return false;	
	}
	if(document.getElementById("issueqty_"+i).value=='')	
	{
	alert("Must Enter Issue Qty");
	document.getElementById('issueqty_'+i).focus();
	return false;	
	}
	if(issueqty>stockqty)
	{
	alert("Issue Qty Not Greater Then Stock balance");
	return false;	
	}		
	}
return true;
}

function showsitename158(str)
{

var xmlhttp;
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)
    {
	var data=xmlhttp.responseText.split("__");	
	
	document.getElementById("hid-Godown-div").innerHTML=data[0];
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  xmlhttp.open("GET","GoDownIssueSlip.php?site="+str,true);
	xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

	
}

function checkdata()
{
if(document.getElementById("sitecode").value=='0')
{
alert("Must Select Branch Name");
return false;	
}
window.open("issu_searchpopupnew.php?1=1<?php echo $rurl;?>&site=<?php echo $_SESSION['site']?>&store=<?php echo $_SESSION['godwan'];?>","profiles_popup_window","height=425,width=600,toolbar=no,menubar=no,dependent=yes,resizable=yes");
			
return true;	
}


function calculateAmt(i)
{

var IssueQty=document.getElementById("issueqty_"+i).value;


var AverageRate=document.getElementById("averagerate_"+i).value;	
var Amount1 =parseFloat(IssueQty)*parseFloat(AverageRate);

document.getElementById("amount1_"+i).value =Amount1.toFixed(2);
}


</script>

<script language="javascript" type="text/javascript">
function Remaningqtn(str)
{

var StockBalance=document.getElementById("Stockblance_"+i).value;	
var Issuequantity=document.getElementById("issuebalanc_"+i).value;	
var RemaningBalance =parseFloat(StockBalance)-parseFloat(Issuequantity;)
document.getElementById("remaningbalance_"+i).value =RemaningBalance;
}

var countries=new ddtabcontent("countrytabs")
countries.setpersist(true)
countries.setselectedClassTarget("link") //"link" or "linkparent"
countries.init();




function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}


 var xmlHttp
function changestorename(str)
{ 
 
 // alert('hi');
   xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		    alert ("Your browser does not support AJAX!");
		    return;
		  } 
	var url="storename.php";
	url=url+"?store_code="+str;
	//alert(url);
	//url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=NumberChanged1;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function NumberChanged1() 
{ 
	if (xmlHttp.readyState==4)
	{ 
	   document.getElementById("txtid").innerHTML=xmlHttp.responseText;
	}
}
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
</script>
<script language="javascript" type="text/javascript">
function addRow(tableID) 
{
	
	if(document)
		var table = document.getElementById(tableID);
		var rowCount = table.rows.length;
		alert(rowCount);
		
		var row = table.insertRow(rowCount);
		document.getElementById("hiditemcount").value=rowCount;
		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;
				switch(newcell.childNodes[0].type) 
				{
				case "text":
					newcell.childNodes[0].value = "";
					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
										
				break;

				case "hidden":

					newcell.childNodes[0].value = "";

					var nod_id_hidden = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "button":

					var nod_id = newcell.childNodes[0].id;

					newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;

				break;

				case "checkbox":

				newcell.childNodes[0].checked = false;
				var nod_id_chk = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				

				break;

				case "select-one":
				
				newcell.childNodes[0].selectedIndex = 0;
				var nod_id = newcell.childNodes[0].id;
				newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
				break;	
			}
		}
	}
function deleteRowOrder(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;		
	}
	catch(e) 
	{
		alert(e);
	}

}


</script> 
