// Function that represents an Attribute
function Attribute(name, value) {
	this.name = name;
	this.value = value;
}

// Convenience function to add Textbox element
function addTextbox (id, value, attributes, isDisabled, tableData) {
	var textboxElem = document.createElement("input");
	textboxElem.type = 'text';
	textboxElem.name = id;
	textboxElem.id = id;
	textboxElem.value = value;
	if (attributes != null) {
		for (i in attributes) {		
			textboxElem.setAttribute(attributes[i].name, attributes[i].value);
		}
	}	
	textboxElem.disabled = isDisabled;
	tableData.appendChild(textboxElem);	
}

//Convenience function to add spaces
function addSpaces(tableData, numberOfSpaces) {
	for (i = 0; i < numberOfSpaces; i++) {
		tableData.appendChild(document.createTextNode("\u00a0"));	
	}	
}

//Convenience function to add Option to Select box elements
function addOption (selectElem, text, value, selectedValue) {
	var selectOption = document.createElement("option");
	selectOption.text = text;
	selectOption.value = value;
	if (text == selectedValue || value == selectedValue) {
		selectOption.selected = true;
	}	
	selectElem.options.add(selectOption);
}

//Convenience function to add Checkbox element
function addCheckbox(id, checked, tableData, onClickText, isDisabled) {
	var checkboxElem = document.createElement("input");
	checkboxElem.type = 'checkbox';
	checkboxElem.name = id;
	checkboxElem.id = id;
	checkboxElem.defaultChecked = checked;	
	if (onClickText && onClickText != null && onClickText != '') {
		checkboxElem.onclick = Function(onClickText);
	}	
	checkboxElem.disabled = isDisabled;
	tableData.appendChild(checkboxElem);	
}

//Convenience function to add Anchor element
function addAnchor(onclickText, imgSource, elemToAddTo, imgId, imgBorder, toolTip, imgHeight, imgWidth, imgAlignment, imgPosition, imgTop) {
	var anchor = document.createElement('a');
	anchor.setAttribute('href', '#');
	anchor.onclick = Function(onclickText);
	var imgElem = createImageElement(imgId, imgSource, toolTip, imgBorder, imgHeight, imgWidth, imgAlignment, imgPosition, imgTop);	
	anchor.appendChild(imgElem);
	elemToAddTo.appendChild(anchor);
}

function createImageElement(imgId, imgSource, toolTip, imgBorder, imgHeight, imgWidth, imgAlignment, imgPosition, imgTop) {
	var img = document.createElement('img');
	img.name = imgId;
	img.id = imgId;
	img.setAttribute('src', imgSource);
	img.style.verticalAlign = 'middle';
	if (toolTip) {
		img.setAttribute('title', toolTip);
		img.setAttribute('alt', toolTip);		
	}
	if (imgBorder) {
		img.setAttribute('border', imgBorder);
	}
	if (imgHeight) {
		img.setAttribute('height', imgHeight);	
	}
	if (imgWidth) {
		img.setAttribute('width', imgWidth);
	}
	if (imgAlignment) {
		img.setAttribute('align', imgAlignment);		
	}
	if (imgPosition) {
		img.style.position = imgPosition;
	}
	if (imgTop) {
		img.style.top = imgTop;
	}
	return img;
}
