function NewWindow(mypage, myname, w, h, scroll) {
var winl = 0;
var wint = 0;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function luhnCheck(CardNumber) {
	
	if (! (CardNumber)) {
		return false;
	}

	var no_digit = CardNumber.length;
	var oddoeven = no_digit & 1;
	var sum = 0;

	for (var count = 0; count < no_digit; count++) {
		var digit = parseInt(CardNumber.charAt(count));
		if (!((count & 1) ^ oddoeven)) {
			digit *= 2;
			if (digit > 9)
			digit -= 9;
			}
		sum += digit;
	}
	if (sum % 10 == 0)
		return true;
	else
		return false;
}
function validate() {

var firstname=document.reg.FirstName.value;
var lastname=document.reg.LastName.value;
var email=document.reg.Email.value;
var phone=document.reg.Phone.value;
var zipcode=document.reg.Zip.value;
var state=document.reg.State.selectedIndex;
var terms=document.reg.Terms.checked;
var message=document.reg.Message.value;

if(firstname==""){
alert("You must enter your first name.");
document.reg.FirstName.focus();
return false;
}
if(lastname==""){
alert("You must enter your last name.");
document.reg.LastName.focus();
return false;
}
if(zipcode!=""){
if(document.reg.Zip.value.length < 5){
alert("Your zip code must contain 5 numbers.");
document.reg.Zip.focus();
return false;
}
}
if(phone==""){
alert("You must enter your phone number.");
document.reg.Phone.focus();
return false;
}
if(document.reg.Phone.value.length < 10){
alert("Your phone number seems incorrect as it has less than 10 numbers.");
document.reg.Phone.focus();
return false;
}
if(document.reg.Phone.value.length > 25){
alert("Your phone number seems incorrect as it has more than 25 characters");
document.reg.Phone.focus();
return false;
}
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=email.match(emailPat);

if (email=="") {

alert("An email address must be entered.");
document.reg.Email.focus();
return false;
}
if (matchArray==null) {

alert("Your email address seems incorrect (check @ and .'s)");
document.reg.Email.focus();
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Your email username contains invalid characters.");
document.reg.Email.focus();
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Your email domain name contains invalid characters.");
document.reg.Email.focus();
return false;
   }
}

if (user.match(userPat)==null) {
alert("Your email username doesn't seem to be valid.");
document.reg.Email.focus();
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Your email destination IP address is invalid!");
document.reg.Email.focus();
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Your email domain name does not seem to be valid.");
document.reg.Email.focus();
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Your email address must end in a well-known domain or two letter " + "country.");
document.reg.Email.focus();
return false;
}
if (len<2) {
alert("Your email address is missing a hostname!");
document.reg.Email.focus();
return false;
}
if(message==""){
alert("You have not entered your message to the innkeeper.");
document.reg.Message.focus();
return false;
}
if (terms==false) {
alert("You must agree to the Walter's Attic & C.A.'s House Bed and Breakfast usage agreement to continue.");
return false;
}
}
function authenticate() {

var email=document.auth.Email.value;
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=email.match(emailPat);

if (email=="") {

alert("An email address must be entered.");
document.auth.Email.focus();
return false;
}
if (matchArray==null) {

alert("Your email address seems incorrect (check @ and .'s)");
document.auth.Email.focus();
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Your email username contains invalid characters.");
document.auth.Email.focus();
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Your email domain name contains invalid characters.");
document.auth.Email.focus();
return false;
   }
}

if (user.match(userPat)==null) {
alert("Your email username doesn't seem to be valid.");
document.auth.Email.focus();
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Your email destination IP address is invalid!");
document.auth.Email.focus();
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Your email domain name does not seem to be valid.");
document.auth.Email.focus();
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Your email address must end in a well-known domain or two letter " + "country.");
document.auth.Email.focus();
return false;
}
if (len<2) {
alert("Your email address is missing a hostname!");
document.auth.Email.focus();
return false;
}
}
function calendar() {

var nights=document.cal.Nights.value;
var date=document.cal.Date.value;

if(date==""){
alert("You must choose a date from the calendar");
return false;
}
if(nights==""){
alert("You must enter the number of nights you would like to reserve");
document.cal.Nights.focus();
return false;
}
var checkOK = "0123456789-";
var checkStr = nights;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++) {
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
 if (ch == checkOK.charAt(j))
   break;
 if (j == checkOK.length) {
   allValid = false;
   break;
 }
 allNum += ch;
}
if (!allValid) {
alert("Your number of nights entered seems incorrect.");
document.cal.Nights.focus();
return false;
}
}
function feedback() {

var comments=document.feed.Comments.value;
var name=document.feed.Name.value;
var location=document.feed.Location.value;
var day=document.feed.Day.value;
var month=document.feed.Month.value;
var year=document.feed.Year.value;
var rightnow=new Date();
var curyear=rightnow.getYear();
if (curyear<2000){
curyear+=1900;
}
if(comments==""){
alert("Your comments, suggestions, feedback is missing.");
document.feed.Comments.focus();
return false;
}
if(name==""){
alert("You must enter your name.");
document.feed.Name.focus();
return false;
}
if(location==""){
alert("You must enter your location.");
document.feed.Location.focus();
return false;
}
if(month==""){
alert("You must enter the month of your stay.");
document.feed.Month.focus();
return false;
}
var checkOK = "0123456789-";
var checkStr = month;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++) {
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
 if (ch == checkOK.charAt(j))
   break;
 if (j == checkOK.length) {
   allValid = false;
   break;
 }
 allNum += ch;
}
if (!allValid) {
alert("The month entered must only contain numbers.");
document.feed.Month.focus();
return false;
}
if(document.feed.Month.value > 12){
alert("The month entered seems to be invalid");
document.feed.Month.focus();
return false;
}
if(document.feed.Month.value <= 0){
alert("The month entered seems to be invalid");
document.feed.Month.focus();
return false;
}
if(day==""){
alert("You must enter the day of your stay.");
document.feed.Day.focus();
return false;
}
var checkOK = "0123456789-";
var checkStr = day;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++) {
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
 if (ch == checkOK.charAt(j))
   break;
 if (j == checkOK.length) {
   allValid = false;
   break;
 }
 allNum += ch;
}
if (!allValid) {
alert("The day entered must only contain numbers.");
document.feed.Day.focus();
return false;
}
if(document.feed.Day.value > 31){
alert("The day entered seems to be invalid");
document.feed.Day.focus();
return false;
}
if(document.feed.Day.value <= 0){
alert("The day entered seems to be invalid");
document.feed.Day.focus();
return false;
}
if(year==""){
alert("You must enter the year of your stay.");
document.feed.Year.focus();
return false;
}
var checkOK = "0123456789-";
var checkStr = year;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0;  i < checkStr.length;  i++) {
ch = checkStr.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
 if (ch == checkOK.charAt(j))
   break;
 if (j == checkOK.length) {
   allValid = false;
   break;
 }
 allNum += ch;
}
if (!allValid) {
alert("The year entered must only contain numbers.");
document.feed.Year.focus();
return false;
}
if(year.length < 4){
alert("The year must be four numbers.");
document.feed.Year.focus();
return false;
}
if(document.feed.Year.value > curyear){
alert("The year entered seems to be invalid");
document.feed.Year.focus();
return false;
}
if(document.feed.Year.value < 1998){
alert("The year entered seems to be invalid");
document.feed.Year.focus();
return false;
}
}
function guestinfo() {

var firstname=document.reg.FirstName.value;
var lastname=document.reg.LastName.value;
var email=document.reg.Email.value;
var phone=document.reg.Phone.value;
var zipcode=document.reg.Zip.value;
var state=document.reg.State.selectedIndex;
var city=document.reg.City.value;
var address=document.reg.Address.value;
var cctype = document.reg.CCType.selectedIndex;
var nameoncard = document.reg.NameOnCard.value;
var ccnumber = document.reg.CCNumber.value;
var ccexpiremonth = document.reg.CCExpireMonth.value;
var ccexpireyear = document.reg.CCExpireYear.value;

var date = new Date();
var thismonth = date.getMonth()+1;
var thisyear = date.getFullYear();

if(firstname==""){
alert("You must enter your first name.");
document.reg.FirstName.focus();
return false;
}
if(lastname==""){
alert("You must enter your last name.");
document.reg.LastName.focus();
return false;
}
if(address==""){
alert("You must enter your address.");
document.reg.Address.focus();
return false;
}
if(city==""){
alert("You must enter your city.");
document.reg.City.focus();
return false;
}
if(zipcode==""){
alert("You must enter your zip code.");
document.reg.Zip.focus();
return false;
}
if(phone==""){
alert("You must enter your phone number.");
document.reg.Phone.focus();
return false;
}
if(document.reg.Phone.value.length < 10){
alert("Your phone number seems incorrect as it has less than 10 numbers.");
document.reg.Phone.focus();
return false;
}
if(document.reg.Phone.value.length > 25){
alert("Your phone number seems incorrect as it has more than 25 characters");
document.reg.Phone.focus();
return false;
}
if (cctype == 0) {
document.reg.CCType.focus();
alert("You must select the type of credit card you are using.");
return false;
}
if (nameoncard == "") {
document.reg.NameOnCard.focus();
alert("Please enter the name as it appears on the credit card.");
return false;
}
if (ccnumber == "") {
document.reg.CCNumber.focus();
alert("Please enter your credit card number you are using for payment.");
return false;
}
if (! luhnCheck(ccnumber)) {
document.reg.CCNumber.focus();
alert("The credit card number entered is not a valid credit card number.");
return false;
}
if (ccexpireyear < thisyear) {
document.reg.CCExpireYear.focus();
alert("The expiration year chosen has already passed.");
return false;
} else {
	if (ccexpireyear == thisyear) {
		if (ccexpiremonth < thismonth) {
			document.reg.CCExpireMonth.focus();
			alert("The expiration date entered has already expired1.");
			return false;
		}
	}
}
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=email.match(emailPat);

if (email=="") {

alert("An email address must be entered.");
document.reg.Email.focus();
return false;
}
if (matchArray==null) {

alert("Your email address seems incorrect (check @ and .'s)");
document.reg.Email.focus();
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Your email username contains invalid characters.");
document.reg.Email.focus();
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Your email domain name contains invalid characters.");
document.reg.Email.focus();
return false;
   }
}

if (user.match(userPat)==null) {
alert("Your email username doesn't seem to be valid.");
document.reg.Email.focus();
return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Your email destination IP address is invalid!");
document.reg.Email.focus();
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("Your email domain name does not seem to be valid.");
document.reg.Email.focus();
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("Your email address must end in a well-known domain or two letter " + "country.");
document.reg.Email.focus();
return false;
}
if (len<2) {
alert("Your email address is missing a hostname!");
document.reg.Email.focus();
return false;
}
}
