﻿// RM3SChapter Class

RM3SChapter = function(id, title, description, parentid, tagids, duration, time) 
{
  this.id = id;
  this.title = title;
  this.description = description;
  this.parentid = parentid;
  this.tagids = tagids;
  this.duration = duration;
  this.time = time;
}

RM3SChapter.prototype = {
	loadFromXML: function(xml) {
	  if(xml == null) return;
	  var _x = getTextXmlNodeValue(xml, "chapter");
	  if(_x != null) xml = _x;
	  this.id = getTextXmlNodeValue(xml, "id");
	  this.title = getTextXmlNodeValue(xml, "title");
	  this.description = getTextXmlNodeValue(xml, "description");
	  this.parentid = getTextXmlNodeValue(xml, "parentid");
	  this.duration = parseFloat(getTextXmlNodeValue(xml, "duration"));
	  this.time = parseFloat(getTextXmlNodeValue(xml, "time"));
	  if(this.id == null) this.id = "";
	  if(this.title == null) this.title = "";
	  if(this.description == null) this.description = "";
	  if(this.parentid == null) this.parentid = "";
	  var tagids_xml = getTextXmlNodeValue(xml, "tagids");
	  this.tagids = new Array();
	  if(tagids_xml != null && tagids_xml != "") {
	    var tagids = getTextXmlNodesList(tagids_xml, "tagid");
	    for(var i = 0, n = (tagids == null ? 0 : tagids.length); i < n; i++) {
	      this.tagids.push(tagids[i] == null ? "" : tagids[i]);
	    }
	  }
	},
	
	hasChildren: function(chapters) {
	  var res = false;
    if(chapters != null) {
      for(var i = 0, n = chapters.length; i < n && res == false; i++) {
        if(chapters[i] != null && chapters[i].parentid == this.id) res = true;
      } 
    }
    return res;
	}
}