if(window.addEventListener) {
	window.addEventListener('load',update_preview,false);
} else if(window.attachEvent) {
	window.attachEvent('onload',update_preview);
}

function update_preview()
{
	if(document.getElementById('text')) {
		var output = document.getElementById('text').value;
		document.getElementById('preview').innerHTML = output;
	}
	setTimeout("update_preview()",500);
}

function resize_form(input) {
	var a = input.value.split('\n');
	var b = 1;
	var c = 0;
	for(c = 0; c < a.length; c++) {
		if(a[c].length > input.cols) {
			b = b + (Math.floor(a[c].length/input.cols));
		}
	}
	b = b + a.length;
	if(b > input.rows) {
		input.rows = b;
	}
}

function hide_input(input,guide) {
	query = input.value;
	if(query == guide) {
		input.value = '';
	}
}

function show_input(input,guide) {
	query = input.value;
	if(query == '') {
		input.value = guide;
	}
}

function toggle(input)
{
	var tag = document.getElementById(input);
	if(tag.style.display == '') {
		tag.style.display = 'none';
		return;
	}
	tag.style.display = '';
}