<?php
   if($_SESSION['p']==2) {
		    $_SESSION['productName'] = $_GET['productName_text'];
			$_SESSION['color'] = $_GET['color_text'];
	}
	
	$query = "SELECT productName FROM products WHERE  productName = '". $_SESSION['productName']." ".$_SESSION['color']."' " ;
	
	$result = mySQL_query($query) or die ("Error in query:   $query . * ". mySQL_error());
	$num = mysql_num_rows($result);
	
	if ($num!=0) { 
	$_SESSION['error']=1;
	$_SESSION['p']=2;
	
	?>
    <script language="javascript" type="text/javascript">
        <!--
		needToConfirm = false;
	 window.location="storeWizbase.php?s=0&p=2 ";
        -->
     </script>

<?php	
       }
    else{


   include ('../include/formValidations.php')
?>


<?php
//$_SESSION['error']=0;
?>
<script type="text/javascript" src="../css/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="../css/wizard.css" />
<script language="JavaScript" src="gen_validatorv4.js"  type="text/javascript" xml:space="preserve"></script>
<!--form validation-->
<script language="javascript" type="text/javascript" >
<!--
function confirmRefresh() {
var okToRefresh = confirm("Do you really want to cancel this entry?");
var url='showAllProducts.php?cat=Tiles and Accessories&productSelect=All&colorSelect=All'
if (okToRefresh)
	{
			window.location=url;
	}
}
// -->
</script>
<script language="JavaScript">
  var needToConfirm = true;
  window.onbeforeunload = confirmExit;
   function confirmExit()
  {
    if (needToConfirm)
      return "You did not finish the wizard./nIf you leave now your data will not be saved.";
  }
function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}
</script>

<script language="Javascript">
       <!--
       function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : event.keyCode
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;
 
          return true;
       }
       //-->
    </script>
    
    
<form id="feedbackform" method="get" action="storeWizbase.php"> 
  <table width=595 border="0" align="center" cellpadding="10" cellspacing="0" bordercolor="#0066FF" border-collapse="collapse">
    <tr>
      <td width="525" ><p class="wizard">
          <label class="left">Minimum stock:</label>
          <input class="wizard2" id="minimumStockText" name="minimumStockText" value="<?php echo $_SESSION['minimumStock'] ?>" type="text" onkeypress="return numbersonly(this, event)"/>
          <label class="star">*</label>
          <label class="right">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Price:&nbsp;&nbsp;&nbsp;</label>
          <input class="wizard2" name="priceText" id="priceText" type="text" value="<?php echo $_SESSION['price'] ?>" style="text-align:right" onkeypress="return isNumberKey(event)"/>


<label class="star">*</label>
        <label class="std">per unit</label>
</p>
<?php if ($_SESSION['category'] == "Direct Materials") { ?>
        <p class="wizard"><label class="left4">  Select a sub category: </label>&nbsp;&nbsp;
          <select name="subCat_select" class="wizard1" id="subCat_select">
            <option value="Depalet">Depalet</option>
            <option value="Pigment">Pigment</option>
            <option value="Skip">Skip</option>
            <option value="Wrapping and Strapping">Wrapping and Strapping</option>
            <option value="<?php echo $value ?>" selected="selected"><?php echo $value ?></option>
          </select>
        <label class="star">*</label></p>
        <?php } ?>
        <?php if ($_SESSION['category'] != "Tiles and Accessories"){ ?>
        <p class="wizard">
          <label class="left">Unit:</label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <label>
            <input type="radio" name="unit_group" value="no" id="unit_group_0" <?php if ($_SESSION['unit']=="no") { echo "checked='checked' " ;} ?> />
            no</label>
          
          <label>
            <input type="radio" name="unit_group" value="kg" id="unit_group_1" <?php if ($_SESSION['unit']=="kg") { echo "checked='checked' " ;} ?> />
            kg</label>
          
          <label>
            <input type="radio" name="unit_group" value="ltr" id="unit_group_2" <?php if ($_SESSION['unit']=="ltr") { echo "checked='checked' " ;} ?> />
            ltr</label>
          
          <label>
            <input type="radio" name="unit_group" value="m" id="unit_group_3" <?php if ($_SESSION['unit']=="m") { echo "checked='checked' " ;} ?> />
            m</label>
          
          <label>
            <input type="radio" name="unit_group" value="m2" id="unit_group_4" <?php if ($_SESSION['unit']=="m2") { echo "checked='checked' " ;} ?> />
            m2</label>
          
          <label>
            <input type="radio" name="unit_group" value="pair" id="unit_group_5" <?php if ($_SESSION['unit']=="pair") { echo "checked='checked' " ;} ?> />
            pair</label>
          
        &nbsp;&nbsp;&nbsp;<label class="star">*</label></p>
        
        <p class="wizard">
          <label class="left">Location:</label>
          <input class="wizard2" id="shelfText" name="shelfText" type="text" value="<?php echo $_SESSION['shelf'] ?>" onkeyup="ToLower(this)"/>
        </p>
        <p class="wizard">
          <label class="std">Returnable:&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
        
          <label>
<input type="radio" name="return_group" value="yes" id="return_group_0" <?php if ($_SESSION['returnable']=="yes") { echo "checked='checked' " ;} ?> />
yes</label>
         
          <label>
            <input type="radio" name="return_group" value="no" id="return_group_1" <?php if ($_SESSION['returnable']=="no") { echo "checked='checked' " ;} ?>/>
            no</label>
          
        
          <label class="star">*</label>
        </p>
      <?php } ?></td>
    </tr>
    <tr>
      <td><table width="590" height="50" align="center" id="tableButtonBar">
          <tr>
            <td width="117"><input type="submit" name="prev_button" id="prev_button" class="imagebutton" value="Prev" onclick=" needToConfirm = false; " /></td>
            <td width="115"><span class="wizard">
              <input name="s" type="hidden" id="s" value="3" />
              <input name="p" type="hidden" id="p" value="3" />
            </span></td>
            <td width="99">&nbsp;</td>
            <td width="125"><input name="cancelbutton" type="button" class="imagebutton" id="cancelbutton" onclick="needToConfirm = false; confirmRefresh();" value="Cancel" /></td>
            <td width="110" align="left"><input type="submit" name="next_button" class="imagebutton" value="Next" onclick="needToConfirm = false;  validate();  " /></td>
          </tr>
        </table></td>
    </tr>
  </table>
  </table>
</form>
<script language="JavaScript" type="text/javascript" xml:space="preserve">
  var frmvalidator  = new Validator("feedbackform");
  frmvalidator.EnableMsgsTogether();
  
  function validate() {


  frmvalidator.addValidation("minimumStockText","req","Please enter the minimum stock.");
  frmvalidator.addValidation("priceText","req","Please enter the price.");
  <?php if ($_SESSION['category'] == "Direct Materials"){ ?>
  frmvalidator.addValidation("subCat_select","req","Please select a sub category.");
  <?php } ?>  
  <?php if ($_SESSION['category'] != "Tiles and Accessories"){ ?>
  frmvalidator.addValidation("unit_group","selone","Please select an unit.");
  frmvalidator.addValidation("return_group","selone","Please select if it can be returned.");
  <?php } ?>
  }
</script>
<?php
}
?>