/******************************************************************************
   Author: Alan Coates (except as otherwise notated)
     Date: 07/31/2009
  Program: miscfunctions.js
******************************************************************************/
function gonew()
{
	window.location="http://www.brookhaven30319.com/form.php";
}
/******************************************************************************/
function goedit()
{
	window.location="http://www.brookhaven30319.com/edit_form.php";
}
/******************************************************************************/
function godelete()
{
var where_to_delete = confirm("WARNING!  There is no UNDO for deletes.  Are you sure you want to delete this directory listing?");
if (where_to_delete)
{
	window.location="http://www.brookhaven30319.com/delete.php";
}
else
	{
	alert("Deletion cancelled.");
	}
}
/******************************************************************************/
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
/******************************************************************************
 * method: ValidateEmailAddr
 *
 * author: Jason Geissler
 *
 * date: March 23, 2002
 *
 * parameters: emailAddress
 *
 * purpose: Makes sure the user entered a valid e-mail address. Supports the
 *          extensions .com, .org, .gov, .net, .edu
 *****************************************************************************/
function ValidateEmailAddr(field,alerttxt){

var emailAddress=document.myForm.email.value;
	 if(emailAddress==null||emailAddress=="")
	{
		 return true;
	}
	else
	{

  var atSymbol = emailAddress.indexOf("@");                                  // Get the index of the '@'
  var period = emailAddress.lastIndexOf(".");                                // Get the value of the last '.'
  var suffix = emailAddress.substring(period + 1, emailAddress.length);
  
  // Make sure the '@' symbol and '.' is in a valid location
  if (((atSymbol != 0) && (atSymbol != -1)) && (suffix.length == 3) && (atSymbol < period) && (atSymbol != period - 1)) { 
    if ((suffix == "com") || (suffix == "org") || (suffix == "gov") || (suffix == "net") || (suffix == "edu")) 
      return true;
  }
  alert(alerttxt);return false;
	}
}
/******************************************************************************/
function check_url(field,alerttxt) {

     var theurl=document.myForm.website.value;
	 if(theurl==null||theurl=="")
	{
		 return true;
	}
	else
	{
	   theurl = "http://" + theurl;
       var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
       if (tomatch.test(theurl))
       {
          return true;
       }
       else
       {
          alert(alerttxt);return false;
       }
	}
}
/******************************************************************************/
function tendigits_required(field,alerttxt)
{
with (field)
  {
  if ((value<=1000000000||value>=9999999999)&&(value!=null&&value!=""))
     {
     alert(alerttxt);return false;
     }
  else
     {
     return true;
     }
   }
}
/******************************************************************************/
function validate_form(thisform)
{
  with (thisform)
  {
  if (ValidateEmailAddr(email,"The format of the email address is not valid.")==false)
  {email.focus();return false;}
  }  
  with (thisform)
  {
  if (check_url(website,"The format of the website address is not valid.")==false)
  {email.focus();return false;}
  }  
  with (thisform)
  {
  if (tendigits_required(telephone,"Enter telephone number as 10 digits, with no spaces, no punctuation. EX: 4049990000")==false)
  {email.focus();return false;}
  }
  with (thisform)
  {
  if (tendigits_required(fax,"Enter fax number as 10 digits, with no spaces, no punctuation. EX: 4049990000")==false)
  {email.focus();return false;}
  }
  with (thisform)
  {
  if (validate_required(name,"Name must be entered.")==false)
  {email.focus();return false;}
  }
  with (thisform)
  {
  if (validate_required(description,"Description must completed.")==false)
  {email.focus();return false;}
  }
  with (thisform)
  {
  if (validate_required(category,"A category must be selected.")==false)
  {email.focus();return false;}
  }
}
/******************************************************************************/
