  <script type="text/javascript" src="calendar1.js"></script>
   <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/base/jquery-ui.css" type="text/css" media="all" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js" type="text/javascript"></script>
  <script>
$(function() {
var date = $('#datepicker').datepicker({ dateFormat: 'dd/mm/yy', minDate:0 });
    //$( "#datepicker" ).datepicker({ minDate: 0 });
	
});
</script>
  
  <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="mro_pkey" id="mro_pkey" type="hidden" value="<?=$mro_data['mro_pkey'];?>">
  <input name="mro_projectpkey" id="mro_projectpkey" type="hidden" value="<?=$mro_data['mro_projectpkey'];?>">
  <input name="mro_requestdate" id="mro_requestdate" type="hidden" value="<?=unconverttounixslash($mro_data['mro_requestdate']);?>">
  <input name="mro_type" id="mro_type" type="hidden" value="<?=$mro_data['mro_type'];?>">
  <input name="mro_subcons" id="mro_subcons" type="hidden" value="<?=$mro_data['mro_subcons'];?>">
  <tr valign=top>
  <td valign=top width=150 class=formlabel>MRO Type</td>
  <td valign=top width=610 class=formvalue><b>
  <?
  if ($mro_data['mro_type']=="1") { 
    echo "Budgeted Material";
  } else if ($mro_data['mro_type']=="2") { 
    echo "Budgeted Material Exceeded";
  } else if ($mro_data['mro_type']=="3") { 
    echo "Non Budgeted Material - VO";
  } else if ($mro_data['mro_type']=="4") { 
    echo "Non Budgeted Material - Subcon";
  } else {
    echo "Unknown";
  }
  ?><b>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>MRO No</td>
  <td valign=top width=610 class=formvalue>
  <input name="mro_id" id="mro_id" type="text" value="<? if (($mro_data['mro_id']=="")||($mro_data['mro_id']=="0")) { echo "[Auto]"; } else { echo mroidstr($mro_data['mro_id']);}//,$mro_data['mro_revno']); } ?>" readonly maxlength=8 style="width: 180px;" onKeypress="integerOnly();">
  </td>
  </tr>
  <? if ($link_data['mro_id']!="") { ?>
    <tr valign=top>
    <td valign=top width=150 class=formlabel>Linked MRO</td>
    <td valign=top width=610 class=formvalue>
    <input name="mro_id" id="mro_id" type="text" value="<? if (($link_data['mro_id']=="")||($link_data['mro_id']=="0")) { echo "[Auto]"; } else { echo mroidstr($link_data['mro_id'],$link_data['mro_revno']); } ?>" readonly maxlength=8 style="width: 180px;" onKeypress="integerOnly();">
    </td>
    </tr>
  <? } ?>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Sub-con PO/Ref</td>
  <td valign=top width=610 class=formvalue>
  <input name="mro_subconref" id="mro_subconref" type="text" value="<?=$mro_data['mro_subconref'];?>" maxlength=80 style="width: 360px;">
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Client MRO No</td>
  <td valign=top width=610 class=formvalue>
  <input name="mro_clientref" id="mro_clientref" type="text" value="<?=$mro_data['mro_clientref'];?>" maxlength=80 style="width: 360px;">
  </td>
  </tr>
  <!--
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Date of Request</td>
  <td valign=top width=610 class=formvalue>
  <input name="mro_requestdate" id="mro_requestdate" type="text" value="<?=unconverttounixslash($mro_data['mro_requestdate']);?>" readonly maxlength=10 style="width: 90px;">
  </td>
  </tr>
  -->
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Date of Delivery</td>
  <td valign=top width=610 class=formvalue>
  <!--
  <input name="mro_deliverydate" id="mro_deliverydate" type="text" value="<?=unconverttounixslash($mro_data['mro_deliverydate']);?>" maxlength=10 style="width: 90px;" onKeypress="dateOnly();">
  <a href="javascript:cal1.popup();"><img src="images/icon/cal.gif" width="16" height="16" border="0" alt="Click to select date"></a>&nbsp;&nbsp;<i>(dd/mm/yyyy)</i>
 
  -->
   <input name="mro_deliverydate" id="datepicker" type="text" value="<?=unconverttounixslash($mro_data['mro_deliverydate']);?>" maxlength=10 style="width: 90px;">
  <i>(dd/mm/yyyy)</i>
   </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Backcharge/Debit Acc.</td>
  <td valign=top width=610 class=formvalue>
  <!--<select name="mro_debitaccount" id="mro_debitaccount" style="width: 360px;">--><!-- onChange="selectSubcons();" -->
  <? //$objdapkey=$mro_data['mro_debitaccount']; ?>
  <? //include_once('views/object-selectbackcharge.tpl'); ?>
  <!--</select>-->
  <input name="mro_debitaccount" id="mro_debitaccount" type="hidden" value="<?=$mro_data['mro_debitaccount'];?>" style="width: 360px;">
  <input name="mro_subconname" id="mro_subconname" type="text" value="<? if (strlen($mro_data['mro_subcons'])>32) { echo "Please Refer Sub Con Remarks"; } else { echo $subcon_data['subconname']; } ?>" readonly style="width: 360px;">
  &nbsp;<button name="selectsubcon" id="selectsubcon" type="button" onClick="selectSubcons2('<?=$mro_data['mro_subcons'];?>');">Sub-cons..</button>
  <? if ($mro_data['mro_pkey']=="") { ?>
    <br><font color="#ff0000"><i>To create MRO - Subcon, please select one or more Sub-contractors now)</i></font>
  <? } ?>
  <!--<input name="mro_debitaccount" id="mro_debitaccount" type="text" value="<?=$mro_data['mro_debitaccount'];?>" maxlength=80 style="width: 360px;">-->
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Sub Con / Remarks</td>
  <td valign=top width=610 class=formvalue>
  <textarea name="mro_remarks" id="mro_remarks" rows=5 style="width: 360px;"><?php if($mro_data['mro_remarks'] == "" ){ echo "-N/A-";} else { echo $mro_data['mro_remarks'];}?></textarea>
  </td>
  </tr>
  <tr valign=top>
  <td valign=top width=150 class=formlabel>Trade</td>
  <td valign=top width=610 class=formvalue>
  <input name="mro_subtradepkey" id="mro_subtradepkey" type="hidden" value="<?=$mro_data['mro_subtradepkey'];?>">
  <?=$trade_data['tradecode'];?> - <?=$trade_data['tradedescription'];?>
  </td>
  </tr>
  <input name="job" id="job" type="hidden" value="">
  </form>
  </table>

  <? if ($pubtask=="edit") { ?>

  <br>

  <? if ($mro_data['mro_type']=="2") { ?>
    <span style="color: red;"><i>Note: This is an MRO Exceeded. Please do not add items within the Budget to this MRO</i></span>
  <? } ?>

  <table border=1 cellspacing=1 cellpadding=2 width=920 style="border: 1px inset;">
  <tr valign=top>
  <td valign=top width=40 class=listheader>Item</td>
  <td valign=top width=360 class=listheader>Description</td>
  <td valign=top width=80 class=listheader>Unit</td>
  <td valign=top width=80 class=listheader>Qty</td>
  <td valign=top width=280 class=listheader>Purpose</td>
  <td valign=top width=80 class=listheader>Options</td>
  </tr>

  <? foreach($item_list as $myitem) { ?>

    <? if ($myitem['item_quantity']>0) { ?>

      <tr valign=top>
      <td valign=top width=40 class=listnumber><?=$myitem['item_no'];?>&nbsp;</td>
      <td valign=top width=360 class=listcontent><?=unescape($myitem['item_description']);?>&nbsp;</td>
      <td valign=top width=80 class=listcontent><?=$myitem['item_unit'];?>&nbsp;</td>
      <td valign=top width=80 class=listcontentnumeric><?=number_format($myitem['item_quantity'],4);?></td>
      <td valign=top width=280 class=listcontent><?=stripslashes($myitem['item_purpose']);?>&nbsp;</td>
      <td valign=top width=80 class=listcontent>
      <? if ($myitem['item_status']==4) { ?>
        <i>Cancelled</i>
      <? } else { ?>
        <a href="index.php?module=mro&task=viewitem&mroid=<?=$mro_data['mro_pkey'];?>&itemid=<?=$myitem['item_pkey'];?>"><img src="gfx/options/b_view.png" border=0 alt="View"></a>
        <? if (($pubuseraccess['access_mro_edit']==1)||($pubuserrole>=2)) { ?>
          <!--<a href="index.php?module=mro&task=edititem&mroid=<?=$mro_data['mro_pkey'];?>&itemid=<?=$myitem['item_pkey'];?>"><img src="gfx/options/b_edit.png" border=0 alt="Edit"></a>-->
          <a href="index.php?module=mro&task=deleteitem&mroid<?=$mro_data['mro_pkey'];?>&itemid=<?=$myitem['item_pkey'];?>"><img src="gfx/options/b_drop.png" border=0 alt="Delete"></a>
        <? } ?>
      <? } ?>
      </td>
      </tr>

   <? } ?>

  <? } ?>

  </table>

  <button name="additem" id="additem" type="button" onClick="mro_button_additem('<?=$mro_data['mro_pkey'];?>');">&nbsp;<img src="gfx/options/b_add.png" class="actionbutton">&nbsp;&nbsp;Add Item&nbsp;</button>

  <? } ?>

  <script language="javascript">
    var cal1 = new calendar1(document.forms['mroform'].elements['mro_deliverydate']);
    cal1.year_scroll = true;
    cal1.time_comp = false;
  </script>

  <script type="text/javascript">

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

  function validateForm() {

    var isvalid=true;
    var errmsg="";
    //var mrosubtrade1=document.getElementById('mro_subtradepkey1');
    var mro_deliverydate=document.getElementById('mro_deliverydate');

    if (mro_deliverydate.value=="") {
      errmsg='Date Must be include!\n';
      isvalid=false;
    }
    if (isvalid==false) alert('Error:\n'+errmsg);
    return isvalid;

  }

  function selectSubcons() {

    var mroda=document.getElementById('mro_debitaccount');
    if (mroda.value=="remarks") {
      window.open('views/ibox_selectsubcons.php','selectwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=960,height=600');
    }

  }

  function selectSubcons2(subcons) {

    window.open('views/ibox_selectsubcons.php?subcons='+subcons,'selectwindow', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=600,height=600');
    // 960

  }

  </script>
