// JavaScript Document
function describe(text) {
	document.getElementById('display').innerHTML = text;
}

function load_style2() {
	return false;
}
function vote(obj) {
	id = obj.htmlFor;
   input_obj = document.getElementById(id);
   input_obj.checked = true;
	input_obj.parentNode.className = 'selected';
	window.title = input_obj.parentNode.textContent;
   input_obj.form.submit();
}
function draw_vip_menu() {
	master_obj = document.getElementById('header');
   embryo = document.createElement("div");
	referenceElement = master_obj.getElementsByTagName('div')[0];
	var vip_menu = master_obj.insertBefore(embryo, referenceElement)
	vip_menu.id = 'vip_menu';
	if(get_cookie("username") != '') {
		vip_menu.innerHTML = '<div>Logged in as <em>'+get_cookie("username")+'</em></div>'+
		'<a href="/vip/profile/edit.php">My profile</a>'+
		'<a href="/vip/msg/index.php">Forums</a>'+
		'<a href="/vip/msg/search.php">Search</a>'+
		'<a href="/vip/profile/search.php">Find users</a>'+
		'<a href="/vip/login/logoff.php" target="_top">Log out</a>';
	}
	else {
		vip_menu.innerHTML = '<div>Not logged in</div>'+
		'<a href="/vip/index.php?rand='+Math.round(Math.random()*1000)+'">Log in</a>'+
		'<a href="/vip/login/login.php?login=newuser">Register</a>';
	}
}

function get_cookie(NameOfCookie)
{
	if (document.cookie.length > 0)
	{
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return "";
}
function doChallengeResponse(superchallenged) {
	password = document.loginform.pass.value;
	if (password)	{
		password = MD5(password);	// this makes it superchallenged!!
		document.loginform.enc_pass.value = password; 
       document.loginform.pass.value = "";
		return true;
	}
}

function _to_bin(text, foo) {
	texten = ""
	for(i=0;i<text.length;i++)
	{
		for(j=0;j<foo;j++)
		{	
			if((text.charCodeAt(i) & Math.pow(2,(foo-1-j))) != 0)	
			{
				texten += "1"
			}
			else 
			{ 
				if((i != (text.length-1)) || (j >= ((text.length*foo)%23)) )
				{ 
					texten += "0";
				}
			}
		}
	}
	return texten;
}
function _bin2numbers(text, foo)
{
	listan = new Array()
	for(i=0;((i+1)*foo-1) < text.length;i++)
	{
		listan[i] = 0
		for(j=0;j<foo;j++)
		{
			listan[i] += text.charAt(i*foo+j)*Math.pow(2,(foo-1-j)) 
		}
	}
	return listan;
}
function _bin2text(text, base)
{
	texten = ""
	for(i=0;i<text.length;i++)
	{
		if(i%base==0)
		{
			foo = 0
		}	
		foo += text.charAt(i)*Math.pow(2,(base-1-i%base)) 
		if((i%base==(base-1))||(i==(text.length-1)))
		{
			if(base==6) {foo += 128}
			texten += String.fromCharCode(foo)
		}
	}
	return texten
}
function _dec(text)
{
	bin_laden = ""
	usama_bin_laden = ""
	guts = new Array()
	enc_letters = new Array()
	bin_laden = _to_bin(text, 6)
	guts = _bin2numbers(bin_laden, 23)
	for(i=0;i<guts.length;i++)
	{
		guts[i] = Math.sqrt(2*guts[i]+1/4)-0.5
//		dump(guts[i]); 
		for(j=0;j<11;j++)
		{
			if((Math.floor(guts[i]) & Math.pow(2,10-j))!=0) {usama_bin_laden += "1"}
			else 
			{
				if((i != (guts.length-1)) || (j >= ((guts.length*11)%8)) )
				{ 
					usama_bin_laden += "0";
				}
			}
		}
	}
	usama_bin_laden = usama_bin_laden.replace(/00000000/ig,"")
	final_string = _bin2text(usama_bin_laden, 8)
	return final_string
}
function sendMail(text)
{
	location.href = "mailto:"+_dec(text)
}
function countdown() {
	obj = document.getElementById('countdown');
	now = new Date();
	linda = new Date(obj.getAttribute('date'));
	dist = linda.getTime()-now.getTime()
	if(dist > 0) {
		days_num = Math.floor(dist/86400000); dist = dist % 86400000
		hours_num = Math.floor(dist/3600000); dist = dist % 3600000
		minutes_num = Math.floor(dist/60000); dist = dist % 60000
		seconds_num = Math.floor(dist/1000);
       days_word = (days_num != 1) ? 'days':'day';
       hours_word = (hours_num != 1) ? 'hours':'hour';
       minutes_word = (minutes_num != 1) ? 'minutes':'minute';
       seconds_word = (seconds_num != 1) ? 'seconds':'second';
		obj.innerHTML = days_num+' '+days_word+', '+hours_num+' '+hours_word+', '+minutes_num+' '+minutes_word+', '+seconds_num+' '+seconds_word
		setTimeout('countdown()',1000);
   }
}
function navi(e)
{
	if(document.all) { key = event.keyCode}
	else if(parseInt(navigator.appVersion) >= 5) { key = e.which } 
	if((key==32)||(key==39)||(key==57376)) 
	{
		if(document.getElementById("next"))
		{
			document.location = document.getElementById("next").getAttribute("href")
		}
	}
	if((key==8)||(key==37)||(key==57375)) 
	{ 
		if(document.getElementById("prev"))
		{
			document.location = document.getElementById("prev").getAttribute("href")
		}
	}
	if((key==38)||(key==57373))
	{
		if(document.getElementById("index")) 
		{
			document.location = document.getElementById("index").getAttribute("href") 
		}
	}
}
function advance(obj) {
	// for surveys
	ec = 0;
	while((obj.className != 'active') && (ec < 20)) {
		obj = obj.parentNode
		ec++;
	}
	obj_old = obj
	obj = obj.nextSibling;
	while((obj.nodeType != 1) && (obj.nextSibling) && (ec < 20)) {
		obj = obj.nextSibling;
		ec++;
	}
	if(obj.nodeType == 1) {
		obj.className = 'active';
		obj_old.className = 'inactive';
	}
}