// editor.js -- Local Ink by Downhill Battle
// Copyright (C) 2004 Nick Nassar <nassar@downhillbattle.org>

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

function checkZip(zip)
{
    var reg = /^\d{5}(-\d{4})?$/;
   if (!reg.exec(zip))
       {
	   alert("Please, enter a zip code in the form 12345 or 12345-1234");
	   return false;
       }
   return true;
}


//This should correspond to validateInput() in index.php
function checkIt(_this)
{
    var ereg = /^[a-zA-Z0-9+._-]+@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,5}$/;
    var preg = /^1?\D*[2-9](\D*\d){9}\D*(x\d+)?$/;

    if (!(_this.firstname.value.length>1))
	{
	    alert("Please, enter a first name");
	    return false;
	}
   if (!(_this.lastname.value.length>1))
	{
	    alert("Please, enter a last name");
	    return false;
	}
   if (!(_this.address.value.length>1))
	{
	    alert("Please, enter a street address");
	    return false;
	}
   if (!(_this.city.value.length>1))
	{
	    alert("Please, enter a city address");
	    return false;
	}
   if (!(ereg.exec(_this.email.value)))
       {
	   alert("Please, enter a valid email address");
	   return false;
       }
   if (!(preg.exec(_this.phone.value)))
       {
	   alert("Please, enter a valid US Phone number");
	   return false;
       }
   if (!(_this.subject.value.length>1))
	{
	    alert("Please, enter a subject for the email");
	    return false;
	}
   if (!(_this.letter.value.length>10))
	{
	    alert("Please, enter a longer letter");
	    return false;
	}
   
    return true;
}

function addText(text) {
    _this = document.forms[0];
    _this.letter.value = _this.letter.value + text;
}
