// Cookie Class [Side : Client]
// Author : kang byoung jun
// All rights reserved.
//////////////////////////////////////////////////////////////////////
function _Cookie()
{
	// Each cookie is stored in a name=value pair
	// Properties
	// protected
	this.m_Name = new Array();
	this.m_Value = new Array();
	this.m_Path = "/";
	this.m_Domain = "";
	this.m_Expires = "";
	this.m_Count = 0;

	// Method
	// public
	this.AddInformation = _CK_AddInformation;
	this.FindName = _CK_FindName;
	this.SetExpireDate = _CK_SetExpireDate;
	this.SetExpireDateEx = _CK_SetExpireDateEx;
	this.SetDomain = _CK_SetDomain;
	this.SetPath = _CK_SetPath;
	this.Read = _CK_Read;
	this.Write = _CK_Write;
	this.Close = _CK_Close;
	// protected
	this.FindNameIndex = _CK_FindNameIndex;
	this.GetName = _CK_GetName;
	this.GetValue = _CK_GetValue;
}
function _CK_AddInformation(strName,Value)
{
	if(strName=="" || Value=="")
		return false;
	if(this.FindNameIndex(strName)<0)
	{
		this.m_Name[this.m_Count] = strName;
		this.m_Value[this.m_Count] = escape(Value);
		this.m_Count++;
		return true;
	}
	return false;
}
function _CK_GetName(nIndex)
{
	if(nIndex<0 || nIndex>this.m_Count)
		return "";
	return this.m_Name[nIndex];
}
function _CK_GetValue(nIndex)
{
	if(nIndex<0 || nIndex>this.m_Count)
		return "";
	return unescape(this.m_Value[nIndex]);
}
function _CK_FindNameIndex(strName)
{
	var nRIndex = -1; // NoFind
	for(var nIndex=0; nIndex<this.m_Count; nIndex++)
	{
		if(this.m_Name[nIndex] == strName) // ´ë/¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÑ´Ù.
		{
			nRIndex = nIndex; // Find
			break;
		}
	}
	return nRIndex;
}
function _CK_FindName(strName)
{
	var nIndex = this.FindNameIndex(strName);
	if(nIndex<0)
		return "";
	return this.GetValue(nIndex);
}
function _CK_SetExpireDate(nDays)
{
	var ToDay = new Date();
	ToDay.setDate(ToDay.getDate() + nDays);
	this.m_Expires = ToDay.toGMTString();
	delete ToDay;
}
function _CK_SetExpireDateEx(objDate)
{
	var ToDay = new Date();
	if(ToDay > objDate)
		this.m_Expires = ToDay.toGMTString();
	else
		this.m_Expires = objDate.toGMTString();
	delete ToDay;
}
function _CK_SetDomain(strDomain)
{
	this.m_Domain=strDomain;
}
function _CK_SetPath(strPath)
{
	this.m_Path = strPath;
}
function _CK_Read()
{
	var strItem="", ItemName="", ItemValue="", nSPos=0;
	var strBuffer = document.cookie + ";";
	var nStartPos=0, nCurrentPos=0;
	while((nCurrentPos=strBuffer.indexOf(";",nStartPos))>0)
	{
		strItem=strBuffer.substring(nStartPos,nCurrentPos);
		nSPos = strItem.indexOf("=",-1);
		if(nSPos>0)
		{
			ItemName = strItem.substring(0,nSPos);
			ItemValue = strItem.substring(nSPos+1,strItem.length);
			this.AddInformation(ItemName,ItemValue);
		}
		nStartPos = nCurrentPos + 1;
		nStartPos = strBuffer.indexOf(" ",nStartPos) + 1; // ±¸ºÐ¹®ÀÚ(°ø¹é)À» Æ÷ÇÔÇÑ´Ù.
		if(nStartPos==0)
			break;
	}
}
function _CK_Write()
{
	for(var nIndex=0; nIndex<this.m_Count; nIndex++)
	{
		var strBuffer = this.m_Name[nIndex] + "=" + this.m_Value[nIndex] + ";";
		strBuffer += " expires=" + this.m_Expires + ";"; // requisite
		if(this.m_Domain!="")
			strBuffer += " domain=" + this.m_Domain + ";";
		strBuffer += " path=" + this.m_Path + ";"; // requisite
		document.cookie = strBuffer;
	}
}
function _CK_Close()
{
	delete this.m_Name;
	delete this.m_Value;
	return true;
}
//////////////////////////////////////////////////////////////////////
