function M44HomeAction() {	
}
M44HomeAction.prototype = new DowWidget;

M44HomeAction.prototype.onWidgetModified = function (widget) {
	if (widget.uid == 'welcome_message') {
		this.sendM44Home();
	} 
}

M44HomeAction.prototype.sendM44Home = function () {
	var action = this.createEmptyAction("setGenericXML");
	action.setAttribute("what_key","welcome");
	gWidgets.welcome_message.appendXMLData(action);
	this.sendAction(action.ownerDocument,null);
}

M44HomeAction.prototype.on_editAction = function(who) {
	gWidgets.welcome_message.toggle_edit();
}

//  *******************

function sc_sortby(scenario_list_id, sort, sort_order) {  //HACK overrides  Yann's sc_sortby in sceanrio.js with my version also in sceanrio.js
	var pagerJSObj = eval("gPagerFor_"+scenario_list_id);
	gJFSPager.sc_sortby(pagerJSObj, sort, sort_order);
}

//  *******************



function UPControlPanel() {
}
UPControlPanel.prototype = new DowWidget;

UPControlPanel.prototype.postInit = function () {
	this.toggleElem = document.getElementById(this.uid+"_toggle");
	this.toggleIconElem = document.getElementById(this.uid+"_toggle_icon");
	this.toggleTextAddElem = document.getElementById(this.uid+"_toggle_text_add");
	this.toggleTextRemoveElem = document.getElementById(this.uid+"_toggle_text_remove");
	this.bindEvent(this.toggleElem,"click","toggleAction"); 
}

UPControlPanel.prototype.toggleAction = function (event) {
	this.params.rank=this.params.rank ? 0 : 1;
	this.doRanking(this.params.rank);
	this.updateToggle();
}

UPControlPanel.prototype.doRanking = function(value) {
	var action = this.createEmptyAction("ranking");
	var doc = action.ownerDocument;
	var rankingElem = doc.createElement("rank");
	rankingElem.setAttribute("value",value);
	action.appendChild(rankingElem);
	this.sendAction(action.ownerDocument);
}

UPControlPanel.prototype.updateToggle = function () {
	if (this.toggleIconElem) {
		if (this.params.rank) {
			this.unsetElementClass(this.toggleIconElem , "up_favorite_icon_off");
			this.setElementClass(this.toggleIconElem , "up_favorite_icon_on");
		} else {
			this.setElementClass(this.toggleIconElem , "up_favorite_icon_off");
			this.unsetElementClass(this.toggleIconElem , "up_favorite_icon_on");
		}
	}
	
	if (this.toggleTextAddElem && this.toggleTextRemoveElem) {
		if (this.params.rank) {
			this.toggleTextAddElem.style.display="none";
			this.toggleTextRemoveElem.style.display="inline";
		} else {
			this.toggleTextAddElem.style.display="inline";
			this.toggleTextRemoveElem.style.display="none";
		}
	}
}

function AvatarWidget(uid) {
}
AvatarWidget.prototype = new DowWidget;

AvatarWidget.prototype.postInit = function () {
	this.editElem = document.getElementById(this.uid+"_edit");
	this.bindEvent(this.editElem,"click","clickAction"); 
}

AvatarWidget.prototype.clickAction = function (event) {
	gWidgets[this.uid+"_editor"].attach(this);
}

AvatarWidget.prototype.setPreview = function (src) {
	this.getWidgetElement().style.backgroundImage = "url(http://www.daysofwonder.com"+src+")";
}





function AvatarEditorWidget() {
}
AvatarEditorWidget.prototype = new DowWidget;

AvatarEditorWidget.prototype.postInit = function () {
	this.editorElem = this.getWidgetElement();
	this.bindEvent(this.editorElem,"click","clickAction"); 
}


AvatarEditorWidget.prototype.clickAction = function (event) {
	var avatarElem = this.findAncestor(event.target , "DIV", "avatar_frame");
	if (avatarElem) {
		var avatarId = avatarElem.id.slice(this.uid.length+1);
		if (avatarId!="") {
			var src = this.params.avatars[avatarId];
			if (src) {
				this.sendSetAvatar(avatarId);
				this.ownerWidget.setPreview(src);
			}
		}
	}
	this.editorElem.style.display = "none";
}


AvatarEditorWidget.prototype.attach = function (ownerWidget) {
	this.ownerWidget = ownerWidget;
	this.editorElem.style.display = "block";
}


AvatarEditorWidget.prototype.sendSetAvatar = function (avatar_id) {
	var action = this.createEmptyAction("setAvatar");
	action.setAttribute("game","m44");
	action.setAttribute("avatar_id",avatar_id);
	this.sendAction(action.ownerDocument);
}


