function updateForm(theForm){
 	theForm.elements["adultCountValue"].value = theForm.elements["ChgAdultCount"].value;
	theForm.elements["childCountValue"].value = theForm.elements["ChgChildCount"].value;
	theForm.elements["adultOut"].value = theForm.elements["ChgAdultCount"].value;
	theForm.elements["adultOut"].readonly = true;
	theForm.elements["childOut"].value = theForm.elements["ChgChildCount"].value;
	theForm.elements["childOut"].readonly = true;
	theForm.elements["resortLOS2"].value = theForm.elements["ChgLOSValue"].value;
	changeTicket(theForm);
}

function changeTicket(theForm) 
{
    var formHopper = "";
    var formOGA = "";
    var formNonExpiring = "";

    var losStr;
    var adultStr;
    var childStr;

    var adultPrice;
    var childPrice;

    var skipDays = 0;
    var days;
    var daysInt;
    var outField;
    var dayField;
    var dayCell;
    var totalCell;
    var radioCell;
    var commissionCell;
      
    loadPrices(theForm);


    var adultCount = parseInt(theForm.elements["adultCountValue"].value);
    var childCount = parseInt(theForm.elements["childCountValue"].value);



    if(theForm.Hopper.checked) formHopper = "_PH";
    if(theForm.OGA.checked) formOGA = "_MPP";
    if(theForm.NonExpiring.checked) formNonExpiring = "_NE";

    for (var xx = 0; xx < getTotalDaysPresented(theForm);xx++){
      losStr = "LOS" + xx;

	if (theForm.elements[losStr] == null)
	{
		skipDays += 1;
		continue;
	}

      days = theForm.elements[losStr].value;

      adultStr = "Day" + days + "MYWPassAdult" + formHopper + formOGA  + formNonExpiring;
      childStr = "Day" + days + "MYWPassChild" + formHopper + formOGA  + formNonExpiring;

      adultPrice = theForm.elements[adultStr].value;
      childPrice = theForm.elements[childStr].value;

       var adultPriceOut = "";
       var childPriceOut = "";
       var totalAdultPrice = "";
       var totalChildPrice = "";
	
       //adult
       var adultDayPrice = formatCurrency(eval(adultPrice / days));
       var adultPriceOut = adultDayPrice;
       var totalAdultPrice = eval(parseFloat(adultPrice) * adultCount) ;


       // child
       var childDayPrice = formatCurrency(eval(childPrice / days));
       var childPriceOut =  childDayPrice;
       var totalChildPrice = eval(parseFloat(childPrice)  * childCount) ;


      if(adultPriceOut == "$0.00"){
        adultPriceOut = "N/A";
        childPriceOut = "N/A";
        totalAdultPrice = 0;
        totalChildPrice = 0;
      }

////////////COMMENT - load form////////////////////////////////////
// Logic in following comment block used to load the values in the fields on the form.      
      
      outField = "ticketPriceString" + xx;
      theForm[outField].value = adultPriceOut;
      theForm[outField].readonly = true;
      outFieldChild = "ticketPriceChildString" + xx;
      theForm[outFieldChild].value = childPriceOut;
      theForm[outFieldChild].readonly = true;
      //total field
      totalPriceOut = "ticketTotalPriceString" + xx;
      //alert("adult " + totalAdultPrice);
      //alert("child " + totalChildPrice);
     
      var grandTotal = formatCurrency(eval(totalAdultPrice + totalChildPrice));
      //alert("Grand " + grandTotal);
      if (grandTotal == "$0.00"){
        theForm[totalPriceOut].value = "N/A";
        theForm[totalPriceOut].readonly = true;
      }
      else{
         theForm[totalPriceOut].value = grandTotal;
         theForm[totalPriceOut].readonly = true;
      }
////////////END COMMENT - load form////////////////////////////////////

        dayCell = "dayCell" + xx;
        totalCell = "totalCell" + xx;
        radioCell = "radioCell" + xx;
        dayField = "ticketDaysString" + xx;
	var dayFieldStr = days + " Day";

//////////COMMENT - Load Day field//////////////////
//// Logic below to hide or show the number of visits if Magic Plus Pack option is selected.

	if(theForm.OGA.checked) {
		if (xx < 2) {
			document.getElementById(dayField).value = dayFieldStr + " (2 Visits)";
		} else if (xx == 2) {
			document.getElementById(dayField).value = dayFieldStr + " (3 Visits)";
		} else if (xx == 3) {
			document.getElementById(dayField).value = dayFieldStr + " (4 Visits)";
		} else if (xx == 4) {
			document.getElementById(dayField).value = dayFieldStr + " (5 Visits)";
		} else if (xx == 5) {
			document.getElementById(dayField).value = dayFieldStr + " (6 Visits)";
		} else if (xx == 6) {
			document.getElementById(dayField).value = dayFieldStr + " (7 Visits)";
		} else if (xx == 7) {
			document.getElementById(dayField).value = dayFieldStr + " (8 Visits)";
		} else if (xx == 8) {
			document.getElementById(dayField).value = dayFieldStr + " (9 Visits)";
		} else if (xx == 9) {
			document.getElementById(dayField).value = dayFieldStr + " (10 Visits)";
		}
	} else {
		document.getElementById(dayField).value = dayFieldStr;
	}
//////////END COMMENT - Load Day Field///////////////

////////////COMMENT - Highlight////////////////////////////////////
// Logic in following comment block used to highlight the row across when the radio button is selected.

        var rad = theForm.elements['TickDays'];

      if (rad[xx - skipDays].checked){
	document.getElementById(dayCell).className = "coll_04_Highlight";
        document.getElementById(totalCell).className = "coll_04_HighlightRight";
        document.getElementById(radioCell).className = "coll_03_Highlight";
        document.getElementById(radioCell).className = "coll_03_Highlight";
		
        theForm[totalPriceOut].className = "HighlightRight";
        theForm[totalPriceOut].readonly = true;
        theForm[outField].className = "Highlight";
        theForm[outField].readonly = true;
        theForm[outFieldChild].className = "Highlight";
        theForm[outFieldChild].readonly = true;
        theForm[dayField].className = "Highlight";
        theForm[dayField].readonly = true;
        
      }
      else{
        document.getElementById(dayCell).className = "coll_04";
        document.getElementById(totalCell).className = "coll_04Right";
        document.getElementById(radioCell).className = "coll_03";
        
        theForm[totalPriceOut].className = "ticketTextRight";
        theForm[totalPriceOut].readonly = true;
        theForm[outField].className = "ticketText";
        theForm[outField].readonly = true;
        theForm[outFieldChild].className = "ticketText";
        theForm[outFieldChild].readonly = true;
        theForm[dayField].className = "ticketText";
        theForm[dayField].readonly = true;
        
      }
//////////// END COMMENT - Highlight////////////////////////////////////

  }
}

function getTotalDaysPresented(theForm){
	var losTotal;
	losTotal = parseInt(theForm.losArraySize.value);
	return losTotal;
}

function formatCurrency( num ) {
        var isNegative = false;
        //num = num.toString().replace(/\\$|\\,/g,'');
	num = num.toString()
        if( isNaN( num ) ) {
          num = "0";
        }
        if ( num < 0 ) {
          num = Math.abs( num );
          isNegative = true;
        }
        cents = Math.floor( ( num * 100 + 0.5 ) % 100 );
        num = Math.floor( ( num * 100 + 0.5 ) / 100 ).toString();
        if ( cents < 10 ) {
          cents = "0" + cents;
        }
        for ( i = 0; i < Math.floor( ( num.length - ( 1 + i ) ) / 3 ); i++) {
          num = num.substring( 0 ,num.length - ( 4 * i + 3 ) ) + ',' + num.substring( num.length - ( 4 * i + 3 ) );
        }

        var result = '$' + num + '.' + cents;
        if ( isNegative ) {
          result = "-" + result;
        }
        return result;
}