<?php

session_start();
header("Content-type: text/html; charset=".$_SESSION['encodingmode']);
if($_SESSION['dbName']==""){
header("location:../index.php");
}


include("config.inc.php");
include("Functions_Trans.php");
//include("Forms_DataGrid.php");
include("Forms_RMA_DataGrid.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

if(	$_SESSION['encodingmode'] == 'utf8' || $_SESSION['encodingmode'] == 'utf-8'){
	mysql_query("SET NAMES 'utf8'"); 
	mysql_query('SET CHARACTER SET utf8'); 
	mysql_set_charset('utf8', $connection);
}

if(!empty($_POST['rmadt_engrecieved'])){
	$rmadt_engrecieved = $_POST['rmadt_engrecieved'];
	//echo $rmadt_engrecieved[0];
	$date = date('Y-m-d H:i:s');
	foreach ($rmadt_engrecieved as $key => $value) {
		$query="Update rmadt set rmadt_engrecieved=1, rmadt_engrecieved_date='$date' where rmadt_id = '$value'";
		//echo $query;exit;
		$result = mysql_query($query, $connection);
	}
}

if(!empty($_POST['rmadt_qcrecieved'])){
	$rmadt_qcrecieved = $_POST['rmadt_qcrecieved'];
	//echo $rmadt_qcrecieved[0];
	$date = date('Y-m-d H:i:s');
	foreach ($rmadt_qcrecieved as $key => $value) {
		$query="Update rmadt set rmadt_qcrecieved=1, rmadt_qcrecieved_date='$date' where rmadt_id = '$value'";
		//echo $query;exit;
		$result = mysql_query($query, $connection);
	}
}

if(!empty($_POST['rmadt_operatorrecieved'])){
	$rmadt_operatorrecieved = $_POST['rmadt_operatorrecieved'];
	//echo $rmadt_operatorrecieved[0];
	$date = date('Y-m-d H:i:s');
	foreach ($rmadt_operatorrecieved as $key => $value) {
		$query="Update rmadt set rmadt_operatorrecieved=1, rmadt_operatorrecieved_date='$date' where rmadt_id = '$value'";
		//echo $query;exit;
		$result = mysql_query($query, $connection);
	}
}

$query_language  = "select user_account, Language from ".$_SESSION['dbLabel'].".login  where user_account = '".$_SESSION['useraccount']."'";
$result_language = mysql_query($query_language, $connection); 
$row_language    = mysql_fetch_array($result_language);
extract($row_language);

$query_journal_labels  = "select Language, label0 as Ref1, TypeRef as TypeRef1, label3 as Folio1, label2 as Date1, label1 as Type1, Project as Project1, Disp_2_1 as Costcenter2, Remark as Remark1, ManualNo as ManualNo1, Disp_1 as LedgerNo1, LedgerName as LedgerName1, Disp_4_1 as DescX, Disp_3 as Curr1, D_C as DC1, Disp_5 as Amount1, Disp_1_3 as ValueDate1, ManualNo as ManualNo1, Desc1 as Desc1,
                          NoRecords, Perpage, Page, Disp_2_2 as Perce, Disp_1_1 as CheckNo, Disp_1_2 as Bankk, Label4 as Debitt, Label5 as Creditt, Disp_4 as Balancee
                          from ".$_SESSION['dbLabel'].".journal_label
                          where Language = '".$Language."'";
$result_journal_labels = mysql_query($query_journal_labels, $connection);
$row_journal_labels    = mysql_fetch_array($result_journal_labels);
extract($row_journal_labels);

$query_isengineer  = "select user_engineer, user_engineerqc from ".$_SESSION['dbLabel'].".users where User_account='".$_SESSION['useraccount']."'";
//echo $query_isengineer;
$result_isengineer = mysql_query($query_isengineer, $connection);
$row_isengineer    = mysql_fetch_array($result_isengineer);
extract($row_isengineer);	

$_SESSION['query_journal_labels'] = $query_journal_labels;

$query_navigator = "SELECT LANGUAGE,
       ClearPage,
       Excel,
       Save,
       Print,
       Addd,
       Search,
       Pending,
       CopyJV,
       PaymentRequests,
       ExportExcel,
	   cancell
FROM ".$_SESSION['dbLabel'].".mainform_label
WHERE LANGUAGE = '".$Language."'";
$result_navigator = mysql_query($query_navigator, $connection);
$row_navigator    = mysql_fetch_array($result_navigator);
extract($row_navigator);

//echo $Costcenter1; exit;
$query_project  = "select Journal as Journal1, ResultsPage as ResultsPage1
                   from ".$_SESSION['dbLabel'].".mainform_label
				   where Language = '".$Language."'";
$result_project = mysql_query($query_project, $connection);
$row_project    = mysql_fetch_array($result_project);
extract($row_project);

$querylog="SELECT FA_Journal as loginaccess from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' 	and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')	";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}
/*
if ($loginaccess=='' or $loginaccess==0)
	header("location:menu.php");
*/	
$querylog=" select ifNull(FA_JournalApp,0) As FA_JournalApp, ifNull(Login_FastPrint,0) As Login_FastPrint, ifNull(FA_LedgerAccess,0) As FA_LedgerAccess ".
		  " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."')  ";
$resultlog=mysql_query($querylog,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}

	
//Read From Setup Table							
$querysetup= " select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2, Journal_DefaultCur ".
             " from setup ";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter, ".
			 " ifNull(Module_RestrictProjCost,0) As Module_RestrictProjCost, ifNull(Module_RestrictCost,0) As Module_RestrictCost, ".
			 " ifNull(Module_ProjectDt,0) As Module_ProjectDt, ifNull(Module_CostCenterDt,0) As Module_CostCenterDt, ".
			 " ifNull(module_referencebycostcenter,0) As Module_ReferenceByCostCenter, ".
			 " ifNull(module_checks,0) As Module_checks, ".
			 " ifNull(Module_ShowBalance,0) As Module_ShowBalance, ifNull(Module_ImportExcell,0) As Module_ImportExcell, ifNull(Module_bill,0) As Module_bill ".
			" ,ifNull(module_journalRate,0) As module_journalRate,ifNull(module_ledgerrestrictcur,0) As module_ledgerrestrictcur  ".	
			" From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

//Read From TransSetup Table							
$querytranssetup= " select DefaultCur, DefaultProject as StpDefaultProject, DefaultCostcenter as StpDefaultCostcenter, ifnull(Hide_ValueDate,0) Hide_ValueDate,  ifnull(Hide_Base2,0) Hide_Base2
					from transsetup where JournalType = 'JV'";
$resulttranssetup=mysql_query($querytranssetup,$connection) or die(mysql_error());
while($rowtranssetup=mysql_fetch_array($resulttranssetup)){
	extract($rowtranssetup);
}

/// Journal Type
$queryjourtype="select type_name from jourtype where ifnull(type_visible,0) = 1 ";
$resultjourtype=mysql_query($queryjourtype,$connection)	or die( mysql_error($connection));



//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1 ";
$resultdflproject=mysql_query($querydflproject,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflproject)){
	extract($rows);
}

//Get Default Coscenter
$querydflcostcent="select costcent_code as defaultcostcent from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_costcenter=1 ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}

$vMainCompanyName=explode('_',$_SESSION['dbName']);  
$DirCompany  = $vMainCompanyName[0];
preg_match_all('!\d+!', $vMainCompanyName[1] ,$DirYears );
$fromdate =  '01/01/'.$DirYears[0][0];
$todate = date('d/m/Y'); 

$engineeroption = $_GET['engineeroption'];

print <<<HERE
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<link type="text/css" rel="stylesheet" href="js/calendar/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="js/calendar/dhtmlgoodies_calendar.js?random=20060118"></script>

<link rel="stylesheet" type="text/css" media="all" href="js/grid/UI_DataGrid_V1.css">
<script type="text/javascript" src="js/grid/UI_DataGrid.js"></script>
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>

<script type="text/javascript" src="js/tabsClass/tabber.js"></script>
<link rel="stylesheet" href="js/tabsClass/tabber.css" type="text/css" />

<link type="text/css" href="js/calendar/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="js/calendar/jquery.datepick.js"></script>

<link type="text/css" href="js/grid/scripts/jquery-ui.css" rel="stylesheet">
<script type="text/javascript" src="js/grid/scripts/jquery-ui.min.js"></script>

<script type="text/javascript" language="javascript">
$(document).ready(function() { 
		
		$(document).on('focus', '.date', function() {
			$('.date').datepick({showTrigger: '#calImg'});
		});
		
		$(document).on('focusin', '.table-focus-g1', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec','ModRec_G1','imgSubmit');
			selRecordColor(this,'SelectedRec','SelectedRecColor');
		});
		$(document).on('focusin', '.table-focus-g2', function() { 
			AutoSaveRecordGrid(this.id,'SelectedRec_G2','ModRec_G2','imgSubmit_D');
			selRecordColor(this,'SelectedRec_G2','SelectedRecColor_G2');
		});
		$(document).on('focusin', '.table-focus-g3', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec_G3','ModRec_G3','imgSubmit_C');
			selRecordColor(this,'SelectedRec_G3','SelectedRecColor_G3');
		});
		$(document).on('focusin', '.table-focus-g4', function() {
			AutoSaveRecordGrid(this.id,'SelectedRec_G4','ModRec_G4','imgSubmit_B');
			selRecordColor(this,'SelectedRec_G4','SelectedRecColor_G4');
		});
});	
function changeValue(rmadt_id){
	if(document.getElementById('chk_rmadt_id_'+rmadt_id).checked){
		document.getElementById('rmadt_id').value = rmadt_id;
	}
	
}
function receive(){
	var rmadt_id = document.getElementById('rmadt_id').value;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var filter_by = document.getElementById('filter_by').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
	var receive_date = document.getElementById('receive_date').value;
	var c = confirm("Are you sure?");
	if(c){
	var str = "Form_ListRMAPendingItems_Actions.php?actionmode=receive&rmadt_id="+rmadt_id+"&receive_date="+receive_date+"&start="+start+"&pagenumber="+pagenumber+"&filter_by="+filter_by;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_pending').innerHTML = data[0];
		document.getElementById('receive_usercode').value = data[1];
		document.getElementById('receive_date').value = data[2];
		document.getElementById('receive_usercode').readOnly = true;
		document.getElementById('receive_date').readOnly = true;
		document.getElementById('chk_rmadt_id_'+rmadt_id).checked = true;
	  }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
  }
}
function deliver(){
	var rmadt_id = document.getElementById('rmadt_id').value;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var filter_by = document.getElementById('filter_by').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
	var deliver_date = document.getElementById('deliver_date').value;
	var c = confirm("Are you sure?");
	if(c){
	var str = "Form_ListRMAPendingItems_Actions.php?actionmode=deliver&rmadt_id="+rmadt_id+"&deliver_date="+deliver_date+"&start="+start+"&pagenumber="+pagenumber+"&filter_by="+filter_by;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) { 
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_pending').innerHTML = data[0];
		document.getElementById('deliver_usercode').value = data[1];
		document.getElementById('deliver_date').value = data[2];
		document.getElementById('deliver_usercode').readOnly = true;
		document.getElementById('deliver_date').readOnly = true;
		document.getElementById('chk_rmadt_id_'+rmadt_id).checked = true;
	  }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
  }
}
function displayDate(rmadt_id){
	var str = "Form_ListRMAPendingItems_Actions.php?actionmode=displaydates&rmadt_id="+rmadt_id;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('receive_usercode').value = data[0];
		document.getElementById('receive_date').value = data[1];
		document.getElementById('receive_usercode').readOnly = true;
		document.getElementById('receive_date').readOnly = true;
		document.getElementById('deliver_usercode').value = data[2];
		document.getElementById('deliver_date').value = data[3];
		document.getElementById('deliver_usercode').readOnly = true;
		document.getElementById('deliver_date').readOnly = true;
	  }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function chkFilter(value){
	document.getElementById('start_par').value = 0;
	document.getElementById('pagenumber_par').value = 1;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var str = "Form_ListRMAPendingItems_Actions.php?actionmode=gofilterby&filter_by="+value+"&start="+start+"&pagenumber="+pagenumber;
	document.getElementById('filter_by').value = value;
	var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_pending').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function moveNext(){
	var from_date = document.getElementById('from_date').value;
	var to_date   = document.getElementById('to_date').value;
	document.getElementById('start_par').value = Number(document.getElementById('start_par').value) + 20;
	document.getElementById('pagenumber_par').value = Number(document.getElementById('pagenumber_par').value) + 1;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var search_type = document.getElementById('search_type').value;
	var search_location = document.getElementById('search_location').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=movenext&start="+start+"&pagenumber="+pagenumber+"&search_type="+search_type+"&search_location="+search_location+"&from_date="+from_date+"&to_date="+to_date;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function movePrev(){
	var from_date = document.getElementById('from_date').value;
	var to_date   = document.getElementById('to_date').value;
	document.getElementById('start_par').value = Number(document.getElementById('start_par').value) - 20;
	document.getElementById('pagenumber_par').value = Number(document.getElementById('pagenumber_par').value) - 1;
	var start = document.getElementById('start_par').value;
	var pagenumber = document.getElementById('pagenumber_par').value;
	var search_type = document.getElementById('search_type').value;
	var search_location = document.getElementById('search_location').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=moveprev&start="+start+"&pagenumber="+pagenumber+"&search_type="+search_type+"&search_location="+search_location+"&from_date="+from_date+"&to_date="+to_date;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function addDates(){
	var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!

var yyyy = today.getFullYear();
if(dd<10){
    dd='0'+dd;
} 
if(mm<10){
    mm='0'+mm;
} 
var today = dd+'/'+mm+'/'+yyyy;
	var search_location = document.getElementById('search_location').value;
	var search_type     = document.getElementById('search_type').value;
	if(search_type == "Expected_Date" || search_type == "Received_Date"){
		document.getElementById('search_location').value = today;
		document.getElementById('date_icon').style.display = "inline-block";
	}
	else{
		//document.getElementById('search_location').value = "";
		document.getElementById('date_icon').style.display = "none";
	}
}
function searchRMALocation(){
	document.getElementById('loader').innerHTML = "<img src='img/ajax-loader.gif' />";
	var search_location = document.getElementById('search_location').value;
	var search_type     = document.getElementById('search_type').value;
	var from_date       = document.getElementById('from_date').value;
	var to_date         = document.getElementById('to_date').value;
	if(document.getElementById('search_rmadt_approved'))
		var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	else
		var search_rmadt_approved = 0;
	if(document.getElementById('engineerchecked'))
		var engineerchecked = document.getElementById('engineerchecked').value;
	else
		var engineerchecked = 0;
	if(document.getElementById('qcchecked'))
		var qcchecked = document.getElementById('qcchecked').value;
	else
		var qcchecked = 0;
	if(document.getElementById('operatorchecked'))
		var operatorchecked = document.getElementById('operatorchecked').value;
	else
		var operatorchecked = 0;

	var str = "Form_ListRMALocation_Actions.php?actionmode=searchrmalocation&search_type="+search_type+"&search_location="+search_location+"&from_date="+from_date+"&to_date="+to_date+"&engineerchecked="+engineerchecked+"&qcchecked="+qcchecked+"&operatorchecked="+operatorchecked+"&search_rmadt_approved="+search_rmadt_approved;
	//alert(str);
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
		document.getElementById('loader').innerHTML = "";
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}

function searchByDate(){
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	var str                   = "Form_ListRMALocation_Actions.php?actionmode=searchbydate&from_date="+from_date+"&to_date="+to_date+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&search_type="+search_type+"&search_location="+search_location;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}
function selectRmaDt(rmadt_id){
	if(document.getElementById('rmadt_id_'+rmadt_id).checked){
		document.getElementById('rmadt_id').value = rmadt_id;
		var str = "Form_ListRMALocation_Actions.php?actionmode=editrmadt&rmadt_id="+rmadt_id;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		//document.getElementById('list_location').innerHTML = data[0];
		document.getElementById('check_update').value = data[0];
		document.getElementById('Rmadt_techquotation').value = data[1];
		document.getElementById('rmadt_approved').value = data[2];
		document.getElementById('rmadt_operatorSpareParts').value = data[3];
		if(data[2] == ""){
			document.getElementById('chk_rmadt_pending').checked = true;
		}
		else
		if(data[2] == 1){
			document.getElementById('chk_rmadt_approved').checked = true;
		}
		else
		    if(data[2] == 0){
			document.getElementById('chk_rmadt_refused').checked = true;
		}
		document.getElementById('rmadt_approved').value = data[2];
		document.getElementById('rmadt_qcduration').value = data[4];
		document.getElementById('rmadt_qcremark').value = data[4];
		document.getElementById('start_date').value = data[6];
		document.getElementById('start_time').value = data[7];
		document.getElementById('end_date').value = data[8];
		document.getElementById('end_time').value = data[9];
		document.getElementById('rmadt_operatoraditionalcomments').value = data[10];
		document.getElementById('rmadt_qcapproved').value = data[11];
		if(data[11] == ""){
			document.getElementById('chk_rmadt_qcnone').checked = true;
		}
		else
		if(data[11] == 1){
			document.getElementById('chk_rmadt_qcapproved').checked = true;
		}
		else
		if(data[11] == 0){
			document.getElementById('chk_rmadt_qcrefuse').checked = true;
		}
		document.getElementById('labeltodisplay').innerHTML = data[12];
		document.getElementById('rmadt_techquotation2').value = data[13];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
		//alert(rmadt_id);
	}
	
}
function chkUpdate(){
	var rmadt_id = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
	var str = "Form_ListRMALocation_Actions.php?actionmode=chkupdate&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		var response = data[0];
		//document.write(response);
		if(response == 1){
			alert("Checked Successfully!");
		}
		else{
			alert("Error in Checking!");
		}
		document.getElementById('check_update').value = data[0];
		document.getElementById('list_location').innerHTML = data[1];
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function updateQuotation(){
	var check_update          = document.getElementById('check_update').value;
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var Rmadt_techquotation   = document.getElementById('Rmadt_techquotation').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else
	   if(check_update == 0){
		  alert("Please check the update!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=updatequotation&rmadt_id="+rmadt_id+"&Rmadt_techquotation="+Rmadt_techquotation+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location;
		var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
		alert("Quotation added successfully!");
		document.getElementById('labeltodisplay').innerHTML = data[1];
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
		
}
function searchStatus(){
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var engineerchecked 	  = document.getElementById('engineerchecked');
	if(search_rmadt_approved == 1){
		{/*document.getElementById('start_end_time').style.display = 'inline-block';
		document.getElementById('chkupdatequotation').style.display = 'none';
		document.getElementById('start_end_time2').style.display = 'none';*/}
		engineerchecked.options[0].selected = 'true';
		engineerchecked.style.display = 'none';
		document.getElementById('checkspan').style.display='none';
	}
	else
		if(search_rmadt_approved == 2){
			{/*document.getElementById('start_end_time').style.display = 'none';
		    document.getElementById('chkupdatequotation').style.display = 'none';
			document.getElementById('start_end_time2').style.display = 'inline-block';*/}
			engineerchecked.options[0].selected = 'true';
			engineerchecked.style.display = 'none';
			document.getElementById('checkspan').style.display='none';
		}
		else
			if(search_rmadt_approved == 0){
				{/*document.getElementById('start_end_time').style.display = 'none';
				document.getElementById('chkupdatequotation').style.display = 'block';
				document.getElementById('start_end_time2').style.display = 'none';*/}
				engineerchecked.options[0].selected = 'true';
				engineerchecked.style.display = 'inline-block';
				document.getElementById('checkspan').style.display='inline-block';
			}
			else{
				{/*document.getElementById('start_end_time').style.display = 'none';
				document.getElementById('chkupdatequotation').style.display = 'block';
				document.getElementById('start_end_time2').style.display = 'none';*/}
			}
		
	
	var str = "Form_ListRMALocation_Actions.php?actionmode=searchstatus&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&engineerchecked=0&qcchecked=0&operatorchecked=0";
	var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	
}
function saveStartEndDuration(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start_date            = document.getElementById('start_date').value;
	var end_date              = document.getElementById('end_date').value;
	var start_time            = document.getElementById('start_time').value;
	var end_time              = document.getElementById('end_time').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	
			else{
				var str = "Form_ListRMALocation_Actions.php?actionmode=savestartendduration&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&rmadt_id="+rmadt_id;
				var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Sorry, you cannot do this process!");
		}
		else{
		document.getElementById('list_location').innerHTML = data[0];
		alert("End process done successfully!");
		document.getElementById('labeltodisplay').innerHTML = data[2];
		}
		//document.getElementById('labeltodisplay').innerHTML = data[2];
			}
			};
			 xhttp.open("GET", str, true);
             xhttp.send();
   }
   
}
function saveStartDuration(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start_date            = document.getElementById('start_date').value;
	var end_date              = document.getElementById('end_date').value;
	var start_time            = document.getElementById('start_time').value;
	var end_time              = document.getElementById('end_time').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	
			else{
				var str = "Form_ListRMALocation_Actions.php?actionmode=savestartduration&start_date="+start_date+"&end_date="+end_date+"&start_time="+start_time+"&end_time="+end_time+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&rmadt_id="+rmadt_id;
				var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("You already started the process!");
		}
		else{
	
		document.getElementById('list_location').innerHTML = data[0];
		alert("Start process done successfully!");
		document.getElementById('labeltodisplay').innerHTML = data[2];
		}
	    //document.getElementById('labeltodisplay').innerHTML = data[2];
			}
			};
			 xhttp.open("GET", str, true);
             xhttp.send();
   }
}
function chkRmadtApproved(reply){
		document.getElementById('rmadt_approved').value = reply;
}
function submitApproval(){
	var rmadt_approved           = document.getElementById('rmadt_approved').value;
	var rmadt_operatorSpareParts = document.getElementById('rmadt_operatorSpareParts').value;
	var rmadt_operatoraditionalcomments = document.getElementById('rmadt_operatoraditionalcomments').value;
	var rmadt_id                 = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	var engineers 			  = document.getElementById('engineers').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
	var str = "Form_ListRMALocation_Actions.php?actionmode=submitapproval&rmadt_approved="+rmadt_approved+"&rmadt_operatorSpareParts="+rmadt_operatorSpareParts+"&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&rmadt_operatoraditionalcomments="+rmadt_operatoraditionalcomments;
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[0];
		alert("Reply submitted successfully!");
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function submitQC(){
	var rmadt_qcduration      = document.getElementById('rmadt_qcduration').value;
	var rmadt_qcremark        = document.getElementById('rmadt_qcremark').value;
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	var rmadt_qcapproved      = document.getElementById('rmadt_qcapproved').value;
	
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=submitqc&rmadt_id="+rmadt_id+"&rmadt_qcduration="+rmadt_qcduration+"&rmadt_qcremark="+rmadt_qcremark+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&rmadt_qcapproved="+rmadt_qcapproved;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Sorry, QC process is not finished yet!");
		}
		else{
		document.getElementById('list_location').innerHTML = data[0];
		alert("Replied Successfully!");
		}
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function startQcProcess(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=startqcprocess&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("You already started the process!");
		}
		else{
			document.getElementById('list_location').innerHTML = data[0];
			alert("Started successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		}
		
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function endQcProcess(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=endqcprocess&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Sorry, you cannot perform this process right now!");
		 }
		 else{
			 document.getElementById('list_location').innerHTML = data[0];
			alert("Process Ended successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		 }
		 
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function chkQcQpproved(v){
	document.getElementById('rmadt_qcapproved').value = v;
}
function startEngProcess2(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=startengprocess2&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&search_rmadt_approved="+search_rmadt_approved;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Quotation not added or you already started the process!");
		}
		else{
			document.getElementById('list_location').innerHTML = data[0];
			alert("Process Started successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		}
		
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function endEngProcess2(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=endengprocess2&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&search_rmadt_approved="+search_rmadt_approved;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Please start the process!");
		}
		else{
			document.getElementById('list_location').innerHTML = data[0];
			alert("Process ended successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		}
		
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function startQcProcess2(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=startqcprocess2&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Sorry, you cannot do this process!");
		}
		else{
			document.getElementById('list_location').innerHTML = data[0];
			alert("Started successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		}
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function endQcProcess2(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=endqcprocess2&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location;
		var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		if(data[1] == 0){
			alert("Sorry, you cannot do this process!");
		}
		else{
			document.getElementById('list_location').innerHTML = data[0];
			alert("Ended successfully!");
			document.getElementById('labeltodisplay').innerHTML = data[2];
		}
	}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function addQuotation2(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	var rmadt_techquotation2  = document.getElementById('rmadt_techquotation2').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=addquotation2&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&rmadt_techquotation2="+rmadt_techquotation2+"&search_rmadt_approved="+search_rmadt_approved;
		var xhttp = new XMLHttpRequest();
	      xhttp.onreadystatechange = function() {
	      if (xhttp.readyState == 4 && xhttp.status == 200) {
		     var data = xhttp.responseText.split('[BRK]');
			 if(data[0] == 0){
				 alert("First process is not done and/or the current transaction is not refused!");
			 }
			 else{
				 document.getElementById('labeltodisplay').innerHTML = data[1];
				 document.getElementById('list_location').innerHTML = data[2];
			 }
			 }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function receiveRmaDt(){
	var rmadt_id              = document.getElementById('rmadt_id').value;
	var start                 = document.getElementById('start_par').value;
	var pagenumber            = document.getElementById('pagenumber_par').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var search_type           = document.getElementById('search_type').value;
	var search_location       = document.getElementById('search_location').value;
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var rmadt_DateReceived    = document.getElementById('rmadt_DateReceived').value;
	if(rmadt_id == ""){
		alert("Please choose a record!");
	}
	else{
		var str = "Form_ListRMALocation_Actions.php?actionmode=receivermadt&rmadt_id="+rmadt_id+"&start="+start+"&pagenumber="+pagenumber+"&from_date="+from_date+"&to_date="+to_date+"&search_type="+search_type+"&search_location="+search_location+"&search_rmadt_approved="+search_rmadt_approved+"&rmadt_DateReceived="+rmadt_DateReceived;
	    var xhttp = new XMLHttpRequest();
	      xhttp.onreadystatechange = function() {
	      if (xhttp.readyState == 4 && xhttp.status == 200) {
		     var data = xhttp.responseText.split('[BRK]');
			 if(data[0] == 0){
				 alert("RMA should be refused by the operator or Accepted by the Quality Control!");
			 }
			 else{
				 document.getElementById('list_location').innerHTML = data[1];
				 alert("Received Successfully!");
			 }
			 }
   };
    xhttp.open("GET", str, true);
    xhttp.send();
	}
}
function setEngineerOption(v){
	var str = "Form_ListRMALocation.php?engineeroption="+v;
	document.location.href = str;
}

function setEngineerCheck(){
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var from_date             = document.getElementById('from_date').value;
	var to_date               = document.getElementById('to_date').value;
	var engineerchecked		  = document.getElementById('engineerchecked').value;
	
	var str = "Form_ListRMALocation_Actions.php?actionmode=searchChecked&search_rmadt_approved="+search_rmadt_approved+"&from_date="+from_date+"&to_date="+to_date+"&engineerchecked="+engineerchecked+"&qcchecked=0&operatorchecked=0";
	var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[1];
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}

function setQcCheck(){
	var qcchecked = document.getElementById('qcchecked').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=searchQcChecked&qcchecked="+qcchecked+"&engineerchecked=0&operatorchecked=0";
	var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[1];
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}

function setOperatorCheck(){
	var operatorchecked = document.getElementById('operatorchecked').value;
	var str = "Form_ListRMALocation_Actions.php?actionmode=searchOperatorChecked&operatorchecked="+operatorchecked+"&qcchecked=0&engineerchecked=0";
	var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var data = xhttp.responseText.split('[BRK]');
		document.getElementById('list_location').innerHTML = data[1];
		}
   };
    xhttp.open("GET", str, true);
    xhttp.send();
}

function openRMADesc(rmadt_id, engineerchecked, rmadt_engrecieved, qcchecked, rmadt_qcrecieved, operatorchecked, rmadt_operatorrecieved){
	var search_rmadt_approved = document.getElementById('search_rmadt_approved').value;
	var user_engineer = document.getElementById('user_engineer').value;
	
	if(user_engineer==3)
		var str = "List_RMADescription.php?rmadt_id="+rmadt_id+"&engineerchecked=1&search_rmadt_approved="+search_rmadt_approved+"&rmadt_engrecieved=1&qcchecked="+qcchecked+"&rmadt_qcrecieved="+rmadt_qcrecieved+"&operatorchecked=-1&rmadt_operatorrecieved=-1";	
	else
		if(user_engineer==2)
			var str = "List_RMADescription.php?rmadt_id="+rmadt_id+"&engineerchecked=1&search_rmadt_approved="+search_rmadt_approved+"&rmadt_engrecieved=1&qcchecked="+qcchecked+"&rmadt_qcrecieved="+rmadt_qcrecieved+"&operatorchecked="+operatorchecked+"&rmadt_operatorrecieved="+rmadt_operatorrecieved;	
		else
			if(user_engineer==1)
				var str = "List_RMADescription.php?rmadt_id="+rmadt_id+"&engineerchecked="+engineerchecked+"&search_rmadt_approved="+search_rmadt_approved+"&rmadt_engrecieved="+rmadt_engrecieved+"&qcchecked=-1&rmadt_qcrecieved=-1&operatorchecked=-1&rmadt_operatorrecieved=-1";
		
	window.open(str, 'mywindow', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=600,top=60,left=100');
}

</script>

<title>RMA Location</title>
</head>
<body>

<input type='hidden' name='actionmode' id='actionmode' value='insert'>
<input type='hidden' name='RMA_Id' id='RMA_Id' value=''>
HERE;




echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
include_once("header.php");
echo" <tr><td  valign='top'>";

include_once("sidemenu.php");
echo"  </td></tr>";

echo" <tr style='height:16px;'>
		<td  valign='top' id='content-top'>
			<table border='0' cellpadding='0' cellspacing='0' style='table-layout:fixed; height:26px;' class='layout-width'>
			<tr style='height:16px;'>
				<td style='width:38px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>RMA Location</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";
	  

echo"<tr>
		<td  height='13'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				
				<td>";
	


echo"   </td></tr>";
echo"	</table>";
echo"</td></tr>";

$strt = $_SESSION['StartFinancial_Date'];
$end = $_SESSION['EndFinancial_Date'];
$curr_date = date("d/m/Y");

$query_setup  = "select base1, base2 from setup";
$result_setup = mysql_query($query_setup, $connection); 
$row_setup    = mysql_fetch_array($result_setup);
extract($row_setup);
$date = date("d/m/Y");

if($user_engineerqc == 1){
	$twidth = "700";
}
else{
	$twidth = "600";
}

echo "<input type='hidden' id='user_engineer' value='$user_engineer'>";
echo "<tr><td id='content-body' style='text-align: left'>
<table width=$twidth style='margin-left: 48px;'>
<tr>
<td style='font-size: 14px; font-weight: bold'>Search</td>
<td style='width: 240px;'><input type='text' name='search_location' id='search_location' style='width: 200px; height: 25px;' /> <span id='date_icon' style='display: none'><A HREF='#' onClick=\"displayCalendar(document.getElementById('search_location'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></span></td>
<td style='width: 240px;'><select name='search_type' id='search_type' style='width: 200px; height: 25px;' onchange=\"addDates()\">
<option value=''></option>
<option value='RMA_Ref'>RMA Ref</option>
<option value='Expected_Date'>Expected Date</option>
<option value='Received_Date'>Received Date</option>
<option value='Service_Center'>Location</option>
<option value='Project'>Project</option>
<option value='Client_Code'>Client Code</option>
<option value='Client_Name'>Client Name</option>
<option value='Remark'>Remark</option>
<option value='Engineer_Name'>Engineer Name</option>
<option value='Repair'>Repair</option>
<option value='Status'>Status</option>
<option value='Item_code'>Item Code</option>
<option value='Item_Description'>Item Description</option>
<option value='Serial_Number'>Serial Number</option>
</select></td>";
if($user_engineer == 1 && $engineeroption == ""){
	$selected1 = "selected = 'selected'";
}
else
if($engineeroption == 1){
	$selected1 = "selected = 'selected'";
}
else{
	$selected1 = "";
}
if($user_engineer == 3 && $engineeroption == ""){
	$selected2 = "selected = 'selected'";
}
else
if($engineeroption == 2){
	$selected2 = "selected = 'selected'";
}
else{
	$selected2 = "";
}
if($user_engineerqc == 1){
echo"<td style='vertical-align: top; text-align: right'><select name='engineeroption' id='engineeroption' style='width: 200px; height: 25px;' onchange=\"setEngineerOption(this.value)\">
<option value=1 $selected1>Engineer</option>
<option value=2 $selected2>Quality Control</option>
</select></td>";
}
echo"</tr>
</table>

<div style='height: 10px;'></div>";
$query_dates  = "select date_format(now(), '%d/%m/%Y') as fromdate, date_format(now(), '%d/%m/%Y') as todate from dual";
$result_dates = mysql_query($query_dates, $connection); 
$row_dates    = mysql_fetch_array($result_dates);
extract($row_dates);
echo "<div style='margin-left: 50px'>
<table width=1000>
<tr>
<td width=105 style='font-size: 14px; font-weight: bold'>From/To</td>
<td width=239><input type='text' name='from_date' id='from_date' style='width: 180px; height: 25px' value='$fromdate'  /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('from_date'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
<td width=210><input type='text' name='to_date' id='to_date' style='width: 180px; height: 25px;' value='$todate' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('to_date'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A></td>
<td><button onclick=\"searchRMALocation()\"><span><span>Search</span></span></button></td>
</tr>
</table>
</div>
";
$start_time = date("H:i:00");
$end_time = date("H:i:59");
echo "<input type='hidden' id='rmadt_id' value='' />";
echo "<div id='loader' style='height: 20px; text-align: center; '></div>";
//$curr_date = $curr_date." ".date("H:i:s");
if($engineeroption == "" && $user_engineer == 1) $engineeroption = 1;
if($engineeroption == "" && $user_engineer == 3) $engineeroption = 2;
if($engineeroption != ""){
	if($engineeroption == 1) $user_engineer = 1;
	if($engineeroption == 2) $user_engineer = 3;
}

if($user_engineer == 1 || $engineeroption == 1){
	/*echo "<fieldset style='width: 88%; margin: auto;'>
	<legend style='font-size: 14px; font-weight: bold'>Status</legend>
	<span style='font-size: 12px; font-weight: bold'>Status: </span>
	<select name='search_rmadt_approved' id='search_rmadt_approved' style='width: 200px;' onchange=\"searchStatus();\">
	<option value='-1'>All</option>
	<option value='0'>Not Approved By Operator</option>
	<option value='1'>Approved By Operator</option>
	<option value='2'>Refused By QC</option>
	</select>&nbsp;&nbsp;&nbsp;<span id='start_end_time' style='font-size: 12px; font-weight: bold; display: none;'><input type='hidden' id='start_date' name='start_date' value='$curr_date' style='width: 75px' /><input type='hidden' name='start_time' id='start_time' style='width: 65px' value='$start_time' /> <input type='hidden' id='end_date' name='end_date' value='$curr_date' style='width: 75px' /><input type='hidden' name='end_time' id='end_time' style='width: 65px' value='$end_time'>&nbsp;&nbsp; <button onclick=\"saveStartDuration()\"><span><span>Start Process</span></span></button> <button onclick=\"saveStartEndDuration()\"><span><span>End Process</span></span></button></span>";
	*/
	echo "<fieldset style='width: 88%; margin: auto;'>
	<legend style='font-size: 14px; font-weight: bold'>Status</legend>
	<span style='font-size: 12px; font-weight: bold'>Status: </span>
	<select name='search_rmadt_approved' id='search_rmadt_approved' style='width: 200px;' onchange=\"searchStatus();\">
	<option value='0'>Not Approved By Operator</option>
	<option value='1'>Approved By Operator</option>
	<option value='2'>Refused By QC</option>
	</select>&nbsp;&nbsp;&nbsp;
	<span style='font-size: 12px; font-weight: bold' id='checkspan'>Checked: </span>
	<select name='engineerchecked' id='engineerchecked' style='width: 200px; height: 25px;' onchange=\"setEngineerCheck();\">
	<option value='0'>Not Checked</option>
	<option value='1'>Checked</option>
	</select>&nbsp;&nbsp;&nbsp;";
	
	
	echo"<span id='start_end_time' style='font-size: 12px; font-weight: bold; display: none;'><input type='hidden' id='start_date' name='start_date' value='$curr_date' style='width: 75px' /><input type='hidden' name='start_time' id='start_time' style='width: 65px' value='$start_time' /> <input type='hidden' id='end_date' name='end_date' value='$curr_date' style='width: 75px' /><input type='hidden' name='end_time' id='end_time' style='width: 65px' value='$end_time'>&nbsp;&nbsp; <button onclick=\"saveStartDuration()\"><span><span>Start Process</span></span></button> <button onclick=\"saveStartEndDuration()\"><span><span>End Process</span></span></button></span>";
	echo "<br><span id='start_end_time2' style='display: none; font-size: 12px; font-weight: bold'><div style='height: 15px'></div>
	Quotation <input type='text' name='rmadt_techquotation2' id='rmadt_techquotation2' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"addQuotation2()\"><span><span>Add Quotation</span></span></button><br>
	<div style='height: 15px'></div>
	<button onclick=\"startEngProcess2()\"><span><span>Start Process 2</span></span></button> <button onclick=\"endEngProcess2()\"><span><span>End Process 2</span></span></button>
	</span>";
	echo"</fieldset>";
	echo "<div style='height: 20px'></div>";
	/*echo "<fieldset style='width: 88%; margin: auto;' id='chkupdatequotation'>
	<legend style='font-size: 14px; font-weight: bold'>Check Update & Add Quotation</legend>
	<button onclick=\"chkUpdate()\"><span><span>Click to check update</span></span></button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='font-size: 12px; font-weight: bold'>Quotation: </span><input type='text' name='Rmadt_techquotation' id='Rmadt_techquotation' style='width: 450px;' />&nbsp;&nbsp;<button onclick=\"updateQuotation()\"><span><span>Submit</span></span></button>
	<input type='hidden' id='check_update' value = 0/>
	</fieldset>";*/
	
	echo "<div style='height: 20px'></div>";
}
else{
	echo "<input type='hidden' name='Rmadt_techquotation' id='Rmadt_techquotation' style='width: 450px;' />
	<input type='hidden' id='check_update' value = 0/>
	<input type='hidden' id='search_rmadt_approved' name='search_rmadt_approved' />
	<input type='hidden' id='start_date' name='start_date' />
	<input type='hidden' id='end_date' name='end_date' />
	<input type='hidden' id='start_time' name='start_time' />
	<input type='hidden' id='end_time' name='end_time' />
	<input type='hidden' name='rmadt_techquotation2' id='rmadt_techquotation2' style='width: 500px' />";
}
if($user_engineer == 2){
	$query_engineers  = "select User_Name as userName, User_account as userAccount from ".$_SESSION['dbLabel'].".users where user_engineer = 1";
	//echo $query_engineers;
	$result_engineers = mysql_query($query_engineers, $connection);
	
	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='font-size: 12px; font-weight: bold' id='checkspan'>Status: </span>
	<select name='operatorchecked' id='operatorchecked' style='width: 200px; height: 25px;' onchange=\"setOperatorCheck();\">
	<option value='0'>All</option>
	<option value='1'>Waiting for Approval</option>
	</select>&nbsp;&nbsp;&nbsp;";

	/*echo "<fieldset style='width: 88%; margin: auto; font-size: 12px; font-weight: bold'>
	<legend style='font-size: 14px; font-weight: bold'>Spare Parts & Status Reply</legend>
	<input type='hidden' id='rmadt_approved' name='rmadt_approved' value='0' />
	<input type='radio' name='chk_rmadt_approved' id='chk_rmadt_approved' onclick=\"chkRmadtApproved('1')\" /> Approve&nbsp;&nbsp;<input type='radio' name='chk_rmadt_approved' id='chk_rmadt_refused' onclick=\"chkRmadtApproved('0')\" /> Refuse&nbsp;&nbsp;<input type='radio' name='chk_rmadt_approved' id='chk_rmadt_pending' onclick=\"chkRmadtApproved('')\" /> Waiting for reply&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Spare Parts <input type='text' name='rmadt_operatorSpareParts' id='rmadt_operatorSpareParts' style='width: 551px' maxlength=200 /> <br>
	&nbsp;Engineer: &nbsp;<select name='engineers' id='engineers'>";
	while($row_engineers = mysql_fetch_array($result_engineers)){
		extract($row_engineers);
		echo "<option value='$userAccount'>$userName</option>";
	}
	echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Additional Comments <input type='text' name='rmadt_operatoraditionalcomments' id='rmadt_operatoraditionalcomments' style='width: 551px;' />
	<button onclick=\"submitApproval()\"><span><span>Submit</span></span></button>
	<div style='height: 10px;'></div>
	Received Date <input type='text' name='rmadt_DateReceived' id='rmadt_DateReceived' value='$date' /> <A HREF='#' onClick=\"displayCalendar(document.getElementById('rmadt_DateReceived'),'dd/mm/yyyy',this);  return false; \" NAME=\"anchor1\" ID=\"anchor1\"><img src='./img/cal.gif' border=0 align=center></A> <button onclick=\"receiveRmaDt()\"><span><span>Receive</span></span></button>
	</fieldset>";*/
	echo "<div style='height: 15px'></div>";
}
else{
	echo "<input type='hidden' id='rmadt_approved' name='rmadt_approved' value='0' />
	<input type='hidden' name='chk_rmadt_approved' id='chk_rmadt_approved' onclick=\"chkRmadtApproved()\" />
	<input type='hidden' name='chk_rmadt_approved' id='chk_rmadt_refused' onclick=\"chkRmadtApproved('0')\" />
	<input type='hidden' name='rmadt_operatorSpareParts' id='rmadt_operatorSpareParts' style='width: 773px' maxlength=200 />
	<input type='hidden' name='rmadt_operatoraditionalcomments' id='rmadt_operatoraditionalcomments' style='width: 690px;' />";
}
if($user_engineer == 3 || $engineeroption == 2){
	echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style='font-size: 12px; font-weight: bold' id='checkspan'>Checked: </span>
	<select name='qcchecked' id='qcchecked' style='width: 200px; height: 25px;' onchange=\"setQcCheck();\">
	<option value='0'>Not Checked</option>
	<option value='1'>Checked</option>
	</select>&nbsp;&nbsp;&nbsp;";
	/*echo "<fieldset style='width: 88%; margin: auto; font-size: 12px; font-weight: bold'>
	<legend style='font-size: 14px; font-weight: bold'>Duration and Remarks</legend>
    <button onclick=\"startQcProcess()\"><span><span>Start Process</span></span></button> <button onclick=\"endQcProcess()\"><span><span>End Process</span></span></button>
	&nbsp;
	<button onclick=\"startQcProcess2()\"><span><span>Start Process 2</span></span></button> <button onclick=\"endQcProcess2()\"><span><span>End Process 2</span></span></button>
	<input type='hidden' name='rmadt_qcduration' id='rmadt_qcduration' style='width: 75px' /> <br><br>
	<input type='hidden' name='rmadt_qcapproved' id='rmadt_qcapproved' value='' /><input type='radio' name='chk_rmadt_qcapproved' id='chk_rmadt_qcapproved' onclick=\"chkQcQpproved(1)\"> Approve <input type='radio' name='chk_rmadt_qcapproved' id='chk_rmadt_qcrefuse' onclick=\"chkQcQpproved(0)\"> Refuse <input type='radio' name='chk_rmadt_qcapproved' id='chk_rmadt_qcnone' onclick=\"chkQcQpproved('')\"> None&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='rmadt_qcremark' id='rmadt_qcremark' style='width: 656px' /> <button onclick=\"submitQC()\"><span><span>Submit</span></span></button>
	</fieldset>";*/
	echo "<div style='height: 15px'></div>";
}
else{
	echo "<input type='hidden' name='rmadt_qcduration' id='rmadt_qcduration' style='width: 75px' />
	<input type='hidden' name='rmadt_qcremark' id='rmadt_qcremark' style='width: 700px' />
	<input type='hidden' name='rmadt_qcapproved' id='rmadt_qcapproved' value='' />
	<input type='hidden' name='chk_rmadt_qcapproved' id='chk_rmadt_qcapproved' onclick=\"chkQcQpproved(1)\"><input type='hidden' name='chk_rmadt_qcapproved' id='chk_rmadt_qcrefuse' onclick=\"chkQcQpproved(0)\">
	<input type='hidden' name='chk_rmadt_qcapproved' id='chk_rmadt_qcnone' onclick=\"chkQcQpproved('')\">";
}
echo "<div id='labeltodisplay'></div>";
echo"<div id='list_location'>";
drawRMALocation($connection, "", "", "", "", "", "", "", 0, 0, 0, 0);
echo"</div>		
</td></tr>";

echo" <tr height='30'><td align='center' id='content-bottom' ></td></tr>";
include("footer.php");	
echo" </table>  ";//end of last table menu





print <<<HERE


</body>
</html>

HERE;

?>