function ValidateBoardingReservation()
{
	if (eval("document.forms[0].pet_name1"))
	{
	  if (document.forms[0].pet_name1.value.length == 0)
	  {
	    alert("Please specify the name of at least one companion.");
			document.forms[0].pet_name1.select();
			return false;
	  }
	}
	
	if (eval("document.forms[0].pet_breed1"))
	{
	  if (document.forms[0].pet_breed1.value.length == 0)
	  {
	    alert("Please specify the breed of at least one companion.");
			document.forms[0].pet_breed1.select();
			return false;
	  }
	}

	if (eval("document.forms[0].pet_age1"))
	{
	  if (document.forms[0].pet_age1.value.length == 0)
	  {
	    alert("Please specify the age of at least one companion.");
			document.forms[0].pet_age1.select();
			return false;
	  }
	}

	if (eval("document.forms[0].pet_weight1"))
	{
	  if (document.forms[0].pet_weight1.value.length == 0)
	  {
	    alert("Please specify the weight of at least one companion.");
			document.forms[0].pet_weight1.select();
			return false;
	  }
	}
	
	if (eval("document.forms[0].arrival") && eval("document.forms[0].departure"))
	{
	  if (document.forms[0].arrival.value.length == 0)
	  {
	    alert("Please specify the arrival date.");
			document.forms[0].arrival.select();
			return false;
	  }

	  if (document.forms[0].departure.value.length == 0)
	  {
	    alert("Please specify the departure date.");
			document.forms[0].departure.select();
			return false;
	  }
	  
	  var arrDate = new Date(document.forms[0].arrival.value);
	  var depDate = new Date(document.forms[0].departure.value);
	  
	  if (((arrDate.getMonth() == depDate.getMonth()) && (arrDate.getDate() == depDate.getDate()) && (arrDate.getFullYear() == depDate.getFullYear())) || (arrDate > depDate))
	  {
	    alert("The departure date must be later than the arrival date.");
			document.forms[0].arrival.select();
			return false;
	  }
	}

	return true;
}

function daysBetween(date1, date2)
{
  // The number of milliseconds in one day
  var ONE_DAY = 1000 * 60 * 60 * 24;

  // Convert both dates to milliseconds
  var date1_ms = new Date(date1).getTime();
  var date2_ms = new Date(date2).getTime();

  // Calculate the difference in milliseconds
  var difference_ms = Math.abs(date1_ms - date2_ms);

  // Convert back to days and return
  return Math.round(difference_ms/ONE_DAY);
}

function setZero(txtBox)
{
  if (txtBox.value == '')
    txtBox.value = '0';
}

function isNumberKey(evt)
{
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
      return false;

   return true;
}

function GetNumberOfCompanions()
{
  var num = 0;
  
  if (document.forms[0].pet_weight1.value != '')
  {
    num++;

    if (document.forms[0].pet_weight2.value != '')
      num++;
    if (document.forms[0].pet_weight3.value != '')
      num++;
  }
  
  return num;
}

function GetCompanionServicesPrice(weight)
{
  var servicesPrice = 0;
  var numCompanions = GetNumberOfCompanions();
  
  if (document.forms[0].patiorun.checked)
  {
    servicesPrice += (numCompanions * 8);
    document.getElementById('patiorunPrice').innerHTML = "<strong>$" + (numCompanions * 8) + ".00</strong>";
  }

  if (document.forms[0].groupplay.checked)
  {
    servicesPrice += (numCompanions * 6); 
    document.getElementById('groupplayPrice').innerHTML = "<strong>$" + (numCompanions * 6) + ".00</strong>";
  }

  if (document.forms[0].playpens.checked)
  {
    servicesPrice += (numCompanions * 6); 
    document.getElementById('playpensPrice').innerHTML = "<strong>$" + (numCompanions * 6) + ".00</strong>";
  }

  if (document.forms[0].bath.value != '')
  {
    var bPrice = 0;
    if (weight>=0 && weight<=25) { bPrice = (parseInt(document.forms[0].bath.value) * 15); }
    if (weight>=26 && weight<=50) { bPrice = (parseInt(document.forms[0].bath.value) * 18); }
    if (weight>=51 && weight<=75) { bPrice = (parseInt(document.forms[0].bath.value) * 21); }
    if (weight>=76) { bPrice = (parseInt(document.forms[0].bath.value) * 24); }
    
    servicesPrice += bPrice;
    document.getElementById('bathPrice').innerHTML = "<strong>$" + bPrice + ".00</strong>";
  }

  if (document.forms[0].nailtrim.value != '')
  {
    servicesPrice += (parseInt(document.forms[0].nailtrim.value) * 15);
    document.getElementById('nailtrimPrice').innerHTML = "<strong>$" + (parseInt(document.forms[0].nailtrim.value) * 15) + ".00</strong>";
  }

  if (document.forms[0].deluxespa.value != '')
  {
    var dPrice = 0;
    if (weight>=0 && weight<=25) { dPrice = (parseInt(document.forms[0].deluxespa.value) * 25); }
    if (weight>=26 && weight<=50) { dPrice = (parseInt(document.forms[0].deluxespa.value) * 28); }
    if (weight>=51 && weight<=75) { dPrice = (parseInt(document.forms[0].deluxespa.value) * 31); }
    if (weight>=76) { dPrice = (parseInt(document.forms[0].deluxespa.value) * 34); }
    
    servicesPrice += dPrice;
    document.getElementById('deluxespaPrice').innerHTML = "<strong>$" + dPrice + ".00</strong>";
  }

  if (document.forms[0].grooming.value != '')
  {
    servicesPrice += (parseInt(document.forms[0].grooming.value) * 45);
    document.getElementById('groomingPrice').innerHTML = "<strong>$" + (parseInt(document.forms[0].grooming.value) * 45) + ".00</strong>";
  }

  if (document.forms[0].teethclean.value != '')
  {
    servicesPrice += (parseInt(document.forms[0].teethclean.value) * 5);
    document.getElementById('teethcleanPrice').innerHTML = "<strong>$" + (parseInt(document.forms[0].teethclean.value) * 5) + ".00</strong>";
  }

  if (document.forms[0].training.value != '')
  {
    servicesPrice += (parseInt(document.forms[0].training.value) * 25);
    document.getElementById('trainingPrice').innerHTML = "<strong>$" + (parseInt(document.forms[0].training.value) * 25) + ".00</strong>";
  }

  if (document.forms[0].vet.value != '')
  {
    servicesPrice += (parseInt(document.forms[0].vet.value) * 38);
    document.getElementById('vetPrice').innerHTML = "<strong>$" + (parseInt(document.forms[0].vet.value) * 38) + ".00</strong>";
  }
  
  return servicesPrice;
}

function calcEstimatedPricing()
{
  var estPrice = 0;
  
  if (ValidateBoardingReservation())
  {
    var numDays = daysBetween(document.forms[0].arrival.value, document.forms[0].departure.value);
    var comp1Weight = 0;
    var comp2Weight = 0;
    var comp3Weight = 0;
    var wp = 0;
    var sp = 0;

    if (document.forms[0].pet_weight1.value != '')
      comp1Weight = parseInt(document.forms[0].pet_weight1.value);
    else
      comp1Weight = 0;
    if (document.forms[0].pet_weight2.value != '')
      comp2Weight = parseInt(document.forms[0].pet_weight2.value);
    else
      comp2Weight = 0;
    if (document.forms[0].pet_weight3.value != '')
      comp3Weight = parseInt(document.forms[0].pet_weight3.value);
    else
      comp3Weight = 0;

    for (var x = 1; x <= numDays; x++)
    {
      var curDate = new Date(document.forms[0].arrival.value);
      var lastDate = new Date(document.forms[0].departure.value);
      
      curDate.setDate(curDate.getDate() + (x - 1));
      
      if (comp1Weight > 0)
      {
        if (dateIsHoliday(curDate.getFullYear(), curDate.getMonth(), curDate.getDate()))
        {
          //date is a holiday
          wp += GetCompanionWeightPrice(comp1Weight, "holiday");
        }
        else if (dateIsPeak(curDate))
        {
          var tempDate = new Date();
          tempDate.setMonth(curDate.getMonth());
          tempDate.setDate(curDate.getDate() + 1);
          tempDate.setFullYear(curDate.getFullYear());
          tempDate.setTime(lastDate.getTime());
          
          if (tempDate <= lastDate)
          {
            wp += GetCompanionWeightPrice(comp1Weight, "peak");
          }
        }
        else
        {
          wp += GetCompanionWeightPrice(comp1Weight, "normal");
        }
      }

      if (comp2Weight > 0)
      {
        if (dateIsHoliday(curDate.getFullYear(), curDate.getMonth(), curDate.getDate()))
        {
          //date is a holiday
          wp += GetCompanionWeightPrice(comp2Weight, "holiday");
        }
        else if (dateIsPeak(curDate))
        {
          var tempDate = new Date();
          tempDate.setMonth(curDate.getMonth());
          tempDate.setDate(curDate.getDate() + 1);
          tempDate.setFullYear(curDate.getFullYear());
          tempDate.setTime(lastDate.getTime());
          
          if (tempDate <= lastDate)
          {
            wp += GetCompanionWeightPrice(comp2Weight, "peak");
          }
        }
        else
        {
          wp += GetCompanionWeightPrice(comp2Weight, "normal");
        }
      }

      if (comp3Weight > 0)
      {
        if (dateIsHoliday(curDate.getFullYear(), curDate.getMonth(), curDate.getDate()))
        {
          //date is a holiday
          wp += GetCompanionWeightPrice(comp3Weight, "holiday");
        }
        else if (dateIsPeak(curDate))
        {
          var tempDate = new Date();
          tempDate.setMonth(curDate.getMonth());
          tempDate.setDate(curDate.getDate() + 1);
          tempDate.setFullYear(curDate.getFullYear());
          tempDate.setTime(lastDate.getTime());
          
          if (tempDate <= lastDate)
          {
            wp += GetCompanionWeightPrice(comp3Weight, "peak");
          }
        }
        else
        {
          wp += GetCompanionWeightPrice(comp3Weight, "normal");
        }
      }      
    }
    
    var bigWeight = GetBiggestWeight(comp1Weight, comp2Weight, comp3Weight);
    
    sp = GetCompanionServicesPrice(bigWeight);
    
    estPrice = (wp + sp);

    document.getElementById('pricingTotal').innerHTML = '<p><strong><font color="#772222">Estimated total: <span style="font-weight: 900;">$' + estPrice + '.00</span></font></strong></p>';
    document.getElementById('estimatedPrice').value = '$' + estPrice;
  } 
}

function GetBiggestWeight(weight1, weight2, weight3)
{
  return Math.max(weight1, weight2, weight3);
}

function GetCompanionWeightPrice(weight, type)
{
  var weightPrice = 0;
  
  switch (type)
  {
    case "holiday":
      if (weight>=0 && weight<=10) { weightPrice = 18; }
      if (weight>=11 && weight<=25) { weightPrice = 19; }
      if (weight>=26 && weight<=40) { weightPrice = 20; }
      if (weight>=41 && weight<=65) { weightPrice = 21; }
      if (weight>=66 && weight<=100) { weightPrice = 22; }
      if (weight>=101) { weightPrice = 23; }
      break;
    case "peak":
      if (weight>=0 && weight<=10) { weightPrice = 17; }
      if (weight>=11 && weight<=25) { weightPrice = 18; }
      if (weight>=26 && weight<=40) { weightPrice = 19; }
      if (weight>=41 && weight<=65) { weightPrice = 20; }
      if (weight>=66 && weight<=100) { weightPrice = 21; }
      if (weight>=101) { weightPrice = 22; }
      break;
    default:
      if (weight>=0 && weight<=10) { weightPrice = 16; }
      if (weight>=11 && weight<=25) { weightPrice = 17; }
      if (weight>=26 && weight<=40) { weightPrice = 18; }
      if (weight>=41 && weight<=65) { weightPrice = 19; }
      if (weight>=66 && weight<=100) { weightPrice = 20; }
      if (weight>=101) { weightPrice = 21; }
      break;
  }
  
  return weightPrice;
}
