<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>

<script src="IDC/js/setToken.js"></script>
<script type="text/javascript">
$(function()
{
	//회선코드에 기입시 작동
	$("#line_code").bind("input",function()
	{
		var data ="searchContent="+$(this).val();
		//get으로 데이터 얻어오기.
		$("#idToggle").empty();
		$("#idToggle").show();
		$.get("IdcGetLineCode.jso",data,function(a)
		{
			var t = a.a;
			for(var i=0;i<t.length;i++)
			{
				var li = $("<li>"); var a = $("<a>");
				a.attr({"href":"#",
						  "value":t[i]}).addClass("btn btn-default").html(t[i]);
				li.append(a);
			$("#idToggle").append(li)
			}
		});
	});
	
	$(document).click(function()
	{
		$("#idToggle").hide();
	});
});
</script>

<script>
$(function()
{
	$("#getIPList").click(function()
	{
		var s="";
		$(".getIP").each(function()
		{
			s+="Line_ip="+$(this).val()+"&";
		});
		$.ajax(
		{
			url : "IdcLineIPWrite.jso",
			type : "post",
			data : s,
			dataType : "json",
			timeout : "30000",
			cache : false,
			success : function(data)
			{
				//alert("나 아이피 등록");
				$("#ipTable").empty();
				var ip_check = $("#ip_check").val("true");
				
				var j = data[0].ip;
				for(var i=0;i<j.length;i++)
				{
					var tr = $("<tr>");
					var td = $("<td>");
					var lable = $("<label>");
					
					lable.html(j[i].ip_address);
					td.append(lable);
					td.append($("<br>"));
					tr.append(td);
					$("#ipTable").append(tr);
				}
			},
			error : function()
			{
				alert("실풰")
			}
		});
		$("#myModalBtn").click();
	});
	
});
</script>
<!-- IP가져오기  -->
<script type="text/javascript">
$(function()
{
	//getip에다가 글쓸때
	$("#getIP").on("input",function()
	{	
		var ul=$("#getIPul");
		ul.empty();
		
		$.ajax(
		{
			url:"IdcGetIPList.jso",
			data:"getIP="+$(this).val(),
			dataType:"json",
			type:"post",
			cache:false,
			success:function(data)
			{
				createIPList(data[0].a,ul);
			},
			error:function()
			{
				alert(" 에서의 Error");
			}
		});
		
		ul.show();
	});
	//ip리스트 눌렀을 경우 
	$(document).on("click","#getIPul > li > a",function()
	{
		$("#getIP").val($(this).attr("value"));
		$("#getIPul").hide();
	});
});
var createIPList=function(data,ul)
{
	for(var i=0;i<data.length;i++)
	{
		var li=$("<li>");
		var a=$("<a>");
		a.addClass("btn btn-default").attr("value",data[i]).html(data[i]);
		li.append(a);
		ul.append(li);
	}
}
</script>

<script>
$(function(){	
	$("form[name='form1']").submit(function(){				
						
		var line_code = $("#line_code").val();
		var line_name = $("#line_name").val();
		var ip_check = $("#ip_check").val();
		
		var ip_dae1 = $("#ip_dae1").val();
		var ip_dae2 = $("#ip_dae2").val();
		var ip_dae3 = $("#ip_dae3").val();
		var ip_dae4 = $("#ip_dae4").val();
		var ip_dae5 = $("#ip_dae5").val();
		
		var line_user_allocatingday = $("#line_user_allocatingday").val();
		
		
		if(line_code == null || line_code == "" || line_code == undefined){
			alert("회선번호를 입력해주세요");
			return false;
		}
		
		if(line_name == null || line_name == "" || line_name == undefined){
			alert("회선명을 입력해주세요");
			return false;
		}
				
		if(ip_check == "false"){
			alert("IP를 등록 하십시오");
			return false;
		}
		
		if(ip_dae1 == null || ip_dae1 == "" || ip_dae1 == undefined){
			alert("IP 대역을 입력해주세요");
			return false;
		}
		
		if(ip_dae2 == null || ip_dae2 == "" || ip_dae2 == undefined){
			alert("IP 대역을 입력해주세요");
			return false;
		}
		
		if(ip_dae3 == null || ip_dae3 == "" || ip_dae3 == undefined){
			alert("IP 대역을 입력해주세요");
			return false;
		}
		
		if(ip_dae4 == null || ip_dae4 == "" || ip_dae4 == undefined){
			alert("IP 대역을 입력해주세요");
			return false;
		}
		
		if(ip_dae5 == null || ip_dae5 == "" || ip_dae5 == undefined){
			alert("IP 대역을 입력해주세요");
			return false;
		}
		
		if(line_user_allocatingday != null && line_user_allocatingday != "" && line_user_allocatingday != undefined){
			
		}else{
			alert("IP할당일을 선택하십시오");
			return false;
		}
	});
});
</script>

<!-- 여기가 본 페이지이다 -->
<div class="row">
	<div class="col-lg-7">
		<div class="panel panel-default">
			<div class="panel-heading">
				<h4><i class="fa fa-desktop fa-fw"></i> 회선 등록</h4>
			</div>
			<div class="panel-body">
   				<form name="form1" action="IdcLineWrite.lin" method="POST">
		   			<input type="hidden" id="token" name="token">
		   			<input type="hidden" id="ip_check" value="false">
		   			<div class="table-responsive">
						<table class="table table-bordered table-hover table-striped">							
							<tbody>
								<tr>
									<td>회선번호</td>
									<td>
										<input type="text" name="line_code" id="line_code">
									</td>
								</tr>
								<tr>
									<td>회선명</td>
									<td><input type="text" name="line_name" id="line_name"></td>
								</tr>
								<tr>
									<td>연락처</td>
									<td><input type="text" name="line_phone"></td>
								</tr>
								<tr>
									<td>회선구분</td>
									<td>
										<input type="radio" name="line_case" value="일반" checked="checked">일반
										<input type="radio" name="line_case" value="전용">전용
									</td>
								</tr>
								<tr>
									<td>가용여부</td>
									<td>
										<input type="radio" name="line_able" value="1" checked="checked">O
										<input type="radio" name="line_able" value="0">X
									</td>
								</tr>
								<tr>
									<td>차단</td>
									<td>
										<input type="radio" name="line_block" value="x" checked="checked">정상
										<input type="radio" name="line_block" value="o">차단
									</td>
								</tr>
								<tr>
									<td>회선 IP</td>
									<td><input type="text" name="line_ip">
											<button class="btn btn-default" type="button" data-toggle="modal" data-target="#myModal" id="myModalBtn">ip 등록</button>
											<input type="hidden" name="IdcIPDBList" id="hiddenIP">
									</td>
								</tr>
								<tr>
									<td>IP 대역</td>
									<td>
										<input type="text" name="ip_dae" value="" size="1" id="ip_dae1">.
										<input type="text" name="ip_dae" value="" size="1" id="ip_dae2">.
										<input type="text" name="ip_dae" value="" size="1" id="ip_dae3">.
										<input type="text" name="ip_dae" value="" size="1" id="ip_dae4">/ 
										<input type="text" name="ip_dae" value="" size="1" id="ip_dae5">
									</td>
								</tr>
								<tr>
									<td>IP할당일</td>
									<td><input type="date" name="line_user_allocatingday" id="line_user_allocatingday"></td>
								</tr>
								<tr>
									<td>고객명</td>
									<td><input type="text" name="line_client_name"></td>
								</tr>
								<tr>
									<td>메인IP</td>
									<td><input type="text" name="line_mainip"></td>
								</tr>
								<tr>
									<td>서브넷</td>
									<td><input type="text" name="line_subnet"></td>
								</tr>
								<tr>
									<td>게이트웨이</td>
									<td><input type="text" name="line_gateway"></td>
								</tr>
								<tr>
									<td>ID</td>
									<td><input type="text" name="line_id"></td>
								</tr>
								<tr>
									<td>Password</td>
									<td><input type="text" name="line_pass"></td>
								</tr>
								<tr>
									<td>서브IP1</td>
									<td><input type="text" name="line_subip1"></td>
								</tr>
								<tr>
									<td>서브IP2</td>
									<td><input type="text" name="line_subip2"></td>
								</tr>
								<tr>
									<td>서브IP3</td>
									<td><input type="text" name="line_subip3"></td>
								</tr>
							</tbody>
							<tfoot>
							</tfoot>
						</table>
					</div>
					<!-- table-responsive -->
					<div class="input-group-btn">
						<input class="btn btn-outline btn-primary" type="submit" value="저장">
						<a class="btn btn-outline btn-default" href="IdcLineListForm.lin">취소</a>
					</div>
				</form>
			</div>
			<!-- panel-body -->
		</div>
		<!-- panel panel-default -->
	</div>
	<!-- col-lg-8 -->

	<div class="col-lg-4">
		<div class="panel panel-default">
			<div class="panel-heading">
				<h4><i class="fa fa-desktop fa-fw"></i> 등록할 IP</h4>
			</div>
			<div class="panel-body">
	   			<div class="table-responsive">
	   				<form action="IdcLineWrite.lin" method="POST">
						<table class="table table-bordered table-hover table-striped">
							<thead>
							</thead>
							<tbody  id="ipTable" style="max-height:50px;">
								<tr>
									<td>선택 IP </td>
								</tr>
							</tbody>
							<tfoot>
							</tfoot>
						</table>
					</form>
				</div>
				<!-- table-responsive -->
			</div>
			<!-- panel-body -->
		</div>
		<!-- panel panel-default -->
	</div>
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
					<h4 class="modal-title">IP등록</h4>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
							<input type="text" class="form-control getIP">
						</div>
						<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
							<input type="text" class="form-control getIP">
						</div>
						<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
							<input type="text" class="form-control getIP">
						</div>
						<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
							<input type="text" class="form-control getIP">
						</div>
						<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2" style="padding-top:6px;">
							<p  class="text-center" style="margin-bottom:0px;">
								<label>~</label>
							</p>
						</div>
						<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
							<input type="text" class="form-control getIP">
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">닫기</button>
					<button type="button" class="btn btn-primary" id="getIPList">저장</button>
				</div>
			</div>
		</div>
	</div>
	<!-- modal fade -->
</div>
<!-- row -->
<!-- /#page-wrapper -->
