/**
 * Class to represent a POICategory. POIs are grouped into categories. Hence 
 * there is a 1 to many relationchip between a POICategory and POIs
 *
 * $Id: POICategory.js,v 1.12 2009/02/23 05:55:12 vpulla Exp $
 */


function POICategory(categoryId_)
{
   var cName = "[POICategory] ";
   var categoryId = categoryId_;
   var pois = new Array();
   var poiCounter=0;
   
   
   /** A C C E S S O R S - & - M U T A T O R S ==============================**/
   this.getCategoryId=function getCategoryId()
   {
      return categoryId;
   };
   
   this.setCateForyId=function setCategoryId(categoryId_)
   {
      categoryId = categoryId_;
   };
   
   this.getPOIs=function getPOIs()
   {
      return pois;
   };
   
   this.setPOIs=function setPOIs(pois_)
   {
      pois = pois_; 
   };
   
   
   /**
    * Ensure that the poi with poiid is unique in the collection, if the POI
    * with a specific poiid already exists, the POI will be replaced
    */
   this.addPOI=function addPOI(poi)
   {
      var fnName = cName + "addPOI() ";
      
      var poiid = poi.$("poiid");
      // check if this poi is already in the list, if it does, remove it
      if(poiid != null && (""+poiid).length > 0)
      {
         for(var i=0; i<pois.length; i++)
         {
            if(poiid == pois[i].$("poiid"))
            {
               log.warn(fnName, "POI with poiid [" + poiid + "] already exists, replacing with new POI");
               
               pois[i].clearVectorElements(map.getLayer("vector"));
               poi.copyVariables(pois[i]);
               pois[i].setStringifiedPOI(poi.getPOI());
               return pois[i];
            }
         }
      }
      else
      {
         poiid = categoryId + "_" + poiCounter;
         poi.setVariable("poiid", "\"" + poiid + "\"");
      }
      pois[pois.length] = poi;
      ++poiCounter;
      return poi;
      
   };
   
}
