tempWindow = false;

function colorFade(inic, finc, step, idx) {
	var i;
	var o;
	var f;
	var n;
	var fade = "#";
	inic = inic.substr(1);
	finc = finc.substr(1);

	for (i = 0; i < 6; i += 2) {
		o = parseInt("0x" + inic.slice(i,i+2));
		f = parseInt("0x" + finc.slice(i,i+2));
		n = Math.floor((o + idx * (f - o) / step)).toString(16);
		fade += n.length < 2 ? ("0" + n) : n;
	}

	return fade;
}

function notpreload(obj, src) {
	eval(obj + ' = new Object()')
	eval(obj + '.src = "' + src + '"')
}

function preload(obj, src) {
	if (document.images) {
		eval(obj + ' = new Image()')
		eval(obj + '.src = "' + src + '"')
	}
}

function changeImage(src, obj) {
	if (document.images) {
		document.images[src].src = eval(obj+".src")
	}
}

function loadAndChange(obj, src) {
	if (document.images) {
		eval(obj + ' = new Image()')
		eval(obj + '.src = "' + src + '"')
		document.images[src].src = eval(obj+".src")
	}
}

function closePopup() {
	if (tempWindow && !tempWindow.closed) {
		tempWindow.close();
		tempWindow = false;
		return tempWindow;
	}
}

function openPopup(page, w, h, n) {
	if (!w) w = 336;
	if (!h) h = 360;
	if (!n) n = "tmp";
	if (!tempWindow || tempWindow.closed) {
		tempWindow = window.open(page, n, "left=0,top=0,toolbar=no,width=" + w + ",height=" + h + ",directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");
		if (!tempWindow.opener) {
			tempWindow.opener = window;
		}
	} else {
		tempWindow.location = page;
	}
	tempWindow.focus();
}

function Google() { 
	//http://home/db/test.awk
	document.location = "http://www.google.com/search?q=" + escape(document.google.q.value) + "+site%3Amia.openworldlearning.org%2F&filter=0" 
	return false
}

function GoMsg() {
	var n = document.gomsg.n.value.toString()
	for (var i = n.length; i < 5; i++) n = "0" + n
	//alert("http://home/mia/mwforum/msg" + n + ".html")
	//mia.openworldlearning.org
	document.location = "http://mia.openworldlearning.org/mwforum/msg" + n + ".html"
	return false
}


function Table(d) {
	var k
	var s
	var k0
	var f

	var t = ""
	for (var i = 0; i < d.length; i++) {
		s = ""
		for (var j = 0; j < d[i].length; j++) {
			k = (d[i])[j]
			if (k[1] == '') {
				s += td("0","bgcolor='#eeeeee' align='right'")
			} else if (k[0] == '') {
				s += td(k[1])
			} else {
				k0 = k[0]
				for (o = k0.length; o < 5; o++) k0 = "0" + k0
				s += td(anchor("msg" + k0 + ".html",k[1]),"bgcolor='#eeeeee' align='right'")
			}
		}
		t += tr(s)
	}
	document.write(table(t,"border=0 cellspacing=3 cellpadding=1"))
}

function obfuscate(dom,name) {
	return name + "@" + dom.replace(/#/g,'.')
}

function email(dom,name,attr,content,subject,body) {
	var address = obfuscate(dom,name);
	var mailto = address;

	if (!content) content = address
	if (subject) mailto = mailto + "?subject=" + subject.replace(/ /g,"%20");
	if (body) mailto = mailto + "&amp;body=" + body.replace(/ /g,"%20");
	document.write('<a ' + attr + ' href="mailto:' + mailto + '">' + content + '</a>');
}

function check_address(field,f) {
	var fieldvalue=document.getElementById(field).value
	var filter=/^([\w-]+(\.[\w-]+)*)@(([\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(\.[a-z]{2})?)$/i

	if (filter.test(fieldvalue)) {
		return true;
	}
	f();
	return false;
}

function img(src, attrs) {return "<img src='" + src + "'" + (attrs ? " " + attrs : "")  + ">"}
function table(body, attrs) {return "<table" + (attrs ? " " + attrs : "") + ">" + body + "</table>"}
function tr(body, attrs) {return "<tr" + (attrs ? " " + attrs : "") + ">" + body + "</tr>"}
function td(body, attrs) {return "<td" + (attrs ? " " + attrs : "") + ">" + body + "</td>"}
function th(body, attrs) {return "<th" + (attrs ? " " + attrs : "") + ">" + body + "</th>"}
function anchor(URL, body, attrs) {return "<a" + (attrs ? " " + attrs : "") + " href='" + URL + "'>" + body + "</a>"}
function center(body) {return "<center>" + body + "</center>"}

	