// $Id: naf.js,v 1.7 2003/10/27 15:03:40 willh Exp $
////////////////////////////////

function checkForm( tf )
{
    if( tf.orgname.value == "" )
    {
	alert( 'Organization Name is required' );

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

    if( tf.orgaddr.value == "" )
    {
	alert( 'Organization Address is required' );

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

    if( tf.orgzip.value == "" )
    {
	alert( 'Organization City, State, and Zipcode are required' );

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

    if( tf.orgphn.value == "" )
    {
	alert( 'Organization Phone Number is required' );

	tf.orgphn.focus();
	return false;
    }
    else
    {
	if( tf.orgphn.value.search( /^\d{3,3}[\-\.\/]?\d{3,3}[\-\.\/]?\d{4,4}$/ ) == -1)
        {
            alert( 'Organization Phone Number does not look like\n' +
                   'a valid number.  Valid numbers look like:\n\n' +
                   '515-555-1212\n515.555.1212\n515/555/1212\n5155551212\n' );

            tf.orgphn.focus();
            tf.orgphn.select();

            return false;
        }
    }


    if( tf.orgfax.value != "" )
    {
	if( tf.orgfax.value.search( /^\d{3,3}[\-\.\/]?\d{3,3}[\-\.\/]?\d{4,4}$/ ) == -1)
        {
            alert( 'Organization Fax Number does not look like\n' +
                   'a valid number.  Valid fax numbers look like:\n\n' +
                   '515-555-1212\n515.555.1212\n515/555/1212\n5155551212\n' );

            tf.orgfax.focus();
            tf.orgfax.select();

            return false;
        }
    }

    if( tf.techname.value == "" )
    {
	alert( 'Technical Contact Name is required' );

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

    if( tf.techaddr.value == "" )
    {
	alert( 'Technical Contact Address is required' );

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

    if( tf.techzip.value == "" )
    {
	alert( 'Technical Contact City, State, and Zipcode are required' );

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

    if( tf.techphn.value == "" )
    {
	alert( 'Technical Contact Phone Number is required' );

	tf.techphn.focus();
	return false;
    }
    else
    {
	if( tf.techphn.value.search( /^\d{3,3}[\-\.\/]?\d{3,3}[\-\.\/]?\d{4,4}$/ ) == -1)
        {
            alert( 'Technical Contact Phone Number does not look like\n' +
                   'a valid number.  Valid numbers look like:\n\n' +
                   '515-555-1212\n515.555.1212\n515/555/1212\n5155551212\n' );

            tf.techphn.focus();
            tf.techphn.select();

            return false;
        }
    }



    if( tf.techemail.value == "" )
    {
	alert( 'Technical Contact E-Mail is required' );

	tf.techemail.focus();
	return false;
    }
    else
    {
	if( tf.techemail.value.search( /^[^\@]+\@([^\.]+\.)*?[^\.]+\.\w+$/ ) == -1 )
	{
	    alert( 'Technical Contact E-Mail does not look like\n' +
		   'a valid e-mail address' );

	    tf.techemail.focus();
	    tf.techemail.select();

	    return false;
	}
    }
    
    var foundSubnet = false;
    for( var x=0;x<tf.subnet_req.length;x++ )
    {
	if( tf.subnet_req[x].checked )
	{
	    foundSubnet = true;

	    if( tf.subnet_req[x].value == "other" )
 	    {
		if( (tf.other_subnet_req.value == "") || 
		    (tf.other_subnet_req.value == "other") )
		{
		    alert( 'You must briefly explain your Subnet needs' );

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

    if( !foundSubnet )
    {
	alert( 'You must choose what Subnet of IP you need' );

	tf.subnet_req[0].focus();
	return false;
    }

    if( tf.dns.value == "" )
    {
	alert( 'You must define what DNS servers you would like to use' );

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

    if( tf.reason.value == "" )
    {
	alert( 'You must provide a detailed reason for this request' );

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

    return true;
}

function setFocus( tgt )
{
    var element = eval( 'document.theForm' );
    if( element == '[object HTMLFormElement]' ||
        element == '[object]' )
    {
        eval( 'document.theForm.' + tgt + '.focus();' );
    }
}