YAHOO.util.Event.onDOMReady(bus_init);

function bus_init(ev) {
}

function check_contact_form(ev) {
   gotowhich = ""; // Reset variable
   var element_good = returnGood(); // Copy variable from included validation functions

   textbox_OK(document.getElementById('organiser'), document.getElementById('organiser'), element_good);
   textbox_OK(document.getElementById('company'), document.getElementById('company'), element_good);
   textbox_OK(document.getElementById('address1'), document.getElementById('address1'), element_good);
   textbox_OK(document.getElementById('town'), document.getElementById('town'), element_good);
   textbox_OK(document.getElementById('county'), document.getElementById('county'), element_good);
   textbox_OK(document.getElementById('postcode'), document.getElementById('postcode'), element_good);
   textbox_OK(document.getElementById('telephone'), document.getElementById('telephone'), element_good);

   textbox_OK(document.getElementById('datefrom'), document.getElementById('datefrom'), element_good);
   textbox_OK(document.getElementById('dateto'), document.getElementById('dateto'), element_good);

   if(document.getElementById('referral') && document.getElementById('other_referral')) {
      if(document.getElementById('referral').value=='Other') {
	 textbox_OK(document.getElementById('other_referral'), document.getElementById('other_referral'), element_good);
      }
   }


   // == Send focus to appropriate element ==============================
   if ( gotowhich != "" ) {
      gotowhich.focus(); // Go to the first incorrect field
      window.scrollBy(0, -50); // Then scroll a bit above it.  (Disabled for short form)
      alert('Please check the questions marked and try again.');
      YAHOO.util.Event.preventDefault(ev);
      return false;
   } 
   else { // Submit form
      return true;
   }

}


function businessAvailabilityChecker(id) {
   YAHOO.util.Event.onAvailable(id, this.handleOnAvailable, this);
}

businessAvailabilityChecker.prototype.handleOnAvailable = function() {
   if(this.id=="businessForm") {
      YAHOO.util.Event.addListener(this, "submit", check_contact_form);
   }
}


var expertForm = new businessAvailabilityChecker('businessForm');

