Button.PARAGRAPH = 0;
Button.DOCUMENT = 1;

function Button(strLabel) {
	this.intDocumentID = 0;
	this.intParagraphID = 0;
	this.intMenuItemID	
	this.strLabel = strLabel;
	this.intKind = 0;
	this.properties=new Array();
}

Button.prototype.initParagraph		= Button_initParagraph;
Button.prototype.initDocument		= Button_initDocument;
Button.prototype.getLabel 			= Button_getLabel;
Button.prototype.getURL 			= Button_getURL;
Button.prototype.addProperty		= Button_addProperty;
Button.prototype.deselected			= Button_deselected;
Button.prototype.matchFilterCount	= Button_matchFilterCount;
Button.prototype.showProps		= Button_showProps;

function Button_initParagraph(intDocumentID, intParagraphID) {
	this.intDocumentID = intDocumentID;
	this.intParagraphID = intParagraphID;
	this.intKind = Button.PARAGRAPH;
}

function Button_initDocument(intDocumentID, intMenuItemID) {
	this.intDocumentID = intDocumentID;
	this.intMenuItemID = intMenuItemID;
	this.intKind = Button.DOCUMENT;
}

function Button_getLabel() {
	return this.strLabel;
}

function Button_getURL() {
	if (this.intKind == Button.DOCUMENT)
		return "mi_"+this.intMenuItemID+"_do_"+this.intDocumentID+".htm";
	else
		return "button_par_"+this.intParagraphID+"_do_"+this.intDocumentID+".htm";
}
function Button_addProperty(intId, strValue) {
	//' add a property to a button
	var o=new Object();
	o.id=intId;
	o.value=strValue;
	this.properties.push(o);
	
}

/* checks if the button matches the filter */
function Button_deselected(arSelectedProps, arUnSelectedProps) {
	//' if no unselected property then item is matching filter
	intSelected=this.matchFilterCount(arSelectedProps, true);
	if (intSelected>0) {
		return false;
	} else {
		if (this.matchFilterCount(arUnSelectedProps,true)>0 && intSelected==0) return true;
		return false;	
	}
}

function Button_matchFilterCount(arProps, blnOneIsEnough) {
	//' parameter blnOneIsEnough is used to return 1 when there is at least one hit
	var intCount=0;
	for (var i=0; i<this.properties.length;i++) {
		for (var j=0; j<arProps.length;j++) {
			if (this.properties[i].id==arProps[j].id &&
				this.properties[i].value==arProps[j].value ) 	{
					intCount++ 	//' property exists in array
					if (blnOneIsEnough) return intCount;
			}
		}
	}
	//alert ("properties of button: " + this.strLabel + "\n" + this.showProps(this.properties) + "\n passed selection:" + this.showProps(arProps) + "\ncount: " + intCount);

	return intCount
}
//' debug
function Button_showProps(ar) {
	var str="";
	for (var i=0; i<ar.length;i++) {
		str+=ar[i].id + " = " + ar[i].value + "\n"; 	
	}
	return  (str);
}

