// portmellon cove guest house JavaScript Document //


// start email a friend //

function mailpage()
{
mail_str = "mailto:?subject=Hillside House Guest House in Cornwall " //+ document.title // took this out until I correct the title
;
mail_str += "&body=I thought you might be interested in this really nice looking Guest House within walking distance of St.Austell Town Centre in Cornwall. They are close to The Eden Project, The Lost Gardens of Heligan, Charlestown, Fowey and close to St.Austell Bus and Train Station ." //+ document.title
;
mail_str += "&body=Find out more details on their website http://www.hillside-guesthouse.com/   " //+ document.title
;
mail_str += "  "// + location.href;
location.href = mail_str;
}

// end email a friend //

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}





// 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
//-->