﻿// KENT COUNTY SHOWGROUND FUNCTIONS

var bChangeCartQuantity = false;

$(document).ready(function(){
   $("input.empty").click(function(){
        bChangeCartQuantity = true;
   }); 
});

// UP TO 2 FREE Children per Adult ticket
function freeChildCalculation(adultId,childId,freeChildId){
    var bValid = true;
    
    var adultQuantity = 'quantity|' + adultId;
    var childQuantity = 'quantity|' + childId;
    var freeChildQuantity = 'quantity|' + freeChildId;
    
    var adultCount = document.getElementById(adultQuantity).value;
    var childCount = document.getElementById(childQuantity).value;
    var freeChildEntitlement = adultCount * 2;
    
    // if there are adults & children
    if (adultCount > 0 && childCount > 0) {
          
          // adjust free children value
          
          if (freeChildEntitlement >= childCount){
          
            // All Children are free, 0 child products and add to freeChild Products
            document.getElementById(freeChildQuantity).value = childCount;
            document.getElementById(childQuantity).value = 0;
            
          } else {
          
            var remaindingChildren = childCount - freeChildEntitlement;
            document.getElementById(freeChildQuantity).value = freeChildEntitlement;
            document.getElementById(childQuantity).value = remaindingChildren;
            
          }
          
    }
    
    
    return bValid
}

function resetCart(){
    var bcartValid=true;
    
    if (bChangeCartQuantity){
        if(confirm("On the next page you will need to enter the exact quantities again.\n  Would you like to proceed?")){
            $("input.empty").val('Empty Cart');
        } else {
            bChangeCartQuantity=false
            bcartValid=false;
        }
    }
    return bcartValid;
}
