// areg validation functions
function validate_email(field,alerttxt) 
{
	with (field)
	{
		if ((value.indexOf(".") > 2) && (value.indexOf("@") > 0))
		{
			return true;
		}
		else
		{
  			alert(alerttxt);
			return false;
		}
	}
}

function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value=="")
		{
  			alert(alerttxt);
			return false;
		}
		else 
		{
			return true;
		}
	}
}

function isValid(string,allowed)
{
    for (var i=0; i < string.length; i++)
    {
        if( allowed.indexOf(string.charAt(i)) == -1 )
        {
             return false;
        }
    }
    return true;
}

function validate_areg_form(thisform)
{
	with (thisform)
	{
		if (validate_required(email,"Please supply your e-mail address")==false)
		{
			email.focus();
			return false;
		}

		if (validate_email(email,"Please supply a valid e-mail address")==false)
		{
			email.focus();
			return false;
		}

		if (validate_required(alias,"Please supply your user name")==false)
		{
			alias.focus();
			return false;
		}

        var valid = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'; // define valid characters

        if( isValid(alias.value,valid) == false )
        {
            alert("Aliases should contain letters, numbers and underscore (_) only");
            pass1.focus();
            return false;
        }

        var valid = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; // define valid characters

        if( isValid(pass1.value,valid) == false )
        {
            alert("Passwords should contain letters and numbers only");
            pass1.focus();
            return false;
        }

		if (validate_required(pass1,"Please supply a password")==false)
		{
			pass1.focus();
			return false;
		}

		if (pass1.value != pass2.value)
		{
			alert("The two passwords entered must be the same");
			pass2.focus();
			return false;
		}

		if( !accept.checked ) 
		{
			alert("Please tick the box to confirm that you have read and understood the Ulinx terms and conditions");
			return false;
		}
	}
}


