<!--
 * this file is to be used in combination with store_item_select_header.php
 *
-->


<div class="wizard_frame"><br>
    <table id="dataTable" width="635" border="1" style="border-collapse:collapse;">
    <?php
	   if ($line_num==0) {
	       
		   $a1='-';
		   $a1a='-';
		   $a2='-';
		   $a3='-';
	   }
	   else {
		   
		   $a1 = mysql_result($line_result, 0, "store_item_id");
		   		$table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$a1."'  ";
				$name_result = mySQL_query($name_query);
				$a1a = mysql_result($name_result, 0, "item_name");
				
		   $a2 = mysql_result($line_result, 0, "quantity");
		   $a3 = mysql_result($line_result, 0, "purchase_price");
		   }
		?>
    <thead> 
        <tr>
          <td>&nbsp;</td>
          <td width="453">Store item</td>
          <td>Quantity</td>
          <td>Unit price</td>
        </tr>
        </thead>
        <script>
			 function check_it() {
				 if (document.getElementById('line_checkbox0').checked) {
					     <?php if ($page=='purchase') { ?>
                         document.getElementById('line_checkbox0').hidden = true;
                         <?php } ?>
                         document.getElementById('store_item_id_select0').style.background = '#F0F0F0';
						 document.getElementById('store_item_text0').style.background = '#F0F0F0';
						 document.getElementById('quantity_text0').style.background = '#F0F0F0';
						 document.getElementById('amount_text0').style.background = '#F0F0F0';
						 document.getElementById('store_item_id_select0').selectedIndex=-1;
						 document.getElementById('category0').selectedIndex=-1;
						 document.getElementById('store_item_text0').value = '.';
						 document.getElementById('quantity_text0').value = '.';
						 document.getElementById('amount_text0').value = '.';
						 document.getElementById('store_item_id_select0').disabled = true;
						 document.getElementById('store_item_text0').disabled = true;
						 document.getElementById('quantity_text0').disabled = true;
						 document.getElementById('amount_text0').disabled = true;
						 document.getElementById('add_icon0').hidden = false;
						 document.getElementById('store_item_divA0').hidden = true;
						 document.getElementById('store_item_divB0').hidden = true;		 
                } else {
                         document.getElementById('store_item_id_select0').style.background = '#FFF';
						 document.getElementById('quantity_text0').style.background = '#FFF';
						 document.getElementById('amount_text0').style.background = '#FFF';
						 document.getElementById('store_item_id_select0').selectedIndex=-1;
						 document.getElementById('category0').selectedIndex=-1;
						 document.getElementById('store_item_text0').value = '';
						 document.getElementById('quantity_text0').value = '';
						 document.getElementById('amount_text0').value = '';
						 document.getElementById('store_item_id_select0').disabled = false;
						 document.getElementById('quantity_text0').disabled = false;
						 document.getElementById('amount_text0').disabled = false;
						 document.getElementById('add_icon0').hidden = false;
						 document.getElementById('store_item_divA0').hidden = false;
						 document.getElementById('store_item_divB0').hidden = true;
                }
				}
		     </script>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox0" id="line_checkbox0" onMouseUp="check_it()" <?php if ($a1!='-') { ?> checked="checked" <?php ;}  if ($page=='edit_receive') { ?> hidden=hidden <?php } ?> /></td>
          <td>
          
          
          <div id=store_item_divA0>
          <?php if ($page!='purchase') { ?>
              <img src=<?php if ($a1a!='') { echo "../images/line_edit.png width=16 height=12 "; } else { echo "../images/line_edit_text.png width=135 height=12 "; } ?>   id="add_icon0" onClick="document.getElementById('store_item_divA0').hidden=true; document.getElementById('store_item_divB0').hidden=false; document.getElementById('quantity_text0').value=''; document.getElementById('amount_text0').value=''; document.getElementById('store_item_text0').value =''; ">&nbsp;<?php } ?>
<input name="store_item_text0" id="store_item_text0" type="text" class="text300" value="<?php echo $a1a ?>" readonly style="border:hidden; background-color:inherit; "> <input name="store_item_id0" id="store_item_id0" type="hidden" value="<?php echo $a1 ?>">
          </div>
            
            <div id=store_item_divB0 hidden="hidden">
              <select name="category0" id="category0" style="width:160px;"  onChange="document.getElementById('store_item_divA0').hidden=true; document.getElementById('store_item_divB0').hidden=false; document.getElementById('store_item_id_select0').selectedIndex=-1; document.getElementById('index0').value = document.getElementById('category0').selectedIndex; ">
              </select>
              <input type="hidden" name="index0" id="index0">
              <select name="store_item_id_select0" id="store_item_id_select0" style="width:160px;" onChange="
              document.getElementById('line_checkbox0').checked=true;
              unit = document.getElementById('store_item_id_select0').options[document.getElementById('store_item_id_select0').selectedIndex].text; 
              unit2 = unit.split('~'); 
              unit3 = unit2[1];
              if (unit3=='no') {
              document.getElementById('quantity_text0').value = '';
              document.getElementById('quantity_text0').onkeypress = function num(event) { return numbersonly(this, event);}
              }
              else {
              document.getElementById('quantity_text0').value = '';
              document.getElementById('quantity_text0').onkeypress = function decnum(event) { return isNumberKey(event);}  
              }            
              document.getElementById('store_item_id0').value=document.getElementById('store_item_id_select0').value; 
              document.getElementById('store_item_text0').value = document.getElementById('store_item_id_select0').value; 
              document.getElementById('quantity_text0').disabled = false;
              document.getElementById('amount_text0').disabled = false;
              
              ">
              </select>
            </div> 
            
            </td>
          <td width="69" align="right"><input  name="quantity_text0" type="text" class="text60" id="quantity_text0" style="text-align:right" onKeyPress="return numbersonly(this, event)" value="<?php echo $a2 ?>" <?php if ($a2=='-') { ?> disabled="true" <?php } ?> size="10" autocomplete="off" onfocus = "this.select();"/>  
            </td>
            <td width="65" align="right"><input  name="amount_text0" type="text" class="text60" id="amount_text0" style="text-align:right" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" onKeyPress="return isNumberKey(event)" value="<?php if ($a3!=0) {echo number_format($a3, 2, '.', ','); } else {echo '-'; }?>" <?php if ($a3=='-') { ?> disabled <?php } ?> size="10" autocomplete="off" onfocus = "this.select();"/><input type="hidden" name="line_num" id="line_num" value="1" onfocus = "this.select();">
        
            

        </td>    
            <!--<input name="textfield0" type="text" id="textfield0" size="5" value="1"></td>-->
        </tr>
        <?php
		$i=1;
		while ($i<$line_num) {
		   $a1 = mysql_result($line_result, $i, "store_item_id");
		        $table_name = $_SESSION['db_prefix']."_store_items";
				$name_query = "SELECT item_name, unit FROM $table_name WHERE store_item_id = '".$a1."'  ";
				$name_result = mySQL_query($name_query);
				$a1a = mysql_result($name_result, 0, "item_name");
		   $a2 = mysql_result($line_result, $i, "quantity");
		   $a3 = mysql_result($line_result, $i, "purchase_price");
		?>
        <tr>
            <td width="20"><input type="checkbox" name="line_checkbox<?php echo $i ?>" id="line_checkbox<?php echo $i ?>"  <?php if ($a1!='') { ?> checked="checked" <?php ;}  if ($page=='edit_receive') { ?> hidden=hidden <?php } ?> onMouseUp="{
				 if (document.getElementById('line_checkbox<?php echo $i ?>').checked) {
                 		 <?php if ($page=='purchase') { ?>
                         document.getElementById('line_checkbox<?php echo $i ?>').hidden = true;
                         <?php } ?>
                         document.getElementById('store_item_id_select<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('store_item_text<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('quantity_text<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('amount_text<?php echo $i ?>').style.background = '#F0F0F0';
						 document.getElementById('store_item_id_select<?php echo $i ?>').selectedIndex=-1;
						 document.getElementById('category<?php echo $i ?>').selectedIndex=-1;
						 document.getElementById('store_item_text<?php echo $i ?>').value = '.';
						 document.getElementById('quantity_text<?php echo $i ?>').value = '.';
						 document.getElementById('amount_text<?php echo $i ?>').value = '.';
						 document.getElementById('store_item_id_select<?php echo $i ?>').disabled = true;
						 document.getElementById('store_item_text<?php echo $i ?>').disabled = true;
						 document.getElementById('quantity_text<?php echo $i ?>').disabled = true;
						 document.getElementById('amount_text<?php echo $i ?>').disabled = true;
						 document.getElementById('add_icon<?php echo $i ?>').hidden = false;
						 document.getElementById('store_item_divA<?php echo $i ?>').hidden = true;
						 document.getElementById('store_item_divB<?php echo $i ?>').hidden = true;		 
                } else {
                          
                         document.getElementById('store_item_id_select<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('quantity_text<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('amount_text<?php echo $i ?>').style.background = '#FFF';
						 document.getElementById('store_item_id_select<?php echo $i ?>').selectedIndex=-1;
						 document.getElementById('category<?php echo $i ?>').selectedIndex=-1;
						 document.getElementById('store_item_text<?php echo $i ?>').value = '';
						 document.getElementById('quantity_text<?php echo $i ?>').value = '';
						 document.getElementById('amount_text<?php echo $i ?>').value = '';
						 document.getElementById('store_item_id_select<?php echo $i ?>').disabled = false;
						 document.getElementById('quantity_text<?php echo $i ?>').disabled = false;
						 document.getElementById('amount_text<?php echo $i ?>').disabled = false;
						 document.getElementById('add_icon<?php echo $i ?>').hidden = false;
						 document.getElementById('store_item_divA<?php echo $i ?>').hidden = false;
						 document.getElementById('store_item_divB<?php echo $i ?>').hidden = true;
                }
				}
                "/></td>
          <td>
          
          
          <div id=store_item_divA<?php echo $i ?>>
          <?php if ($page!='purchase') { ?>
              <img src="../images/line_edit.png" width="16" height="12" id="add_icon<?php echo $i ?>" onClick="document.getElementById('store_item_divA<?php echo $i ?>').hidden=true; document.getElementById('store_item_divB<?php echo $i ?>').hidden=false; document.getElementById('quantity_text<?php echo $i ?>').value=''; document.getElementById('amount_text<?php echo $i ?>').value=''; document.getElementById('store_item_text<?php echo $i ?>').value =''; ">&nbsp;<?php } ?>
<input name="store_item_text<?php echo $i ?>" id="store_item_text<?php echo $i ?>" type="text" class="text300" value="<?php echo $a1a ?>" readonly style="border:hidden; background-color:inherit"> <input name="store_item_id<?php echo $i ?>" id="store_item_id<?php echo $i ?>" type="hidden" value="<?php echo $a1 ?>">
          </div>
            
            <div id=store_item_divB<?php echo $i ?> hidden="hidden">
              <select name="category<?php echo $i ?>" id="category<?php echo $i ?>" style="width:160px;"  onChange="document.getElementById('store_item_divA<?php echo $i ?>').hidden=true; document.getElementById('store_item_divB<?php echo $i ?>').hidden=false; document.getElementById('store_item_id_select<?php echo $i ?>').selectedIndex=-1; document.getElementById('index<?php echo $i ?>').value = document.getElementById('category<?php echo $i ?>').selectedIndex; ">
              </select>
              <input type="hidden" name="index<?php echo $i ?>" id="index<?php echo $i ?>">
              <select name="store_item_id_select<?php echo $i ?>" id="store_item_id_select<?php echo $i ?>" style="width:160px;" onChange="
              document.getElementById('line_checkbox<?php echo $i ?>').checked=true;
              unit = document.getElementById('store_item_id_select<?php echo $i ?>').options[document.getElementById('store_item_id_select<?php echo $i ?>').selectedIndex].text; 
              unit2 = unit.split('~'); 
              unit3 = unit2[1];
              if (unit3=='no') {
              document.getElementById('quantity_text<?php echo $i ?>').value = '';
              document.getElementById('quantity_text<?php echo $i ?>').onkeypress = function num(event) { return numbersonly(this, event);}
              }
              else {
              document.getElementById('quantity_text<?php echo $i ?>').value = '';
              document.getElementById('quantity_text<?php echo $i ?>').onkeypress = function decnum(event) { return isNumberKey(event);}  
              }            
              document.getElementById('store_item_id<?php echo $i ?>').value=document.getElementById('store_item_id_select<?php echo $i ?>').value; 
              document.getElementById('store_item_text<?php echo $i ?>').value = document.getElementById('store_item_id_select<?php echo $i ?>').value; 
              "
              >
               
              </select>
            </div> 
            
            </td>
          <td width="69" align="right"><input  name="quantity_text<?php echo $i ?>" type="text" class="text60" id="quantity_text<?php echo $i ?>" style="text-align:right" onKeyPress="return numbersonly(this, event)" value="<?php echo $a2 ?>" size="10" autocomplete="off" onfocus = "this.select();"/></td>
            <td width="65" align="right"><input  name="amount_text<?php echo $i ?>" type="text" class="text60" id="amount_text<?php echo $i ?>" style="text-align:right" onKeyUp=" this.value = this.value.replace (/(\...).*/, '$1')" onKeyPress="return isNumberKey(event)" value="<?php echo number_format($a3, 2, '.', ',') ?>" size="10" autocomplete="off"  onfocus = "this.select();"/>              <input type="hidden" name="line_num" id="line_num" value="<?php echo $line_num?>"><input type="hidden" name="line_num2" id="line_num2" value="<?php echo $line_num?>"></td>
        </tr>
        <?php
		$i++;
		}
		?>
        
  </table>
  
    <input type="button" class="imagebutton" onClick="addRow('dataTable')" value="Add line" />
    <div align="right"><label class="label_small">To delete a line: uncheck line box</label></div>
  
					
				
  </div>