/*
Gain and Watts Calculator Copyright (C) 2005 Giacomo Cau

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
*/

var debug = false;

function tag(t, e) {

	if (e) return emptytag;
	return fulltag

	function gt() {
		 return debug ? '&gt;' : '>';
	}
	
	function lt() {
		return debug ? '&lt;' : '<';
	}

	function tagon(t, o) {
		document.write( lt() + t );
		if (o) {
			var s = ''
			for (var p in o) {
				s += p + '="' + o[p] + '" '
			}
			document.write( ' ', s );
		}
		document.write( gt() );
	}
	
	function tagoff(t) {
		document.write( lt() + '/' + t + gt() )
	}

	function emptytag () {
		var a = arguments
		return function () {
			tagon( t, a[0] );
		}
	}
	
	function fulltag () {
		var a = arguments
		if (a.length == 0) {
			return function () {
			 	tagon(t);
				tagoff(t)
			}
		} 
		else {
			return function () {
				var i=a[0].constructor == Object ? 1 : 0					
				if (i) {
					tagon(t, a[0])
				}
				else {
					tagon(t)
				}
				for (; i<a.length; i++) {
					if (a[i].constructor == Function) {
						//alert(t + ' fn ' + a[i]);
						(a[i])()
					}
					else {
						//alert(t + ' vn ' + a[i]);
						document.write(' ' + a[i])
					}
				}
				tagoff(t)
			}
		}
	}
}

function html() {
	for (var i=0; i<arguments.length; i++) {
		if (arguments[i].constructor == Function) {
			(arguments[i])()
		}
		else {
			document.write(' ' + arguments[i])
		}
	}
}
		
table = tag('table')
tr = tag('tr')
td = tag('td')
a = tag('a')

div = tag('div')
center = tag('center')	
font = tag('font')	
img = tag('img', true)
br = tag('br', true)

/*
html(
	table({border:6},
		tr(
			function () {
				for (var i=0; i<3; i++) {
					html(
						td('pippo'+i)
					)
				}
			},
			td('ciccia'),
			td(
				img({src:"image1.png"})
			)
		)
	) 
)
*/
	
	 