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 selectField(object)
{
    object.select();
}

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;
        }
        
    var re= /<\S[^><]*>/g
    if (textComments.value.match(re))
    {
	  alert("Sorry, HTML markup is not allowed in the comments.");
      result = false;
    }
    }

    return result;
}

function validateIndexPageForm()
{
    var words;
    var result = true;

    with( document.main )
    {
        words = textName.value.split(" ");
        if( result == true &&
            (textName.value == "" || textName.value == "Name" || words.length < 2) )
        {
            alert("Please enter your full name.");
            textName.focus();
            textName.select();
            result = false;
        }

        textEmail.value.replace(/ /, "");
        if( result == true )
        {
			if( textEmail.value == "" || textEmail.value == "Email" )
			{
                alert("Please enter your email address.");
                textEmail.focus();
                result = false;
            }
            else
            {
                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 && (textComments.value == "" || textComments.value == "Your comments") )
        {
            alert("Please enter your comments.");
            textComments.focus();
            result = false;
        }
        
    var re= /<\S[^><]*>/g
    if (textComments.value.match(re))
    {
      result = false;
    }
        
    }

    return result;
}


// Strip HTML Tags (form) script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

function stripHTML(){
var re= /<\S[^><]*>/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, "")
}
