  <br>
  <table border=1 cellspacing=1 cellpadding=2 width=760 style="border: 1px inset;">
  <form action="controllers/inputController.php" method="post" name="mroform" id="mroform">
  <input name="projectpkey" id="projectpkey" type="hidden" value="<?=$pubprojectpkey;?>">
  <input name="item_mropkey" id="item_mropkey" type="hidden" value="<?=$mro_data['mro_pkey'];?>">
  <input name="item_pkey" id="item_pkey" type="hidden" value="<?=$item_data['item_pkey'];?>">
  <input name="item_code" id="item_code" type="hidden" value="<?=$item_data['item_code'];?>">
  <input name="item_budgetflag" id="item_budgetflag" type="hidden" value="">
  <input name="mrotype" id="mrotype" type="hidden" value="<?=$mro_data['mro_type'];?>">
  <input name="mro_exceedpkey" id="mro_exceedpkey" type="hidden" value="<?=$mro_data['mro_exceedpkey'];?>">
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Item No</td>
  <td valign=top width=610 class=formvalue>
  <input name="item_no" id="item_no" type="text" value="<?=$item_data['item_no'];?>" maxlength=8 style="width: 60px;" onKeypress="integerOnly();">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Description *</td>
  <td valign=top width=610 class=formvalue>
  <input name="item_maintradepkey" id="item_maintradepkey" type="hidden" value="<?=$item_data['item_maintradepkey'];?>">
  <input name="item_submaintradepkey" id="item_submaintradepkey" type="hidden" value="<?=$item_data['item_submaintradepkey'];?>">
  <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_trisubtradepkey" id="item_trisubtradepkey" type="hidden" value="<?=$item_data['item_trisubtradepkey'];?>">
  <input name="item_description" id="item_description" type="text" value="<?=unescape($item_data['item_description']);?>" style="width: 360px;">
  &nbsp;<button name="selecttrade" id="selecttrade" type="button" onClick="selectTrade('<?=$mro_data['mro_pkey'];?>','<?=$mro_data['mro_type'];?>','<?=$mro_data['mro_subtradepkey'];?>','<?=$item_data['item_no'];?>');">Select Trade..</button>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Additional Description</td>
  <td valign=top width=610 class=formvalue>
  <textarea name="item_remarks" id="item_remarks" rows=4 style="width: 360px;"><?=$item_data['item_remarks'];?></textarea>
  </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'];?>" maxlength=40 style="width: 180px;">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Total Budget</td>
  <td valign=top width=610 class=formvalue style="background: #ffe0ff;">
  <input name="item_totalquantity" id="item_totalquantity" type="text" value="0.0000" readonly style="width: 180px; background: #ffe0ff;">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Budget Balance</td>
  <td valign=top width=610 class=formvalue style="background: #ffe0ff;">
  <input name="item_totalbalance" id="item_totalbalance" type="text" value="0.0000" readonly style="width: 180px; background: #ffe0ff;">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>This Order *</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;" onKeypress="decimalOnly();" onChange="calcExceeded();">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Budget Exceeded</td>
  <td valign=top width=610 class=formvalue style="background: #ffe0ff;">
  <input name="item_totalexceed" id="item_totalexceed" type="text" value="0.0000" readonly style="width: 180px; background: #ffe0ff;">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>
  <div name="div1" id="div1" style="display: none;">
  MRO Type<!-- * -->
  </div>
  </td>
  <td valign=top width=610 class=formvalue>
  <div name="div2" id="div2" style="display: none;">
  <!--
  <input name="item_mrotype" id="item_mrotype3" type="radio" value="3" <? if ($mro_data['mro_type']=="3") echo "checked"; ?> onClick="setMrotype();">VO</input><br>
  <input name="item_mrotype" id="item_mrotype4" type="radio" value="4" <? if ($mro_data['mro_type']=="4") echo "checked"; ?> onClick="setMrotype();">Sub-con</input><br>
  -->
  <i><font color="#ff0000">Note: This MRO will be saved as <b>MRO - VO</b></font></i>
  </div>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Purpose</td>
  <td valign=top width=610 class=formvalue>
  <input name="item_purpose" id="item_purpose" type="text" value="<?=stripslashes($item_data['item_purpose']);?>" style="width: 360px;">
  </td>
  </tr>
  <input name="job" id="job" type="hidden" value="">
  </form>
  </table>

  <script type="text/javascript">

  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 calcExceeded(icount,suppcount) {

    var objtotalquantity = document.getElementById('item_totalquantity');
    var objtotalbalance = document.getElementById('item_totalbalance');
    var objtotalexceed = document.getElementById('item_totalexceed');
    var objquantity = document.getElementById('item_quantity');
    var objmrotype = document.getElementById('mrotype');
    var objdiv1 = document.getElementById('div1');
    var objdiv2 = document.getElementById('div2');
    //var itemradio1=document.getElementById('item_mrotype3');
    //var itemradio2=document.getElementById('item_mrotype4');

    var mytotalquantity = objtotalquantity.value
    var mytotalbalance = objtotalbalance.value
    var mytotalexceed = objtotalexceed.value
    var myquantity = objquantity.value

    mytotalquantity = mytotalquantity.replace(/,/g,"");
    mytotalbalance = mytotalbalance.replace(/,/g,"");
    mytotalexceed = mytotalexceed.replace(/,/g,"");
    myquantity = myquantity.replace(/,/g,"");

    mytotalquantity = parseFloat(mytotalquantity)
    mytotalbalance = parseFloat(mytotalbalance)
    mytotalexceed = parseFloat(mytotalexceed)
    myquantity = parseFloat(myquantity)

    if (mytotalquantity>0) {
      if (myquantity>mytotalbalance) {
        if (mytotalbalance==0) {
          if (objmrotype.value!="4") {
            objmrotype.value="2";
          }
        } else {
          if (objmrotype.value!="4") {
            objmrotype.value="1";
          }
        }
        var myorder = mytotalbalance;
        var myexceed = myquantity - mytotalbalance;
      } else {
        if (objmrotype.value!="4") {
          objmrotype.value="1";
        }
        var myorder = myquantity;
        var myexceed = 0.0000;
      }
      if (objmrotype.value=="4") {
        var myorder = myquantity;
        var myexceed = 0.0000;
      }
      myorder = myorder.toFixed(4);
      myexceed = myexceed.toFixed(4);
      objquantity.value=myorder; //TS(myorder);
      objtotalexceed.value=myexceed; //TS(myexceed);
      objdiv1.style.cssText="display: none;";
      objdiv2.style.cssText="display: none;";
      //itemradio1.checked = false;
      //itemradio2.checked = false;
    } else {
      if ((objmrotype.value!="3")&&(objmrotype.value!="4")) {
        objmrotype.value="3";
        objdiv1.style.cssText="display: block;";
        objdiv2.style.cssText="display: block;";
        //itemradio1.checked = true;
      }
    }
  }

  /*
  function setMrotype() {
    var objmrotype = document.getElementById('mrotype');
    var itemradio1=document.getElementById('item_mrotype3');
    var itemradio2=document.getElementById('item_mrotype4');
    if (itemradio1.checked==true) {
      objmrotype.value="3";
    } else if (itemradio2.checked==true) {
      objmrotype.value="4";
    }
  }
  */

  function selectTrade(mropkey,mrotype,subtrade,itemno) {
    window.open('views/ibox_selecttrade-mro.php?subid='+subtrade+'&type='+mrotype+'&itemid='+mropkey+'&itemno='+itemno,'selectwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=1,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 itemexc=document.getElementById('item_totalexceed');
    var itemsubsub=document.getElementById('item_subsubtradepkey');
    var itemflag=document.getElementById('item_budgetflag');
    //var itemradio1=document.getElementById('item_mrotype3');
    //var itemradio2=document.getElementById('item_mrotype4');
    var objmrotype = document.getElementById('mrotype');

    if (itemflag.value=="") {
      errmsg='Item Description must be specified!\n';
      isvalid=false;
    } else if (itemflag.value=="1") {
      if ((itemqty.value=="")||(itemsubsub.value=="")||((itemqty.value=="0.0000")&&(itemexc.value=="0.0000"))) {
        errmsg='Item Description and Quantity (This Order) must be specified!\n';
        isvalid=false;
      }
    } else if (itemflag.value=="0") {
      //if ((itemqty.value=="")||(itemsubsub.value=="")||((itemqty.value=="0.0000")&&(itemexc.value=="0.0000"))||((itemradio1.checked==false)&&(itemradio2.checked==false))) {
      if ((itemqty.value=="")||(itemsubsub.value=="")||((itemqty.value=="0.0000")&&(itemexc.value=="0.0000"))) {
        errmsg='Item Description, Quantity (This Order) and MRO Type must be specified!\n';
        isvalid=false;
      }
    }

    if (isvalid==false) {
      alert('Error:\n'+errmsg);
    } else {
      if ((itemqty.value=="0.0000")&&(itemexc.value!="0.0000")) {
        if (objmrotype.value!="2") {
          alert('The selected item will appear on the corresponding MRO - Exceeded');
        }
      }
    }
    return isvalid;

  }

  </script>
