///////////////////////////////////////////
//get cookie
///////////////////////////////////////////
function getCookieNoDecode(name) { 
  var arg = name + "="; 
  var alen = arg.length; 
  var clen = document.cookie.length; 
  var i = 0; 
  while (i < clen) { 
    var j = i + alen; 
    if (document.cookie.substring(i, j) == arg) 
      return getCookieValNoDecode (j); 
    i = document.cookie.indexOf(" ", i) + 1; 
    if (i == 0) break; 
  } 
return null; 
}

///////////////////////////////////////////
//needed for cookie stuff
///////////////////////////////////////////
function getCookieValNoDecode (offset) { 
  var endstr = document.cookie.indexOf(";", offset); 
  if (endstr == -1) 
    endstr = document.cookie.length; 
  return document.cookie.substring(offset, endstr); 
} 

///////////////////////////////////////////
//parse the grouped cookies
///////////////////////////////////////////
function parseCookieGroup(name,parameter) {
   var foundCookie = false;
   var str = getCookieNoDecode(name);
   if (str != null) {
     //str = unescape(str); the value is not double encoded, this step is not necessary
     strArray = str.split('&');  //array of name / value pairs for cookie.
     for (i=0;i<strArray.length;i++) {
       //strArray[i] contain name value pair
       nameValuePair = strArray[i].split('=');
       if (nameValuePair[0] == parameter) {
         foundCookie = true;
         str = nameValuePair[1];
       }
     }
   }
   if (!foundCookie) {
     str = getCookie(parameter);
   }
   // check for the local variable used for the cookie name
  return stripNull(str); 
}

///////////////////////////////////////////
// stripNull checks for double encoding in CookieVal
///////////////////////////////////////////
function stripNull(CookieVal) {
  if(CookieVal == null) {
    return '';
  }
  else {
    if (!/%\w{2}/.test(CookieVal)) {
      CookieVal = escape(CookieVal).replace(/\./g,'%2E').replace(/\//g,'%2F').replace(/\+/g,'%2B');
    }
    return CookieVal;
  }
}