addEvent(window,'load', init, false);

function addEvent(elm, evType, fn, useCapture) 
{
  if (elm.addEventListener) {
    elm.addEventListener(evType, fn, useCapture); 
    return true; 
  } else if (elm.attachEvent) {
    var r = elm.attachEvent('on' + evType, fn); 
    return r; 
  } else {
    elm['on' + evType] = fn;
  }
}


function init()
{
	var isLoggedIn=document.getElementById('isLoggedIn').value;
	if (isLoggedIn != 0)
	{
		return true;
	}
	var signupLink=document.getElementById('loginLink');
	var cancelLink=document.getElementById('cancelLoginLink');
	//addEvent(signupLink,'click',function() {show('loginForm','email'); } ,false);
	addEvent(cancelLink,'click',function() {hide('loginForm'); } ,false);
}




function show(thingId,focusat)
{
	if (! elementExists(thingId))
	{
		return true;
	}
	
	var thing=document.getElementById(thingId);
	
	thing.style.display='block';
	if (focusat=='')
	{
		return true;
	}
	var toFocus=document.getElementById(focusat);
	toFocus.focus();
}

function hide(thingId)
{
	if (! elementExists(thingId))
	{		
		return true;
	}
	var thing=document.getElementById(thingId);
	thing.style.display='none';
}

function elementExists(eleId)
{
	if (!document.getElementById(eleId) || document.getElementById(eleId) ==
	null || document.getElementById(eleId) == "undefined")
	{
		return false;
	}
	return true;
}

function checkLogin()
{
	var rules=new Array();
	rules[0]='email:Email address|required';
	rules[1]='email:Email address|email';
	rules[2]='email:Email address|maxlength|125';
	rules[3]='pass:Password|required';
	rules[4]='pass:Password|alphanumeric';
	rules[5]='pass:Password|maxlength|50';
	var validated=performCheck('login',rules,'innerHtml');
	if (! validated)
	{
		hide('phpErrs');
		document.getElementById('errorsDiv').style.fontSize='0.7em';
		return false;
	}
	xajax.loadingFunction=function()
	{
		show('login_loading','');
		document.getElementById('loginBttn').value='Validating login...';
	}
	xajax.doneLoadingFunction=function() {
		hide('login_loading');
		
		if (document.getElementById('pass').className!='inputOk')
		{
			document.getElementById('loginBttn').disabled=false;
		}
	}
	//document.getElementById('loginBttn').disabled=true;
	xajax_ajaxLogin(xajax.getFormValues('login'));
}


function delConfirm()
{
	var confirmed=window.confirm("Are you sure you want to delete this? Note: There is no undo");
	if (confirmed)
		return true;
	else
		return false;
}

function getHomeUrl()
{
	return document.getElementById('homeurl').value;
}
