var dtpInter,dtpStartYear;
var dtpFolder = document.parentWindow.parent.dtpFolder;
var dtpDayName = document.parentWindow.parent.dtpDayName;
var dtpMonthDay = document.parentWindow.parent.dtpMonthDay;
var dtpMonthList = document.parentWindow.parent.dtpMonthList;
var dtpHourList = document.parentWindow.parent.dtpHourList;
var dtpMinuteList = document.parentWindow.parent.dtpMinuteList;
function dtpGetElement(eId){
	return document.getElementById(eId);
}
function dtpGetFrame(eId){
	return document.frames(eId);
}
function dtpSpanOver(eSpan, eImg, destImg){
	eSpan.style.borderColor = '#88AAFF';
	dtpSwapImg(eImg, destImg);
}
function dtpSpanOut(eSpan, eImg, destImg){
	eSpan.style.borderColor = '#3366FF';
	dtpSwapImg(eImg, destImg);
}
function dtpSwapImg(eImg, destImg){
	var e = dtpGetElement(eImg);
	e.setAttribute('src', dtpFolder + destImg);
}
function dtpGetIE(e){
	var top = e.offsetTop;
	var left = e.offsetLeft;
	while(e = e.offsetParent){
		top += e.offsetTop;
		left += e.offsetLeft;
	}
	return {x:top,y:left}
}
function dtpClose(){
	document.parentWindow.parent.dtpClose();
}
function dtpOpenMenu(e, text, width, height){
	var ifrMenu = document.parentWindow.parent.document.frames('dtpDropMenu');
	var elemMenu = document.parentWindow.parent.document.getElementById('dtpDropMenu');
	ifrMenu.document.open('text/html', 'replace');
	ifrMenu.document.write('<html><head><style>body{background-color:#FFFFDD;}</style>'+
				'<link rel="stylesheet" type="text/css" href="'+ dtpFolder +'default.css">'+
				'<script language="javascript" src="'+ dtpFolder +'selector.js"></script>'+
				'</head><body>'+ text +'</body></html>');
	ifrMenu.document.close();
	ifrMenu.document.body.style.border = '1px solid #a0a0a0';
	
	var Parent = dtpGetIE(document.parentWindow.parent.document.getElementById('DateTimePicker'));
	var Current = dtpGetIE(e);
	elemMenu.style.display = '';
	elemMenu.style.width = width;
	elemMenu.style.height = height;
	elemMenu.style.left = Parent.y + Current.y;
	elemMenu.style.top = Parent.x + Current.x + 20;
}
function dtpSetPreMonth(){
	var n = document.parentWindow.parent.dtpMonth;
	if(n < 1) n = 1;
	dtpSetMonth(n - 1);
}
function dtpSetNextMonth(){
	var n = document.parentWindow.parent.dtpMonth;
	if(n > 10) n = 10;
	dtpSetMonth(n + 1);
}
function dtpMonth(e){
	var n = document.parentWindow.parent.dtpMonth;
	var _html = '';
	for(i=0; i<dtpMonthList.length; i++){
		_html += '<div id="'+ i +'" class="dtpPopItem"'+
		' onClick="dtpSetMonth('+ i +')"'+
		' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
		' onMouseOut="this.style.backgroundColor=\'\'">&nbsp; ';
		if(i == n){
			_html += '<b>'+ dtpMonthList[i] +'</b>';
		}else{
			_html += dtpMonthList[i];
		}
		_html += ' &nbsp;</div>';
	}
	dtpOpenMenu(e, _html, 75, 210);
}
function dtpSetMonth(n){
	document.parentWindow.parent.dtpSetMonth(n);
}
function dtpYear(e){
	var _html = '';
	_html += '<div class="dtpPopItem" onMouseDown="clearInterval(dtpInter); dtpInter=setInterval(\'dtpAscYear()\',30)"'+
	' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
	' onMouseUp="clearInterval(dtpInter)"'+
	' onMouseOut="this.style.backgroundColor=\'\'" align="center">&nbsp; - &nbsp;</div>';
	
	var n = parseInt(document.parentWindow.parent.dtpYear);
	for(i=0; i<7; i++){
		var NowYear = n - 3 + i;
		_html += '<div id="dtpY'+ i +'" class="dtpPopItem"'+
		' onClick="dtpSetYear(this.innerText)"'+
		' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
		' onMouseOut="this.style.backgroundColor=\'\'">&nbsp; ';
		if(NowYear == n){
			_html += '<b>'+ NowYear +'</b>';
		}else{
			_html += NowYear;
		}
		_html += ' &nbsp;</div>';
	}
	_html += '<div class="dtpPopItem" onMouseDown="clearInterval(dtpInter); dtpInter=setInterval(\'dtpDescYear()\',30)"'+
	' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
	' onMouseUp="clearInterval(dtpInter)"'+
	' onMouseOut="this.style.backgroundColor=\'\'" align="center">&nbsp; + &nbsp;</div>';
	
	dtpOpenMenu(e, _html, 43, 160);
	eval(document.parentWindow.parent.dtpStartYear = n - 3);
}
function dtpSetYear(y){
	var n = parseInt(y);
	document.parentWindow.parent.dtpSetYear(n);
}
function dtpAscYear(){
	var _html = '';
	var n = parseInt(document.parentWindow.parent.dtpYear);
	var y = parseInt(document.parentWindow.parent.dtpStartYear);
	for(i=0; i<7; i++){
		var NowYear = y - 1 + i;
		if(NowYear == n){
			_html = '&nbsp; <b>'+ NowYear +'</b> &nbsp;';
		}else{
			_html = '&nbsp; '+ NowYear +' &nbsp;';
		}
		dtpGetElement('dtpY'+ i).innerHTML = _html;
	}
	eval(document.parentWindow.parent.dtpStartYear--);
}
function dtpDescYear(){
	var _html = '';
	var n = parseInt(document.parentWindow.parent.dtpYear);
	var y = parseInt(document.parentWindow.parent.dtpStartYear);
	for(i=0; i<7; i++){
		var NowYear = y + 1 + i;
		if(NowYear == n){
			_html = '&nbsp; <b>'+ NowYear +'</b> &nbsp;';
		}else{
			_html = '&nbsp; '+ NowYear +' &nbsp;';
		}
		dtpGetElement('dtpY'+ i).innerHTML = _html;
	}
	eval(document.parentWindow.parent.dtpStartYear++);
}
function dtpSetDate(date){
	document.parentWindow.parent.dtpSetDate(date);
}
function dtpHour(e){
	var _html = '';
	_html += '<div class="dtpPopItem" onMouseDown="clearInterval(dtpInter); dtpInter=setInterval(\'dtpAscHour()\',30)"'+
	' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
	' onMouseUp="clearInterval(dtpInter)"'+
	' onMouseOut="this.style.backgroundColor=\'\'" align="center">&nbsp; - &nbsp;</div>';
	
	var n = parseInt(document.parentWindow.parent.dtpHour);
	var s = n - 3;
	if(s < 0){
		s = 0;
	}else if(s > 17){
		s = 17;
	}
	for(i=0; i<7; i++){
		var NowHour = s + i;
		_html += '<div id="dtpH'+ i +'" class="dtpPopItem"'+
		' onClick="dtpSetHour(this.innerText)"'+
		' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
		' onMouseOut="this.style.backgroundColor=\'\'">&nbsp; ';
		if(NowHour == n){
			_html += '<b>'+ dtpHourList[NowHour] +'</b>';
		}else{
			_html += dtpHourList[NowHour];
		}
		_html += ' &nbsp;</div>';
	}
	_html += '<div class="dtpPopItem" onMouseDown="clearInterval(dtpInter); dtpInter=setInterval(\'dtpDescHour()\',30)"'+
	' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
	' onMouseUp="clearInterval(dtpInter)"'+
	' onMouseOut="this.style.backgroundColor=\'\'" align="center">&nbsp; + &nbsp;</div>';
	
	dtpOpenMenu(e, _html, 30, 160);
	eval(document.parentWindow.parent.dtpHour = n - 3);
}
function dtpAscHour(){
	var _html = '';
	var n = parseInt(document.parentWindow.parent.dtpHour);
	var h = parseInt(document.parentWindow.parent.dtpStartHour);
	if(h < 1){
		clearInterval(dtpInter);
		return;
	}
	for(i=0; i<7; i++){
		var NowHour = h - 1 + i;
		if(NowHour == n){
			_html = '&nbsp; <b>'+ dtpHourList[NowHour] +'</b> &nbsp;';
		}else{
			_html = '&nbsp; '+ dtpHourList[NowHour] +' &nbsp;';
		}
		dtpGetElement('dtpH'+ i).innerHTML = _html;
	}
	eval(document.parentWindow.parent.dtpStartHour--);
}
function dtpDescHour(){
	var _html = '';
	var n = parseInt(document.parentWindow.parent.dtpHour);
	var h = parseInt(document.parentWindow.parent.dtpStartHour);
	if(h > 16){
		clearInterval(dtpInter);
		return;
	}
	for(i=0; i<7; i++){
		var NowHour = h + 1 + i;
		if(NowHour == n){
			_html = '&nbsp; <b>'+ dtpHourList[NowHour] +'</b> &nbsp;';
		}else{
			_html = '&nbsp; '+ dtpHourList[NowHour] +' &nbsp;';
		}
		dtpGetElement('dtpH'+ i).innerHTML = _html;
	}
	eval(document.parentWindow.parent.dtpStartHour++);
}
function dtpSetHour(hour){
	var n = parseInt(hour);
	document.parentWindow.parent.dtpSetHour(n);
}
function dtpMinute(e){
	var _html = '';
	_html += '<div class="dtpPopItem" onMouseDown="clearInterval(dtpInter); dtpInter=setInterval(\'dtpAscMinute()\',30)"'+
	' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
	' onMouseUp="clearInterval(dtpInter)"'+
	' onMouseOut="this.style.backgroundColor=\'\'" align="center">&nbsp; - &nbsp;</div>';
	
	var n = parseInt(document.parentWindow.parent.dtpMinute);
	var s = n - 3;
	if(s < 0){
		s = 0;
	}else if(s > 53){
		s = 53;
	}
	for(i=0; i<7; i++){
		var NowMinute = s + i;
		_html += '<div id="dtpM'+ i +'" class="dtpPopItem"'+
		' onClick="dtpSetMinute(this.innerText)"'+
		' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
		' onMouseOut="this.style.backgroundColor=\'\'">&nbsp; ';
		if(NowMinute == n){
			_html += '<b>'+ dtpMinuteList[NowMinute] +'</b>';
		}else{
			_html += dtpMinuteList[NowMinute];
		}
		_html += ' &nbsp;</div>';
	}
	_html += '<div class="dtpPopItem" onMouseDown="clearInterval(dtpInter); dtpInter=setInterval(\'dtpDescMinute()\',30)"'+
	' onMouseOver="this.style.backgroundColor=\'#FFCC99\'"'+
	' onMouseUp="clearInterval(dtpInter)"'+
	' onMouseOut="this.style.backgroundColor=\'\'" align="center">&nbsp; + &nbsp;</div>';
	
	dtpOpenMenu(e, _html, 30, 160);
	eval(document.parentWindow.parent.dtpMinute = n - 3);
}
function dtpAscMinute(){
	var _html = '';
	var n = parseInt(document.parentWindow.parent.dtpMinute);
	var h = parseInt(document.parentWindow.parent.dtpStartMinute);
	if(h < 1){
		clearInterval(dtpInter);
		return;
	}
	for(i=0; i<7; i++){
		var NowMinute = h - 1 + i;
		if(NowMinute == n){
			_html = '&nbsp; <b>'+ dtpMinuteList[NowMinute] +'</b> &nbsp;';
		}else{
			_html = '&nbsp; '+ dtpMinuteList[NowMinute] +' &nbsp;';
		}
		dtpGetElement('dtpM'+ i).innerHTML = _html;
	}
	eval(document.parentWindow.parent.dtpStartMinute--);
}
function dtpDescMinute(){
	var _html = '';
	var n = parseInt(document.parentWindow.parent.dtpMinute);
	var h = parseInt(document.parentWindow.parent.dtpStartMinute);
	if(h > 52){
		clearInterval(dtpInter);
		return;
	}
	for(i=0; i<7; i++){
		var NowMinute = h + 1 + i;
		if(NowMinute == n){
			_html = '&nbsp; <b>'+ dtpMinuteList[NowMinute] +'</b> &nbsp;';
		}else{
			_html = '&nbsp; '+ dtpMinuteList[NowMinute] +' &nbsp;';
		}
		dtpGetElement('dtpM'+ i).innerHTML = _html;
	}
	eval(document.parentWindow.parent.dtpStartMinute++);
}
function dtpSetMinute(Minute){
	var n = parseInt(Minute);
	document.parentWindow.parent.dtpSetMinute(n);
}