// Globals
var qs          = new String( location.search.substring(1) );
var doPageBury  = new Boolean();

function checkCookie()
{
    // Get the cookies
    var allcookies = document.cookie;

    // Is our cookie there?
    var pos = allcookies.indexOf( "unique=" );
    if( pos != -1 )
    {
    	// Yup... send them to login
	// We need to pass along the QUERY_STRING to rn_login
	location = "rn_login.cgi?arg=cc&" + qs;
    	return false;
    }
    else
    {
	// No cookie, which means they are logging in for the first
	// time.  We need to bury the passed QUERY_STRING in the
	// form to pass it along.  This triggers buryQS().
	doPageBury = true;
    }
}

function buryQS()
{
    // This only gets called if the user didn't have a previously set cookie
    // Note that while this does effectively work, it doesn't show up in the
    // page source ever...  just know that it's there:)
    if( doPageBury )
    {
	document.writeln( '<INPUT NAME = "t" TYPE = "hidden" VALUE = "' + 
	                   qs.substring(2) + '">' );
    }
}

function checkForm( theForm )
{
    // Valid username@domain?
    var valid_id = theForm.username.value.search( /^[^\@]+@[^\.]+\.\w+$/ );
    if( valid_id == -1 )
    {
	alert( 'Username must be your complete email address' );

	theForm.username.focus();
	theForm.username.select();
	
	return false;
    }

    // They have provided the appropriate data?
    if( theForm.auth_value.value == "" )
    {
	alert( 'You need to provide your ' + 
	       theForm.auth_option[theForm.auth_option.selectedIndex].value );

	theForm.auth_value.focus();

	return false;
    }

    return true;
}
