<style type="text/css">
.body_lightbox {
width:100%;
background-color:#e7e7e7;
position:absolute;
left:280px;
top:95px;
padding-left:5px;
padding-right:5px;
border:#666666 solid 3px;
}
.success
    {
        background-color: greenyellow;
        color: green;
    }

</style>
<script type="text/javascript" language="javascript">
$.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];
		var site=document.getElementById("site").value;
		
		//var LeaveType=document.getElementById("LeaveType_"+tt2).value;
		$("#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(site);
		});
	});
	
	function GetitemListForDirectPO(str)
{
	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","popup_item_list.php?site="+str,true);
	xmlhttp.send();
}

function getItemsList(id,code,shade,desc,ctr,current)
{  
	
  var dup='empty';
	var itemcount=parseInt(document.getElementById('rowcount1').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)
	{
	    
       
		if(document.getElementById('itemid') && document.getElementById('itemid').value=='')
		{
			if(edit_cnt=='')
			{
				var counter=0;
			}
		
			for(var j=0; j<counter; j++)
			{
          
           if(document.getElementById('itemid1_'+j))
            {
				if(document.getElementById('itemid1_'+j).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					var dup = "dup";
					break;
				}
            }
			}
			
			if(dup=='empty')
			{	
				//var data=addRow('dataTable');
				document.getElementById('itemid').value = id;
				document.getElementById('itemcode').value = code;
				document.getElementById('itemname').value = shade;	
				document.getElementById('Unit').value =desc ;		
				document.getElementById('stockqty').value =current ;					
				//document.getElementById('instrumentname').value = desc;	
				
				
			}
		} 
		
		else
		{
		
		
			for(var i=counter; i<=itemcount; i++)
			{	
			
			
				if(edit_cnt=='')
				{
					var counter=0;
				}
				for(var j=0; j<counter; j++)
				{}
				if(document.getElementById('itemid'))
				{
				if(document.getElementById('itemid').value==id)
				{
					alert("Duplicate Value");
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				if(document.getElementById('itemid1_'+i))
				{
				if(document.getElementById('itemid_'+i).value==id)
				{
					alert("Duplicate Value"); 
					document.getElementById("row_id_"+ctr).checked=false;
					break;
				}
				}
				
				if(dup=='empty')
				{
				if(!document.getElementById('itemid_'+i))
				{	
					
				var data= addRow('dataTable');	
				}
					if(document.getElementById('itemid_'+i))
					{	
					
					if(document.getElementById('itemid_'+i).value=='')
					{	
						document.getElementById('itemid_'+i).value = id;
						document.getElementById('itemcode_'+i).value = code;
						document.getElementById('itemname_'+i).value = shade;
						document.getElementById('Unit_'+i).value =desc ;		
				         document.getElementById('stockqty_'+i).value =current ;
						//document.getElementById('instrumentname_'+i).value = desc;	
												
						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
	{
		if(document.getElementById('itemid').value==document.getElementById("row_id_"+ctr).value)
		{
			document.getElementById('itemid').value = '';
			document.getElementById('itemcode').value = '';
			document.getElementById('itemname').value = '';
			document.getElementById('Unit').value = '';		
				document.getElementById('stockqty').value = '';
			//document.getElementById('instrumentname').value = '';
		}
		else
		{
			for(var i=counter; i<itemcount; i++)
			{
				if(document.getElementById('itemid_'+i).value==document.getElementById("row_id_"+ctr).value)
				{
					document.getElementById('itemid_'+i).value = '';
					document.getElementById('itemcode_'+i).value = '';
					document.getElementById('itemname_'+i).value = '';
					document.getElementById('Unit_'+i).value = '';		
				document.getElementById('stockqty_'+i).value = '';
					//document.getElementById('instrumentname_'+i).value = '';
				}
			}
		}
	}
//IF WE UNCHECK THE CHECK BOX FOR DESELECT ANY ITEM***********************END HERE******************************************
}
	



//function claculateExcise(id,val)
//{
//	$("#div_id").dialog({
//	modal: true,
//	resizable: false,
//	width:300,
//	height:150,
//	closeText: 'fechar',
//	draggable: true,
//	show: 'fade',
//	hide: 'fade',
//	dialogClass: 'main-dialog-class',
//	buttons: {
//		//Save: function()
////		{
////		$("#myform").closest("form").submit();
////		},
//		//Exit: function()
////		{
////			$(this).dialog("close");
////		}
//	}
//	});
//	$(".ui-dialog-titlebar").hide();
//	calculateExcisejq(id,val)
//}

function changefromTo(str)
{
    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("dataTable").innerHTML=xmlhttp.responseText;
            }
	}
	xmlhttp.open("GET","ajax_get_labls.php?val="+str,true);
	xmlhttp.send();
}
function deactivate1(str)
{ 
	 var confirmText = "Are you sure you want to delete the Document?";
    if(confirm(confirmText))
	{
		//var qty=document.getElementById("hrdqty1A_"+str).value;
		//var n=qty.split(",");
//		var count=n.length;
//		for(var j=0;j<count;j++)
//		{
//			var fin=parseFloat(n[j]);
//			var hrdqty=parseFloat(document.getElementById("hrdstock_qty2_"+j).value);
//			var diff=hrdqty-fin;
//			document.getElementById("hrdstock_qty2_"+j).value=diff;
//		}
		//document.getElementById("itemid1_"+str).value='';
		//document.getElementById("active_"+str).style.display='block';
		
                document.getElementById("docDetailsId_"+str).value='';
		document.getElementById("deactive_"+str).style.display='none';
		document.getElementById("hide_"+str).style.display='none';
		//alert('Item removed');
		//calqty(str);
		//caltotal(str);
		
	}
}
</script>
<?php session_name('CAKEPHP'); session_start();
$title=$s->GetFieldValue('modules_form',"id='652'",'frm_name');
$PageSecurity = 4;
$PageName = $title;
$title = _($title);
$desc=$s->GetFieldValue('modules_form',"id='".$_REQUEST['frmid']."'",'description');
function extension($filename)
		{
			$name_brk=explode('.',$filename);
			return  $name_brk[1];
		}
                
if($_REQUEST['Save']!='')
{
    
             
       
        //echo $usrstr;exit;
        $detailstring=$_REQUEST['detailsIDS'];
       $detailsArray=explode(',', $detailstring);
       
       $docDetailsid=implode(',', $_REQUEST['docDetailsId']);
       $realDEtailsID=explode(',', $docDetailsid);
       $realDEtailsIDNew=array_filter($realDEtailsID);
       
       $result=array_diff($detailsArray,$realDEtailsIDNew);
       //print_r($detailsArray);
       $countDiff=count($result);
        if($countDiff!=0)
        {
            foreach($result as $unlinkID)
            {
               $docFileName=$s->GetFieldValue('dms_doc_type_dtls'," id='".$unlinkID."' " ,'doc_file_name');
            
               $Path="uploaded_docs/".$docFileName;
                if ( unlink($Path) )
                {
                    $deleteQry="delete from dms_doc_type_dtls where id='".$unlinkID."'";
                    $deleteQryExec=DB_query($deleteQry,$db);
                    echo '<div class="success">Record Updated Succesfully!!</div>';
                    $s->pageLocation("index.php?route=DMS/doc_type_index".$rurl);
                }
            }
        }
        else{
            
            for($i=0;$i<count($detailsArray);$i++)
            {
                $userArray=explode(',', $_REQUEST['userId'][$i]);
                $newusrArray=array_filter($userArray);
                $usrstr=implode(',', $newusrArray);
                
                if($_REQUEST['doc']=='I'){ $from=$_REQUEST['from'][$i]; $to=$usrstr;}
                 else { $from=$usrstr; $to=$_REQUEST['to'][$i]; }
                
                $docname = htmlspecialchars($_REQUEST['doc_name'][$i], ENT_QUOTES);
                $dataP['parent_id']=$_REQUEST['dmsID'];
                $dataP['doc_name']=$docname;
                 $dataP['doc_type_mstr_id']=$_REQUEST['doc_type_mstr_id'][$i];
                $dataP['cariers']=$_REQUEST['cariers'][$i];
                $dataP['tracking_no']=$_REQUEST['tracking_no'][$i];
                $dataP['from_name']=$from;
                $dataP['to_name']=$to;
                $dataP['address']=$_REQUEST['address'][$i];
                $dataP['mobile']=$_REQUEST['mobile'][$i];
                 

//                echo "<pre>";
//                print_r($dataP);
//                exit;
                 $cond1="id='".$detailsArray[$i]."'";
                $s->RecordEdit('dms_doc_type_dtls', $dataP, $cond1);// UPDATE ON OLD ITEM
                
            } 
               $docFile=$_FILES['doc_file_names']['name'];
         if(count($docFile)!=0)
         {
           for($i=0;$i<count($_REQUEST['doc_name']);$i++)
           {
               if($_REQUEST['doc_name'][$i]!='')
               {

               $docname = htmlspecialchars($_REQUEST['doc_names'][$i], ENT_QUOTES);
               
               $name=$_FILES['doc_file_names']['name'][$i];
               $type=extension($name);
               
                           if($type!='')
                           {
                                if($type!='pdf' && $type!='doc' && $type!='txt' && $type!='docx' && $type!='rtf' && $type!='jpeg'
                                && $type!='jpg' && $type!='jpeg' && $type!='JPEG' && $type!='JPG' && $type!='png' && $type!='gif' && $type!='gif')
                                {
                                        echo "<strong>Invalid Extension! Kindly please check the image before uploading</strong>";
                                        $flag=1;
                                }
                                else
                                {  
                                    
                                        $tmp_name=$_FILES['doc_file_names']['tmp_name'][$i];
                                        //echo $_FILES['photo']['size'];
                                       $new_name2[]=$strBothFinal.'_'.$name;
                                         
                                        $path="uploaded_docs/".$name;
                                        $file_copy=move_uploaded_file($tmp_name,$path);
                                       
                                        if(!$file_copy)
                                        {
                                                echo "<strong>Copy Unsuccessful</strong>";
                                                $flag=1;
                                        }
                                }
                             }
                                
                                             $userArray1=explode(',', $_REQUEST['userId1'][$i]);
                                            $newusrArray1=array_filter($userArray1);
                                            $usrstr1=implode(',', $newusrArray1);
                                            if($_REQUEST['doc']=='I'){ $from1=$_REQUEST['froms'][$i]; $to1=$usrstr1;}
                                            else { $from1=$usrstr1; $to1=$_REQUEST['tos'][$i]; }
                
                                            
                                            $dataP1['parent_id']=$_REQUEST['dmsID'];
                                            $dataP1['doc_name']=$docname;
                                            $dataP1['doc_type_mstr_id']=$_REQUEST['doc_type_mstr_id'][$i];
                                            $dataP1['doc_file_name']=$name;
                                            $dataP1['cariers']=$_REQUEST['carierss'][$i];
                                            $dataP1['tracking_no']=$_REQUEST['tracking_nos'][$i];
                                            $dataP1['from_name']=$from1;
                                            $dataP1['to_name']=$to1;
                                            $dataP1['address']=$_REQUEST['addresss'][$i];
                                            $dataP1['mobile']=$_REQUEST['mobiles'][$i];
                                             
//                                            echo "<pre>";
//                                            print_r($dataP);
//                                            exit;

                                            $s->RecordInsert('dms_doc_type_dtls',$dataP1);
                                        
                                    //}
                                
                                
                                
                                
                            
           }
        }

   	
  
    }

             
        }
       
    
        $data['doc_Type']=$_REQUEST['doc_Type'];
	$data['doc_id']=$_REQUEST['doc_id'];
       $data['doc']=$_REQUEST['doc'];
        $data['modifiedBy']=$_SESSION['UserID'];
	$data['modifiedDate']=date("Y-m-d H:i:s");
	
//	echo "<pre>";
//	print_r($data);
//	exit;
        $cond="id='".$_REQUEST['dmsID']."'";
	$s->RecordEdit('dms_doc_type', $data, $cond);// UPDATE ON OLD ITEM
	
	       
       echo '<div class="success">Record Updated Succesfully!!</div>';
  $s->pageLocation("index.php?route=DMS/doc_type_index".$rurl);

        
}
?>
<div id="PickedItems" style="display:none">
</div>

<div id="div_id" style="display:none"></div>

<div id="div_idEcess" style="display:none"></div>
<script language="javascript" type="text/javascript">
function CalrequiredQty(val,i)
{
 var ctr1=i.split("_");
 //alert(ctr1[0]);
 if(ctrl[0]==undefined)
 {
var a=	document.getElementById("stock_qty").value;
var res = val-a;
document.getElementById("required_qty").value=res.toFixed(3);
 }
 else
 {
var a=	document.getElementById("stock_qty_"+ctr1[1]).value;
var res = val-a;
document.getElementById("required_qty_"+ctr1[1]).value=res.toFixed(3);
 }
 

 
}
function open_items()
{
	window.open("requisition_items.php?action=add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>","item_popup_window","height=600,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function generate_reqno(str)
{
	if (str.length==0)
  {
  document.getElementById("reqno").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("reqno").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_reqno.php?site="+str,true);
xmlhttp.send();
}
function check_approveqty(str,j)
{
	var req_qty=document.getElementById("req_qty_"+j).value;
	if(str>req_qty)
	{
		alert("Quantity to approve cannot be greater than requsition quantity");
		document.getElementById("app_qty_"+j).value='';
		document.getElementById("app_qty_"+j).focus();
	}
	
}
</script>
<?php
$fetchSql="select * from dms_doc_type where id='".$_REQUEST['id']."'";
$fetchSqlExec=DB_query($fetchSql,$db);
$row=DB_fetch_array($fetchSqlExec);

$data1='';
$data2='';
$type=$row['doc_Type'];
if($type=='V'){
    $data1='Vendor';
    ?>
    <?php
            $ven_sql="select id,vendor_name from suppliers where CompanyId='".$_SESSION['ACGCompanyId']."' order by vendor_name";
            $ven_sqlExec=DB_query($ven_sql,$db);
            
	$data2.='<select name="doc_id" id="doc_id" style="width:150px;">';
	 while($ven_row=DB_fetch_array($ven_sqlExec)){
             if($ven_row==$row['doc_id']){ $r='selected';}
	$data2.='<option value="'.$ven_row['id'].'"'.$r.'>'.$ven_row['vendor_name'].'</option>';
	} 
	$data2.='</select>';
}

elseif($type=='C') {
$data1='Client';
$client_sql="select id,c_name from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' order by c_name";
            $client_sqlExec=DB_query($client_sql,$db);
            
	$data2.='<select name="doc_id" id="doc_id" style="width:150px;">';
	while($clnt_row=DB_fetch_array($client_sqlExec)){
            if($clnt_row==$row['doc_id']){ $r='selected';}
	$data2.='<option value="'.$clnt_row['id'].'"'.$r.'>'.$clnt_row['c_name'].'</option>';
	 } 
	$data2.='</select>';
 }
 
 elseif($type=='G') {
$data1='General';
$data2='<input type="text" name="doc_id" id="doc_id" style="width:150px;" value="'.$row['doc_id'].'"/>';
 }
 elseif($type=='O') {
$data1='Other';
$data2='<input type="text" name="doc_id" id="doc_id" style="width:150px;" value="'.$row['doc_id'].'"/>';
 }
 elseif($type=='B') {
$data1='Branch';
$ss1="SELECT loccode,locationname FROM  locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$_SESSION['AssignedBranch']."')";
	$site_sql=DB_query($ss1,$db);
	$data2.='<select name="branch" id="site" style="width:150px;">';
	 while($site_row=DB_fetch_array($site_sql)){
             if($site_row['loccode']==$row['doc_id']){ $r='selected';}
	$data2.='<option value="'.$site_row['loccode'].'"'.$r.'>'.$site_row['locationname'].'</option>';
	 } 
	$data2.='</select>';
 }
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div"> 
<h1><?php echo $desc; ?></h1>		
<form name="RequisitionDetailsform" enctype="multipart/form-data" action="" method="post" onsubmit="return formvalidate()">
    
    
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<input type="hidden" name="dmsID" id="dmsID" value="<?php echo $_REQUEST['id']; ?>" />
<tr class="row1">
	<td class="tabledata1"><strong>Branch</strong></td>
	<td>
	<?php 
	$ss1="SELECT loccode,locationname FROM  locations where CompanyId='".$_SESSION['ACGCompanyId']."' and loccode in('".$row['branch']."')";
	$site_sql=DB_query($ss1,$db);?>
	<select name="branch" id="site" style="width:150px;"><!-- onchange="generate_reqno(this.value)"-->
	<?php while($site_row=DB_fetch_array($site_sql)){?>
	<option value="<?php echo $site_row['loccode'];?>"<?php echo ($row['branch']==$site_row['loccode']?'selected':'')?>><?php echo $site_row['locationname'];?></option>
	<?php } ?>
	</select></td>
	<td class="tabledata1"><strong>Document No.</strong></td>
	<td>
	<input type="text" name="autoNo" id="autoNo" readonly="true" value="<?php echo $row['doc_no']; ?>" style="width:150px;">
	</td>
        <td class="tabledata1"><strong>Date</strong></td>
	<td>
	<input type="text" name="doc_date" id="doc_date" readonly="true" value="<?php if(isset($row['doc_date']))echo ConvertSQLDate($row['doc_date']);?>" style="width:150px;">
	</td>
  </tr>
  
  <tr class="row1">
	<td class="tabledata1"><strong>Document From/To</strong></td>
	<td>
	<?php  $doctype=array("V" =>"Vendor","C" =>"Client","G" =>"General","O" =>"Other","B" =>"Branch"); ?>
	<select name="doc_Type" id="doc_Type" style="width:150px;" onchange="getTypeDetails(this.value)">
	<?php foreach($doctype as $keyDoc => $docName){?>
	<option value="<?php echo $keyDoc; ?>"<?php echo ($row['doc_Type']==$keyDoc?'selected':'')?>><?php echo $docName;?></option>
	<?php } ?>
	</select></td>
        <td class="tabledata1" ><strong><label id="showTypes1"><?php echo $data1; ?></label></strong></td>
	<td id="showTypes2">
            <?php
          echo  $data2;
            ?>
	</td>
        
        <td class="tabledata1"><strong>Movement</strong></td>
	<td>
           <?php 
           $docType=$row['doc'];
           $doc=array($row['doc']); ?>
	<select name="doc" id="doc" style="width:150px;" >
	<?php foreach($doc as $keyDocs){?>
        <option value="<?php echo $keyDocs; ?>"<?php echo ($row['doc']==$keyDocs?'selected':'')?>><?php if($keyDocs=='O') { echo 'Outgoing'; } else { echo 'Incoming'; }?></option>
	<?php } ?>
	</select>
	</td>
  </tr>
  
 <!-- <tr class="row1">
	<td class="tabledata1"><strong>Mobile</strong></td>
	<td>
	<input type="text" name="phone" id="phone" style="width:150px;" value="<?php echo $row['phone']; ?>"></td>
	
        <td class="tabledata1"><strong></strong></td>
	<td>
            
	</td>
  </tr>-->
<tr class="row1">
	<td colspan="6"></td>
</tr>


<!--<tr class="row1">
	<td colspan="6">
	<input type="button" name="profile_popup" value="Pick Items" id="profile_popup" class="search" />
	
    <input type="button" class="search"   onclick="deleteRowOrder('dataTable')" value="Delete" />       
	</td>
</tr>-->
<tr class="row1">
	<td colspan="6" style="font-size:12px; font-weight:bold;">Document Details</td>
</tr>
</table>
<div class="box" >
	<table width="100%" border="1" cellpadding="3" cellspacing="0">
            <?php if($_REQUEST['action']=='Edit') { ?>
	<tr class="row1">
		<td colspan="11"><center>
		<input type="button" onclick="addRow('dataTable')" class="search" value="Add More" />
		<input type="button" onclick="deleteRow('dataTable')" class="search" value="Delete Row" />
		</center></td>
	</tr>
            <?php } ?>
        <tr class="row1">
			<td class="tabledata" style="width:3%;">Select</td>
			<td class="tabledata" style="width:1%;">&nbsp;</td>
			<td class="tabledata" width="10%">Subject</td>
			<td class="tabledata" width="10%">Document Type</td>
			<td class="tabledata" width="10%">Document</td>
			<td class="tabledata" width="10%">Courrier</td>
			<td class="tabledata" width="9%">Tracking No.</td>
			<td class="tabledata" width="10%">From</td>
			<td class="tabledata" width="10%">To</td>
			<td class="tabledata" width="15%">Address</td>
			<td class="tabledata">Mobile No.</td>
                
	</tr>
        <?php 
       $detDta="select * from dms_doc_type_dtls where parent_id='".$_REQUEST['id']."'";
        $detDtaExec=DB_query($detDta,$db);
        $i=0;
        while ($detRow=DB_fetch_array($detDtaExec))
	  {
            $detailsID[]=$detRow['id'];
        ?>
	<input type="hidden" name="docDetailsId[]" id="docDetailsId_<?php echo $i; ?>" value="<?php echo $detRow['id']; ?>" />
	<tr class="row1" id='hide_<?php echo $i; ?>'>
            <td><div id='deactive_<?php echo $i; ?>' style='display:block;'>
                    <a href='#'   onclick='deactivate1(<?php echo $i; ?>)'><img src='images/delete1.Gif' /></a>
                </div></td>
                <?php  if($docType=='I') { ?>
                <td><input type="hidden" name="userId[]" id="userId_<?php echo $i; ?>" value="<?php echo $detRow['to_name']; ?>"/></td>
                <?php } else { ?>
                <td><input type="hidden" name="userId[]" id="userId_<?php echo $i; ?>" value="<?php echo $detRow['from_name']; ?>"/></td>
                <?php } ?>
		<td><input type="text" name="doc_name[]" value="<?php echo $detRow['doc_name']; ?>" style="width:100%;"/></td>
		<td><select name="doc_type_mstr_id[]" id="doc_type_mstr_id" style="width:100%;">
                        <option value="0">--Select Type--</option>
                        <?php
                        $userqry="select * from dms_doc_type_mstr where company_id='".$_SESSION['ACGCompanyId']."'";
                        $userqryExec=DB_query($userqry,$db);
                        while($row=DB_fetch_array($userqryExec))
                        { ?>
                        <option value="<?php echo $row['id']; ?>" <?php echo ($detRow['doc_type_mstr_id']==$row['id']?'selected':'')?>><?php echo $row['doc_type_name']; ?></option>
                      <?php  } ?>
                    </select></td>
		<td><?php if($detRow['doc_file_name']==''){ echo "No file Uploaded"; }else{?><a href="uploaded_docs/<?php echo $detRow['doc_file_name']; ?>" target="_blank"><?php echo $detRow['doc_file_name'];
                ?></a><?php } ?></td>
                <td>
                    <select name="cariers[]" id="cariers" style="width:100%;">
                    <?php 
                $carqry="select * from dms_crrer_mstr where companyid='".$_SESSION['ACGCompanyId']."'";
                        $carqryExec=DB_query($carqry,$db);
                while($rowCar=DB_fetch_array($carqryExec))
                        { ?>
                <option value="<?php echo $rowCar['id']; ?>" <?php echo ($detRow['cariers']==$rowCar['id']?'selected':'')?>><?php echo $rowCar['carrer_name'];?></option>
                <?php } ?>
                </select>
                   
                </td>
                <td><input type="text" name="tracking_no[]" value="<?php echo $detRow['tracking_no']; ?>" style="width:100%;"/></td>
                <?php if($docType=='I') {
                    $userArray=explode(',', $detRow['to_name']);
                    ?>
                <td id="fromDta"><input type="text" name="from[]" value="<?php echo $detRow['from_name']; ?>" style="width:100%;"/></td>
                <td id="toDta"><select name="to[]" id="to_<?php echo $i; ?>" multiple onchange="getUsers(this,this.id);" style="width:100%;">
                        <option value="0">--Select Users--</option>
                        <?php
                        $userqry="select * from www_users where companyid='".$_SESSION['ACGCompanyId']."'";
                        $userqryExec=DB_query($userqry,$db);
                        while($row=DB_fetch_array($userqryExec))
                        {
                             if(in_array($row['id'], $userArray)){ $r='selected';} else { echo $r='';} 
                            ?>
                        <option value="<?php echo $row['id']; ?>"<?php echo $r; ?>><?php echo $row['realname']; ?></option>
                      <?php  } ?>
                    </select></td>
          <?php } else {
              $userArray=explode(',', $detRow['from_name']);
              
              ?>
                <td id="fromDta"><select name="from[]" id="from" multiple onchange="getUsers(this,this.id);" style="width:100%;">
                        <option value="0">--Select Users--</option>
                        <?php
                        $userqry="select * from www_users where companyid='".$_SESSION['ACGCompanyId']."'";
                        $userqryExec=DB_query($userqry,$db);
                        while($row=DB_fetch_array($userqryExec))
                        {
                          if(in_array($row['id'], $userArray)){ $r='selected';} else { echo $r='';}   
                            ?>
                        <option value="<?php echo $row['id']; ?>"<?php echo $r; ?>><?php echo $row['realname']; ?></option>
                      <?php  } ?>
                    </select></td>
                <td id="toDta"><input type="text" name="to[]" value="<?php echo $detRow['to_name']; ?>" style="width:100%;"/></td>
          <?php } ?>
                <td><textarea name="address[]"  style="width:100%;"><?php echo $detRow['address']; ?></textarea></td>
                 <td><input type="text" name="mobile[]" value="<?php echo $detRow['mobile']; ?>" style="width:100%;" /></td>

	</tr>
	
          <?php $i++; }
          //print_r($detailsID);
          if($detailsID)
          $detailsStr=implode(',',$detailsID);
          ?>
        <input type="hidden" name="detailsIDS" id="detailsIDS" value="<?php echo $detailsStr; ?>" />
        <?php if($_REQUEST['action']=='Edit') { ?>
        <tbody id="dataTable">
        <tr class="row1">
		<td><input type="checkbox" name="chk"  /></td>
                <td><input type="hidden" name="userId1[]" id="userId1" value="<?php echo $detRow['to_name']; ?>"/></td>
		<td><input type="text" name="doc_names[]" value="<?php echo $detRow['doc_name']; ?>" style="width:100%;"/></td>
		 <td><select name="doc_type_mstr_id[]" id="doc_type_mstr_id" style="width:100%;">
                        <option value="0">--Select Type--</option>
                        <?php
                        $userqry="select * from dms_doc_type_mstr where company_id='".$_SESSION['ACGCompanyId']."'";
                        $userqryExec=DB_query($userqry,$db);
                        while($row=DB_fetch_array($userqryExec))
                        { ?>
                        <option value="<?php echo $row['id']; ?>"><?php echo $row['doc_type_name']; ?></option>
                      <?php  } ?>
                    </select></td>
		<td><input type="file" name="doc_file_names[]" id="docmnt" value="" tabindex="69" style="width:100%;"/></td>
                <td><select name="carierss[]" id="cariers" style="width:100%;" >
                    <?php 
                $carqry="select * from dms_crrer_mstr where companyid='".$_SESSION['ACGCompanyId']."'";
                        $carqryExec=DB_query($carqry,$db);
                while($rowCar=DB_fetch_array($carqryExec))
                        { ?>
                <option value="<?php echo $rowCar['id']; ?>"<?php echo ($_REQUEST['cariers']==$rowCar['id']?'selected':'')?>><?php echo $rowCar['carrer_name'];?></option>
                <?php } ?>
                </select></td>
                <td><input type="text" name="tracking_nos[]" style="width:100%;" /></td>
                <?php if($docType=='I') { ?>
                <td><input type="text" name="froms[]" value="<?php echo $detRow['from_name']; ?>" style="width:100%;"/></td>
                <td><select name="tos[]" id="to" multiple onchange="getUsers1(this,this.id);" style="width:100%;">
                        <option value="0">--Select Users--</option>
                        <?php
                        $userqry="select * from www_users where companyid='".$_SESSION['ACGCompanyId']."'";
                        $userqryExec=DB_query($userqry,$db);
                        while($row=DB_fetch_array($userqryExec))
                        { ?>
                        <option value="<?php echo $row['id']; ?>"<?php if($detRow['to_name']==$row['id']) { echo 'selected'; } else { echo ''; } ?>><?php echo $row['realname']; ?></option>
                      <?php  } ?>
                    </select></td>
          <?php } else { ?>
                <td><select name="froms[]" id="from" multiple onchange="getUsers1(this,this.id);" style="width:100%;">
                        <option value="0">--Select Users--</option>
                        <?php
                        $userqry="select * from www_users where companyid='".$_SESSION['ACGCompanyId']."'";
                        $userqryExec=DB_query($userqry,$db);
                        while($row=DB_fetch_array($userqryExec))
                        { ?>
                        <option value="<?php echo $row['id']; ?>"<?php if($detRow['from_name']==$row['id']) { echo 'selected'; } else { echo ''; } ?>><?php echo $row['realname']; ?></option>
                      <?php  } ?>
                    </select></td>
                <td><input type="text" name="tos[]" value="<?php echo $detRow['to_name']; ?>" style="width:100%;"/></td>
          <?php } ?>
                
                <td><textarea name="addresss[]"  style="width:100%;"></textarea></td>
                <td><input type="text" name="mobiles[]" style="width:100%;" /></td>
                
	</tr>
	
        </tbody>
        <?php } ?>
	<input type="hidden" id="hiditemcount" value="<?php echo $i; ?>"/>
	</table>
	</div>
    
    
<table width="100%" cellpadding="3" cellspacing="0">
    <tr class="row1">
	<td colspan="6"></td>
</tr><?php if($_REQUEST['action']=='Edit') { ?>
<tr class="row1">
	<td style="text-align:center;" colspan="15">
        <input type="submit" name="Save" value="Update" class="search" onclick="return validatedata()">
	<input type="button" name="back" class="search" value="Back" onclick="window.location.href='index.php?route=DMS/doc_type_index&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid']?>'">
	<input type="reset" name="cancel" class="search" value="Reset" />
	</td>
</tr>
<?php } ?>
</table>
</form>
</div>
</div>

<script language="javascript" type="text/javascript">
  function getUsers(pBox,id)
{ 
    var brk=id.split('_');
//alert(brk[1]);
var x= brk[1];

if(x==undefined)   	
{
var sub_cat_array=Array();
    for(var i = 0; i < pBox.options.length; i++){
        if(pBox.options[i].selected){
           
            sub_cat_array[i]=pBox.options[i].value;
        }
    }
     document.getElementById("userId").value=sub_cat_array;
}
else
    {
        var sub_cat_array=Array();
    for(var i = 0; i < pBox.options.length; i++){
        if(pBox.options[i].selected){
           
            sub_cat_array[i]=pBox.options[i].value;
        }
    }
     document.getElementById("userId_"+x).value=sub_cat_array;
     
    }
    
}

 function getUsers1(pBox,id)
{ 
    var brk=id.split('_');
//alert(brk[1]);
var x= brk[1];

if(x==undefined)   	
{
var sub_cat_array=Array();
    for(var i = 0; i < pBox.options.length; i++){
        if(pBox.options[i].selected){
           
            sub_cat_array[i]=pBox.options[i].value;
        }
    }
     document.getElementById("userId1").value=sub_cat_array;
}
else
    {
        var sub_cat_array=Array();
    for(var i = 0; i < pBox.options.length; i++){
        if(pBox.options[i].selected){
           
            sub_cat_array[i]=pBox.options[i].value;
        }
    }
     document.getElementById("userId1_"+x).value=sub_cat_array;
     
    }
    
}
    
    
   function formvalidate()
   {
        if(document.getElementById("doc_Type").value=='O')
       {
       	if(document.getElementById("doc_id").value==''){
         alert("Enter Other Details");
		 document.getElementById("doc_id").focus();
         return false;
       }
       }
       if(document.getElementById("doc_Type").value=='G')
       {
        if(document.getElementById("doc_id").value==''){
         alert("Enter General Details");
		 document.getElementById("doc_id").focus();
         return false;
       }
       }
        if(document.getElementById("doc_name").value=='')
       {
         alert("Enter Document Details");
		 document.getElementById("doc_name").value='';
		 document.getElementById("doc_name").focus();
         return false;
       }
	   
      else{
         return true;}
   }
 function numeric(str,id)
{
  
var count=0;
var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?abcdefghijklmnopqrstuvwxyz";
  
for (var i = 0; i < str.length; i++) {
    if (iChars.indexOf(str.charAt(i)) != -1) {
  count++;
        }
    }
if(count>0)
{
    alert('Charcters Cannot Be Entered');
    document.getElementById(id).value='';
    document.getElementById(id).focus();
    
}
}

function addQty(str,id)
{
    numeric(str,id);
    id1=id.split("_");
     i=id1[1];
     var recQty=document.getElementById("recQty_"+i).value;
     var openQty=document.getElementById("openQty_"+i).value;
     if(recQty=='') { recQty=0; }
     if(openQty=='') { openQty=0; }
     
     var total=parseFloat(recQty)+parseFloat(openQty);
     document.getElementById("stockQty_"+i).value=total.toFixed(2);
       
}
function deactivate(str)
{
	document.getElementById("mst_itemid_"+str).value='';
	document.getElementById("active_"+str).style.display='block';
	alert('Item removed');
}
function activate(str)
{
	document.getElementById("mst_itemid_"+str).value=document.getElementById("temp_item_id_"+str).value;
	document.getElementById("active_"+str).style.display='none';
}
function open_copy_items()
{
	window.open("requisition_items.php?action=copy&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&reqid=<?php echo $_REQUEST['reqid'];?>","item_popup_window","height=600,width=500,toolbar=no,menubar=no,dependent=yes,resizable =yes, scrollbars=yes");
}
function checkReqDate()
{

var curr_date2='';	
var curr_month2='';
var d = new Date();

//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();


var curr_month1 = d.getMonth();

var curr_year = d.getFullYear();
var curr_month=curr_month1+1;
var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);

var date1=document.getElementById("date").value;
var str1 = date1;
var str2 = datedat;
    var dt1  = parseInt(str1.substring(0,2),10);
    var mon1 = parseInt(str1.substring(3,5),10);
    var yr1  = parseInt(str1.substring(6,10),10);
    var dt2  = parseInt(str2.substring(0,2),10);
    var mon2 = parseInt(str2.substring(3,5),10);
    var yr2  = parseInt(str2.substring(6,10),10);
    var date1 = new Date(yr1, mon1, dt1);
    var date2 = new Date(yr2, mon2, dt2);
    if(date2 > date1)
    {
        alert(" Requisition Date Can't Be Less than Current Date");
		document.getElementById("date").value='';
		document.getElementById("date").focus();
        return false;
    }
    else
    {
        return true;
        
    } 




}

function checkReqDate1(i)
{

var j=i.split("_");

if(j[1]==undefined)
{
var date1=document.getElementById("materialrequiredby").value;
}
else
{
var k=j[1];	
var date1=document.getElementById("materialrequiredby_"+k).value;
}
       
       var collection1 =   date1.split("/");
             
       var DobDate   = collection1[0];
       var DobMonth = collection1[1];       
       var DobYear   = collection1[2];     
	   
	   
	   var d = new Date();        
              
       var SysDate   = d.getDate();
       var SysMonth = d.getMonth()+1;
       var SysYear   = d.getFullYear();       
        
       if(DobYear < SysYear)
       {
         alert(" Requisition Date Can't Be Less than Current Date");
		
		
		 
         return false;      
       }
       else if((DobYear == SysYear) && (DobMonth < SysMonth))
       {
        alert(" Requisition Date Can't Be Less than Current Date");
		
		
         return false; 
       }
       
        else if((DobYear == SysYear) && (DobMonth == SysMonth) && (DobDate < SysDate))
       {
        alert(" Requisition Date Can't Be Less than Current Date");
		
		
         return false;
       }
      
         return true;


	


}

function validatedata()
{
var date=document.getElementById("date").value;

var from_date= document.getElementById('date').value; 


	    
var curr_date2='';	
var curr_month2='';
var d = new Date();


//alert(d.format("m/dd/yy"));
var curr_date = d.getDate();



var curr_month1 = d.getMonth();


var curr_year = d.getFullYear();
var curr_month=curr_month1+1;


var t=curr_month;
var d=curr_date;
if(t!=10 || t!=11 ||t!=12 )
{
 curr_month2="0" + curr_month;	
}
else
{
 curr_month2=curr_month;	
}
if(d==1 || d==2 || d==3 || d==4 || d==5 || d==6 || d==7 || d==8 || d==9 )
{
 curr_date2="0" + curr_date;		
}
else
{
 curr_date2=curr_date;		
}


var datedat=(curr_date2 + "/" + curr_month2 
+ "/" + curr_year);


var date1=Date.parse(date);
var datedat1=Date.parse(datedat);


if(date1 < datedat1)
		{
			alert("Requisition Date Can't Be Less than Current Date");
			
			document.getElementById("date").focus();
			return false;
		}
	
if(document.getElementById("site").value=='000')
{
	alert("Please Select The Site First");
	document.getElementById("site").focus();
	return false;
}


if(document.getElementById("date").value=='')
{
	alert("Please Select The Requisition Date First");
	document.getElementById("date").focus();
	return false;
}

if(document.getElementById("requition_by").value=='')
{
	alert("Please Select The Requisition By First");
	document.getElementById("requition_by").focus();
	return false;
}


if(document.getElementById("category").value=='')
{
	alert("Please Select The Category First");
	document.getElementById("category").focus();
	return false;
}
		
		
var count=document.getElementById("hiditemcount").value;	
	//if(count=='')
//	{
//	alert("Must Select Items");
//	return false;	
//	}
if(count==''){

if(document.getElementById("itemcode").value=='')
{
	alert("Please Select Items First");
	document.getElementById("itemcode").focus();
	return false;
}
}else if(count=='1'){
 if(document.getElementById("requisitionqty").value=='' || document.getElementById("requisitionqty").value=='0')
{   alert("Priyanka");
	alert("Please Select Requisition Qty");
	document.getElementById("requisitionqty").focus();
	return false;
}

if(document.getElementById("materialrequiredby").value=='')
{
	alert("Please Select Date");
	document.getElementById("materialrequiredby").focus();
	return false;
}
}

/*if(document.getElementById("requisitionqty").value=='' || document.getElementById("requisitionqty").value=='0')
{
	alert("Please Select Requisition Qty");
	return false;
}

if(document.getElementById("materialrequiredby").value=='')
{
	alert("Please Select Date");
	return false;
}*/

else
{
	for(var i=1;i<=count;i++)
	{
	
	/*if(document.getElementById("itemcode_"+i).value=='')
	{
	alert("Please Select Items First");
	return false;
	}*/
	
	if(document.getElementById("itemcode_"+i).value!=''){
		if(document.getElementById("requisitionqty_"+i).value=='' || document.getElementById("requisitionqty_"+i).value=='0')
		{ 
			alert("Please Enter Requisition Quantity");
			document.getElementById("requisitionqty_"+i).focus();
			return false;	
		}	
		if(document.getElementById("materialrequiredby_"+i).value=='')
		{
			alert("Please Select Material Required Date");
			document.getElementById("materialrequiredby_"+i).focus();
			return false;	
		}	
	
	
	/*if(document.getElementById("requiredqty_"+i).value=='' || document.getElementById("requiredqty_"+i).value==0)
	{
	alert("Please Enter Reqired Quantity");
	document.getElementById("requiredqty_"+i).focus();
	return false;	
	}	
	*/
	
		if(document.getElementById("materialrequiredby_"+i).value<datedat)
		{
			alert("Material Required Date Can't Be Less than Current Date");
			document.getElementById("materialrequiredby_"+i).focus();
			return false;
			
		}
	}else{
	    return true;
	}
	
	}	return true;
	
	}
	
}
function validate()
{
	
	var counter=document.getElementById("count_req").value;
	
	for(var x=1;x<=counter;x++)
	{
	
		var approve=document.getElementById("app_qty_"+x).value;
		
		if(approve=='')
		{
			alert("Please enter quantity to be approved for all items");
			return false;
		}
	}
	
}

function subTotal(str,i)
{
		var rate=document.getElementById("last_po_rate_"+i).value;
		if(rate==''){rate=0;}
		var total=parseFloat(str) * parseFloat(rate);
		var approve=document.getElementById("sub_total_"+i).value=total.toFixed(2);
		var count_req=document.getElementById("count_req").value;
		var grand_tot=0;
		for(var k=1;k<=count_req;k++)
		{
			var sub_tot=document.getElementById("sub_total_"+k).value;
			grand_tot=parseFloat(grand_tot)+parseFloat(sub_tot);
		}
		document.getElementById("grand_total").value=grand_tot.toFixed(2);
		
}
function calc_basicamt()
{
	var grand_total=0;
	var cnt=document.getElementById("count_req").value
	for(var j=1;j<=cnt;j++)
	{
		var sub_total=document.getElementById("sub_total_"+j).value;
		if(sub_total==''){sub_total=0;}
		grand_total=parseFloat(grand_total)+parseFloat(sub_total);
	}
	document.getElementById("grand_total").value=grand_total.toFixed(2);
}

function calamt(i,str)
{
	
document.getElementById("app_qty1_"+i).value=str;	
	
}

function opendata(str,id)
{

  var sitecode=document.getElementById("site").value;
  var date=document.getElementById("date").value;
 if (str.length == 0)
    {    	
     document.getElementById("lightbox2").innerHTML="";
     document.getElementById("lightbox2").style.border="0px";
      return;
    }	
	
	if(sitecode=='000')
	{
	alert("Must Select Site");
	document.getElementById("site").focus();
	return;
	}
	else if(date=='')
	{
	alert("Must Select Date");
	document.getElementById("date").focus();
	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("lightbox2").style.display='block';	
	document.getElementById("lightbox2").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  
  var sitecode=document.getElementById("site").value;
  var date=document.getElementById("date").value;


  xmlhttp.open("GET","showpopup_for_requisition.php?site="+str+"&data="+id+"&site1="+sitecode+"&date="+date,true);
  xmlhttp.send();	
}

function getTypeDetails(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("showTypes1").innerHTML=data[0];
        document.getElementById("showTypes2").innerHTML=data[1];
	
    }
  }
  
  xmlhttp.open("GET","ajax_get_docType.php?val="+str,true);
  xmlhttp.send();
}

function hidedata()
{
document.getElementById("lightbox2").style.display='none';
}

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+1;
        //alert(rowCount);
	var colCount = table.rows[0].cells.length;
	for(var i=0; i<colCount; i++) {	
	
	var newcell = row.insertCell(i);
	row.className='row1';
	//newcell.style.background='#e7e7e7';
	newcell.className='tabledata1';
	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;	
        case "select-multiple":
	newcell.childNodes[0].selectedIndex = 0;
	var nod_id = newcell.childNodes[0].id;
	newcell.childNodes[0].id = newcell.childNodes[0].id+'_'+rowCount;
	break;	
	}
		//document.getElementById("stock_perunit_"+rowCount).value=1;
	}
	document.getElementById("stock_perunit_"+rowCount).value='1';
	}





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=(rowCount);		}
	catch(e) 
	{
	alert(e);
	}
}
function opendata1(str,id)
{

  var sitecode=document.getElementById("site").value;
  var date=document.getElementById("date").value;
 if (str.length == 0)
    {    	
     document.getElementById("lightbox2").innerHTML="";
     document.getElementById("lightbox2").style.border="0px";
      return;
    }	
	
	if(sitecode=='000')
	{
	alert("Must Select Site");
	document.getElementById("site").focus();
	return;
	}
	else if(date=='')
	{
	alert("Must Select Date");
	document.getElementById("date").focus();
	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("lightbox2").style.display='block';	
	document.getElementById("lightbox2").innerHTML=xmlhttp.responseText;
	
   // document.getElementById("textitem").innerHTML=data[1];
	
    }
  }
  
  var sitecode=document.getElementById("site").value;
  var date=document.getElementById("date").value;


  xmlhttp.open("GET","showpopup_for_requisition.php?site3="+str+"&data="+id+"&site1="+sitecode+"&date="+date,true);
  xmlhttp.send();	
}

function getdata1(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("ItemListDiv").innerHTML=data[0];
	//document.getElementById("subcategory1").innerHTML=data[0];
	//alert(xmlhttp.responseText);
	document.getElementById("ItemListDiv").innerHTML=xmlhttp.responseText;
	}
	}
	 var site=document.getElementById("site").value;
	xmlhttp.open("GET","ajax_item_list_srch.php?keywd="+str+"&site="+site,true);
	xmlhttp.send();
	//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);
}	


</script>


