function checkWholeForm(theForm) {
    var why = "";
    why += isEmptyName(theForm.Name.value);
    why += checkEmail(theForm.Email.value);
    why += checkPhone(theForm.Phone.value);
    why += isEmptyPostAddr(theForm.PostAddr.value);
    why += checkDropdownArriveYear(theForm.ArriveYear.options[theForm.ArriveYear.options.selectedIndex].text);
    why += checkDropdownArriveMonth(theForm.ArriveMonth.options[theForm.ArriveMonth.options.selectedIndex].text);
    why += checkDropdownArriveDay(theForm.ArriveDay.options[theForm.ArriveDay.options.selectedIndex].text);
    why += checkDropdownLeavingYear(theForm.LeavingYear.options[theForm.LeavingYear.options.selectedIndex].text);
    why += checkDropdownLeavingMonth(theForm.LeavingMonth.options[theForm.LeavingMonth.options.selectedIndex].text);
    why += checkDropdownLeavingDay(theForm.LeavingDay.options[theForm.LeavingDay.options.selectedIndex].text);
    why += checkDropdownRoomType(theForm.RoomType.options[theForm.RoomType.options.selectedIndex].text);
    why += checkDropdownOccupacy(theForm.Occupacy.options[theForm.Occupacy.options.selectedIndex].text);
    why += checkDigitNumber(theForm.Number.value);
    why += checkDropdownCreditCard(theForm.CreditCard.options[theForm.CreditCard.options.selectedIndex].text);
  if (why != "") {
       why = "Error:\n\n" + why;
       alert(why);
       return false;
	}
	return true;
}

function isEmptyName(strng) {
	var error = "";
	if (strng == "") {
	 error = "Field \"Name\" shouldn't be empty.\n";
	}
	return error;
}

function isEmptyPostAddr(strng) {
	var error = "";
	if (strng == "") {
	 error = "Field \"Mailing Address\" shouldn't be empty.\n";
	}
	return error;
}

function checkEmail(strng) {
	var error = "";
	var xxx = strng.length;
	var yyy = strng.indexOf("@");
	var zzz = strng.lastIndexOf(".");
	//document.write(' length= ' + xxx + ' at= ' + yyy + ' last dot= ' + zzz);
	if ( xxx == 0 ) {
		error = "Field \"E-mail\" shouldn't be empty.\n";
	} else {
		if ( !allValidChars(strng) ) {  // check to make sure all characters are valid
			error = "There are unvalid symbols in field  \"E-mail\".\n";
		} else {
			if (yyy < 1) { //  must contain @, and it must not be the first character
			   error = "E-mail address does't contain or starts with \"@\".\n";
			} else {
				if ( zzz <= yyy) {  // last dot must be after the @
				   error = "There is no dot in the domain of the \"E-mail\" field.\n";
				} else {
					if ( yyy == xxx - 1 ) {  // @ must not be the last character
						error = "\"@\" could not be last symbol in the \"E-mail\" field.\n";				
					} else {
						if (strng.indexOf("..") >=0) { // two periods in a row is not valid
							   error = " Tho consequtive dots in the  \"E-mail\" field\n";						
						} else {		
							if ( zzz == xxx - 1 ) {  // . must not be the last character
							   error = "Unvalid last dot in the  \"E-mail\" field.\n";							
							} else {
								//error = "no error\n"
							}
						}
					}
				}
			}
		}
	}	
	//alert(error)
	return error;
}


function checkPhone(strng) {
	var error = "";
	var ccc = strng.length;
	//document.write(' length= ' + xxx + ' at= ' + yyy + ' last dot= ' + zzz);
	if ( ccc == 0 ) {
		error = "Field \"Phone Number\" shouldn't be empty.\n";
	} else {
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		   error = "There are unvalid symbols in the \"Phone Number\" field.\n";
		} else {
			if ( stripped.length < 4 ) {
				error = "\"Phone Number\" field is too short.\n"
			}
		}
	}
	return error;
}

function checkDigitNumber(strng) {
	var error = "";
	var ccc = strng.length;
	//document.write(' length= ' + xxx + ' at= ' + yyy + ' last dot= ' + zzz);
	if ( ccc == 0 ) {
		error = "\"Number of Rooms\" is not set.\n";		
	} else {
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
		//strip out acceptable non-numeric characters
		if (isNaN(parseInt(stripped))) {
		   error = "There are unvalid symbols in the \"Number of Rooms\" field.\n";
		} else {
			if ( stripped.length < 1 ) {
				error = "\"Number of Rooms\" is not set.\n";		
			}
		}
	}
	return error;
}

function allValidChars(strng) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < strng.length; i++) {
    var letter = strng.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

//================== Arrive Date

function checkDropdownArriveYear(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == '---' ) {
       error = "\"Arriving year\" is not set.\n";
    }    
	return error;
}  

function checkDropdownArriveMonth(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == '---' ) {
       error = "\"Arriving month\" is not set.\n";
    }    
	return error;
}  

function checkDropdownArriveDay(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == '---' ) {
       error = "\"Arriving day\" is not set.\n";
    }    
	return error;
}  

//================== Leaving Date

function checkDropdownLeavingYear(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == '---' ) {
       error = "\"Departure year\" is not set.\n";
    }    
	return error;
}  

function checkDropdownLeavingMonth(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == '---' ) {
       error = "\"Departure month\" is not set.\n";
    }    
	return error;
}  

function checkDropdownLeavingDay(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == '---' ) {
       error = "\"Departure day\" is not set.\n";
    }    
	return error;
}  

//================== Other

function checkDropdownRoomType(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == 'Choose' ) {
       error = "\"RoomType\" is not set.\n";
    }    
	return error;
}  

function checkDropdownOccupacy(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == 'Choose' ) {
       error = "\"Occupacy\" is not set.\n";
    }    
	return error;
}  

function checkDropdownCreditCard(strng) {
	//document.write('choice = ' + strng ); 
	var error = "";
    if ( strng == '---' ) {
       error = "\"Method of Payment\" is not set.\n";
    }    
	return error;
}  



