// Get the Cookie value then use a Cookie Cutter to parse it into an array.
function ParseCookieIntoArray(CookieName)
  {
   ParseCookie(GetCookie(CookieName));
   return cookArray;
  } 

// Get the Cookie name from a list of possible cookies.
function GetCookie(CookieName)
  {
   var i = 0;
   var cname = CookieName + "=";

   while (i < document.cookie.length)
     {
      var j = i + cname.length;
      if(document.cookie.substring(i, j) == cname)
        {
	 var leng = document.cookie.indexOf(";", j);
	 if(leng == -1)
           {leng = document.cookie.length;}
	 return unescape(document.cookie.substring(j, leng));
        }
      i = document.cookie.indexOf(" ", i) + 1;
      if(i == 0) break;   //thats -1 plus 1.
     }
   return "*";
  }

// Parse Cookie (Cookie Cutter) into an array.
function ParseCookie(cookieValue)
  {
   var i = 0, indx = 0, citemlen =0;

   cookArray = new Array();

   if(cookieValue == null)
     {cookArray[0] = "*"; return}  //Data has expired or never entered.

   if(cookieValue == "*") 
     {cookArray[0] = "*"; return}  //Data has expired or never entered.

   while(citemlen < cookieValue.length)
        {
         citemlen=(cookieValue.indexOf("`", indx) >= 0)
	          ?cookieValue.indexOf("`", indx):cookieValue.length;
         cookArray[i] = cookieValue.substring(indx, citemlen); i++;
         indx = citemlen + 1;
        }
  }

// Get and return the index of the checked radio button (radio group).
function RadioCheckedIndex(radioGroup)
  { 
   for(var i=0; i < radioGroup.length; i++ )
      {
       if(radioGroup[i].checked == true) 
         {return i;}   // Return index of checked radio button. 
      }
   return "*";         // Return '*' if none of radio buttons where checked.  
  }

// Find and return list of the indexes of *all* the selected multiple selections. The function
// returns a list of indexes, seperated by ",".
function FindMultipleSelectionsIndex(selectList)
  { 
   var indxlist = "";
   for(var i=0; i < selectList.options.length; i++ )
      {
       if(selectList.options[i].selected == true) indxlist = indxlist + "," + i; 
      }
   return (indxlist == "")?indxlist = "*":indxlist;
  }

// Use the list to set all stored cookie multiple selects. Requires clearing all document (form)
// current selections prior to loading the selections (checked entries) contained within the
// cookie (array entry).
function SetMultipleSelectionsIndex(selectObject, selectList)
  {
   for(var i=0; i < selectObject.options.length; i++)
      { 
       // Clear all document (form) current selections prior to setting the selections 
       // (checked entries) contained within the cookie (array entry).
       selectObject.options[i].selected = false; 
      } 
       var ilen = 0;
       while(ilen < selectList.length-1 )
            { 
             var indxstart = selectList.indexOf(',',ilen);
             if(indxstart == -1) return;

             ilen = selectList.indexOf(',',indxstart+1);
             if(ilen == -1) ilen = selectList.length;

             // Make sure its an integer before using it as subscript.
             var indx = parseInt(selectList.substring(indxstart+1,ilen) ,10);
             selectObject.options[indx].selected = true;            
            }
  }

