<%
include("language.html")
if _SESSION["logined"] ~= nil then
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Schedule</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
body,td,span {font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%else%>
body,td,span {font:11px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%end%>

body {
	background-color:#E7E6DA;
	padding:0px;
	margin:0px;
	margin-top:20px;
}

button{
border:none;background:none;padding:0;
margin:0;width:auto;overflow:visible;text-align:center;	
white-space:nowrap;height:24px;line-height:22px;
cursor:pointer;
color:#000;
margin-left:2px;
margin-top:2px;
}
button span, button em{
display:block;height:24px;line-height:22px;margin:0;
}	
button span{
padding-left:14px;
background:url("images/button_left.gif") no-repeat 0 0;
}
button em{
font-style:normal;padding-right:14px;
background:url("images/button.gif") no-repeat 100% 0;
}
button:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
button span:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
.buttonhover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}


.m_frameborder {
	border-left: 2px inset #D4D0C8;
	border-top: 2px inset #D4D0C8;
	border-right: 2px inset #FFFFFF;
	border-bottom: 2px inset #FFFFFF;
	width: 100px;
	height: 19px;
	background-color: #FFFFFF;
	overflow: hidden;
	text-align: right;
	font-family: "Tahoma";
	font-size: 10px;
}
.m_arrow {
	width: 16px;
	height: 16px;
	font-size: 8px;
	line-height: 2px;
	padding-left: 2px;
	cursor: default;
}
.m_input {
	width: 18px;
	height: 14px;
	border: 0px solid black;
	font-family: "Tahoma";
	font-size: 9px;
	text-align: right;
	ime-mode:disabled;
}
</style>
<script language="javascript" src="include/common.js"></script>
<script language="javascript">
function getEvent()
{
  if(window.event)
  {
    return window.event;
  }
  func=getEvent.caller;
  while(func!=null)
  {
    var arg0=func.arguments[0];
    if(arg0)
    {
      if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
		||(typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
       {
          return arg0;
       }
    }
    func=func.caller;
  }
  return null;
}

if(window.HTMLElement) 
{
    HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
        var r=this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df=r.createContextualFragment(sHTML);
        this.parentNode.replaceChild(df,this);
        return sHTML;
        });

    HTMLElement.prototype.__defineGetter__("outerHTML",function(){
    var attr;
        var attrs=this.attributes;
        var str="<"+this.tagName.toLowerCase();
        for(var i=0;i<attrs.length;i++){
            attr=attrs[i];
            if(attr.specified)
                str+=" "+attr.name+'="'+attr.value+'"';
            }
        if(!this.canHaveChildren)
            return str+">";
        return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
        });
        
	HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
	switch(this.tagName.toLowerCase()){
            case "area":
            case "base":
			case "basefont":
            case "col":
            case "frame":
            case "hr":
            case "img":
            case "br":
            case "input":
            case "isindex":
            case "link":
            case "meta":
            case "param":
            return false;
        }
        return true;

     });
}

function minute(name,fName,initHour,initMin,initSec)
{
	this.name = name;
	this.fName = fName || "m_input";
	this.timer = null;
	this.fObj = null;
	
	this.toString = function()
	{
		var sMinute_Common = "class=\"m_input\" maxlength=\"2\" name=\""+this.fName+"\" onclick=\""+this.name+".setFocusObj(this)\" onblur=\""+this.name+".setTime(this)\" onkeyup=\""+this.name+".prevent(this)\" onkeypress=\"if (!/[0-9]/.test(String.fromCharCode(event.keyCode)))event.keyCode=0\" onpaste=\"return false\" ondragenter=\"return false\"";
		var sButton_Common = "class=\"m_arrow\" onfocus=\"this.blur()\" onmouseup=\""+this.name+".controlTime()\" "
		var str = "";
		str += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >"
		str += "<tr>"
		str += "<td>"
		str += "<div class=\"m_frameborder\">"
		str += "<input alt=\"24\" value=\""+initHour+"\" "+sMinute_Common+">:"
		str += "<input alt=\"60\" value=\""+initMin+"\" "+sMinute_Common+">:"
		str += "<input alt=\"60\" value=\""+initSec+"\" "+sMinute_Common+">"
		str += "</div>"
		str += "</td>"
		str += "<td>"
		str += "<table border=\"0\" cellspacing=\"2\" cellpadding=\"0\">"
		str += "<tr><td><input type='button' value='+' id=\""+this.fName+"_up\" "+sButton_Common+"></td></tr>"
		str += "<tr><td><input type='button' value='-' id=\""+this.fName+"_down\" "+sButton_Common+"></td></tr>"
		str += "</table>"
		str += "</td>"
		str += "</tr>"
		str += "</table>"
		return str;
	}
	this.formatTime = function(sTime)
	{
		sTime = ("0"+sTime);
		return sTime.substr(sTime.length-2);
	}
	this.prevent = function(obj)
	{
		clearInterval(this.timer);
		this.setFocusObj(obj);
		var value = parseInt(obj.value,10);
		var radix = parseInt(obj.alt,10)-1;
		if (obj.value>radix||obj.value<0)
		{
			obj.value = obj.value.substr(0,1);
		}
	}
	this.controlTime = function(cmd)
	{
		if (!this.fObj) return;
		clearInterval(this.timer);
		var evt = getEvent();
		var element = evt.srcElement || evt.target;
		var cmd = element.value=="+"?true:false;
		var i = parseInt(this.fObj.value,10);
		var radix = parseInt(this.fObj.alt,10)-1;
		if (i==radix&&cmd)
		{
			i = 0;
		}
		else if (i==0&&!cmd)
		{
			i = radix;
		}
		else
		{
			cmd?i++:i--;
		}
		this.fObj.value = this.formatTime(i);
		this.fObj.select();
	}
	this.setTime = function(obj)
	{
		obj.value = this.formatTime(obj.value);
	}
	this.setFocusObj = function(obj)
	{
		this.fObj = obj;
	}
	this.getTime = function()
	{
		var arrTime = new Array(2);
		for (var i=0;i<document.getElementsByName(this.fName).length;i++)
		{
			arrTime[i] = document.getElementsByName(this.fName)[i].value;
		}
		return arrTime.join(":");
	}
}

function compareTime(value1,value2)
{
	var mm_array1 = value1.split(":");
	var mm_array2 = value2.split(":");
	if(parseInt(mm_array1[0]) > parseInt(mm_array2[0]))
	{
		return false;
	}
	else
	{
		if(parseInt(mm_array1[0]) == parseInt(mm_array2[0]))
		{
			if(parseInt(mm_array1[1]) > parseInt(mm_array2[1]))
			{
				return false;
			}
			else
			{
				if(parseInt(mm_array1[1]) == parseInt(mm_array2[1]))
				{
					if(parseInt(mm_array1[2]) > parseInt(mm_array2[2]))
						return false;
				}
			}
		}
	}
	return true;
}

function returnTime()
{
	var mm_value1 = mm1.getTime();
	var mm_value2 = mm2.getTime();
	var retval = compareTime(mm_value1,mm_value2);
	if(retval == false)
	{
		alert("<%=LANG['str_addtime_tip']%>");
	}
	else
	{
		var checkallday = "0";
		<% if _GET["weekday"] == nil then %>
		if($("checkallday").checked)
			checkallday = "1";
		<% end %>
		var timevalue = $("weekday").value+","+mm_value1+","+mm_value2+","+checkallday;
		top.closewindow(timevalue);
	}
}
</script>

<body leftmargin="0" topmargin="10" marginwidth="0" marginheight="0">
<table cellSpacing="0" cellPadding="0" border="0">

<tr>
<td align="right" height="40" style="padding-left:10px;">
<%=LANG["title_weekday"]%>:&nbsp;&nbsp;
</td>
<td colspan="3">
<select id="weekday">
<script>
var weekdays = [<%=LANG["calendar_weekdays"]%>];
var selectday = '<%=_GET["weekday"] or "0"%>';
selectday = parseInt(selectday);
var temp = "";
for (var i=0;i<weekdays.length;i++) {
	if(selectday == i)
		temp += "<option value=\""+i+"\" selected>"+weekdays[i]+"</option>";
	else
		temp += "<option value=\""+i+"\" >"+weekdays[i]+"</option>";
}
document.write(temp);
</script>
</select>
</td>
</tr>

<tr>
<td align="right" height="40" style="padding-left:10px;">
<%=LANG["title_from"]%>&nbsp;&nbsp;
</td><td>
<script>
var timefrom = '<%=_GET["timefrom"] or "06:00:00"%>';
timefrom = timefrom.split(":");
var mm1 = new minute("mm1","m1",timefrom[0],timefrom[1],timefrom[2]);
document.write(mm1);
</script>
</td>
<td align="right">&nbsp;&nbsp;<%=LANG["title_to"]%></td>
<td>
<script>
var timeto = '<%=_GET["timeto"] or "20:00:00"%>';
timeto = timeto.split(":");
var mm2 = new minute("mm2","m2",timeto[0],timeto[1],timeto[2]);
document.write(mm2);
</script>
</td>
</tr>

<% if _GET["weekday"] == nil then %>
<tr>
<td colspan="4" height="40" style="padding:10px;">
<input type="checkbox" id="checkallday" ><%=LANG["str_same_schedule"]%>
</td>
</tr>
<% end %>

<tr>
<td colspan="4" align="center" height="60">
<button type='submit' onclick='returnTime();'><span><em><%=LANG["button_submit"]%></em></span></button>&nbsp;<button onclick='top.closewindow();'><span><em><%=LANG["button_cancel"]%></em></span></button>
</td>
</tr>
</table>

</body>
</html>

<% 
else
	print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
	print("<script>alert('"..LANG["session_expire"].."');top.location='admin_login.html';</script>")
end 
%>

<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>