<?php
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);

session_start();

if (isset($_SESSION["client_id"])){
}else{
	$_SESSION["client_id"] = 1;
	
	//get sales_id if logged in
	
	
}

	

?>
<!doctype html>
<html lang="en">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="theme-color" content="#000000">
    <title>PhoenixPOS Point of Sale Cloud Software</title>
    <meta name="description" content="phoenixsoftware.co.nz. Shop POS solutions.">
    <link rel="icon" type="image/png" href="../images/logo.png" sizes="32x32">
    <link rel="apple-touch-icon" sizes="180x180" href="../images/logo.png">


	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="manifest" href="../manifest.json">

</head>

<body class=""  onload="load_cart()">
    <link rel="stylesheet" href="../assets/css/style.css">
	<link rel="stylesheet" href="../css/jquery-ui.min.css">
	


	<style>
	.chip {
  display: inline-block;
  padding: 0 25px;
  height: 50px;
  font-size: 16px;
  line-height: 50px;
  border-radius: 25px;
  background-color: #f1f1f1;
}

.chip img {
  float: left;
  margin: 0 10px 0 -25px;
  height: 50px;
  width: 50px;
  border-radius: 50%;
}

</style>

	
	
    <!-- loader -->

    <!-- * loader -->

    <!-- App Header -->
<?php include ("../php/posheader.php") ?>
    <!-- * App Header -->

    <!-- Search Component -->

    <!-- * Search Component -->

    <!-- App Capsule -->
    <div id="appCapsule"  class="col-md-12">
<center>






    <div class="row" style="height: 900px;" >
	


        <div style="border: solid 1px; border-color: #6c757d" class="col-md-8">
                
				 
				 
				 
				           <div class="tab-pane fade show active" id="pilled" role="tabpanel">

                <div class="section full mt-1">



                    <div class="wide-block pt-2 pb-2">

                        <ul class="nav nav-tabs lined" role="tablist">
                            <li class="nav-item">
                                <a onclick="javascript: load_cart_currentsale()" id="tabcurrentsale" class="nav-link active" data-toggle="tab" href="#home" role="tab">
                                    Current Job
                                </a>
                            </li>
			<?		

if (isset( $_COOKIE['phxcrmclient_id'])){
	
	
	$phxclientid 	= $_COOKIE['phxcrmclient_id'];
	

}else{
	
	
	$phxclientid 	= 0;

	
}			
									
									
if (isset( $_COOKIE['phxcrmuserid'])){
	
	
	
	$phxcrmuserid 		= $_COOKIE['phxcrmuserid'];

}else{
	
	$phxcrmuserid 		= 0;
	
}

		$staff_sec_level ="None";
		$sec_level = 0;
		
		
		if ($phxclientid == 0 && $phxcrmuserid == 0){
			
		}else{
		
			$queryuser="SELECT * from ".$phxclientid."_staff where uid_staff = ".$phxcrmuserid;

		//	echo $queryuser;
			$resultuser=mysqli_query($conn, $queryuser);


			while($rowuser=mysqli_fetch_array($resultuser)) { 

				$staff_sec_level	= $rowuser['staff_sec_level'];

			
			}
		
			if ($staff_sec_level == "Cashier"){
				$sec_level = 0;
			}else if ($staff_sec_level == "None"){
				$sec_level = 0;
			}else if ($staff_sec_level == "Superuser"){
				$sec_level = 1;
			}
			
		}
			
			if ($sec_level == 1){
				?>			

							
							<?php
							
			}
							?>
                        </ul>
                        <div class="tab-content mt-2">
                            <div class="tab-pane fade show active" id="home" role="tabpanel">
                                
                <div class="section full mt-1">
				

                    
                    <div style="padding-left: 8px; padding-right: 8px"  class="wide-block pt-2 pb-2">
					<table>
					<tr>
					<td style="width: 50%">
                               <form class="search-form">
            <div style="width:400px" class="form-group searchbox">
                <input type="text" tabindex="1" id="tagsprodsearch"  class="form-control" placeholder="Search / Scan Product ..." >
                <i class="input-icon">
                    <ion-icon name="search-outline"></ion-icon>
                </i>
            </div>
        </form>
		</td>
		<td style="width: 50%">
<table style="width: 100%">
<tr>
<td style="width: 50%; text-align:right"> 		
<span><i> <strong>JOB: <span style="border: none:" id="sel_job_id"></span></strong></i></span>	

</td>
<td style="width: 50%; text-align:right"> 		


</tr>
</table>	
</td>
</tr>
</table>	

		<?php
		

		
		$phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
		
		

		include("../php/configi.php");
		
		$sqlphx1 = "SELECT * FROM phx_userid where idphx_userid = " . $phxcrmclient_id;
		
		$comp_eftpos_type = "None";				

		$resultphx1 = $conn->query($sqlphx1);

		if ($resultphx1->num_rows > 0) {
			// output data of each row
			while($rowphx1 = $resultphx1->fetch_assoc()) {

				$comp_pos_layout				= $rowphx1["comp_pos_layout"];
				$comp_screen_size				= $rowphx1["comp_screen_size"];
				$comp_eftpos_type				= $rowphx1["comp_eftpos_type"];				
				
			}
			
		}
		

		
		if ($comp_screen_size == "Medium"){

			$ssize = "275px";
			
		}else{
			
			$ssize = "400px";
			
		}
		
		

                               
	
				if ($comp_pos_layout == "Compact"){
			?>
		

		<div style="margin-top: 2px; height: 14px; " class="section mt-2">
				<div style="width: 35px; float: left; font-size: 10px;">Del</div>
	
				<div style="width: 50px; float: left; font-size: 10px;">SKU</div>


				<div style="width:730px; float: left; font-size: 10px;">Title</div>
				<div style="width: 100px; float: left; font-size: 10px;">Unit$</div>
				<div style="display: none; width: 100px; float: left; font-size: 10px;">Disc%</div>
				<div style="width: 130px; float: left; font-size: 10px;">Qty</div>
			<div style="width: 130px; float: left; font-size: 10px;">Total$</div>

		</div>

		
		<?php
				}
				
				
				$ssize = 190;
				
				?>
		
		<div style="font-size: 13px; margin-top: 2px; height: <?php echo $ssize ?>; overflow-y: scroll;" class="section mt-2" id="divcartitems">


        </div>


        <!-- Discount Action Sheet -->

        <!-- * Discount Action Sheet -->

        <div class="section mt-0 mb-0" id="divcarttotals">

        </div>
                    </div>
					
																						<div class="row" style="margin-top: 0px; padding-top: 0px">											
												
														<div class="col-md-12 col-sm-12"  style="margin-top: 0px; padding-top: 0px">
															
<div style="display: none">
															<textarea id="j_job_descr_edit"  data-height="90" data-lang="en-US"></textarea>
						</div>									
														

														</div>

													</div>
                </div>
						 <button id="printorder" style="display: none" type="button" class="btn btn-secondary" data-toggle="modal" data-target="#DialogOrderPrint">Receipt</button>
						 
						
						 <br>
						 
						 <br>
	
						   <button id="allvoidsale"   data-toggle="modal" data-target="#DialogVoid" style="width: 120px; display: none"  class="btn btn-outline-secondary mr-1 mb-1"  type="button">Void Sale</button> 
						 
					

                            </div>
							                            <div class="tab-pane fade" id="inprogress" role="tabpanel">
                          <div id="divtodaysalesprog">
						  
						  </div>

                            </div>
                            <div class="tab-pane fade" id="profile" role="tabpanel">
                          <div id="divtodaysaleswebreport">
						  
						  </div>

                            </div>
                            <div class="tab-pane fade" id="contact" role="tabpanel">
                          <div id="divtodaysalesreport">
						  
						  </div>
						  
                            </div>
                        </div>

                    </div>
                </div> </div>
				 
				 




      
        </div>
		

        <div style="border: solid 1px; border-color: #6c757d; margin-top: 0px;padding-top: 0px;"  class="col-md-4">

 <div style="margin-top: 0px; padding-top: 0px;"  class="section mt-6 mb-6">
                 

				           <div class="tab-pane fade show active" id="pilled" role="tabpanel">

                <div class="section full mt-1">
				<input type="hidden" id="seldept"   class="form-control">

                    <div class="wide-block pt-2 pb-2">

                        <ul class="nav nav-tabs lined" role="tablist">
                            <li class="nav-item">
                                <a id="tabcurrentsale" class="nav-link active" data-toggle="tab" href="#quickpicks" role="tab">
                                    Select Cust / Items
                                </a>
                            </li>




                        </ul>
                        <div class="tab-content mt-2">
						               

                            <div class="tab-pane fade show active" id="quickpicks" role="tabpanel">
                                
                <div class="section full mt-1">
                    
             
                    
                    <div class="wide-block pt-2 pb-2">

					<table>

					<tr>

<td>
            <div  class="form-group searchbox">


                <input readonly type="text" value=""  id="tagsprodcont"  class="form-control"  placeholder="Search Customer ..." >
                <input readonly type="text" style="display: none" id="tagsprodcontnew"  class="form-control" placeholder="Search Customer ..." >

				<input readonly type="text" id="sel_uid_client" value="" style="display: none"  class="form-control" placeholder="Search Customer ..." >
                <i class="input-icon">
                    <ion-icon onclick="javascript: document.getElementById('tagsprodcont').select()" name="search-outline"></ion-icon>
                </i>


  
								

            </div>
				
          <div class="accordion" id="accordionExample1">

                <div class="item">
                    <div class="accordion-header">

                        <button class="btn collapsed text-secondary" type="button" data-toggle="collapse" data-target="#accordion1">
                            Order Delivery Address and details
                        </button>
				

                    </div>
                    <div id="accordion1" class="accordion-body collapse" data-parent="#accordionExample1">
                        <div class="accordion-content">
					
							<input type="text" id="s_postline1"  class="form-control" placeholder="Post address line 1"  onchange="javascript: update_field_st('s_postline1', 'input', this.value)"  >
							<input type="text" id="s_postline2"  class="form-control" placeholder="Post address line 2"  onchange="javascript: update_field_st('s_postline2', 'input', this.value)"  >
							<input type="text" id="s_postline3"  class="form-control" placeholder="Post address line 3"  onchange="javascript: update_field_st('s_postline3', 'input', this.value)"  >
							<input type="text" id="s_postline4"  class="form-control" placeholder="Post address line 4"  onchange="javascript: update_field_st('s_postline4', 'input', this.value)"  >
							<input type="text" id="s_postline5"  class="form-control" placeholder="Post address line 5"  onchange="javascript: update_field_st('s_postline5', 'input', this.value)"  >
							<label class="label" for="c_status">Country</label>

										<?

	
include("../php/configi.php");

$querycy="SELECT * FROM 1_countries order by country_order, country_name";
//echo $querycy;
$resultcy=mysqli_query($conn, $querycy);

?>
		<select    class="form-control"   id = "s_postcountry" name="s_postcountry" style="width: 100%;"  onchange="javascript: update_field_st('s_postcountry', 'input', this.options[this.selectedIndex].value)"  >

<?php

 while($rowcy=mysqli_fetch_array($resultcy)) {

?>
		<option value="<? echo $rowcy["country_name"]; ?>"><? echo $rowcy["country_name"]; ?></option>

		<?


}


	 
?>
</select>




						
						
                         </div>
                    </div>
                </div>
				</div>

</td>
</tr>
</table>
<div  id="area1" ondrop="dropIt(event);" ondragover="event.preventDefault();">



        <div class="section full mt-3">

            <div class="wide-block p-0 pt-2 pb-2" style="padding-top: 0px; padding-bottom: 0px;">
                <!-- Story Blocks -->
				
						<?php
		
		$ssize2 = "280px";
		
		$phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
		
		if ($phxcrmclient_id == "142"){

			$ssize2 = "180px";
			
		}
		
		$ssize2 = "280px";
				
		if ($comp_screen_size == "Medium"){

			$ssize2 = "190px";
			
		}else{
			
			$ssize2 = "280px";
			
		}
		
		$ssize2 = "350px";
		
		?>
		


        <div id="divshowvoidstatus" style="display: none;" class="section full mt-1">
		<span style=" font-size: 35px;">This sale is Void</span>
		</div>
			
        <div id="divshowpaymentactions" class="section full mt-1">
          
			                    <div class="form-group basic">
                        <div class="input-wrapper">
<table>
<tr>
<td style="width: 100px">
</td>
<td>
 <label class="label" for="currentsalesid">Sales ID:</label>
						 <input id="j_st_id" value="" readonly class="form-control" style="width: 100px; border: none; background: transparent; text-decoration: underline;" value="" class="form-control">
</td>

<td>    

<?php


		$phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
		

		include("../php/configi.php");
		
		$sqlstaff = "SELECT * FROM phx_userid where idphx_userid = " . $phxcrmclient_id;
		
//		echo $sqlstaff;
					

		$resultstaff = $conn->query($sqlstaff);

		if ($resultstaff->num_rows > 0) {
			// output data of each row
			while($rowcompany = $resultstaff->fetch_assoc()) {

				$comp_type2				= $rowcompany["comp_type2"];
				
				
			}
			
		}
				
?>
			<input type="hidden" id="phx_comp_name" value = ""   class="form-control">
			<input type="hidden" id="phx_username" value = ""   class="form-control">
			<input type="hidden" id="comp_eftpos_type" value = "<?php echo htmlspecialchars($comp_eftpos_type); ?>"   class="form-control">
			
			<input type="hidden" id="comp_phys_addr1" value = ""   class="form-control">
			<input type="hidden" id="comp_phys_addr2" value = ""   class="form-control">
			<input type="hidden" id="comp_phys_addr3" value = ""   class="form-control">
			<input type="hidden" id="comp_website_url" value = ""   class="form-control">
			<input type="hidden" id="comp_phone" value = ""   class="form-control">
			<input type="hidden" id="phxcrmclient_id" value = "<?php echo $_COOKIE['phxcrmclient_id']?>"   class="form-control">
			<input type="hidden" id="sel_id_stl" value = ""   class="form-control">




</td>

<td>    
 <label class="label" for="stage">Job Status:</label>
									<?php
include_once("../php/configi.php");

$querystatus="SELECT * FROM " . $_COOKIE['phxcrmclient_id'] . "_code_lookup  where code_type = 'jobstatus' order by code_additional";

$querystatus="SELECT * FROM 1_job_codes2 order by jc_order";
//echo $querystaff;
$resultstatus=mysqli_query($conn, $querystatus);
	?>	
<select id = "job_status" name="job_status"   class="form-control"   onchange="javascript: update_field_job('status', 'input', this.options[this.selectedIndex].text)" >

<?



//mysql_close();



$i = 0;

 $status = "Quote Sent";

while($rowstatus=mysqli_fetch_array($resultstatus)) { 

		?>

		<option <?php if ($rowstatus['jc_name'] == $status){echo " selected ";} ?>
		value='<?php echo $rowstatus['jc_name']?>'><?php echo $rowstatus['jc_name']; ?></option> 	

<?php

}


	 
?>
</select>
</td>


<td>    

</td>

<td> 
					
<input type="text" style="text-align: right; display: none;" id="sales_cust_disc" value="0" size="4" class="form-control"  onchange="javascript: update_field_st('sales_cust_disc', 'inputint', this.value)"   >
</td>
</tr>
</table>    
	</div>
                    </div>
					
					<?php
					
					$showcredit = 1;
					$showlaybuy = 1;
					$showaccount = 1;
					$showpaypal = 1;
					$showbartercard = 1;
					
					if ($phxcrmclient_id == 264){
						
						$showcredit = 0;
						$showlaybuy = 0;
						$showaccount = 0;
						$showpaypal = 0;
						$showbartercard = 0;

					}
					
					
					?>
            <div style="display: none" class="wide-block pt-2 pb-1">
			
			
			<button id="creditcardfeecalc"  data-toggle="modal" data-target="#DialogCreditCardfee" style="display: none"  class="btn btn-outline-primary mr-1 mb-1"  type="button">Credit Card Fee Adjust</button> 
						   
						   
                <!-- do not forget to delete mr-1 and mb-1 when copy / paste codes -->
               <button id="allpaycash"  data-toggle="modal" data-target="#DialogCash"  style="width: 120px" class="btn btn-outline-primary mr-1 mb-1"  type="button">All Cash</button> 
                 <button id="allpayeftpos"  data-toggle="modal" data-target="#DialogEftpos" style="width: 120px"  class="btn btn-outline-primary mr-1 mb-1"  type="button">All Eftpos</button> 
               <?php
			   if ($showcredit == 1){
				   
				   ?>
			   <button id="allpaycreditcard"  data-toggle="modal" data-target="#DialogCreditCard" style="width: 120px"  class="btn btn-outline-primary mr-1 mb-1"  type="button">All Credit Card</button> 
			   <?php
			   }
			   ?>
			                  <?php
			   if ($showaccount == 1){
				   
				   ?>
               <button id="allpayaccount"  data-toggle="modal" data-target="#DialogAccount" style="width: 120px"  class="btn btn-outline-primary mr-1 mb-1"  type="button">All On Account</button>
			   			   <?php
			   }
			   ?>
               <button id="allpayvoucher"  data-toggle="modal" data-target="#DialogVoucher" style="width: 120px"  class="btn btn-outline-primary mr-1 mb-1"  type="button">All Voucher</button> 
			   

			   
			   			                  <?php
			   if ($showlaybuy == 1){
				   
				   ?>
			   <button id="allpaylaybuy"  data-toggle="modal" data-target="#DialogLaybuy" style="width: 120px"  class="btn btn-outline-primary mr-1 mb-1"  type="button">All Laybuy</button> 
			   			   			   <?php
			   }
			   ?>
   			   <button id="allpaylaybuy"  data-toggle="modal" data-target="#DialogSplit" style="width: 120px"  class="btn btn-outline-secondary mr-1 mb-1"  type="button">Pay $</button> 
   </div>

	<br>
	<select style="width: 200px; display: none"  class="form-control custom-select" id="st_outlet_id"  onchange="javascript: update_field_st('st_outlet_id', 'inputint', this.options[this.selectedIndex].value)" >
	
	
	<?php
		 include '../php/configi.php';


		$queryoutl="SELECT * from phx_userid_outlet where client_id = ".$_COOKIE['phxcrmclient_id']." order by uid_outlet";

//		echo $querystage;
		$resultoutl=mysqli_query($conn, $queryoutl);


		while($rowoutl=mysqli_fetch_array($resultoutl)) { 

			$uid_outlet				= $rowoutl['uid_outlet'];
			$outlet_name 			= $rowoutl['outlet_name'];
			$outlet_id	 			= $rowoutl['outlet_id'];

			 echo "<option value='".$outlet_id."'>".htmlspecialchars($outlet_name)."</option>";
			
		}
			
			?>
	
                            </select>
							  <br>
    <img id="img_company_logo" style="max-height: 60px" src="https://app.phoenixcrm.co.nz/crm/images/logo/<?php echo $_COOKIE['phxcrmclient_id']; ?>.jpg" alt="" class="imaged">

            </div>
        </div>
		
		<div class="modal fade dialogbox" id="DialogCustCreate" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm you want to create a customer for:</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id=""></div>
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>
                            <a href="#" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade dialogbox" id="DialogCr8Client" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm you want to create client for</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="dispclientname">dispclientname</div>
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>
                            <a href="#" onclick="create_client()" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div class="modal fade dialogbox" id="DialogCash" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm Cash payment</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="disptotalsalecash">disptotalsalecash</div>
					<br>
                         <div class="custom-control custom-checkbox mb-1">
                    <input type="checkbox" class="custom-control-input" id="receipt_cash">
                    <label class="custom-control-label" for="receipt_cash">Receipt Required</label>
                </div>
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" style="padding-left: 5px; padding-right: 5px" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>

							<a href="#" style="padding-left: 5px; padding-right: 5px" onclick="cs_full('allpay','Cash','Complete')" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		
        <div class="modal fade dialogbox" id="DialogEftpos" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm Eftpos payment</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="disptotalsaleeftpos">disptotalsaleeftpos</div>
					<br><br>
					<div style="background-color: #FAFACC"  id="dispwcresponse"></div>
					<div style="background-color: #FAFACC"   id="dispwcresponse2"></div>
          					<br>
							
								<button id="canceleftpos"   style="display: block" onclick="javascript: windcave_cancel_payment(0)" class="btn btn-outline-primary mr-1 mb-1"  type="button">Cancel Transaction</button> 
								<button id="retryeftpos"   style="display: none" onclick="javascript: windcave_request_payment(0)" class="btn btn-outline-secondary mr-1 mb-1"  type="button">Retry Transaction</button> 
								<br>
                         <div id="divreceiptreqdeftpos"   style="display: none"  class="custom-control custom-checkbox mb-1">
                    <input type="checkbox" class="custom-control-input" id="receipt_eftpos">
                    <label class="custom-control-label" for="receipt_eftpos">Receipt Required</label>
                </div>
<?php			

	//		<button id="cancelallpaycash"   style="width: 120px" onclick="javascript: windcave_cancel_payment(2.00)" class="btn btn-outline-primary mr-1 mb-1"  type="button">Cancel</button> 
	?>			 
	
			
				  <button id="statusallpaycash"   style="display: none; width: 120px" onclick="javascript: windcave_request_status(2.00)" class="btn btn-outline-primary mr-1 mb-1"  type="button">Status</button> 
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#"  id="buteftposfullclose"   style="padding-left: 5px; padding-right: 5px" class="btn btn-text-secondary" data-dismiss="modal">CLOSE</a>

							<a href="#" id="buteftposfullconfirm" style="display: hidden; padding-left: 5px; padding-right: 5px" onclick="cs_full('allpay','Eftpos','Complete')" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		
		        <div class="modal fade dialogbox" id="DialogCreditCard" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm Credit Card payment</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="disptotalsalecreditcard">disptotalsalecreditcard</div>
					
										<br>
                         <div class="custom-control custom-checkbox mb-1">
                    <input type="checkbox" class="custom-control-input" id="receipt_credit_card">
                    <label class="custom-control-label" for="receipt_credit_card">Receipt Required</label>
                </div>
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" style="padding-left: 5px; padding-right: 5px" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>

							<a href="#" style="padding-left: 5px; padding-right: 5px" onclick="cs_full('allpay','Credit Card','Complete')" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		
		
				        <div class="modal fade dialogbox" id="DialogCreditCardfee" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Enter the amount to be paid by Credit Card for fee calculation</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="disptotalsalecreditcardfee">disptotalsalecreditcardfee</div>
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" style="padding-left: 5px; padding-right: 5px" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>

							<a href="#" style="padding-left: 5px; padding-right: 5px" onclick="apply_fee()" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		
				<div class="modal fade" id="DialogContEdit" tabindex="-1" role="dialog" aria-labelledby="divcontedit" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">

                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Edit Contact Details</h5>
						 <a href="javascript:;" data-dismiss="modal">Close</a>
                    </div>
                    <form>
                        <div id="divcontedit" style="height: 700px; overflow-y: scroll" class="modal-body text-left mb-6">


                        </div>
                        <div class="modal-footer">
                            <div class="btn-inline">
                            
                                <button  type="button" data-dismiss="modal" class="btn btn-text-primary">CLOSE</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
		        <div class="modal fade dialogbox" id="DialogAccount" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm Account payment</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="disptotalsaleAccount"></div>
															<br>
                         <div class="custom-control custom-checkbox mb-1">
                    <input type="checkbox" class="custom-control-input" id="receipt_account">
                    <label class="custom-control-label" for="receipt_account">Receipt Required</label>
                </div>
          
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" style="padding-left: 5px; padding-right: 5px" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>

							<a href="#" style="padding-left: 5px; padding-right: 5px" onclick="cs_full('allpay','Account','Complete')" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		        <div class="modal fade dialogbox" id="DialogVoucher" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm Voucher payment</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="disptotalsaleVoucher"></div>
          										<br>
                         <div class="custom-control custom-checkbox mb-1">
                    <input type="checkbox" class="custom-control-input" id="receipt_voucher">
                    <label class="custom-control-label" for="receipt_voucher">Receipt Required</label>
                </div>
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" style="padding-left: 5px; padding-right: 5px" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>

							<a href="#" style="padding-left: 5px; padding-right: 5px" onclick="cs_full('allpay','Voucher','Complete')" class="btn btn-text-primary" data-dismiss="modal">COMPLETE</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

		        <div class="modal fade dialogbox" id="DialogLaybuy" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm Laybuy payment</h5>
                    </div>
                    <div class="modal-body">
					<center>
					<div  id="disptotalsaleLaybuy"></div>
															<br>
                         <div class="custom-control custom-checkbox mb-1">
                    <input type="checkbox" class="custom-control-input" id="receipt_laybuy">
                    <label class="custom-control-label" for="receipt_laybuy">Receipt Required</label>
                </div>
          
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" style="padding-left: 5px; padding-right: 5px" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>
                        		<a href="#" style="padding-left: 5px; padding-right: 5px" onclick="cs_full('allpay','Laybuy','Complete')" class="btn btn-text-primary" data-dismiss="modal">COMPLETE</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

		        <div class="modal fade dialogbox" id="DialogVoid" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please confirm you want to void this entire sale.</h5>
                    </div>
                    <div class="modal-body">
					<center>
						<div>         
						<div  id="disptotalVoid">This will put all items back into stock and change the Sale to Void status.</div>    
                <div class="btn-group btn-group-toggle" data-toggle="buttons">

                </div>						


			               

				

</div>
				
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>
                            <a href="#" onclick="cs_void('voidall')" class="btn btn-text-primary">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

		        <div class="modal fade dialogbox" id="DialogSplit" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please enter payment details</h5>
                    </div>
                    <div class="modal-body">
					<center>
						<div>         
						<div  id="disptotalsaleSplit"></div>    
                <div class="btn-group btn-group-toggle" data-toggle="buttons">
				<div class="row">
					<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary active">
                        <input onclick="javascript: paytabsel('option1')" type="radio" name="paytype" id="option1" checked />Cash
						</label>
					</div>
					<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary">
                        <input onclick="javascript: paytabsel('option2')"  type="radio" name="paytype" id="option2" /> Eftpos
						</label>
					</div>
								                  <?php
			   if ($showaccount == 1){
				   
				   ?>
					<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary">
                        <input type="radio" name="paytype" id="option3" /> Credit Card
                    </label>
					</div>
					
			   <?php
			   }
			   ?>
			   								                  <?php
			   if ($showaccount == 1){
				   
				   ?>
					<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary ">
                        <input  type="radio" name="paytype" id="option4" />On Account
                    </label>
					</div>
								   <?php
			   }
			   ?>
					<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary">
                        <input  type="radio" name="paytype" id="option5" /> Voucher
						</label>
					</div>
								   								                  <?php
			   if ($showaccount == 1){
				   
				   ?>
					<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary">
                        <input  type="radio" name="paytype" id="option6" /> Laybuy
						</label>
					</div>
													   <?php
			   }
			   ?>
			   								   								                  <?php
			   if ($showbartercard == 1){
				   
				   ?>
					<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary">
                        <input  type="radio" name="paytype" id="option7" /> Bartercard
						</label>
					</div>
																		   <?php
			   }
			   ?>
										<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary">
                        <input  type="radio" name="paytype" id="option8" /> Park Sale
						</label>
					</div>
													   								                  <?php
			   if ($showpaypal == 1){
				   
				   ?>
						<div class="col-sm-6">
						<label style="width:120px" class="btn btn-outline-primary">
                        <input  type="radio" name="paytype" id="option9" /> Paypal
						</label>
					</div>
																							   <?php
			   }
			   ?>
			   

          
		  
		  
					</div>
                </div>	

			   	<div class="col-sm-6">
			   									
                         <div class="custom-control custom-checkbox mb-1">
                    <input type="checkbox" class="custom-control-input" id="receipt_paydollar">
                    <label class="custom-control-label" for="receipt_paydollar">Receipt Required</label>
                </div>
                 </div>				

			   <div  id="disptotalsaleSplitchange"></div>  
			               

				

</div>
				
          
                    </center>
					</div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>
                            <a href="#" onclick="cs_full('partpay','Split')" class="btn btn-text-primary">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade dialogbox" id="DialogBasic" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Dialog title</h5>
                    </div>
                    <div class="modal-body">
                        This is a dialog message
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-secondary" data-dismiss="modal">CANCEL</a>
                            <a href="#" class="btn btn-text-primary" data-dismiss="modal">CONFIRM</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
                <!-- Story Blocks -->
            </div>

        </div>
		
		

</div>


        <!-- Discount Action Sheet -->

        <!-- * Discount Action Sheet -->


                   
                </div>
                            </div>
                            <div class="tab-pane fade" id="bycat" role="tabpanel">
							
							            <!-- pilled tab -->
            <div class="tab-pane fade show active" id="pilled" role="tabpanel">

                <div class="section full mt-1">
                   
                    <div class="wide-block pt-2 pb-2">
			<h3>Jobsheet Comments</h3><br>

															
	<textarea id="j_jobsheet_comments_edit" data-height="200" data-lang="en-US"></textarea>
															



		</div>
					                      <div id="divjobsheetdetails" class="section full mt-1" style="height: 300px; overflow-x: scroll;">
  


				</div>  
		
                    </div>
                </div>



            </div>
            <!-- * pilled tab -->
                                           
                            <div class="tab-pane fade" id="byinvoice" role="tabpanel">
							
							            <!-- pilled tab -->
            <div class="tab-pane fade show active" id="pilled" role="tabpanel">

                <div class="section full mt-1">
                   
                    <div class="wide-block pt-2 pb-2">
					<h3>Invoices for Job</h3>

		</div>

					                      <div id="divinvoiceresults" class="section full mt-1" style="height: 300px; overflow-x: scroll;">
					<div id="divshowinvoices">
				    
						loading invoices...
						
					</div>    


				</div>         






                    </div>
                </div>



            </div>

                            <div class="tab-pane fade" id="byfile" role="tabpanel">
							
							            <!-- pilled tab -->
            <div class="tab-pane fade show active" id="pilled" role="tabpanel">

                <div class="section full mt-1">
                   
                    <div class="wide-block pt-2 pb-2">
					<h3>Files for Job</h3>

		</div>

					                      <div id="divinvoiceresults" class="section full mt-1" style="height: 300px; overflow-x: scroll;">
					<div id="divshowinvoices">
				    
						loading files...
						
					</div>    


				</div>         






                    </div>
                </div>



            </div>
        <!-- Discount Action Sheet -->

        <!-- * Discount Action Sheet -->


                   
                </div>

                            </div>
                            <div class="tab-pane fade" id="no3" role="tabpanel">
 
						  
                            </div>
                        </div>

                    </div>
                </div> </div>
				


         


</div>


        <div class="section full mt-2">
            <div class="section-title"></div>
            <div  class="wide-block pt-2 pb-2">
				

				 
            </div>   
        </div>

        <!-- Dialog Form -->
        <div class="modal fade dialogbox" id="DialogStaffLogin" data-keyboard="false"  data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Please log in</h5>
                    </div>
                    <form>
                        <div class="modal-body text-left mb-2">
                            <div class="form-group basic">
                                <div class="input-wrapper">
								<table align="center">
								<tr align="center">
								<td style="width: 65px">
								<button onclick="javascript: add_charp('1')" type="button" style="border-radius: 50%; width: 55px; height: 55px" class="button button5">1</button>
								</td>
								<td style="width: 65px">

								<button onclick="javascript: add_charp('2')"  type="button"  style="border-radius: 50%; width: 55px; height: 55px" class="button button5">2</button>
		</td>
		
								<td style="width: 65px">

						<button  onclick="javascript: add_charp('3')"  type="button"  style="border-radius: 50%; width: 55px; height: 55px" class="button button5">3</button>
											</td>
								<td>
</tr>



								<tr style="margin-top: 15px; padding-top: 15px;" align="center">
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">
								<button  onclick="javascript: add_charp('4')"  type="button"  style="border-radius: 50%; width: 55px; height: 55px" class="button button5">4</button>
								</td>
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">

								<button onclick="javascript: add_charp('5')"  type="button"  style="border-radius: 50%; width: 55px; height: 55px" class="button button5">5</button>
		</td>
		
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">

						<button  onclick="javascript: add_charp('6')"  type="button"  style="border-radius: 50%; width: 55px; height: 55px" class="button button5">6</button>
											</td>
								<td>
</tr>




								<tr align="center">
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">
								<button  onclick="javascript: add_charp('7')"  type="button"  style="border-radius: 50%; width: 55px; height: 55px" class="button button5">7</button>
								</td>
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">

								<button  onclick="javascript: add_charp('8')"  type="button" style="border-radius: 50%; width: 55px; height: 55px" class="button button5">8</button>
		</td>
		
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">

						<button type="button"  onclick="javascript: add_charp('9')"   style="border-radius: 50%; width: 55px; height: 55px" class="button button5">9</button>
											</td>
								<td>
</tr>
								<tr align="center">
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">
							
								</td>
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">

								<button  onclick="javascript: add_charp('0')"  type="button"  style="border-radius: 50%; width: 55px; height: 55px" class="button button5">0</button>
		</td>
		
								<td style="width: 65px;margin-top: 15px; padding-top: 15px;">
<button type="button" onclick="javascript: clear_charp();"  style="border-radius: 10%; width: 55px; height: 55px" class="button button5">Clear</button>
					
											</td>
								<td>
</tr>
</table>
<table style="width: 100%">
<tr style="width: 100%">


<td style="width: 100%">

<table style="width: 100%">
<tr style="width: 100%">
<td>

<label style="text-align: center" class="label" for="password1">Enter Your PIN</label>

</td>
<td>

  <input size="4" maxlength="4" readonly type="text" class="form-control" style="; width: 85px; font-size: 24px;  text-align: centre;"  id="Bullets" value="" />
  </td>
  </tr>
  <tr>
  <td>
  <label style="text-align: center" class="label" for="password1">Select Your Name</label>
  </td>
  <td>
  <input size="4" tabindex="999" maxlength="4" id="tagsstaffpw" type="text" class="form-control"  style="width: 180px;; position:absolute;left:0px;top:0px;opacity:0; width: 85px; font-size: 24px;  text-align: centre;" onkeyup="document.getElementById('Bullets').value=this.value.replace(/(.)/g,'•');" />

										<?php

$i = 0;
	
include("../php/configi.php");

$querysta="SELECT * FROM ".$_COOKIE['phxcrmclient_id']."_staff where staff_status = 'Current' and uid_staff <> 0 order by staff_def_user, staff_name";
//echo $querysta;
$resultsta=mysqli_query($conn, $querysta);

?>
		<select onchange="change_login_staff(<?php echo $phxcrmclient_id?>,this.options[this.selectedIndex].value)"   style="width: 180px; font-size: 14px;" class="form-control"   id = "login_staff_id" name="login_staff_id" >

<?php
$curr_staff = 0 ;

 while($rowsta=mysqli_fetch_array($resultsta)) {
	 
	 if ($i == 0){
	
		$curr_staff = $rowsta["uid_staff"];
		
	 }

?>
		<option value="<? echo $rowsta["uid_staff"]; ?>"><? echo htmlspecialchars($rowsta["staff_name"]); ?></option>

		<?


	$i = $i + 1;
}


	 
?>
</select>
</td>
</tr>
<tr>
<td>

  
										<?php
										
										//check for kia 
										
										$loc_disp_set = "";
										
										if ($phxcrmclient_id == 264){

										
											if ($curr_staff == 5 OR $curr_staff == 6){
											
												$loc_disp_set = " readonly disabled ";
											
											}
										
										}

	
include("../php/configi.php");

$queryoid="SELECT * FROM phx_userid_outlet where client_id = ".$_COOKIE['phxcrmclient_id'];
//echo $querysta;
$resultoid=mysqli_query($conn, $queryoid);

?>
  <label style="text-align: center" class="label" for="password1">Select Your Location</label>
  </td>
  <td>
		<select  <?php echo $loc_disp_set; ?>  style="width: 180px; font-size: 14px;" class="form-control"   id = "sel_uid_outlet" name="sel_uid_outlet" >

<?php

 while($rowoid=mysqli_fetch_array($resultoid)) {

?>
		<option value="<? echo $rowoid["outlet_id"]; ?>"><? echo htmlspecialchars($rowoid["outlet_name"]); ?></option>

		<?


}


	 
?>
</select>
</td>
</tr>
</table>





</td>

</tr>

</table>								

                                </div>
                            </div>

                        </div>
                        <div class="modal-footer">
                            <div class="btn-inline">
                                <button  onclick="javascript: logout_staff();" type="button" class="btn btn-text-secondary">LOGOUT</button>
                                <button onclick="javascript: login_staff();" type="button" class="btn btn-text-primary">SIGN IN</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- * Dialog Form -->
		

		        <div class="modal fade dialogbox" id="DialogOrderPrint" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog modal-xl" style="min-width:90%" role="document">
                <div class="modal-content">
										                            <div class="btn-inline">
                                 <button onclick="javascript: show_receipt();" type="button" class="btn btn-text-primary">VIEW</button>
                                <button onclick="javascript: show_receipt_email();" type="button" class="btn btn-text-primary">EMAIL</button>
								 <button onclick="javascript: receipt_print();" type="button" class="btn btn-text-primary">PRINT</button>
								 	   <button  data-dismiss="modal" type="button" class="btn btn-text-secondary">CLOSE</button>
                            </div>
                    <div class="modal-header" style=|"padding-top: 0px; padding-bottom: 0px;">
                        <h5 class="modal-title">Receipt</h5>
					
                    </div>

	<div style="display: block" id="divorderprintdetails">

                </div>
				
			<div style="display: block" id="divorderprintdetails2">

                </div>
				
							<div id="divemailreceipt" style="display: none;">
		<br>
		<br>

			<div style="width: 100px;">Email to:</div>

			<div style="width: 300px;"><input style="width: 300px;" name="reportemailto" id="reportemailto" type="text"  value="" /></div>



			<div style="width: 100px;">Subject:</div>


			<div style="width: 300px;"><input style="width: 300px;" name="reportemailsubject" id="reportemailsubject" type="text"  value="Receipt" /></div>



			<div style="width: 100px;">Message:</div>


			<textarea style="background: white; border: solid grey" id="reportemailmessage" name="reportemailmessage"  rows="5" cols="50"></textarea>
<br>

<button type="button" onClick='javascript:emailreceipt();' style="height: 25px; font-size: 12px;">Send Email</button>

<div id="result"></div>
		</div>	
				


				                        <div class="modal-footer">
                            <div class="btn-inline">
                                      <button onclick="javascript: show_receipt();" type="button" class="btn btn-text-primary">VIEW</button>
                                <button onclick="" type="button" class="btn btn-text-primary">EMAIL</button>
								 <button onclick="javascript: receipt_print();" type="button" class="btn btn-text-primary">PRINT</button>
								   <button  data-dismiss="modal" type="button" class="btn btn-text-secondary">CLOSE</button>
                            </div>
                        </div>
            </div>
        </div>


		</div>
		</div>
	
		
        </div>
    </div>

</div>




        <!-- app footer -->
        <div  class="section mt-6 mb-6">


		<center>	<small>
 </center>
	<?	
					 	 include '../php/configi.php';
						 
		//	echo "cookie".$_COOKIE['phxcrmclient_id'];			 
						 
						 
	if (isset($_COOKIE['phxcrmclient_id'])){
		 $phxcrmclient_id = $_COOKIE['phxcrmclient_id'];
		 
		 		$queryclient="SELECT * from ".$_COOKIE['phxcrmclient_id']."_client where uid_client = " . $phxcrmclient_id;
	//	echo $queryprod;
		$resultclient=mysqli_query($conn, $queryclient);

		while($rowclient=mysqli_fetch_array($resultclient)) { 

			$comp_name			 				= $rowclient['comp_name'];
			
		}

?>

<?

//echo $_COOKIE['phxcrmclient_id'];

	}else{
		
		
	//	echo $_COOKIE['phxcrmclient_id'];

		
	}
	?>
	<br>

     
            <div class="footer-title">
			<center>
                Copyright © phoenixsoftware.co.nz 2021.<br> All Rights Reserved.
            </center>
			</div>
 


        </div>
        <!-- * app footer -->

    </div>
    <!-- * App Capsule -->
<div class="modal fade dialogbox" id="DialogBasic" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Apply Payment:</h5>
                    </div>
                    <div class="modal-body">
                      

						
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="#" class="btn btn-text-primary" data-dismiss="modal">OK</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		

		
		        <div class="modal inset fade action-sheet ios-add-to-home" id="ios-add-to-home-screen" tabindex="-1"
            role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Add to Home Screen</h5>
                        <a href="javascript:;" class="close-button" data-dismiss="modal">
                            <ion-icon name="close"></ion-icon>
                        </a>
                    </div>
                    <div class="modal-body">
                        <div class="action-sheet-content text-center">
                            <div class="mb-1"><img src="../images/logo.png" alt="image" class="imaged w48">
                            </div>
                            <h4>phoenixsoftware.co.nz</h4>
                            <div>
                                Install phoenixsoftware.co.nz on your iPhone's home screen.
                            </div>
                            <div>
                                Tap the menu for your browser. Then tap Add to homescreen.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- * iOS Add to Home Action Sheet -->
        <!-- Android Add to Home Action Sheet -->
        <div class="modal inset fade action-sheet android-add-to-home" id="android-add-to-home-screen" tabindex="-1"
            role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">Add to Home Screen</h5>
                        <a href="javascript:;" class="close-button" data-dismiss="modal">
                            <ion-icon name="close"></ion-icon>
                        </a>
                    </div>
                    <div class="modal-body">
                        <div class="action-sheet-content text-center">
                            <div class="mb-1"><img src="../images/logo.png" alt="image" class="imaged w48">
                            </div>
                            <h4>phoenixsoftware.co.nz</h4>
                            <div>
                                Install phoenixsoftware.co.nz on your Android's home screen.
                            </div>
                            <div>
								Click menu for your browser then click "add app" or "install app".<br>If these options are not there - check for "add to home" option.<br> Once install is complete, go to your home screen and there should<br> be a phoenixsoftware.co.nz app installed. 
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    <!-- App Bottom Menu -->
    <div class="appBottomMenu">
        <a href="index.php" class="item active">
            <div class="col">
                <ion-icon name="home-outline"></ion-icon>
            </div>
        </a>


		
		
        <a href="javascript:;" class="item" data-toggle="modal" data-target="#sidebarPanel">
            <div class="col">
                <ion-icon name="menu-outline"></ion-icon>
            </div>
        </a>
    </div>
    <!-- * App Bottom Menu -->

    <!-- App Sidebar -->
	<?php include ('../php/sidebar.php'); ?>
    <!-- * App Sidebar -->

    <!-- welcome notification  -->
    <div id="notification-welcome" class="notification-box">
        <div class="notification-dialog android-style">
            <div class="notification-header">
                <div class="in">
                    <img src="../assets/img/icon/72x72.png" alt="image" class="imaged w24">
                    <strong>phoenixsoftware.co.nz</strong>
                    <span>just now</span>
                </div>
                <a href="#" class="close-button">
                    <ion-icon name="close"></ion-icon>
                </a>
            </div>
            <div class="notification-content">
                <div class="in">
                    <h3 class="subtitle">Welcome to phoenixpos.app</h3>
                    <div class="text">
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
        <div id="toast-login-successful" class="toast-box toast-bottom bg-success">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Login Successful</center>
                </div>
            </div>
        </div>
		        <div id="toast-login-failed" class="toast-box toast-bottom bg-danger">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Login Failed. Incorrect password. Please try again.</center>
                </div>
            </div>
        </div>
		        <div id="toast-sale-successful" class="toast-box toast-bottom bg-success">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Sale Successfuly procesed</center>
                </div>
            </div>
        </div>
				        <div id="toast-sale-void" class="toast-box toast-bottom bg-success">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Sale Voided</center>
                </div>
            </div>
        </div>
		
				        <div id="toast-sale-parked" class="toast-box toast-bottom bg-success">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Sale Successfuly parked</center>
                </div>
            </div>
        </div>
		
		
		
				        <div id="toast-disc_notvalid" class="toast-box toast-bottom bg-danger">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Discount amount not valid. Please try again</center>
                </div>
            </div>
        </div>
	        <div id="toast-amount_notvalid" class="toast-box toast-bottom bg-danger">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>Item amount not valid. Please try again</center>
                </div>
            </div>
        </div>
		
						        <div id="toast-fail0" class="toast-box toast-bottom bg-danger">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>The total is $0 so can't apply payment</center>
                </div>
            </div>
        </div>
		
								        <div id="toast-client_dup" class="toast-box toast-bottom bg-danger">
            <div style="text-align: center;" class="in">
                <div style="text-align: center;" class="text">
					<center>This client already is in system. Please select them from drop down list</center>
                </div>
            </div>
        </div>

    <!-- * welcome notification -->

    <!-- ///////////// Js Files ////////////////////  -->
    <!-- Jquery -->
    <script src="../assets/js/lib/jquery-3.4.1.min.js"></script>
	
	

	<script src="../js/jquery-ui.min.js"> </script>
	
    <!-- Bootstrap-->
    <script src="../assets/js/lib/popper.min.js"></script>
    <script src="../assets/js/lib/bootstrap.min.js"></script>
    <!-- Ionicons -->
    <script type="module" src="https://unpkg.com/ionicons@5.2.3/dist/ionicons/ionicons.js"></script>
  
    <!-- Base Js File -->
    <script src="../assets/js/base.js"></script>
	
	    <!-- phoenoxpos.app common -->
    <script src="../js/phxpos_comm.js"></script>
	    <script src="../js/phxcrm.js"></script>
    <!-- Owl Carousel -->

	 <script src="../js/jsBarcode.min.js"></script>
<script type="text/javascript" src="../ckeditor/ckeditor.js"></script>

    <script>
	
	
	
	    function deleteCookie(name) {
        setCookie(name, "", null , null , null, 1);
    }


	function check_loggedin(){
		
	//	alert ("check_loggedin");
		
		var staff_id = sessionStorage.getItem("phxcrmuserid");
		
	//	alert (staff_id);
		
		var loggedin = 0;
		
		if (staff_id == ""){
		}else if (staff_id === null){
					
		}else{

			var loggedin = 1;
			
		}
		
		
	//	alert (loggedin);
		
	//	if (typeof staff_id === 'undefined') {
			
			// Your variable is undefined
	//	}
		
	//	if (typeof staff_id === null) {
			
			// Your variable is undefined
	//	}
	
	if (loggedin == 0){
		
		document.getElementById("openstafflogin").click();
		
	}else{
		
		var sales_id_report = getCookie("phxcrm_sales_id_report");
		
	//	alert (sales_id_report);
		
		if (sales_id_report != "") {
	//		alert (" found");
				load_cart_fromreport(sales_id_report,0);
				setCookie("phxcrm_sales_id_report", 0, -365);
				setCookie("phxcrm_sales_id_sel", sales_id_report, 365);
				

			//	deleteCookie("phxcrm_sales_id_report");
				
			
		}else{
		//	alert ("not found");
			load_cart();
			get_quickpick_list();
		
		}
		
	}

	//	alert (staff_id + loggedin);
			
			
			
	}


$(document).ready(function(){
	
	
	
	//contact
	
		$("#tagsprodcont").autocomplete({

		source: "../php/searchcont.php",
		cacheLength: 0,
		minLength: 1,
		select: function (event, ui) {
			
		//	alert (ui.item.uid);
		
			document.getElementById("sel_uid_client").value = ui.item.uid;

			change_client(ui.item.uid);

		},
		}).data("ui-autocomplete")._renderItem = function (ul, item) {
			var highlighted = item.label.split(this.term).join('<strong>' + this.term +  '</strong>');
			let txt = String(item.value).replace(new RegExp(this.term, "gi"),"<b>$&</b>");
			return $("<li></li>")
				.data("item.autocomplete", item)
				.append("<a span style='font-family: \'Helvetica Neue\', Helvetica, Arial'>" + txt + "</a>")
				.appendTo(ul);

		};



 
	
	
	
	
	
	
	
	
	
	
	//contact
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	$("#tagsprodsearch").autocomplete({

		source: "../php/searchprod.php",
		cacheLength: 0,
		minLength: 1,
		select: function (event, ui) {
			
		//	alert (ui.item.uid);

			add_cart(ui.item.uid, 'uid');
			//add item to cart then reload card with latest item at top


		},
		}).data("ui-autocomplete")._renderItem = function (ul, item) {
			var highlighted = item.label.split(this.term).join('<strong>' + this.term +  '</strong>');
			let txt = String(item.value).replace(new RegExp(this.term, "gi"),"<b>$&</b>");
			return $("<li></li>")
				.data("item.autocomplete", item)
				.append("<a span style='font-family: \'Helvetica Neue\', Helvetica, Arial'>" + txt + "</a>")
				.appendTo(ul);

		};

$("#tagsprodsearch").keydown(function(event){
    if(event.keyCode == 13) {

      if($("#tagsprodsearch").val().length==0) {
          event.preventDefault();
		  
		//  alert ($("#tagsprodsearch").val());
		  
          return false;
      }else{
		   event.preventDefault();
		   
		   // go get item and if found add to cart.
		   
		   var search_string = $("#tagsprodsearch").val();
		   
		    var sales_id = $("#j_st_id").val();
		   
		   
		   
		//	alert ("enterno2"+$("#tagsprodsearch").val());
			
			var uid = 0;
			
			var qty = 1;
			
			$.ajax({
				url: '../php/additem.php',
				type: 'post',
				async: 'false',
				data: {"uid" : uid, "qty" : qty, "search_string" : search_string, "sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
					document.getElementById("tagsprodsearch").value = "";
					
					load_cart();
					
					

					
					
				//	if (data == "successful"){
						
				//				toastbox('toast-4', 2000);			

				//	}else{
												
				//		alert ("An error ocurred adding item "+data);
					
				//	}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
	  }
    }
 });

});


 
 

	function clear_search(type, value){
	
		document.getElementById("tagsprodsearch").value = "";
		product_search(type, value);
	
	}
	


    </script>

    <script>
	

	function load_cart(){
		
		var sales_id = sessionStorage.getItem('sel_job_id');
		
	//	alert ("load cart"+sales_id);
		
					
		document.getElementById("divcartitems").innerHTML = "loading ...";
		document.getElementById("divcarttotals").innerHTML = "";

		
		var type = "category";

		$.ajax({
				url: '../php/getquoteitems2.php',
				type: 'post',
				async: 'true',
				data: {"sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					
							document.getElementById("divcartitems").innerHTML = data;
							
						//	document.getElementById("currentsalesid").value = sales_id;
							
							load_cart_totals(sales_id);
							load_pos_fields(sales_id);

							
							
				//			alert ("setfocus done");
			

				}
			});



		
			
		
	}
	
		function load_cart_totals(sales_id){
		
		//s	alert ("load totals" + sales_id);
			
					

		

	//	alert ("in function "+value);
		
		var type = "category";
		
	//	var cat_id = 


		$.ajax({
				url: '../php/getcarttotals.php',
				type: 'post',
				async: 'true',
				data: {"sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					

							document.getElementById("divcarttotals").innerHTML = data;
							$('#tagsprodsearch').focus();

				}
			});



		
			
		
	}
	
	
	function load_pos_fields(cart_id){
		
//		alert (sessionStorage.getItem('sel_job_id'));
	//	alert ("loadpos"+cart_id);


	var cart_id = sessionStorage.getItem('sel_job_id');
	
	
//	sel_job_id

		$.ajax({
				url: '../php/getposfields.php',
				type: 'post',
				async: 'true',
				data: {"cart_id" : cart_id},
				success: function(data) {

				//	alert (data);

	                var obj = JSON.parse( data );
					
			//		alert (obj.job_descr);
					
					document.getElementById("sel_job_id").innerText = cart_id;

					document.getElementById("j_st_id").value = cart_id;
					
//					CKEDITOR.instances['j_job_descr_edit'].setData(obj.job_descr);
 
	//				var count_web_today 	  		= obj.count_web_today;
		//			var count_all_today 	  		= obj.count_all_today;
			//		var count_prog_today 	  		= obj.count_prog_today;
					
					var uid_client		 	  		= obj.uid_client;
					var comp_name		 	  		= obj.comp_name;
					var prog_status		 	  		= obj.prog_status;
					
					var st_outlet_id	 	  		= obj.st_outlet_id;
					
					
					var st_table		 	  		= obj.st_table;
					
					var phx_comp_name				= obj.phx_comp_name;
					var phx_username				= obj.phx_username;
					
					var comp_phys_addr1				= obj.comp_phys_addr1;
					var comp_phys_addr2				= obj.comp_phys_addr2;
					var comp_phys_addr3				= obj.comp_phys_addr3;
					var comp_website_url			= obj.comp_website_url;
					var comp_phone					= obj.comp_phone;
					
					var s_postline1					= obj.s_postline1;
					var s_postline2					= obj.s_postline2;
					var s_postline3					= obj.s_postline3;
					var s_postline4					= obj.s_postline4;
					var s_postline5					= obj.s_postline5;
					
					var s_postcountry				= obj.s_postcountry;
					
					var sales_cust_disc				= obj.sales_cust_disc;
					
					var status						= obj.status;
					var staff_sec_level				= obj.staff_sec_level;
					
					
//					document.getElementById("count_web_today").innerText = count_web_today;

				//	document.getElementById("count_all_today").innerText = count_all_today;
				//	document.getElementById("count_prog_today").innerText = count_prog_today;
					
					document.getElementById("tagsprodcont").value = comp_name;
					document.getElementById("sel_uid_client").value = uid_client;
					
					document.getElementById("phx_comp_name").value = phx_comp_name;
					
					document.getElementById("phx_username").value = phx_username;
					
					document.getElementById("comp_phys_addr1").value = comp_phys_addr1;
					document.getElementById("comp_phys_addr2").value = comp_phys_addr2;					
					document.getElementById("comp_phys_addr3").value = comp_phys_addr3;
					document.getElementById("comp_website_url").value = comp_website_url;
					document.getElementById("comp_phone").value = comp_phone;
					
					document.getElementById("sales_cust_disc").value = sales_cust_disc;
					
					document.getElementById("job_status").value = status;
					
					
					//set order delivery address
					
					document.getElementById("s_postline1").value = s_postline1;		
					document.getElementById("s_postline2").value = s_postline2;	
					document.getElementById("s_postline3").value = s_postline3;	
					document.getElementById("s_postline4").value = s_postline4;	
					document.getElementById("s_postline5").value = s_postline5;	
					
					
					let element = document.getElementById("next_stage");
					element.value = prog_status;
					
					let elementc = document.getElementById("s_postcountry");
					elementc.value = s_postcountry;
					
					let elemento = document.getElementById("st_outlet_id");
					elemento.value = st_outlet_id;
					
			//		alert (st_outlet_id);
			
		//	alert (staff_sec_level);
			
			
			
			//set the void button
			
			if (staff_sec_level == "Superuser"){
			
				if (status == "New"){

					document.getElementById("allvoidsale").style.display="none";

				}else if (status == "Park"){

					document.getElementById("allvoidsale").style.display="none";

				}else if (status == "Account"){

					document.getElementById("allvoidsale").style.display="block";

				}else if (status == "Paid"){

					document.getElementById("allvoidsale").style.display="block";

				}else if (status == "Void"){

					document.getElementById("allvoidsale").style.display="none";

				}
			}else{

				document.getElementById("allvoidsale").style.display="none";
				
			}
			
			
			//
			
			if (status == "Void"){

					document.getElementById("divshowpaymentactions").style.display="block";
					document.getElementById("divshowquickpickitems").style.display="none";
					document.getElementById("divshowvoidstatus").style.display="block";
					
			}else{
					document.getElementById("divshowpaymentactions").style.display="block";
					document.getElementById("divshowquickpickitems").style.display="block";
					document.getElementById("divshowvoidstatus").style.display="none";
				
				
			}
			
			
			//		alert (st_table);
					
//					let elementst_table = document.getElementById("table_id");
	//				elementst_table.value = st_table;
					
				//	alert (prog_status);
					
				//	alert (count_web_today);
					
					if (count_web_today == "0"){
					
//						document.getElementById("count_web_today").className = "badge badge-success";
						
					}else{
					
//						document.getElementById("count_web_today").className = "badge badge-WARNING";
						
					}
					
					

				//			document.getElementById("divcarttotals").innerHTML = data;

				}
			});
		
		
	}
	
					
	function upd_cart(client_id, cart_function, cart_uid){
		
		var newqty = 0;
		
		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
				//	var new_item_amount   	= "$"+obj.new_item_amount;
					
					if (phx_result == ""){
						
						load_cart();			

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
							
	function upd_cart_supp(client_id, cart_function, cart_uid, newqty){
		
	

		var newqty = newqty;
		

		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var sales_id 	  		= obj.sales_id;
					var new_line_amount   	= "$"+obj.new_line_amount;
					
					if (cart_function == "addqtysupp"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						
						var qty_supp_field = "qty_supp_"+cart_uid;
						
						document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
						
					}
					
					if (cart_function == "subqtysupp"){
						
				//		alert ("init");
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						
						var qty_supp_field = "qty_supp_"+cart_uid;
						
						document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
						
					}
					
					if (cart_function == "newqtysupp"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						
						var qty_supp_field = "qty_supp_"+cart_uid;
						
						document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
						
					}
					
					if (phx_result == ""){
						
								//update item line qty
							var line_amount_field = "line_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(line_amount_field).value = new_line_amount;
								
							load_cart_totals(sales_id);
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
						
	function upd_cart_qty(client_id, cart_function, cart_uid, newqty, sales_id2){
		
	

		var newqty = newqty;
		

		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty, "cart_id" : sales_id2},
				success: function(data) {
					
//					alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var sales_id 	  		= obj.sales_id;
					var comp_stock_type		= obj.comp_stock_type;
					var new_line_amount   	= "$"+obj.new_line_amount;
					
					if (cart_function == "addqty"){
						

						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
						document.getElementById(qty_field).value = new_qty;						
						var qty_field = "qty_"+cart_uid;
						
						//						alert (new_qty_supp);


					//	alert (comp_stock_type);
						
						if (comp_stock_type == "0"){
	
						}else{
						
							var qty_supp_field = "qty_supp_"+cart_uid;
						
							document.getElementById(qty_supp_field).value = new_qty_supp;

							var qty_bo_field = "qty_bo_"+cart_uid;
						
							document.getElementById(qty_bo_field).value = new_qty_bo;
							
							var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
							document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
						}					
						
					}
					
					if (cart_function == "subqty"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
						document.getElementById(qty_field).value = new_qty;						
						var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);

						if (comp_stock_type == "0"){
	
						}else{
						
						var qty_supp_field = "qty_supp_"+cart_uid;
						
						document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
						}
						
					}
					
					if (cart_function == "newqty"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
						document.getElementById(qty_field).value = new_qty;						
						var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);

						if (comp_stock_type == "0"){
	
						}else{
						
						var qty_supp_field = "qty_supp_"+cart_uid;
						
						document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
						}	
							
							
						
					}
					
					if (phx_result == ""){
						
								//update item line qty
							var line_amount_field = "line_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(line_amount_field).value = new_line_amount;
							
						//	alert (sales_id2);
							
														$.ajax({
				url: '../php/getcarttotals.php',
				type: 'post',
				async: 'true',
				data: {"sales_id" : sales_id2},
				success: function(data) {
					
				//	alert (data);
					

							document.getElementById("divcarttotals").innerHTML = data;
				//			$('#tagsprodsearch').focus();

				}
			});
								
						//	load_cart_totals(sales_id);
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
							
	function upd_cart_bo(client_id, cart_function, cart_uid, newqty){
		
	

		var newqty = newqty;
		

		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
			//		alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var sales_id 	  		= obj.sales_id;
					var new_line_amount   	= "$"+obj.new_line_amount;
					
					if (cart_function == "addqtybo"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
				//		document.getElementById(qty_field).value = new_qty;						
				//		var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);
						
				//		var qty_supp_field = "qty_supp_"+cart_uid;
						
				//		document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
							
							
						
					}
					
					if (cart_function == "subqtybo"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
				//		document.getElementById(qty_field).value = new_qty;						
				//		var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);
						
				//		var qty_supp_field = "qty_supp_"+cart_uid;
						
				//		document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
						
					}
					
					if (cart_function == "newqtybo"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
				//		document.getElementById(qty_field).value = new_qty;						
				//		var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);
						
				//		var qty_supp_field = "qty_supp_"+cart_uid;
						
				//		document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
							
						
					}
					
					if (phx_result == ""){
						
								//update item line qty
							var line_amount_field = "line_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(line_amount_field).value = new_line_amount;
								
							load_cart_totals(sales_id);
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
	function upd_cart_bo_pay(client_id, cart_function, cart_uid, newqty){
		
	

		var newqty = newqty;
		

		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var sales_id 	  		= obj.sales_id;
					var new_line_amount   	= "$"+obj.new_line_amount;
					
					if (cart_function == "addqtybopay"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
				//		document.getElementById(qty_field).value = new_qty;						
				//		var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);
						
				//		var qty_supp_field = "qty_supp_"+cart_uid;
						
				//		document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
						
							
						
					}
					
					if (cart_function == "subqtybopay"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
				//		document.getElementById(qty_field).value = new_qty;						
				//		var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);
						
				//		var qty_supp_field = "qty_supp_"+cart_uid;
						
				//		document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
						
							
							
						
					}
					
					if (cart_function == "newqtybopay"){
						
						var new_qty_supp 	  		= obj.new_qty_supp;
						var new_qty_bo	 	  		= obj.new_qty_bo;
						var new_qty_bo_pay 	  		= obj.new_qty_bo_pay;
						var new_qty 	  			= obj.new_qty;
						
						var qty_field = "qty_"+cart_uid;
						
				//		document.getElementById(qty_field).value = new_qty;						
				//		var qty_field = "qty_"+cart_uid;
						
//						alert (new_qty_supp);
						
				//		var qty_supp_field = "qty_supp_"+cart_uid;
						
				//		document.getElementById(qty_supp_field).value = new_qty_supp;

						var qty_bo_field = "qty_bo_"+cart_uid;
						
						document.getElementById(qty_bo_field).value = new_qty_bo;
							
						var qty_bo_pay_field = "qty_bo_pay_"+cart_uid;
						
						document.getElementById(qty_bo_pay_field).value = new_qty_bo_pay;
							
							
						
					}
					
					if (phx_result == ""){
						
								//update item line qty
							var line_amount_field = "line_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(line_amount_field).value = new_line_amount;
								
							load_cart_totals(sales_id);
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
		function make_order(cart_id, disc){
			
			var cart_id = cart_id;
		
			var totalitems = document.getElementById("totalitems").value;
	
			// do da validations
			
	//		alert (totalitems);
	
	//		if (disc == 1){
				
				//then friends and family so no minimum order qty
				
		//	}else{
	//	
			//	if (totalitems >= 60){
		//
	//			}else{
//	
	//				toastbox('toast-1', 2000);	
	//					
	//				return false;
	//			
	//			}
	//			
	//		}


			window.location.href = "make_order.php?sales_id="+cart_id;
		

			

	}
	
		function apply_voucher(client_id){
		
		
		var voucher_code = document.getElementById("voucher_code").value;

		var client_id = client_id;
		
		var cart_uid = 0;
		var newqty = 0;
		
		
		if (voucher_code.toLowerCase() == "yourspecial"){
			
			var cart_function = "removedelivery";
			
		}else{
			
			toastbox('toast-8', 2000);	

			return false;

				
		}
		
		
				$.ajax({
					url: '../php/updcart.php',
					type: 'post',
					async: 'false',
					data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
					success: function(data) {
					
					//	alert (data);
					
						var obj = JSON.parse( data );
					
						var phx_result 	  	= obj.phx_result;
					
						if (phx_result == ""){
						
							load_cart_totals();
							document.getElementById("voucher_code").value = "";
							toastbox('toast-9', 2000);	
							
					//	alert ("success");
						
//						toastbox('toast-success', 2000);	
						}else{
							alert ("an error occurred"+phx_result);
						}

					}
				});
					

	}
	
	

	
	$('#DialogStaffLogin').on('shown.bs.modal', function () {
		
	//	alert ("shown");
		

//		$('#tagsstaffpw').value = "";
	//	$('#Bullets').value = "";
		clear_charp();
		
//		alert ("1");
	//	$('#tagsstaffpw').focus();
		document.getElementById("tagsstaffpw").focus();
		document.getElementById("tagsstaffpw").select();
	//	alert ("2");
		document.getElementById("tagsstaffpw").style.borderBottom = "solid";
	//	alert ("done");
		
		

}) 
$('#DialogCr8Client').on('shown.bs.modal', function () {
	
//	alert ("cash");



	var tagsprodcont = document.getElementById("tagsprodcont").value;

const words = tagsprodcont.split(" ");

for (let i = 0; i < words.length; i++) {
    words[i] = words[i][0].toUpperCase() + words[i].substr(1);
}



	document.getElementById("dispclientname").innerHTML = words.join(" ");
	document.getElementById("tagsprodcontnew").value = words.join(" ");
	
	
	
	

}) 


$('#DialogCr8Client').on('hidden.bs.modal', function () {
	
	 var curr_sales_id = getCookie("phxcrm_sales_id");
	
	load_pos_fields(curr_sales_id);

}) 


$('#DialogCash').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var ttl_due = document.getElementById("totaldue").value;

	if (ttl_due == 0){
		$('#DialogCash').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}


	document.getElementById("disptotalsalecash").innerHTML = "The Client is paying <br><strong>$"+ttl_due+"</strong> in Cash";
	
	
	

}) 


$('#DialogEftpos').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var ttl_due = document.getElementById("totaldue").value;

	if (ttl_due == 0){
		$('#DialogEftpos').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}

	document.getElementById("disptotalsaleeftpos").innerHTML = "The Client is paying <br><strong>$"+ttl_due+"</strong> in Eftpos";
	
		
		var comp_eftpos_type = document.getElementById("comp_eftpos_type").value;
	
//		alert (comp_eftpos_type);
		if (comp_eftpos_type == "Windcave"){
			windcave_request_payment(ttl_due);
		}
			
	

}) 


$('#DialogCreditCard').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var ttl_due = document.getElementById("totaldue").value;

	if (ttl_due == 0){
		$('#DialogCreditCard').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}

	document.getElementById("disptotalsalecreditcard").innerHTML = "The Client is paying <br><strong>$"+ttl_due+"</strong> by Credit Card";
	
	
	

}) 


$('#DialogCreditCardfee').on('shown.bs.modal', function () {
	
//	alert ("cash");

	var sel_fee_perc	= document.getElementById("sel_fee_perc").value;
	var sel_fee_base	= document.getElementById("sel_fee_base").value;
	var sel_fee_curr	= document.getElementById("sel_fee_curr").value
	
	sel_fee_base = parseFloat(sel_fee_base).toFixed(2);
	sel_fee_curr = parseFloat(sel_fee_curr).toFixed(2);

	
	var ttl_due = document.getElementById("totaldue").value;
//	var ttl_due = document.getElementById("totaldue").value;
	
	

	if (ttl_due == 0){
		$('#DialogCreditCardfee').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}

	document.getElementById("disptotalsalecreditcardfee").innerHTML = 'The Client is paying <strong>$<input style="width: 100px"  type="text" onchange="javascript: change_fee(this.value)" id="cardfeettlbycard" name="cardfeettlbycard" value='+sel_fee_base+'></strong> by Credit Card. <br> Therefore fee will be $<input readonly  style="width: 100px; border: none" type="text" id="cardfeecalc" name="cardfeecalc" value='+sel_fee_curr+'>';
	
	
	

}) 


$('#DialogAccount').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var ttl_due = document.getElementById("totaldue").value;


	if (ttl_due == 0){
		$('#DialogAccount').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}
	document.getElementById("disptotalsaleAccount").innerHTML = "The Client is paying <br><strong>$"+ttl_due+"</strong> by Account";
	
	
	

}) 



$('#DialogVoucher').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var ttl_due = document.getElementById("totaldue").value;


	if (ttl_due == 0){
		$('#DialogVoucher').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}
	document.getElementById("disptotalsaleVoucher").innerHTML = "The Client is paying <br><strong>$"+ttl_due+"</strong> by Voucher";
	
	
	

}) 



$('#DialogLaybuy').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var ttl_due = document.getElementById("totaldue").value;


	if (ttl_due == 0){
		$('#DialogLaybuy').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}
	document.getElementById("disptotalsaleLaybuy").innerHTML = "The Client is paying <br><strong>$"+ttl_due+"</strong> by Laybuy";
	
	
	

})

$('#DialogSplit').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var ttl_sale = document.getElementById("totalsale").value;
	var ttl_due = document.getElementById("totaldue").value;
	var ttl_change = 0;


	if (ttl_due == 0){
		$('#DialogSplit').modal('hide');
		toastbox('toast-fail0', 2000);
		return false();
	}else{
		
	}
	document.getElementById("disptotalsaleSplit").innerHTML = "Total Sale: "+ttl_sale+" The Client is now paying <br><strong>$&nbsp;&nbsp;<input id='pay_amt' style='width: 100px; text-align: right; display: inline;'   onchange='javascript: process_amt(this.value)'  class='form-control'  value="+ttl_due+"></strong><div id='pay_amt_err' style='display: none'><span style='color: red;'>Error in amount.</span></div> by :";

	document.getElementById("disptotalsaleSplitchange").innerHTML = "Change/Remaining: $<strong><input readonly id='ttl_change' style='width: 100px; text-align: right'  class='form-control'  value="+ttl_change+" ></strong>";

	
		document.getElementById("pay_amt").focus();
	document.getElementById("pay_amt").select();

	

})

function exec_openstafflogin(){
	
	document.getElementById("openstafflogin").click();
//	alert ("clicked");
	
	
}


function add_charp(val){
	
	var cur_val = document.getElementById("tagsstaffpw").value;

	var new_val = String(cur_val)+String(val);
	
	
	var pin_length = new_val.length;
	
//	alert (pin_length);
	
	if (pin_length == 0){
		new_val_disp = "";	
	}else if (pin_length == 1){
		new_val_disp = "*";	
	}else if (pin_length == 2){
		new_val_disp = "**";	
	}else if (pin_length == 3){
		new_val_disp = "***";	
	}else if (pin_length == 4){
		new_val_disp = "****";	
	}else{

		return false;
		
	}
	
	document.getElementById("tagsstaffpw").value = new_val;
	
	document.getElementById("Bullets").value = new_val;

	document.getElementById('Bullets').value=new_val.replace(/(.)/g,'•');


	
}



function add_charp_input(val){
	
	
//	alert ("addinput"+val);
	
	var new_val = document.getElementById("tagsstaffpwdisp").value;
	var full_val = document.getElementById("tagsstaffpw").value;
	
    var length = new_val.length;

	var position = length -1;
	
	result = new_val.substring(position, position + length);
	
	var full_val = String(full_val)+String(result);
	
	document.getElementById("tagsstaffpw").value = full_val;
	
	
	var pin_length = full_val.length;
	
//	alert (pin_length);
	
	if (pin_length == 0){
		new_val_disp = "";	
	}else if (pin_length == 1){
		new_val_disp = "*";	
	}else if (pin_length == 2){
		new_val_disp = "**";	
	}else if (pin_length == 3){
		new_val_disp = "***";	
	}else if (pin_length == 4){
		new_val_disp = "****";	
	}else{

		return false;
		
	}
	
	document.getElementById("tagsstaffpwdisp").value = new_val_disp;
	


	
}


function clear_charp(){
	
//	alert ("clear");
	

	var new_val = "";

	document.getElementById("tagsstaffpw").value = new_val;
	document.getElementById("Bullets").value = new_val;


	document.getElementById("tagsstaffpw").focus();


}




function logout_staff(){



	window.location.replace("../php/logout.php");

//	alert ("logout staff");

	
}


		
	function add_cart(uid, type){
	
	var qty = 1;
	
	var sales_id = $("#j_st_id").val();
		
		// add item
		
		$.ajax({
				url: '../php/additem.php',
				type: 'post',
				async: 'false',
				data: {"uid" : uid, "qty" : qty, "sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
					document.getElementById("tagsprodsearch").value = "";
					
					load_cart();
					
					

					
					
				//	if (data == "successful"){
						
				//				toastbox('toast-4', 2000);			

				//	}else{
												
				//		alert ("An error ocurred adding item "+data);
					
				//	}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
	function dragItqp(theEvent, prodserv_uid) {
 //tell the browser what to drag
	theEvent.dataTransfer.setData("Text", theEvent.target.id);
	sessionStorage.setItem("sel_qp_id", prodserv_uid);
	
	

 
}


function dropItqp(theEvent) {
	
//	alert ("drop");
	
	theEvent.preventDefault();
	
	var sel_prod_id = sessionStorage.getItem("sel_qp_id");
	
	
	//do something
	
		if (sel_prod_id === null){
			
		//	nothing dragged that is expected;
			
		}else{
			
			// call ajax and add item to quickpick
			
			var action = "rempick";
			
			$.ajax({
				url: '../php/updquickpick.php',
				type: 'post',
				async: 'false',
				data: {"prod_uid" : sel_prod_id, "action" : action},
				success: function(data) {
					
				//	alert (data);
					
					get_quickpick_list();
					
					//	var data = data.trim();
					
					//	document.getElementById("tagsprodsearch").value = "";
					//	
					//	load_cart();

				}
			});

			
		}
	
	
	sessionStorage.removeItem("sel_qp_id");
	
	

	
//	console.log(theEvent);
	
	return false;
	
//get a reference to the element being dragged
var theData = theEvent.dataTransfer.getData("Text");
//get the element
var theDraggedElement = document.getElementById(theData);
//add it to the drop element
theEvent.target.appendChild(theDraggedElement);
//instruct the browser to allow the drop

}
	
function dragIt(theEvent, prodserv_uid) {
 //tell the browser what to drag
	theEvent.dataTransfer.setData("Text", theEvent.target.id);
	sessionStorage.setItem("sel_prod_id", prodserv_uid);
	
	

 
}

//function called when element drops
function dropIt(theEvent) {
	
	theEvent.preventDefault();
	
	var sel_prod_id = sessionStorage.getItem("sel_prod_id");
	
	
	//do something
	
		if (sel_prod_id === null){
			
		//	nothing dragged that is expected;
			
		}else{
			
			// call ajax and add item to quickpick
			
			var action = "addpick";
			
			$.ajax({
				url: '../php/updquickpick.php',
				type: 'post',
				async: 'false',
				data: {"prod_uid" : sel_prod_id, "action" : action},
				success: function(data) {
					
				//	alert (data);
					
					get_quickpick_list();
					
					//	var data = data.trim();
					
					//	document.getElementById("tagsprodsearch").value = "";
					//	
					//	load_cart();

				}
			});

			
		}
	
	
	sessionStorage.removeItem("sel_prod_id");
	
	

	
//	console.log(theEvent);
	
	return false;
	
//get a reference to the element being dragged
var theData = theEvent.dataTransfer.getData("Text");
//get the element
var theDraggedElement = document.getElementById(theData);
//add it to the drop element
theEvent.target.appendChild(theDraggedElement);
//instruct the browser to allow the drop

}

	  function load_todays_sales() {
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		         document.getElementById("divtodaysalesreport").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "../php/todaysalesshop2.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}



	  function load_todays_sales_web() {
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		         document.getElementById("divtodaysaleswebreport").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "../php/todaysalesweb.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}

	  function load_todays_sales_prog() {
			
		//		var e =  document.getElementById('Outlet_ID');
		//		var outlet_id =  e.options[e.selectedIndex].value;
		
		var outlet_id = 1;

				var currentTime = new Date();

		        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
					xmlhttp = new XMLHttpRequest();
				}
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		         document.getElementById("divtodaysalesprog").innerHTML = xmlhttp.responseText;
			}
        }
        xmlhttp.open("GET", "../php/todaysalesprog.php?outlet_id="+outlet_id+"&reqtime=" + currentTime, true);
        xmlhttp.send();
	
}

function get_quickpick_list(){
	
	return false;
	

			var sel_prod_id = 0;
			var action = "";

			$.ajax({
				url: '../php/getquickpick.php',
				type: 'post',
				async: 'false',
				data: {"prod_uid" : sel_prod_id, "action" : action},
				success: function(data) {
					
		//			alert (data);
					
					
						document.getElementById("divshowquickpickitems").innerHTML = data;

				}
			});	
	
}


function add_item_quickpick(uid){


			
			var qty = 1;
			var sales_id = $("#j_st_id").val();
			
			
			$.ajax({
				url: '../php/additem.php',
				type: 'post',
				async: 'false',
				data: {"uid" : uid, "qty" : qty, "sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
					document.getElementById("tagsprodsearch").value = "";
					
					load_cart();
					
					

					
					
				//	if (data == "successful"){
						
				//				toastbox('toast-4', 2000);			

				//	}else{
												
				//		alert ("An error ocurred adding item "+data);
					
				//	}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});	
	
}

			
		function cs_full(action, pay_type, prog_status) {
			
		//	alert ("cs_full"+pay_type);
			
			
			var sales_id =  document.getElementById('currentsalesid').value;
			
			var ttl_sale = document.getElementById("totalsale").value;
			
			var pay_type = pay_type;
			
			var prog_status = prog_status;
			
			var action = action;
			
			//check if receipt required
			
			var receipt_reqd = 0;
			
			if (action == "allpay"){
				
				if (pay_type == "Cash"){
					receipt_cash = document.getElementById('receipt_cash').checked;
					
				//	alert (receipt_cash);
					
					if (receipt_cash){
						
						receipt_reqd = 1;
					
					//	alert ("print receipt");
						
					}else{

					//	alert ("NO print receipt");
						
					}
					
				}


				if (pay_type == "Eftpos"){
					receipt_eftpos = document.getElementById('receipt_eftpos').checked;
					
				//	alert (receipt_cash);
					
					if (receipt_eftpos){
						
						receipt_reqd = 1;
					
					//	alert ("print receipt");
						
					}else{

					//	alert ("NO print receipt");
						
					}
					
				}				




				if (pay_type == "Credit Card"){
					receipt_credit_card = document.getElementById('receipt_credit_card').checked;
					
				//	alert (receipt_cash);
					
					if (receipt_credit_card){
						
						receipt_reqd = 1;
					
					//	alert ("print receipt");
						
					}else{

					//	alert ("NO print receipt");
						
					}
					
				}				
	


				if (pay_type == "Account"){
					receipt_account = document.getElementById('receipt_account').checked;
					
				//	alert (receipt_cash);
					
					if (receipt_account){
						
						receipt_reqd = 1;
					
					//	alert ("print receipt");
						
					}else{

					//	alert ("NO print receipt");
						
					}
					
				}		



				if (pay_type == "Voucher"){
					receipt_voucher = document.getElementById('receipt_voucher').checked;
					
				//	alert (receipt_cash);
					
					if (receipt_voucher){
						
						receipt_reqd = 1;
					
					//	alert ("print receipt");
						
					}else{

					//	alert ("NO print receipt");
						
					}
					
				}


				if (pay_type == "Laybuy"){
					receipt_laybuy = document.getElementById('receipt_laybuy').checked;
					
				//	alert (receipt_cash);
					
					if (receipt_laybuy){
						
						receipt_reqd = 1;
					
					//	alert ("print receipt");
						
					}else{

					//	alert ("NO print receipt");
						
					}
					
				}				
			}
			

			
			if (action == "partpay"){
				
				var ttl_paid_now = document.getElementById('pay_amt').value;
				
			//	alert ("checked"+document.getElementById("option8").checked);
				
			//	alert (document.getElementById("option8"));
				
				
				
				
				   if (document.getElementById("option1") !==null) {
					   
					//    alert ("check for Cash");
						if (document.getElementById("option1").checked){
					
							var pay_sel_type = "Cash";
					
						}
						
				   }
					   
					   
				   if (document.getElementById("option2") !==null) {
					   
						if (document.getElementById("option2").checked){
					
							var pay_sel_type = "Eftpos";
					
						}
						
				   }
	
				   if (document.getElementById("option3") !==null) {
					   
						if (document.getElementById("option3").checked){
					
							var pay_sel_type = "Credit Card";
					
						}
								   
				   }
				   
				   if (document.getElementById("option4") !==null) {
					   
						if (document.getElementById("option4").checked){
					
							var pay_sel_type = "Account";
					
						}
								   
				   }
				   
				   if (document.getElementById("option5") !==null) {
					   
						if (document.getElementById("option5").checked){
					
							var pay_sel_type = "Voucher";
					
						}
								   
					   	
				   }

				   if (document.getElementById("option6") !==null) {
					   
						if (document.getElementById("option6").checked){
					
							var pay_sel_type = "Laybuy";
					
						}
								   
				   }   	
					   					   					   
				 
				   
				   if (document.getElementById("option7") !==null) {
					   
						if (document.getElementById("option7").checked){
					
							var pay_sel_type = "Bartercard";
					
						}
								   
				   }	   	
					   					   		  	   
				  if (document.getElementById("option8") !==null) {
					   
				//	   alert ("check for park");
					   
						if (document.getElementById("option8").checked){
							
						//	alert ("yes park");
					
							var pay_sel_type = "Park";
					
						}
								   
				  }   	
					   					   					   
				   if (document.getElementById("option9") !==null) {
					   
						if (document.getElementById("option9").checked){
					
							var pay_sel_type = "Paypal";
					
						}
								   
					   	
					   						   														   					   					   
					   
				   }
				


				
				var pay_type = pay_sel_type;
				
			//	alert (pay_type);
				
				
			}else{
			
				var pay_sel_type ="";
				var ttl_paid_now = ttl_sale;
			
			}
			$.ajax({
				url: '../php/comp_sale.php',
				type: 'post',
				async: 'false',
				data: {"sales_id" : sales_id, "pay_type" : pay_type, "ttl_paid_now" : ttl_paid_now,"ttl_sale" : ttl_sale, "pay_action": action, "pay_sel_type": pay_sel_type, "prog_status": prog_status},
				success: function(data) {
			//		alert ("success"+data);
					
					obj = JSON.parse(data);
					
					var sales_id = obj.new_sales_id;

					if (obj.obhok == "Yes"){
						
						
					}else{

						alert(obj.obhmsg);
					
						return false;
					
						
					}
					
					if (obj.complete_sale == "1"){
						
						var tillport = obj.tillport;
						
						if (tillport == "None"){
							
						}else{
						
							$.ajax({
								url: 'http://localhost/utils/opendrawer.php',
								type: 'post',
								async: 'true',
								data: {"tillport" : tillport},
								success: function(data) {
					
							//		alert ("done"+data);
							
									}
			 
							})

						}
						
							
						//	alert ("1");
						toastbox('toast-sale-successful', 2000);
						
//						document.getElementById("curr_sales_id").value = sales_id;

						
									if (receipt_reqd == 1){
				
		//			alert ("view receipt");
					
							//load_cart();
									document.getElementById("printorder").click();

			}else{
				
										document.getElementById("currentsalesid").value = sales_id;
					
						load_cart();
				
			}

						//close modal
						
						$('#DialogSplit').modal('hide');
					

					}else if (obj.complete_sale == "2"){
							
						//	alert ("1");
						toastbox('toast-sale-parked', 2000);
						
//						document.getElementById("curr_sales_id").value = sales_id;
						document.getElementById("currentsalesid").value = sales_id;
					
						load_cart();

						//close modal
						
						$('#DialogSplit').modal('hide');

					
					}else{
						
//						alert ("ttl paid is "+obj.ttl_paid);
	//					alert ("ttl totaldue is "+obj.ttl_due);
						
						ttl_due_disp =  parseFloat(obj.ttl_due).toFixed(2);
						ttl_paid_disp =  parseFloat(obj.ttl_paid).toFixed(2);
						
						document.getElementById("pay_amt").value = ttl_due_disp;
						document.getElementById("totaldue").value = ttl_due_disp;
						document.getElementById("totalpaid").value = ttl_paid_disp;						
						
					//	alert ("not complete");
						
							
					}
					
					//if tillport set then open register



					//if all ok tell user with toastbox and go to next sale
					
					//only do this is fully complete
					

					
	
				}
			 
		 })
		
		 

}	


	function product_search(type, value){
		
			
	//	alert ("type is" + type + "value is"+value);
			
		
		document.getElementById("divsearchresults").innerHTML = "loading ...";
		

	//	alert ("in function "+value);
		
		var type = type;
		var value = value;
		
	//	var cat_id = 


		$.ajax({
				url: '../php/getprodsearch.php?type='+type,
				type: 'post',
				async: 'false',
				data: {"type" : type, "value" : value},
				success: function(data) {
					
			//	alert (data);
					

							document.getElementById("divsearchresults").innerHTML = data;

				}
			});



		

	}
	

	
	function process_amt(value){
	
	//	alert (value);

		var regex = /^[1-9]\d*(((,\d{3}){1})?(\.\d{0,2})?)$/;
		var number = value;
		
		if (regex.test(number)){
		//	alert("Number is valid");
			document.getElementById("pay_amt").style.borderColor = "rgb(255, 255, 255)";
			document.getElementById("pay_amt_err").style.display = "none";
		}else{
			document.getElementById("pay_amt").style.borderColor = "red";
			document.getElementById("pay_amt_err").style.display = "block";
			
			

		}
		
		var ttl_due = document.getElementById("totaldue").value;
		var change = ttl_due - value;

		pay_amt = parseFloat(value).toFixed(2);
		
		document.getElementById("pay_amt").value = pay_amt;
		
		change = parseFloat(change).toFixed(2);
		
		document.getElementById("ttl_change").value = change;
		
		

		
	
	}


	function paytabsel(option){
		
	//	alert (option);
		
		if (option == "option1"){
			

			var element2 = document.getElementById("option2");
				element2.removeClass("active");
			var element3 = document.getElementById("option3");
				element3.removeClass("active");
			var element4 = document.getElementById("option4");
				element4.removeClass("active");
			var element5 = document.getElementById("option5");
				element5.removeClass("active");
			var element6 = document.getElementById("option6");
				element6.removeClass("active");
			var element7 = document.getElementById("option7");
				element7.removeClass("active");			
		}else if (option == "option2"){

			var element1 = document.getElementById("option1");
				element1.removeClass("active");
			var element3 = document.getElementById("option3");
				element3.removeClass("active");
			var element4 = document.getElementById("option4");
				element4.removeClass("active");
			var element5 = document.getElementById("option5");
				element5.removeClass("active");
			var element6 = document.getElementById("option6");
				element6.removeClass("active");
			var element7 = document.getElementById("option7");
				element7.removeClass("active");	

		}else if (option == "option3"){

			var element1 = document.getElementById("option1");
				element1.removeClass("active");
			var element2 = document.getElementById("option2");
				element2.removeClass("active");
			var element4 = document.getElementById("option4");
				element4.removeClass("active");
			var element5 = document.getElementById("option5");
				element5.removeClass("active");
			var element6 = document.getElementById("option6");
				element6.removeClass("active");
			var element7 = document.getElementById("option7");
				element7.removeClass("active");	
		}else if (option == "option4"){
			
			var element1 = document.getElementById("option1");
				element1.removeClass("active");
			var element2 = document.getElementById("option2");
				element2.removeClass("active");
			var element3 = document.getElementById("option3");
				element3.removeClass("active");
			var element5 = document.getElementById("option5");
				element5.removeClass("active");
			var element6 = document.getElementById("option6");
				element6.removeClass("active");
			var element7 = document.getElementById("option7");
				element7.removeClass("active");	

		}else if (option == "option5"){
			
			var element1 = document.getElementById("option1");
				element1.removeClass("active");
			var element2 = document.getElementById("option2");
				element2.removeClass("active");
			var element3 = document.getElementById("option3");
				element3.removeClass("active");
			var element4 = document.getElementById("option4");
				element4.removeClass("active");
			var element6 = document.getElementById("option6");
				element6.removeClass("active");
			var element7 = document.getElementById("option7");
				element7.removeClass("active");	

		}else if (option == "option6"){
			
			var element1 = document.getElementById("option1");
				element1.removeClass("active");
			var element2 = document.getElementById("option2");
				element2.removeClass("active");
			var element3 = document.getElementById("option3");
				element3.removeClass("active");
			var element4 = document.getElementById("option4");
				element4.removeClass("active");
			var element5 = document.getElementById("option5");
				element5.removeClass("active");
			var element7 = document.getElementById("option7");
				element7.removeClass("active");
				
			}else if (option == "option7"){
			
			var element1 = document.getElementById("option1");
				element1.removeClass("active");
			var element2 = document.getElementById("option2");
				element2.removeClass("active");
			var element3 = document.getElementById("option3");
				element3.removeClass("active");
			var element4 = document.getElementById("option4");
				element4.removeClass("active");
			var element5 = document.getElementById("option5");
				element5.removeClass("active");
			var element6 = document.getElementById("option6");
				element6.removeClass("active");	
	}
	
	}
	
			function get_contact_edit(uid_client){
		
	//	alert (uid_client);
		
		
			var uid_client = uid_client;
			
	
			$.ajax({
				url: '../php/custeditshop.php',
				type: 'post',
				async: 'false',
				data: {"uid_client" : uid_client},
				success: function(data) {
					
					var data = data.trim();
					
					document.getElementById("divcontedit").innerHTML = data;
					
					$("#c_cust_since").datepicker();
					
												 
CKEDITOR.replace('c_favcmts', {
		           on: {
            instanceReady: function (ev) {
                this.dataProcessor.writer.setRules('p', {
                    breakAfterClose: false
                });
            }
			   },
	 toolbar: [
   [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ],
   { name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule', 'SpecialChar' ] },
   { name: 'font', items: ['Font','FontSize'] },
   '/',
   { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline','-','JustifyLeft','JustifyCenter','JustifyRight','-','NumberedList','BulletedList','-','Link','Unlink','-','Source' ] },
   { name: 'colors', items: [ 'TextColor', 'BGColor' ] },
   { name: 'tools', items: [ 'Maximize' ] }
  ]
}
);


				CKEDITOR.instances['c_favcmts'].on('blur', function(e) {
				    if (e.editor.checkDirty()) {
						
						update_field_contact('c_favcmts', 'ckeditor', '')
					
					//	 update_field_product('prod_descr', 'ckeditor', '');
      
				//	alert("editjd2");
				}
				});
				
					
				}
			});	
		
		
	}
	
		
	$('#DialogContEdit').on('shown.bs.modal', function () {

	//alert ("shown");
//		$('#tagsstaffpw').value = "";
	//	$('#Bullets').value = "";
	//	clear_charp();
	
		var sel_uid_client = document.getElementById("sel_uid_client").value;
		
		get_contact_edit(sel_uid_client);
		$('#comp_name_edit').focus();
		
	//	alert ("done");
	

}) 


	function change_client(uid_client){
	
		var uid_client = uid_client;

		var sales_id =  document.getElementById('currentsalesid').value;
		
		// add item
		
		$.ajax({
				url: '../php/changestclient.php',
				type: 'post',
				async: 'false',
				data: {"uid_client" : uid_client, "sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
					document.getElementById("tagsprodsearch").value = "";
					
					load_cart();
					

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
	function create_client(){
		
		var tagsprodcont = document.getElementById("tagsprodcontnew").value;

		//alert (tagsprodcont);
		
		
		var sales_id =  document.getElementById('currentsalesid').value;
		
		// add item
		
		$.ajax({
				url: '../php/createstclient.php',
				type: 'post',
				async: 'false',
				data: {"tagsprodcont" : tagsprodcont, "sales_id" : sales_id},
				success: function(data) {
			//		alert (data);
					
	                var obj = JSON.parse( data.trim() );
					
					if (obj.phx_result == "duplicate"){
							toastbox('toast-client_dup', 2000);
					}else{
						load_cart();
						
					}

				}
			});
			
			
		
	}
	
	


		 
		 
		 function load_cart_fromreport(sales_id){
			 
		//	 alert ("load_cart_fromreport"+sales_id);
		
			var sales_id = sales_id;
			
			setCookie("phxcrm_sales_id_sel", sales_id, 365);

//			document.getElementById("curr_sales_id").value = sales_id;
			document.getElementById("currentsalesid").value = sales_id;
			load_cart();
			
		 }
		
		 
		 function load_cart_currentsale(){
			 
			 var curr_sales_id = getCookie("phxcrm_sales_id");
			 
			 setCookie("phxcrm_sales_id_sel", curr_sales_id, 365);
			
//			document.getElementById("curr_sales_id").value = curr_sales_id;
			document.getElementById("currentsalesid").value = curr_sales_id;
			 
			load_cart();
			 
			 
			 
		 }
		 
		 
 		 function load_cart_tab(){
			 
			 load_cart();
			 
		 }
		 
		 
		 			
	 function update_field_st(field_name, field_type, field_value) {

		//	alert ("update"+field_name+field_type+field_value);
			
		//	return false;
	//		alert ("update ");
			
			var st_id			=  getCookie("phxcrm_sales_id_sel");
			
		//	alert (uid_client);
			

	//		var element_je_job_outlet_name = document.getElementById('je_job_outlet_name')
			var outlet_id 			= 1;			
			var old_status			= "";

			var c_favcmts 			= "";

			
			//set defaults
			var c_favcmts = "";
			var c_popup = "";

	
				
				var field_type			= field_type;
				var field_name1_db		= field_name;
				var field_name2_db		= "";
				var field_value1 		= field_value;				
		
			var jobfields = {};

			jobfields.st_id	 = st_id;			
			jobfields.field_name = field_name;
			jobfields.field_type = field_type;
			jobfields.field_name1_db = field_name1_db;
			jobfields.field_name2_db = field_name2_db;
			jobfields.field_value1 = field_value1;
			jobfields.old_status = old_status;
			jobfields.uid_client = 0;
			jobfields.outlet_id = outlet_id;			
	
			
			$.ajax({
				url: '../php/orderupdstfield.php',
				type: 'post',
				data: {"jobfields" : JSON.stringify(jobfields), "c_favcmts" : c_favcmts, "c_popup" : c_popup},
				success: function(data) {
				//	alert ("success"+data);
				//
				if (data == "Update Successful"){
				}else{
					alert ("Update failed error details are"+data);
				}

				}
			});			
			
			
		 }
		 
		 
		 function load_cat(slot, dept_id, sel){
			 
//			 alert ("slot"+slot+"load"+dept_id+"sel"+sel);

			document.getElementById("seldept").value = dept_id;
			
			$.ajax({
				url: '../php/getprodbydept.php',
				type: 'post',
				data: {"slot" : slot, "dept_id" : dept_id, "sel" : sel},
				success: function(data) {
					
					var slotname = "divcattab"+slot;
					document.getElementById(slotname).innerHTML = data;
					
					get_cat_list(dept_id);
					
			//		alert (data);


				}
			});	
			
			
			 
		 }
		 
		 function get_cat_list(dept_id){

			document.getElementById("divshowcatitems").innerHTML = "loading ...";		 
			 
			 //gewt stock yes or no 
			 
			 var instockonly = "zz"+document.getElementById("instockonly").checked;
			 
			 var ps = document.getElementById("prodsortby");
			var prodsortby = ps.value;

			 
			 if (instockonly == "zztrue"){
				 instockonly = 1;

			 }else{
				  instockonly = 0;
			 }
			 
			
//		  alert (instockonly);

			 

			var sel_prod_id = 0;
			var action = "";

			$.ajax({
				url: '../php/getcatprod.php',
				type: 'post',
				async: 'false',
				data: {"prod_uid" : sel_prod_id, "action" : action, "dept_id" : dept_id, "instockonly" : instockonly, "prodsortby" : prodsortby},
				success: function(data) {
					
				//	alert (data);
					
					
						document.getElementById("divshowcatitems").innerHTML = data;

				}
			});	
	
}



	
			 
	 $('#DialogOrderPrint').on('hide.bs.modal', function () {
	
	//	alert ("hide");
	//	load_cart();
	
	
		document.getElementById("tabcurrentsale").click()
	
	

}) 

		 
		 
		 $('#DialogOrderPrint').on('shown.bs.modal', function () {
	
//	alert ("cash");


	var sales_id = document.getElementById("currentsalesid").value;
	
				
			$.ajax({
				url: '../php/orderprint.php',
				type: 'post',
				data: {"sales_id" : sales_id},
				success: function(data) {
					
					document.getElementById("divorderprintdetails").innerHTML = data;
							JsBarcode("#barcode", "sale_1234", {
								width: 2,
								height: 30,
								displayValue: false
							});			
					

					

				}
			});

	
	
	

}) 

		function printDiv(divName){
			
			var divContents = document.getElementById(divName).innerHTML;
			
			var a = window.open('', '', 'width=500');
            a.document.write('<html> <style type="text/css" media="print"> @page { size: auto;   /* auto is the current printer page size */ margin: 0mm;  /* this affects the margin in the printer settings */} body { background-color:#FFFFFF; border: solid 1px black ; margin: 0px;  /* the margin on the content before printing */} </style>');
	
            a.document.write('<body>');
            a.document.write(divContents);
            a.document.write('</body></html>');
            a.print();
            a.document.close();
			
		}
		
		function sel_cat(btn_id, cat_id, dept_id){
			
			var btn_id = btn_id;
			var btn_sel = 0;
						
			//			alert (document.getElementById(btn_id).className);
			if (document.getElementById(btn_id).className == 'btn btn-primary rounded shadowed mr-1 mb-1'){
				
				document.getElementById(btn_id).className = 'btn btn-outline-primary rounded shadowed mr-1 mb-1';
			
				
			}else{
				document.getElementById(btn_id).className = 'btn btn-primary rounded shadowed mr-1 mb-1';
				btn_sel = 1;
			}
			
			
						 
			 var instockonly = "zz"+document.getElementById("instockonly").checked;

			 
			 if (instockonly == "zztrue"){
				 instockonly = 1;

			 }else{
				  instockonly = 0;
			 }
			 var ps = document.getElementById("prodsortby");
			var prodsortby = ps.value;
			 document.getElementById("divshowcatitems").innerHTML = "loading ...";
			 
			//update categories
			
			$.ajax({
				url: '../php/updcatsel.php',
				type: 'post',
				data: {"cat_id" : cat_id, "btn_sel" : btn_sel},
				success: function(data) {
						
				$.ajax({
					url: '../php/getcatprod.php',
					type: 'post',
					data: {"dept_id" : dept_id, "instockonly" : instockonly, "prodsortby" : prodsortby},
					success: function(data) {
						
						document.getElementById("divshowcatitems").innerHTML = data;

					}
				});


				}
			});





					
		}


		function sel_cat_all(btn_id, cat_id, dept_id, slot){
			
			var btn_id = btn_id;
			
		//	alert (btn_id);
			
			var btn_sel = 0;
						
			//if btn_sel is selected then 1 else 0

			if (document.getElementById(btn_id).className == 'btn btn-primary rounded shadowed mr-1 mb-1'){
				
				document.getElementById(btn_id).className = 'btn btn-outline-primary rounded shadowed mr-1 mb-1';
			
				
			}else{
				document.getElementById(btn_id).className = 'btn btn-primary rounded shadowed mr-1 mb-1';
				btn_sel = 1;
			}
						 
			 var instockonly = "zz"+document.getElementById("instockonly").checked;

			 
			 if (instockonly == "zztrue"){
				 instockonly = 1;

			 }else{
				  instockonly = 0;
			 }
			 
			 var ps = document.getElementById("prodsortby");
			var prodsortby = ps.value;
			 
			 
			document.getElementById("divshowcatitems").innerHTML = "loading ...";
			
			//update categories
			
			$.ajax({
				url: '../php/updcatsel2.php',
				type: 'post',
				data: {"cat_id" : cat_id, "btn_sel" : btn_sel, "slot" : slot},
				success: function(data) {
					
			//		alert (data);
					list_ids(btn_sel, slot);
						
				$.ajax({
					url: '../php/getcatprod.php',
					type: 'post',
					data: {"dept_id" : dept_id, "slot" : slot, "instockonly" : instockonly, "prodsortby" : prodsortby},
					success: function(data) {
						
						document.getElementById("divshowcatitems").innerHTML = data;
						

					}
				});


				}
			});





					
		}
		
		function stockonoff(){
			
									 
			 var instockonly = "zz"+document.getElementById("instockonly").checked;
			 
			 var dept_id =  document.getElementById("seldept").value;
			

			 
			 if (instockonly == "zztrue"){
				 instockonly = 1;

			 }else{
				  instockonly = 0;
			 }
			 
			var ps = document.getElementById("prodsortby");
			var prodsortby = ps.value;
			
			$.ajax({
				url: '../php/getcatprod.php',
				type: 'post',
				data: {"dept_id" : dept_id,  "instockonly" : instockonly, "prodsortby" : prodsortby, "dept_id" : dept_id},
				success: function(data) {
						
					document.getElementById("divshowcatitems").innerHTML = data;
						

				}
			});
			
			
		}
		
		function list_ids(onoff, slot){
			
			var onoff = onoff;
			var slot = slot;
			
			var cattab = "cattab"+slot;
			
			var childDivs = document.getElementById(cattab).getElementsByTagName('button');

let ids = Array.from({length: childDivs.length}, (v, i) => childDivs[[i]].id);

var arrayLength = ids.length;

//alert ("length"+arrayLength);

ids.forEach(function (item, index) {
  console.log(item, index);
  
  //alert (item);
  if (item.trim() == ""){
  }else{
	  
	  if (onoff == 1){
			document.getElementById(item.trim()).className = 'btn btn-primary rounded shadowed mr-1 mb-1';

	  }else{

			document.getElementById(item.trim()).className = 'btn btn-outline-primary rounded shadowed mr-1 mb-1';
		  
	  }
  }
 // item
});

//console.log(ids);
			
		}
		
		function receipt_print(){
			
			var phx_comp_name 		= document.getElementById("phx_comp_name").value;
			var phx_username 		= document.getElementById("phx_username").value;
			var comp_phys_addr1 	= document.getElementById("comp_phys_addr1").value;
			var comp_phys_addr2 	= document.getElementById("comp_phys_addr2").value;
			var comp_phys_addr3 	= document.getElementById("comp_phys_addr3").value;
			var comp_website_url 	= document.getElementById("comp_website_url").value;
			var comp_phone 			= document.getElementById("comp_phone").value;
			var tagsprodcont 		= document.getElementById("tagsprodcont").value;
			

			
			var phxcrmclient_id 		= document.getElementById("phxcrmclient_id").value;

			var logo_img 			= "../../logo/"+phxcrmclient_id+".jpg";

			
			var currentsalesid 			= document.getElementById("currentsalesid").value;
			
			

			
									$.ajax({
								url: 'http://localhost/utils/escpos-php/receipt/rprint.php',
								type: 'post',
								async: 'true',
								data: {"phx_comp_name" : phx_comp_name, "phx_username" : phx_username, "comp_phys_addr1" : comp_phys_addr1, "comp_phys_addr2" : comp_phys_addr2, "comp_phys_addr3" : comp_phys_addr3, "comp_website_url" : comp_website_url, "comp_phone" : comp_phone, "currentsalesid" : currentsalesid, "tagsprodcont" : tagsprodcont, "logo_img" : logo_img},
								success: function(data) {
					
							//		alert ("done"+data);
	
								}
			 
							})
	
		}
		
			
								
	function upd_stl_title(client_id, cart_function, cart_uid, new_value){
		
		
		//	alert ("upd_disc");
	
	//	alert (cart_function+""+newqty+""+cart_uid);
		
		
	//	if (isNaN(newqty)){
			
		//	alert (newqty+"Not");
		
	//		toastbox('toast-disc_notvalid', 2000);		
	//		return false;
	//	}else{

	//	}
		
		
		
	//	return false;
		
	

		var new_value = new_value;
		

		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "new_value" : new_value, "newqty" : new_value},
				success: function(data) {
					
				//	alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var new_line_amount   	= "$"+obj.new_line_amount;
					var sales_id		   	= obj.sales_id;
					
					if (phx_result == ""){
						
								//update item line qty
							var item_amount_field = "line_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(item_amount_field).value = new_line_amount;
								
							load_cart_totals(sales_id);
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}	
								
	function upd_disc(client_id, cart_function, cart_uid, newqty){
		
		
		//	alert ("upd_disc");
	
	//	alert (cart_function+""+newqty+""+cart_uid);
		
		
		if (isNaN(newqty)){
			
		//	alert (newqty+"Not");
		
			toastbox('toast-disc_notvalid', 2000);		
			return false;
		}else{

		}
		
		
		
	//	return false;
		
	

		var newqty = newqty;
		

		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
					//alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var new_line_amount   	= "$"+obj.new_line_amount;
					var sales_id		   	= obj.sales_id;
					
					if (phx_result == ""){
						
								//update item line qty
							var item_amount_field = "line_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(item_amount_field).value = new_line_amount;
								
							load_cart_totals(sales_id);
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
									
	function upd_item(client_id, cart_function, cart_uid, newqty){
		
		
		//	alert ("upd_disc");
	
	//	alert (cart_function+""+newqty+""+cart_uid);
		
		
		if (isNaN(newqty)){
			
		//	alert (newqty+"Not");
		
			toastbox('toast-amount_notvalid', 2000);		
			return false;
		}else{

		}
		
		
		
	//	return false;
		
	

		var newqty = newqty;
		

		// add item
		
		$.ajax({
				url: '../php/updcart.php',
				type: 'post',
				async: 'false',
				data: {"client_id" : client_id, "cart_function" : cart_function, "cart_uid" : cart_uid, "newqty" : newqty},
				success: function(data) {
					
			//		alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					var sales_id 	  		= obj.sales_id;
					var new_line_amount   	= "$"+obj.new_line_amount;
					var new_item_amount   	= obj.new_item_amount;
					
					if (phx_result == ""){
						
								//update item line qty
							var line_amount_field = "line_amount_"+cart_uid;
							var item_amount_field = "item_amount_"+cart_uid;
							
						//	alert (item_amount_field);
							
							document.getElementById(line_amount_field).value = new_line_amount;
							document.getElementById(item_amount_field).value = new_item_amount;
								
							load_cart_totals(sales_id);
							

					}else{
												
						alert ("An error ocurred adding item "+data);
					
					}

					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}
	
	
				
		function cs_void(action, pay_type) {
			
			var sales_id =  document.getElementById('currentsalesid').value;
			
			var ttl_sale = document.getElementById("totalsale").value;
			
			var pay_type = pay_type;
			
			var prog_status = "";
			
			var ttl_paid_now = 0;
			
			var pay_sel_type = "";
			
			var action = action;
			

			$.ajax({
				url: '../php/void_sale.php',
				type: 'post',
				async: 'false',
				data: {"sales_id" : sales_id, "pay_type" : pay_type, "ttl_paid_now" : ttl_paid_now,"ttl_sale" : ttl_sale, "pay_action": action, "pay_sel_type": pay_sel_type, "prog_status": prog_status},
				success: function(data) {
				//	alert ("success"+data);
					
					obj = JSON.parse(data);
					
					var sales_id = obj.new_sales_id;


					
					if (obj.complete_sale == "1"){
						
						
						//	alert ("1");
						toastbox('toast-sale-void', 2000);
						
//						document.getElementById("curr_sales_id").value = sales_id;
						document.getElementById("currentsalesid").value = sales_id;
					
						load_cart();

						//close modal
						
						$('#DialogVoid').modal('hide');
					



					
					}else{
						
						alert ("An error occured"+data);
						
							
					}
					
					//if tillport set then open register



					//if all ok tell user with toastbox and go to next sale
					
					//only do this is fully complete
					

					
	
				}
			 
		 })
		
		 

}	
	
function show_receipt_email(){
	
	//alert ("show_receipt_email");
	
	document.getElementById("divorderprintdetails").style.display="none";
	document.getElementById("divorderprintdetails2").style.display="none";
	document.getElementById("divemailreceipt").style.display="block";
	
}
		
function show_receipt(){
	
	//alert ("show_receipt_email");
	
	document.getElementById("divorderprintdetails").style.display="block";
	document.getElementById("divorderprintdetails2").style.display="block";
	document.getElementById("divemailreceipt").style.display="none";
	
}

function emailreceipt(){
	
//	alert ("email receipt");
	

		//	var suppid=getCookie("rec_supp");
			
	//		var suppid = document.getElementById("rec_supp2").value
//			alert (suppid);
					
	//		var reporttype  					= document.getElementById('reporttype').value;
	
			var sales_id 						= document.getElementById('currentsalesid').value;
			var reportemailto 					= document.getElementById('reportemailto').value;
			var reportemailsubject 				= document.getElementById('reportemailsubject').value;
			var reportemailmessage 				= document.getElementById('reportemailmessage').value;	

if (reportemailto == ""){
	alert ("Please enter an email address");
	return false;
	
}	
			
		//	var reportcompname 					= document.getElementById('comp_name').value;	
			var reportcompname 					= "";
						

			var phxcrmclient_id=142;
			
	
		
			var emailurl = "../php/shopreceiptemail"+phxcrmclient_id+".php";
		
	

//		alert ("2");
			
			document.getElementById('result').innerHTML = 'Sending ...';
			
			var suppid = 1;
			
			$.ajax({
				url: emailurl,
				type: 'post',
				cache: false,
				data: {"sales_id" : sales_id,"supp_id" : suppid,"reportemailmessage" : reportemailmessage, "reportemailto" : reportemailto, "reportemailsubject" : reportemailsubject, "reportcompname" : reportcompname},
				success: function(data) {
				//	alert (data);
					
					
			//		document.getElementById("divquoteemail").style.display = 'none';
			//	alert (data);
					document.getElementById('result').innerHTML = data;

					var result = data.trim();
				
										
//										alert ("1"+result+"1");
	//									alert (result.length);

//alert (result);
	
					var result = result.substring(0, 12);
			//		alert (result);
					if (result == "Message Sent" || result == " Message Sent" || result == " Mail sent successfully" || result == "Mail sent successfully" || result == "SERVER ->"){
					
					}else{				
									Alert("send message failed. Please try again. Error details are a"+result+"a")


				}
				},
				error: function (error) {
                  alert('error; ' + error);
				}
			});	
		
		}
			

									
	function upd_ptl(ptl_uid, ptl_field, st_id, new_value){
		
		
			alert ("upd_ptl"+new_value);
	
		//	return false;
			
	//	alert (cart_function+""+newqty+""+cart_uid);
		
		
	//	if (isNaN(newqty)){
			
		//	alert (newqty+"Not");
		
	//		toastbox('toast-amount_notvalid', 2000);		
	//		return false;
	//	}else{

	//	}
		
		
		
	//	return false;
		
	

		var newqty = newqty;
		

		// add item
		
		$.ajax({
				url: '../php/updptl.php',
				type: 'post',
				async: 'true',
				data: {"st_id" : st_id, "ptl_uid" : ptl_uid, "ptl_field" : ptl_field, "new_value" : new_value},
				success: function(data) {
					
					alert (data);
					
					var data = data.trim();
					
	                var obj = JSON.parse( data );
 
					var phx_result 	  		= obj.phx_result;
					
					alert (phx_result);


					//		document.getElementById("divsearchresults").innerHTML = data;

				}
			});
			
			
			
	//	alert ("add to cart"+qty);
	

				
	}			
	
	
	
	function change_login_staff(client_id, staff_id){
	
//		alert ("change staff");
		
		if (client_id == 264){
			
			if (staff_id == 5){
			
				document.getElementById("sel_uid_outlet").value = 1;
				document.getElementById("sel_uid_outlet").readonly = true;
				document.getElementById('sel_uid_outlet').setAttribute("disabled","disabled");

			}else if (staff_id == 7){
				
				document.getElementById("sel_uid_outlet").value = 1;
				document.getElementById("sel_uid_outlet").readonly = true;
				document.getElementById('sel_uid_outlet').setAttribute("disabled","disabled");


			}else if (staff_id == 8){
				
				document.getElementById("sel_uid_outlet").value = 1;
				document.getElementById("sel_uid_outlet").readonly = true;
				document.getElementById('sel_uid_outlet').setAttribute("disabled","disabled");

			}else if (staff_id == 9){
				
				document.getElementById("sel_uid_outlet").value = 1;
				document.getElementById("sel_uid_outlet").readonly = true;
				document.getElementById('sel_uid_outlet').setAttribute("disabled","disabled");

			}else if (staff_id == 10){
				
				document.getElementById("sel_uid_outlet").value = 1;
				document.getElementById("sel_uid_outlet").readonly = true;
				document.getElementById('sel_uid_outlet').setAttribute("disabled","disabled");

			}else if (staff_id == 11){
				
				document.getElementById("sel_uid_outlet").value = 1;
				document.getElementById("sel_uid_outlet").readonly = true;
				document.getElementById('sel_uid_outlet').setAttribute("disabled","disabled");
				
			}else if (staff_id == 6){
				
				document.getElementById("sel_uid_outlet").value = 2;
				document.getElementById("sel_uid_outlet").readOnly  = true;
				document.getElementById('sel_uid_outlet').setAttribute("disabled","disabled");
			
		
			}else{
				
				document.getElementById("sel_uid_outlet").readOnly  = false;
				document.getElementById('sel_uid_outlet').removeAttribute("disabled");
				
			}
		
		}
	
	}
	
	function open_product(uid, fee_perc, fee_base, fee_curr, id_stl, uid_client, card_fee_sel){
		
	
		//	alert (uid+""+fee_perc+""+fee_base);
			
			document.getElementById("sel_fee_perc").value = fee_perc;
			document.getElementById("sel_fee_base").value = fee_base;
			document.getElementById("sel_fee_curr").value = fee_curr;
			document.getElementById("sel_id_stl").value = id_stl;
			
			if (card_fee_sel == 1){
			
				document.getElementById("creditcardfeecalc").click();
			
			}
	}
	
		
	function change_fee(new_value){
		
	//	alert (new_value);
		
		
	
		//	alert (uid+""+fee_perc+""+fee_base);
			
			var fee_per2 = document.getElementById("sel_fee_perc").value ;
			var fee_base2 = document.getElementById("sel_fee_base").value;
			var fee_curr2 = document.getElementById("sel_fee_curr").value;
			
			if (new_fee_curr == 0){
				var new_fee_curr = 0;
			}else{
				var new_fee_curr = (new_value/100)*fee_per2;
				
				new_fee_curr = parseFloat(new_fee_curr).toFixed(2);
				
			}
			

	//	alert ("change fee"+new_fee_curr);
		
		document.getElementById("cardfeecalc").value = new_fee_curr;
		
	}
	
	function apply_fee(){
		
	
		//	alert (uid+""+fee_perc+""+fee_base);
		
		var new_fee_curr = document.getElementById("cardfeecalc").value;
		var phxcrmclient_id = document.getElementById("phxcrmclient_id").value;
		var sel_id_stl = document.getElementById("sel_id_stl").value;

		upd_item(phxcrmclient_id,'newitemvalue',sel_id_stl, new_fee_curr);
		
		$('#DialogCreditCardfee').modal('hide');

		
	}
	
		
	function windcave_request_payment(amt) {
		
	//	alert (amt);
		
		
		//get windcave user and setup details then call url
		
			var amt = amt;
			
			
			if (amt == 0){
				
				var amt = document.getElementById("totaldue").value;
				
			}
			
		
			wc_phxid = document.getElementById("phxcrmclient_id").value;
			wc_salesid = document.getElementById("currentsalesid").value;
			document.getElementById("dispwcresponse").innerText = "Sending payment to Eftpos machine";
			document.getElementById("dispwcresponse2").innerText = "";
			
			document.getElementById("canceleftpos").style.display = "block";
			
			document.getElementById("retryeftpos").style.display = "none";
			
			document.getElementById("divreceiptreqdeftpos").style.display = "none";
			
			
			
				
			document.getElementById("buteftposfullconfirm").style.display = "none";
			
			document.getElementById("buteftposfullclose").style.display = "none";		
			
			document.getElementById("dispwcresponse").style.backgroundColor = "#FAFACC";
			document.getElementById("dispwcresponse2").style.backgroundColor = "#FAFACC";

		
		
			$.ajax({
				url: '../php/get_wc_user.php',
				type: 'post',
				async: 'true',
				data: {"wc_phxid" : wc_phxid, "amt" : amt},
				success: function(data) {
					
				//	alert (data);
					
	                var obj = JSON.parse( data );
 
					var eftpos_username 	  		= obj.eftpos_username;
					var eftpos_key 	  				= obj.eftpos_key;
					var eftpos_station1 	  		= obj.eftpos_station1;
					var req_amt			 	  		= obj.amt;
					var txn_type			 	 	= obj.txn_type;			
					
					var txn_mreference = wc_salesid;
					var txn_ref = wc_salesid;
					var txn_currency = "NZD";
					
					var data = data.trim();
					
					var http = new XMLHttpRequest();
					var url = "https://uat.windcave.com/hit/pos.aspx";
					http.open("POST", url, true);
					var datapurch = '<Scr action="doScrHIT" user="'+eftpos_username+'" key="'+eftpos_key+'"><Amount>'+req_amt+'</Amount><Cur>'+txn_currency+'</Cur><TxnType>'+txn_type+'</TxnType><Station>'+eftpos_station1+'</Station><TxnRef>'+txn_ref+'</TxnRef><DeviceId>1</DeviceId><PosName>PhoenixPOS</PosName><PosVersion>1</PosVersion><VendorId>1</VendorId><MRef>'+txn_mreference+'</MRef></Scr>';
  
				//	alert (datapurch);
					var result = document.getElementById("response");

					http.onreadystatechange = function () {
					//Call a function when the state changes.
						if (http.readyState == 4 && http.status == 200) {
							
						//	alert (http.responseText);
							
							windcave_request_status(2.00);
							
							

							var dl1_start = http.responseText.indexOf("<DL1>");
							
						//	alert (dl1_start);
							
							if (dl1_start == "-1"){
								
								var dl1_text = "";
								
							}else{
								
								var dl1_end = http.responseText.indexOf("</DL1>");
							
								var dl1_len = dl1_end - dl1_start-5;
							
								var dl1_text = http.responseText.substr(dl1_start+5, dl1_len);	
							
							}
							
							
						//	alert ("dl1_text"+dl1_text);

							
	
							var dl2_start = http.responseText.indexOf("<DL2>");
							
							if (dl2_start == "-1"){
								
								var dl2_text = "";
								
							}else{
								
								var dl2_end = http.responseText.indexOf("</DL2>");
							
								var dl2_len = dl2_end - dl2_start-5;
							
								var dl2_text = http.responseText.substr(dl2_start+5, dl2_len);	
							
							}
							
														
	
							var comp_start = http.responseText.indexOf("<Complete>");
							
							if (comp_start == "-1"){
								
								var complete_response = 0;
								
							}else{
								
								var comp_end = http.responseText.indexOf("</Complete>");
							
								var comp_len = comp_end - comp_start-10;
							
								var complete_response = http.responseText.substr(comp_start+10, comp_len);	
							
							}

			
							//		var show_msg = "status ... DL1 "+xmlDoc1_DL1+"<br>"+" DL2 "+xmlDoc1_DL2;
			
							//	alert (show_msg);
			
							document.getElementById("dispwcresponse").innerText = dl1_text;
							document.getElementById("dispwcresponse2").innerText = dl2_text;
			

						}
					};
					
						http.send(datapurch);
	
				}


			});
			
	}
	
		
	function windcave_cancel_payment(amt) {
		
		//get windcave user and setup details then call url
		
			var amt = amt;
		

			wc_salesid = document.getElementById("currentsalesid").value;
			document.getElementById("dispwcresponse").innerText = "Status ... Issuing cancel to Eftpos machine";
			document.getElementById("dispwcresponse2").innerText = "";		
			
			wc_phxid = document.getElementById("phxcrmclient_id").value;			

		
		
			$.ajax({
				url: '../php/get_wc_user.php',
				type: 'post',
				async: 'true',
				data: {"wc_phxid" : wc_phxid, "amt" : 0},
				success: function(data) {
				//	
				//	alert (data);
					
	                var obj = JSON.parse( data );
 
					var eftpos_username 	  		= obj.eftpos_username;
					var eftpos_key 	  				= obj.eftpos_key;
					var eftpos_station1 	  		= obj.eftpos_station1;
					
					var txn_type = "UI";
					var txn_mreference = wc_salesid;
					var txn_ref = wc_salesid;
					var txn_currency = "NZD";
					

					
					var data = data.trim();
					
					var http = new XMLHttpRequest();
					var url = "https://uat.windcave.com/hit/pos.aspx";
					http.open("POST", url, true);
					var datapurch = '<Scr action="doScrHIT" user="'+eftpos_username+'" key="'+eftpos_key+'"><TxnType>'+txn_type+'</TxnType><UiType>Bn</UiType><Name>B1</Name><Station>'+eftpos_station1+'</Station><TxnRef>'+txn_ref+'</TxnRef><Val>CANCEL</Val><DeviceId>1</DeviceId><PosName>PhoenixPOS</PosName><PosVersion>1</PosVersion><VendorId>1</VendorId><MRef>'+txn_mreference+'</MRef></Scr>';
  
				//	alert (datapurch);
					var result = document.getElementById("response");

					
					

					http.onreadystatechange = function () {
					//Call a function when the state changes.
						if (http.readyState == 4 && http.status == 200) {
							
						//	alert ("cancel returned"+http.responseText);
							
							document.getElementById("canceleftpos").style.display = "none";
			
							document.getElementById("retryeftpos").style.display = "block";
							
							document.getElementById("divreceiptreqdeftpos").style.display = "none";							
												
							document.getElementById("buteftposfullconfirm").style.display = "none";
			
							document.getElementById("buteftposfullclose").style.display = "block";		

							
		//					parser1c = new DOMParser();
		//	xmlDoc1c = parser1c.parseFromString(http.responseText,"text/xml");
	
		//	var xmlDoc1c_status = xmlDoc1c.getElementsByTagName("TxnType")[0].childNodes[0].nodeValue;
			
		//	alert ("Status"+xmlDoc1c_status);

						}
					};
					
						http.send(datapurch);
	
				}


			});
			
	}
	
	
		function windcave_request_status(amt) {
		
		//get windcave user and setup details then call url
		
			var amt = amt;
		
			wc_phxid = document.getElementById("phxcrmclient_id").value;
			wc_salesid = document.getElementById("currentsalesid").value;

			
			


		
			$.ajax({
				url: '../php/get_wc_user.php',
				type: 'post',
				async: 'true',
				data: {"wc_phxid" : wc_phxid, "amt" : 0},
				success: function(data) {
					
				//	alert (data);
					
	                var obj = JSON.parse( data );
 
					var eftpos_username 	  		= obj.eftpos_username;
					var eftpos_key 	  				= obj.eftpos_key;
					var eftpos_station1 	  		= obj.eftpos_station1;
					
					var txn_type = "Status";
					var txn_mreference = wc_salesid;
					var txn_ref = wc_salesid;
					var txn_currency = "NZD";
					

					
					var data = data.trim();
					
					var http = new XMLHttpRequest();
					var url = "https://uat.windcave.com/hit/pos.aspx";
					http.open("POST", url, true);
					var datapurch = '<Scr action="doScrHIT" user="'+eftpos_username+'" key="'+eftpos_key+'"><Amount>'+amt+		'</Amount><Cur>'+txn_currency+'</Cur><TxnType>'+txn_type+'</TxnType><Station>'+eftpos_station1+'</Station><TxnRef>'+txn_ref+'</TxnRef><DeviceId>1</DeviceId><PosName>PhoenixPOS</PosName><PosVersion>1</PosVersion><VendorId>1</VendorId><MRef>'+txn_mreference+'</MRef></Scr>';
  
				//	alert (datapurch);
					var result = document.getElementById("response");
					
					

					http.onreadystatechange = function () {
					//Call a function when the state changes.
						if (http.readyState == 4 && http.status == 200) {
							
						

							var dl1_start = http.responseText.indexOf("<DL1>");
							
						//	alert (dl1_start);
							
							if (dl1_start == "-1"){
								
								var dl1_text = "";
								
							}else{
								
								var dl1_end = http.responseText.indexOf("</DL1>");
							
								var dl1_len = dl1_end - dl1_start-5;
							
								var dl1_text = http.responseText.substr(dl1_start+5, dl1_len);	
							
							}
							
							
						//	alert ("dl1_text"+dl1_text);

							
	
							var dl2_start = http.responseText.indexOf("<DL2>");
							
							if (dl2_start == "-1"){
								
								var dl2_text = "";
								
							}else{
								
								var dl2_end = http.responseText.indexOf("</DL2>");
							
								var dl2_len = dl2_end - dl2_start-5;
							
								var dl2_text = http.responseText.substr(dl2_start+5, dl2_len);	
							
							}
							
														
	
							var comp_start = http.responseText.indexOf("<Complete>");
							
							if (comp_start == "-1"){
								
								var complete_response = 0;
								
							}else{
								
								var comp_end = http.responseText.indexOf("</Complete>");
							
								var comp_len = comp_end - comp_start-10;
							
								var complete_response = http.responseText.substr(comp_start+10, comp_len);	
							
							}
							
							
						//	alert ("complete_response"+complete_response);
							
							
							var xmlDoc1s_DL1 = dl1_text;
							var xmlDoc1s_DL2 = dl2_text;
							
							
	  
						//	parsers = new DOMParser();
						//	xmlDoc1s = parsers.parseFromString(http.responseText,"text/xml");

	
						//	var dave = xmlDoc1s.getElementsByTagName("TxnType")[0].childNodes[0].nodeValue;
			
						//	var complete_response = xmlDoc1s.getElementsByTagName("Complete")[0].childNodes[0].nodeValue;


			
							//		var show_msg = "status ... DL1 "+xmlDoc1_DL1+"<br>"+" DL2 "+xmlDoc1_DL2;
			
							//	alert (show_msg);
			
							document.getElementById("dispwcresponse").innerText = xmlDoc1s_DL1;
							document.getElementById("dispwcresponse2").innerText = xmlDoc1s_DL2;
	
							if (complete_response == 1){
								

		
							//	alert ("complete"+complete_response+http.responseText);
		
								complete_appr = 0;
								
								//check if approved
								
								
								var comp_appr_start = http.responseText.indexOf("<AP>");
							
								if (comp_appr_start == "-1"){
								
									var complete_appr = 0;
								
							}else{
								
								var comp_appr_end = http.responseText.indexOf("</AP>");
							
								var comp_appr_len = comp_appr_end - comp_appr_start-4;
							
								var complete_appr = http.responseText.substr(comp_appr_start+4, comp_appr_len);	
							
							}
							
						//	alert (complete_appr);
							
							
							if (complete_appr == 1){
								
								document.getElementById("canceleftpos").style.display = "none";
			
								document.getElementById("retryeftpos").style.display = "none";
								
								document.getElementById("dispwcresponse").style.backgroundColor  = "#03AC13";
								document.getElementById("dispwcresponse2").style.backgroundColor = "#03AC13";

								document.getElementById("divreceiptreqdeftpos").style.display = "block";	
												
								document.getElementById("buteftposfullconfirm").style.display = "block";
			
								document.getElementById("buteftposfullclose").style.display = "none";		

							
						//		alert ("Approved");
								
							}else{
						//		alert ("Declined");

								document.getElementById("canceleftpos").style.display = "none";
			
								document.getElementById("retryeftpos").style.display = "block";		

				
								document.getElementById("buteftposfullconfirm").style.display = "none";
			
								document.getElementById("buteftposfullclose").style.display = "block";	

								document.getElementById("divreceiptreqdeftpos").style.display = "none";									
								
								document.getElementById("dispwcresponse").style.backgroundColor = "#FF0000";
								document.getElementById("dispwcresponse2").style.backgroundColor = "#FF0000";
								
								
							}
								
								
										
								//		alert ("return false 5589");
								return false;
		
							}else{
				
				
								windcave_request_status(0);
								//	alert ("not complete");
					
							}
		
	
	//	i = i + 1;
						}
					};
					
						http.send(datapurch);
	
				}


			});
			
	}
	

		
    </script>
	
	<script>
/**
 * CKEditor 4 Configuration Documentation 
 * (http://docs.ckeditor.com/#!/guide/dev_configuration)
 *
 */

// Default CKEditor 4 Full Toolbar
//CKEDITOR.replace('fulleditor');

// In-page customized CKEditor 4 Toolbar



				function open_quote() {

		//	jobsaveold();

		//		var j1					=  document.getElementById('je_job_status');
			//	var job_status			=  j1.options[j1.selectedIndex].value;
		
			var js			= document.getElementById("job_status");
			var job_status			= js.options[js.selectedIndex].text;

//		alert (job_status);
		
//		var sales_id			= document.getElementById("j_st_id").value;
			
	//		alert (job_status);
			
			if (job_status == "Quote Draft" || job_status == "Quote Decl"){
				
				$("#butchangejobstatus").click();

			}
			
			
			
			
			
			var sales_id			= document.getElementById("j_st_id").value;
			
	//		var sales_id = 45944;
			
			var phxcrmclient_id=getCookie("phxcrmclient_id");
			
			var phxclient_type=getCookie("phxclient_type");
			

			if (phxcrmclient_id == "70"){
			
				window.open("../php/tradesquote70.php?sales_id="+sales_id, "_blank"); 

			}else if (phxcrmclient_id == "91"){
			
				window.open("../php/tradesquote91.php?sales_id="+sales_id, "_blank");
				
			}else if (phxcrmclient_id == "65"){
			
				window.open("../php/tradesquote65.php?sales_id="+sales_id, "_blank");				
			}else if (phxcrmclient_id == "101"){
			
				window.open("../php/tradesquote101.php?sales_id="+sales_id, "_blank"); 
			}else if (phxcrmclient_id == "102"  || phxcrmclient_id == "103" || phxcrmclient_id == "104"){
			
				window.open("../php/tradesquote101.php?sales_id="+sales_id, "_blank"); 

			}else if(phxclient_type == "printer"){

				window.open("../php/tradesquote91demo.php?sales_id="+sales_id, "_blank");
				
			}else{
			
				window.open("../php/tradesquote.php?sales_id="+sales_id, "_blank"); 
 
			}

			
		}
		
		
			

			function lineupdate(uid, type, value) {
				
				
				if (type == 0){
					
					type = "qtl_title";
				
				}
				
			//	alert (type);
				
		//		alert(uid+""+type+""+value);
				
					var sales_id = document.getElementById("j_st_id").value;
					var value2 = "";
				
				
														$.ajax({
						url: '../php/updatesimplyqtl.php',
						type: 'post',
						async: 'true',
						data: {"uid" : uid, "type" : type, "value" : value, "value2" : value2, "sales_id" : sales_id},
						    error: function(data) {
		//		alert (data);
	  },
						success: function(data) {
					//		alert (data);
							
							obj = JSON.parse(data);
							


							var result_message = obj.result_message;
							var response_ttl_quote = parseFloat(obj.ttl_quote).toFixed(2);
			
							//	alert (xmlhttp.responseText);
							
							if (result_message == "Update Successful"){


						//		alert ("gettotals");
								
								if (type == "qty"){
								
									document.getElementById("qtyedit_"+uid).value = value;
									document.getElementById("line_amount_"+uid).value = obj.new_item_total;
									
								}
		$.ajax({
				url: '../php/getcarttotals.php',
				type: 'post',
				async: 'true',
				data: {"sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					

							document.getElementById("divcarttotals").innerHTML = data;
					//		$('#tagsprodsearch').focus();

				}
			});


				
							}else{
								alert ("An error occurred " + data);
							}
			   
					//	location.reload();
					
						//	alert ("ended");

						}
					});
		
				
			}


		
			function lineupdateqtl(uid, type, value, value2) {
				
				if (type == 0){
					
					type = "qtl_prod_catid";
					
				}
			
			//	alert ("d"+type+"d"+value+"v2"+value2);

		
		//		alert (uid+type+value);
				
			var job_st_id			= document.getElementById("j_st_id").value;
	
		if (type == "qtl_incl_price"){

	//		var value			= document.getElementById("qtl_incl_price").checked;

		}else if (type == "qtl_incl_option"){

	//		var value			= document.getElementById("qtl_incl_option").checked;

		
		}else if (type == "qtl_prod_catid"){
//		alert ("incat");

			var value 			= value;
			var value2 			= value2;


			if (value2 == "Select Category") {
	
			var value2 = "";
			var value = 0;

			}
			
		
		
				}else if (type == "item_amount"){
//		alert ("incat");

			var value 			= value2;
		
		
				}
		
						var sales_id = document.getElementById("j_st_id").value;
		
		
										$.ajax({
						url: '../php/updatesimplyqtl.php',
						type: 'post',
						async: 'true',
						data: {"uid" : uid, "type" : type, "value" : value, "value2" : value2, "sales_id" : sales_id},
						    error: function(data) {
			//	alert (data);
	  },
						success: function(data) {
					//		alert (data);
							
							obj = JSON.parse(data);
							


							var result_message = obj.result_message;
							var response_ttl_quote = parseFloat(obj.ttl_quote).toFixed(2);
			
							
							if (result_message == "Update Successful"){


							//	alert ("gettotalsdave"+obj.new_item_total);
								
								var update_totals = 1;
								
							//	alert (type);
								
								
								if (type == "qty"){
								
									document.getElementById("qtyedit_"+uid).value = value;
									document.getElementById("line_amount_"+uid).value = obj.new_item_total;
									document.getElementById("line_cost_"+uid).value = obj.new_ttl_cost;
									
									
//																				new_item_total
//new_ttl_cost
									
								}else if (type == "cost_price"){
									
									document.getElementById("cost_price_"+uid).value = obj.new_item_cost;
									document.getElementById("line_cost_"+uid).value = obj.new_ttl_cost;
									
								}else if (type == "item_amount"){
									
								//	alert ("item amoiunt");
									
									document.getElementById("line_amount_"+uid).value = obj.new_item_total;
									document.getElementById("item_amount_"+uid).value = obj.new_item_price;
																	
									
								}

									if (type == "qtl_prod_catid"){
										
										update_totals = 0;
									}


									if (update_totals == 1){
							//			var job_ttl_qty = obj.job_ttl_qty;
							//			var job_ttl_quote_xgst = obj.job_ttl_quote_xgst;
							//			var job_ttl_quote_gst = obj.job_ttl_quote_gst;
							//			var job_ttl_quote = obj.job_ttl_quote;
							//			var job_ttl_quote_cost_xgst = obj.job_ttl_quote_cost_xgst;
							//			var job_ttl_quote_cost_gst = obj.job_ttl_quote_cost_gst;
							//			var job_ttl_quote_cost = obj.job_ttl_quote_cost;
							

							
							//			document.getElementById("job_ttl_qty").value = job_ttl_qty;
							//			document.getElementById("job_ttl_quote_xgst").value = job_ttl_quote_xgst;
							//			document.getElementById("job_ttl_quote_gst").value = job_ttl_quote_gst;
							//			document.getElementById("job_ttl_quote").value = job_ttl_quote;
							//			document.getElementById("job_ttl_quote_cost_xgst").value = job_ttl_quote_cost_xgst;
							//			document.getElementById("job_ttl_quote_cost_gst").value = job_ttl_quote_cost_gst;
							//			document.getElementById("job_ttl_qty").value = job_ttl_qty;
									}
				
							}else{
								alert ("An error occurred " + data);
							}
			   
					//	location.reload();
					
					//		alert ("ended");
					
							$.ajax({
				url: '../php/getcarttotals.php',
				type: 'post',
				async: 'true',
				data: {"sales_id" : sales_id},
				success: function(data) {
					
				//	alert (data);
					

							document.getElementById("divcarttotals").innerHTML = data;
				//			$('#tagsprodsearch').focus();

				}
			});


						}
					});
		


				
			}
			

function clear_calc(){
	document.getElementById("seltop").style.display="none";


}	
			
function setupmaincatsel(type){

//return false;
	
//	alert ("setupmaincatsel"+type);
	



	document.getElementById("seltop").style.display="block";

	var ourObj = {};
	
	ourObj.data = "getprodpkgallcatactive";

									document.getElementById("cat1selqtl").options.length = 0;								
									document.getElementById("cat2selqtl").options.length = 0;
									document.getElementById("cat3selqtl").options.length = 0;
									document.getElementById("cat4selqtl").options.length = 0;

									document.getElementById("qtyqtla").options.length = 0;

									
										$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		success: function(data) {
			//	alert (data);
		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat1selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_code_name;
					p.add(option);

											}
								}
							
//alert ("done");

							$('#cat1selqtl').val(type);
							setupmaincatselnew();	
				

			
//			alert (data);
        // Do something with data that came back. 
		}
			});						
								
								
									
									//	alert ("setup main");								
	}
	
					function setupmaincatselnew(level){
						
//return false;
						
	//							 alert ("setupmaincatselnew"+level);
								 
				if (level === undefined || level === null) {
				
					var level = 0;
				
				}else{

					var level = level;
				
				}

//									alert ("setupmaincatselnew");
//									alert (cat1selqtl);	

									var a = document.getElementById("cat1selqtl");
									var cat1selqtl = a.options[a.selectedIndex].text;	
									
								//	alert (cat1selqtl);	
							//		var cat1selqtl = "Business Cards";

									document.getElementById("priceppdiv").style.display = "none";
									document.getElementById("priceqtydiv").style.display = "none";

//									alert ("12");
									document.getElementById("80gsmlabel").style.display = "none";
									document.getElementById("80gsmcheck").style.display = "none";
									
									document.getElementById("cat5selqtl").style.display = "none";
//									document.getElementById("qtyqtla").style.display = "none";									
	
		if (cat1selqtl == "Business Cards") {
								
						document.getElementById("cat2selqtl").style.display = "inline";
						document.getElementById("cat3selqtl").style.display = "inline";
						document.getElementById("cat4selqtl").style.display = "inline";
						document.getElementById("qtyqtla").style.display = "inline";									
						document.getElementById("pricesetsdiv").style.display = "none";

										
						//set cat2selqtl
					
						var ourObj = {};				
						ourObj.data = "getprodpkgsellevel2new";
						ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		success: function(data) {
//				alert (data);

	if (level > 0){

//		var precat2 = document.getElementById("cat2selqtl");
//		var cat2selqtl = precat2.options[precat2.selectedIndex].text;	

//		var precat3 = document.getElementById("cat3selqtl");
//		var cat3selqtl = precat3.options[precat3.selectedIndex].text;		

//		var precat4 = document.getElementById("cat4selqtl");
//		var cat4selqtl = precat4.options[precat4.selectedIndex].text;			
		
//		var preqtyqtla = document.getElementById("qtyqtla");
//		var catqtyqtla = preqtyqtla.options[preqtyqtla.selectedIndex].text;			
		
	

		}


	if (level == 0){

		document.getElementById("cat2selqtl").options.length = 0;

			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat2selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat1;
					p.add(option);

											}
								}
								
}

				var davecat2 = document.getElementById("cat2selqtl");
				var cat2selqtl = davecat2.options[davecat2.selectedIndex].text;	
				
				
				
						var ourObj = {};				
						ourObj.data = "getprodpkgsellevel3new";
						ourObj.selcat = cat1selqtl;
						ourObj.selcat2 = cat2selqtl;
//						ourObj.selcat3 = cat3selqtl;
				
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		success: function(data) {
//				alert (data);

	if (level == 0 || level == 1){

	document.getElementById("cat3selqtl").options.length = 0;

		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat3selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat2;
					p.add(option);

											}
								}


					}
			//dave333
												
				var davecat2 = document.getElementById("cat2selqtl");
				var cat2selqtl = davecat2.options[davecat2.selectedIndex].text;	

				var davecat3 = document.getElementById("cat3selqtl");
				var cat3selqtl = davecat3.options[davecat3.selectedIndex].text;	

//				var davecat4 = document.getElementById("cat4selqtl");
	//			var cat4selqtl = davecat4.options[davecat4.selectedIndex].text;	
				
				var ourObj = {};				
				ourObj.data = "getprodpkgsellevel4new";
				ourObj.selcat = cat1selqtl;
				ourObj.selcat2 = cat2selqtl;
				ourObj.selcat3 = cat3selqtl;
		//		ourObj.selcat4 = cat4selqtl;
				
				$.ajax({
					url: '../php/getprodpkg.php',
					type: 'post',
					data: {"points" : JSON.stringify(ourObj)},
					success: function(data) {
//				alert (data);

	if (level == 0 || level == 1){

			document.getElementById("cat4selqtl").options.length = 0;

					var json = JSON.parse(data);

					for (var key in json) {
					
					if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat4selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat3;
					p.add(option);

											}
								}
								
								}
			var davecat2 = document.getElementById("cat2selqtl");
				var cat2selqtl = davecat2.options[davecat2.selectedIndex].text;	

				var davecat3 = document.getElementById("cat3selqtl");
				var cat3selqtl = davecat3.options[davecat3.selectedIndex].text;	

				var davecat4 = document.getElementById("cat4selqtl");
				var cat4selqtl = davecat4.options[davecat4.selectedIndex].text;	
	
								
				var ourObj = {};


				ourObj.data = "getprodpkgsellevel5businesscards";
				
				ourObj.selcat = cat1selqtl;
				ourObj.selcat2 = cat2selqtl;
				ourObj.selcat3 = cat3selqtl;
				ourObj.selcat4 = cat4selqtl;

								
			//dave333
			
							$.ajax({
					url: '../php/getprodpkg.php',
					type: 'post',
					data: {"points" : JSON.stringify(ourObj)},
					success: function(data) {
		//		alert ("bc"+data);
	if (level == 0 || level == 1){

		document.getElementById("qtyqtla").options.length = 0;

		var json = JSON.parse(data);

		for (var key in json) {
					
			if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
				var p = document.getElementById("qtyqtla");
				var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
				option.text = json[key].pkg_qty;
				p.add(option);

			}
		}
	}								
			//dave333
	
//ensure values remain if required

//if (level > 0){
//
//	alert ("do da thing"+cat2selqtl+cat3selqtl+cat4selqtl);
//
//	var cat2selqtl2 = document.getElementById("cat2selqtl");
//	for (var i = 0; i < cat2selqtl2.options.length; i++)
//	{
//		alert (cat2selqtl2.value + cat2selqtl);
//    		if (cat2selqtl2.value == cat2selqtl){
//				alert ("found ir"+cat2selqtl2.value);
//        			cat2selqtl2.options[i].selectedIndex = i;
//		}
//	}

//	var cat3selqtl2 = document.getElementById("cat3selqtl");
//	for (var i = 0; i < cat3selqtl2.options.length; i++)
//	{
 //   		if (cat3selqtl2.value == cat3selqtl){
  //      			cat3selqtl2.options[i].selected = true;
//		}
//	}

//	var cat4selqtl2 = document.getElementById("cat4selqtl");
//	for (var i = 0; i < cat4selqtl2.options.length; i++)
//	{
 //   		if (cat4selqtl2.value == cat4selqtl){
  //      			cat4selqtl2.options[i].selected = true;
//		}
//	}

//	var catqtyqtla2 = document.getElementById("qtyqtla");
//	for (var i = 0; i < catqtyqtla2.options.length; i++)
//	{
 //   		if (catqtyqtla2.value == catqtyqtla){
  //      			catqtyqtla2.options[i].selected = true;
//		}
//	}

//}


	
										getprodpkgprice();
			
			//dave444
			
			
//			alert (data);
        // Do something with data that came back. 
		}
			});	

										
			
			//dave444
			
			
//			alert (data);
        // Do something with data that came back. 
		}
			});	

			//dave444
			
			
//			alert (data);
        // Do something with data that came back. 
		}
			});									
			
//			alert (data);
        // Do something with data that came back. 
		}
			});											
										

					}else if (cat1selqtl == "Wide Format Printing") {
								
						document.getElementById("cat2selqtl").style.display = "inline";
						document.getElementById("cat3selqtl").style.display = "inline";
						document.getElementById("cat4selqtl").style.display = "inline";
						document.getElementById("cat5selqtl").style.display = "inline";
			//			document.getElementById("qtyqtla").style.display = "inline";
						document.getElementById("priceqtydiv").style.display = "inline";

						document.getElementById("qtyqtla").style.display = "none";

						if (level == 0){
							document.getElementById("cat2selqtl").options.length = 0;
							document.getElementById("cat3selqtl").options.length = 0;
							document.getElementById("cat4selqtl").options.length = 0;
							document.getElementById("cat5selqtl").options.length = 0;
						}

						//		document.getElementById("qtyqtla").options.length = 0;
						document.getElementById("pricesetsdiv").style.display = "none";

										
						//set cat2selqtl
					
						var ourObj = {};				
						ourObj.data = "getprodpkgsellevel2new";
						ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		success: function(data) {
//				alert (data);

	if (level == 0){
		
			var json = JSON.parse(data);
			document.getElementById("cat2selqtl").options.length = 0;

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat2selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat1;
					p.add(option);

											}
								}
								
				}
				
				var davecat2 = document.getElementById("cat2selqtl");
				var cat2selqtl = davecat2.options[davecat2.selectedIndex].text;	
				
				
				
						var ourObj = {};				
						ourObj.data = "getprodpkgsellevel3new";
						ourObj.selcat = cat1selqtl;
						ourObj.selcat2 = cat2selqtl;
//						ourObj.selcat3 = cat3selqtl;
				
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		success: function(data) {
//				alert (data);

	if (level == 0 || level == 1){

			document.getElementById("cat3selqtl").options.length = 0;
		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat3selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat2;
					p.add(option);

											}
								}
}								
			//dave333
												
				var davecat2 = document.getElementById("cat2selqtl");
				var cat2selqtl = davecat2.options[davecat2.selectedIndex].text;	

				var davecat3 = document.getElementById("cat3selqtl");
				var cat3selqtl = davecat3.options[davecat3.selectedIndex].text;	

//				var davecat4 = document.getElementById("cat4selqtl");
	//			var cat4selqtl = davecat4.options[davecat4.selectedIndex].text;	
				
				var ourObj = {};				
				ourObj.data = "getprodpkgsellevel4new";
				ourObj.selcat = cat1selqtl;
				ourObj.selcat2 = cat2selqtl;
				ourObj.selcat3 = cat3selqtl;
		//		ourObj.selcat4 = cat4selqtl;

		
				$.ajax({
					url: '../php/getprodpkg.php',
					type: 'post',
					data: {"points" : JSON.stringify(ourObj)},
					success: function(data) {
		//		alert ("12"+data);

			if (level == 0 || level == 1 || level == 2){

					var json = JSON.parse(data);

					document.getElementById("cat4selqtl").options.length = 0;

					for (var key in json) {
					
					if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat4selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat3;
					p.add(option);

											}
								}

}										
			
			//dave444
			
			
//			alert (data);
        // Do something with data that came back. 
		
		
						var davecat2 = document.getElementById("cat2selqtl");
				var cat2selqtl = davecat2.options[davecat2.selectedIndex].text;	

				var davecat3 = document.getElementById("cat3selqtl");
				var cat3selqtl = davecat3.options[davecat3.selectedIndex].text;	

				var davecat4 = document.getElementById("cat4selqtl");
				var cat4selqtl = davecat4.options[davecat4.selectedIndex].text;	

				var ourObj = {};				
				ourObj.data = "getprodpkgsellevel5new";
				ourObj.selcat = cat1selqtl;
				ourObj.selcat2 = cat2selqtl;
				ourObj.selcat3 = cat3selqtl;
				ourObj.selcat4 = cat4selqtl;

				document.getElementById("cat5selqtl").options.length = 0;

				$.ajax({
					url: '../php/getprodpkg.php',
					type: 'post',
					data: {"points" : JSON.stringify(ourObj)},
					success: function(data) {
		//		alert ("12"+data);

					if (level == 0 || level == 1 || level == 2 || level == 3){

					var json = JSON.parse(data);

					for (var key in json) {
					
					if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat5selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat4;
					p.add(option);

											}
								}
								}

getprodpkgprice();
										
			
			//dave444
			
			
//			alert (data);
        // Do something with data that came back. 
		}
			});	
		
		
		}
			});	

			//dave444
			
			
//			alert (data);
        // Do something with data that came back. 
		}
			});									
			
//			alert (data);
        // Do something with data that came back. 
		}
			});											
										
										
	
									}else if (cat1selqtl == "Courier" || cat1selqtl == "Finishing"  || cat1selqtl == "Photocopying DF"  || cat1selqtl == "Photocopying FG" || cat1selqtl == "Tab") {

									document.getElementById("cat3selqtl").style.display="none";
									document.getElementById("cat4selqtl").style.display="none";
									document.getElementById("qtyqtla").style.display="none";
									
																		if (level > 0 ) {
											getprodpkgprice();
//											return false();
									}else{
									document.getElementById("cat2selqtl").options.length = 0;
									document.getElementById("cat3selqtl").options.length = 0;
									document.getElementById("cat4selqtl").options.length = 0;
									document.getElementById("qtyqtla").options.length = 0;
									
									//dave22
					var ourObj = {};				

					ourObj.data = "getprodpkgalllevel2";
					ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		success: function(data) {
	//			alert (data);


		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat2selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_code_name);
					option.text = json[key].pkg_subcat1;
					p.add(option);

											}
								}
								
						getprodpkgprice();
			
//			alert (data);
        // Do something with data that came back. 
		}
			});	
			}
												}else if (cat1selqtl == "Paper" || cat1selqtl == "Foam Board") {
//alert ("paperfb");

									document.getElementById("80gsmlabel").style.display = "none";
									document.getElementById("80gsmcheck").style.display = "none";

									
									document.getElementById("pricesetsdiv").style.display = "none";
									document.getElementById("priceppdiv").style.display = "none";
									document.getElementById("priceqtydiv").style.display = "inline";

									document.getElementById("cat3selqtl").style.display="inline";
									document.getElementById("cat4selqtl").style.display="inline";
									document.getElementById("qtyqtla").style.display="none";

									if (level > 0 ) {
											getprodpkgprice();
//											return false();
									}else{
									
									document.getElementById("cat2selqtl").options.length = 0;
									document.getElementById("cat3selqtl").options.length = 0;
									document.getElementById("cat4selqtl").options.length = 0;
									document.getElementById("qtyqtla").options.length = 0;
									

									
									//dave22
					var ourObj = {};				

					ourObj.data = "getprodpkgalllevel2";
					ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
        async: false, //blocks window close
		success: function(data) {
		//		alert (data);


		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat2selqtl");
					var option = document.createElement("option");
			//		alert (json[key].pkg_subcat1);
					option.text = json[key].pkg_subcat1;
					p.add(option);

											}
								}
								

			
//			alert (data);
        // Do something with data that came back. 
		}
			});	
			
					var ourObj = {};				
					
					var e = document.getElementById("cat2selqtl");
					var selcat2 = e.options[e.selectedIndex].text;
					
	//				alert (selcat2);
					
					ourObj.data = "getprodpkgalllevel3andlevel2";
					ourObj.selcat = cat1selqtl;
					ourObj.selcat2 = selcat2;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		          async: false, //blocks window close
		success: function(data) {
	//			alert (data);


		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
				//	alert(json[key].pkg_code_name);
			var p = document.getElementById("cat3selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_subcat2);
					option.text = json[key].pkg_subcat2;
					p.add(option);

											}
								}
													
				//			getprodpkgprice();
					
//			alert (data);
        // Do something with data that came back. 
		}
			});	
			
													var ourObj = {};				

					var e2 = document.getElementById("cat2selqtl");
					var selcat2 = e2.options[e2.selectedIndex].text;

					var f2 = document.getElementById("cat3selqtl");
					var selcat3 = f2.options[f2.selectedIndex].text;
					
					ourObj.data = "getprodpkgalllevel4level3";
					ourObj.selcat = cat1selqtl;
					ourObj.selcat2 = selcat2;
					ourObj.selcat3 = selcat3;
					
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		          async: false, //blocks window close
		success: function(data) {
			//	alert (data);


		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
				//	alert(json[key].pkg_code_name);
			var p = document.getElementById("cat4selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_subcat2);
					option.text = json[key].pkg_subcat3;
					p.add(option);

											}
								}
													
							getprodpkgprice();
					
//			alert (data);
        // Do something with data that came back. 
		}
			});					
									
		}
					
									}else if (cat1selqtl == "Foam Boards") {
								
									if (level > 0 ) {
											getprodpkgprice();
//											return false();
									}else{
									document.getElementById("cat2selqtl").options.length = 0;
									document.getElementById("cat3selqtl").options.length = 0;
									document.getElementById("cat4selqtl").options.length = 0;
									document.getElementById("qtyqtla").options.length = 0;
									
										var x = document.getElementById("cat2selqtl");
										var option = document.createElement("option");
										option.text = "Foam Board Only";
										x.add(option);
										var option = document.createElement("option");
										option.text = "Foam Board Mount Only";
										x.add(option);
										
										var option = document.createElement("option");
										option.text = "Print, Laminate, Mount";
										x.add(option);

										var y = document.getElementById("cat3selqtl");
										var option = document.createElement("option");
										option.text = "A4";
										y.add(option);
										var option = document.createElement("option");
										option.text = "A3";
										y.add(option);
										var option = document.createElement("option");
										option.text = "A2";
										y.add(option);
										var option = document.createElement("option");
										option.text = "A1";
										y.add(option);
										var option = document.createElement("option");
										option.text = "A0";
										y.add(option);

										var z = document.getElementById("cat4selqtl");
										var option = document.createElement("option");
										option.text = "Black";
										z.add(option);
										var option = document.createElement("option");
										option.text = "White";
										z.add(option);
									
										var w = document.getElementById("qtyqtla");
										var option = document.createElement("option");
										option.text = "1";
										w.add(option);
										
										getprodpkgprice();
										}
									}else if (cat1selqtl == "Binding" || cat1selqtl == "Envelope" || cat1selqtl == "Folder" || cat1selqtl == "Pouch laminating"){
//alert ("bindendfold");
									document.getElementById("80gsmlabel").style.display = "none";
									document.getElementById("80gsmcheck").style.display = "none";

									
									document.getElementById("pricesetsdiv").style.display = "none";
									document.getElementById("priceppdiv").style.display = "none";
									document.getElementById("priceqtydiv").style.display = "inline";

									document.getElementById("cat3selqtl").style.display="inline";
									document.getElementById("cat4selqtl").style.display="none";
									document.getElementById("qtyqtla").style.display="none";

									if (level > 0 ) {
											getprodpkgprice();
//											return false();
									}else{									
									
									document.getElementById("cat2selqtl").options.length = 0;
									document.getElementById("cat3selqtl").options.length = 0;
									document.getElementById("cat4selqtl").options.length = 0;
									document.getElementById("qtyqtla").options.length = 0;
									

									
									//dave22
					var ourObj = {};				

					ourObj.data = "getprodpkgalllevel2";
					ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
        async: false, //blocks window close
		success: function(data) {
		//		alert (data);


		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat2selqtl");
					var option = document.createElement("option");
			//		alert (json[key].pkg_subcat1);
					option.text = json[key].pkg_subcat1;
					p.add(option);

											}
								}
								

			
//			alert (data);
        // Do something with data that came back. 
		}
			});	
			
								var ourObj = {};				

					ourObj.data = "getprodpkgalllevel3";
					ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		          async: false, //blocks window close
		success: function(data) {
	//			alert (data);


		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
				//	alert(json[key].pkg_code_name);
			var p = document.getElementById("cat3selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_subcat2);
					option.text = json[key].pkg_subcat2;
					p.add(option);

											}
								}
													
							getprodpkgprice();
					
//			alert (data);
        // Do something with data that came back. 
		}
			});	
			
									}
																

									}else if (cat1selqtl == "Digital Printing") {

									document.getElementById("80gsmlabel").style.display = "inline";
									document.getElementById("80gsmcheck").style.display = "inline";

									document.getElementById("priceppdiv").style.display = "inline";
									document.getElementById("priceqtydiv").style.display = "inline";

									document.getElementById("cat3selqtl").style.display="inline";
									document.getElementById("cat4selqtl").style.display="inline";
									document.getElementById("qtyqtla").style.display="none";

									document.getElementById("pricesetsdiv").style.display = "inline";
									
									if (level > 0 ) {
											getprodpkgprice();
//											return false();
									}else{
									
								

			//			if (level == 0){
									
									
									document.getElementById("cat2selqtl").options.length = 0;
									document.getElementById("cat3selqtl").options.length = 0;
									document.getElementById("cat4selqtl").options.length = 0;
									document.getElementById("qtyqtla").options.length = 0;

//}									

									var x = document.getElementById("cat4selqtl");
									
									var option = document.createElement("option");
									option.text = "Single Sided";
									x.add(option);
					
									var option = document.createElement("option");
									option.text = "Double Sided";
									x.add(option);

									
									//dave22
					var ourObj = {};				

					ourObj.data = "getprodpkgalllevel2";
					ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
        async: false, //blocks window close
		success: function(data) {
		//		alert (data);

		//				if (level == 0){
		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
//					alert(json[key].pkg_code_name);
			var p = document.getElementById("cat2selqtl");
					var option = document.createElement("option");
			//		alert (json[key].pkg_subcat1);
					option.text = json[key].pkg_subcat1;
					p.add(option);

											}
								}
								
//}
			
//			alert (data);
        // Do something with data that came back. 
		}
			});	
			
								var ourObj = {};				

					ourObj.data = "getprodpkgalllevel3";
					ourObj.selcat = cat1selqtl;
					
															$.ajax({
		url: '../php/getprodpkg.php',
		type: 'post',
		data: {"points" : JSON.stringify(ourObj)},
		          async: false, //blocks window close
		success: function(data) {
	//			alert (data);

					//	if (level == 0){
		
			var json = JSON.parse(data);

			for (var key in json) {
				if (json.hasOwnProperty(key)) {
				//	alert(json[key].pkg_code_name);
			var p = document.getElementById("cat3selqtl");
					var option = document.createElement("option");
				//	alert (json[key].pkg_subcat2);
					option.text = json[key].pkg_subcat2;
					p.add(option);

											}
								}
						//		}
													
							getprodpkgprice();
					
//			alert (data);
        // Do something with data that came back. 
		}
			});	
			
									
																

	}
									
									}									
														
									
	
													
								 }    

				
		 function getprodpkgprice(level) {
					//							alert ("draft"+st_id+mode);

		//		alert ("getprodpkgprice");


				if (level === undefined || level === null) {
				
					var level = 0;
				
				}else{

					var level = level;
				
				}
				
				var cat5selqtl = "";
					
		//		if (initial_cat == 
				var c1 = document.getElementById("cat1selqtl");
				var cat1selqtl = c1.options[c1.selectedIndex].text;
				
	//			document.getElementById("pricegen").value = 0;
		//		document.getElementById("pricediffperc").value = "0 %";
				
				if (cat1selqtl == "Business Cards"){
				
//					alert (cat1selqtl);
				
					var c2 = document.getElementById("cat2selqtl");
					var cat2selqtl = c2.options[c2.selectedIndex].text;

					var c3 = document.getElementById("cat3selqtl");
					var cat3selqtl = c3.options[c3.selectedIndex].text;

					var c4 = document.getElementById("cat4selqtl");
					var cat4selqtl = c4.options[c4.selectedIndex].text;

					var q1 = document.getElementById("qtyqtla");
					var qtyqtla = q1.options[q1.selectedIndex].text;

					
				}else if (cat1selqtl == "Binding" || cat1selqtl == "Envelope" || cat1selqtl == "Folder"  || cat1selqtl == "Pouch laminating"){

					var c2 = document.getElementById("cat2selqtl");
					var cat2selqtl = c2.options[c2.selectedIndex].text;

					var c3 = document.getElementById("cat3selqtl");
					var cat3selqtl = c3.options[c3.selectedIndex].text;
					
					var cat4selqtl = "";
					
					var qtyqtla = 	document.getElementById("priceqty").value;
					
			//		alert (qtlqtla);
					
				}else if (cat1selqtl == "Paper"){
				//	alert ("pp");

					var c2 = document.getElementById("cat2selqtl");
					var cat2selqtl = c2.options[c2.selectedIndex].text;

					var c3 = document.getElementById("cat3selqtl");
					var cat3selqtl = c3.options[c3.selectedIndex].text;

					var c4 = document.getElementById("cat4selqtl");
					var cat4selqtl = c4.options[c4.selectedIndex].text;
					
					var qtyqtla = 	document.getElementById("priceqty").value;

			//		var q1 = document.getElementById("qtyqtla");
				//	var qtyqtla = q1.options[q1.selectedIndex].text;

				}else if (cat1selqtl == "Wide Format Printing"){
			//		alert ("pp");

					var c2 = document.getElementById("cat2selqtl");
					var cat2selqtl = c2.options[c2.selectedIndex].text;

					var c3 = document.getElementById("cat3selqtl");
					var cat3selqtl = c3.options[c3.selectedIndex].text;

					var c4 = document.getElementById("cat4selqtl");
					var cat4selqtl = c4.options[c4.selectedIndex].text;

					var c5 = document.getElementById("cat5selqtl");
					var cat5selqtl = c5.options[c5.selectedIndex].text;
					
					var qtyqtla = 	document.getElementById("priceqty").value;

			//		var q1 = document.getElementById("qtyqtla");
				//	var qtyqtla = q1.options[q1.selectedIndex].text;


				
				}else if (cat1selqtl == "Courier"){
					
				//	alert ("courier");

					var c2 = document.getElementById("cat2selqtl");
					var cat2selqtl = c2.options[c2.selectedIndex].text;

					var cat3selqtl = "";
					var cat4selqtl = "";				

					var qtyqtla = 1;

				}else if (cat1selqtl == "Digital Printing"){
					
//					alert ("DP");

					//size

					var c2 = document.getElementById("cat2selqtl");
					var cat2selqtl = c2.options[c2.selectedIndex].text;

					
					//col - bw
					var c3 = document.getElementById("cat3selqtl");
					var cat3selqtl = c3.options[c3.selectedIndex].text;


					//ss - ds
					var c4 = document.getElementById("cat4selqtl");
					var cat4selqtl = c4.options[c4.selectedIndex].text;
					

					var pricepp 	 = document.getElementById("pricepp").value;
					var pricesets	 = document.getElementById("pricesets").value;

					var qtyqtla = (pricesets * pricepp);
			//		alert (qtyqtla);
					
					document.getElementById("priceqty").value = qtyqtla;
				}


				//	alert ("changed select");
//									alert (cat1selqtl);	

									
				
		var hr = new XMLHttpRequest();
 
		// Create some variables we need to send to our PHP file
	
		var url = "../php/getprodpkgprice.php";

		var cat1selqtl	 = cat1selqtl.replace("&","#$#$#$?");		
		var cat2selqtl	 = cat2selqtl.replace("&","#$#$#$?");		
		var cat3selqtl	 = cat3selqtl.replace("&","#$#$#$?");		
		var cat4selqtl	 = cat4selqtl.replace("&","#$#$#$?");		
		var cat5selqtl	 = cat5selqtl.replace("&","#$#$#$?");		
		
		var vars = "cat1selqtl="+cat1selqtl+"&cat2selqtl="+cat2selqtl+"&cat3selqtl="+cat3selqtl+"&cat4selqtl="+cat4selqtl+"&cat5selqtl="+cat5selqtl+"&qtyqtla="+qtyqtla;

//		alert (vars);
		
		hr.open("POST", url, true);
 
		// Set content type header  for sending url encoded variables in the request
 
		hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	
		// Access the onreadystatechange event for the XMLHttpRequest object
 
		hr.onreadystatechange = function() {
		
		if(hr.readyState == 4 && hr.status == 200) {

//		   	alert (hr.responseText);

			var data = hr.responseText;			

			obj = JSON.parse(data);
			
//			document.getElementById('comphead').style.display = 'none';
			
			var pkg_cell_pricenum = obj.pkg_sell_price;
			var pkg_descr		  = obj.pkg_descr;

			//		alert (obj.pkg_sell_price);

	//		var pkg_cell_pricenum = parseFloat(pkg_cell_pricenum.replace(/,/g,''))
		//	alert ("hello");
			
			
			if (isNaN(pkg_cell_pricenum)){

				document.getElementById('priceunit').value = 0;
		
				document.getElementById('priceqtya').value = 0;
				
				document.getElementById('priceunitgen').value = 0;

				document.getElementById('priceqtya').style.background = "red";

			}else{
			
				var priceqty = document.getElementById('priceqty').value;
				
				document.getElementById('priceunit').value = obj.pkg_unit_price;

				document.getElementById('priceunitgen').value = obj.pkg_unit_price;

				var pricegencalc = obj.pkg_unit_price * priceqty;
				
				document.getElementById('pricegen').value = pricegencalc.toFixed(2);


//				generated price /100*newprice
				
				document.getElementById('priceqtya').value = obj.pkg_sell_price;
				document.getElementById('priceqtya').style.background = "lightgreen";

				var pricediff = (document.getElementById('pricegen').value - document.getElementById('priceqtya').value);
//				alert (pricediff);
				document.getElementById('pricediff').value = pricediff;

				
			}
			
			document.getElementById('product_descr').value = pkg_descr;
			
			calcpriceqty();
			
			var job_st_id = obj.job_st_id;
			

		
		}

		}
		
		    hr.send(vars); // Actually execute the request

			
	
}


		 function calcpriceqty() {
			 
			 var priceunit = document.getElementById('priceunit').value;
			 var priceqty = document.getElementById('priceqty').value;
		 
			var priceqtya = priceunit * priceqty;
			
			document.getElementById('priceqtya').value = priceqtya;

				var pricegeni = document.getElementById('pricegen').value;
				var priceqtyai = document.getElementById('priceqtya').value;
				
				pricegeni 	= pricegeni.replace(",","");
				priceqtyai 	= priceqtyai.replace(",","");

				var pricediff = (pricegeni - priceqtyai);
//				alert (pricediff);

				document.getElementById('pricediff').value = pricediff;

//				alert (pricegeni);
				
				if (pricegeni == 0){
					var pricediffperc = 0;
				document.getElementById('pricediffperc').value = "0%";
					}else{
				//		alert(priceqtya+""+pricegen);
					var pricediffperc = (priceqtyai-pricegeni)/pricegeni*100;
				//	alert (pricediffperc);
					document.getElementById('pricediffperc').value = pricediffperc.toFixed(2) + "%";
				}


			
		 }
		 
		 
		 		 
		 						         function qtladvadd(){
								 
var new_value = 1012;

var job_start_date = "";
var job_end_date = "";
						//			alert ("advanced add232");
		var suid			= document.getElementById("j_st_id").value;
		
		var b = document.getElementById("cat1selqtl");
		var cat1selqtl = b.options[b.selectedIndex].text;

		
		if (cat1selqtl == "Business Cards") {
											
			var newqty			= document.getElementById("defqtyqtl").value;
			var priceqtya	=	 document.getElementById("priceqtya").value;

			var a = document.getElementById("qtyqtla");
			var qtyqtla = a.options[a.selectedIndex].text;

			var b = document.getElementById("cat1selqtl");
			var cat1selqtl = b.options[b.selectedIndex].text;

			var c = document.getElementById("cat2selqtl");
			var cat2selqtl = c.options[c.selectedIndex].text;		
	
			var d = document.getElementById("cat3selqtl");
			var cat3selqtl = d.options[d.selectedIndex].text;		

			var e = document.getElementById("cat4selqtl");
			var cat4selqtl = e.options[e.selectedIndex].text;	

			var priceunit		=	document.getElementById("priceunit").value;			
		
			var item_name = qtyqtla + " " + cat1selqtl + " " + cat2selqtl + " " + cat3selqtl + " " + cat4selqtl;
		
			var item_name = item_name.trim();
		
		}else if (cat1selqtl == "Digital Printing") {

			var newqty			= 	document.getElementById("priceqty").value;
			var priceqtya		=	document.getElementById("priceqtya").value;
			var pricepp			=	document.getElementById("pricepp").value;
			var pricesets		=	document.getElementById("pricesets").value;
			var priceunit		=	document.getElementById("priceunit").value;
			var check80gsm		=	document.getElementById("80gsmcheck").checked;
			
		//	var a = document.getElementById("qtyqtla");
	//		var qtyqtla = a.options[a.selectedIndex].text;



			//size
			var c = document.getElementById("cat2selqtl");
			var cat2selqtl = c.options[c.selectedIndex].text;		
			
			//col bw
			var d = document.getElementById("cat3selqtl");
			var cat3selqtl = d.options[d.selectedIndex].text;		

			//single dbl
			var e = document.getElementById("cat4selqtl");
			var cat4selqtl = e.options[e.selectedIndex].text;		
		
			var item_name = pricepp + "pp " + cat2selqtl + " " + cat3selqtl + " " + cat4selqtl + " x " + pricesets + " Sets";
			
			if (check80gsm === true){
					item_name = item_name + " on 80 gsm";
			}
		
			var item_name = item_name.trim();		
//			alert (item_name + check80gsm);
			var item_name = item_name.trim();
			var item_name = item_name.replace(/"/g, "*#qd");
			var item_name = item_name.replace(/'/g, "*#qs");

		}else if (cat1selqtl == "Paper") {

//			alert ("paper");
			var newqty			= 	document.getElementById("priceqty").value;
			var priceqtya		=	document.getElementById("priceqtya").value;
			var pricepp			=	document.getElementById("pricepp").value;
			var pricesets		=	document.getElementById("pricesets").value;
			var priceunit		=	document.getElementById("priceunit").value;
			var check80gsm		=	document.getElementById("80gsmcheck").checked;
			
		//	var a = document.getElementById("qtyqtla");
	//		var qtyqtla = a.options[a.selectedIndex].text;



			//paper type
			var c = document.getElementById("cat2selqtl");
			var cat2selqtl = c.options[c.selectedIndex].text;		
			
			//size
			var d = document.getElementById("cat3selqtl");
			var cat3selqtl = d.options[d.selectedIndex].text;		

			//gsm
			var e = document.getElementById("cat4selqtl");
			var cat4selqtl = e.options[e.selectedIndex].text;		
		
			var item_name = cat2selqtl + " " + cat3selqtl + " " + cat4selqtl;
			
		
			var item_name = item_name.trim();		
//			alert (item_name + check80gsm);
			var item_name = item_name.trim();
			var item_name = item_name.replace(/"/g, "*#qd");
			var item_name = item_name.replace(/'/g, "*#qs");

		}else if (cat1selqtl == "Wide Format Printing") {

//			alert ("paper");
			var newqty			= 	document.getElementById("priceqty").value;
//			var priceqtya		=	document.getElementById("priceqtya").value;
	//		var pricepp			=	document.getElementById("pricepp").value;
		//	var pricesets		=	document.getElementById("pricesets").value;
			var priceunit		=	document.getElementById("priceunit").value;
			var priceqtya		=	document.getElementById("priceqtya").value;
			var product_descr	=	document.getElementById("product_descr").value;
//			var check80gsm		=	document.getElementById("80gsmcheck").checked;
			
		//	var a = document.getElementById("qtyqtla");
	//		var qtyqtla = a.options[a.selectedIndex].text;


			var item_name = product_descr.trim();
			var item_name = item_name.replace(/"/g, "*#qd");
			var item_name = item_name.replace(/'/g, "*#qs");

			
			
		}else if (cat1selqtl == "Binding") {

			var newqty			= 	document.getElementById("priceqty").value;
			var priceqtya		=	document.getElementById("priceqtya").value;
	//		var pricepp			=	document.getElementById("pricepp").value;
	//		var pricesets		=	document.getElementById("pricesets").value;
	//		var check80gsm		=	document.getElementById("80gsmcheck").checked;
			
		//	var a = document.getElementById("qtyqtla");
	//		var qtyqtla = a.options[a.selectedIndex].text;

			var priceunit		=	document.getElementById("priceunit").value;

			//size
			var c = document.getElementById("cat2selqtl");
			var cat2selqtl = c.options[c.selectedIndex].text;		
			
			//col bw
			var d = document.getElementById("cat3selqtl");
			var cat3selqtl = d.options[d.selectedIndex].text;		

			//single dbl
	//		var e = document.getElementById("cat4selqtl");
	//		var cat4selqtl = e.options[e.selectedIndex].text;		
		
			var item_name = cat2selqtl + " " + cat3selqtl;
			
	//		if (check80gsm === true){
	//				item_name = item_name + " on 80 gsm";
	//		}
		
			var item_name = item_name.trim();		
//			alert (item_name + check80gsm);

			var item_name = item_name.trim();
			var item_name = item_name.replace(/"/g, "*#qd");
			var item_name = item_name.replace(/'/g, "*#qs");
			
			
	}else if (cat1selqtl == "Pouch laminating") {

			var newqty			= 	document.getElementById("priceqty").value;
			var priceqtya		=	document.getElementById("priceqtya").value;
	//		var pricepp			=	document.getElementById("pricepp").value;
	//		var pricesets		=	document.getElementById("pricesets").value;
	//		var check80gsm		=	document.getElementById("80gsmcheck").checked;
			
		//	var a = document.getElementById("qtyqtla");
	//		var qtyqtla = a.options[a.selectedIndex].text;

			var priceunit		=	document.getElementById("priceunit").value;

			//size
			var c = document.getElementById("cat2selqtl");
			var cat2selqtl = c.options[c.selectedIndex].text;		
			
			//col bw
			var d = document.getElementById("cat3selqtl");
			var cat3selqtl = d.options[d.selectedIndex].text;		

			//single dbl
	//		var e = document.getElementById("cat4selqtl");
	//		var cat4selqtl = e.options[e.selectedIndex].text;		
		
			var item_name = cat2selqtl + " " + cat3selqtl;
			
	//		if (check80gsm === true){
	//				item_name = item_name + " on 80 gsm";
	//		}
		
			var item_name = item_name.trim();		
//			alert (item_name + check80gsm);

			var item_name = item_name.trim();
			var item_name = item_name.replace(/"/g, "*#qd");
			var item_name = item_name.replace(/'/g, "*#qs");

		}else if (cat1selqtl == "Courier") {

	//		var newqty			= 	document.getElementById("priceqty").value;
	//		var priceqtya		=	document.getElementById("priceqtya").value;
	//		var pricepp			=	document.getElementById("pricepp").value;
	//		var pricesets		=	document.getElementById("pricesets").value;
	//		var check80gsm		=	document.getElementById("80gsmcheck").checked;
			
		//	var a = document.getElementById("qtyqtla");
	//		var qtyqtla = a.options[a.selectedIndex].text;

			var newqty 		=	1;
			var qtyqtla 		=	1;
			var priceunit		=	document.getElementById("priceunit").value;
			var priceqtya 		=	priceunit;

			//courier type
			var c = document.getElementById("cat2selqtl");
			var cat2selqtl = c.options[c.selectedIndex].text;		
			
			//col bw
	//		var d = document.getElementById("cat3selqtl");
		//	var cat3selqtl = d.options[d.selectedIndex].text;		

			//single dbl
	//		var e = document.getElementById("cat4selqtl");
	//		var cat4selqtl = e.options[e.selectedIndex].text;		
		
			var item_name = cat2selqtl;
			
	//		if (check80gsm === true){
	//				item_name = item_name + " on 80 gsm";
	//		}
		
			var item_name = item_name.trim();		
//			alert (item_name + check80gsm);

			var item_name = item_name.trim();
			var item_name = item_name.replace(/"/g, "*#qd");
			var item_name = item_name.replace(/'/g, "*#qs");

		
		}else{

			var newqty			= document.getElementById("defqtyqtl").value;
			var priceqtya	=	 document.getElementById("priceqtya").value;
			var priceunit		=	document.getElementById("priceunit").value;
			
			var a = document.getElementById("qtyqtla");
			var qtyqtla = a.options[a.selectedIndex].text;

			var b = document.getElementById("cat1selqtl");
			var cat1selqtl = b.options[b.selectedIndex].text;

			var c = document.getElementById("cat2selqtl");
			var cat2selqtl = c.options[c.selectedIndex].text;		

			var d = document.getElementById("cat3selqtl");
			var cat3selqtl = d.options[d.selectedIndex].text;		

			var e = document.getElementById("cat4selqtl");
			var cat4selqtl = e.options[e.selectedIndex].text;		
		
			var item_name = qtyqtla + " " + cat1selqtl + " " + cat2selqtl + " " + cat3selqtl + " " + cat4selqtl;
		
			var item_name = item_name.trim();
			var item_name = item_name.replace(/"/g, "*#qd");
			var item_name = item_name.replace(/'/g, "*#qs");


		}
		
	//	alert ("item name is" + item_name);
		
		var itemfields = {};

		itemfields.sales_id	 		= 	suid;	
		itemfields.item_name 		= 	item_name;
		itemfields.suid				= 	suid;
		itemfields.new_value		= 	new_value;
		itemfields.job_start_date	= 	job_start_date;
		itemfields.job_end_date		= 	job_end_date;
		itemfields.suid		 		= 	suid;
		itemfields.new_qty			=	newqty;
		itemfields.priceqtya		=	priceqtya;
		itemfields.priceunit		=	priceunit;
		itemfields.cat1selqtl		=	cat1selqtl;
	//	itemfields.item_name 		= 	"hello12";
		
	//	alert (JSON.stringify(itemfields));
		
					$.ajax({
				url: '../php/rentaladdqtl2.php',
				type: 'post',
				data: {"itemfields" : JSON.stringify(itemfields)},
				success: function(data) {
				//
							//		alert ("returned12"+data);

					obj = JSON.parse(data);
			
					var result_message = obj.result_message;
				if (result_message == "Insert Successful"){
										
				//	alert (data);

					var response_ttl_quote = parseFloat(obj.ttl_quote).toFixed(2);

				
					if (result_message == "Insert Successful") {
						
												reload_qty()
						document.getElementById("tagsqtl").value = "";
						document.getElementById('tagsqtl').focus();
						document.getElementById('tagsqtl').select();


						reload_qty();
//						location.reload(true);

		//				document.getElementById("j_ttl_quote").value = response_ttl_quote;
									
					}else{
						document.getElementById("chargemessageqtl").innerHTML = xmlhttp.responseText;
		//			alert (xmlhttp.responseText);
					}

			//	alert (xmlhttp.responseText);	
				}else{
					alert ("Update failed error details are22"+data);
				}
//				alert (data);

//					alert (field_name+data);
					// Do something with data that came back. 
				}
			});
		
	//	alert ("rentaladdqtl2.php?suid="+suid+"&new_value="+new_value+"&job_start_date="+job_start_date+"&job_end_date="+job_end_date+"&newqty="+newqty+"&item_name="+item_name);
//		alert (item_name);
		


									}
									
											function removeqtl(uid) {

			var sales_id			= document.getElementById("j_st_id").value;
							
							//				alert (uid + qty + todo);
                                                
        $.ajax({
           url: '../php/delsimplyqtl.php',
           type: 'post',
           async: 'false',
           data: {"sales_id" : sales_id, "uid" : uid},
           success: function(data) {
			   
		//	   alert ("returndata"+data);
			   
	//		   return false;
			   
                                                                                
                var obj = JSON.parse( data );
 
                var field_name 	  	= obj.field_name;
                var field_value 	  	= obj.field_value;

                var result_message   		= obj.result_message;
                  //
				  
				if (result_message == "Validation Failed"){
					  
                }else if (result_message == "Delete Successful"){
					  

					load_cart();
						  
				//	  }
				}else{
					
					alert ("delete item error"+data);
            }
		   }
            });                                           
                                                
                                                
    } 
	
	
	function reload_qty(){
		
		load_cart();
		
	}
	


		 
	  	 function update_field_contact_sec(field_name, field_type, field_value, field_value2) {

		//	alert ("update"+field_name+field_type+field_value+field_value2);
			
		//	return false;
			
			
			var uid_client			= document.getElementById('cv_uid_client').value;
			
		//	alert (uid_client);
			

	//		var element_je_job_outlet_name = document.getElementById('je_job_outlet_name')
			var outlet_id 			= 1;			
			var old_status			= "";

			var c_favcmts 			= "";

			
			//set defaults
			var c_favcmts = "";
			var c_popup = "";

				

				var field_type			= "inputsec";
				var field_name1_db		= field_name;
				var field_name2_db		= "";
				var field_value1		= field_value;
				var field_value2 		= field_value2;
				var c_favcmts 			=  "";
				
			//	alert (c_favcmts);
				
		
		
			var jobfields = {};

			jobfields.sales_id	 = 0;			
			jobfields.field_name = field_name;
			jobfields.field_type = field_type;
			jobfields.field_name1_db = field_name1_db;
			jobfields.field_name2_db = field_name2_db;
			jobfields.field_value1 = field_value1;
			jobfields.field_value2 = field_value2;
			jobfields.old_status = old_status;
			jobfields.uid_client = uid_client;
			jobfields.outlet_id = outlet_id;			
			
	//		alert (jobfields.field_name);
	//		alert ("about to ajax");


			
	//		alert (JSON.stringify(jobfields));
			
//			alert (c_favcmts);
			
			
			
			$.ajax({
				url: '../php/orderupdcontactfieldsec.php',
				type: 'post',
				data: {"jobfields" : JSON.stringify(jobfields), "c_favcmts" : c_favcmts, "c_popup" : c_popup},
				success: function(data) {
			//		alert ("success"+data);
				//
				if (data == "Update Successful"){
				}else{
					alert ("Update failed error details are"+data);
				}
//				alert (data);

//					alert (field_name+data);
					// Do something with data that came back. 
				}
			});			
			
		//	alert (	jobfields.sales_id+jobfields.field_name+jobfields.field_type+jobfields.field_name1_db+jobfields.field_name2_db+jobfields.field_value1+jobfields.field_value2);


			
		 }
 function create_contact(uid_client){
	
			var st_id				= 0;
			var new_uid_client	 	= uid_client;
			
		//	var new_cont_name 		= document.getElementById('new_cont_name').value;
		//	var new_cont_mobile 	= document.getElementById('new_cont_mobile').value;
		//	var new_cont_email 		= document.getElementById('new_cont_email').value;
		//	var new_cont_jobtitle 	= document.getElementById('new_cont_jobtitle').value;
			
			var new_cont_name 		= "";
			var new_cont_mobile 	= "";
			var new_cont_email 		= "";
			var new_cont_jobtitle 	= "";
			
			
			var new_cont_attn 		= "";
						

					//		alert (new_cont_name);
							

//			if (new_cont_name == ""){

	//			document.getElementById('diverr').innerHTML = "<span style='color: red;'>You must enter a contact name</span>";

		//		return false;
				
			
		//	}else{
				
				
		//	}



			var outlet_id 			= 1;			
			
			var field_type			= "input";
			
				
			var sales_id = 0;
			
		
			var jobfields = {};

			jobfields.st_id	 				= st_id;
			jobfields.new_uid_client		= new_uid_client;			
			jobfields.new_cont_name 		= new_cont_name;
			jobfields.new_cont_mobile 		= new_cont_mobile;
			jobfields.new_cont_email 		= new_cont_email;
			jobfields.new_cont_jobtitle 	= new_cont_jobtitle;
			jobfields.new_cont_attn 		= new_cont_attn;
		

			
			$.ajax({
				url: '../php/jobaddcontactclient.php',
				type: 'post',
				async: 'false',
				data: {"jobfields" : JSON.stringify(jobfields)},
				success: function(data) {
				//	alert ("returned"+data);
				//
		
					var obj = JSON.parse( data );
					var phx_result = obj.phx_result;

				if (phx_result == ""){
					
					
						$.ajax({
							url: '../php/getcustmulticontact2.php',
							type: 'post',
							async: 'true',
							data: {"uid_client" : uid_client},	
							success: function(data) {
								
					//			alert (data);
							
								document.getElementById('divmulticontact').innerHTML = data;
					
							}
						});	
					
				//	$("#butclose").click();
					
				//	 $('#datatablequal').DataTable().ajax.reload();

				
				}else{
					alert ("Update failed error details are"+data);
				}
//				alert (data);

//					alert (field_name+data);
					// Do something with data that came back. 
				}
			});			
			
		//	alert (	jobfields.sales_id+jobfields.field_name+jobfields.field_type+jobfields.field_name1_db+jobfields.field_name2_db+jobfields.field_value1+jobfields.field_value2);

			
		
	
	
}


 	 function del_custcontact(con_uid, uid_client) {


			var current_function	= "delmulticontact";
			
		
			var jobfields = {};

			jobfields.con_uid			= con_uid;

			jobfields.current_function	= current_function;

			
	//		alert (JSON.stringify(jobfields));

			
			$.ajax({
				url: '../php/delmulticontact.php',
				type: 'post',
				async: 'false',
				data: {"jobfields" : JSON.stringify(jobfields)},
				success: function(data) {
					
					
				//	alert (data);

					
						$.ajax({
							url: '../php/getcustmulticontact2.php',
							type: 'post',
							async: 'true',
							data: {"uid_client" : uid_client},	
							success: function(data) {
								
							//	alert (data);
							
								document.getElementById('divmulticontact').innerHTML = data;
					
							}
						});	
								


				}
			});			
			
		//	alert (	jobfields.sales_id+jobfields.field_name+jobfields.field_type+jobfields.field_name1_db+jobfields.field_name2_db+jobfields.field_value1+jobfields.field_value2);

			
		 }
</script>

</body>

</html>