  <br>
  
  <table border=1 cellspacing=1 cellpadding=2 width=760 style="border: 1px inset;">
  <form action="controllers/inputController.php" method="post" name="mblform" id="mblform">
  <input name="item_projectpkey" id="item_projectpkey" type="hidden" value="<?=$pubprojectpkey;?>">
  <input name="item_pkey" id="item_pkey" type="hidden" value="<?=$item_data['item_pkey'];?>">
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Code *</td>
  <td valign=top width=610 class=formvalue>
  <input name="item_subtradepkey" id="item_subtradepkey" type="hidden" value="<?=$item_data['item_subtradepkey'];?>">
  <input name="item_subsubtradepkey" id="item_subsubtradepkey" type="hidden" value="<?=$item_data['item_subsubtradepkey'];?>">
  <input name="item_level" id="item_level" type="hidden" value="<?=$item_data['item_level'];?>">
  
  
  <input name="item_code" id="item_code" type="text" value="<?=stripslashes($item_data['item_code']);?>" readonly style="width: 180px;">&nbsp;
  
  &nbsp;<button name="selecttrade" id="selecttrade" type="button" onClick="selectTrade('<?=$item_data['item_subtradepkey'];?>');">Select Trade..</button>
  &nbsp;<button name="selectsubtrade" id="selectsubtrade" type="button" onClick="selectSubtrade('<?=$item_data['item_subsubtradepkey'];?>');">Select Sub-Trade..</button>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Description *</td>
  <td valign=top width=610 class=formvalue>
  <input name="item_description" id="item_description" type="text" value="<?=stripslashes($item_data['item_description']);?>" style="width: 360px;">
  
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Unit</td>
  <td valign=top width=610 class=formvalue>
  <input name="item_unit" id="item_unit" type="text" value="<?=$item_data['item_unit'];?>">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Quantity *</td>
  <td valign=top width=610 class=formvalue>
 <!--
 <input name="item_quantity" id="item_quantity" type="text" value="<?=number_format($item_data['item_quantity'],4);?>" maxlength=21 style="width: 180px;" onChange="calcAmount();" onKeypress="decimalOnly();">
  -->
 <input name="item_quantity" id="item_quantity" type="text" value="<?=$item_data['item_quantity'];?>" maxlength=21 style="width: 180px;" onChange="calcAmount();" onKeypress="decimalOnly();">

  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Rate *</td>
  <td valign=top width=610 class=formvalue>
  <!--
  <input name="item_rate" id="item_rate" type="text" value="<?=number_format($item_data['item_rate'],2);?>" maxlength=21 style="width: 180px;" onChange="calcAmount();" onKeypress="decimalOnly();">
  -->
  <input name="item_rate" id="item_rate" type="text" value="<?=$item_data['item_rate'];?>" maxlength=21 style="width: 180px;" onChange="calcAmount();" onKeypress="decimalOnly();">
  
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Amount</td>
  <td valign=top width=610 class=formvalue>
  <input name="item_amount" id="item_amount" type="text" value="<?=number_format($item_data['item_amount'],2);?>" readonly maxlength=21 style="width: 180px;">
  </td>
  </tr>
  <input name="job" id="job" type="hidden" value="">
  </form>
  </table>

  <script type="text/javascript">

  function selectTrade(subtrade) {
    window.open('views/ibox_selecttrade.php?level=3','selectwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=600,height=600');
    //960
    //location.href='index.php?module=crawler&task=spisearch';
  }

  function selectSubtrade(subtrade) {
    window.open('views/ibox_selecttrade.php?level=4','selectwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=600,height=600');
    //960
    //location.href='index.php?module=crawler&task=spisearch';
  }

  function validateForm() {

    var isvalid=true;
    var errmsg="";
    var itemqty=document.getElementById('item_quantity');
    var itemrate=document.getElementById('item_rate');
    var itemsub=document.getElementById('item_subtradepkey');
    var itemsubsub=document.getElementById('item_subsubtradepkey');

    if ((itemqty.value=="")||(itemrate.value=="")||((itemsubsub.value=="")&&(itemsub.value==""))) {
      errmsg='Item Trade/Subtrade, Quantity and Rate must be specified!\n';
      isvalid=false;
    }
    if (isvalid==false) alert('Error:\n'+errmsg);
    return isvalid;

  }

  function TS(v) {
    var val = v.toString();
    var result = "";
    var len = val.length;
    var dec = val.substr(len-3);
    val = val.substr(0,len-3);
    len -=3;
    while (len > 3){
      result = ","+val.substr(len-3,3)+result;
      len -=3;
    }
    return val.substr(0,len)+result+dec;
  }

  function calcAmount(){
    var amt=0;
    var y=document.mblform;
    if ((y.item_quantity.value!="")&&(y.item_rate.value!="")) {
      var qty=parseFloat(y.item_quantity.value);
      var rate=parseFloat(y.item_rate.value);
      var amt=qty*rate;
      document.mblform.item_amount.value=amt.toFixed(4);
    }
  }

  </script>
