//----------------------------------------------------------------------------
// File Modifications:
// CC1	10/16/2004	Colin Chong	Cookie name comparison to be case insensitive 
//----------------------------------------------------------------------------

function getCookie(sName)
{
	// cookies are separated by semicolons
	var sCookieName = String(sName).toLowerCase();
	var oCookie = document.cookie.split(";");
	for (var i=0; i < oCookie.length; i++)
	{
		// a crumb (name/value pair) is separated by an equal sign
		var aCrumb = oCookie[i].split("=");
		if (sCookieName == trim(aCrumb[0]).toLowerCase() && unescape(aCrumb[1])!='') // ** CC1 case insensitivity **
			return unescape(aCrumb[1]);
	}
	// a cookie with the requested name does not exist
	return null;
}

function setCookie(sName, sValue, sPath)
{
  document.cookie = sName + "=" + escape(sValue)
  								+ "; path=" + (((typeof(sPath) != 'undefined') && (sPath.length>0)) ? sPath : "/") + ";";
}

function clearAllCookie(arNoClearList)
{
	var bClear = true;
	var bCheckClearList= false;
	var aCrumb;
	if( (typeof(arNoClearList)!='undefined') && (arNoClearList.length>0) )
		bCheckClearList = true;
	var oCookie = document.cookie.split(";");
	for (var i=0; i < oCookie.length; i++)
	{
		bClear = true;
		aCrumb = oCookie[i].split("=");
		if( bCheckClearList )
			bClear = !InList(trim(aCrumb[0]),arNoClearList);
		if( bClear )
				clearCookie(trim(aCrumb[0]));
	}
}

function clearCookie(sName)
{
  document.cookie = sName + "=''; expires=Fri, 31 Dec 1999 23:59:59 GMT;path=/";
}

function trim(s)
{
	var d = String(s); 
	if (!d.length) return "";
	var i_begin = 0, i_end = d.length - 1;
	while (i_begin < i_end && d.charAt(i_begin) == " ") i_begin++;
	while (i_begin <= i_end && d.charAt(i_end) == " ") i_end--;

	return d.substr(i_begin, i_end + 1 - i_begin);
}
///////////////////////////////////////////////////////////////////
function getServerTime()
{
	var s = getCookie("CurRunningTime");
	return (s == null ? -1 : s)
}
		
function setSSFlag(iV)
{
	var iInterval = 2*60000;
	if (iV == 1)
		setCookie("SSFlag",1);
	
	window.setTimeout("setSSFlag(1)", iInterval);
}

//-------------------------------------------------
function getAllCookiesInfo()
{
	var sCookies='';
	// cookies are separated by semicolons
	var oCookie = document.cookie.split(";");
	var nCookie=0;
	var iCookie=0;
	for(iCookie=0; iCookie < oCookie.length; iCookie++)
		sCookies += ' [' + (iCookie+1) + ']' + oCookie[iCookie];
	return sCookies;
}

//--------------------------------------------------
function InList(sName,arList)
{
	var iList;
	var bInList = false;
	if( arList.length > 0 )
	{
		for(iList=0; iList < arList.length; iList++ )
		{
			if( arList[iList] == sName )
			{
				bInList = true;
				break;
			}
		} 
	}
	return bInList;
}

function getHost()  // 04/03/09 Mercado added 
{
	var sPath=window.location.href;
	var nPos=sPath.indexOf("//");
	if(nPos>0)
	{
		var nPosx=sPath.indexOf("/",nPos+2);
		if(nPosx>0)
			return sPath.substring(0,nPosx);
		else
			return sPath;
	}
	return sPath;
}


