function clearField(object)
{
    object.value = "";
}

function newWindow(mypage, myname, w, h, features)
{
    if( screen.width )
    {
        var winl = (screen.width-w) / 2;
        var wint = (screen.height-h) / 2;
    }
    else
    {
        winl = 0;
        wint = 0;
    }
    if( winl < 0 ) winl = 0;
    if( wint < 0 ) wint = 0;

    var settings = 'height=' + h + ',';
    settings += 'width=' + w + ',';
    settings += 'top=' + wint + ',';
    settings += 'left=' + winl + ',';
    settings += features;

    win = window.open(mypage, myname, settings);
    win.window.focus();
}

function validate()
{
    var words;
    var result = true;

    with( document.main )
    {
        words = textName.value.split(" ");
        if( result == true &&
            (textName.value == "" || words.length < 2) )
        {
            alert("Please enter your full name.");
            textName.focus();
            textName.select();
            result = false;
        }

        textEmail.value.replace(/ /, "");
        textPhone1.value.replace(/ /, "");
        textPhone2.value.replace(/ /, "");
        textPhone3.value.replace(/ /, "");
        if( result == true )
        {
			if( textEmail.value == "" &&
                (textPhone1.value == "" &&
                 textPhone2.value == "" &&
                 textPhone3.value == "") )
			{
                alert("Please enter a valid email address or phone number.");
                textEmail.focus();
                result = false;
            }
        }

        if( result == true )
        {
            if( textEmail.value != "" )
            {
                match = textEmail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
                if( match == null )
                {
                    alert("Please enter a valid email address.");
                    textEmail.focus();
                    textEmail.select();
                    result = false;
                }
            }
        }

        if( result == true && 
            (textEmail.value == "" || textPhone1.value != "" || textPhone2.value != "" || textPhone3.value != "") )
        {
            if( textPhone1.value.match(/^[2-9][0-9][0-9]$/) == null )
            {
                alert("Please enter a valid area code.");
                textPhone1.focus();
                textPhone1.select();
                result = false;
            }

            if( result == true &&
                textPhone2.value.match(/^\d\d\d$/) == null )
            {
                alert("Please enter a valid phone number prefix.");
                textPhone2.focus();
                textPhone2.select();
                result = false;
            }

            if( result == true &&
                textPhone3.value.match(/^\d\d\d\d$/) == null )
            {
                alert("Please enter a valid phone number suffix.");
                textPhone3.focus();
                textPhone3.select();
                result = false;
            }
        }

		if( result == true && textComments.value == "" )
        {
            alert("Please enter your comments.");
            textComments.focus();
            result = false;
        }
    }

    return result;
}

// JavaScript Document