<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="layout.html" />
  <xi:include href="macros.html" />
  <head>
    <title>アンケートタイトル</title>
  </head>

  <body>
  	<py:if test="error!=''">
	<div id="content" class="error">
		<h2>Error:</h2>
		<div class="message">${error}</div>
	</div>
	</py:if>
	<form name="enquetetitle"  method="post">
	<py:if test="req.perm.has_permission('ENQUETE_EDIT')">
	<div>
		<fieldset>
			<legend>アンケートタイトル</legend>
			<table>
			<tr><td>アンケートタイトル:</td><td><input type="text" name="newtitle" size="70" value="${title}"/></td></tr>
			<tr><td>回答期限:</td>
			<td>
				<table><tr><td><div class="expire_text" id="expire_text">${expire_date}</div><div id="cal1Container"></div></td><td><input type="hidden" id="expire_date" name="expire_date"  value="${expire_date}"/></td><td><input type="button" name="clear" value="クリア"  onclick="eventHandler('clear');" /></td></tr></table>
			</td></tr>
			<tr><td>説明:</td><td><textarea rows="3"  cols="60" name="description">${description}</textarea></td></tr>
			<tr><td><input type="button" name="regist" value="登録"  onclick="eventHandler('regist');" />
			<input type="button" name="enquetelist" value="戻る"  onclick="javascript:eventHandler('enquetelist');" /></td></tr>
			</table>
		</fieldset>
	</div>
	</py:if>
	<input type="hidden" id="enquete_id"  name="enquete_id" value="${enquete_id}"/>
	<input type="hidden" id="actionName"  name="actionName"/>
	</form>

<script type="text/javascript">
	YAHOO.namespace("enquate.calendar");

	YAHOO.enquate.calendar.init = function() {

		function handleSelect(type,args,obj) {
			var dates = args[0];
			var date = dates[0];
			var year = date[0], month = date[1], day = date[2];

			var txtDate1 = document.getElementById("expire_date");
			var txtDate2 = document.getElementById("expire_text");
			if((""+day).length == 1){
				day = "0" + day;
			}
			txtDate1.value = year + "/" + month + "/" + day ;
			if (typeof txtDate2.textContent != "undefined") {
				txtDate2.textContent = txtDate1.value;
			} else {
				txtDate2.innerText = txtDate1.value;
			}
			YAHOO.enquate.calendar.cal1.hide();
		}

		YAHOO.enquate.calendar.cal1 = new YAHOO.widget.Calendar("cal1","cal1Container", { title:"回答期限:", close:true } );
		YAHOO.enquate.calendar.cal1.selectEvent.subscribe(handleSelect, YAHOO.enquate.calendar.cal1, true);
		YAHOO.enquate.calendar.cal1.render();

		YAHOO.util.Event.addListener("expire_text", "click", YAHOO.enquate.calendar.cal1.show,YAHOO.enquate.calendar.cal1, true);
	}

	YAHOO.util.Event.onDOMReady(YAHOO.enquate.calendar.init);
</script>
<script type="text/javascript">
function eventHandler(actionName,enquete_id) {
	var f = document.forms['enquetetitle'];
	document.getElementById('actionName').value = actionName;
	if(actionName == "regist"){
		f.action = "${href.enquete('edittitle')}";
	} else if(actionName == 'clear'){
		var txtDate1 = document.getElementById("expire_date");
		var txtDate2 = document.getElementById("expire_text");
		txtDate1.value = "";
		if (typeof txtDate2.textContent != "undefined") {
			txtDate2.textContent = "";
		} else {
			txtDate2.innerText = "";
		}
		return false;
	} else if(actionName == "enquetelist"){
		location.href="${href.enquete()}";
		return;
	}
	f.submit();
}
</script>
  </body>
</html>
