var yearSelect;
var monthSelect;
var todayDate;
var calFocus = '';
var calFocus2 = '';
var color_1 = "#CF0000";
var color_2 = "#0867A7";
var color_3 = "#86B20E";
var color_4 = "#66666C";

if (typeof(headerfooter_time_year) != "undefined") { 
	/* ¿À´ÃÀÇ ³¯Â¥¸¦ ¼­¹ö ³¯Â¥·Î ¼³Á¤ */
	todayDate = new Date(
					headerfooter_time_year, headerfooter_time_month - 1,
					headerfooter_time_day, headerfooter_time_hour,
					headerfooter_time_minute, headerfooter_time_second);
}
else
	todayDate = new Date();

function memorialDay(name, month, day, solarLunar, holiday, type) { 
	this.name = name;
	this.month = month;
	this.day = day;
	this.solarLunar = solarLunar;
	this.holiday = holiday;	/* true : »¡°£³¯ false : ¾È»¡°£³¯ */
	this.type = type;	/* true : real time setting */
	this.techneer = true;
}

var memorialDays = Array (
	new memorialDay("½ÅÁ¤", 1, 1, 1, true),
	new memorialDay("", 12, 0, 2, true, true),	/* ½Ç½Ã°£À¸·Î Á¤ÇØÁü */
	new memorialDay("¼³³¯", 1, 1, 2, true),
	new memorialDay("", 1, 2, 2, true),
	new memorialDay("»ïÀÏÀý", 3, 1, 1, true),
	new memorialDay("¼®°¡Åº½ÅÀÏ", 4, 8, 2, true),
	new memorialDay("¾î¸°ÀÌ³¯", 5, 5, 1, true),
	new memorialDay("ÇöÃæÀÏ", 6, 6, 1, true),
	new memorialDay("Á¦ÇåÀý", 7, 17, 1, true),
	new memorialDay("±¤º¹Àý", 8, 15, 1, true),
	new memorialDay("", 8, 14, 2, true),
	new memorialDay("Ãß¼®", 8, 15, 2, true),
	new memorialDay("", 8, 16, 2, true),
	new memorialDay("°³ÃµÀý", 10, 3, 1, true),
	new memorialDay("¼ºÅºÀý", 12, 25, 1, true),

	new memorialDay("Á¤¿ù´ëº¸¸§", 1, 15, 2, false),
	new memorialDay("½Ä¸ñÀÏ", 4, 5, 1, false),
	new memorialDay("´Ü¿À", 5, 5, 2, false),
	new memorialDay("±¹±ºÀÇ³¯", 10, 1, 1, false),
	new memorialDay("ÇÑ±Û³¯", 10, 9, 1, false),
	new memorialDay("625»çº¯ÀÏ", 6, 25, 1, false),
	new memorialDay("»ïÁù³¯", 3, 3, 2, false),
	new memorialDay("¹°ÀÇ³¯", 3, 22, 1, false),
	new memorialDay("¸¸¿ìÀý", 4, 1, 1, false),
	new memorialDay("Àå¾ÖÀÎÀÇ³¯", 4, 20, 1, false),
	new memorialDay("°úÇÐÀÇ³¯", 4, 21, 1 , false),
	new memorialDay("Ãæ¹«°øÅº½ÅÀÏ", 4, 28, 1, false),
	new memorialDay("±Ù·ÎÀÚÀÇ³¯¡¤¹ýÀÇ³¯", 5, 1, 1, false),
	new memorialDay("¾î¹öÀÌ³¯", 5, 8, 1, false),
	new memorialDay("½º½ÂÀÇ³¯", 5, 15, 1, false),
	new memorialDay("¹ß¸íÀÇ³¯", 5, 19, 1, false),
	new memorialDay("¹Ù´ÙÀÇ³¯", 5, 31, 1, false),
	new memorialDay("È¯°æÀÇ³¯", 6, 5, 1, false),
	new memorialDay("À¯µÎ", 6, 15, 2, false),
	new memorialDay("Ä¥¿ùÄ¥¼®", 7, 7, 2, false),
	new memorialDay("Áß¾çÀý", 9, 9, 2, false),
	new memorialDay("Ã¶µµÀÇ³¯", 9, 18, 1, false),
	new memorialDay("¼Ò¹æÀÇ³¯", 11, 9, 1, false)
);

function myDate(year, month, day, leapMonth) { 
	this.year = year;
	this.month = month;
	this.day = day;
	this.leapMonth = leapMonth;
}

// À½·Â µ¥ÀÌÅÍ (Æò´Þ - ÀÛÀº´Þ :1,  Å«´Þ:2 )
// (À±´ÞÀÌ ÀÖ´Â ´Þ - Æò´ÞÀÌ ÀÛ°í À±´Þµµ ÀÛÀ¸¸é :3 , Æò´ÞÀÌ ÀÛ°í À±´ÞÀÌ Å©¸é : 4)
// (À±´ÞÀÌ ÀÖ´Â ´Þ - Æò´ÞÀÌ Å©°í À±´ÞÀÌ ÀÛÀ¸¸é :5,  Æò´Þ°ú À±´ÞÀÌ ¸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 1, 2, 2, 5, 2],
[1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1],
[2, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2],
[2, 2, 1, 2, 1, 4, 1, 1, 2, 2, 1, 2],
[2, 2, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2],
[2, 2, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1],
[2, 2, 1, 2, 5, 2, 1, 2, 1, 2, 1, 1],
[2, 1, 2, 2, 1, 2, 2, 1, 2, 1, 2, 1],
[2, 1, 1, 2, 1, 2, 2, 1, 2, 2, 1, 2],   /* 2041 */
[1, 5, 1, 2, 1, 2, 1, 2, 2, 2, 1, 2],
[1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2]];
/* ¾ç·Â <-> À½·Â º¯È¯ ÇÔ¼ö
 * type : 1 - ¾ç·Â -> À½·Â
 *        2 - À½·Â -> ¾ç·Â
 * leapmonth : 0 - Æò´Þ
 *             1 - À±´Þ (type = 2 ÀÏ¶§¸¸ À¯È¿)
*/ 

function lunarCalc(year, month, day, type, leapmonth) { 
	var solYear, solMonth, solDay;
	var lunYear, lunMonth, lunDay;
	var lunLeapMonth, lunMonthDay;	
	var i, lunIndex;

	var solMonthDay = [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

	/* range check */
	if (year < 1900 || year > 2040)
	{
		alert('2040³â±îÁö¸¸ Áö¿øÇÕ´Ï´Ù');
		return;
	}

	/* ¼Óµµ °³¼±À» À§ÇØ ±âÁØ ÀÏÀÚ¸¦ 2000³âÀ¸·Î */
	if (year >= 2000)
	{
		/* ±âÁØÀÏÀÚ ¾ç·Â 2000³â 1¿ù 1ÀÏ (À½·Â 1999³â 11¿ù 25ÀÏ) */
		solYear = 2000;
		solMonth = 1;
		solDay = 1;
		lunYear = 1999;
		lunMonth = 11;
		lunDay = 25;
		lunLeapMonth = 0;

		solMonthDay[1] = 29;	/* 2000 ³â 2¿ù 28ÀÏ */
		lunMonthDay = 30;	/* 1999³â 11¿ù */
	}

	lunIndex = lunYear - 1899;

	while (true)
	{
//		document.write(solYear + "-" + solMonth + "-" + solDay + "<->");
//		document.write(lunYear + "-" + lunMonth + "-" + lunDay + " " + lunLeapMonth + " " + lunMonthDay + "<br>");

		if (type == 1 &&
			year == solYear &&
			month == solMonth &&
			day == solDay)
		{
			return new myDate(lunYear, lunMonth, lunDay, lunLeapMonth);
		}	
		else if (type == 2 &&
				year == lunYear &&
				month == lunMonth &&
				day == lunDay && 
				leapmonth == lunLeapMonth)
		{
			return new myDate(solYear, solMonth, solDay, 0);
		}

		/* add a day of solar calendar */
		if (solMonth == 12 && solDay == 31)
		{
			solYear++;
			solMonth = 1;
			solDay = 1;

			/* set monthDay of Feb */
			if (solYear % 400 == 0)
				solMonthDay[1] = 29;
			else if (solYear % 100 == 0)
				solMonthDay[1] = 28;
			else if (solYear % 4 == 0)
				solMonthDay[1] = 29;
			else
				solMonthDay[1] = 28;

		}
		else if (solMonthDay[solMonth - 1] == solDay)
		{
			solMonth++;
			solDay = 1;	
		}
		else
			solDay++;

		/* add a day of lunar calendar */
		if (lunMonth == 12 &&
			((lunarMonthTable[lunIndex][lunMonth - 1] == 1 && lunDay == 29) ||
			(lunarMonthTable[lunIndex][lunMonth - 1] == 2 && lunDay == 30)))
		{
			lunYear++;
			lunMonth = 1;
			lunDay = 1;

			if (lunYear > 2043) {
				alert("ÀÔ·ÂÇÏ½Å ´ÞÀº ¾ø½À´Ï´Ù.");
				break;
			}

			lunIndex = lunYear - 1899;

			if (lunarMonthTable[lunIndex][lunMonth - 1] == 1)
				lunMonthDay = 29;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 2)
				lunMonthDay = 30;
		}
		else if (lunDay == lunMonthDay)
		{
			if (lunarMonthTable[lunIndex][lunMonth - 1] >= 3
				&& lunLeapMonth == 0)
			{
				lunDay = 1;
				lunLeapMonth = 1;
			}
			else
			{
				lunMonth++;
				lunDay = 1;
				lunLeapMonth = 0;
			}

			if (lunarMonthTable[lunIndex][lunMonth - 1] == 1)
				lunMonthDay = 29;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 2)
				lunMonthDay = 30;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 3)
				lunMonthDay = 29;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 4 &&
					lunLeapMonth == 0)
				lunMonthDay = 29;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 4 &&
					lunLeapMonth == 1)
				lunMonthDay = 30;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 5 &&
					lunLeapMonth == 0)
				lunMonthDay = 30;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 5 &&
					lunLeapMonth == 1)
					lunMonthDay = 29;
			else if (lunarMonthTable[lunIndex][lunMonth - 1] == 6)
				lunMonthDay = 30;
		}
		else
			lunDay++;
	}
}

function getWeekday(year, month, day) { 

	var weekday = Array("ÀÏ", "¿ù", "È­", "¼ö", "¸ñ", "±Ý", "Åä");
	var date = new Date(year, month - 1, day);

	if (date)
		return weekday[date.getDay()];
}

function getPassDay(year, month, day) { 
	var date = new Date(year, month - 1, day);

	var interval = Math.floor((todayDate - date) / (1000 * 60 * 60 * 24) + 1);

	return interval;
}

function getDDay(year, month, day) { 
	var date = new Date(year, month - 1, day);

	var interval = Math.floor((date - todayDate) / (1000 * 60 * 60 * 24) + 1);

	return interval;
}

function getDateSpecificInterval(year, month, day, interval) { 
	var date = new Date(year, month - 1, parseInt(day, 10) + parseInt(interval, 10) - 1);

	return date;
}

function dayCalcDisplay(type) { 
	switch (type) {
		/* ¿À´ÃÀº ¸îÀÏÂ° */
		case 1:
			var startYear = parseInt(document.getElementById("mStartYear").value, 10);
			var startMonth = parseInt(document.getElementById("mStartMonth").value, 10);
			var startDay = parseInt(document.getElementById("mStartDay").value, 10);
			break;

		/* x ÀÏÂ° µÇ´Â³¯ */
		case 2:
			var startYear = parseInt(document.getElementById("mmStartYear").value, 10);
			var startMonth = parseInt(document.getElementById("mmStartMonth").value, 10);
			var startDay = parseInt(document.getElementById("mmStartDay").value, 10);
			break;

		/* D-day */
		case 3:	
			var startYear = parseInt(document.getElementById("targetYear").value, 10);
			var startMonth = parseInt(document.getElementById("targetMonth").value, 10);
			var startDay = parseInt(document.getElementById("targetDay").value, 10);
			break;
			
		/* ¿äÀÏ °è»ê */			
		case 4:	
			var startYear = parseInt(document.getElementById("weekdayYear").value, 10);
			var startMonth = parseInt(document.getElementById("weekdayMonth").value, 10);
			var startDay = parseInt(document.getElementById("weekdayDay").value, 10);
			break;

		/* ¾ç·Â À½·Â º¯È¯ */			
		case 5:
			var startYear = parseInt(document.getElementById("lsStartYear").value, 10);
			var startMonth = parseInt(document.getElementById("lsStartMonth").value, 10);
			var startDay = parseInt(document.getElementById("lsStartDay").value, 10);
			break;
	}
	
	
	if ( !startYear || startYear == 0 ||
		 !startMonth || startMonth == 0 ||
		 !startDay || startDay == 0 )
	{
		alert('³¯Â¥¸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä');
		return;
	}

	var solMonthDay = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

	if (startYear % 400 == 0 || ( startYear % 4 == 0 && startYear % 100 != 0 )) solMonthDay[1] += 1;


	if ( startMonth < 1 || startMonth > 12 ||
		 startDay < 1 || startDay > solMonthDay[startMonth-1] ) {
		if ( solMonthDay[1] == 28 && startMonth == 2 && startDay > 28 ) 
			alert("À±³âÀÌ ¾Æ´Õ´Ï´Ù. ´Ù½Ã ÀÔ·ÂÇØÁÖ¼¼¿ä");
		else
			alert("³¯Â¥ ¹üÀ§¸¦ ¹þ¾î³µ½À´Ï´Ù. ´Ù½Ã ÀÔ·ÂÇØÁÖ¼¼¿ä");
		return;
	}

	var startDate = new Date(startYear, startMonth - 1, startDay);
	var today = new Date(todayDate.getFullYear(),
						todayDate.getMonth(), todayDate.getDate());

	switch (type)
	{
	/* ¿À´ÃÀº ¸îÀÏÂ° */
	case 1:
		if (today < startDate)
		{
			alert("±âÁØÀÏÀ» ¿À´Ãº¸´Ù ÀÌÀü ³¯Â¥·Î ¼³Á¤ÇÏ¼¼¿ä");
			return;
		}

		var interval = getPassDay(startYear, startMonth, startDay);

		document.getElementById("day1").value = interval;
		break;
	/* x ÀÏ µÇ´Â ³¯Àº */
	case 2:
		/*	
		if (today < startDate)
		{
			alert("±âÁØÀÏÀ» ¿À´Ã ÀÌÀü ³¯Â¥·Î ¼³Á¤ÇÏ¼¼¿ä");
			return;
		}
		*/

		var day2 = document.getElementById("day2").value;

		if (day2 <= 0)
		{
			alert("0 º¸´Ù Å« ¼ö¸¦ ÀÔ·ÂÇÏ¼¼¿ä");
			return;
		}

		var date = getDateSpecificInterval(startYear, startMonth, startDay, day2);

		document.getElementById("resultDay").value = 
			String(date.getFullYear()) + "³â " + 
			String(date.getMonth() +1 ) + "¿ù " + 
			String(date.getDate()) + "ÀÏ";

		break;	
	/* D-Day */
	case 3:
		
		var interval = getDDay(startYear, startMonth, startDay);

		if (today > startDate)
		{
			alert("±âÁØÀÏÀ» ¿À´Ã ÀÌÈÄ ³¯Â¥·Î ¼³Á¤ÇÏ¼¼¿ä");
			return;
		}

		document.getElementById("day3").value = interval;

		break;

	/* ¿äÀÏ °è»ê */
	case 4:
		if (startYear < 100)
		{
			alert('³âµµ¸¦ 100³â ÀÌÈÄ·Î ÀÔ·ÂÇØ ÁÖ¼¼¿ä');
			return;
		}
		weekday.value = getWeekday(startYear, startMonth, startDay) + "¿äÀÏ";

		break;

	/* ¾ç·Â/À½·Â º¯È¯ */
	case 5:
		if (document.getElementById('solarLunar').value == 'solar')
		{
			var leapMonth = document.getElementById('leapMonth').checked;
			var date = lunarCalc(startYear, startMonth, startDay, 2, leapMonth);
		}
		else
		{
			var date = lunarCalc(startYear, startMonth, startDay, 1);
		}

		if (date)
		{
			document.getElementById('solarLunarDay').value = 
				date.year + "³â " + 
				(date.leapMonth ? "À±" : "") + date.month + "¿ù " +
				date.day + "ÀÏ ";

		}
		else
		{
			document.getElementById('solarLunarDay').value = "";
		}

		break;
	}
}

function memorialDayCheck(solarDate, lunarDate) { 
	var i;
	var memorial;


	for (i = 0;i < memorialDays.length;i++)
	{
		if (memorialDays[i].month == solarDate.month &&
			memorialDays[i].day == solarDate.day &&
			memorialDays[i].solarLunar == 1)
			return memorialDays[i];

		if (memorialDays[i].month == lunarDate.month &&
			memorialDays[i].day == lunarDate.day &&
			memorialDays[i].solarLunar == 2 &&
			!memorialDays[i].leapMonth)
			return memorialDays[i];
	}

	return null;
}

/*


function setStartDate(year, month, day) { 
	document.getElementById('startYear').value = year;
	document.getElementById('startMonth').value = month;
	document.getElementById('startDay').value = day;
}
*/

function setCalendar(year, month) { 
	var i;
	var oYearSelect = document.getElementById('yearSelect');
	var oMonthSelect = document.getElementById('monthSelect');

	if (!year)
	{
		year = oYearSelect.value;
		month = oMonthSelect.value;
	}
	else
	{
		for (i = 0;i < oYearSelect.length;i++)
			if (oYearSelect[i].value == year)
			{
				oYearSelect.selectedIndex = i;
				break;
			}
	
		for (i = 0;i < oMonthSelect.length;i++)
			if (oMonthSelect[i].value == month)
			{
				oMonthSelect.selectedIndex = i;
				break;
			}
	}

	var monthDay = Array(31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var wwck = "";

	/* set monthDay of Feb */
	if (year % 400 == 0)
		monthDay[1] = 29;
	else if (year % 100 == 0)
		monthDay[1] = 28;
	else if (year % 4 == 0)
		monthDay[1] = 29;
	else
		monthDay[1] = 28;


	/* set the day before ¼³³¯ */
	if (lunarMonthTable[year - 1 - 1899][11] == 1)
		memorialDays[1].day = 29;
	else if (lunarMonthTable[year - 1 - 1899][11] == 2)
		memorialDays[1].day = 30;

	var date = new Date(year, month - 1, 1);
	var startWeekday = date.getDay();

	/* clean all day cell */
	for (i = 0;i < 42;i++)
	{
		document.getElementById('dayCell' + i).innerHTML = "";
//		document.getElementById('memoCell' + i).innerHTML = "";
	}

	/* fill day cell */		
	for (i = 0;i < monthDay[month - 1];i ++)
	{
		var index = startWeekday + i;
		var dayHTML;
		var memoHTML;

		var solarDate = new myDate(year, month, i + 1);
		var lunarDate = lunarCalc(year, month, i + 1, 1);

		/* memorial day */
		var memorial = memorialDayCheck(solarDate, lunarDate);

		/* ½¬Áö¾Ê´Â ±â³äÀÏ */
		var memorialDay = false;
		if (memorial && memorial.holiday == false)
			memorialDay = true;

		if (memorial && memorial.holiday == true) {
			wwck = 0;
		} else {
			wwck = index % 7;
		}

		/* day print */
		dayHTML = "<table width='18' border='0' cellpadding='0' cellspacing='0'><tr><td align='center' onClick='calinput("+(i+1)+","+index+","+(wwck)+");' style='cursor:pointer;'><a href='javascript:'><font color='COLOR' title='TITLE'>HIGHLIGHT_START" +
		    ( i + 1 ) + "HIGHLIGHT_END</font></a></td></tr></table>";

		/* decoration */
		if ((memorial && memorial.holiday) || wwck == 0)
			dayHTML = dayHTML.replace("COLOR", color_1);
		else if (wwck == 6)
			dayHTML = dayHTML.replace("COLOR", color_2);
		else
			dayHTML = dayHTML.replace("COLOR", color_4);

		if (memorial)
			dayHTML = dayHTML.replace("TITLE", memorial.name);

		if (todayDate.getFullYear() == year &&
			todayDate.getMonth() + 1 == month &&
			todayDate.getDate() == i + 1)
		{
			dayHTML = dayHTML.replace(color_1, color_3);
			dayHTML = dayHTML.replace(color_2, color_3);
			dayHTML = dayHTML.replace(color_4, color_3);
			dayHTML = "<table width='18' border='1' bordercolor='#F96D19' cellpadding='0' cellspacing='0'><tr><td align='center' onClick='calinput("+(i+1)+","+index+","+(wwck)+");' style='cursor:pointer;'><a href='javascript:'><font color='COLOR' title='TITLE'>HIGHLIGHT_START" +
		    ( i + 1 ) + "HIGHLIGHT_END</font></a></td></tr></table>";
			calFocus = index;
			calFocus2 = (wwck);
		}

		dayHTML = dayHTML.replace("TITLE", "");	
		dayHTML = dayHTML.replace("COLOR", "");
		dayHTML = dayHTML.replace("HIGHLIGHT_START", "");
		dayHTML = dayHTML.replace("HIGHLIGHT_END", "");


		document.getElementById('dayCell' + index).innerHTML = dayHTML;


		/* lunar calnedar print */
/*		if (lunarDate.day == 1 || lunarDate.day == 15)
		{
			memoHTML = "<img src=/common/visualphone/images/" + (lunarDate.month < 10 ? "0" + lunarDate.month : lunarDate.month) + (lunarDate.day < 10 ? "0" + lunarDate.day: lunarDate.day) + ".gif border=0>";

		}
		else
			memoHTML = "<table border=0 cellpadding=0 cellspacing=0><tr height=8><td></td><tr></table>";

		document.getElementById('memoCell' + index).innerHTML = memoHTML;*/
	}
}

function lunarMonthCheck() { 
	if (document.getElementById('solarLunar').value == "solar") 
		document.getElementById('leapMonth').disabled = false;
	else
		document.getElementById('leapMonth').disabled = true;
}

var ayear = todayDate.getFullYear(), amonth = todayDate.getMonth() + 1;

function noAlpha(e) { 
    	if (e.keyCode < 48 || e.keyCode > 57)
	    e.returnValue = false;
}




//ºñÁÖ¾óÆù ´Þ·Â¿¡¼­ ¿¹¾à ³â,¿ù,ÀÏ ¼³Á¤
function calinput(aaa,bbb,ccc){
	var yy = document.calform.cal_year.value;
	var mm = document.calform.cal_month.value;
	var dd = aaa;
	document.VisualPhone.yy.value = yy;
	if(mm>=10){
	document.VisualPhone.mm.value = mm;
	}
	else{
	document.VisualPhone.mm.value = "0"+mm;
	}
	if(dd>=10){
	document.VisualPhone.dd.value = dd;
	}
	else{
	document.VisualPhone.dd.value = "0"+dd;
	}

	var ccc1 = ""
	if (ccc==0) {
		ccc1 = color_1;
	} else if (ccc==6) {
		ccc1 = color_2;
	} else {
		ccc1 = color_4;
	}
	if (calFocus2==0) {
		ccc2 = color_1;
	} else if (calFocus2==6) {
		ccc2 = color_2;
	} else {
		ccc2 = color_4;
	}
	document.getElementById('dayCell' + calFocus).innerHTML = document.getElementById('dayCell' + calFocus).innerHTML.replace('<B>','').replace('</B>','').replace(color_3,ccc2);
	document.getElementById('dayCell' + bbb).innerHTML = document.getElementById('dayCell' + bbb).innerHTML.replace('<FONT ','<B><FONT ').replace('</FONT>','</FONT></B>').replace(ccc1,color_3);
	calFocus = bbb;
	calFocus2 = ccc;
	document.VisualPhone.h.select();
}

