/************************************************** 
参数说明： 
sMainName Cookie名 
sSubName Cookie子键名，留空表示单值Cookie 
**************************************************/ 
function GetCookie(sMainName,sSubName)
{ 
	var sCookieName = sMainName + "=";
	var sSubCookieName = (sSubName) ? sSubName + "=" : null;
	var sCookie;
	var sWholeCookie = document.cookie;
	var nValueBegin = sWholeCookie.indexOf(sCookieName);
	if(nValueBegin != -1)
	{
		var nValueEnd = sWholeCookie.indexOf( "; ", nValueBegin);
		if (nValueEnd == -1)
			nValueEnd = sWholeCookie.length;
		var sValue = sWholeCookie.substring(nValueBegin + sCookieName.length, nValueEnd); //获得Cookie值
		
		if(sSubCookieName) //多值Cookie
		{
			nSubValueBegin = sValue.indexOf(sSubCookieName);
			if(nSubValueBegin != -1)
			{
				var   nSubValueEnd = sValue.indexOf( "& ", nSubValueBegin);
				if(nSubValueEnd == -1)
				nSubValueEnd = sValue.length;
				var sSubValue = sValue.substring(nSubValueBegin + sSubCookieName.length, nSubValueEnd); //获得指定的子键值
				return unescape(sSubValue);
			}
		} 
		if(!sSubCookieName)
			return unescape(sValue);
	}
	return null;
} 
