function openWindow(url, width, height)
{
  window.open(url, 'popupWindow', 'location=0,status=0,scrollbars=1,toolbar=0,menubar=0,resizable=1,left=100,top=5,height=' + height + ',width=' + width);
}

function getScreenWidth()
{
  // use old default
  var screenWidth = 640;

  if (parseInt(navigator.appVersion)>3)
    screenWidth = screen.width;

  return screenWidth;
}

function getScreenHeight()
{
  // use old default
  var screenHeight = 480;

  if (parseInt(navigator.appVersion)>3)
    screenHeight = screen.height;

  return screenHeight;
}

function getCourseTourPopupHeight()
{
  var windowHeight = getScreenHeight() - 80;

  if (windowHeight > 880)
    return 880;
  else
    return windowHeight;
}

function openCourseTour()
{
  openWindow('course_tour/hole1.cfm', 621, getCourseTourPopupHeight());
}

function setPhoto1(newPhotoName)
{
  document.getElementById('hole_photo_img').src = '../images/course_tour/hole_photos/' + newPhotoName;
}

function confirmFields(formName) {

  var errorMessage = "";
  var numErrors = 0;

  for (var i = 0; i < document.forms[formName].elements.length; i++) {
    if (trim(document.forms[formName].elements[i].value) == "" && document.forms[formName].elements[i].attributes["required"] != null ) {
      errorMessage += "*   " + document.forms[formName].elements[i].attributes["required"].value + "\n";
      numErrors++;
    }
    }
    if (errorMessage != "") {
      if (numErrors == 1)
        alert ("Please fill in the following field:\n\n" + errorMessage);
      else
      alert ("Please fill in the following fields:\n\n" + errorMessage);
    return false;
  }
  else
    return true;
}

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}
