mouseX = 0;
mouseY = 0;
comment = "";
alias = "";
isok = "";
passcheck = "";
pass1 = "";
pass2 = "";
block = "";
hdn = "";
btn = "";

function init( ct, show_options )
{
	comment = document.getElementById( "commentField" );
	comment.disabled = ct == "none";

	alias = document.getElementById( "aliasField" );
	isok = document.getElementById( "isok" );
	passcheck = document.getElementById( "passcheck" );
	pass1 = document.getElementById( "pass1" );
	pass2 = document.getElementById( "pass2" );

	block = document.getElementById( "options" );
	hdn = document.getElementById( "optionsHdn" );
	btn = document.getElementById( "optionsBtn" );
	block.style.display = show_options ? "block" : "none";
	hdn.value = show_options ? "1" : "";
	btn.innerHTML = show_options ? "Hide Extra Options" : "Show Extra Options";
}

function toggleOptions()
{
	var is_on = block.style.display == "block";
	block.style.display = is_on ? "none" : "block";
	hdn.value = is_on ? "" : "1";
	btn.innerHTML = is_on ? "Show Extra Options" : "Hide Extra Options";
}

function comment_no()
{
	comment.value = "";
	comment.disabled = true;
}

function comment_yes()
{
	comment.disabled = false;
}

function savePosition(e)
{
	if ( !e ) e = window.event;
	p = e.pageX;

	if ( typeof( p ) != "undefined" )
	{
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else
	{
		mouseX = e.clientX+( document.documentElement.scrollLeft || document.body.scrollLeft );
		mouseY = e.clientY+( document.documentElement.scrollTop || document.body.scrollTop );
	}
}


function showTooltip(e,message)
{
	savePosition(e);

	tt = document.getElementById( "tooltip" );
	tt.innerHTML = message;
	tt.style.left = (mouseX+20)+"px";
	tt.style.top = (mouseY-20)+"px";
	tt.style.display = "block";	
}

function hideTooltip()
{
	document.getElementById( "tooltip" ).style.display = "none";
}

function checkAlias()
{
	//alias.value = alias.value.toLowerCase();
	var a = alias.value;

	AjaxRequest.get(
	{
		'url': "check.php?alias="+encodeURIComponent(a),
		'onSuccess': function(req){ setCheckResult( req.responseText ); },
		'onInteractive': function(req){ setWaiting(); },
		'onLoaded': function(req){ setWaiting(); },
		'onLoading': function(req){ setWaiting(); }
	} );
}

function setCheckResult( output )
{
	var c = output == "OK" ? "0e0" : "e00";
	isok.style.color = "#"+c;
	isok.innerHTML = output;
}

function setWaiting()
{
	isok.innerHTML = '<img src="image/loading.gif" />';
}

function checkPasswd()
{
	if ( pass1.value == "" && pass2.value == "" )
	{
		passcheck.innerHTML = "";
	}
	else if ( pass1.value == pass2.value )
	{
		passcheck.style.color = "#0e0";
		passcheck.innerHTML = "OK";
	}
	else
	{
		passcheck.style.color = "#e00";
		passcheck.innerHTML = "not equal";
	}
}
