// portmellon cove guest house JavaScript Document //


// start email a friend //

function mailpage()
{
mail_str = "mailto:?subject=Portmellon Cove Guest House in Cornwall " //+ document.title // took this out until I correct the title
;
mail_str += "&body=I thought you might be interested in staying at this really nice guest house in Cornwall " //+ document.title
;
mail_str += ". You can view all details at, " + location.href;
location.href = mail_str;
}

// end email a friend //

//--------------- LOCALIZEABLE GLOBALS ---------------
var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
//---------------   END LOCALIZEABLE   ---------------


// test form validation //


///START OF PIERS' CODE
function validateFormOnSubmit(theForm) {
var reason = "";


  reason += validateEmail(theForm.mail);
  reason += validateEmpty(theForm.name);
  reason += validateEmpty(theForm.telephone);
  reason += validateEmpty(theForm.arrivaldate);
  reason += validateEmpty(theForm.departuredate);
  reason += validateEmpty(theForm.length_of_stay);
//  reason += validateEmpty(theForm.People);
      
  if (reason != "") {
    alert("Fields highlighted in red need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'pink'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'pink';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'pink';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'pink';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
///END OF PIERS' CODE
//-->
