<?php session_start();
		if (isset($_SESSION['logged']) && $_SESSION['logged'] == 'yes') {
			include ('../scripts/classes.php'); //Connect Database
			if ($_SESSION['lang']=="EN"){include ('../lang/en.php');}elseif ($_SESSION['lang']=="GR"){include ('../lang/gr.php');}else{include ('../lang/en.php');}
			$mode = $lbl_idle_scan_page;
			$page_title =$lbl_cls_ready ;
			
			$array = getGlobalSettings();foreach ($array as $settings){extract($settings);}
			$array = getClsSettings();foreach ($array as $cls_settings){extract($cls_settings);}			
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title ?></title>
<link rel="shortcut icon" href="../img/favicon.png" />
<link href="../cms1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../scripts/prototype.js"></script>
<script type="text/javascript" src="../scripts/menu.js" ></script>
<script type="text/javascript">
	function checkLength(field) {
        if (field.value.length == <?php echo $barcode_len ?>)	
        {
            return processForm();
        }
	}
</script>
<script type="text/javascript">
  function processForm()
  {
    $('submit').disabled = true;
    $('submit').value = "Αναζήτηση...";

    $('barcode_frm').request({
      onSuccess: function(transport)
      {
        if(transport.responseText.match(/^OK/) != null) {
		<!--          $('barcode_frm').reset();-->
		window.location=('customer_status.php?barcode='+$('barcode').value );
        } else {
			document.getElementById('errorloc').style.visibility='visible';
          //alert(transport.responseText);
		  $('barcode_frm').reset();
        }

        $('submit').value = 'Υποβολή';
        $('submit').disabled = false;
      }
    });

    return false;
  }

</script>
<?php //script to show numpad ?>
	<script>
		function Myfocus(barcode_pad) {
		var mypad = barcode_pad.id;
		//alert(mypad);
			document.getElementById(mypad).style.visibility = 'visible';
	}
</script>
<script>	
		function insertThisInThere(thisChar, thereId) {
		function theCursorPosition(ofThisInput) {
		// set a fallback cursor location
		var theCursorLocation = 0;
		 
		// find the cursor location via IE method...
		if (document.selection) {
		ofThisInput.focus();
		var theSelectionRange = document.selection.createRange();
		theSelectionRange.moveStart('character', -ofThisInput.value.length);
		theCursorLocation = theSelectionRange.text.length;
		} else if (ofThisInput.selectionStart || ofThisInput.selectionStart == '0') {
		// or the FF way
		theCursorLocation = ofThisInput.selectionStart;
		}
		return theCursorLocation;
		}
		 
		// now get ready to place our new character(s)...
		var theIdElement = document.getElementById(thereId);
		var currentPos = theCursorPosition(theIdElement);
		var origValue = theIdElement.value;
		var newValue = origValue.substr(0, currentPos) + thisChar + origValue.substr(currentPos);
		 
		theIdElement.value = newValue;
		 
		}
</script>
</head>
<body onload="document.barcode_frm.barcode.focus()">
<script>top.document.title=self.document.title;</script>
		<div onclick="document.barcode_frm.barcode.focus();">
		<fieldset style="min-height:300px">
		<legend><?php echo  $mode ?></legend>
		<br />
		<label class="bar_label_redeem_ready"><span class="blink"><?php echo $lbl_idle_redeem ?></span></label>
			<div class="critical" id="errorloc" style="visibility:hidden">
			<ul>
				<li><?php echo _NO_CUSTOMER_FOUND ?></li>
			</ul>	
			</div>
		<br />
		<br />
		
		<br />
		<?php
				if ($cls_flag==1){
				?>
				<div class="align-center">
				<label class="bar_label">Barcode</label>
				<form name="barcode_frm" id="barcode_frm" action="barcode_search_redeem.php" method="post" onsubmit="return processForm()">
				<input type="text" id="barcode"  name="barcode" class="input_scan_big" tabindex="1" onfocus='Myfocus(barcode_pad);' oninput="checkLength(this)" value="" autocomplete="off" maxlength="<?php echo $barcode_len ?>"/><br />
				<?php 
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~check if POS is activated~~~~~~~~~~~~~~~~~~~~~~~~~~
				if (isset($_SESSION['POS']) && $_SESSION['POS'] == 'ON'){
				include ('modules/pos/barcode_keypad.php');
				}
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				?>	
				<br /><br />
				<input type="submit"  style="visibility:hidden" name="submit"  id="submit"  value="Υποβολή" class="button" onclick="return processForm()"/>
				</form>
				</div>
				<?php }else{
				echo "CLS Module not installed! Please contact your provider";
				}
				?>				
		</fieldset>		
		</div>
		
</body>
</html>
<?php 
} else {
    header('Location: login.php');
}
?>

