function checkRequiredFields(objForm) {
   var intFields = objForm.elements.length;
   var intField = 0;
   if (intFields) {
      switch (objForm.id) {
         case 'contact_us':
            for (intField = 0; intField < intFields - 1; intField++) {
               if (objForm.elements[intField].value == '') {
                  alert('\'' + objForm.elements[intField].name + '\' is a required field.')
                  return false;
               }
            }
            break;
         case 'free_trial':
            for (intField = 0; intField < intFields - 1; intField++) {
               if (objForm.elements[intField].value == '') {
                  alert('\'' + objForm.elements[intField].id.replace('_', ' ') + '\' is a required field.')
                  objForm.elements[intField].focus();
                  return false;
               }
            }
            break;
         default:
            alert('Unhandled form: ' + objForm.id);
      }
   }
   return true;
}

// **********************************************
// ** Method to go directly to the location page
// **  when a club is selected in the drop-down.
// **********************************************
function handleSelect(objSelect) {
   switch (objSelect.id) {
      case 'locations':
         if (objSelect.value)
            top.location.href = 'Location.asp?objid=' + objSelect.value;
         break;
      case 'state':
         break;
      default:
         alert('Unhandled select box: ' + objSelect.id);
   }
}

// **********************************************
// ** Method to open the employee console
// **********************************************
function openConsole() {
   // Desired attributes of the employee console
   strURL = 'Console_Login.asp';
   w = 800;
   h = 600;

   w += 32; // "Fudge factors" for scrolls/browser controls
   h += 96; // (work well on most platforms/browsers)

   // Determine the ideal top and left position, based on the screen's width
   l = (screen.width - w) / 2;
   t = (screen.height - h) / 2;

   // Fix older browsers that might allow an off-screen window
   if (l < 0) {
      w = screen.width;
      l = 0;
   }
   if (t < 0) {
      h = screen.height;
      t = 0;
   }

   // Launch the pop-up window
   var winConsole = window.open(strURL, 'console', 'status=0,'             +
                                                   'toolbar=0,'            +
                                                   'location=0,'           +
                                                   'menubar=0,'            +
                                                   'directories=0,'        +
                                                   'resizable=1,'          +
                                                   'scrollbars=auto,'      +
                                                   'width=\''  + w + '\',' +
                                                   'height=\'' + h + '\',' +
                                                   'left=\''   + l + '\',' +
                                                   'top=\''    + t + '\''  );

   // Just in case the left and top properties are ignored
   winConsole.moveTo(l, t);
   // Just in case the height and width properties are ignored
   winConsole.resizeTo(w, h);
   // Make sure it's on-top
   winConsole.focus();
   // Pass the window object back to the callee, in case they need to modify/control it.
   return winConsole;
}

// **********************************************
// ** Control the bahavior of the drop-down menu
// **********************************************
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open() {
   jsddm_canceltimer();
   jsddm_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function jsddm_close() {
   if (ddmenuitem)
      ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer() {
   closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {
   if (closetimer) {
      window.clearTimeout(closetimer);
      closetimer = null;
   }
}

$(document).ready(function() {
   $('#jsddm > li').bind('mouseover', jsddm_open);
   $('#jsddm > li').bind('mouseout',  jsddm_timer);
});

document.onclick = jsddm_close;
