/**
 * @fileoverview 팝업달력
 * @author 김동완
 * @version 0.1
 * @since 2008.05.08 First Draft.
 * @since 2008.06.02 XHTML + FF3.0 에서 위치값 못찾는것 수정!
 */






var	fixedX = -1;			// x 축(-1일 경우 객체 밑에 표현)
var	fixedY = -1;			// y 축(-1일 경우 객체 밑에 표현)
var startAt = 0;			// 0 - 일요일; 1 - 월요일
var showWeekNumber = 0;
var showToday = 0;
var imgDir = "/common/images/nexCalendar/"

var gotoString = "오늘날짜로 이동합니다."
var todayString = "오늘은"
var todayLastString = "오늘은"
var weekString = "주"
var scrollLeftMessage = ""
var scrollRightMessage = ""
var selectMonthMessage = ""
var selectYearMessage = ""
var selectDateMessage = "Select [date] as date."

var	crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear

var	bPageLoaded=false
var	ie=document.all
var	dom=document.getElementById

var	ns4=document.layers
var	today =	new	Date()
var	dateNow	 = today.getDate()
var	monthNow = today.getMonth()
var	yearNow	 = today.getYear()
var	imgsrc = new Array("cal_drop.gif","cal_drop.gif","cal_pre_m.gif","cal_pre_m.gif","cal_next_m.gif","cal_next_m.gif")
var	img	= new Array()

var bShow = false;

/**
 * IE6이하에서 select나 object숨기기
 */
function hideElement( elmID, overDiv ){
	if( ie ) {
		for( i = 0; i < document.all.tags( elmID ).length; i++ ){
			obj = document.all.tags( elmID )[i];
			if( !obj || !obj.offsetParent ){
				continue;
			}
			// Find the element's offsetTop and offsetLeft relative to the BODY tag.
			objLeft   = obj.offsetLeft;
			objTop    = obj.offsetTop;
			objParent = obj.offsetParent;

			while( objParent.tagName.toUpperCase() != "BODY" ){
				objLeft  += objParent.offsetLeft;
				objTop   += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}

			objHeight = obj.offsetHeight;
			objWidth = obj.offsetWidth;
			if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
			else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
			else if( overDiv.offsetTop >= ( objTop + objHeight ));
			else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
			else 	{
				obj.style.visibility = "hidden";
			}
		}
	}
}


/**
 * IE6이하에서 select나 object 다시 보이기
 */
function showElement( elmID ){
	if( ie ){
		for( i = 0; i < document.all.tags( elmID ).length; i++ )	{
			obj = document.all.tags( elmID )[i];
			if( !obj || !obj.offsetParent ){
				continue;
			}
			obj.style.visibility = "";
		}
	}
}



/**
 * 주말계산 클래스
 * @param {d} day
 * @param {m} month
 * @param {y} year
 * @param {desc} description
 */
function HolidayRec (d, m, y, desc){
	this.d = d;	//day
	this.m = m;	//month
	this.y = y;	//year
	this.desc = desc;	//description
}

var HolidaysCounter = 0
var Holidays = new Array()

/**
 * 휴일추가 함수
 * @param {d} day
 * @param {m} month
 * @param {y} year
 * @param {desc} description
 */
function addHoliday (d, m, y, desc){
	Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
}


if (dom){
	for	(i=0;i<imgsrc.length;i++){
		img[i] = new Image
		img[i].src = imgDir + imgsrc[i]
	}
	document.write ("<div onclick='bShow=true' id='calendar'	style='z-index:+999;position:absolute;visibility:hidden;'><table	width="+((showWeekNumber==1)?180:160)+" style='font-family:tahoma;font-size:10px;border-width:1px;border-style:solid;border-color:#545F69;font-family:tahoma; font-size:11px}' bgcolor='#ffffff'><tr style='background:url("+imgDir+"cal_bg.gif) 0 0 repeat-x;''><td style='padding:2px 5px 8px 2px'><table width='"+((showWeekNumber==1)?180:160)+"'><tr><td style='padding:2px;font-family:tahoma; font-size:10px;'><font color='black'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><IMG SRC='"+imgDir+"cal_close.gif' WIDTH='15' HEIGHT='15' BORDER='0' ALT='Close'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='contents'></span></td></tr>")

	if (showToday==1) 	{
	document.write ("<tr bgcolor=#f0f0f0><td  align=center><span id='lblToday'></span></td></tr>")
	}
	document.write ("</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;'></div>");
}

var	monthName =	new	Array("1","2","3","4","5","6","7","8","9","10","11","12")
var	monthName2 =	new	Array("1","2","3","4","5","6","7","8","9","10","11","12")
if (startAt==0)	{
	dayName = new Array	("일","월","화","수","목","금","토")
} else {
	dayName = new Array	("월","화","수","목","금","토","일")
}
var	styleAnchor="text-decoration:none;color:black;"
var	styleLightBorder="border-style:solid;border-width:1px;border-color:#545F69;"

function swapImage(srcImg, destImg){
	if (ie)	{ document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
}


/**
 * 캘린더 초기로딩
 */
function init()	{
	if (!ns4) {
		if (!ie) { yearNow += 1900	}
		crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar
		hideCalendar()
		crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth
		crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear
		monthConstructed=false;
		yearConstructed=false;
		if (showToday==1) {
			document.getElementById("lblToday").innerHTML =	todayString + " <a onmousemove='window.status=\""+gotoString+"\"' onmouseout='window.status=\"\"' title='"+gotoString+"' style='"+styleAnchor+"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();' style='color:red;font-family:tahoma;font-size:11px'>" +	yearNow	+ "�� "  + monthName[monthNow].substring(0,3) + " " + dateNow + " " +dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+"����</a>"
		}
		sHTML1="<span id='spanLeft'	style='cursor:pointer'  onclick='javascript:decMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"cal_pre_m.gif' width=15 height=15 BORDER=0 align=absmiddle></span>"
		sHTML1+="<span id='spanRight' style='cursor:pointer'	onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'	onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"cal_next_m.gif'	width=15 height=15 BORDER=0 align=absmiddle></span>"
		sHTML1+="<span id='spanMonth' style='cursor:pointer' onclick='popUpMonth()'></span>&nbsp;"
		sHTML1+="<span id='spanYear' style='cursor:pointer' onclick='popUpYear()'></span>&nbsp;"

		document.getElementById("caption").innerHTML  =	sHTML1

		bPageLoaded=true
	}
}


/**
 * 칼렌다 숨기기
 */
function hideCalendar()	{
	crossobj.visibility="hidden"
	if (crossMonthObj != null){crossMonthObj.visibility="hidden"}
	if (crossYearObj !=	null){crossYearObj.visibility="hidden"}

	showElement( 'SELECT' );
	showElement( 'APPLET' );
}

/**
 * 10보다 작을 경우 0 붙이기
 */
function padZero(num) {
	return (num	< 10)? '0' + num : num ;
}


/**
 * 날짜 생성하기
 * @param {d} day
 * @param {m} month
 * @param {y} year
 */
function constructDate(d,m,y){
	sTmp = dateFormat
	sTmp = sTmp.replace	("dd","<e>")
	sTmp = sTmp.replace	("d","<d>")
	sTmp = sTmp.replace	("<e>",padZero(d))
	sTmp = sTmp.replace	("<d>",d)
	sTmp = sTmp.replace	("mmmm","<p>")
	sTmp = sTmp.replace	("mmm","<o>")
	sTmp = sTmp.replace	("mm","<n>")
	sTmp = sTmp.replace	("m","<m>")
	sTmp = sTmp.replace	("<m>",m+1)
	sTmp = sTmp.replace	("<n>",padZero(m+1))
	sTmp = sTmp.replace	("<o>",monthName[m])
	sTmp = sTmp.replace	("<p>",monthName2[m])
	sTmp = sTmp.replace	("yyyy",y)
	return sTmp.replace ("yy",padZero(y%100))
}

/**
 * 캘린더 닫기
 */
function closeCalendar() {
	var	sTmp
	hideCalendar();
	ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected)
}



/**
 * 월(month)목록 풀다운 decrease
 */
function StartDecMonth(){
	intervalID1=setInterval("decMonth()",80)
}

/**
 * 월(month)목록 풀다운 increase
 */
function StartIncMonth(){
	intervalID1=setInterval("incMonth()",80)
}

/**
 * 월(month) increase - 다음날
 */
function incMonth () {
	monthSelected++
	if (monthSelected>11) {
		monthSelected=0
		yearSelected++
	}
	constructCalendar()
}

/**
 * 월(mont) decrease - 이전달
 */
function decMonth () {
	monthSelected--
	if (monthSelected<0) {
		monthSelected=11
		yearSelected--
	}
	constructCalendar()
}


/**
 * 월(month) 레이어 콤보박스 만들기
 */
function constructMonth() {
	popDownYear()
	if (!monthConstructed) {
		sHTML =	""
		for	(i=0; i<12;	i++) {
			sName =	monthName[i];
			if (i==monthSelected){
				sName =	"<B>" +	sName +	"</B>"
			}
			sHTML += "<tr><td id='m" + i + "' onmouseover='this.style.backgroundColor=\"#51BEB9\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer;font-family:tahoma;font-size:10px' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
		}
		document.getElementById("selectMonth").innerHTML = "<table width=40	style='font-family:tahoma; font-size:10px; border-width:1; border-style:solid; border-color:#545F69;' bgcolor='#EAECEB' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'	onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" +	sHTML +	"</table>"
		monthConstructed=true
	}
}

/**
 * 만들어진 월(month)레이어 숨기기/나타내기
 */
function popUpMonth() {
	constructMonth()
	crossMonthObj.visibility = (dom||ie)? "visible"	: "show"
	crossMonthObj.left = parseInt(crossobj.left) + 50 + 'px';
	crossMonthObj.top =	parseInt(crossobj.top) + 26 + 'px';

	hideElement( 'SELECT', document.getElementById("selectMonth") );
	hideElement( 'APPLET', document.getElementById("selectMonth") );
}

/**
 * 월(month)선택시 레이어 닫기
 */
function popDownMonth()	{
	crossMonthObj.visibility= "hidden"
}




/**
 * Year Pulldown  - 다음 년(year)찾기
 */
function incYear() {
	for	(i=0; i<7; i++){
		newYear	= (i+nStartingYear)+1
		if (newYear==yearSelected)
		{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
		else
		{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
		document.getElementById("y"+i).innerHTML = txtYear
	}
	nStartingYear ++;
	bShow=true
}

/**
 * Year Pulldown  - 이전 년(year)찾기
 */
function decYear() {
	for	(i=0; i<7; i++){
		newYear	= (i+nStartingYear)-1
		if (newYear==yearSelected)
		{ txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" }
		else
		{ txtYear =	"&nbsp;" + newYear + "&nbsp;" }
		document.getElementById("y"+i).innerHTML = txtYear
	}
	nStartingYear --;
	bShow=true
}

/**
 * 년도 선택
 * @param {nYear} 해당년도 선택
 */
function selectYear(nYear) {
	yearSelected=parseInt(nYear+nStartingYear);
	yearConstructed=false;
	constructCalendar();
	popDownYear();
}


/**
 * 년도 선택 레이어 생성하기
 */
function constructYear() {
	popDownMonth()
	sHTML =	""
	if (!yearConstructed) {
		sHTML =	"<tr><td align='center'	onmouseover='this.style.backgroundColor=\"#51BEB9\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer;font-family:tahoma;font-size:10px'	onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"
		j =	0
		nStartingYear =	yearSelected-3
		for	(i=(yearSelected-3); i<=(yearSelected+3); i++) {
			sName =	i;
			if (i==yearSelected){
				sName =	"<B>" +	sName +	"</B>"
			}

			sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#51BEB9\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer;font-family:tahoma;font-size:10px' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
			j ++;
		}

		sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"#51BEB9\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer;font-family:tahoma;font-size:10px' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>"

		document.getElementById("selectYear").innerHTML	= "<table width=50 style='font-family:tahoma; font-size:10px; border-width:1; border-style:solid; border-color:#545F69;'	bgcolor='#EAECEB' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>"

		yearConstructed	= true
	}
}

/**
 * 생성된 년도 콤보레이어 숨기기
 */
function popDownYear() {
	clearInterval(intervalID1)
	clearTimeout(timeoutID1)
	clearInterval(intervalID2)
	clearTimeout(timeoutID2)
	crossYearObj.visibility= "hidden"
}

/**
 * 생성된 년도 팝업 보이기
 */
function popUpYear() {
	var	leftOffset;
	constructYear()
	crossYearObj.visibility	= (dom||ie)? "visible" : "show"
	leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft;
	if (ie){
		leftOffset += 6
	}
	crossYearObj.left =	leftOffset + 'px';
	crossYearObj.top = parseInt(crossobj.top) +26 + 'px';
}

/**
 * calendar의 주말찾기 <br />
 * 주말 찾기 알고리즘 참조 : Klaus Tondering's Calendar ���� http://www.tondering.dk/claus/calendar.html
 * <ul>
 * <li>a = (14-month) / 12</li>
 * <li>y = year + 4800 - a</li>
 * <li>m = month + 12a - 3</li>
 * <li>J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045</li>
 * <li>d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461</li>
 * <li>L = d4 / 1460</li>
 * <li>d1 = ((d4 - L) mod 365) + L</li>
 * <li>WeekNumber = d1 / 7 + 1</li>
 * </ul>
 */
function WeekNbr(n) {

	year = n.getFullYear();
	month = n.getMonth() + 1;
	if (startAt == 0) {
		day = n.getDate() + 1;
	}else {
		day = n.getDate();
	}
	a = Math.floor((14-month) / 12);
	y = year + 4800 - a;
	m = month + 12 * a - 3;
	b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
	J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
	d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
	L = Math.floor(d4 / 1460);
	d1 = ((d4 - L) % 365) + L;
	week = Math.floor(d1/7) + 1;

	return week;
}


/**
 * 캘린더 몸체 생성하기
 */
function constructCalendar () {
	var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)

	var dateMessage
	var	startDate =	new	Date (yearSelected,monthSelected,1)
	var endDate

	if (monthSelected==1){
		endDate	= new Date (yearSelected,monthSelected+1,1);
		endDate	= new Date (endDate	- (24*60*60*1000));
		numDaysInMonth = endDate.getDate()
	}else{
		numDaysInMonth = aNumDays[monthSelected];
	}

	datePointer	= 0
	dayPointer = startDate.getDay() - startAt

	if (dayPointer<0){
		dayPointer = 6
	}

	sHTML =	"<table border=0 style='font-family:tahoma;font-size:12px;'><tr>"

	if (showWeekNumber==1){
		sHTML += "<td width=20><b>" + weekString + "</b></td><td width=1 rowspan=7 bgcolor='#d0d0d0' style='padding:0px'><img src='"+imgDir+"cal_divider.gif' width=1></td>"
	}

	for	(i=0; i<7; i++)	{
		sHTML += "<td width=20  valign=middle align=right style='font:normal 12px arial'>"+ dayName[i]+"</td>"
	}
	sHTML +="</tr><tr>"

	if (showWeekNumber==1){
		sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>"
	}

	for	( var i=1; i<=dayPointer;i++ ){
		sHTML += "<td>&nbsp;</td>"
	}

	for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ ) {
		dayPointer++;
		sHTML += "<td align=right>"
		sStyle=styleAnchor
		if ((datePointer==odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
		{ sStyle+=styleLightBorder }

		sHint = ""
		for (k=0;k<HolidaysCounter;k++)
		{
			if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
			{
				if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
				{
					sStyle+="background-color:#FFDDDD;"
					sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
				}
			}
		}

		var regexp= /\"/g
		sHint=sHint.replace(regexp,"&quot;")

		dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "

		if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
		{ sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer+";closeCalendar();'><font style='color:black;font-family:tahoma;font-size:11px'>&nbsp;" + datePointer + "</font></a></b>"}
		else if	(dayPointer % 7 == (startAt * -1)+1)
		{ sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'><font style='color:red;font-family:tahoma;font-size:11px'>" + datePointer + "</font></a>" }
		else if	(dayPointer % 7 == (startAt * -1))
		{ sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'><font style='color:blue;font-family:tahoma;font-size:11px'>" + datePointer + "</font></a>" }
		else
		{ sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();' ><font style='color:#000000;font-family:tahoma;font-size:11px'>" + datePointer + "</font></a>" }

		sHTML += ""
		if ((dayPointer+startAt) % 7 == startAt) {
			sHTML += "</tr><tr>"
			if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
			{
				sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "&nbsp;</td>"
			}
		}
	}

	document.getElementById("contents").innerHTML   = sHTML
	document.getElementById("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"cal_drop.gif' WIDTH='15' HEIGHT='15'  align='absmiddle' BORDER=0>"
	document.getElementById("spanYear").innerHTML =	"&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"cal_drop.gif' WIDTH='15' HEIGHT='15' BORDER=0 align='absmiddle'>"
}

/**
 * 캘린더 팝업시키기
 * @param {ctl} 버튼객체
 * @param {ctl2} 입력결과 뿌려줄 객체
 * @param {format} 캘린더 나타낼형식 yyyy-dd-mm
 */
function popUpCalendar(ctl,	ctl2, format) {
	var	leftpos=0
	var	toppos=0

	if (bPageLoaded){
		if ( crossobj.visibility ==	"hidden" ) {
			ctlToPlaceValue	= ctl2
			dateFormat=format;

			formatChar = " "
			aFormat	= dateFormat.split(formatChar)
			if (aFormat.length<3){
				formatChar = "/"
				aFormat	= dateFormat.split(formatChar)
				if (aFormat.length<3){
					formatChar = "."
					aFormat	= dateFormat.split(formatChar)
					if (aFormat.length<3){
						formatChar = "-"
						aFormat	= dateFormat.split(formatChar)
						if (aFormat.length<3)	{
							// invalid date	format
							formatChar=""
						}
					}
				}
			}

			tokensChanged =	0
			if ( formatChar	!= "" ){
				// use user's date
				aData =	ctl2.value.split(formatChar)

				for	(i=0;i<3;i++) {
					if ((aFormat[i]=="d") || (aFormat[i]=="dd")){
						dateSelected = parseInt(aData[i], 10)
						tokensChanged ++
					} else if	((aFormat[i]=="m") || (aFormat[i]=="mm")) {
						monthSelected =	parseInt(aData[i], 10) - 1
						tokensChanged ++
					}else if	(aFormat[i]=="yyyy"){
						yearSelected = parseInt(aData[i], 10)
						tokensChanged ++
					}else if	(aFormat[i]=="mmm"){
						for	(j=0; j<12;	j++)
						{
							if (aData[i]==monthName[j])
							{
								monthSelected=j
								tokensChanged ++
							}
						}
					}else if	(aFormat[i]=="mmmm"){
						for	(j=0; j<12;	j++){
							if (aData[i]==monthName2[j]){
								monthSelected=j
								tokensChanged ++
							}
						}
					}
				}
			}

			if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected)){
				dateSelected = dateNow
				monthSelected =	monthNow
				yearSelected = yearNow
			}

			odateSelected=dateSelected
			omonthSelected=monthSelected
			oyearSelected=yearSelected

			aTag = ctl

			do {
				aTag = aTag.offsetParent;
				leftpos	+= aTag.offsetLeft;
				toppos += aTag.offsetTop;
		    } while(aTag.tagName!="BODY");    


			var leftPnt = (fixedX==-1) ? parseInt(ctl.offsetLeft	+ leftpos) :  fixedX;
			var topPnt =  (fixedY==-1) ? parseInt(ctl.offsetTop + toppos) + ctl.offsetHeight + 2 : fixedY;

			crossobj.left =	leftPnt +'px';
			crossobj.top = topPnt +'px';


			constructCalendar (1, monthSelected, yearSelected);
			crossobj.visibility=(dom||ie)? "visible" : "show"

			hideElement( 'SELECT', document.getElementById("calendar") );
			hideElement( 'APPLET', document.getElementById("calendar") );

			bShow = true;
		}else{
			hideCalendar()
			if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format)}
		}
		ctlNow = ctl
	}
}

document.onkeypress = function hidecal1 (e) {
	var evt = e || window.event;
	if (evt.keyCode==27){
		hideCalendar()
	}
}
document.onclick = function hidecal2 () {
	if (!bShow){
		hideCalendar()
	}
	bShow = false
}

if(ie){
	init()
}else{
	window.onload=init
}
