function getUserName(rawCookie)
{
  var pos = rawCookie.indexOf("username=") + 9;
  var endOfParam = rawCookie.indexOf("|", pos);
  
  return rawCookie.substring(pos, endOfParam);  
}

function getDomain(rawCookie)
{
  var pos = rawCookie.indexOf("domainname=") + 11;
  var endOfParam = rawCookie.length;
  
  return rawCookie.substring(pos, endOfParam);  
}
/*
Read the cookie and return the raw content
*/
function getCookieDetails(cookieName)
{
  
  var allCookies = document.cookie;
  var pos = -1;
  if ( allCookies != null )
  {
    pos = allCookies.indexOf(cookieName);
  }
  var value = "";
  
  if (pos != -1)
  {
    startOfCookie = pos + cookieName.length + 1;
    endOfCookie = allCookies.indexOf(";", startOfCookie);
    if ( endOfCookie < startOfCookie)
    {
      endOfCookie = allCookies.length;
    }
    //alert("startOfCookie:" + startOfCookie + " endOfCookie: " + endOfCookie + " : " + allCookies.length);
    value = allCookies.substring(startOfCookie, endOfCookie);
    value = unescape(value);
  }
  //alert(value);
  return value;
}

function geturl(siteURL,section,docrefid, refid, panelaccessed)
{
/*
    This gets the url in which to call the servlet.
    It needs the following parameters
        section - which is either pcategory or ecategory
        refid - if the refid is set
        docrefid - referenceid 
        panelaccessed - 1 if breaking news else 0
*/
  var the_cookie_name = "ilpcookie";
  var cookieValue = getCookieDetails(the_cookie_name);  
  //alert("cookieValue: " + getUserName(cookieValue) + " <> " + getDomain(cookieValue));
  var pageurl = "";
  if (cookieValue != "")
  {
    pageurl = siteURL + "servlet/reportservlet/orange.gif?section=" + section + "&documentrefid=" + docrefid + "&refid=" + refid + "&panel-accessed=" + panelaccessed + "&username=" + getUserName(cookieValue) + "&domain=" + getDomain(cookieValue);
  }
  return pageurl;
}
