// JScript source code
//////////´Þ·Â°ü·Â½ÃÀÛ///////////////
var tmpObj;
var tmpCount = 0;

var tmpYear = 0;
var tmpMonth = 0;
var tmpDate = 0;

function SelectedDate(obj)
{
	if(obj.innerText == '')
	{
		return(false);
	}
	/*
	tmpCount++;

	if(tmpCount > 1)
	{
		if(tmpObj.className == "SunDay")
		{
			tmpObj.style.color = "#1590CA";
		}
		else
		{
			tmpObj.style.color = "#7D7D7D";
		}

		tmpObj.style.backgroundColor = "white";
	}

	obj.style.color = "white";
	obj.style.backgroundColor = "#99acc6";
	*/
	tmpObj = obj;
	tmpDate = Math.abs(obj.innerText);
	
	var DMonth;
	var DDay;
	var strMonth=document.all.item("select_month").value;
	var k=strMonth.indexOf("¿ù");
	if(strMonth.indexOf("¿ù")>0)
	{
		strMonth=strMonth.substr(0,k);
	}
	if(strMonth.length == 1)
	{
		DMonth = "0" + strMonth;
	}
	else
	{
		DMonth = strMonth;
	}
	
	if(obj.innerText.length == 1)
	{
		DDay = "0" + obj.innerText
	}
	else
	{
		DDay = obj.innerText
	}
	
	var DDate = document.all.item("select_year").value + DMonth + DDay;
	//ÀÌºÎºÐ °íÃÄ¼­ ¸µÅ©½ÃÅ°¸é µÊ.
	//alert("UI/DailyBook/DiaryReg.aspx?dt=" + DDate);				
	//parent.Body.location.href = "UI/DailyBook/DiaryReg.aspx?dt=" + DDate;
	document.location.href = "EventsGuide/SpringEvents.asp";	
}

function SetToday(obj)
{
	if(obj.innerText == '')
	{
		return(false);
	}

	/*tmpCount++;

	if(tmpCount > 1)
	{
		if(tmpObj.className == "SunDay")
		{
			tmpObj.style.color = "#1590CA";
		}
		else
		{
			tmpObj.style.color = "#7D7D7D";
		}

		tmpObj.style.backgroundColor = "white";
	}*/

	obj.style.color = "white";
	obj.style.backgroundColor = "#99acc6";

	tmpObj = obj;
	tmpDate = Math.abs(obj.innerText);
}

function dateSetting()
{
	var date = new Date();
	var mon = date.getMonth();
	var week = date.getDay();
	var today = date.getDate();
	var year = date.getYear();

	var monthLen = setMonthLen(year, mon);
	var firstDay = (new Date(year, mon, 1)).getDay();
	var count = 0;
	var daycount = 0;

	for(var i=1;i<7;i++)
	{
		for(var j=1;j<8;j++)
		{
			if(count < firstDay)
			{
				count++;
			}
			else if(count - firstDay < monthLen)
			{
				daycount++;
				
					document.all.item(i+"_"+j).innerText = daycount;
				count++;
				if(daycount == today)
					//document.all.item(i+"_"+j).click();
					SetToday(document.all.item(i+"_"+j))
			}
		}
	}

	document.all.item("select_year").value = year;
	document.all.item("select_month").value = (mon + 1);
	tmpYear = year;
	tmpMonth = mon;
	tmpDate = today;
}

function setMonthLen(year, mon)
{
	var tmpDate = new Date(year, mon + 1, 1);
	var tmpSec = tmpDate.getTime() - (1000 * 60 * 60 * 24);
	tmpDate = new Date(tmpSec);
	return tmpDate.getDate();
}

function changeMonth(selected_month)
{
	var dayClick = false;
	var year = tmpYear;
	var mon = tmpMonth;
	
	mon = Math.abs(selected_month.value) - 1;

	var monthLen = setMonthLen(year, mon);
	var firstDay = (new Date(year, mon, 1)).getDay();
	var count = 0;
	var daycount = 0;

	var to_date = new Date();
	var to_mon = to_date.getMonth();
	var to_week = to_date.getDay();
	var today = to_date.getDate();
	var to_year = to_date.getYear();
	
	for(var i=1;i<7;i++)
	{
		for(var j=1;j<8;j++)
		{
			if(count < firstDay)
			{
				count++;
				document.all.item(i+"_"+j).innerText = "";							
			}
			else if(count - firstDay < monthLen)
			{
				daycount++;
				document.all.item(i+"_"+j).innerText = daycount;
				if(daycount == tmpDate)
				{
						document.all.item(i+"_"+j).click();
						dayClick= !dayClick;
				}
				else if(count - firstDay == monthLen - 1 && !dayClick)
				{
					document.all.item(i+"_"+j).click();
				}

				count++;							
			}
			else
			{
				document.all.item(i+"_"+j).innerText = "";
			}
			///ÇöÀç ³¯Â¥ Ç¥½Ã
			if(daycount == today&&year==to_year&&mon==to_mon)
				SetToday(document.all.item(i+"_"+j))
			else 
			{							
				document.all.item(i+"_"+j).style.color = "";							
				document.all.item(i+"_"+j).style.backgroundColor = "";
			}
			
		}//for
	}//for

	document.all.item("select_year").value = year;
	document.all.item("select_month").value = (mon + 1);
	tmpYear = year;
	tmpMonth = mon;
}

function changeYear(selected_year)
{
	var dayClick = false;
	var year = tmpYear;
	var mon = tmpMonth;

	year=Math.abs(selected_year.value);

	var monthLen = setMonthLen(year, mon);
	var firstDay = (new Date(year, mon, 1)).getDay();
	var count = 0;
	var daycount = 0;
	
	var to_date = new Date();
	var to_mon = to_date.getMonth();
	var to_week = to_date.getDay();
	var today = to_date.getDate();
	var to_year = to_date.getYear();
	for(var i=1;i<7;i++)
	{
		for(var j=1;j<8;j++)
		{
			if(count < firstDay)
			{
				count++;
				document.all.item(i+"_"+j).innerText = "";
			}
			else if(count - firstDay < monthLen)
			{
				daycount++;
				document.all.item(i+"_"+j).innerText = daycount;

				if(daycount == tmpDate)
				{
					document.all.item(i+"_"+j).click();
						dayClick= !dayClick;
				}
				else if(count - firstDay == monthLen - 1 && !dayClick)
				{
					document.all.item(i+"_"+j).click();
				}
				count++;
			}
			else
			{
				document.all.item(i+"_"+j).innerText = "";
			}
			///ÇöÀç ³¯Â¥ Ç¥½Ã
			if(daycount == today&&year==to_year&&mon==to_mon)
				SetToday(document.all.item(i+"_"+j))
			else 
			{							
				document.all.item(i+"_"+j).style.color = "";							
				document.all.item(i+"_"+j).style.backgroundColor = "";
			}
		}
	}

	document.all.item("select_year").value = year;
	document.all.item("select_month").value = (mon + 1);
	tmpYear = year;
	tmpMonth = mon;
}
/////////´Þ·Â°ü·Ã ³¡//////////////
/////////ÄíÅ°°ü·Ã ½ÃÀÛ/////////////
function delCookie_All(reHref)
{	
	if (document.cookie != "") 
	{ 
		this_Cookie = document.cookie.split("; ") 
		expire_Date = new Date 
		expire_Date.setDate(expire_Date.getDate()-1) 
		for (i=0; i<this_Cookie.length; i++) 
		{ 
			cookie_Name = this_Cookie[i] + "\n";
		} 
		
		thisCookie = document.cookie.split("; ") 
		expireDate = new Date 
		expireDate.setDate(expireDate.getDate()-1) 
		
		for (i=0; i<thisCookie.length; i++) { 
			cookieName = thisCookie[i].split("=")[0] 
			document.cookie = cookieName + "=;expires=" + expireDate.toGMTString() + "; path=/";
		} 
		if(reHref !="")
		{
		document.location.href =reHref;
		}
	} 
}

function setCookie(name, value, expires) {
document.cookie = name + "=" + escape (value) +
	"; path=/; expires=" + expires.toGMTString();
}

function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) { // ÄíÅ°°¡ ¼³Á¤µÇ¾î ÀÖ´Ù¸é
	offset = document.cookie.indexOf(search)
	if (offset != -1) { 
	offset += search.length
	end = document.cookie.indexOf(";", offset)
	
	if (end == -1)
		end = document.cookie.length
	return unescape(document.cookie.substring(offset, end))
	}
}
return "";
}
/////ÄíÅ°°ü·Ã ³¡////
function IsLogIN()
{
	var user_id= getCookie("uid");
	if(user_id =="")
		document.location.href ="index.asp";
}
///¿ìÆí¹øÈ£ popup////
function Pop_Zipcode()
{
window.open('../Resource/zipcode.asp','popup','resizable=no,scrollbars=yes,width=320,height=450,menubar=no, left=' + (screen.availWidth-500) / 2 + ', top=' + (screen.availHeight-500) / 2 + ', status=no'); 
document.m_Reg.Haddr.focus();
}

function Pop_OZipcode()
{
window.open('../Resource/ozipcode.asp','popup','resizable=no,scrollbars=yes,width=320,height=450,menubar=no, left=' + (screen.availWidth-500) / 2 + ', top=' + (screen.availHeight-500) / 2 + ', status=no'); 
document.m_Reg.Oaddr.focus();
}
