﻿// JScript File




var sLodgingsSelected="";

function ProcessFeeChange() 
{
	objRegCost = document.getElementById("RegCost");
	objGrandTotal = document.getElementById("GrandTotal");
	
	if(objRegCost) {
		if(IsNumeric(objRegCost.value)) {
			objGrandTotal.value=objRegCost.value
			CalculateDeposit();
		} else {
			alert("Please enter a numeric value for the Fee");			 
		}
	}
}
	

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
    
    if(sText.length==0) {
      return false;
    }
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
   }

  function SetFamilyCampoutChoices() 
  {
	    objTable1 = document.getElementById("LodgingTable");
	    objTable2 = document.getElementById("ServicesTable");
	    objTable3 = document.getElementById("FoodTable");
	    objTable4 = document.getElementById("RegistrationTable");
    if(document.registration.EventType[0].checked) {
	    objTable1.style.display="none";
	    objTable2.style.display="none";
	    objTable3.style.display="none";
	    objTable4.style.display="none";
    } else {
	    objTable1.style.display="inline";
	    objTable2.style.display="inline";
	    objTable3.style.display="inline";
	    objTable4.style.display="inline";
    }
  }

  function ApplyVolunteerDiscount() {
    
    var cGrandTotal=0;
	  objCheckBox = document.getElementById("Volunteer");
	  objGrandTotal = document.getElementById("GrandTotal");
    if(IsNumeric(objGrandTotal.value)) { cGrandTotal=parseFloat(objGrandTotal.value)}

    if(objCheckBox.checked) {
      cGrandTotal=.5*cGrandTotal
    } else {
      cGrandTotal=2*cGrandTotal
    }
    objGrandTotal.value=cGrandTotal
    CalculateDeposit();
  }
  
  function CalculateDeposit() 
  {
    var cGrandTotal=0, cDeposit=0;
	  objGrandTotal = document.getElementById("GrandTotal");
	  objDeposit = document.getElementById("Deposit");
    if(IsNumeric(objGrandTotal.value)) { cGrandTotal=parseFloat(objGrandTotal.value)}

    objDeposit.value=.5*cGrandTotal  
  }

 	function calcRegistration()
	{	
    var cServicesTotal=0, cGrandTotal=0, cCost=0, cPeople=0, cCurrCost=0;

	  objGrandTotal = document.getElementById("GrandTotal");
	  objCost = document.getElementById("RegCost");
	  objPeople = document.getElementById("RegPPL");

    if(IsNumeric(objGrandTotal.value)) { cGrandTotal=parseFloat(objGrandTotal.value)}
    if(IsNumeric(objCost.value)) { cCurrCost=parseFloat(objCost.value)}

    if(objPeople!=null) { 
      objPeople.value.replace(/ /,"");
      if(IsNumeric(objPeople.value)) {
        cPeople=objPeople.value;
        iRegisteredPeople=cPeople;
		  } else {
		    if(objPeople.value=="") {
		      objCost.value="";
	        cGrandTotal=cGrandTotal-cCurrCost;
	        cCurrCost="";
	        iRegisteredPeople=0;
		    } else {
		      alert("Please enter only a number");
		      objPeople.focus();
		      return;
		    }
		  }
//		  alert(cPeople)
		  if(cPeople>0) {
		    cCurrCost=cPeople*2
		    cGrandTotal=cGrandTotal+cCurrCost
		  }
		  objCost.value=cCurrCost;
		  objGrandTotal.value=cGrandTotal;
      CalculateDeposit();
	  }

  }

function calcAllServicesTotal() {

	  objServicesTotal = document.getElementById("ServicesCost");
	  objServicesTotal.value=0;
	  objCheckBox = document.getElementById("CCenterhalf");
	  if (objCheckBox.checked) {calcServicesTotal("CCenterhalf","CCCost",50)};
	  objCheckBox = document.getElementById("CCenter");
	  if (objCheckBox.checked) calcServicesTotal("CCenter","CCCost",100);
	  objCheckBox = document.getElementById("CDininghalf");
	  if (objCheckBox.checked) calcServicesTotal("CDininghalf","CCCost",25);
	  objCheckBox = document.getElementById("CDining");
	  if (objCheckBox.checked) calcServicesTotal("CDining","CCCost",50);
}

 	function calcServicesTotal(CheckBox,CostBox,DollarAmt)
	{	
    var cServicesTotal=0, cGrandTotal=0, cCost=0, cCCDays=1, cLodgingCost=0;

    if(CheckBox!="Bonfire") { 
      if(sLodgingsSelected!="") return true;
    }
    
	  objCheckBox = document.getElementById(CheckBox);
	  objGrandTotal = document.getElementById("GrandTotal");
	  objLodgingCost = document.getElementById("LodgingCost");
	  objServicesTotal = document.getElementById("ServicesCost");
	  objCost = document.getElementById(CostBox);
	  objCCDays = document.getElementById("CCDays");

    if(objServicesTotal) { if(IsNumeric(objServicesTotal.value)) { cServicesTotal=parseFloat(objServicesTotal.value)}}
    if(objGrandTotal) { if(IsNumeric(objGrandTotal.value)) { cGrandTotal=parseFloat(objGrandTotal.value)}}
    if(objLodgingCost) { if(IsNumeric(objLodgingCost.value)) { cLodgingCost=parseFloat(objLodgingCost.value)}}
    if(objCost) { if(IsNumeric(objCost.value)) { cCost=parseFloat(objCost.value)}}
    if(objCCDays) { if(IsNumeric(objCCDays.value)) { cCCDays=parseFloat(objCCDays.value)}}    

    if(objCheckBox!=null) {     
      DollarAmt=cCCDays*DollarAmt
      if(!objCheckBox.checked) {
        if (cServicesTotal>0) { DollarAmt=-1.0*DollarAmt};
      }
      cCost=cCost+DollarAmt
      cServicesTotal=cServicesTotal+DollarAmt
      cGrandTotal=cGrandTotal+DollarAmt
	    objCost.value=cCost;
	    objServicesTotal.value=cServicesTotal;
	    objGrandTotal.value=cGrandTotal;
	    objCCDays.value=cCCDays;
      CalculateDeposit();
    }

  }

 	function calcLodgingRowTotal(Type,DollarAmt,MaxPeople)
	{	

	  var cTotalBox=0,  cPeople=1, cNights=0,cNewCost=0, cCurrCost=0,cLodgingTotal=0, cGrandTotal=0,cCurrLinenCost=0;
	  var objCost, objPeople, objNights, objCheckBox, cRegPeople=0;;
	  
	  
	  objCheckBox = document.getElementById(Type);
	  objCost = document.getElementById(Type + "Cost");
	  objGrandTotal = document.getElementById("GrandTotal");
	  objLodgingCost = document.getElementById("LodgingCost");
	  objPeople = document.getElementById(Type + "PPL");
	  objNights = document.getElementById(Type + "Ngts");

    if(IsNumeric(objCost.value)) { cCurrCost=objCost.value}
    if(objLodgingCost) { if(IsNumeric(objLodgingCost.value)) { cLodgingTotal=parseFloat(objLodgingCost.value)}}
    if(IsNumeric(objGrandTotal.value)) { cGrandTotal=parseFloat(objGrandTotal.value)}

	  if(Type=="Linen") {	  
	    objLinenCost = document.getElementById("LinenCost");
	    objRegPeople = document.getElementById("RegPPL");
	    objLinen = document.getElementById("Linen");

      if(objLinenCost) { if(IsNumeric(objLinenCost.value)) { cCurrLinenCost=parseFloat(objLinenCost.value)}}
      if(objRegPeople) { if(IsNumeric(objRegPeople.value)) { cRegPeople=parseFloat(objRegPeople.value)}}

		  if(objLinen) {
			  if(objLinen.checked) {
				cCurrLinenCost=cRegPeople*DollarAmt
				objLinenCost.value=cCurrLinenCost;
			  } else {
				cCurrLinenCost=-1*cRegPeople*DollarAmt		  
				objLinenCost.value="";
			  }
		  }
	    objGrandTotal.value=cGrandTotal+cCurrLinenCost;
	    objLodgingCost.value=cLodgingTotal+cCurrLinenCost;
	  
	    return true;
	  }
	  

    if(objNights!=null) { 
      objNights.value.replace(/ /,"");
      if(IsNumeric(objNights.value)) {
        cNights=objNights.value;
		  } else {
		    if(objNights.value=="") {
		      objCost.value="";
	        cLodgingTotal=cLodgingTotal-cCurrCost;
	        cGrandTotal=cGrandTotal-cCurrCost;
	        objCheckBox.checked=false;
          sLodgingsSelected=sLodgingsSelected.replace(Type,"");
		    } else {
		      alert("Please enter only a number");
		      objNights.focus();
		      return;
		    }
		  }
	  }
    if(objPeople!=null) { 
      objPeople.value.replace(/ /,"");
      if(IsNumeric(objPeople.value)) {
        cPeople=objPeople.value;
        if(cPeople>MaxPeople) {
          cPeople=MaxPeople;
          objPeople.value=cPeople;
        }
		  } else {
		    if(objPeople.value=="") {
		      if(objNights.value!="") {
		        cPeople=0;
		        objCost.value="";
	          cLodgingTotal=cLodgingTotal-cCurrCost;
	          cGrandTotal=cGrandTotal-cCurrCost;
	          objCheckBox.checked=false;
            sLodgingsSelected=sLodgingsSelected.replace(Type,"");
	        }
		    } else {
		      alert("Please enter only a number");
		      objPeople.focus();
		      return;
		    }
		  }
	  }
	  if(cNights>0) {
	    if(objPeople!=null) { 
        if(objPeople.value==""&&cCurrCost==0) {return;}
      } 
	    cNewCost=cNights*DollarAmt*cPeople;
	    objCost.value=cNewCost;
	    cLodgingTotal=cLodgingTotal + 0.0 + cNewCost;
	    cGrandTotal=cGrandTotal + 0.0 + cNewCost;
	    objCheckBox.checked=true;
      sLodgingsSelected=sLodgingsSelected+Type;
	    objConferenceCost = document.getElementById("CCCost");
      objConferenceCost.value="";
	  }
	  objLodgingCost.value=cLodgingTotal;
	  objGrandTotal.value=cGrandTotal;
	  if (cLodgingTotal==0) {calcAllServicesTotal();}
    CalculateDeposit();

	}

  function CheckForDeluxeDiscount(Type) {
    if(Type!="Snack") return false;
  
	  objBreakFastType = document.getElementById("BreakfastType");
	  objLunchType = document.getElementById("LunchType");
	  objDinnerType = document.getElementById("DinnerType");
	  if((objBreakFastType.selectedIndex+1)==objBreakFastType.length) {
	    if((objLunchType.selectedIndex+1)==objLunchType.length) {
	      if((objDinnerType.selectedIndex+1)==objDinnerType.length) {
    	    return true;
	      }  	  
	    }	  
	  }
	  return false;
  }

 	function calcFoodRowTotal(Type)
	{	

	  var cAmount=0,  cPeople=0, cTimes=0,cNewCost=0, cCurrCost=0,cFoodTotal=0, cGrandTotal=0;
	  var objCost, objPeople, objNights, objCheckBox;

	  objCost = document.getElementById(Type + "Cost");
	  objGrandTotal = document.getElementById("GrandTotal");
	  objFoodCost = document.getElementById("FoodCost");
	  objPeople = document.getElementById(Type + "PPL");
	  objTimes = document.getElementById(Type + "Iteration");
	  objType = document.getElementById(Type + "Type");

    if(IsNumeric(objCost.value)) { cCurrCost=objCost.value}
    if(IsNumeric(objFoodCost.value)) { cFoodTotal=parseFloat(objFoodCost.value)}
    if(IsNumeric(objGrandTotal.value)) { cGrandTotal=parseFloat(objGrandTotal.value)}
    if(objType) { if(IsNumeric(objType.value)) { cAmount=parseFloat(objType.value)}}
    
    if(objTimes!=null) { 
      objTimes.value.replace(/ /,"");
      if(IsNumeric(objTimes.value)) {
        cTimes=objTimes.value;
		  } else {
		    if(objTimes.value=="") {
		      objCost.value="";
	        cFoodTotal=cFoodTotal-cCurrCost;
	        cGrandTotal=cGrandTotal-cCurrCost;
		    } else {
		      alert("Please enter only a number");
		      objTimes.focus();
		      return;
		    }
		  }
	  }
    if(objPeople!=null) { 
      objPeople.value.replace(/ /,"");
      if(IsNumeric(objPeople.value)) {
        cPeople=objPeople.value;
		  } else {
		    if(objPeople.value=="") {
		      objCost.value="";
	        cFoodTotal=cFoodTotal-cCurrCost;
	        cGrandTotal=cGrandTotal-cCurrCost;
		    } else {
		      alert("Please enter only a number");
		      objPeople.focus();
		      return;
		    }
		  }
	  }
	  
	  if(cTimes>0&&cPeople>0) {
	    // Only caveat - if getting deluxe meals rest of day, get free snack
	    if(!CheckForDeluxeDiscount(Type)){
	      cNewCost=cTimes*cAmount*cPeople;
	      if(cCurrCost>0){
	        cFoodTotal=cFoodTotal-cCurrCost;
	        cGrandTotal=cGrandTotal-cCurrCost;	      
	      }
	      objCost.value=cNewCost;
	      cFoodTotal=cFoodTotal + 0.0 + cNewCost;
	      cGrandTotal=cGrandTotal + 0.0 + cNewCost;
	    }
	  }
	  objFoodCost.value=cFoodTotal;
	  objGrandTotal.value=cGrandTotal;
    CalculateDeposit();
	}

  function ToggleLodging(Type,DollarAmt,MaxPeople)
  {
  
    var cRegPeople=0;
    
	  objRegPeople = document.getElementById("RegPPL");
	  objCheckBox = document.getElementById(Type);
	  objPeople = document.getElementById(Type + "PPL");
	  objNights = document.getElementById(Type + "Ngts");
    if(IsNumeric(objRegPeople.value)) { cRegPeople=objRegPeople.value}

    if(objCheckBox.checked==false) {
	    if(objPeople!=null) {objPeople.value="";}
	    objNights.value="";
      calcLodgingRowTotal(Type,DollarAmt,MaxPeople) 
      sLodgingsSelected=sLodgingsSelected.replace(Type,"");
   } else {
      if(objPeople==null) {
        objNights.focus()
      } else {
        objPeople.focus()
        if(cRegPeople>0) {
          objPeople.value=cRegPeople
        }
      }
   }
   return true;
  }
