<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)
            {
                    var data=xmlhttp.responseText.split("__");	
                    //alert(data[0]);alert(data[1]);
                    document.getElementById("fromDta").innerHTML=data[0];
                    document.getElementById("toDta").innerHTML=data[1];
            }
	}
	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']!='')
{
    //print_r($_REQUEST['docDetailsId']);exit;
            for($i=0;$i<count($_REQUEST['docDetailsId']);$i++)
            {
                if($_REQUEST['remarks'][$i]!='')
                {
                    $data['followUpDate']=FormatDateForSQL($_REQUEST['followUpDate']);
                    $data['nxtfolowDate']=FormatDateForSQL($_REQUEST['nxtfolowDate']);
                    $data['doc_type_id']=$_REQUEST['dmsID'];
                    $data['doc_type_dtls_id']=$_REQUEST['docDetailsId'][$i];
                    $data['remarks']=$_REQUEST['remarks'][$i];
                    $data['createdBy']=$_SESSION['UserID'];
                    $data['createdDate']=date("Y-m-d H:i:s");
                    $data['CompanyId']=$_SESSION['ACGCompanyId'];
    //                echo "<pre>";
    //                print_r($data);
    //                exit;
                    $s->RecordInsert('dms_doc_followUp',$data);
                    echo '<div class="success">Record Added 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</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;">
	<?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>Document Type</strong></td>
	<td>
           <?php  $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  style="font-size:12px; font-weight:bold;">Follow-Up Date <font style='color:red;'>* </font></td>
        <td><input type="text" name="followUpDate" id="flup_date" readonly="true" value="<?php echo date("d/m/Y"); ?>" style="width:150px;" class='datepicker'></td>
        <td  style="font-size:12px; font-weight:bold;">Next Follow-Up Date </td>
        <td colspan='3'><input type="text" name="nxtfolowDate" id="nxt_flup_date" readonly="true"  style="width:150px;" class='datepicker'></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>-->

</table>
<div class="box" >
	<table width="100%" border="1" cellpadding="3" cellspacing="0">
            
        <tr class="row1">           
		<td class="tabledata">Doc. Name</td>
                <td class="tabledata">Document</td>
		<td class="tabledata">Carrier</td>
		<td class="tabledata">Tracking No.</td>
                <td class="tabledata" colspan='2'>Remarks <font style='color:red;'>*</font></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><input type="text" name="doc_name[]" value="<?php echo $detRow['doc_name']; ?>"/></td>
		<td><a href="uploaded_docs/<?php echo $detRow['doc_file_name']; ?>" target="_blank"><?php echo $detRow['doc_file_name'];
                ?></a></td>
                <td>
                    <select name="cariers[]" id="cariers" style="width:150px;">
                    <?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']; ?>"/></td>
                <td><a onclick="popup('pop_up_remrks.php?modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&id=<?php echo $detRow['id'];?>',600,300)" href="#" >Prev. Remarks</a></td>
                <td><textarea name="remarks[]" id='remarks'  style="width:100%;"></textarea></td>
	</tr>
	
          <?php $i++; }
          //print_r($detailsID);
          if($detailsID)
          $detailsStr=implode(',',$detailsID);
          ?>
        <input type="hidden" name="detailsIDS" id="detailsIDS" value="<?php echo $detailsStr; ?>" />
        </table>
	</div>
    
    
<table width="100%" cellpadding="3" cellspacing="0">
    <tr class="row1">
	<td colspan="6"></td>
</tr>
<tr class="row1">
	<td style="text-align:center;" colspan="15">
        <input type="submit" name="Save" value="Save" class="search" onclick="return validatedata()">
	<input type="button" name="back" class="search" value="Back">
	<input type="submit" name="cancel" class="search" value="Reset" />	
	</td>
</tr>

</table>
</form>
</div>
</div>

<script language="javascript" type="text/javascript">
    
   function formvalidate()
   {
        if(document.getElementById("itemcode").value=='')
       {
         alert("Enter Item Details");
		 document.getElementById("itemcode").value='';
		 document.getElementById("itemcode").focus();
         return false;
       }
	   
      
         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()
{
    if(document.getElementById("flup_date").value=='')
        {
            alert("Enter Follow Up Date");
            document.getElementById("date").focus();
            return false;
        }
        
      if(document.getElementById("remarks").value=='')
        {
            alert("Enter Remarks");
            document.getElementById("remarks").focus();
            return false;
        }
       
        var date=document.getElementById("nxt_flup_date").value;
        if(date=='')
            {
        var r = confirm("Do You Want To Enter Next Follow-Up Date?");
        if(r == true)
          {
            
            
        if(date!='')
            {

            var from_date= document.getElementById('flup_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("Next Follow-Up Date Can't Be Less than Follow-Up Date");

                                    document.getElementById("nxt_flup_date").focus();
                                    return false;
                            }
          }
          else
              {
          document.getElementById("nxt_flup_date").focus();
          return false;
              }
          }
        else
          {
          return true;
          }
        
            } 
var date=document.getElementById("nxt_flup_date").value;
if(date!='')
    {

    var from_date= document.getElementById('flup_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("Next Follow-Up Date Can't Be Less than Follow-Up Date");

                            document.getElementById("nxt_flup_date").focus();
                            return false;
                    }
    }

	 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;	
	}
		//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>


