 

////////////////////////////////////////////////////////////////////
//// Site Tree javascript representation ///////
////////////////////////////////////////////////////////////////////
// Example of use :
// Retrieve siteRoot Section : 
//	var siteRoot = sectionById[siteRootId];
// Retrieve first level Sections
//	var firstLevel = childrenById[siteRootId];
var siteRootId = 93;
var sectionById = new Object();
var childrenById = new Object();

//////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Section is a javascript Object that represent a Smart Section
//// Interface description :
////	id : integer, primary key value of this Section
////	parentId : id of this Section parent Section
////	screenorder : order of this Section among its brother Sections
////	name : name to be displayed to the user.
////	url : url of the page that represent this Section
////	getChildren() : return the children (as an Array) of this Section. May return null.
////	getParent() : return the parent Section of this Section
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//var roles = new Array();
function Section(id, parentId, screenorder, name, aUrl, allowedRights) {
	this.id 	 = id;
	this.parentId	 = parentId;
	this.screenorder = screenorder;
	this.name 	 = name;
	this.url 	 = aUrl;
	this.allowedRights = allowedRights;

//	if(this.id == siteRootId || this.isAllowedFor(roles)) {
		// this Section is allowed, so register it
		sectionById[this.id] = this;
		var brothers = childrenById[this.parentId];
		if(brothers == null) {
			brothers = new Array();
			childrenById[this.parentId] = brothers;
		}
		brothers.push(this);
//	}
}

Section.EMPTY_ARRAY = new Array(0); 

Section.compare = function(section1, section2) {
	return section1.screenorder - section2.screenorder ;
}

Section.prototype.getChildren = function() {
	var children = childrenById[this.id];
	if(children == null) {
		children = childrenById[this.id] = Section.EMPTY_ARRAY ;
	}

	if(!this.childrenHasBeenOrdered) {
		children.sort(Section.compare);
	}

	return children;
}

Section.prototype.getParent = function() {
	return sectionById[this.parentId];
}

Section.prototype.getLevel = function() {
	var parent = this.getParent();
	if(parent != null) {
		return parent.getLevel()+1;
	} else {
		return 0;
	}
}

Section.prototype.isAllowedFor = function(roleArray) {
	var result = false;
	var i = 0;
	while(!result && i<roleArray.length) {
		var cRole = roleArray[i++];
		result = "ADMIN" == cRole ||  this.allowedRights.indexOf('|'+cRole+'|') != -1;
	}

	return result;
}

////////////////////////////////////////////////////////////////////////////////////////
//// Represents a process on the Site Tree
////////////////////////////////////////////////////////////////////////////////////////
function SectionVisitor() {
}

SectionVisitor.prototype.visit = function(aSection) {
	var shouldProcessChildren = this.process(aSection);
	if(shouldProcessChildren) {
		var children = aSection.getChildren();
		if(children != null) {
			for(var i=0; i<children.length; ++i) {
				this.visit(children[i]);
			}
		}
	}
}

SectionVisitor.prototype.process = function(aSection) {
	alert("SectionVisitor.process() on "+aSection.id+" - "+aSection.name+". Should be overriden to perform custom processing.");
	return false;   // Return if process should be called on children Sections
}

new Section(93, null, 0, "Sarb gheerbrant", "/fre/", "|");


   new Section(1200, 93, 14, "Présentation", "/fre/alimentation-poissons", "|");
  
  
      new Section(1230, 1200, 0, "Qui sommes-nous?", "/fre/alimentation-poissons/qui-sommes-nous", "|");
      
      
  
      new Section(1201, 1200, 1, "Notre métier", "/fre/alimentation-poissons/metier", "|");
      
      
          new Section(1276, 1201, 1, "Concevoir l'aliment", "/fre/alimentation-poissons/metier/concevoir-aliment", "|");
      
          new Section(1277, 1201, 2, "Connaître le poisson", "/fre/alimentation-poissons/metier/connaitre-poisson", "|");
      
          new Section(1278, 1201, 3, "Caracteriser l'élevage", "/fre/alimentation-poissons/metier/caracteriser-elevage", "|");
      
  
      new Section(1202, 1200, 2, "L'équipe", "/fre/alimentation-poissons/equipe", "|");
      
      
  

   new Section(1205, 93, 15, "Votre activité", "/fre/activite-alimentation-elevage", "|");
  
  
      new Section(1206, 1205, 1, "Salmoniculture", "/fre/activite-alimentation-elevage/salmoniculture", "|");
      
      
          new Section(1261, 1206, 1, "Catalogue produits", "/fre/activite-alimentation-elevage/salmoniculture/catalogue", "|");
      
          new Section(1262, 1206, 2, "Les Espèces", "/fre/activite-alimentation-elevage/salmoniculture/especes", "|");
      
          new Section(1263, 1206, 3, "La qualité de l'eau", "/fre/activite-alimentation-elevage/salmoniculture/qualite-eau", "|");
      
          new Section(1264, 1206, 4, "La qualité de chair", "/fre/activite-alimentation-elevage/salmoniculture/qualite-chair", "|");
      
  
      new Section(1207, 1205, 2, "Aquaculture marine", "/fre/activite-alimentation-elevage/aquamarine", "|");
      
      
          new Section(1269, 1207, 1, "Catalogue Produits", "/fre/activite-alimentation-elevage/aquamarine/catalogue", "|");
      
          new Section(1270, 1207, 2, "Les Espèces", "/fre/activite-alimentation-elevage/aquamarine/especes", "|");
      
          new Section(1271, 1207, 3, "L'environnement", "/fre/activite-alimentation-elevage/aquamarine/environnement", "|");
      
          new Section(1272, 1207, 4, "la qualité de chair", "/fre/activite-alimentation-elevage/aquamarine/qualite", "|");
      
  
      new Section(1208, 1205, 3, "L'aquaculture continentale", "/fre/activite-alimentation-elevage/aquacontinentale", "|");
      
      
          new Section(1267, 1208, 1, "Catalogue produits", "/fre/activite-alimentation-elevage/aquacontinentale/catalogue", "|");
      
          new Section(1268, 1208, 2, "Les Espèces", "/fre/activite-alimentation-elevage/aquacontinentale/especes", "|");
      
  
      new Section(1260, 1205, 4, "Ornement/Loisirs", "/fre/activite-alimentation-elevage/ornement", "|");
      
      
          new Section(1273, 1260, 1, "Les produits ornements", "/fre/activite-alimentation-elevage/ornement/catalogue", "|");
      
          new Section(1274, 1260, 2, "les produits pêche", "/fre/activite-alimentation-elevage/ornement/produits-peche", "|");
      
  

   new Section(1209, 93, 16, "Les services", "/fre/services-elevage-poissons", "|");
  
  
      new Section(1210, 1209, 1, "Sélectionnez vos produits", "/fre/services-elevage-poissons/produit", "|");
      
      
  
      new Section(1211, 1209, 2, "Vous avez des questions?", "/fre/services-elevage-poissons/questions", "|");
      
      
  
      new Section(1212, 1209, 3, "Les petites annonces", "/fre/services-elevage-poissons/annonces", "|");
      
      
  
      new Section(1213, 1209, 4, "Les liens", "/fre/services-elevage-poissons/liens", "|");
      
      
  
      new Section(1294, 1209, 5, "Offres complémentaires", "/fre/services-elevage-poissons/offres-complementaires", "|");
      
      
  

   new Section(1220, 93, 19, "Contact", "/fre/contact", "|");
  
  



// If only one subsection, then do not show the subsection
function postInit(aSection) {
	var children = aSection.getChildren();
	if(children != null && children.length == 1) {
		var onlyChildSection = children[0];
		aSection.url = onlyChildSection.url;
		if(aSection.getLevel() > 0) {
			childrenById[aSection.id] = childrenById[onlyChildSection.id];
		}
	}
	/*if(children != null && children.length > 1) {
		var firstSection = children[0];
		aSection.url = firstSection.url;
	}*/
	return true;
}
var postInitVisitor = new SectionVisitor();
postInitVisitor.process = postInit;
postInitVisitor.visit(sectionById[siteRootId]);