function get_none(timeout,url,dstid) {
	return false;
}
function get_async(timeout,url,dstid) {
	var request = new XMLHttpRequest();
	var el = document.getElementById(dstid);
	if (!el)
		return;
	var par = el.parentNode;
	// don't cross the http<->https boundary
	if (url[0] == 'h') {
	var ishttps = document.location.href.indexOf("https") == 0;
	if (ishttps && url.indexOf("https") != 0) {
		url = 'https' + url.substr(4);
	}
	if (!ishttps && url.indexOf("https") == 0) {
		url = 'http' + url.substr(5);
	}
	}
	if (url.substr(0, 2) == '//') {
		url = url.substr(1);
	}
	request.open("GET",url,false);
	//request.onreadstatechange = handler;
	var t = '';
	try {
		request.send(null);
		t = request.responseText;
	} catch(e) {
		// silently retry
	}
	if (timeout < 5000) {
		timeout += 1000;
	}
	if (!t || (t == '') || (t == 'None') ) {

		window.setTimeout('get_async('+timeout+',"' + url + '","'+dstid + '");', timeout);
	} else {
		if (t.indexOf('FINAL') != -1) {
			t = t.replace(/get_async/,'get_none');
			//if (updatelinks) { updatelinks(); }
		} else {
			window.setTimeout('get_async('+timeout+',"' + url + '","'+dstid + '");', timeout);
		}
		el.innerHTML = t;
	}
}

function showel(id) {
	var e = document.getElementById(id);
	if (!e)
		return;
	e.style.visibility = "visible";
	e.style.display = "block";
	e.className = e.className.replace(/hidden/,'');
}
function hideel(id) {
	var e = document.getElementById(id);
	if (!e)
		return;
	e.style.visibility = "hidden";
	e.style.display = "none";
	e.className += ' hidden';
}

function showexpired() {
	var items = document.getElementsByTagName("li");
	var j;
	for(j = 0; j < items.length; j++) {
		var i = items[j];
		if (i.className && i.className.indexOf("oldrecord")!=-1) {
			i.className = i.className.replace(/hidden/,'');
		}
	}
	hideel('expiredlink');
	return false;
}


function addcomment() {
	showel('addcommentform');hideel('addcommentlink');return false;
}

function showsnap(u,d) {
	var e = document.getElementById('snapimg');
	if (!e) { return; }
	e.src = u;
	e = document.getElementById('snapdate');
	if (!e) { return; }
	e.innerHTML = d;
}


function b64decode(s) {
	var i;
	var r = "";
	s = s.replace(/ \n\r\t/g,'');
	//alert(":" + s + ":");
	for(i = 0; i < s.length-3; i+=4) {
		var a = [], b = [], c = [], d = [];
		for(j = 0; j < 4; j++) {
			c[j] = s.charAt(i+j);
			b[j] = s.charCodeAt(i+j);
			if (b[j] < 'A'.charCodeAt(0)) {
				a[j] = b[j] - '0'.charCodeAt(0) + 52;
			} else if (b[j] <= 'Z'.charCodeAt(0)) {
				a[j] = b[j] - 'A'.charCodeAt(0);
			} else if (b[j] <= 'z'.charCodeAt(0)) {
				a[j] = b[j] - 'a'.charCodeAt(0) + 26;
			} else {
				return r;
			}

		}
		d[0] = String.fromCharCode(((a[0] << 2) | (a[1] >> 4))&0xff);
		d[1] = String.fromCharCode((((a[1] & 0x0f) << 4) | (a[2] >> 2))&0xff);
		d[2] = String.fromCharCode((((a[2] & 0x03) << 6) | a[3])&0xff);

		r = r + d.join("");

		//document.write("<p>" + c.join(',')+ " " + b.join(',') + "  " + a.join(',') + " " + d.join(',') + "</p>");
	}
	return r;
}

function whois_decode() {
	var p = document.getElementById("whoisdata");
	var o = document.createElement("pre");
	var t = document.createElement("p");
	o.id = "whoisoverlay";
	if (!p)
		return;
	var h = p.innerHTML;
	p.innerHTML = "";
	try {
		t.innerHTML = b64decode(h);
	} catch(e) {
	}
	//p.appendChild(o);
	p.appendChild(t);
	showel("whoisdata");
}

