var whitespace  = " \t\n\r";
var defaultEmptyOK = false;
function isEmpty(s) {                        // Check whether string s is empty.
    return ((s == null) || (s.length == 0))
}
function isWhitespace (s) {     // Returns true if string s is empty or whitespace characters only.
    var i;
    if (isEmpty(s)) return true;    // Is s empty?

    // Search through string's characters until non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);    // Check that current character isn't whitespace.
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;         // All characters are whitespace.
}

function isEmail (s) {
    if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);

    if (isWhitespace(s)) return false;                  // is s whitespace?

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@")) {    // look for @
        i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != ".")) {    // look for .
        i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function check_form() {
    if (document.bookingform.name.value == "") {                     // TEXT
        alert("Please enter your name in the \"Name\" box!");
        document.bookingform.name.focus();
        return false;
    }
    if (document.bookingform.address.value == "") {                    // TEXTAREA
        alert("Please enter your address in the \"address\" box!");
        document.bookingform.address.focus();
        return false;
    }
    defaultEmptyOK = true;
    if (!isEmail(document.bookingform.email.value)) {
        alert("Please enter a valid email address!");
        document.bookingform.email.focus();
        return false;
    }
    if ( (document.bookingform.email.value == "" ) &&
        (document.bookingform.telephone.value == "" ) ) {
        alert("Please enter your telephone number or your email address!");
        document.bookingform.email.focus();
        return false;
    }
    if (document.bookingform.dates.value == "") {                     // TEXT
        alert("Please enter your preferred dates in the \"Dates\" box!");
        document.bookingform.dates.focus();
        return false;
    }
    if (document.bookingform.namelist.value == "") {                    // TEXTAREA
        alert("Please enter the names of the party members in the \"Names\" box!");
        document.bookingform.namelist.focus();
        return false;
    }
}
function openIT() {
    top.name = "main_window";
    var popupURL = "availability_fset.html";
    var popup = window.open(popupURL,"availability",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=*');
    if( navigator.appName.substring(0,8) == "Netscape" ){
        popup.location = popupURL;
        popup.opener = self;
    }
}
// -->

