/* ${__APPLICATION_VERSION__} */

eds.webapp.widget.Widget = function(domIds) {

	/* get runtime element. html elements that are created at when the page
	 * loads.
	 */
	this.getRtEl = function(id) {
		return document.getElementById(id);
	}

	this.getId = function(key) {
		if ( !domIds ) {
			throw "Cannot get elements without a DomIds. " + this.toString() + " " + key;
		}
		return domIds.getId(key);
	}

	this.getEl = function(id) {

		if ( !domIds ) {
			throw "Cannot get elements without a DomIds. " + this.toString() + " " + key;
		}
		return document.getElementById(domIds.getId(id));
	}

	this.getElValue = function(id) {
		var el = this.getEl(id);
		if ( el ) {
			return el.value;
		} else {
			throw 'Cannot get value for nonexistent element. ID: ' + id + '.';
		}
	}

	this.setElValue = function(id, value) {
		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot set value for nonexistent element. ID: ' + id + '.';
		}
		el.value = value;
	}

	this.enableEl = function(id) {
		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot enable nonexistent element. ID: ' + id + '.';
		}
		el.disabled = false;
	}

	this.disableEl = function(id) {
		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot disable nonexistent element. ID: ' + id + '.';
		}
		el.disabled = true;
	}

	this.getElHtml = function(id) {
		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot set HTML of nonexistent element. ID: ' + id + '.';
		}
		return el.innerHTML;
	}

	this.setElHtml = function(id, html) {
		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot set HTML of nonexistent element. ID: ' + id + '.';
		}
		el.innerHTML = html;
	}

	this.setElSrc = function(id, url) {
		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot set source of nonexistent element. ID: ' + id + '.';
		}
		el.src = url;
	}

	this.getElStyle = function(id, property) {
		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot get style of nonexistent element. ID: ' + id + '.';
		}

		if (property) {
			return el.style[property];
		} else {
			return el.style;
		}
	}

	this.setElStyle = function(id, property, value) {

		var el;

		if ( !id || !property || !value ) {
			throw "Invalid arguments to setElStyle.";
		}

		var el = this.getEl(id);
		if ( !el ) {
			throw 'Cannot get style of nonexistent element. ID: ' + id + '.';
		}

		el.style[property] = value;
	}
}

