// Common stuff for Basic Showcase pages
////////////////////////////////////////////////

function mainPageSearchForm( tf )
{
   // Cycle through the choices... 100 is an arbitrary number
   for( j = 0; j < 100; j++ )
   {
        if( tf["box"+j] )
        {
            if( tf["box"+j].checked )
            {
                return true;
            }
        }
        else
        {
            //We've made it past all the available boxes and not found one,
            //Error out that they need to select one.
            alert( "You must select at least one category to search for." );
            return false;
        }
   }
   //This is here to pretty much catch anything that goes over the count of the
   //for() loop in the future.
   alert( "You must select at least one category to search for." );
   return false;
}
////////////////////////////////////////////////

function signupFirstPage( tf )
{
    if( tf.register_name.value == "" )
    {
	alert( 'You must enter your username' );

	tf.register_name.focus();

	return false;
    }

    return true;
}
////////////////////////////////////////////////

function signupMainForm( tf )
{
    // First, check to see if the username and password fields actually 
    // have something in them.
    if( tf.password.value == "" )
    {
        alert( "You must provide your password for identification" );
        tf.password.focus();
        return false;
    }
    if( tf.areaname.value == "" )
    {
        alert( "You must provide an areaname for your site." );
        tf.areaname.focus();
        return false;
    }
    else
    {
	if( tf.areaname.value.search( /[^0-9a-z]/ ) != -1 )
	{
	    alert( "Areanames can only contain a-z and 0-9" );

	    tf.areaname.focus();
	    tf.areaname.select();

	    return false;
	}
    }


    // Check for length requirements of the areaname
    if( (tf.areaname.value.length > 20) || (tf.areaname.value.length < 3) )
    {
        alert( "areanames can only be between 3 and 20 characters.  You have "+tf.areaname.value.length+"." );
        tf.areaname.focus();
	tf.areaname.select();
        return false;
    }

    if( tf.desc.value == "" )
    {
        alert( "A description of your site is necessary to process this order." );
        tf.desc.focus();
        return false;
    }
    else
    {
	if( tf.desc.value.search( /\\|\|/ ) != -1 )
	{
	    alert( "Descriptions cannot contain \\ or |" );

	    tf.desc.focus();
	    tf.desc.select();

	    return false;
	}
    }

    var counter = 0;
    // Cycle through the choices... 100 is an arbitrary number
    for( j = 0; j < 100; j++ )
    {
        if( tf["box"+j] )
        {
            if( tf["box"+j].checked )
            {
                counter++;
            }
        }
    }

    // Now just check to see if we have more than 10 boxes checked.. if so, error.
    // if not, let it pass to the backend.
    if( counter > 10 )
    {
        alert( "You can only have up to 10 categories selected.\nYou have "+ counter );
        return false;
    }
    else if( counter == 0 )
    {
        //We have made it past all the available boxes and not found one,
        //Error out that they need to select one.
        alert( "You must select at least one category to describe the site." );
        return false;
    }
    else
    {
        return true;
    }
}
////////////////////////////////////////////////

function statsFirstPage( tf )
{
    if( tf.areaname.value == "" )
    {
	alert( "You must enter an areaname" );
	tf.areaname.focus();

	return false;
    }

    return true;
}
////////////////////////////////////////////////

function diskspaceFirstPage( tf )
{
    if( tf.username.value == "" )
    {
	alert( "Please enter your username" );
	
	tf.username.focus();
	return false;
    }

    if( tf.password.value == "" )
    {
	alert( "Please enter your password" );
	
	tf.password.focus();
	return false;
    }

    return true;
}
////////////////////////////////////////////////

function prefsFirstPage( tf )
{
    if( tf.username.value == "" )
    {
	alert( 'You must provide your username.' );

	tf.username.focus();
	return false;
    }

    return true;
}
////////////////////////////////////////////////

function prefsChangePage( tf )
{
    if( tf.password.value == "" )
    {
        alert( "You must provide your email password to identify yourself." );
        tf.password.focus();
        return false;
    }

    if( tf.desc.value == "" )
    {
        alert( "A description of your site is necessary to process this order." );
        tf.desc.focus();
        return false;
    }
    else
    {
	if( tf.desc.value.search( /\\|\|/ ) != -1 )
	{
	    alert( "Descriptions cannot contain \\ or |" );

	    tf.desc.focus();
	    tf.desc.select();

	    return false;
	}
    }

    var counter = 0;
    // Cycle through the choices... 100 is an arbitrary number
    for( j = 0; j < 100; j++ )
    {
        if( tf["box"+j] )
        {
            if( tf["box"+j].checked )
            {
                counter++;
            }
        }
    }

    // Now just check to see if we have more than 10 boxes checked.. if so, error.
    // if not, let it pass to the backend.
    if( counter > 10 )
    {
        alert( "You can only have up to 10 categories selected.\nYou have "+ counter );
        return false;
    }
    else if( counter == 0 )
    {
        //We have made it past all the available boxes and not found one,
        //Error out that they need to select one.
	alert( "You must select at least one category to describe this site" );
        return false;
    }
    else
    {
        return true;
    }
}
////////////////////////////////////////////////
