function RecordFieldFormatterCSVImportStatus( ) {
	var m_formatterError =  new FormatterImage("Error");
	var m_formatterOK =  new FormatterImage("Success");
	this.Format = function ( colname, record ) {
		if (record[ colname ]==0 ) {
			return m_formatterOK.Format("/img/success.png");
		}
		return m_formatterError.Format("/img/error.png");
	}
}

function RecordFieldFormatterCSVImportValue( ) {
	this.Format = function ( colname, record ) {
		var errColumn	= '__error_' + colname;
		var result = record[ colname ];
		if ( record[ errColumn ] ) {
			result +='<p class="csverror">' +eval(record[ errColumn ]) +'</p>'
		}
		return result;
	}
}

function RecordFieldFormatter( formatter ) {
	var m_formatter = formatter;
	this.Format = function ( colname, record ) {
		return m_formatter.Format( record[ colname ] );
	}
}
function RecordFieldFormatterSubrecord( subName ) {
	var m_subname = subName;
	this.Format = function ( colname, record ) {
		var subrecord = record[ colname ];
		return  subrecord[m_subname];
	}
}

function RecordFieldFormatterLabelsMap() {
	var m_formatter = new FormatterMap( arguments );
	this.Format = function ( colname, record ) {
		return m_formatter.Format( record[ colname ] );
	}
}

function RecordFieldFormatterImagesMap() {
	var m_formatter = new DoubleFormatterMap( arguments );
	m_formatter.Formatter = new FormatterImage("");
	this.Format = function ( colname, record ) {
		return m_formatter.Format( record[ colname ] );
	}
}

function RecordFieldFormatterLabelsMapArray( args ) {
	var m_formatter = new FormatterMap( args );
	this.Format = function ( colname, record ) {
		return m_formatter.Format( record[ colname ] );
	}
}

function RecordFieldFormatterEditArtefact( labelEdit, labelTranslate ) {	
	this.Format = function ( colname, record ) {
		var operation = 'edit';
		var label = labelEdit;
		if ( record['fkTranslatedFrom'] ) {
			operation = 'translate';
			label = labelTranslate;
		} 
		var artefacts = 'articles';
		if ( record['artefactType']==1  ) {
			artefacts = 'calculators';
		} else if ( record['artefactType']==4  ) {
			artefacts = 'handbooks';
		}
		var url = "/personal/" + artefacts + '/' + operation + '/?id=' + record['pkID'];
		
		return '<a href="' + url + '">' + label + '</a>';
	}
}

function RecordFieldFormatterURLPattern( urlPattern, formatter ) {
	this.Format = function ( colname, record ) {
		var value = formatter ? formatter.Format(colname, record) : record[colname];
		return '<a href="' + urlPattern.replace(/%1/g,record["pkID"]) + '">' + value + '</a>';
	}
}

function RecordFieldFormatterURLPatternKey( urlPattern, formatter, key ) {
	this.Format = function ( colname, record ) {
		var value = formatter ? formatter.Format(colname, record) : record[colname];
		return '<a href="' + urlPattern.replace(/%1/g,record[key]) + '">' + value + '</a>';
	}
}

function RecordFieldFormatterPublishedArtefact( formatter ) {
	var m_linkstatus = status;
	this.Format = function ( colname, record ) {
		var value = formatter ? formatter.Format(colname, record) : record[colname];
		if (record["published"])
			return '<a href="/'+ record["pkID"] + '/">' + value + '</a>';
		else 
			return value;
	}
}

function RecordFieldFormatterParamScriptURL( pattern, propName, formatter ) {
	var m_pattern = pattern;
	this.Format = function ( colname, record ) {
		var name = formatter?formatter.Format( colname, record ):record[colname];
		return '<a href="#" onclick="' + m_pattern.replace(/%1/g,record[propName]) + '; return BSPreventDefaultAction( event);">' + name + '</a>';
	}
}


function RecordFieldFormatterParamScriptURLEx( pattern, formatter ) {
	var m_pattern = pattern;
	var m_fields = new Array();
	for( var i=2;i<arguments.length;++i ) {
		m_fields[i-2] = arguments[i];
	}

	this.Format = function ( colname, record ) {
		var name = formatter?formatter.Format( colname, record ):record[colname];
		var dest = m_pattern;
		for( var i=0;i<m_fields.length;++i ) {
			var toReplace = "%" + (i+1).toString();
			var replaceWith = record[m_fields[i]]?record[m_fields[i]]:'';
			dest = dest.replace( toReplace , replaceWith );
		}
		return '<a href="#" onclick="' + dest + ';return BSPreventDefaultAction( event);">' + name + '</a>';
	}
}

function RecordFieldFormatterParamScriptURLLabel( pattern, propName, label ) {
	var m_pattern = pattern;
	var m_label = label;
	this.Format = function ( colname, record ) {
		return '<a href="#" onclick="' + m_pattern.replace(/%1/g,record[propName]) + '; return BSPreventDefaultAction( event);">' + m_label + '</a>';
	}
}

function RecordFieldFormatterLabel( label ) {
	this.Format = function ( colname, record ) {
		return label;
	}
}

function RecordFieldFormatterEmptyLabel( emptyLabel ) {
	this.Format = function ( colname, record ) {
		var name = record[colname];
		if ( typeof(name)=='undefined'|| name=="" ) {
			name = emptyLabel;
		}
		return name;
	}
}

function RecordFieldFormatterAlternate( alternateColumn, anotherFormatter ) {
	this.Format = function ( colname, record ) {
		if( typeof(record[colname]) == 'undefined' ) {
			return anotherFormatter.Format( alternateColumn, record );
		} else {
			return anotherFormatter.Format( colname, record );
		}
	}
}

function RecordFieldFormatterChangeButtons( id, deleteLabel, editLabel )  {
	function GetButtonCode( pkId, id, func, label, cls ) {
		return '<a class="'+ cls +'" title="' + label + '" href="#" onclick="' + id + '.' + func + '(' + pkId + '); return BSPreventDefaultAction( event);"><span>&nbsp;</span><a>';
	}
	this.Format = function ( colname, record ) {
		var pkID = record["pkID"];
		return GetButtonCode(pkID, id, 'Edit', editLabel, 'btn_edit') + ' ' +  GetButtonCode(pkID, id, 'Delete', deleteLabel, 'btn_del');
	}
}