<%--
  - Author(s)  : Hyung min Son
  - Date       : 2014.07.07
  - Description: 연기 사유 팝업
  --%>

<%@page import="monfox.toolkit.snmp.agent.modules.SnmpV2Mib.SysOREntry"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%@ page import="kr.co.udapsoft.common.*" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>
<%@ page import="com.udapsoft.waf.system.*" %>
<%@ page import="com.udapsoft.waf.common.*" %>
<%@ page import="com.udapsoft.waf.common.ui.HTMLMaker" %>
<%@ page import="com.udapsoft.waf.system.HandlerStorage" %>
<%@ page import="kr.co.hsnc.common.util.*"%>
<%@ page import="kr.co.hsnc.common.util.ValueObject" %>
<%@ page import="kr.co.hsnc.common.sql.*" %>
<%@ page import="kr.co.hsnc.common.sql.RowSet" %>
<%@ page import="kr.co.hsnc.common.sql.util.*" %>
<%@ page import="com.udapsoft.waf.common.ui.*" %>
<%@ page import="kr.co.udapsoft.common.code.*" %>

<%-- <%@ include file="/jsp/work/taglib.jsp" %> --%>

<jsp:useBean id="ctx" class="com.udapsoft.waf.system.context.SessionContext" scope="session" />

<%
	ctx.init(request, response); 
	HandlerStorage storage = ctx.getHandlerStorage();
	ValueObject params = storage.getParams();
	ValueObject user = ctx.getUser();
	String BID_NO =   (String) storage.get("BID_NO");
	String BID_DEG =   (String) storage.get("BID_DEG");
	String BID_FROM_DT =   (String) storage.get("BID_FROM_DT");
	String BID_TO_DT =   (String) storage.get("BID_TO_DT");
	String pop_win_id =   (String) storage.get("pop_win_id");
    SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
    String str = sd.format(new Date()); 
%>

<%@ page contentType="text/html; charset=utf-8" %>
<SCRIPT language="JavaScript">
	var from_dt = "<%=BID_FROM_DT%>";
	var from_date = from_dt.substring(0,10);
	var from_hh = from_dt.substring(11,13);
	var from_mi = from_dt.substring(14,16);
	
	function doPageInit() {
		$("#BID_TO_DT").change(function() {
			To_Date_ck();
		});
		$("#BID_TO_HH").change(function() {
			To_Date_ck();
		});
		$("#BID_TO_MI").change(function() {
			To_Date_ck();
		});
	}
	
	function To_Date_ck(){
		if($("#BID_TO_DT").val() < from_date){//적을경우
			alert("견적제출 마감일시는 제출 시작일시 보다 커야 합니다.");
			$("#BID_TO_DT").val("");
			$("#BID_TO_DT").focus();
			return;
		}else if($("#BID_TO_DT").val() == from_date){//같은 경우
			if($("#BID_TO_HH").val().length > 0){
				if($("#BID_TO_HH").val() < from_hh){
					alert("견적제출 마감일시는 제출 시작일시 보다 커야 합니다.");
					$("#BID_TO_HH").val("");
					$("#BID_TO_HH").focus();
					return;
				}else if($("#BID_TO_HH").val() == from_hh){
					if($("#BID_TO_MI").val().length > 0){
						if($("#BID_TO_MI").val() < from_mi){
							alert("견적제출 마감일시는 제출 시작일시 보다 커야 합니다.");
							$("#BID_TO_MI").val("");
							$("#BID_TO_MI").focus();
							return;
						}
					}
				}
			}
		}
	}
	
	
	function doClose()
	{
     	returnValue = null;
     	parent.PopClose("<%=pop_win_id%>",returnValue);
	}

	function postpone(){
		if($("#BID_TO_DT").val().length == 0 ||$("#BID_TO_HH").val().length == 0 || $("#BID_TO_MI").val().length == 0){
			alert("변경 견적마감일시는 필수 입니다.");
			return;
		}
		if(time_ck("BID_TO_HH","HH"))return;
		if(time_ck("BID_TO_MI","MI"))return;
		if($("#POSTPONE_REASON").val().length > 0){
			replace();
			if(confirm("견적제출마감시간을 변경하시겠습니까?")){
				var f = document.form1;
				submitXmlRequest("/bid/purchase/BidDeferPop_form.screen", "FORM_POSTPONE_UPDATE", f);
			}
		}else{
			alert("연기사유는 필수 입니다.");
		}
	}
	
	function replace(){
		var content = $("#POSTPONE_REASON").val();
		$("#POSTPONEREASON").val(content);
	}
	

	function doResult(resultObj) {
		try {
			if( resultObj.getRequestEvent() == "FORM_POSTPONE_UPDATE") {
				if( resultObj.getSuccess() ) {
					returnValue = new Array(0,"연기 되었습니다.");
					parent.PopClose("<%=pop_win_id%>",returnValue);
				}
				else {
					dlgErrorMsg(resultObj);
				}
			}
		}
		catch(errorObject) {
			showErrorDlg("doResult()", errorObject);
		}
	}
	
	function time_ck(obj,type){
		if(must_ck_val(obj,""))return true;
		if(!isNumber($("#"+obj).val())){
			alert("숫자만 입력 가능합니다.");
			$("#"+obj).focus();
			return true;
		}else{
			var time = Number($("#"+obj).val());
			if(type == "HH"){
				if(time < -1 || time > 23){
					alert("0~23 까지 입력 가능합니다.");
					$("#"+obj).focus();
					return true;
				}
			}else if(type == "MI"){
				if(time < -1 || time > 59){
					alert("0~59 까지 입력 가능합니다.");
					$("#"+obj).focus();
					return true;
				}
			}
		}
		if($("#"+obj).val().length == 1){
			var timelength = $("#"+obj).val();
			$("#"+obj).val("0"+timelength); 
		}
		return false; 
	}
	
	// value 값 체크 
	function must_ck_val(obj,desc){
		if($("#"+obj).val().length == 0){
			if(desc.length > 0){
				alert(desc+must_msg);
			}else{
				alert($("#"+obj).attr("desc")+must_msg);
			}
			$("#"+obj).focus();
			return true;
		}
		return false;
	}
	document.body.onload = doPageInit;
	setInterval("dpTime()",1000);

</SCRIPT>
<modular:search id="form1">
	<modular:key id="fevent" />
</modular:search>

<FORM name="form1" method="post">
<INPUT type="hidden" name="BID_NO" value="<%=BID_NO%>">
<INPUT type="hidden" name="BID_DEG" value="<%=BID_DEG%>">
<INPUT type="hidden" name="STATUS_CD" value="04">
<INPUT type="hidden" name="fevent" id="fevent" value="FROM_POSTPONE_UPDATE">
<INPUT type="hidden" name="POSTPONEREASON" id="POSTPONEREASON" value="">
<INPUT type="hidden" name="BID_FROM_DT" value="<%=BID_FROM_DT %>">

<TABLE class="screen_title_table">
  <TR height="2"><TD colspan="2"></TD>
  </TR>
  <TR height="25"><TD>
  	<!-- 제목 및 버튼 -->
   	<table id="t1" width="100%" class="ftit_table">
		<colgroup>
			<col width="*" />
			<col width="150" />
		</colgroup>
	<tr>
	   	<th>
	   </th>
	   <td align="right">
			<span class="btnSearch center"><a href="javascript:postpone();">연기</a></span>
	   </td>
   	</tr>
   	</table>
    </TD>
  </TR>
  <tr>
  <td>

<!-- 버튼 영역 : 시작 -->



<!-- 발주의뢰정보 : 시작 -->
<TABLE  class="form-table">
	<colgroup>
		<col width="150" />
		<col width="*" />
	</colgroup>
	<TR height="25"> 
	    <TH >서버시간</TH>
		<TD > 
		 &nbsp;&nbsp; <font color='red'><b><%=str %> <span id="dpTime"></b></font></span>
	    </TD>
	  </TR>
	  <TR height="25"> 
	    <TH >견적제출기간</TH>
		<TD > 
		 &nbsp;&nbsp; <%=BID_FROM_DT %> ~ <%=BID_TO_DT %> 
	    </TD>
	  </TR>
	  <TR height="25"> 
	    <TH class=" required">변경 견적마감일시</TH>
		<TD  > 
		 &nbsp;&nbsp; 
		 	<%= InputText.get("BID_TO_DT", "", 13, 10, "center,desc=견적마감일시,readOnly") %>
			<IMG name="calendar_sitedescdate" id="calendar_sitedescdate" src="/img/buyer/button/bt_calender.gif" border="0" align="absmiddle" style="cursor:pointer;" onClick="JavaScript:dlgCalendar('BID_TO_DT');">
			<%= InputText.get("BID_TO_HH", "", 2, 2, "center,desc=견적마감일시,Time") %> : <%= InputText.get("BID_TO_MI", "", 2, 2, "center,desc=견적마감일시,Time") %> 
	    </TD>
	  </TR>
    <TR height="25"> 
	    <th width="15%" class="required">공지여부</th>
		<TD width="35%"> 
		 &nbsp;&nbsp; 
		 	<LABEL for="obc_ind_type_1"><INPUT id="obc_ind_type_1" type="radio" name="DELAY_NOTI_YN" value="Y" desc="Notice여부" checked>예</LABEL>
		<LABEL for="obc_ind_type_2"><INPUT id="obc_ind_type_2" type="radio" name="DELAY_NOTI_YN" value="N" desc="Notice여부" >아니오</LABEL> 
	    </TD>
	  </TR>
	  <TR height="80"> 
	    <TH class=" required">연기사유</TH>
		<TD > 
		 &nbsp;&nbsp; <textarea name="POSTPONE_REASON" id="POSTPONE_REASON" style="width:95%; height:150px; overflow-y:auto" maxlength="100" class="input byteChk ctrlTarget"></textarea>
	    </TD>
	  </TR>
</TABLE>
  </td>
  </tr>
</TABLE>
</FORM>
