var cal_source="/com/cal.jsp";

var target;
var stime;
var calendar;
var cfunct;

if(typeof(cal_included) == 'undefined') {
	document.writeln('<div id="minical" onmouseover="Calendar_Over()" onmouseout="Calendar_Out()" style="display:none; position:absolute; z-index:5;">');
	document.writeln('<iframe id="Cal_iFrame" width=160 height=130 src="' + cal_source + '" scrolling=no frameborder=no></iframe>');
	document.writeln('</div>');
	cal_included = true;
}

function Calendar_Over() {
	window.clearTimeout(stime);
}

function Calendar_Out() {
	stime = window.setTimeout("calendar.style.display='none';", 200);
}

function Calendar_Click(cal_Day) {
	if (cal_Day.length > 6) {
		target.value = cal_Day;
	}
	if (cfunct != null && typeof(cfunct)=='function') cfunct(target);
	calendar.style.display = "none";
}

function Calendar_D(obj, isTop, fnc) {
	var now = obj.value.split("/");
	target = obj;
	cfunct = fnc;

	var top = document.body.clientTop + GetObjectTop(obj);
	var left = document.body.clientLeft + GetObjectLeft(obj);
	calendar = document.all.minical;

	if(isTop != null && isTop)
		calendar.style.pixelTop = top + obj.offsetHeight - 160;
	else
		calendar.style.pixelTop = top + obj.offsetHeight;

	if (left > document.body.clientWidth - 160) {
		left = document.body.clientWidth - 174;
	}

	calendar.style.pixelLeft = left;
	calendar.style.display = "block";

	if (now.length == 3) {
		Cal_iFrame.Show_cal(now[2], now[1], now[0]);
	} else {
		now = new Date();
		Cal_iFrame.Show_cal(now.getFullYear(), now.getMonth()+1, now.getDate());
	}
}

function GetObjectTop(obj) {
	if (obj.offsetParent == document.body) {
		return obj.offsetTop;
	} else {
		return obj.offsetTop + GetObjectTop(obj.offsetParent);
	}
}

function GetObjectLeft(obj) {
	if (obj.offsetParent == document.body) {
		return obj.offsetLeft;
	} else {
		return obj.offsetLeft + GetObjectLeft(obj.offsetParent);
	}
}

function getDateYMDHMS(date, hour, minute, second) {
	var rdate;

	if (date == "") {
		// alert("Please input date value");
		return "";
	}

	date = date.substring(0, 4) + date.substring(5, 7) + date.substring(8, 10);
	rdate = date+hour+minute+second;
	return rdate;
}

function outHourList(obj, shour) {
	var hour = "";
	hour = hour + "<select name='ihour'>";
	for(var i=1; i<=12; i++){
		if(i<10) {
			if(i==shour) {
				hour=hour+"<option value='0"+i+"' selected>0"+i+"</option>";
			} else {
				hour=hour+"<option value='0"+i+"'>0"+i+"</option>";
			}
		} else {
			if(i==shour) {
				hour = hour + "<option value='"+i+"' selected>"+i+"</option>";
			} else {
				hour=hour+"<option value='"+i+"'>"+i+"</option>";
			}
		}
	}
	hour = hour + "</select>";
	obj.innerHTML = hour;
}

function outMSList(obj, div, s) {
	var ns = "";
	if(div=="M") {
		ns=ns+"<select name='iminute'>";
	} else if(div=="S") {
		ns=ns+"<select name='isecond'>";
	}
	for(var i=0; i<=59; i++) {
		if(i<10) {
			if(s==i) {
				ns=ns+"<option value='0"+i+"' selected>0"+i+"</option>";
			} else {
				ns=ns+"<option value='0"+i+"'>0"+i+"</option>";
			}
		} else {
			if(s==i) {
				ns=ns+"<option value='"+i+"' selected>"+i+"</option>";
			} else {
				ns=ns+"<option value='"+i+"'>"+i+"</option>";
			}
		}
	}
	ns = ns + "</select>";
	obj.innerHTML = ns;
}

function cvrtDateType(source, type) {
	var result;
	if(type=="list") {
		result = source.substring(0, 4) +
		"-" + source.substring(4, 6) +
		"-" + source.substring(6, 8);
	} else if (type=="view") {
		result = source.substring(0, 4) +
		"-" + source.substring(4, 6) +
		"-" + source.substring(6, 8) +
		" " + source.substring(8, 10) +
		":" + source.substring(10, 12) +
		":" + source.substring(12, 14);
	}
	return result;
}

function getHour(source) {
	var result;
	result = source.substring(8, 10);
	return result;
}

function getMinute(source) {
	var result;
	result = source.substring(10, 12);
	return result;
}

function getSecond(source) {
	var result;
	result = source.substring(12, 14);
	return result;
}
