/* this file contains the javascript for checking the Bonadea Gardens contact form */

/*FUNCTION*/
// this function checks the required form fields for content and validates the email if it exists    
function formCheck(currentform) 
{
   // define the variables for validating the form
   var first = currentform.Fname.value;
   var last = currentform.Lname.value;
   var phone = currentform.phone.value;
   var address = currentform.address.value;
   var city = currentform.city.value;
   var stateprov = currentform.stateprov.value;
   var zippost = currentform.zippost.value;
   var email = currentform.email.value;
   // set up a regular expression to validate the phone number
   var regex_phone = /^((\(\d{3}\))? *\d{3}(-| )\d{4},? *)+$/;
   // set up a regular expression to validate the email address
   var regex_email = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
   
   
   // validate the first name
   if (first == "") 
   {
      alert('Please enter your first name.');
      return false;
   } 
   // validate the last name
   if (last == "") 
   {
      alert('Please enter your last name.');
      return false;
   }
   if (address == "") 
   {
      alert('Please enter your address.');
      return false;
   }
   if (city == "") 
   {
      alert('Please enter your city.');
      return false;
   }
   if (stateprov == "") 
   {
      alert('Please enter your state or province.');
      return false;
   }
   if (zippost == "") 
   {
      alert('Please enter your zip or postal code.');
      return false;
   }
   // validate the phone number
   if (phone == "") 
   {
      alert('Please enter a phone number.');
      return false;
   }
   /*
   if ((phone != "") && (!phone.match(regex_phone))) 
   {
      alert('The phone number you entered is not in the correct format \n Please use this syntax. (204) 555-5555');
      return false;
   }
   */
   // validate the email
   if (email == "") 
   {
      alert('Please enter an email address.');
      return false;
   }
   /*
   if ((email != "") && (!regex_email.test(email)))
   {  
      alert("\"" + email + "\" is an invalid e-mail address!"); 
      return false;

   }
   */
}

/*FUNCTION*/
// set up the function for the date
function the_date()
{
   // set a variable for reformatting the date
   var date_formatted = new Date();

   // set an array for the months of the year
   var month_array = new Array();
   month_array[0] = "January";
   month_array[1] = "February";
   month_array[2] = "March";
   month_array[3] = "April";
   month_array[4] = "May";
   month_array[5] = "June";
   month_array[6] = "July";
   month_array[7] = "August";
   month_array[8] = "September";
   month_array[9] = "October";
   month_array[10] = "November";
   month_array[11] = "December";
   
   // set an array for the days of the week
   var day_array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

   // set the date in the proper format
   var weekday = day_array[date_formatted.getDay()];
   var month = month_array[date_formatted.getMonth()];
   var day = date_formatted.getDate();
   var year = date_formatted.getFullYear(); 
   
   // write out the date to the page in the proper format
   document.write(weekday + ', ' + month + ' ' + day + ', ' + year);
}

/*FUNCTION*/
// set up the function for the time
function the_time()
{
   // declare variables 
   var date_time = new Date();
   var hours;
   var minutes;
   var seconds;
   var ampm;
    
   // format the hour to standard time from military time and determine if am or pm
   hours = date_time.getHours();
   if (hours > 12)
   {
      hours -= 12;
      ampm = 'pm';
   }
   else
   {
      ampm = 'am';
   }
   if (hours == 12)
   {
      ampm = 'pm';
   }
   if(hours < 1)
   {
      hours = 12;
      ampm = 'am';
   }
    
   // format minutes - add a 0 for minutes < 10    
   minutes = date_time.getMinutes();
   if(minutes < 10)
   {
      minutes = '0' + minutes;
   }
    
   // format seconds - add a 0 for seconds < 10 
   seconds = date_time.getSeconds();
   if(seconds < 10)
   {
      seconds = '0' + seconds;
   }
    
   // write out the time to the screen in standard format
   document.write(hours + ':' + minutes + ampm);
}
