var LINKS_COOKIE_NAME = "xeditlinks";

// add a document to the cookie
function addDocument( aType, aId, aDescription ) {
//  alert( "add document (" + aType + ", " + aId + ", " + aDescription + ")" );
  // read document cookie
  var cookie_value = GetCookie( LINKS_COOKIE_NAME );
//  alert( "current cookie value " + cookie_value );
  if( cookie_value ) {
    var documents = cookie_value.split( "~" );

    // check if already in cookie
    for( var i=0; i<documents.length-1; i++) {
      var document_values = documents[i].split( "^" );
      if( document_values[1] == aId )
        return;
    }
  }
  else {
    cookie_value = "";
  }

//  alert( "cookie value ["+cookie_value+"]");

  // add new document to cookie
  var new_document = aType + "^" + aId + "^" + aDescription + "~";
  var new_cookie_value = cookie_value + new_document;
  SetCookie( LINKS_COOKIE_NAME, new_cookie_value, null, "/" );
}

// remove a document from the cookie
function removeDocument( aId ) {
  // read document cookie
  var cookie_value = GetCookie( LINKS_COOKIE_NAME );
  var documents = cookie_value.split( "~" );

  // check if already in cookie
  var new_cookie_value = "";
  for( var i=0; i<documents.length-1; i++) {
    var document_values = documents[i].split( "^" );
    if( document_values[1] != aId ) {
      new_cookie_value += documents[i] + "~";
    }
  }

  SetCookie( LINKS_COOKIE_NAME, new_cookie_value, null, "/" );
}

// get a list of documents
function getDocuments() {
  // read document cookie
  var cookie_value = GetCookie( LINKS_COOKIE_NAME );
  if( cookie_value ) {
    var documents = cookie_value.split( "~" );
    return documents;
  }
}