<?php


session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include("Forms_DataGrid_Reports.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");


	
print <<< HERE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

HERE;
 
//Read From Module Table
$querymodule=" Select ifNull(Module_Project,0) As Module_Project, ifNull(Module_Costcenter,0) As Module_CostCenter,IfNull(Module_RestrictProjectReport,0) As Module_RestrictProjectReport,ifnull(Module_RandomeSupplier,0) as Module_RandomeSupplier ".
             " From Module";
$resultmodule=mysql_query($querymodule,$connection) or die(mysql_error());
while($rowmodule=mysql_fetch_array($resultmodule)){
	extract($rowmodule);
}

$querylog=" select ifNull(FI_RepRestrictProject,0) As FI_RepRestrictProject, ifNull(FI_RepRestrictCostcenter,0) As FI_RepRestrictCostcenter, ".
		  " ifNull(FI_RepRestrictWarehouse,0) As FI_RepRestrictWarehouse ".
          " from ".$_SESSION['dbLabel'].".login where user_account='".$_SESSION['useraccount']."' and Upper(Login_Schema) = Upper('".$_SESSION['dbName']."') ";
$resultlog=mysql_query($querylog) or die(mysql_error());
while($rows=mysql_fetch_array($resultlog)){
	extract($rows);
}


$querysetup="select Module_AdditionalTaxes as ModuleAdditionalTax, ifNull(Module_Heatno,0) As Module_Heatno, ifnull(module_delivery,0) as module_delivery from module";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultsetup)){
  extract($rows);
}



//Projects List
$queryproject=" select distinct project.project_code, project_name ".
              " from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.project_code,project.project_code),'%') ".
			  " where user_account='".$_SESSION['useraccount']."'  and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ".
			  " and (loginstk.project_code is not null and loginstk.project_code != '') ".
			  " order by project.project_code";
$projectresult = mysql_query($queryproject,$connection) or die(mysql_error());
$projectexist  = mysql_num_rows($projectresult);	
if ($projectexist == 0 || $FI_RepRestrictProject == 0)
    $queryproject=" select distinct project_code, project_name from project order by project_code ";	  

$resultfromproject=mysql_query($queryproject,$connection) or die(mysql_error());
$resulttoproject  =mysql_query($queryproject,$connection) or die(mysql_error());

//Master Projects List
$querymasterproject=" select distinct project.project_code, project_name ".
					" from project left join ".$_SESSION['dbLabel'].".loginstk on project.project_code like concat(ifnull(loginstk.masterproject,project.project_code),'%') ".
					" where user_account='".$_SESSION['useraccount']."' and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."')  ".
					" and (loginstk.masterproject is not null and loginstk.masterproject != '') ".
					" order by project.project_code";
$masterprojectresult = mysql_query($querymasterproject,$connection) or die(mysql_error());
$masterprojectexist  = mysql_num_rows($masterprojectresult);	
if ($masterprojectexist == 0 || $FI_RepRestrictProject == 0)
    $querymasterproject=" select distinct project_code, project_name from project order by project_code ";	  

$resultfrommasterproject=mysql_query($querymasterproject,$connection) or die(mysql_error());
$resulttomasterproject  =mysql_query($querymasterproject,$connection) or die(mysql_error());
	
//Costcenter List
$querycostcent=" select distinct costcent.costcent_code, costcent_name ".
               " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(ifnull(loginstk.costcent_code,costcent.costcent_code),'%') ".
			   " where user_account='".$_SESSION['useraccount']."'  and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ".
			   " and (loginstk.costcent_code is not null and loginstk.costcent_code != '') ".
			   " order by costcent.costcent_code";
$costcentresult = mysql_query($querycostcent,$connection) or die(mysql_error());
$costcentexist  = mysql_num_rows($costcentresult);		  
if ($costcentexist == 0 || $FI_RepRestrictCostcenter == 0)
    $querycostcent=" select distinct costcent_code, costcent_name from costcent order by costcent_code ";			  
	
$resultfromcostcent=mysql_query($querycostcent,$connection) or die(mysql_error());
$resulttocostcent  =mysql_query($querycostcent,$connection) or die(mysql_error());

//Master Costcenter List
$querymastercostcent=" select distinct costcent.costcent_code, costcent_name ".
					 " from costcent left join ".$_SESSION['dbLabel'].".loginstk on costcent.costcent_code like concat(ifnull(loginstk.mastercostcenter,costcent.costcent_code),'%') ".
					 " where user_account='".$_SESSION['useraccount']."'  and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ".
					 " and (loginstk.mastercostcenter is not null and loginstk.mastercostcenter != '') ".
					 " order by costcent.costcent_code";
$mastercostcentresult = mysql_query($querymastercostcent,$connection) or die(mysql_error());
$mastercostcentexist  = mysql_num_rows($mastercostcentresult);		  
if ($mastercostcentexist == 0 || $FI_RepRestrictCostcenter == 0)
    $querymastercostcent=" select distinct costcent_code, costcent_name from costcent order by costcent_code ";			  
	
$resultfrommastercostcent=mysql_query($querymastercostcent,$connection) or die(mysql_error());
$resulttomastercostcent  =mysql_query($querymastercostcent,$connection) or die(mysql_error());

//Get Default Project
$querydflproject="select project_code as defaultproject from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and default_project=1  and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ";
$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  and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ";
$resultdflcostcent=mysql_query($querydflcostcent,$connection) or die(mysql_error());
while($rows=mysql_fetch_array($resultdflcostcent)){
	extract($rows);
}



//Item Groups List
$querygroup=" select distinct group_code,group_name ".
			" from grouping where group_code in (select group_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ) ".
			" order by group_code";
$resultgroup = mysql_query($querygroup,$connection) or die(mysql_error());
$groupexist   = mysql_num_rows($resultgroup);
if ($groupexist == 0)
	$querygroup="select distinct group_code,group_name from grouping order by group_code";
$resultfromgroup=mysql_query($querygroup,$connection) or die(mysql_error());
$resulttogroup=mysql_query($querygroup,$connection) or die(mysql_error());

//Item SubGroups List
$querysubgroup= " select distinct subgroup_code, subgroup_name ".
				" from subgroup where subgroup_code in (select subgroup_code from ".$_SESSION['dbLabel'].".loginstk where user_account='".$_SESSION['useraccount']."' and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ) ".
				" order by subgroup_code";
$resultsubgroup = mysql_query($querysubgroup,$connection) or die(mysql_error());
$subgroupexist   = mysql_num_rows($resultsubgroup);
if ($subgroupexist == 0)
	$querysubgroup="select distinct subgroup_code,subgroup_name from subgroup order by subgroup_code";
$resultfromsubgroup=mysql_query($querysubgroup,$connection) or die(mysql_error());
$resulttosubgroup=mysql_query($querysubgroup,$connection) or die(mysql_error());


//Warehouse List
$querywarehouse=" select distinct warehouse.warehouse_code, warehouse_name ".
				" from warehouse where warehouse_code in (select warehouse_code from ".$_SESSION['dbLabel'].".loginstk ".
				"                                         where user_account='".$_SESSION['useraccount']."'  and Upper(loginstk.company_name) = Upper('".$_SESSION['dbName']."') ".
				"                                         and (loginstk.warehouse_code is not null and loginstk.warehouse_code != '') ) ".
				" order by warehouse.warehouse_code";
$resultwh = mysql_query($querywarehouse,$connection) or die(mysql_error());
$whexist   = mysql_num_rows($resultwh);
if ($whexist == 0 || $FI_RepRestrictWarehouse == 0)
	$querywarehouse="select warehouse_code,warehouse_name from warehouse order by warehouse_code";
	
$resultfromwarehouse=mysql_query($querywarehouse,$connection) or die(mysql_error());
$resulttowarehouse  =mysql_query($querywarehouse,$connection) or die(mysql_error());

//Item Category List
$querycategory= " select distinct category_code, category_name ".
				" from category  ".
				" order by category_code";
$resultfromcategory=mysql_query($querycategory,$connection) or die(mysql_error());
$resulttocategory=mysql_query($querycategory,$connection) or die(mysql_error());


//Area List
$queryarea=" select distinct area_code, area_name from area order by area_code";
$resultfromarea=mysql_query($queryarea,$connection) or die(mysql_error());

//Client Rating List
$queryclientrating=" select distinct client_rating from clientrating order by client_rating";
$resultclientrating=mysql_query($queryclientrating,$connection) or die(mysql_error());

//Client Business Type List
$querybustype=" select distinct Client_BusinessType from clients where Client_BusinessType is not null and Client_BusinessType != '' order by Client_BusinessType";
$resultfrombustype=mysql_query($querybustype,$connection) or die(mysql_error());
$resulttobustype=mysql_query($querybustype,$connection) or die(mysql_error());

$queryjvtype="select type_name from jourtype order by type_name";
$resultjvtype=mysql_query($queryjvtype,$connection) or die(mysql_error());

$message = ereg_replace("'"," ",$message);
if (empty($mainaction)) $mainaction='insert';

if ((!isset($fromproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1 && $Module_RestrictProjectReport==1)
	$fromproject = $defaultproject;
//if ((!isset($frommasterproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1)
	//$frommasterproject = $defaultproject;	
if ((!isset($toproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1  && $Module_RestrictProjectReport==1)
	$toproject = $defaultproject;
//if ((!isset($tomasterproject)) && $Module_Project == 1 && $FI_RepRestrictProject == 1)
	//$tomasterproject = $defaultproject;		
if ((!isset($fromcostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	$fromcostcent = $defaultcostcent;	
//if ((!isset($frommastercostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	//$frommastercostcent = $defaultcostcent;	
if ((!isset($tocostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	$tocostcent = $defaultcostcent;	
//if ((!isset($tomastercostcent)) && $Module_CostCenter == 1 && $FI_RepRestrictCostcenter == 1)	
	//$tomastercostcent = $defaultcostcent;		
	

print <<< HERE

<html xmlns="http://www.w3.org/1999/xhtml">
<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"> 
<link rel="stylesheet" type="text/css" media="all" href="css-v2/style.css">
<script type="text/javascript" src="js/grid/jquery-1.9.1.js"></script>
<script language="JavaScript" src="CalendarPopup.js" ></script><!-- Date only with year scrolling -->
<script type="text/javascript" language="javascript">
var ledgertype = "LEDGERS";


 
<!--




function MoveLevel12(option) {
	var ob = document.form1.availgroupby;
	var leng = ob.options.length;
	
	var vSelectedOptionValue='';
	var vSelectedOptionName='';
	var vSelectedCount=0;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	while (ob.selectedIndex != -1)
    {
        if (ob.selectedIndex != -1) {
			vSelectedCount = vSelectedCount + 1;
			vSelectedOptionName  = ob.options[ob.selectedIndex].text;
			vSelectedOptionValue = ob.options[ob.selectedIndex].value;
		}	
        ob.options[ob.selectedIndex].selected = false;
    }

	if (vSelectedCount == 1) {
		if (option == 1) {
			document.form1.groupbylevel1name.value  = vSelectedOptionName;
			document.form1.groupbylevel1value.value = vSelectedOptionValue;
		}	
		else {
			document.form1.groupbylevel2name.value  = vSelectedOptionName;
			document.form1.groupbylevel2value.value = vSelectedOptionValue;
		}	
	}	
	else
		alert ('Not allowed multi selection for Level 1 and 2');
		
	
}

function RemoveLevel12(option) {
	var x = document.form1;
	
	if (option == 1) {
		x.groupbylevel1name.value = '';
		x.groupbylevel1value.value = '';
	}	
	else {
		x.groupbylevel2name.value = '';
		x.groupbylevel2value.value = '';
	}	
}

function showlistheatno(str){

	window.open('Select_HeatNo.php?heatno='+str,'mywindow','width=900,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}



function MoveLevel3() {
	var ob = document.form1.availgroupby;
	var leng = ob.options.length;
	var TargetElement = document.form1.assigngroupby.options;
	
	var vExists = 0;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	if(TargetElement[0] != null) {
		if (TargetElement[0].value=='') 
			TargetElement[0] = null;
	}			

		
	while (ob.selectedIndex != -1)
    {  
        if (ob.selectedIndex != -1) {
		
			vExists = 0;
			for(i=0; i < TargetElement.length; i++) {
				if (TargetElement[i].value == ob.options[ob.selectedIndex].value)
					vExists = 1;
			}
			
			if (vExists == 0)	
				TargetElement[TargetElement.length] = new Option(ob.options[ob.selectedIndex].text, ob.options[ob.selectedIndex].value);
		}	  

		ob.options[ob.selectedIndex].selected = false;
    }

	
}

function RemoveLevel3() {
	var ob = document.form1.assigngroupby;
	var leng = ob.options.length;
	
	if(ob.selectedIndex == -1) {
		alert('No selection is done.');
		return;
	}
	
	while (ob.selectedIndex != -1)
    {  
        if (ob.selectedIndex != -1) 
			  ob.options[ob.selectedIndex] = null;
    }
	
}

function select_alljvtypes() {
   
   var checkname;
   var x;
   for (var i=1; i <= document.form1.i.value; i++)
  {
    checkname='type'+i;
	
	x = document.getElementById(checkname);
	if (document.form1.alltypes.checked) {
		x.checked = true;
	}	
	else {
       	x.checked = false;
	}	
    
  }
  
  if (document.form1.alltypes.checked) {
     document.form1.exclude.checked = false;
     document.form1.exclude.disabled = true;
  }	 
  else
     document.form1.exclude.disabled = false;

}

function select_alldbtypes() {
   
   var checkname;
   var x;
   for (var i=1; i <= document.form1.i.value; i++)
  {
    checkname='debit'+i;
	
	x = document.getElementById(checkname);
	if (document.form1.alldebit.checked) {
		x.checked = true;
	}	
	else {
       	x.checked = false;
	}	
    
  }
  
}

function select_allcrtypes() {
   
   var checkname;
   var x;
   for (var i=1; i <= document.form1.i.value; i++)
  {
    checkname='credit'+i;
	
	x = document.getElementById(checkname);
	if (document.form1.allcredit.checked) {
		x.checked = true;
	}	
	else {
       	x.checked = false;
	}	
    
  }
  
} 

function SetLedger(Vcheck,Vobj){
	
	if (Vcheck.checked){ 
		Vobj.disabled=false;
	}
	else {
		Vobj.value='';
		Vobj.disabled=true;
	}
}


function showlistitem(str){

  window.open('select_item.php?item='+str,'mywindow','width=900,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistclient(str){

  window.open('select_client.php?item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistSupplier(str){

  window.open('select_supplier.php?item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function showlistsalesman(str){

  window.open('select_salesman.php?item='+str,'mywindow','width=850,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}




function showlistledger(str){

  var str1;
  for (var i=0; i < document.form1.accountno.length; i++)
  {
    if (document.form1.accountno[i].checked)
    {
      str1 = document.form1.accountno[i].value;
    }
  }

  
  window.open('select_accountno.php?item='+str+'&accountoption='+str1,'mywindow','width=720,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}


function ClearPage(){
	if (confirm ( "Are you sure you want to Clear Page?"))
	{
		ClearForm('All');
		x = document.form1;
		x.mainaction.value='insert';
		x.action='Form_ReportsOptions.php';
		x.submit();
	}	
}

function PostChanges() {
	x = document.form1;
	var vTempId   = x.templateid.value;
	var vMainMode = x.mainaction.value;
	//var result = CheckFields();
	var result = 1;
	
	varexclude = 0;
	if (x.exclude.checked)	varexclude = 1;	
		
	varalltypes = 0;
	if (x.alltypes.checked) varalltypes = 1;	
	varalldebit = 0;
	if (x.alldebit.checked) varalldebit = 1;	
	varallcredit = 0;
	if (x.allcredit.checked) varallcredit = 1;	
	
	//Getting Journal Types	
	var checkname, debitname, creditname, ledgername;
	var y,z,w,varjvtype,varjvdb,varjvcr,varledgers;
	
	varjvtype  = '';
	varjvdb    = '';
	varjvcr    = '';
	varledgers = '';
	
	for (var i=1; i <= x.i.value; i++)
	{
		checkname ='type'+i;
		debitname ='debit'+i;
		creditname='credit'+i;
		ledgername='ledger'+i;
		
		y = document.getElementById(checkname);
		z = document.getElementById(debitname);
		w = document.getElementById(creditname);
		m = document.getElementById(ledgername);
		
		if (varalltypes == 0 && y.checked) {
			if (varjvtype.length > 0) varjvtype += ",";
			varjvtype += y.value;
		}
			
		if (varalldebit == 0 && z.checked) {
			if (varjvdb.length > 0) varjvdb   += ",";
			varjvdb += z.value;
		}

		if (varallcredit == 0 && w.checked) {
			if (varjvcr.length > 0) varjvcr   += ",";
			varjvcr += w.value;
		}	
		
		if (m.value != '') {
			if (varledgers.length > 0) varledgers  += "-";
			varledgers += y.value+":"+m.value;
		}
		
	}
	
	
	//Getting Assigngroupby Values
	var ob = document.form1.assigngroupby;
	var seloptionsname = '';
	var seloptionsvalue = '';
	for (var i = 0; i < ob.options.length; i++) {
		if (seloptionsvalue.length > 0)
			seloptionsvalue += ",";
			
		if (seloptionsname.length > 0)
			seloptionsname += ",";	

        seloptionsvalue += ob.options[i].value;
		seloptionsname += ob.options[i].text;
    }
	
	
	
	if (result == 1) {
		if (confirm ( "Are you sure you want to Save changes?"))
		{
			x.btnPost.disabled = true;
			x.btnSearch.disabled = true;
			x.btnCancel.disabled = true;
			x.btnClear.disabled = true;
				
			x.action="Form_ReportsOptions_Actions.php?SMode="+vMainMode+"&STempId="+vTempId+"&SJvAlltypes="+varalltypes+
					 "&SJvAlldebit="+varalldebit+"&SJvAllcredit="+varallcredit+
			         "&SJvExclude="+varexclude+"&SJvTypes="+varjvtype+"&SJvdb="+varjvdb+"&SJvcr="+varjvcr+"&SJvLedgers="+varledgers+
					 "&SGroupbyLevel3Name="+seloptionsname+"&SGroupbyLevel3Value="+seloptionsvalue;
			x.submit();
		}
	}
	
}

function CancelRecord(){
	x = document.form1;
	var vTempId   = x.templateid.value;
	var vMainMode = x.mainaction.value;
	
	if (confirm ( "Are you sure you want to Cancel changes?"))
	{
		ClearForm('All');
		x.templateid.value = vTempId;
		x.mainaction.value='edit';
		x.action='Form_ReportsOptions.php';
		x.submit();
	}
    
}

function SearchForRef(){
    
	x = document.form1;
    win = window.open('Form_ReportsOptionsSearch.php', 'Form_ReportsOptionsSearch', 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=1040,height=450,top=100');		
	win.creator = self;
	win.focus();		
			
}

function CheckFields(){
  
    x = document.form1;
	
	var vReportName = x.reportname.value;
	var vmode  = x.mainaction.value;
	
	if (vReportName=='' )
	{
		alert("Report Name is mandatory!");
		x.reportname.focus();
		return 0;
	}
	
			
	
	else
		return 1 ;	
}

//All= All form; D= Detail Part
function ClearForm(Option){
    x = document.form1;
	
	if (Option == 'All') {
		x.templateid.value='';
		x.reportname.value='';
		x.templatename.value='';
		
		x.groupbylevel1value.value='';
		x.groupbylevel2value.value='';
		x.groupbylevel1name.value='';
		x.groupbylevel2name.value='';
		x.assigngroupby.value='';
		
		x.fromledger.value='';
		x.fromledgername.value='';
		x.toledger.value='';
		x.toledgername.value='';
		x.fromclient.value='';
		x.fromdesc.value='';
		x.toclient.value='';
		x.todesc.value='';

		x.fromsupplier.value='';
		x.fromsuppdesc.value='';
		x.tosupplier.value='';
		x.tosuppdesc.value='';
		x.fromsalesman.value='';
		x.fromsalesmandesc.value='';
		x.tosalesman.value='';
		x.tosalesmandesc.value='';

		x.fromitem.value='';
		x.fromitemdesc.value='';
		x.toitem.value='';
		x.toitemdesc.value='';
		x.fromwarehouse.value='';
		x.towarehouse.value='';

		x.fromgroup.value='';
		x.fromsubgroup.value='';
		x.togroup.value='';
		x.tosubgroup.value='';

		x.fromproject.value='';
		x.toproject.value='';
		x.fromcostcent.value='';
		x.tocostcent.value='';

		x.frommasterproject.value='';
		x.frommastercostcent.value='';
		x.tomasterproject.value='';
		x.tomastercostcent.value='';
		
		x.fromarea.value='';

		x.message.value='';
		x.mainaction.value = 'insert';
		x.isseloption.value='';
		x.formname.value='';
		
		x.alltypes.checked = false;
		x.alldebit.checked = false;
		x.allcredit.checked = false;
		x.exclude.checked = false;
		
	} 
}

function selectInvoices(){
	$('#displayInvoice').slideToggle();	
}

function SelectOptions(){
	if (!Array.indexOf) {
	  Array.prototype.indexOf = function (obj, start) {
		for (var i = (start || 0); i < this.length; i++) {
		  if (this[i] == obj) {
			return i;
		  }
		}
		return -1;
	  }
	}
	
	var x = document.form1;
	
	var vFormName = x.formname.value;
	var vReportOptions = '';
	
	var InValArray  = new Array(3,4,5,6,7,9,20,21,22,23);
	var InValArray1 = new Array(4,5,6,7,9,20,21,22,23);
	var InValArray2 = new Array(2,3,4,5,6,7,8,10,11,12,20,21,22,23,24,25,26);
	
	//Getting Assigngroupby Values
	var ob = document.form1.assigngroupby;
	var vGroupByOptions = '';
		
	//Remove All Data In The Parent Select List
	if (opener.RemoveOption)
		opener.RemoveOption('assigngroupby');
	
	
		
	for (var i = 0; i < ob.options.length; i++) {
		if (vGroupByOptions.length > 0)
			vGroupByOptions += ",";	

		if (vFormName == 'clientsales' || vFormName == 'yearlysales') {		
			vGroupByOptions += ob.options[i].text;
			opener.AddOption('assigngroupby', ob.options[i].text,  ob.options[i].value);
		} 
		else if (vFormName == 'aging' && InValArray.indexOf(ob.options[i].value) != -1 ) {
			vGroupByOptions += ob.options[i].text;
			opener.AddOption('assigngroupby', ob.options[i].text,  ob.options[i].value);
		}
		else if (vFormName == 'dailyreport' && InValArray1.indexOf(ob.options[i].value) != -1 ) {
			vGroupByOptions += ob.options[i].text;
			opener.AddOption('assigngroupby', ob.options[i].text,  ob.options[i].value);
		}
		else if ((vFormName == 'salesorder' || vFormName == 'purchaseorder') && InValArray2.indexOf(ob.options[i].value) != -1 ) {
			vGroupByOptions += ob.options[i].text;
			opener.AddOption('assigngroupby', ob.options[i].text,  ob.options[i].value);
		}		
			
	}
	
	
		
	if (vFormName == 'clientsales' || vFormName == 'yearlysales') {
				
		opener.document.form1.fromitem.value  	 = x.fromitem.value;
		opener.document.form1.toitem.value    	 = x.toitem.value;
		opener.document.form1.fromgroup.value 	 = x.fromgroup.value;
		opener.document.form1.togroup.value   	 = x.togroup.value;
		opener.document.form1.fromsubgroup.value = x.fromsubgroup.value;
		opener.document.form1.tosubgroup.value   = x.tosubgroup.value;
		opener.document.form1.fromproject.value  = x.fromproject.value;
		opener.document.form1.fromcostcent.value = x.fromcostcent.value;
		opener.document.form1.fromclient.value   = x.fromclient.value;
		opener.document.form1.toclient.value     = x.toclient.value;
		opener.document.form1.fromsupplier.value = x.fromsupplier.value;
		opener.document.form1.tosupplier.value   = x.tosupplier.value;
		opener.document.form1.fromsalesman.value = x.fromsalesman.value;
		opener.document.form1.tosalesman.value   = x.tosalesman.value;
		opener.document.form1.fromwarehouse.value = x.fromwarehouse.value;
		opener.document.form1.fromarea.value 	  = x.fromarea.value;
		opener.document.form1.subproj.value       = x.subproj.value;
		opener.document.form1.subcostcent.value   = x.subcostcent.value;
		//Sup 1
		
		if(opener.document.form1.fromsupplier1) opener.document.form1.fromsupplier1.value = x.fromsupplier1.value;
		if(opener.document.form1.tosupplier1) opener.document.form1.tosupplier1.value   = x.tosupplier1.value;		

		if(opener.document.form1.cltrating)
			opener.document.form1.cltrating.value   = x.cltrating.value;
		if(opener.document.form1.frombustype)
			opener.document.form1.frombustype.value = x.frombustype.value;
		if(opener.document.form1.tobustype)
			opener.document.form1.tobustype.value   = x.tobustype.value;
		if(opener.document.form1.fromcategory)
			opener.document.form1.fromcategory.value = x.fromcategory.value;
		if(opener.document.form1.tocategory)
			opener.document.form1.tocategory.value   = x.tocategory.value;
		
		opener.document.form1.groupbylevel1value.value 	 = x.groupbylevel1value.value;
		opener.document.form1.groupbylevel2value.value	 = x.groupbylevel2value.value;
		opener.document.form1.groupbylevel1name.value  	 = x.groupbylevel1name.value;
		opener.document.form1.groupbylevel2name.value  	 = x.groupbylevel2name.value;
		
		vReportOptions = 'Group by: ';
		if (x.groupbylevel1name.value != '' ) vReportOptions += x.groupbylevel1name.value + ',';
		if (x.groupbylevel2name.value != '' ) vReportOptions += x.groupbylevel2name.value + ',';
		if (vGroupByOptions != '' )           vReportOptions += vGroupByOptions + ',';
		vReportOptions = vReportOptions.substring(0, vReportOptions.length-1) + '\\n' + 'Filter by: \\n';
		
		if (x.fromitem.value != '')      vReportOptions += "-> Item From: "+ x.fromitem.value + "  To: "+ x.toitem.value +"\\n";
		if (x.fromgroup.value != '')     vReportOptions += "-> Group From: "+ x.fromgroup.value + "  To: "+ x.togroup.value +"\\n";
		if (x.fromsubgroup.value != '')  vReportOptions += "-> SubGroup From: "+ x.fromsubgroup.value + "  To: "+ x.tosubgroup.value +"\\n";
		if (x.fromcategory.value != '')  vReportOptions += "-> Category From: "+ x.fromcategory.value + "  To: "+ x.tocategory.value +"\\n";
		if (x.fromproject.value != '')   vReportOptions += "-> Project From: "+ x.fromproject.value + "\\n";
		if (x.fromcostcent.value != '')  vReportOptions += "-> Costcent From: "+ x.fromcostcent.value + "\\n";
		if (x.fromclient.value != '')    vReportOptions += "-> Client From: "+ x.fromclient.value + "  To: "+ x.toclient.value +"\\n";
		if (x.fromsupplier.value != '')  vReportOptions += "-> Supplier From: "+ x.fromsupplier.value + "  To: "+ x.tosupplier.value +"\\n";
		if (x.fromsupplier1.value != '')  vReportOptions += "-> Supplier1 From: "+ x.fromsupplier1.value + "  To: "+ x.tosupplier1.value +"\\n";
		if (x.fromsalesman.value != '')  vReportOptions += "-> Salesman From: "+ x.fromsalesman.value + "  To: "+ x.tosalesman.value +"\\n";
		if (x.fromwarehouse.value != '') vReportOptions += "-> Warehouse From: "+ x.fromwarehouse.value + "\\n";
		if (x.fromarea.value != '') 	 vReportOptions += "-> Area From: "+ x.fromarea.value + "\\n";
		if (x.cltrating.value != '') 	 vReportOptions += "-> Client Rating: "+ x.cltrating.value + "\\n";
		if (x.subproj.value != '') 	 	 vReportOptions += "-> Project Include: "+ x.subproj.value + "\\n";
		if (x.subcostcent.value != '') 	 vReportOptions += "-> Costcent Include: "+ x.subcostcent.value + "\\n";
		if (x.frombustype.value != '')   vReportOptions += "-> Client Business Type From: "+ x.frombustype.value + "  To: "+ x.tobustype.value +"\\n";
	
		
		opener.document.form1.reportoptions.value   = vReportOptions;
	}
	else if (vFormName == 'salesreport') {
				
		opener.document.form1.fromitem.value  	 = x.fromitem.value;
		opener.document.form1.toitem.value    	 = x.toitem.value;
		opener.document.form1.fromgroup.value 	 = x.fromgroup.value;
		opener.document.form1.togroup.value   	 = x.togroup.value;
		opener.document.form1.fromsubgroup.value = x.fromsubgroup.value;
		opener.document.form1.tosubgroup.value   = x.tosubgroup.value;
		opener.document.form1.fromproject.value  = x.fromproject.value;
		opener.document.form1.fromcostcent.value = x.fromcostcent.value;
		opener.document.form1.fromclient.value   = x.fromclient.value;
		opener.document.form1.toclient.value     = x.toclient.value;
		opener.document.form1.fromsupplier.value = x.fromsupplier.value;
		opener.document.form1.tosupplier.value   = x.tosupplier.value;
		opener.document.form1.fromsupplier1.value = x.fromsupplier1.value;
		opener.document.form1.tosupplier1.value   = x.tosupplier1.value;
		opener.document.form1.fromsalesman.value = x.fromsalesman.value;
		opener.document.form1.tosalesman.value   = x.tosalesman.value;
		opener.document.form1.fromwarehouse.value = x.fromwarehouse.value;
		opener.document.form1.fromarea.value 	  = x.fromarea.value;
		opener.document.form1.subproj.value       = x.subproj.value;
		opener.document.form1.subcostcent.value   = x.subcostcent.value;
		if(opener.document.form1.fromcategory)
			opener.document.form1.fromcategory.value = x.fromcategory.value;
		if(opener.document.form1.tocategory)
			opener.document.form1.tocategory.value   = x.tocategory.value;
		
		
		
		vReportOptions = 'Filter by: \\n';
		
		if (x.fromitem.value != '')      vReportOptions += "-> Item From: "+ x.fromitem.value + "  To: "+ x.toitem.value +"\\n";
		if (x.fromgroup.value != '')     vReportOptions += "-> Group From: "+ x.fromgroup.value + "  To: "+ x.togroup.value +"\\n";
		if (x.fromsubgroup.value != '')  vReportOptions += "-> SubGroup From: "+ x.fromsubgroup.value + "  To: "+ x.tosubgroup.value +"\\n";
		if (x.fromproject.value != '')   vReportOptions += "-> Project From: "+ x.fromproject.value + "\\n";
		if (x.fromcostcent.value != '')  vReportOptions += "-> Costcent From: "+ x.fromcostcent.value + "\\n";
		if (x.fromclient.value != '')    vReportOptions += "-> Client From: "+ x.fromclient.value + "  To: "+ x.toclient.value +"\\n";
		if (x.fromsupplier.value != '')  vReportOptions += "-> Supplier From: "+ x.fromsupplier.value + "  To: "+ x.tosupplier.value +"\\n";
		if (x.fromsupplier1.value != '')  vReportOptions += "-> Supplier1 From: "+ x.fromsupplier1.value + "  To: "+ x.tosupplier1.value +"\\n";
		if (x.fromsalesman.value != '')  vReportOptions += "-> Salesman From: "+ x.fromsalesman.value + "  To: "+ x.tosalesman.value +"\\n";
		if (x.fromwarehouse.value != '') vReportOptions += "-> Warehouse From: "+ x.fromwarehouse.value + "\\n";
		if (x.fromarea.value != '') 	 vReportOptions += "-> Area From: "+ x.fromarea.value + "\\n";
		if (x.subproj.value != '') 	 	 vReportOptions += "-> Project Include: "+ x.subproj.value + "\\n";
		if (x.subcostcent.value != '') 	 vReportOptions += "-> Costcent Include: "+ x.subcostcent.value + "\\n";
		if (x.fromcategory.value != '')  vReportOptions += "-> Category From: "+ x.fromcategory.value + "  To: "+ x.tocategory.value +"\\n";
	
		
		opener.document.form1.reportoptions.value   = vReportOptions;
	}
	else if (vFormName == 'salesorder' || vFormName == 'purchaseorder') {
				
		opener.document.form1.fromitem.value  	  = x.fromitem.value;
		opener.document.form1.toitem.value    	  = x.toitem.value;
		opener.document.form1.fromgroup.value 	  = x.fromgroup.value;
		opener.document.form1.togroup.value   	  = x.togroup.value;
		opener.document.form1.fromsubgroup.value  = x.fromsubgroup.value;
		opener.document.form1.tosubgroup.value    = x.tosubgroup.value;
		opener.document.form1.fromproject.value   = x.fromproject.value;
		opener.document.form1.fromcostcent.value  = x.fromcostcent.value;
		opener.document.form1.fromwarehouse.value = x.fromwarehouse.value;
		
		if (vFormName == 'salesorder') {
			opener.document.form1.fromclient.value   = x.fromclient.value;
			opener.document.form1.toclient.value     = x.toclient.value;
			opener.document.form1.fromsalesman.value = x.fromsalesman.value;
			opener.document.form1.tosalesman.value   = x.tosalesman.value;
		}	
		else if (vFormName == 'purchaseorder') {
			opener.document.form1.fromsupplier.value = x.fromsupplier.value;
			opener.document.form1.tosupplier.value   = x.tosupplier.value;
			opener.document.form1.fromheatno.value  	  = x.fromheatno.value;
			opener.document.form1.toheatno.value    	  = x.toheatno.value;
 
		}
		
		
		opener.document.form1.groupbylevel1value.value 	 = x.groupbylevel1value.value;
		opener.document.form1.groupbylevel2value.value	 = x.groupbylevel2value.value;
		opener.document.form1.groupbylevel1name.value  	 = x.groupbylevel1name.value;
		opener.document.form1.groupbylevel2name.value  	 = x.groupbylevel2name.value;
		
		vReportOptions = 'Group by: ';
		if (x.groupbylevel1name.value != '' ) vReportOptions += x.groupbylevel1name.value + ',';
		if (x.groupbylevel2name.value != '' ) vReportOptions += x.groupbylevel2name.value + ',';
		if (vGroupByOptions != '' )           vReportOptions += vGroupByOptions + ',';
		vReportOptions = vReportOptions.substring(0, vReportOptions.length-1) + '\\n' + 'Filter by: \\n';
		
		if (x.fromitem.value != '')      vReportOptions += "-> Item From: "+ x.fromitem.value + "  To: "+ x.toitem.value +"\\n";
		if (x.fromgroup.value != '')     vReportOptions += "-> Group From: "+ x.fromgroup.value + "  To: "+ x.togroup.value +"\\n";
		if (x.fromsubgroup.value != '')  vReportOptions += "-> SubGroup From: "+ x.fromsubgroup.value + "  To: "+ x.tosubgroup.value +"\\n";
		if (x.fromproject.value != '')   vReportOptions += "-> Project From: "+ x.fromproject.value + "\\n";
		if (x.fromcostcent.value != '')  vReportOptions += "-> Costcent From: "+ x.fromcostcent.value + "\\n";
		
		if (vFormName == 'salesorder') {
			if (x.fromclient.value != '')    vReportOptions += "-> Client From: "+ x.fromclient.value + "  To: "+ x.toclient.value +"\\n";
			if (x.fromsalesman.value != '')  vReportOptions += "-> Salesman From: "+ x.fromsalesman.value + "  To: "+ x.tosalesman.value +"\\n";
		}
		else if (vFormName == 'purchaseorder') {		
			if (x.fromsupplier.value != '')  vReportOptions += "-> Supplier From: "+ x.fromsupplier.value + "  To: "+ x.tosupplier.value +"\\n";
			if (x.fromheatno.value != '')      vReportOptions += "-> HeatNo From: "+ x.fromheatno.value + "  To: "+ x.toheatno.value +"\\n";
		}
		
		if (x.fromwarehouse.value != '') vReportOptions += "-> Warehouse From: "+ x.fromwarehouse.value + "\\n";
	
		
		
			
			
			
		opener.document.form1.reportoptions.value   = vReportOptions;
	}
	else if (vFormName == 'aging') {
		
				
		opener.document.form1.fromproject.value    = x.fromproject.value;
		opener.document.form1.fromcostcent.value   = x.fromcostcent.value;
		opener.document.form1.clientproject.value  = x.frommasterproject.value;
		opener.document.form1.clientcostcent.value = x.frommastercostcent.value;
		opener.document.form1.fromledger.value     = x.fromledger.value;
		opener.document.form1.toledger.value       = x.toledger.value;
		opener.document.form1.fromsalesman.value   = x.fromsalesman.value;
		opener.document.form1.tosalesman.value     = x.tosalesman.value;
		opener.document.form1.subproj.value        = x.subproj.value;
		opener.document.form1.subcostcent.value    = x.subcostcent.value;
		
		vReportOptions = 'Group by: ';
		
		if (InValArray.indexOf(x.groupbylevel1value.value) != -1 ) {
			opener.document.form1.groupbylevel1value.value 	 = x.groupbylevel1value.value;
			opener.document.form1.groupbylevel1name.value  	 = x.groupbylevel1name.value;
			if (x.groupbylevel1name.value != '' ) vReportOptions += x.groupbylevel1name.value + ',';
		}
		if (InValArray.indexOf(x.groupbylevel2value.value) != -1 ) {
			opener.document.form1.groupbylevel2value.value	 = x.groupbylevel2value.value;
			opener.document.form1.groupbylevel2name.value  	 = x.groupbylevel2name.value;
			if (x.groupbylevel2name.value != '' ) vReportOptions += x.groupbylevel2name.value + ',';
		}
		
		if (vGroupByOptions != '' )           vReportOptions += vGroupByOptions + ',';
		vReportOptions = vReportOptions.substring(0, vReportOptions.length-1) + '\\n' + 'Filter by: \\n';
		
	
		if (x.fromledger.value != '')         vReportOptions += "-> Ledger From: "+ x.fromledger.value + "  To: "+ x.toledger.value +"\\n";
		if (x.fromsalesman.value != '')       vReportOptions += "-> Salesman From: "+ x.fromsalesman.value + "  To: "+ x.tosalesman.value +"\\n";
		if (x.fromproject.value != '')        vReportOptions += "-> Project From: "+ x.fromproject.value + "\\n";
		if (x.fromcostcent.value != '')       vReportOptions += "-> Costcent From: "+ x.fromcostcent.value + "\\n";
		if (x.frommasterproject.value != '')  vReportOptions += "-> Master Project From: "+ x.frommasterproject.value +"\\n";
		if (x.frommastercostcent.value != '') vReportOptions += "-> Master Costcent From: "+ x.frommastercostcent.value + "\\n";
		if (x.subproj.value != '') 	 	 	  vReportOptions += "-> Project Include: "+ x.subproj.value + "\\n";
		if (x.subcostcent.value != '') 	 	  vReportOptions += "-> Costcent Include: "+ x.subcostcent.value + "\\n";
		
		
		opener.document.form1.reportoptions.value   = vReportOptions;
	}
	else if (vFormName == 'dailyreport') {
		
				
		opener.document.form1.fromproject.value    = x.fromproject.value;
		opener.document.form1.fromcostcent.value   = x.fromcostcent.value;
		opener.document.form1.clientproject.value  = x.frommasterproject.value;
		opener.document.form1.clientcostcent.value = x.frommastercostcent.value;
		opener.document.form1.fromledger.value     = x.fromledger.value;
		opener.document.form1.toledger.value       = x.toledger.value;
		opener.document.form1.subproj.value        = x.subproj.value;
		opener.document.form1.subcostcent.value    = x.subcostcent.value;
		
		
		vReportOptions = 'Group by: ';
		
		if (InValArray1.indexOf(x.groupbylevel1value.value) != -1 ) {
			opener.document.form1.groupbylevel1value.value 	 = x.groupbylevel1value.value;
			opener.document.form1.groupbylevel1name.value  	 = x.groupbylevel1name.value;
			if (x.groupbylevel1name.value != '' ) vReportOptions += x.groupbylevel1name.value + ',';
		}
		if (InValArray1.indexOf(x.groupbylevel2value.value) != -1 ) {
			opener.document.form1.groupbylevel2value.value	 = x.groupbylevel2value.value;
			opener.document.form1.groupbylevel2name.value  	 = x.groupbylevel2name.value;
			if (x.groupbylevel2name.value != '' ) vReportOptions += x.groupbylevel2name.value + ',';
		}
		
		
		
		if (vGroupByOptions != '' )           vReportOptions += vGroupByOptions + ',';
		vReportOptions = vReportOptions.substring(0, vReportOptions.length-1) + '\\n' + 'Filter by: \\n';
		
	
		if (x.fromledger.value != '')         vReportOptions += "-> Ledger From: "+ x.fromledger.value + "  To: "+ x.toledger.value +"\\n";
		if (x.fromproject.value != '')        vReportOptions += "-> Project From: "+ x.fromproject.value + "\\n";
		if (x.fromcostcent.value != '')       vReportOptions += "-> Costcent From: "+ x.fromcostcent.value + "\\n";
		if (x.frommasterproject.value != '')  vReportOptions += "-> Master Project From: "+ x.frommasterproject.value +"\\n";
		if (x.frommastercostcent.value != '') vReportOptions += "-> Master Costcent From: "+ x.frommastercostcent.value + "\\n";
		if (x.subproj.value != '') 	 	 	  vReportOptions += "-> Project Include: "+ x.subproj.value + "\\n";
		if (x.subcostcent.value != '') 	 	  vReportOptions += "-> Costcent Include: "+ x.subcostcent.value + "\\n";
		
		
		opener.document.form1.reportoptions.value   = vReportOptions;
		
		if (x.alltypes.checked)  opener.document.form1.alltypes.checked = true;
		if (x.alldebit.checked)  opener.document.form1.alltypesdebit.checked = true;
		if (x.allcredit.checked) opener.document.form1.alltypescredit.checked = true;
		
		//Getting Journal Types	
		var checkname, debitname, creditname, ledgername;
		var y,z,w,varjvtype,varjvdb,varjvcr,varledgers;
		
		varjvtype  = '';
		varjvdb    = '';
		varjvcr    = '';
		varledgers = '';
		
		for (var i=1; i <= x.i.value; i++)
		{
			checkname ='type'+i;
			debitname ='debit'+i;
			creditname='credit'+i;
			ledgername='ledger'+i;
			
			opener.document.getElementById(checkname).checked  = false;
			opener.document.getElementById(debitname).checked  = false;
			opener.document.getElementById(creditname).checked = false;
			opener.document.getElementById(ledgername).value   = '';
		}
		
		for (var i=1; i <= x.i.value; i++)
		{
			checkname ='type'+i;
			debitname ='debit'+i;
			creditname='credit'+i;
			ledgername='ledger'+i;
			
			y = document.getElementById(checkname);
			z = document.getElementById(debitname);
			w = document.getElementById(creditname);
			m = document.getElementById(ledgername);
			
			if (y.checked) {
				opener.document.getElementById(checkname).checked = true;
			}
				
			if (z.checked) {
				opener.document.getElementById(debitname).checked = true;
			}

			if (w.checked) {
				opener.document.getElementById(creditname).checked = true;
			}	
			
			if (m.value != '') {
				opener.document.getElementById(ledgername).value = m.value;
			}
			
		}
	}
	else if (vFormName == 'ListofTransaction'){
		
		opener.document.getElementById('delIds').value = document.getElementById('delIds').value;
	}
	self.close();
	
}

function addDelivery(){
	var tot = document.getElementById('totalrow').value;
	var idArr = '';
	for (i=0; i<tot; i++){
		if (document.getElementById('delId'+i).checked){
			var delId = document.getElementById('delId'+i).value;
			idArr = idArr+','+delId;
		}
	}
	document.getElementById('delIds').value = idArr;
}

function selectAll(){
	var tot = document.getElementById('totalrow').value;
	var idArr = '';
	
	if (document.getElementById('allIds').checked){
		for (i=0; i<tot; i++){
			document.getElementById('delId'+i).checked = true;
			var delId = document.getElementById('delId'+i).value;
			idArr = idArr+','+delId;
		}
		document.getElementById('delIds').value = idArr;
	} else {
		for (i=0; i<tot; i++){
			document.getElementById('delId'+i).checked = false;
		}
		document.getElementById('delIds').value = '';
		
	}
	
}

function RefreshPage(){
	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("[BRK]");
			document.getElementById('invoiceGrid').innerHTML=data[1];
		}
	  }
	var perpage 	= document.getElementById('perpage').value;
	var startrange 	= document.getElementById('startrange').value;
	
	var invFromdate = document.getElementById('invFromdate').value;
	var invTodate 	= document.getElementById('invTodate').value;
	var orderby 	= document.getElementById('orderby').value;
	
	xmlhttp.open("GET","Form_ReportsOptions_Action.php?mode=RefreshPage&perpage="+perpage+"&startrange="+startrange+"&invFromdate="+invFromdate+"&invTodate="+invTodate+"&orderby="+orderby,true);
	xmlhttp.send();
	
}

function SetNextPage(startrange,perpage){ 
	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("[BRK]");
			document.getElementById('invoiceGrid').innerHTML=data[1];
		}
	  }
	
	var invFromdate = document.getElementById('invFromdate').value;
	var invTodate 	= document.getElementById('invTodate').value;
	var orderby 	= document.getElementById('orderby').value;
	
	xmlhttp.open("GET","Form_ReportsOptions_Action.php?mode=RefreshPage&perpage="+perpage+"&startrange="+startrange+"&invFromdate="+invFromdate+"&invTodate="+invTodate+"&orderby="+orderby,true);
	xmlhttp.send();
}

function SetLastPage(perpage,totalrows){
	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("[BRK]");
			document.getElementById('invoiceGrid').innerHTML=data[1];
		}
	  }
	
	var result=totalrows % perpage;
	if (result == 0) result = perpage;
	startrange=totalrows-result;
	
	var invFromdate = document.getElementById('invFromdate').value;
	var invTodate 	= document.getElementById('invTodate').value;
	var orderby 	= document.getElementById('orderby').value;
	
	xmlhttp.open("GET","Form_ReportsOptions_Action.php?mode=RefreshPage&perpage="+perpage+"&startrange="+startrange+"&invFromdate="+invFromdate+"&invTodate="+invTodate+"&orderby="+orderby,true);
	xmlhttp.send();
}

function SetPrvPage(startrange,perpage){
	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("[BRK]");
			document.getElementById('invoiceGrid').innerHTML=data[1];
		}
	  }
	
	var invFromdate = document.getElementById('invFromdate').value;
	var invTodate 	= document.getElementById('invTodate').value;
	var orderby 	= document.getElementById('orderby').value;
	
	xmlhttp.open("GET","Form_ReportsOptions_Action.php?mode=RefreshPage&perpage="+perpage+"&startrange="+startrange+"&invFromdate="+invFromdate+"&invTodate="+invTodate+"&orderby="+orderby,true);
	xmlhttp.send();
}

function SetFirstPage(startrange,perpage){
	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("[BRK]");
			document.getElementById('invoiceGrid').innerHTML=data[1];
		}
	  }
	
	var invFromdate = document.getElementById('invFromdate').value;
	var invTodate 	= document.getElementById('invTodate').value;
	var orderby 	= document.getElementById('orderby').value;
	
	xmlhttp.open("GET","Form_ReportsOptions_Action.php?mode=RefreshPage&perpage="+perpage+"&startrange=0&invFromdate="+invFromdate+"&invTodate="+invTodate+"&orderby="+orderby,true);
	xmlhttp.send();
}

function showListProject(str){
	window.open('List_SorProject.php?frm=29&item='+str,'Project List', 'width=600px,height=600px');
}

function showlistCostcenter(str){
	window.open('List_SorCostcenter.php?frm=29&item='+str,'Costcenter List', 'width=600px,height=600px');
}
-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Reports Option Template</title>
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
	<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
}
a:link {
	text-decoration: none;
}
a:visited {
	text-decoration: none;
}
a:hover {
	text-decoration: none;
}
a:active {
	text-decoration: none;
}
.style1 {
	color: #FF0000;
	font-family: "Times New Roman", Times, serif;
	font-size: 20px;
}
.style8 {font-size: 11px; color: #999999; font-weight: bold; }
.style11 {font-size: 11px}
body {
	margin-top: 0px;
}

.divstyle {
	display:none;
	width:1090px;
	height:400px;
	position: absolute;
	z-index: 999;
	opacity: 1;
    filter: alpha(opacity=50);
	background-color: #e8e4e4;
    border: 3px solid gray;
	box-shadow: 5px 5px #0000008c;
	border-radius: 5px;
}

.datestyle {
	width: 80px;
    font-size: 12px;
    border-radius: 5px;
}
-->
</style>

<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
	<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>
	
	  <!--       Form Report Functions          -->
      <script type="text/javascript" src="report/js/jquery-1.9.1.js"></script>
      <script type="text/javascript" src="report/js/jquery-ui.min.js"></script>
      <script type="text/javascript" src="report/js/autocomplete.js"></script>
      <link type="text/css" href="report/js/autocomplete.css" rel="stylesheet">
      <link type="text/css" href="report/js/jquery-ui.css" rel="stylesheet">
   <!--     End  Form Report Functions          -->   
   
   
</head>
<body >


 
<script>
$(document).ready(function() {
	
 
    $('input[type=radio][name=accountno]').change(function() {
        if (this.value == '0') {
           ledgertype = "LEDGERS";
        }
        else if (this.value == '1') {
           ledgertype = "SUPPLIERS";
        }
		   else if (this.value == '2') {
           ledgertype = "CLIENTS";
        }
		   else if (this.value == '3') {
           ledgertype = "SALESMEN";
        }
    });
});
</script>


HERE;

echo "<form id='form1' name='form1' method='post' action=''>
		<input type='hidden' name='mainaction' value='$mainaction'>
		<input type='hidden' name='templateid' value='$templateid'>
		<input type='hidden' name='isseloption' value='$isseloption'>
		<input type='hidden' name='formname' value='$formname'>
		<input type='hidden' name='message' value='$message' size='200'>";

//echo '  <table height="534" border="0" align="center" width="100%" cellpadding=0>';
echo"<table cellpadding='0' cellspacing='0' border='0'  align='center' class='layout-width'>";
if ($isseloption != 1) {


	include_once("header.php");

	echo" <tr><td  valign='top'>";

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


	echo" <tr style='height:26px;'>
		<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:26px;'>
				<td style='width:38px; height:26px;'>&nbsp;</td>
				<td valign='middle' style='width:300px; height:26px;'><span class='title'>Reports Option Template</span></td>
				<td class='message' valign='middle' style='height:26px;'>".htmlspecialchars($message, ENT_QUOTES)."</td>
			</tr></table>
		</td>
	  </tr>";
	  
	echo"<tr>
		<td  height='34'  valign='top' id='content-top2'>
			<table border='0' cellpadding='0' cellspacing='0' class='layout-width'>
			<tr>
				<td width='30'  height='34'>&nbsp;</td>
				<td valign='middle' height='34' width='720px' align='left'>";

//if ($isseloption != 1) {
	echo" <button type='button' id='btnClear' name='btnClear' onclick='ClearPage();return false;' title='Clear Page'><span><span>Clear Page</span></span></button>";

	echo"   <button type='button' name='btnCancel' id='btnCancel'  ";//cancel
			if ($mainaction!='edit')
				echo " disabled ";
			echo" onclick='CancelRecord();return false;' title='Cancel Changes'><span><span>Cancel</span></span></button>";

	echo"   <button type='button' name='btnPost' id='btnPost'  ";//post
			//if (($actionmode=='' || $actionmode=='cancel') && $mainaction!='edit')
				//echo " disabled ";
			echo" onclick='PostChanges();return false;' title='Save Changes'><span><span>Save</span></span></button>";

	echo" <button type='button' id='btnSearch' name='btnSearch' onclick='SearchForRef();return false;' title='Search By Reference' ";
	if ($templateid != '') 
				echo " disabled ";
	echo"><span><span>Search</span></span></button>";
	
	
//}

//	else {
		echo" <button type='button' id='btnSelectOption' name='btnSelectOption' onclick='SelectOptions();return false;' title='Select Options'><span><span>Select Options</span></span></button>";
//} 
	if ($formname == 'ListofTransaction' && $module_delivery == 0)
		echo" <button type='button' id='btnselectInvoice' name='btnselectInvoice' onclick=\"selectInvoices();return false;\" title='Select Invoices'><span><span>Select Invoices</span></span></button>";
echo"	</td></tr></table>";
echo"</td></tr>";				
				
	/*  
echo '  <tr><td colspan="9" align="left" valign="top">';

include_once("MenuBar.php");

print <<< HERE
       </td>
      </tr>
      <tr><th height="30" colspan="9" align="left" valign="top"><span class="style3">Reports Option Template </span></th></tr>
	  <tr><td height="20" colspan="9" align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>

HERE;
*/


if (!isset($alltypes))  $alltypes = 1;
if (!isset($alldebit))  $alldebit = 1;
if (!isset($allcredit)) $allcredit = 1;

if ($templateid != '') {
	
	$query = " SELECT Template_Name, Report_Name, Groupby_Level1Value, Groupby_Level2Value, Groupby_Level3Value, Groupby_Level1Name, ".
			 " Groupby_Level2Name, LedgersPertype, JournalType_alltypes, JournalType_exclude, JournalType_types, JournalType_db, JournalType_cr, ".
			 " FromLedger_Number, ToLedger_Number, FromClient_Code, ToClient_Code, FromSupplier_Code, ToSupplier_Code, FromSalesman_Code, ".
			 " ToSalesman_Code, FromItem_Code, ToItem_Code, FromWarehouse_Code, ToWarehouse_Code, FromGroup_Code, ToGroup_Code, ".
			 " FromSubgroup_Code, ToSubgroup_Code, FromProject_Code, ToProject_Code, FromMasterProject_Code, ToMasterProject_Code, ".
			 " FromCostcent_Code, ToCostcent_Code, FromMasterCostcent_Code, ToMasterCostcent_Code, FromArea_Code, ToArea_Code,  ".
			 " AllTypesDebit, AllTypesCredit, LedgersPerType ".
			 " FROM ReportsOptions_Templates ".
			 " WHERE Template_Id = '".$templateid."'";
			 
			 
	//echo $query;
	$result=mysql_query($query,$connection) or die(mysql_error());
    $rows=mysql_fetch_array($result);
	
	$templatename       = $rows[0];
	$reportname         = $rows[1];
	$groupbylevel1value = $rows[2];
	$groupbylevel2value = $rows[3];
	$groupbylevel3value = $rows[4];
	$groupbylevel1name  = $rows[5];
	$groupbylevel2name  = $rows[6];
	$groupbylevel3name  = $rows[7];
	$alltypes  = $rows[8];
	$alldebit  = $rows[39];
	$allcredit = $rows[40];
	$exclude  = $rows[9];
	$journaltypes    = $rows[10];
	$journaltypes_db = $rows[11];
	$journaltypes_cr = $rows[12];
	$journalledgers  = $rows[41];
	
	
	$fromledger   = $rows[13];
	$toledger     = $rows[14];
	$fromclient   = $rows[15];
	$toclient     = $rows[16];
	$fromsupplier = $rows[17];
	$tosupplier   = $rows[18];
	$fromsalesman = $rows[19];
	$tosalesman   = $rows[20];
	$fromitem     = $rows[21];
	$toitem       = $rows[22];
	$fromwarehouse = $rows[23];
	$towarehouse   = $rows[24];
	$fromgroup     = $rows[25];
	$togroup       = $rows[26];
	$fromsubgroup  = $rows[27];
	$tosubgroup    = $rows[28];
	$fromproject   = $rows[29];
	$toproject     = $rows[30];
	$frommasterproject   = $rows[31];
	$tomasterproject     = $rows[32];
	$fromcostcent        = $rows[33];
	$tocostcent          = $rows[34];
	$frommastercostcent  = $rows[35];
	$tomastercostcent    = $rows[36];
	$fromarea            = $rows[37];
	
}

if ($orderby == '') $orderby = 1;
if ($invFromdate == '') $invFromdate = date('d/m/Y');
if ($invTodate == '') 	$invTodate 	 = date('d/m/Y');

echo"<tr><td id='content-body'>
<table border='0'  align='center' valign='top' width=100% class='tablecontent'>
   <tr bgcolor='#F7F7F7'><td valign='top' align='left' colspan='10'>";
echo '  <table height="534" border="0" align="center" width="100%" cellpadding=0>';   
echo "<tr><td><div id='displayInvoice' class = 'divstyle' >";
echo "<div style='height:50px;'>";
echo "<table align='center' cellpadding=2 cellspacing=2 width=970px>
		<col width=90px><col width=180px><col width=50px><col width=100px><col width=200px><col width=350px>";
echo "<tr>";
echo "<td><span class='style8'>From</span></td>";
echo "<td><input type='text' name='invFromdate' id='invFromdate' value='$invFromdate' class='datestyle' onchange=\"RefreshPage();\">
		<A HREF=\"#\" onClick=\"displayCalendar(document.form1.invFromdate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A>
	</td><td></td>";
echo "<td><span class='style8'>Order By</span></td>
	<td><select name='orderby' id='orderby' onchange=\"RefreshPage();\" style='border-radius: 5px; font-size: 11px;'>
			<option value='1' ".($orderby == '1'?'selected':'').">Reference</option>
			<option value='2' ".($orderby == '2'?'selected':'').">Date</option>
 	    </select></td><td></td></tr>";

echo "<tr>";
echo "<td><span class='style8'>To</span></td>";
echo "<td><input type='text' name='invTodate' id='invTodate' value='$invTodate' class='datestyle' onchange=\"RefreshPage();\">
		<A HREF=\"#\" onClick=\"displayCalendar(document.form1.invTodate,'dd/mm/yyyy',this); return false;\" NAME=\"anchor1\" ID=\"anchor1\"><image src='./img/cal.gif' border=0 align=center></image></A>
	</td><td></td>";
echo "<td colspan='3'></td></tr>";

echo "</table>";
echo "</div>";
echo "<div id='invoiceGrid' style='height:350px;overflow-y:scroll;overflow-x:hidden;'>";
 getInvoiceGrid ($invFromdate, $invTodate, $orderby, $startrange, $perpage, $connection);
 echo "</div>";
echo "</div></td></tr>";
echo" <tr height='25'>";
echo"   <td width='6%'  align='left' bgcolor='#F5F5F5' ><span class='style8'>Report</span></td>";
echo"   <td width='44%' bgcolor='#F5F5F5'><span class='style8'>";
echo"		<select name='reportname' id='reportname' style='width:200px;'>
				<option></option>";
			if ($reportname == 'inventory')
				echo"<option value='inventory' selected>Inventory</option>";
			else 	
				echo"<option value='inventory'>Inventory</option>";
				
			if ($reportname == 'clientsales')
				echo"<option value='clientsales' selected>Client Sales</option>";
			else 	
				echo"<option value='clientsales'>Client Sales</option>";	
				
			if ($reportname == 'yearlysales')
				echo"<option value='yearlysales' selected>Yearly Sales</option>";
			else 	
				echo"<option value='yearlysales'>Yearly Sales</option>";	
				
			if ($reportname == 'salesorder')
				echo"<option value='salesorder' selected>Sales Order</option>";
			else 	
				echo"<option value='salesorder'>Sales Order</option>";		
			
			if ($reportname == 'aging')
				echo"<option value='aging' selected>Aging</option>";
			else 	
				echo"<option value='aging'>Aging</option>";	
				
			if ($reportname == 'dailyreport')
				echo"<option value='dailyreport' selected>Daily Report</option>";
			else 	
				echo"<option value='dailyreport'>Daily Report</option>";		
				
			if ($reportname == 'trialbalance')
				echo"<option value='trialbalance' selected>Trial Balance</option>";
			else 	
				echo"<option value='trialbalance'>Trial Balance</option>";		
				
echo"		</select>";
echo"   </span></td>";	
if ($isseloption != 1) {	
	echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Template Name: </span><input type='text' id='templatename' name='templatename' value='$templatename' maxlength='100' style='width:200px;'></td>";
} else {
	echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span><input type='hidden' id='templatename' name='templatename' value=''></td>";
}	
echo" </tr>";

echo" <tr><td colspan='7'>";
echo" 	<table border='0' align='left' width='100%' cellpadding=0 cellspacing=1>";

echo"	 <tr>";
echo"   	<td width='45%' height='19' colspan='3' bgcolor='#F5F5F5'><span class='style8'>Group By</span></td>";
echo"   	<td width='30%' align='left' bgcolor='#F5F5F5' ><span class='style8'>";
echo" 		  <label><input name='alltypes' type='checkbox' id='alltypes' value='1' onclick='select_alljvtypes();' ";  echo ($alltypes==1)?"checked":'';  echo "/>"; echo " All </label>&nbsp;&nbsp;";
echo" 		  <label><input name='alldebit' type='checkbox' id='alldebit' value='1' onclick='select_alldbtypes();' ";  echo ($alldebit==1)?"checked":'';  echo "/>"; echo " All </label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
echo" 		  <label><input name='allcredit' type='checkbox' id='allcredit' value='1' onclick='select_allcrtypes();' ";  echo ($allcredit==1)?"checked":'';  echo "/>"; echo " All </label>&nbsp;&nbsp;&nbsp;";
echo"		  <label><input name='exclude' type='checkbox' id='exclude' value='1' "; echo ($exclude==1)?"checked ":'';  echo ($alltypes==1)?"disabled ":'';  echo "/>"; echo" Exclude </label></span>";
echo"       </td>";
//echo"  	 	<td width='20%' height='19' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" 	 </tr>";

echo"    <tr>";
echo"  		<td width='15%' valign='top' bgcolor='#F5F5F5' ><span class='style8'><label>";
echo"			<select name='availgroupby' multiple='multiple' size='8'>    
					<option value='1' name='Client'>Client</option>     
					<option value='2' name='Supplier'>Supplier</option>
					<option value='3' name='Salesman'>Salesman</option>
					<option value='20' name='Transaction Project(Parent)'>Transaction Project(Parent)</option>
					<option value='4' name='Transaction Project(Detail)'>Transaction Project(Detail)</option>
					<option value='21' name='Archieve Project(Parent)'>Archieve Project(Parent)</option>
					<option value='5' name='Archieve Project(Detail)'>Archieve Project(Detail)</option>
					<option value='22' name='Transaction Costcenter(Parent)'>Transaction Costcenter(Parent)</option>
					<option value='6' name='Transaction Costcenter(Detail)'>Transaction Costcenter(Detail)</option>
					<option value='23' name='Archieve Costcenter(Parent)'>Archieve Costcenter(Parent)</option>
					<option value='7' name='Archieve Costcenter(Detail)'>Archieve Costcenter(Detail)</option>
					<option value='24' name='Warehouse(Parent)'>Warehouse(Parent)</option>
					<option value='8' name='Warehouse(Detail)'>Warehouse(Detail)</option>
					<option value='9' name='Business Type'>Business Type</option>
				</select>";
echo"   	</td>";

echo"  		<td width='15%' valign='middle' bgcolor='#F5F5F5' >";
echo"   		<div style='text-align: center;' class='style8'>Level 1 <input type='button' name='btnSelLevel1' value=' > ' onClick='MoveLevel12(1);' title='Add'>  <input type='button' name='btnUnSelLevel1' value=' < ' onClick='RemoveLevel12(1);' title='Remove'></div><br>";
echo"   		<div style='text-align: center;' class='style8'>Level 2 <input type='button' name='btnSelLevel2' value=' > ' onClick='MoveLevel12(2);' title='Add'>  <input type='button' name='btnUnSelLevel2' value=' < ' onClick='RemoveLevel12(2);' title='Remove'></div><br>";
echo"   		<div style='text-align: center;' class='style8'>Level 3 <input type='button' name='btnSelLevel3' value=' > ' onClick='MoveLevel3();'   title='Add'>  <input type='button' name='btnUnSelLevel3' value=' < ' onClick='RemoveLevel3();'     title='Remove'></div>";
echo"   	</td>";

echo"  		<td width='20%' align='left' valign='top' bgcolor='#F5F5F5' >";
echo"   		<span class='style8'><input type='hidden' name='groupbylevel1value' value='$groupbylevel1value' style='width:165px;'></span>";
echo"   		<span class='style8'><input type='hidden' name='groupbylevel2value' value='$groupbylevel2value' style='width:165px;'></span>";
echo"   		<span class='style8'><input type='text' name='groupbylevel1name' value='$groupbylevel1name' style='width:165px;'></span><br>";
echo"   		<span class='style8'><input type='text' name='groupbylevel2name' value='$groupbylevel2name' style='width:165px;'></span><br>";
echo"   		<span class='style8'>
				<select name='assigngroupby' multiple='multiple' size='5' style='width:171px;'>  ";  
			if ($groupbylevel3value !=''){
				$level3values = explode(",", $groupbylevel3value);
				$level3names  = explode(",", $groupbylevel3name);
				
				$k = 0;
				foreach ($level3values as $level3value) {
					$level3names  = explode(",", $groupbylevel3name);
					echo"<option value='$level3value' name='$level3names[$k]'>$level3names[$k]</option>";
					
					$k = $k + 1;
				}

			
			}
			else
				echo"<option value='' name=''></option>";
				
echo"			</select></span>";
echo"   	</td>";

echo"   	<td width='50%' valign='top' bgcolor='#F5F5F5'><div style='overflow:auto; height:130px; width:360px;' ><table border='0'>";
		
$i = 0;
$k = 0;
while($jvtype=mysql_fetch_row($resultjvtype)){
    $i = $i + 1;
    $type  = 'type'.$i;
    $$type = $jvtype[0];
	
	$debit  = 'debit'.$i;
	$credit = 'credit'.$i;
	$ledger = 'ledger'.$i;
	
	$JvSelected = '';
	$JvDbSelected = '';
	$JvCrSelected = '';
	
	
	if ($journaltypes != '' && $alltypes != 1) {
		$pos = strrpos($journaltypes, $jvtype[0]);
		//echo $pos;
		if ($pos !== false) { 
			$JvSelected = ' checked ';
		}
	}
	else if ($alltypes == 1) {
		$JvSelected   = ' checked ';
	}
	
	if ($journaltypes_db != '' && $alldebit != 1) {
		$pos = strrpos($journaltypes_db, $jvtype[0]);
	
		if ($pos !== false) { 
			$JvDbSelected = ' checked ';
		}
	}
	else if ($alldebit == 1) {
		$JvDbSelected = ' checked ';
	}
	
	if ($journaltypes_cr != '' && $allcredit != 1) {
		$pos = strrpos($journaltypes_cr, $jvtype[0]);
	
		if ($pos !== false) { 
			$JvCrSelected = ' checked ';
		}
	}
	else if ($allcredit == 1) {
		$JvCrSelected = ' checked ';
	}
	
	
	if ($journalledgers != ''){
		$trims = explode('-', $journalledgers);

		$k = 0;
		foreach ($trims as $trim) {
			$ledgers  = explode(":", $trim);
			
			if ($ledgers[0] == $jvtype[0])
				$$ledger = $ledgers[1];
					
			$k = $k + 1;
		}
	}
	
	
			
    echo"<tr bgcolor='E8E8E8'>";
    echo"<td width='50px;'><span class='style8'><label><input type='checkbox' name='$type' id='$type' value='".$$type."' $JvSelected onclick='SetLedger(this,$ledger)' /> $jvtype[0] </label></span></td>";
	echo"<td width='70px;'><span class='style8'><label><input type='checkbox' name='$debit' id='$debit' value='".$$type."' $JvDbSelected /> Debit </label></span></td>";
	echo"<td width='70px;'><span class='style8'><label><input type='checkbox' name='$credit' id='$credit' value='".$$type."' $JvCrSelected /> Credit </label></span></td>";
	echo"<td width='140px;'><span class='style8'><label><input type='text' style='width:130px; height:20' name='".$ledger."' id='$ledger' value='".$$ledger."'></label></span></td>";
	echo"</tr>";
}
echo "		<input type='hidden' name='i' value='$i'>";
echo "		</table></div>";   
echo"   	</td>";		

		
//echo"   	<td width='20%' colspan='2' align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";		

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



echo" <tr>";
echo"   <td colspan='7' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr height='20'>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Ledger No. / Name</span>";
echo"   <span class='style8'><label>";
		if ($accountno=="0" || $accountno=="")
           echo "<input name='accountno' type='radio' value='0' checked />";
		else
			echo "<input name='accountno' type='radio' value='0' />";
			
		echo "All</label></span>";
echo"   <span class='style8'><label>";
		if ($accountno=="1")
           echo "<input name='accountno' type='radio' value='1' checked />";
		else
			echo "<input name='accountno' type='radio' value='1' />";
			
		echo "Suppliers</label></span>";
echo"   <span class='style8'><label>";
		if ($accountno=="2" )
           echo "<input name='accountno' type='radio' value='2' checked />";
		else	   
		   echo "<input name='accountno' type='radio' value='2' />";
		   
		echo "Clients</label></span>";		
echo"   <span class='style8'><label>";
		if ($accountno=="3" )
           echo "<input name='accountno' type='radio' value='3' checked />";
		else	
		   echo "<input name='accountno' type='radio' value='3' />";
		echo "Salesmen </label></span></td>";

echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Client Code / Description</span></td>";
echo" </tr>";



echo" <tr>";	  
echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='44%' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>


<!-- 	   -->
<!-- old  showlistledger(1) -->
        <input name='fromledger' type='text' id='fromledger' size='15' value='".$fromledger."' 
		
	  tag='primarykey'
  
	 onfocus=\"_AutoCompleteData(event,this.id,'fromledger','fromledgername',ledgertype,'toledger','toledgername');\"
     onkeyup=\"_AutoCompleteData(event,this.id,'fromledger','fromledgername',ledgertype,'toledger','toledgername');\"
     onkeydown=\"_Check_EnterPressed(event,this.id,'fromledgername','primarykey',ledgertype,'toledger','toledgername');\"	
     onblur = \"return _CHECKISVALID(event,this.id,'fromledgername','primarykey',ledgertype,'toledger','toledgername')\" 
 
 
	 
       
		/>
 
        <input name='fromledgername' type='text' id='fromledgername' size='39' value='".$fromledgername."'
        tag='description'

       onfocus=\"_AutoCompleteData(event,this.id,'fromledger','fromledgername',ledgertype,'toledger','toledgername');\" 	
       onkeyup=\"_AutoCompleteData(event,this.id,'fromledger','fromledgername',ledgertype,'toledger','toledgername');\" 
	   onkeydown=\"_Check_EnterPressed(event,this.id,'fromledger','description',ledgertype,'toledger','toledgername');\"  
       onblur = \"return _CHECKISVALID(event,this.id,'fromledger','description',ledgertype,'toledger','toledgername')\" 
 

		/>
		
<!--     -->
        </label> 
    	</span>
        <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Ledger From ' 
        onClick=\"_Check_EnterPressed(event,'fromledger','fromledgername','primarykey',ledgertype,'toledger','toledgername','btn');\" 
		><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";			 

echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";		
echo"   <td width='44%' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='fromclient' type='text' id='fromclient' size='15' value='".$fromclient."' 
		
tag='primarykey'
onfocus=\"_AutoCompleteData(event,this.id,'fromclient','fromdesc','CLIENTS','toclient','todesc');\"
onkeyup=\"_AutoCompleteData(event,this.id,'fromclient','fromdesc','CLIENTS','toclient','todesc');\"
onkeydown=\"_Check_EnterPressed(event,this.id,'fromdesc','primarykey','CLIENTS','toclient','todesc');\"
onblur = \"return _CHECKISVALID(event,this.id,'fromdesc','primarykey','CLIENTS','toclient','todesc')\" 			
		
		
		
		/>
        <input name='fromdesc' type='text' id='fromdesc' size='39' value='".$fromdesc."'


tag='description'
onfocus=\"_AutoCompleteData(event,this.id,'fromclient','fromdesc','CLIENTS','toclient','todesc');\" 	  
onkeyup=\"_AutoCompleteData(event,this.id,'fromclient','fromdesc','CLIENTS','toclient','todesc');\" 
onkeydown=\"_Check_EnterPressed(event,this.id,'fromclient','description','CLIENTS','toclient','todesc');\"
onblur = \"return _CHECKISVALID(event,this.id,'fromclient','description','CLIENTS','toclient','todesc')\" 


		/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Client From ' 
             
			 onClick=\"_Check_EnterPressed(event,'fromclient','fromdesc','primarykey','CLIENTS','toclient','todesc','btn');\" 
			 ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
echo" </tr>";
   

echo" <tr>";	  
echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='44%' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
		<input name='toledger' type='text' id='toledger' size='15' value='".$toledger."'

 tag='primarykey'
  onfocus=\"_AutoCompleteData(event,this.id,'toledger','toledgername',ledgertype);\"
  onkeyup=\"_AutoCompleteData(event,this.id,'toledger','toledgername',ledgertype);\"
  onkeydown=\"_Check_EnterPressed(event,this.id,'toledgername','primarykey',ledgertype);\"	 
  onblur = \"return _CHECKISVALID(event,this.id,'toledgername','primarykey',ledgertype,)\"   


	  />
        <input name='toledgername' type='text' id='toledgername' size='39' value='".$toledgername."' 
		
		
		  tag='description'
   onfocus=\"_AutoCompleteData(event,this.id,'toledger','toledgername',ledgertype);\" 
   onkeyup=\"_AutoCompleteData(event,this.id,'toledger','toledgername',ledgertype);\" 
   onkeydown=\"_Check_EnterPressed(event,this.id,'toledger','description',ledgertype);\"
   onblur = \"return _CHECKISVALID(event,this.id,'toledger','description',ledgertype,)\"    
   
	   
	   
		/>
		</label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Ledger To ' 
             onClick=\"_Check_EnterPressed(event,'toledger','toledgername','primarykey',ledgertype,'undefined','undefined','btn');\"
			 '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";


echo"   <td width='6%' align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";	
echo"   <td width='44%' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='toclient' type='text' id='toclient' size='15' value='".$toclient."' 
		
  tag='primarykey'
  onfocus=\"_AutoCompleteData(event,this.id,'toclient','todesc','CLIENTS');\"
  onkeyup=\"_AutoCompleteData(event,this.id,'toclient','todesc','CLIENTS');\"
  onkeydown=\"_Check_EnterPressed(event,this.id,'todesc','primarykey','CLIENTS');\"
  onblur = \"return _CHECKISVALID(event,this.id,'todesc','primarykey','CLIENTS',)\"   	
		
		/>
        <input name='todesc' type='text' id='todesc' size='39' value='".$todesc."'

tag='description'
   onfocus=\"_AutoCompleteData(event,this.id,'toclient','todesc','CLIENTS');\" 
   onkeyup=\"_AutoCompleteData(event,this.id,'toclient','todesc','CLIENTS');\" 
   onkeydown=\"_Check_EnterPressed(event,this.id,'toclient','description','CLIENTS');\"
   onblur = \"return _CHECKISVALID(event,this.id,'toclient','description','CLIENTS',)\"   

		/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Client To ' 
            
onClick=\"_Check_EnterPressed(event,'toclient','todesc','primarykey','CLIENTS','undefined','undefined','btn');\"			
			><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>"; 
echo" </tr>";

echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Supplier Code / Description</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Salesman Code / Description</span></td>";
echo" </tr>";



echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='44%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='fromsupplier' type='text' id='fromsupplier' size='15' value='".$fromsupplier."'
tag='primarykey'
onfocus=\"_AutoCompleteData(event,this.id,'fromsupplier','fromsuppdesc','SUPPLIERS','tosupplier','tosuppdesc');\"
onkeyup=\"_AutoCompleteData(event,this.id,'fromsupplier','fromsuppdesc','SUPPLIERS','tosupplier','tosuppdesc');\"
onkeydown=\"_Check_EnterPressed(event,this.id,'fromsuppdesc','primarykey','SUPPLIERS','tosupplier','tosuppdesc');\"
onblur = \"return _CHECKISVALID(event,this.id,'fromsuppdesc','primarykey','SUPPLIERS','tosupplier','tosuppdesc')\" 	 

		/>
        <input name='fromsuppdesc' type='text' id='fromsuppdesc' size='39' value='".$fromsuppdesc."' 
tag='description'
onfocus=\"_AutoCompleteData(event,this.id,'fromsupplier','fromsuppdesc','SUPPLIERS','tosupplier','tosuppdesc');\" 	  
onkeyup=\"_AutoCompleteData(event,this.id,'fromsupplier','fromsuppdesc','SUPPLIERS','tosupplier','tosuppdesc');\" 
onkeydown=\"_Check_EnterPressed(event,this.id,'fromsupplier','description','SUPPLIERS','tosupplier','tosuppdesc');\"
onblur = \"return _CHECKISVALID(event,this.id,'fromsupplier','description','SUPPLIERS','tosupplier','tosuppdesc')\" 
		
		/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Supplier From ' 
             onClick=\"_Check_EnterPressed(event,'fromsupplier','fromsuppdesc','primarykey','SUPPLIERS','tosupplier','tosuppdesc','btn');\" 
			 ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";

echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";		
echo"   <td width='44%' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='fromsalesman' type='text' id='fromsalesman' size='15' value='".$fromsalesman."'

tag='primarykey'
onfocus=\"_AutoCompleteData(event,this.id,'fromsalesman','fromsalesmandesc','SALESMEN','tosalesman','tosalesmandesc');\"
onkeyup=\"_AutoCompleteData(event,this.id,'fromsalesman','fromsalesmandesc','SALESMEN','tosalesman','tosalesmandesc');\"
onkeydown=\"_Check_EnterPressed(event,this.id,'fromsalesmandesc','primarykey','SALESMEN','tosalesman','tosalesmandesc');\"
onblur = \"return _CHECKISVALID(event,this.id,'fromsalesmandesc','primarykey','SALESMEN','tosalesman','tosalesmandesc')\" 


		/>
        <input name='fromsalesmandesc' type='text' id='fromsalesmandesc' size='39' value='".$fromsalesmandesc."'

tag='description'
onfocus=\"_AutoCompleteData(event,this.id,'fromsalesman','fromsalesmandesc','SALESMEN','tosalesman','tosalesmandesc');\" 	  
onkeyup=\"_AutoCompleteData(event,this.id,'fromsalesman','fromsalesmandesc','SALESMEN','tosalesman','tosalesmandesc');\" 
onkeydown=\"_Check_EnterPressed(event,this.id,'fromsalesman','description','SALESMEN','tosalesman','tosalesmandesc');\"
onblur = \"return _CHECKISVALID(event,this.id,'fromsalesman','description','SALESMEN','tosalesman','tosalesmandesc')\" 

		/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Salesman From ' 
           
onClick=\"_Check_EnterPressed(event,'fromsalesman','fromsalesmandesc','primarykey','SALESMEN','tosalesman','tosalesmandesc','btn');\" 		   
		   ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
echo" </tr>";
   
echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='44%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='tosupplier' type='text' id='tosupplier' size='15' value='".$tosupplier."' 
		
		tag='primarykey'
  onfocus=\"_AutoCompleteData(event,this.id,'tosupplier','tosuppdesc','SUPPLIERS');\"
  onkeyup=\"_AutoCompleteData(event,this.id,'tosupplier','tosuppdesc','SUPPLIERS');\"
  onkeydown=\"_Check_EnterPressed(event,this.id,'tosuppdesc','primarykey','SUPPLIERS');\"
  onblur = \"return _CHECKISVALID(event,this.id,'tosuppdesc','primarykey','SUPPLIERS',)\"  		
		
		/>
        <input name='tosuppdesc' type='text' id='tosuppdesc' size='39' value='".$tosuppdesc."'

tag='description'
   onfocus=\"_AutoCompleteData(event,this.id,'tosupplier','tosuppdesc','SUPPLIERS');\" 
   onkeyup=\"_AutoCompleteData(event,this.id,'tosupplier','tosuppdesc','SUPPLIERS');\" 
   onkeydown=\"_Check_EnterPressed(event,this.id,'tosupplier','description','SUPPLIERS');\"
   onblur = \"return _CHECKISVALID(event,this.id,'tosupplier','description','SUPPLIERS',)\" 

		/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Supplier To ' 
            
onClick=\"_Check_EnterPressed(event,'tosupplier','tosuppdesc','primarykey','SUPPLIERS','undefined','undefined','btn');\"
><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";

echo"   <td width='6%' align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";	
echo"   <td width='44%' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='tosalesman' type='text' id='tosalesman' size='15' value='".$tosalesman."' 
		
tag='primarykey'
  onfocus=\"_AutoCompleteData(event,this.id,'tosalesman','tosalesmandesc','SALESMEN');\"
  onkeyup=\"_AutoCompleteData(event,this.id,'tosalesman','tosalesmandesc','SALESMEN');\"
  onkeydown=\"_Check_EnterPressed(event,this.id,'tosalesmandesc','primarykey','SALESMEN');\"			
  onblur = \"return _CHECKISVALID(event,this.id,'tosalesmandesc','primarykey','SALESMEN',)\"  		
		
		/>
        <input name='tosalesmandesc' type='text' id='tosalesmandesc' size='39' value='".$tosalesmandesc."'

   tag='description'
   onfocus=\"_AutoCompleteData(event,this.id,'tosalesman','tosalesmandesc','SALESMEN');\" 
   onkeyup=\"_AutoCompleteData(event,this.id,'tosalesman','tosalesmandesc','SALESMEN');\" 
   onkeydown=\"_Check_EnterPressed(event,this.id,'tosalesman','description','SALESMEN');\"
   onblur = \"return _CHECKISVALID(event,this.id,'tosalesman','description','SALESMEN',)\" 

		/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Salesman To ' 
            
onClick=\"_Check_EnterPressed(event,'tosalesman','tosalesmandesc','primarykey','SALESMEN','undefined','undefined','btn');\"			
			><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>"; 
echo" </tr>";

echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Item Code / Description</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Warehouse</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='44%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='fromitem' type='text' id='fromitem' size='15' value='".$fromitem."' 
		
tag='primarykey'
onfocus=\"_AutoCompleteData(event,this.id,'fromitem','fromitemdesc','ITEMS_TYPE0','toitem','toitemdesc');\"
onkeyup=\"_AutoCompleteData(event,this.id,'fromitem','fromitemdesc','ITEMS_TYPE0','toitem','toitemdesc');\"
onkeydown=\"_Check_EnterPressed(event,this.id,'fromitemdesc','primarykey','ITEMS_TYPE0','toitem','toitemdesc');\"
onblur = \"return _CHECKISVALID(event,this.id,'fromitemdesc','primarykey','ITEMS_TYPE0','toitem','toitemdesc')\"		
		
		/>
        <input name='fromitemdesc' type='text' id='fromitemdesc' size='39' value='".$fromitemdesc."' 
		
tag='description'
onfocus=\"_AutoCompleteData(event,this.id,'fromitem','fromitemdesc','ITEMS_TYPE0','toitem','toitemdesc');\" 	  
onkeyup=\"_AutoCompleteData(event,this.id,'fromitem','fromitemdesc','ITEMS_TYPE0','toitem','toitemdesc');\" 
onkeydown=\"_Check_EnterPressed(event,this.id,'fromitem','description','ITEMS_TYPE0','toitem','toitemdesc');\"	
onblur = \"return _CHECKISVALID(event,this.id,'fromitem','description','ITEMS_TYPE0','toitem','toitemdesc')\" 	
		
		
		/>
        </label>
        </span>
        <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item From ' 
            onClick=\"_Check_EnterPressed(event,'fromitem','fromitemdesc','primarykey','ITEMS_TYPE0','toitem','toitemdesc','btn');\" 
			 
			 ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";

echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>
		<td width='44%' bgcolor='#F5F5F5' ><span class='style8'><select name='fromwarehouse' id='fromwarehouse' style='width:400px'>";
		echo"<option></option>";
		while($wrhf=mysql_fetch_row($resultfromwarehouse)){
		echo"<option ";
			if ($fromwarehouse==$wrhf[0])
				echo " selected ";
		echo" value='$wrhf[0]'>$wrhf[0] / $wrhf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";	 
		
echo" </tr>";			 
echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='44%'  valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='toitem' type='text' id='toitem' size='15' value='".$toitem."'

tag='primarykey'
  onfocus=\"_AutoCompleteData(event,this.id,'toitem','toitemdesc','ITEMS_TYPE0');\"
  onkeyup=\"_AutoCompleteData(event,this.id,'toitem','toitemdesc','ITEMS_TYPE0');\"
  onkeydown=\"_Check_EnterPressed(event,this.id,'toitemdesc','primarykey','ITEMS_TYPE0');\"	  
  onblur = \"return _CHECKISVALID(event,this.id,'toitemdesc','primarykey','ITEMS_TYPE0',)\"   

		/>
        <input name='toitemdesc' type='text' id='toitemdesc' size='39' value='".$toitemdesc."'

   tag='description'
   onfocus=\"_AutoCompleteData(event,this.id,'toitem','toitemdesc','ITEMS_TYPE0');\" 
   onkeyup=\"_AutoCompleteData(event,this.id,'toitem','toitemdesc','ITEMS_TYPE0');\" 
   onkeydown=\"_Check_EnterPressed(event,this.id,'toitem','description','ITEMS_TYPE0');\"
    onblur = \"return _CHECKISVALID(event,this.id,'toitem','description','ITEMS_TYPE0',)\" 

		/>
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item To ' 
onClick=\"_Check_EnterPressed(event,'toitem','toitemdesc','primarykey','ITEMS_TYPE0','undefined','undefined','btn');\"
			 
			 ><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";

echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>
		<td width='44%' bgcolor='#F5F5F5' ><span class='style8'><select name='towarehouse' id='towarehouse' style='width:400px'>";
		echo"<option></option>";
		while($wrht=mysql_fetch_row($resulttowarehouse)){
		echo"<option ";
			if ($towarehouse==$wrht[0])
				echo " selected ";
		echo" value='$wrht[0]'>$wrht[0] / $wrht[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";	 
echo" </tr>";



if($Module_Heatno==1){
echo" <tr height='20'>";
echo"   <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>HeatNo";
echo"   </span></td>";

echo"</tr>";

echo" <tr height='15px'>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='45%'  colspan='3' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='fromheatno' type='text' id='fromheatno' size='15' value='".$fromheatno."' />
        <input name='fromheatnotype' type='text' id='fromheatnotype' size='35' value='".$fromheatnotype."' />
        <input name='btncode1' type='hidden' id='btncode1' value='...' style='width:20px; height:20px; border:thin;' title='Select HeatNo' />
        </label>
      </span>
      <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select HeatNo ' 
             onClick='showlistheatno(1); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>      ";
echo"</td>";


echo" </tr>";


echo" <tr height='15px'>";	  
echo"   <td width='5%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='45%'  colspan='3' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
echo"   <label>
        <input name='toheatno' type='text' id='toheatno' size='15' value='".$toheatno."' />
        <input name='toheatnotype' type='text' id='toheatnotype' size='35' value='".$toheatnotype."' />
        <input name='btncode1' type='hidden' id='btncode1' value='...' style='width:20px; height:20px; border:thin;' title='Select Item To' />
        </label>
		</span>
		<label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Item To ' 
             onClick='showlistheatno(2); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label>      ";
echo"</td>";


echo" </tr>";
}


echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Item Group</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Item SubGroup</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='44%'  bgcolor='#F5F5F5' ><span class='style8'><select name='fromgroup' id='fromgroup' style='width:400px'>";
		echo"<option></option>";
		while($grpf=mysql_fetch_row($resultfromgroup)){
		echo"<option ";
			if ($fromgroup==$grpf[0])
				echo " selected ";
		echo" value='$grpf[0]'>$grpf[0] | $grpf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";					 

echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='44%'  bgcolor='#F5F5F5' ><span class='style8'><select name='fromsubgroup' id='fromsubgroup' style='width:400px'>";
		echo"<option></option>";
		while($subgrpf=mysql_fetch_row($resultfromsubgroup)){
		echo"<option ";
			if ($fromsubgroup==$subgrpf[0])
				echo " selected ";
		echo" value='$subgrpf[0]'>$subgrpf[0] | $subgrpf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";		
		
echo" </tr>";

echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='44%'  bgcolor='#F5F5F5' ><span class='style8'><select name='togroup' id='togroup' style='width:400px'>";
		echo"<option></option>";
		while($grpt=mysql_fetch_row($resulttogroup)){
		echo"<option ";
			if ($togroup==$grpt[0])
				echo " selected ";
		echo" value='$grpt[0]'>$grpt[0] | $grpt[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";
		
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='44%'  bgcolor='#F5F5F5' ><span class='style8'><select name='tosubgroup' id='tosubgroup' style='width:400px'>";
		echo"<option></option>";
		while($subgrpt=mysql_fetch_row($resulttosubgroup)){
		echo"<option ";
			if ($tosubgroup==$subgrpt[0])
				echo " selected ";
		echo" value='$subgrpt[0]'>$subgrpt[0] | $subgrpt[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";		

echo" </tr>";


if ($Module_Project == 1) {
	echo" <tr>";
	echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Project</span></td>";
	echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Master Project</span></td>";
	echo" </tr>";

	echo" <tr>
			<td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
			<td width='44%' bgcolor='#F5F5F5'> <span class='style8'><select name='fromproject' id='fromproject' style='width:400px'>";
			echo"<option></option>";
			while($prjf=mysql_fetch_row($resultfromproject)){
			echo"<option ";
				if ($fromproject==$prjf[0]) 
					echo " selected ";
			echo" value='$prjf[0]'>$prjf[0] / $prjf[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";

	echo"   <td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
			<td width='44%' bgcolor='#F5F5F5'> <span class='style8'><select name='frommasterproject' id='frommasterproject' style='width:400px'>";
			echo"<option></option>";
			while($mprjf=mysql_fetch_row($resultfrommasterproject)){
			echo"<option ";
				if ($frommasterproject==$mprjf[0]) 
					echo " selected ";
			echo" value='$mprjf[0]'>$mprjf[0] / $mprjf[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";

			
	echo" </tr>";

	echo" <tr>
			<td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
			<td width='44%' bgcolor='#F5F5F5'> <span class='style8'><select name='toproject' id='toproject' style='width:400px'>";
			echo"<option></option>";
			while($prjt=mysql_fetch_row($resulttoproject)){
			echo"<option ";
				if ($toproject==$prjt[0]) 
					echo " selected ";
			echo" value='$prjt[0]'>$prjt[0] / $prjt[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";

	echo"   <td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
			<td width='44%' bgcolor='#F5F5F5'> <span class='style8'><select name='tomasterproject' id='tomasterproject' style='width:400px'>";
			echo"<option></option>";
			while($mprjt=mysql_fetch_row($resulttomasterproject)){
			echo"<option ";
				if ($tomasterproject==$mprjt[0]) 
					echo " selected ";
			echo" value='$mprjt[0]'>$mprjt[0] / $mprjt[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";

			
	echo" </tr>";

} else {
	echo"<input type='hidden' name='fromproject' id='fromproject' value='$fromproject'>
		 <input type='hidden' name='toproject' id='toproject' value='$toproject'>
		 <input type='hidden' name='frommasterproject' id='frommasterproject' value='$frommasterproject'>
		 <input type='hidden' name='tomasterproject' id='tomasterproject' value='$tomasterproject'>";
}

if ($Module_CostCenter == 1){ 
	echo" <tr>";
	echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>CostCenter</span></td>";
	echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Master CostCenter</span></td>";
	echo" </tr>";

	echo" <tr>";
	echo"	<td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
			<td width='44%' align='left' bgcolor='#F5F5F5' ><span class='style8'>
			<select name='fromcostcent' id='fromcostcent' style='width:400px'>";
			echo"<option></option>";
			while($cstf=mysql_fetch_row($resultfromcostcent)){
			echo"<option ";
				if (($fromcostcent==$cstf[0]) || ($defaultcostcent==$cstf[0]))
					echo " selected ";
			echo" value='$cstf[0]'>$cstf[0] / $cstf[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";	

	echo"	<td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>
			<td width='44%' align='left' bgcolor='#F5F5F5' ><span class='style8'>
			<select name='frommastercostcent' id='frommastercostcent' style='width:400px'>";
			echo"<option></option>";
			while($mcstf=mysql_fetch_row($resultfrommastercostcent)){
			echo"<option ";
				if (($frommastercostcent==$mcstf[0]))
					echo " selected ";
			echo" value='$mcstf[0]'>$mcstf[0] / $mcstf[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";	
			
	echo" </tr>";

	echo" <tr>";
	echo"	<td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
			<td width='44%' align='left' bgcolor='#F5F5F5' ><span class='style8'>
			<select name='tocostcent' id='tocostcent' style='width:400px'>";
			echo"<option></option>";
			while($cstt=mysql_fetch_row($resulttocostcent)){
			echo"<option ";
				if (($tocostcent==$cstt[0]) || ($defaultcostcent==$cstt[0]))
					echo " selected ";
			echo" value='$cstt[0]'>$cstt[0] / $cstt[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";	

	echo"	<td width='6%' align='right' bgcolor='#F5F5F5'><span class='style8'>To</span></td>
			<td width='44%' align='left' bgcolor='#F5F5F5' ><span class='style8'>
			<select name='tomastercostcent' id='tomastercostcent' style='width:400px'>";
			echo"<option></option>";
			while($mcstt=mysql_fetch_row($resulttomastercostcent)){
			echo"<option ";
				if (($tomastercostcent==$mcstt[0]) )
					echo " selected ";
			echo" value='$mcstt[0]'>$mcstt[0] / $mcstt[1]</option>";
			}
			echo"</select>";
			echo"</span></td>";	
			
	echo" </tr>";
} else {
	echo"<input type='hidden' name='fromcostcent' id='fromcostcent' value='$fromcostcent'>
		 <input type='hidden' name='tocostcent' id='tocostcent' value='$tocostcent'>
		 <input type='hidden' name='frommastercostcent' id='frommastercostcent' value='$frommastercostcent'>
		 <input type='hidden' name='tomastercostcent' id='tomastercostcent' value='$tomastercostcent'>";
}


echo" <tr>";
echo"   <td colspan='7' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";




echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Project Include/Like</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Costcenter Include/Like</span></td>";
echo" </tr>";
echo" </tr>";
echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";
echo"   <td width='44%' align='left' bgcolor='#F5F5F5' ><input name='subproj' type='text' id='subproj'  value='".$subproj."' style='width:395px;'/></td>";
echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";
echo"	<td width='44%' align='left' bgcolor='#F5F5F5'><input name='subcostcent' type='text' id='subcostcent' value='".$subcostcent."' style='width:395px;'/></td>";
echo" </tr>";


echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Client Rating</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";

echo" <tr>";
echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";			 		
echo"   <td width='44%' bgcolor='#F5F5F5' ><span class='style8'><select name='cltrating' id='cltrating' style='width:400px'>";
		echo"<option></option>";
		while($rating=mysql_fetch_row($resultclientrating)){
		echo"<option ";
			if ($cltrating==$rating[0])
				echo " selected ";
		echo" value='$rating[0]'>$rating[0]</option>";
		}
		echo"</select>";
		echo"</span></td>";		
		
//echo"	<td width='50%' colspan='2' align='right' bgcolor='#F5F5F5'>&nbsp;</td>";		
echo"   <td width='6%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>Area</span></td>";			 		
echo"   <td width='44%' bgcolor='#F5F5F5' ><span class='style8'><select name='fromarea' id='fromarea' style='width:400px'>";
		echo"<option></option>";
		while($areaf=mysql_fetch_row($resultfromarea)){
		echo"<option ";
			if ($fromarea==$areaf[0])
				echo " selected ";
		echo" value='$areaf[0]'>$areaf[0] / $areaf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";		
echo" </tr>";

echo" <tr>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Client Business Type</span></td>";
echo"   <td colspan='2' bgcolor='#F5F5F5'><span class='style8'>Item Category</span></td>";
echo" </tr>";

echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='44%'  bgcolor='#F5F5F5' ><span class='style8'><select name='frombustype' id='frombustype' style='width:400px'>";
		echo"<option></option>";
		while($btypef=mysql_fetch_row($resultfrombustype)){
		echo"<option ";
			if ($frombustype==$btypef[0])
				echo " selected ";
		echo" value='$btypef[0]'>$btypef[0]</option>";
		}
		echo"</select>";
		echo"</span></td>";					 

//echo"   <td width='50%' colspan='2' align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>From</span></td>";
echo"   <td width='44%' bgcolor='#F5F5F5' ><span class='style8'><select name='fromcategory' id='fromcategory' style='width:400px'>";
		echo"<option></option>";
		while($catf=mysql_fetch_row($resultfromcategory)){
		echo"<option ";
			if ($fromcategory==$catf[0])
				echo " selected ";
		echo" value='$catf[0]'>$catf[0] | $catf[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";	
echo" </tr>";

echo" <tr>";	  
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='44%'  bgcolor='#F5F5F5' ><span class='style8'><select name='tobustype' id='tobustype' style='width:400px'>";
		echo"<option></option>";
		while($btypet=mysql_fetch_row($resulttobustype)){
		echo"<option ";
			if ($tobustype==$btypet[0])
				echo " selected ";
		echo" value='$btypet[0]'>$btypet[0]</option>";
		}
		echo"</select>";
		echo"</span></td>";
		
//echo"   <td width='50%' colspan='2' align='right' bgcolor='#F5F5F5' ><span class='style8'>&nbsp;</span></td>";
echo"   <td width='6%'   align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";
echo"   <td width='44%'  bgcolor='#F5F5F5' ><span class='style8'><select name='tocategory' id='tocategory' style='width:400px'>";
		echo"<option></option>";
		while($catt=mysql_fetch_row($resulttocategory)){
		echo"<option ";
			if ($tocategory==$catt[0])
				echo " selected ";
		echo" value='$catt[0]'>$catt[0] | $catt[1]</option>";
		}
		echo"</select>";
		echo"</span></td>";
echo" </tr>";


if($Module_RandomeSupplier == 1){
	echo" <tr height='35px'>";
	echo"   <td colspan='4' bgcolor='#F5F5F5'><span class='style8'>Supplier (1)</span></td>";
	 echo" </tr>";
	
	echo" <tr>
			<td width='5%' align='right' bgcolor='#F5F5F5'><span class='style8'>From</span></td>";
	echo"   <td width='45%'  colspan='3' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
	echo"   <label>
			<input name='fromsupplier1' type='text' id='fromsupplier1' size='15' value='".$fromsupplier1."' />
			<input name='fromsuppdesc1' type='text' id='fromsuppdesc1' size='35' value='".$fromsuppdesc1."' />
			 </label>
		  </span>
		  <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Supplier From ' 
				 onClick='showlistSupplier(3); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
	echo"</tr><tr height='35px'>";
	echo"   <td width='5%'  align='right' bgcolor='#F5F5F5' ><span class='style8'>To</span></td>";			 		
	echo"   <td width='45%'  colspan='3' valign='middle' bgcolor='#F5F5F5' ><span class='style8'>";
	echo"   <label>
			<input name='tosupplier1' type='text' id='tosupplier1' size='15' value='".$tosupplier1."' />
			<input name='tosuppdesc1' type='text' id='tosuppdesc1' size='35' value='".$tosuppdesc1."' />
			 </label>
		  </span>
		  <label><span class='style11'><a href='javascript:void(0);' NAME='My Window Name' title=' Select Supplier From ' 
				 onClick='showlistSupplier(4); '><img src='img/btnopen.jpg' width='15' height='20' border='0' /></a> </span></label></td>";
	echo" </tr>";
	}else{
		echo "<input  type ='hidden' id='fromsupplier1'>";
		echo "<input  type ='hidden' id='tosupplier1'>";
	}
	
echo" <tr>";
echo"   <td colspan='7' bgcolor='#F5F5F5'><span class='style8'>&nbsp;</span></td>";
echo" </tr>";
/*
echo"<tr height='30'>
      <td colspan='9' align='center' bgcolor='#F5F5F5'>";
	  
//$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";	  

if ($isseloption != 1) {
	echo"   <input type='button' id='btnClear' name='btnClear' value='Clear Page'  onclick='ClearPage();' $style title='Clear Page'>";
					
	echo"   <input type='button' name='btnCancel' id='btnCancel' value='Cancel' ";//cancel
			if ($mainaction!='edit')
				echo " disabled ";
			echo" onclick='CancelRecord();' $style title='Cancel Changes'>";
					
	echo"   <input type='button' name='btnPost' id='btnPost' value='Save' ";//post
			//if (($actionmode=='' || $actionmode=='cancel') && $mainaction!='edit')
				//echo " disabled ";
			echo" onclick='PostChanges();' $style	title='Save Changes' />";

	echo"   <input type='button' name='btnSearch' id='btnSearch' value='Search' onclick='SearchForRef();' $style title='Search By Reference' ";
			if ($templateid != '') 
				echo " disabled ";
			echo " />";
} else {
	echo"   <input type='button' id='btnSelectOption' name='btnSelectOption' value='Select Options'  onclick='SelectOptions();' $style title='Select Options'>";
}


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

	

	echo"   </table></td></tr>"; 
 echo"   </table></td></tr><tr height='30'><td align='center' id='content-bottom' ></td></tr>";  
 echo" </table>
 
</form>
</body>
</html>";


	  
?>