﻿//Visualalized and Developed by Salvatore Joseph Aiello
//Dested@gmail.com
//10/22/08 v0.4
var $_ = function(id) {
    return document.getElementById(id);
}
var HTML = {
	TEXT: function(id, value, text) {
		var div = HTML.DIV();
		if (text)
			HTML.APPEND(div, HTML.SPAN(text));

		var d = document.createElement('input');
		d.setAttribute('type', 'text');
		if (id) d.setAttribute('id', id);
		if (value) d.setAttribute('value', value);
		HTML.APPEND(div, d);
		return div;
	},
	HIDDEN: function(id, value) {
		var d = document.createElement('input');

		d.setAttribute('type', 'hidden');
		if (id) d.setAttribute('id', id);
		if (value) d.value = value;
		return d;
	},
	DIV: function(id) {
		var d = document.createElement('div');
		if (id) d.setAttribute('id', id);
		d.style.display = 'inline';
		return d;
	},
	ADD: function(first, second) {
		first.appendChild(second);
	},

	CLEARADD: function(first, second) {
		for (var c = first.childNodes.length-1; c >= 0; c--)
			first.removeChild(first.childNodes.item(c));
		first.appendChild(second);
	},
	SPAN: function(text) {
		var d = document.createElement('span');
		if (text) d.innerHTML = text;
		return d;
	},
	SUBMIT: function(id, text, onclick) {

		var d = document.createElement('input');
		d.setAttribute('type', 'submit');
		if (id) d.setAttribute('id', id);
		if (text) d.setAttribute('value', text);
		if (onclick) d.setAttribute('onclick', onclick);
		return d;
	},
	APPEND: function(a, b) {
		a.appendChild(b);
	},
	LINK: function(href, text, onclick) {
		var a = document.createElement('a');
		a.href = href;
		a.innerHTML = text;
		if (onclick)
			a.setAttribute('onclick', onclick);
		return a;
	},
	RADIO: function(id, selected, value, name, onclick) {
		var rad = document.createElement('input');
		rad.setAttribute('type', 'radio');
		if (id) rad.setAttribute('id', id);
		if (name) rad.setAttribute('name', name);
		if (selected) rad.setAttribute('checked', selected ? 'checked' : '');
		if (value) rad.setAttribute('value', value);
		if (onclick) rad.setAttribute('onclick', onclick);
		return rad;
	},
	FOR: function(for_, text) {
		var rad = document.createElement('label');
		rad.setAttribute('for', for_);
		rad.innerHTML = text;
		return rad;
	},
	BR: function() {
		return document.createElement('br');
	},
	RADIOLIST: function(id, text, items, default_) {
		var div = HTML.DIV();
		HTML.APPEND(div, HTML.SPAN(text));

		var table = document.createElement('table');
		table.setAttribute('id', id);
		var count = 0;
		var tr = document.createElement('tr');
		for (var i = 0; i < items.length; i++) {
			var item = items[i];
			var td = document.createElement('td');
			var r = HTML.RADIO(id.replace('Field', '') + "_" + count, item.selected, item.value, id, item.onclick);
			var f = HTML.FOR(r.id, item.text);
			HTML.APPEND(td, r);
			HTML.APPEND(td, f);
			HTML.APPEND(tr, td);
			count++;
		}
		HTML.APPEND(table, tr);
		HTML.APPEND(div, table);
		return div;
	}
}
 
 