function ValidateForm() {
  var Valid=false;
  var difference = 0;
  var min_nights;
  
  if($('type').value == 'Tour') 
  {
    $('prebooking').submit();
  }
  
  if($('type').value=='Accommodation') 
  {
     $A(document.getElementsByClassName('bookroom')).each(function(el) { 
      Valid = (el.checked) ? true : (Valid) ? true : false;
      
      if(Valid && el.checked) { //- Valid, Check to make sure minimum nights are fulfilled.
        min_nights = $('minnights_'+el.id.split('_')[1]).value;
        var checkin_date=new Date($('checkin_Year').value, $('checkin_Month').value, $('checkin_Day').value);
        var checkout_date=new Date($('checkout_Year').value, $('checkout_Month').value, $('checkout_Day').value);
        var one_day=1000*60*60*24;     //- 1 day in milliseconds

        //- Calculate difference btw the two dates, and convert to days
        var k = Math.ceil((checkout_date.getTime()-checkin_date.getTime())/(one_day));
        difference = (min_nights - k); //- How many days are left? Must be 0 to pass.
      }
    });
    if(!Valid) {
      alert('Please select a Room Type before proceeding.');
    }else if(difference != 0 && min_nights!=0) {
      alert('The minimum night stay requirement of '+min_nights+' nights has not been met. \nPlease check your dates and try again.');
    } else {
      $('prebooking').submit();
    }
  }
}

function SwapButton() {
  if($('book-now').hasClassName('mouseover')) {
    $('book-now').removeClassName('mouseover');
  }else{
    $('book-now').addClassName('mouseover');
  }
}

function UpdatePrice(QuantityInput) 
{
  var idSelectedRateOption = QuantityInput.id.split("_")[1];
  var RateOptions = $A(document.getElementsByClassName('quantity'));
  var Locked = false;
  RateOptions.each(function(q) 
  { 
    if(q.id.split("_")[1] != idSelectedRateOption) 
    {
      q.value='';
      q.disable();
      q.addClassName('disabled'); //- Because IE doesnt grey disabled inputs.
      $('btnSubmit').enable();
    }
  });
  if(QuantityInput.value <= 0) 
  {
    $('btnSubmit').disable();
    RateOptions.each(function(q) 
    { 
      if(q.id.split("_")[1] == idSelectedRateOption && q.value > 0 && Locked==false) 
      {
        Locked = true;
      }
      else if(Locked != true) {
        Locked = false;
      }
    });
    if(Locked==false) 
    { 
      RateOptions.each(function(q) 
      { 
        q.enable();
        q.removeClassName('disabled');
      }); 
    }
  }
  else {
    $('btnSubmit').enable();
  }

  $('rate_option').value=idSelectedRateOption;
  $(QuantityInput.id.split("_")[0]).value=QuantityInput.value; 
}

/**
 * Accom
 */
function UpdateProduct(idproduct) {
  $('idproduct').value=idproduct;
}

function ShowDetails(e) 
{
 var HPos = Event.pointerX(e);
 var VPos = Event.pointerY(e);
 var el = Event.element(e);
 var idElement = $(el).readAttribute('id');
 var inclusions = $(el).readAttribute('inclusions');
 var minnights = $(el).readAttribute('minnights');

 if(inclusions || minnights) {
 if(inclusions.length>0 || minnights > 1) {
   $('hover').innerHTML = inclusions;
   if(minnights>1)  {
     if(inclusions.length>0)
      $('hover').innerHTML += "<br/>";
    $('hover').innerHTML += 'This Rate has a Minimum Night stay of '+minnights+' nights.';
   }
   $('hover').style.top=(parseInt(VPos)-150)+'px';
   $('hover').style.left=(HPos+5)+'px';
   $('hover').style.display="block";
 }
}
}
function HideDetails() 
{
 $('hover').hide();
}

