 

////////////////////////////////////////////////////////////////////
//// Site Tree javascript representation ///////
////////////////////////////////////////////////////////////////////
// Example of use :
// Retrieve siteRoot Section : 
//	var siteRoot = sectionById[siteRootId];
// Retrieve first level Sections
//	var firstLevel = childrenById[siteRootId];
var siteRootId = 1077;
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(1077, null, 0, "Royal Horse", "/eng/", "|");


   new Section(1157, 1077, 2, "Presentation", "/eng/presentation", "|");
  
  
      new Section(1158, 1157, 1, "Royal Horse in short", "/eng/presentation/royal-horse-equine-diet", "|");
  
      new Section(1159, 1157, 2, "Historical", "/eng/presentation/historical-royal-horse-breeding", "|");
  
      new Section(1160, 1157, 3, "Key numbers", "/eng/presentation/key-number-royal-horse", "|");
  
      new Section(1161, 1157, 4, "News", "/eng/presentation/news-horse-nutrition", "|");
  
      new Section(1162, 1157, 5, "Research and Development", "/eng/presentation/recherche-developpement", "|");
  
      new Section(1163, 1157, 6, "Certification", "/eng/presentation/certification-performance-equine", "|");
  
      new Section(1164, 1157, 7, "CNEF", "/eng/presentation/french-equine-nutrition-club", "|");
  
      new Section(1199, 1157, 8, "Partners sites", "/eng/presentation/partners-sites-royal-horse", "|");
  

   new Section(1165, 1077, 3, "Team RH", "/eng/team-royal-horse", "|");
  
  
      new Section(1166, 1165, -1, "The RH team", "/eng/team-royal-horse/team-royal-horse", "|");
  
      new Section(1167, 1165, 0, "The team news", "/eng/team-royal-horse/team-news", "|");
  

   new Section(1168, 1077, 4, "How to find us", "/eng/how-to-find-royal-horse", "|");
  
  
      new Section(1169, 1168, 1, "Channel of distribution", "/eng/how-to-find-royal-horse/reseau-distribution", "|");
  

   new Section(1170, 1077, 5, "Products", "/eng/equine-food-and-horse-nutrition", "|");
  
  
      new Section(1171, 1170, 1, "Products research", "/eng/equine-food-and-horse-nutrition/products-research-horse-care", "|");
  
      new Section(1175, 1170, 2, "Specific branch research", "/eng/equine-food-and-horse-nutrition/specific-branch-research", "|");
  

   new Section(1178, 1077, 6, "Advices", "/eng/advices", "|");
  
  
      new Section(1179, 1178, 1, "General condition", "/eng/advices/horse-nutrition", "|");
  
      new Section(1180, 1178, 2, "Nutritional problems", "/eng/advices/nutritional-problem-horse-feedin", "|");
  
      new Section(1181, 1178, 3, "Breeding", "/eng/advices/horse-breeding", "|");
  
      new Section(1182, 1178, 4, "Elderly horses", "/eng/advices/elderly-horse", "|");
  
      new Section(1183, 1178, 5, "Performances", "/eng/advices/performance-equine", "|");
  
      new Section(1184, 1178, 6, "Pathology", "/eng/advices/horse-health", "|");
  
      new Section(1185, 1178, 7, "Practical advices", "/eng/advices/practical-advices-horse-care", "|");
  

   new Section(1186, 1077, 7, "Your horse", "/eng/your-horse", "|");
  
  
      new Section(1187, 1186, 1, "Horse digestive system", "/eng/your-horse/horse-nutrition", "|");
  
      new Section(1188, 1186, 2, "Nutrition basis", "/eng/your-horse/horse-nutrition-basis", "|");
  
      new Section(1189, 1186, 3, "Calculate its weight", "/eng/your-horse/horse-care-calculate-its-weight", "|");
  
      new Section(1190, 1186, 4, "Calculate its feed ration", "/eng/your-horse/caluler-sa-ration", "|");
  
      new Section(1191, 1186, 5, "Key words", "/eng/your-horse/keywords-equine-diet", "|");
  

   new Section(1192, 1077, 8, "Contact", "/eng/contact", "|");
  
  
      new Section(1193, 1192, 1, "Contact", "/eng/contact/contact-royal-horse", "|");
  



// 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]);