var formname	=	'form-login';
var timeoutsessionid = 0;
var sessionsecs = 0;

function closeSession()
{
	//alert('session timeout');
	window.location = '/login.php?mode=timeout';
}

function initSessionTimeout(secs)
{
	//alert(timeoutsessionid + ' ' + sessionsecs);
	sessionsecs = secs;
	if (timeoutsessionid > 0)
	{
		clearTimeout(timeoutsessionid);
	}
	timeoutsessionid = setTimeout('closeSession()', secs * 1000); 
}

function refreshSession()
{
	if (sessionsecs > 0)
	{
		initSessionTimeout(sessionsecs);
	}
}

function querySt(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0; i<gy.length; i++)
	{
		ft = gy[i].split("=");
		if (ft[0] == ji)
		{
			return ft[1];
		}
	}
	
	return '';
}

function validate_form()
{
//	alert(querySt('url'));
	var redir_url = $('login-url').value;
	
	$(formname).request(  {
		onSuccess: function(transport){
			response = transport.responseXML.documentElement;
			//alert(transport.responseText);
			$('login-status').update('');
			if(response.getElementsByTagName('result_flag')[0].childNodes[0].firstChild.nodeValue=="true") {
				$('login-status').update('Login Successful');
				$('redir_username').value = $('l-username').value;
				$('redir_password').value = $('l-password').value;
				if (redir_url != undefined)
				{
					$('redir_url').value = redir_url;
				}
				else
				{
					$('redir_url').value = response.getElementsByTagName('redirect')[0].childNodes[0].firstChild.nodeValue;
				}
				$('redir-form').submit();
			} else {
				$('login-status').update(response.getElementsByTagName('result_flag')[0].childNodes[0].firstChild.nodeValue);
			}
		},
		onLoading: function() {
			$('login-status').update('<img src="/img/ajax-loader.gif" width="16" height="16" border="0" /> Verifying...');
		}
	});
	return false;
}

function registerUser()
{
	window.location = "account.php?mode=add";
}

function loadLoginForm()
{
	new Ajax.Updater('login-form','/login.php?mode=form', {method: 'get', evalJS: true, onComplete: function() { $('l-username').focus(); } });
}

function getData()
{
	var c = $('character').value;
	var r = $('realm').value;
	
	url = 'http://www.wowarmory.com/character-sheet.xml';
	pars = 'r=' + r + '&c=' + c;

	myAjax = new Ajax.Request(url,
							{ method: 'get',
								parameters: pars,
								onSuccess: function(t) {
									alert(t.responseText);
								},
								onFailure: function(t) {
									alert('fail');
								}
							}
						);

}

function closeopen(tagid)
{
	$(tagid).style.display = ($(tagid).style.display == "block") ? 'none' : 'block';
}

function closediv(tagid)
{
	$(tagid).style.display = 'none';
}

function showLookup(s)
{
	if (s != 'search') { $('search-form').style.display = 'none'; $('l-search').style.background = '#000000'; $('l-search').style.color = '#8e724b'; }
	if (s != 'guild') { $('guild-form').style.display = 'none'; $('l-guild').style.background = '#000000'; $('l-guild').style.color = '#8e724b'; }

	$(s + '-form').style.display = 'block';
//	alert($('l-' + s).className);
	if (s != 'login')
	{
		$('l-' + s).style.background = '#7e623b';
	}
	$('l-' + s).style.color = '#ffd200';
//	alert($('l-' + s).className);
}

function removeToon(t)
{
	if (confirm('Are you sure you want to remove this Toon from your profile?'))
	{
		window.location = "toon.php?mode=remove&t=" + t;
	}
}

