var LF = '\n';
var NBSP = '';

var RunAt = new Object();
RunAt.SERVER = 0;
RunAt.CLIENT = 1;

/*
+ ---------------------------------------------------------------------------------+
| Object....: ImageMapping
| Function..: 
| Arguments.: 
|
| Date        Author            Note
| ----------  ----------------  ----------------------------------------------------
| 05.01.2005  G.Schulz (SCC)    Initial version
+ ---------------------------------------------------------------------------------+
*/
function ImageMapping(rule, src, width, height, tooltip, alt, resource) {
	var a = arguments;

	this.rule     = rule;                              // RegExpression teh image must match
	this.src      = src;                               // image source
	this.width    = width;                             // image width
	this.height   = height;                            // image height
	this.tooltip  = (a.length >= 5) ? tooltip : '';    // additional tooltip
	this.alt      = (a.length >= 6) ? alt : '';        // alt attribute
	this.resource = (a.length >= 7) ? resource : '';
}
function ImageMapping_getSource() {
	return this.src;
}
function ImageMapping_getWidth() {
	return this.width;
}
function ImageMapping_getHeight() {
	return this.height;
}
function ImageMapping_getTooltip() {
	return this.tooltip;
}
function ImageMapping_getAlt() {
	return this.alt;
}
function ImageMapping_toString() {
	var out = '';
	out += '********* ImageMapping ***********' + LF
	out += 'Rule...........: ' + this.rule + LF;
	out += 'Source.........: ' + this.src + LF;
	out += 'Width..........: ' + this.width + LF;
	out += 'Height.........: ' + this.height + LF;
	out += 'Tooltip........: ' + this.tooltip + LF;
	out += 'Alt............: ' + this.alt + LF;
	out += 'Resource.......: ' + this.resource + LF;
	return out;
}
new ImageMapping();
ImageMapping.prototype.getSource  = ImageMapping_getSource;
ImageMapping.prototype.getWidth   = ImageMapping_getWidth;
ImageMapping.prototype.getHeight  = ImageMapping_getHeight;
ImageMapping.prototype.getTooltip = ImageMapping_getTooltip;
ImageMapping.prototype.getAlt     = ImageMapping_getAlt;
ImageMapping.prototype.toString   = ImageMapping_toString;



/*
+ ---------------------------------------------------------------------------------+
| Object....: ImageMap
| Function..: Collection for ImageMapping objects
| Arguments.: id, runAt
|
| Date        Author            Note
| ----------  ----------------  ----------------------------------------------------
| 05.01.2005  G.Schulz (SCC)    Initial version
+ ---------------------------------------------------------------------------------+
*/
function ImageMap(id, runAt, base) {
	var a = arguments;
	
	this.arrImageMappings = new Array();                            // Collection
	this.id     = id;                                               // the id for this image map
	this.runAt  = (a.length >= 2) ? runAt : RunAt.SERVER;           // indicates if the control should work with or without roundtrips
	this.base   = (a.length >= 3) ? base : '';                      // The base directory for all the images
}
function ImageMap_addImageMapping(mapping) {
	if (mapping instanceof ImageMapping) {
		this.arrImageMappings[this.arrImageMappings.length] = mapping;
	}
}
function ImageMap_getImageMapping(rule) {
	for (var i=0; i <= this.arrImageMappings.length; i++) {
		var imRule = this.arrImageMappings[i]['rule'];
		
		if (imRule == rule) {
			return this.arrImageMappings[i];
		}
	}

	return null;
}
function ImageMap_getImageMappings() {
	// return the collection
	return this.arrImageMappings;
}
function ImageMap_toString() {
	var out = '';
	out += '********* ImageMap ***********' + LF
	out += 'Id.............: ' + this.id + LF;
	out += 'RunAt..........: ' + this.runAt + LF;
	out += 'Base...........: ' + this.base + LF;
	return out;
}
new ImageMap();
ImageMap.prototype.toString           = ImageMap_toString;
ImageMap.prototype.addImageMapping    = ImageMap_addImageMapping;
ImageMap.prototype.getImageMapping    = ImageMap_getImageMapping;
ImageMap.prototype.getImageMappings   = ImageMap_getImageMappings;



/*
+ ---------------------------------------------------------------------------------+
| Object....: Icon
| Function..: An Image object
| Arguments.: id, resPath, src, width, height, tooltip, alt
|
| Date        Author            Note
| ----------  ----------------  ----------------------------------------------------
| 17.08.2004  G.Schulz (SCC)    Initial version
| 22.11.2004  G.Schulz (SCC)    Hide ALT + TITLE if null
+ ---------------------------------------------------------------------------------+
*/
function Icon(id, resPath, src, width, height, tooltip, alt) {
	this.id        = id;             // unique button id
	this.width     = width;          // button width
	this.height    = height;         // button height
	this.src       = src;            // src-Attribute
	this.onclick   = Icon_onclick;
	this.resPath   = resPath;
	this.tooltip   = tooltip;        // Tooltip
	this.alt       = alt;
	this.border    = 0;
}
function Icon_onclick() {
	return;
}
function Icon_create() {
	var img    = document.createElement('Img');
	img.src    = this.src;
	img.title  = (null != this.tooltip) ? this.tooltip : '';
	img.alt    = (null != this.alt) ? this.alt : '';
	img.border = 0;
	img.width  = this.width;
	img.height = this.height;
	img.setAttribute('vspace', 0);
	img.border = this.border;
	return img;
}
function Icon_toString() {
	var out = '';
	out += '******* Icon *********' + LF
	out += 'Id.............: ' + this.id + LF;
	out += 'ResPath........: ' + this.resPath + LF;
	out += 'Source.........: ' + this.src + LF;
	out += 'Width..........: ' + this.width + LF;
	out += 'Height.........: ' + this.height + LF;
	out += 'Tooltip........: ' + this.tooltip + LF;
	out += 'Alt............: ' + this.alt + LF;
	out += 'Border.........: ' + this.border + LF;
	return out;
}
new Icon();
Icon.prototype.onclick    = Icon_onclick;       // used to assign an onclick handler
Icon.prototype.toString   = Icon_toString;      // toString
Icon.prototype.create     = Icon_create;        // creates a html img object

/*
+ ---------------------------------------------------------------------------------+
| Calendar Message Resources
| 
| Date        Author            Note
| ----------  ----------------  ----------------------------------------------------
| 22.05.2004  G.Schulz (SCC)    Initial version
|
+ ---------------------------------------------------------------------------------+
*/
function TextButton(id, label, width, resPath, imgSrc, imgWidth, height, tooltip) {
	this.id        = id;             // unique button id
	this.label     = label;          // the button label
	this.width     = width;          //
	this.imgWidth  = imgWidth;       // array including width of the bgimages (left, middle, right)
	this.imgSrc    = imgSrc;         // array including the image resources (left, middle, right)
	this.height    = height;         // button hight
	this.onclick   = TextButton_onclick;
	this.resPath   = resPath;
	this.tooltip   = tooltip;

	if (arguments.length <= 4) {
		// register some default images
		this.imgSrc   = ['btnBkg1_left.gif', 'btnBkg1_middle.gif', 'btnBkg1_right.gif'];
		this.imgWidth = [7, 0, 7];
		this.height   = 24;
		this.tooltip  = label;
	}
}
function TextButton_create() {
	var row   = null;
	var cell  = null;
	var img   = null;
	var span  = null;
	
	// create Table
	var table = document.createElement('Table');
	table.cellSpacing = 0;
	table.cellPadding = 0;
	table.width = (this.width - TextButton.getWidth(this.imgWidth));
	table.className = 'tbtn';
	table.onclick = this.onclick;
	
	row = table.insertRow(table.rows.length);
	row.setAttribute('valign', 'middle');
	
	// left
	cell = row.insertCell(row.cells.length);
	img = document.createElement('Img');
	img.width  = this.imgWidth[0];
	img.height = this.height;
	img.src    = this.resPath + this.imgSrc[0];
	img.border = 0;
	cell.appendChild(img);
	
	// middle
	cell = row.insertCell(row.cells.length);
	cell.width = '100%';
	cell.setAttribute('background-position', 'right');
	cell.setAttribute('word-wrap', true);
	cell.setAttribute('background', this.resPath + this.imgSrc[1]);
	
	span = document.createElement('Span');
	span.appendChild(document.createTextNode(this.label));
	span.title  = this.tooltip;
	cell.appendChild(span);
	
	// right
	cell = row.insertCell(row.cells.length);
	img = document.createElement('Img');
	img.width  = this.imgWidth[2];
	img.height = this.height;
	img.src    = this.resPath + this.imgSrc[2];
	img.border = 0;
	cell.appendChild(img);

	return table;
}
function TextButton_onclick() {
	return;
}
function TextButton_getWidth(widths) {
	var total = 0;
	
	for(var i=0; i < widths.length; i++) {
		var val = parseInt(widths[i]);
		
		if (!isNaN(val)) {
			total =+ val;
		}
	}
	return total;
}
function TextButton_toString() {
	var out = '';
	out += '******* TextButton *********' + LF
	out += 'Id.............: ' + this.id + LF;
	out += 'Label..........: ' + this.label + LF;
	out += 'BGImages.......: ' + this.imgSrc + LF;
	out += 'Tooltip........: ' + this.tooltip + LF;
	out += 'Alt............: ' + this.alt + LF;
	return out;
}
new TextButton();
TextButton.prototype.create     = TextButton_create;
TextButton.prototype.onclick    = TextButton_onclick;
TextButton.prototype.toString   = TextButton_toString;
TextButton.getWidth             = TextButton_getWidth;


/*
+ ---------------------------------------------------------------------------------+
| Object...: StringHelp
| Function.: 
|
| Date        Author            Description
| ----------  ----------------  ----------------------------------------------------
| 08.01.2005  G.Schulz          Inital version
|
+ ---------------------------------------------------------------------------------+
*/

function StringHelp() {
}
function StringHelp_truncate(str, maxlength) {
	if ((maxlength == -1) || (str == null) || (str.length <= maxlength)) {
		return str;
	} else {
		return str.substring(0, maxlength) + '...';
	}
}
new StringHelp();
StringHelp.truncate = StringHelp_truncate;


