function Adv(id, gameObj) {
	this.id = id;
	this.gameObj = gameObj;
	if (gameObj)
		gameObj.adv = this;
	this.initContent = false;
	Adv.allAdvs[id] = this;
}

Adv.allAdvs = [];

Adv.getAdv = function(id) {
	return Adv.allAdvs[id];
};

Adv.myrandom = new MyRandom();

Adv.doAction = function(action, advId) {
	var adv = Adv.getAdv(advId);
	if (adv && adv.gameObj && adv.gameObj.doAction) {
		adv.gameObj.doAction(action);
	}
};

Adv.maxEntry = function(arr, start, cnt) {
	var mx = arr[start];
	for (i=1; i<cnt; ++i) {
		if (arr[start + i] > mx) mx = arr[start + i];
	}
	return mx;
};

Adv.setElemValue = function(elemId, elemValue) {
		var elem = document.getElementById(elemId);
		if (!elem) return;
		elem.innerHTML = elemValue;
};

Adv.addElemValue = function(elemId, elemAddValue) {
	var elem = document.getElementById(elemId);
	if (!elem) return;
	elem.innerHTML += elemAddValue;
};

Adv.setElemNode = function(elemId, elemNode) {
	if (!elemId) return;
	var elem = document.getElementById(elemId);
	if (!elem) return;
	while (elem.lastChild) elem.removeChild(elem.lastChild);
	if (elemNode) elem.appendChild(elemNode);
};

Adv.addElemNode = function(elemId, elemNode) {
	if (!elemId || !elemNode) return;
	var elem = document.getElementById(elemId);
	if (!elem) return;
	elem.appendChild(elemNode);
};

Adv.removeFromArray = function(arr, ind) {
	if (!arr) return;
	if (!arr.length) return;
	if (ind < 0 || ind >= arr.length) return;
	var len = arr.length;
	var i;
	for (i=ind + 1; i<len; ++i) {
		arr[i-1] = arr[i];
	}
	arr[len - 1] = undefined;
	arr.length = len - 1;
};

Adv.prototype.setContentId = function(id) {
	this.contentId = id;
};

Adv.prototype.setActionsId = function(id) {
	this.actionsId = id;
	this.actions = new Actions(id);
};

Adv.prototype.setClasses = function(classes) {
	this.classes = classes;
};

Adv.prototype.clearContent = function() {
	Adv.setElemValue(this.contentId, "");
};

Adv.prototype.showInitContent = function() {
	if (this.initContent !== false)
		this.setContent(this.initContent);
	else
		this.clearContent();
};

Adv.prototype.setContent = function(content) {
	if (this.initContent === false) {
		this.initContent = content;
	}
	Adv.setElemValue(this.contentId, content);
};

Adv.prototype.addContent = function(content) {
	Adv.addElemValue(this.contentId, content);
};

Adv.prototype.clearActions = function() {
	if (this.actions) this.actions.clearActions();
};

Adv.prototype.addAction = function(action) {
	if (!this.actions) return;
	var label = action;
	var link = "javascript:Adv.doAction(\"" + action + "\", \"" + this.id + "\")";
	var hotKey = action.substring(0,1);
	this.actions.addLink(label, link, hotKey, this.classes);
};

Adv.prototype.addActionCategory = function(category) {
	this.actions.addLabel(category, this.classes);
};
