function F_LTrim(str) 
{ 
	var s = new String(str); 

	if (s.substr(0,1) == " ") 
		return F_LTrim(s.substr(1)); 
	else 
		return s; 
} 

function F_RTrim(str) 
{ 
	var s = new String(str); 
	if(s.substr(s.length-1,1) == " ") 
		return F_RTrim(s.substring(0, s.length-1)) 
	else 
		return s; 
} 

function F_Trim(str) 
{ 
	return F_LTrim(F_RTrim(str)); 
}

function F_GetRealCookie(name)
{
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length )
	{
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
			if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
			
		x = document.cookie.indexOf( " ", x ) + 1;
			
		if ( x == 0 ) break;
	}
			return "";
}

function F_GetCookie(name)
{
	var strCookie = F_GetRealCookie("netmarble_popup", false);

	if(strCookie == "") return "";

	var nPos = strCookie.indexOf(name+":");
	var nLen = name.length + 1;
	var strTempName, strTempCookie;

	if(nPos != -1)
	{
		strTempName = strCookie.substring(nPos, nLen);
		strTempCookie = strCookie.substring(nPos+nLen, strCookie.length);
		nPos = strTempCookie.indexOf("|");

		return unescape(strTempCookie.substring(0, nPos));
	}
	else
		return "";
}

function F_SetCookie(name, value)
{
	if(F_Trim(name) == "" || name == null) return;

	var strCookie = F_GetRealCookie("netmarble_popup", false);
	var nPos = strCookie.indexOf(name+":");
	var nLen = name.length + 1;
	var strTemp1, strTemp2;

	if(F_Trim(value) == "" || value == null)
	{
		strTemp1 = strCookie.substring(0, nPos);
		strTemp2 = strCookie.substring(nPos+nLen, strCookie.length);
		nPos = strTemp2.indexOf("|") + 1;
		strTemp2 = strTemp2.substring(nPos, strCookie.length);		
		strCookie = strTemp1 + strTemp2;		
	}
	else
	{
		if(nPos != -1)
		{
			strTemp1 = strCookie.substring(0, nPos+nLen);
			strTemp2 = strCookie.substring(nPos+nLen, strCookie.length);
			nPos = strTemp2.indexOf("|");
			strTemp2 = strTemp2.substring(nPos, strCookie.length);

			strCookie = strTemp1 + escape(escape(value)) +strTemp2;
		}
		else
			strCookie = strCookie + name + ":" + escape(escape(value)) + "|";
	}

	var todayDate = new Date(); 
	todayDate.setHours(8);
	todayDate.setMinutes(59);
	todayDate.setSeconds(59);
	todayDate.setDate( todayDate.getDate() + 1 ); 

	document.cookie = "netmarble_popup=" + strCookie + "; path=/; expires=" + todayDate.toGMTString() + ";" 
}
