/* written by: Theron P. Keller
 * with help from lots of sample code from various and sundry places
 * Thanks to George Raudabaugh for help with the indexing techniques
 *          and for providing feedback!
 * tpkeller@rocketmail.com
 * Version 4.16, released January 25, 2009. 
 * Copyright © 2002 - 2009 Theron P. Keller
 */

function SaveCookies ()
            {
                        if (document.CruiseInfo.ckbxSave.checked)
                                    {
                                                SetCookie('days',document.CruiseInfo.Days.value,exp);
                                                SetCookie('adults',document.CruiseInfo.Adults.value,exp);
                                                SetCookie('children',document.CruiseInfo.Children.value,exp);
                                                SetCookie('discount',document.CruiseInfo.childFull.checked,exp);
                                    }
                        else
                                    {
                                                DeleteCookie('days');
                                                DeleteCookie('adults');
                                                DeleteCookie('children');
                                                DeleteCookie('discount');
                                    }
            }

function LoadCookies ()
            {
                        var cdays = GetCookie('days');
                        idays = cdays == null ? 7 : cdays;  // boy this is ugly but it
                        var cadults = GetCookie('adults');
                        iadults = cadults == null ? 2 : cadults;// works nicely for default values
                        var cchildren = GetCookie('children');
                        ichildren = cchildren == null ? 0 : cchildren;
                        var cdiscount = GetCookie('discount');
                        bdiscount = cdiscount == null ? "true" : cdiscount == "true" ? true : false;

                        // check to see if we found a cookie, if so, check the checkbox
                        if ((cdays == null) && (cadults == null) && (cchildren == null))
                                    {
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }
                        else
                                    {
                                                // save it again to update the expiration
                                                SetCookie('days',idays,exp);
                                                SetCookie('adults',iadults,exp);
                                                SetCookie('children',ichildren,exp);
                                                SetCookie('discount',bdiscount,exp);
                                                document.CruiseInfo.ckbxSave.checked=true;
                                    }
                        document.CruiseInfo.Days.value = idays;
                        document.CruiseInfo.Adults.value = iadults;
                        document.CruiseInfo.Children.value = ichildren;
                        document.CruiseInfo.childFull.checked = bdiscount;
            }

function SuggestAlert ()
            {
                        alert("These amounts are based on guidelines provided by" +
                        " \nthe cruise line.  This calculation is only for your reference." +
                        '\n\nIf there is no "suggested" amount, it is because the cruise' +
                        "\nline has specifically stated that the tip amount is at your discretion.");
            }

function ChildrenAlert ()
            {
                        alert("Tipping for children can be somewhat controversial.  In the past, some," +
                        " \ncruise lines suggested that children may, in certain circumstances," +
                        " \ntip at 50% the rate paid by adults.  At this time, I am not aware of any cruise" +
                        " \nlines that provide this exception in their official recommendation." +
                        '\n\nAs the author of this calculator, I do not offer a recommendation on how much you' +
                        " \nshould tip for your children.  I encourage you to seek guidance from the cruise" +
                        " \nline on which you are traveling, and tip according to the service you receive." +
                        '\n\nIf you decide to tip the adult rate for your children, leave the "Full Tip"' +
                        '\ncheckbox selected.  If you decide to tip 50% of the adult rate for them, simply' +
                        ' \nuncheck the "Full Tip" checkbox.' +
                        '\n\nSince no cruise lines currently specify partial tipping for children, the "Full Tip"' +
                        '\ncheckbox will be selected by default for all cruise lines.');
            }

function ActualAlert ()
            {
                        alert("In this column you should enter the ACTUAL tip you wish to" +
                        " \ngive to each staff person at the end of the cruise." +
                        "\n\nNOTE:  Partial dollars are rounded UP to the next highest dollar!" +
                        "\n\nYou may TYPE in the actual tip amount, or you can click on the" +
                        ' \n"Transfer" button to move the Suggested amounts over to the Actual' +
                        ' \ncolumn.' +
                        '\n\nYou may use the "-1" link to decrease the tip by $1, or you may use' +
                        ' \nthe "Nxt 5" link to round the tip amount up to the next highest $5.' +
                        '\n\nYou may use these links multiple times to correctly adjust the Actual' +
                        '\ntip amount.');
            }

function CookieAlert ()
            {
                        alert("Clicking the Save checkbox will use a cookie" +
                        "\nto store these values so that the next time you visit" +
                        "\nthis page it will remember the details of your cruise." +
                        "\n\nThe default values are 7 Nights, 2 Adults and 0 Children.");
            }

function TradAlert ()
            {
                        alert("This section covers cruise lines that generally utilize traditional" +
                        "\ntipping, namely, tips are paid to the service personnel directly," +
                        "\nusing cash in individual envelopes.  These lines may also allow other," +
                        "\nmore convenient methods to take this payment, but it is not uncommon" +
                        "\nfor passengers to tip in cash.");
            }

function SCAlert ()
            {
                        alert("This section covers cruise lines that have either mostly" +
                        "\nor entirely switched their tipping to some form of a service" +
                        "\ncharge.  Some will allow you to adjust the amount.  Generally" +
                        "\nspeaking, most people pay this charge at booking or through their" +
                        "\nshipboard account, rather than directly in cash." +
                        "\n\nWhile some lines still break out how the money is divided up," +
                        "\nother lines do not provide that information, so it is not possible to" +
                        "\ncorrectly ascertain how the service charge is distributed among the" +
                        "\nservice personnel who assisted you during your cruise." +
                        "\n\nThe main purpose of this section is to provide information that" +
                        "\nwill allow you to easily and correctly budget for the service charge" +
                        "\nthat will be applied to your account.");
            }

function DaysAlert ()
            {
                        alert("The length of a cruise is generally DISCUSSED in terms" +
                        '\nof "days", however it is actually COUNTED in terms of "nights".' +
                        '\n\nNo matter what time you embark or disembark the ship, the length' +
                        "\n\of your cruise in days is the number of nights you spend on board.");
            }

function DisneyAlert ()
            {
                        alert('As of July 13, 2008, Disney Cruise Line has updated the recommended' +
                        '\ntip amount for their tipped staff.  The new amounts implement a slight' +
                        '\nincrease, but more importantly, they bring Disney in line with the rest' +
                        '\nof the cruise industry by recommending amounts that are consistent on a' +
                        '\n"per person / per day" basis across the extent of their itinerary offerings.' +
                        '\n\nThese new recommendations should make tip calculation easier for all' +
                        '\nDisney passengers.' );
            }

function Default ()
            {
                        LoadCookies();
                        Suggest();
                        Calculate();
            }

function Suggest ()
            {
            var fTemp = 0.0;
            var fTempTPPPD = 0.0;
            var fTPPPDTotal = 0.0;
            var fRecTipTotal = 0.0;

            with (document.CruiseInfo)
                        {
                                    // ADD BULLETPROOFING HERE TO CHECK FOR NaN
                                    var childs = 0;
                                    var days= parseInt(Days.value);
                                    if(isNaN(days))
                                                {
                                                            alert('You must enter a NUMBER for "Days"');
                                                }
                                    else
                                                {
                                                            Days.value = days;
                                                }
                                    var adults= parseInt(Adults.value);
                                    if(isNaN(adults))
                                                {
                                                            alert('You must enter a NUMBER for "Adults"');
                                                }
                                    else
                                                {
                                                            Adults.value = adults;
                                                            gAdults = adults;
                                                }
                                    // "children" is a keyword, have to use "childs"
                                    if (Children.value == "")
                                                {
                                                            childs = 0;
                                                }
                                    else
                                                {
                                                            childs = parseInt(Children.value);
                                                }
                                    if(isNaN(childs))
                                                {
                                                            alert('You must enter a NUMBER for "Children"');
                                                }
                                    else
                                                {
                                                            Children.value = childs;
                                                }

                                    if (document.CruiseInfo.childFull.checked)
                                                {
                                                            factor = days*(adults+childs);      // full rate for children
                                                }
                                    else
                                                {
                                                            factor = days*(adults+childs*0.5); // 50% rate for children
                                                }

// this poor programming style has bit me this many times:  2
//
                                    if (lineradio[0].checked)           // Crystal Radio Button
                                                {
                                                            CheckCrystal();
                                                }
                                    if (lineradio[1].checked)           // Crystal Penthouse Radio Button
                                                {
                                                            CheckCrystal();
                                                }
                                    }

//          calculate the suggested total tip
            for (i=1; i <= 8; i++)
                        {
                                    fTempTPPPD = parseFloat(document.StaffInfo["TPPPD" + i].value);
                                    fTemp= fTempTPPPD * factor;
                                    if(!isNaN(fTemp))
                                                {
                                                document.StaffInfo["RecTip" + i].value = formatCurrency(fTemp);
                                                fRecTipTotal += fTemp;
                                                document.StaffInfo["TPPPD" + i].value = formatCurrency(fTempTPPPD);
                                                fTPPPDTotal += fTempTPPPD;
                                                }
                                    else
                                                {
                                                document.StaffInfo["RecTip" + i].value="";
                                                }
                        }
            document.StaffInfo.StaffT.value="Totals:";
            document.StaffInfo.TPPPDT.value=toBills(formatCurrency(fTPPPDTotal));
            document.StaffInfo.RecTipT.value=toBills(formatCurrency(fRecTipTotal));

            }

function Calculate ()
            {
            var fTemp = 0.0;
            var fTipTotal = 0;
            var fFifty = 0,                     fFiftyT = 0;
            var fTwenty = 0,        fTwentyT = 0;
            var fTen = 0,                       fTenT = 0;
            var fFive = 0,                      fFiveT = 0;
            var fOne = 0,                       fOneT = 0;

            for (i=1; i <= 8; i++)
                        {


                        // make the Actual Tip amounts look nice
                        fTemp = parseFloat(document.StaffInfo["ActTip" + i].value);
                        if(!isNaN(fTemp))
                                    {
                                    fTemp = Math.ceil(fTemp);
                                    fTipTotal += fTemp;
                                    fTemp = formatCurrency(fTemp);
                                    }
                        else
                                    {
                                    fTemp="";
                                    }
                        document.StaffInfo["ActTip" + i].value = fTemp;

                        // calculate the bills
                        if (document.StaffInfo.use50s.checked)
                                    {
                                                fFifty = Math.floor(fTemp/50.0);
                                                fFiftyT += fFifty;
                                                fTemp = fTemp - (fFifty * 50.0);
                                    }

                        fTwenty = Math.floor(fTemp/20.0);
                        fTemp = fTemp - (fTwenty * 20.0);
                        fTwentyT += fTwenty;

                        fTen = Math.floor(fTemp/10.0);
                        fTemp = fTemp - (fTen * 10.0);
                        fTenT += fTen;

                        fFive = Math.floor(fTemp/5.0);
                        fTemp = fTemp - (fFive * 5.0);
                        fFiveT += fFive;

                        fOne = Math.floor(fTemp);
                        fOneT += fOne;

                        document.StaffInfo["D50s" + i].value=toBills(fFifty);
                        document.StaffInfo["D20s" + i].value=toBills(fTwenty);
                        document.StaffInfo["D10s" + i].value=toBills(fTen);
                        document.StaffInfo["D5s" + i].value=toBills(fFive);
                        document.StaffInfo["D1s" + i].value=toBills(fOne);

                        }

            document.StaffInfo.ActTipT.value=toBills(formatCurrency(fTipTotal));
            document.StaffInfo.D50sT.value=toBills(fFiftyT);
            document.StaffInfo.D20sT.value=toBills(fTwentyT);
            document.StaffInfo.D10sT.value=toBills(fTenT);
            document.StaffInfo.D5sT.value=toBills(fFiveT);
            document.StaffInfo.D1sT.value=toBills(fOneT);

            }

function Transfer ()
            {
            for (i=1; i <= 8; i++)
                        {
                                    fTemp = document.StaffInfo["RecTip" + i].value;
                                    if(!(fTemp)==0.0)
                                    {
                                                document.StaffInfo["ActTip" + i].value = formatCurrency(fTemp);
                                    }
                        }
            Calculate();
            }

function Inc (i, j)     //increment (or decrement) actual tip row "i" by "j" amount
            {
                        fTemp = parseFloat(document.StaffInfo["ActTip" + i].value);
                        if((!isNaN(fTemp)) && (fTemp > 0.0))
                        {
                                    document.StaffInfo["ActTip" + i].value = formatCurrency(fTemp + j);
                                    Calculate();
                        }
            }

function Next (i, j)    //round actual tip row "i" up to next "j"
            {
                        fTemp = parseFloat(document.StaffInfo["ActTip" + i].value);
                        fOldTemp = fTemp;
                        if(!isNaN(fTemp))
                        {
                                    fTemp = fTemp / j;
                                    fTemp = Math.ceil(fTemp);
                                    fTemp = fTemp * j;
                                    if(fTemp == fOldTemp)
                                    {
                                                fTemp = fTemp + j;
                                    }
                                    document.StaffInfo["ActTip" + i].value = formatCurrency(fTemp);
                                    Calculate();
                        }
            }

function ResetAll ()
            {

            LoadCookies();

            for (i=1; i <= 8; i++)
                        {
                        document.StaffInfo["Staff" + i].value="";
                        document.StaffInfo["TPPPD" + i].value="";
                        document.StaffInfo["RecTip" + i].value="";
                        document.StaffInfo["ActTip" + i].value="";
                        document.StaffInfo["Staff" + i].value="";
                        document.StaffInfo["ActTip" + i].value="";
                        document.StaffInfo["D50s" + i].value="";
                        document.StaffInfo["D20s" + i].value="";
                        document.StaffInfo["D10s" + i].value="";
                        document.StaffInfo["D5s" + i].value="";
                        document.StaffInfo["D1s" + i].value="";
                        }
            document.StaffInfo.StaffT.value="";
            document.StaffInfo.TPPPDT.value="";
            document.StaffInfo.RecTipT.value="";
            document.StaffInfo.ActTipT.value="";
            document.StaffInfo.use50s.checked=Boolean(1);
            document.StaffInfo.D50sT.value="";
            document.StaffInfo.D20sT.value="";
            document.StaffInfo.D10sT.value="";
            document.StaffInfo.D5sT.value="";
            document.StaffInfo.D1sT.value="";

//          reset the radio buttons
            for (i=1; i <= 20; i++)
                        {
                        document.CruiseInfo.lineradio[i].checked=false;
                        }
            }

function Example ()
            {
                        LoadCookies();

                        ResetCelebrity ( );

                        document.CruiseInfo.lineradio[1].checked=true;
                        document.StaffInfo["ActTip1"].value = 70.0;
                        document.StaffInfo["ActTip2"].value = 30.0;
                        document.StaffInfo["ActTip3"].value = 11.0;
                        document.StaffInfo["ActTip4"].value = 50.0;
                        document.StaffInfo["ActTip5"].value = 10.0;
                        document.StaffInfo.Staff7.value="These are EXAMPLES";
                        document.StaffInfo.Staff8.value="Click RESET to start over";
                        Suggest();
                        Calculate();

            }

function ResetCelebrity ( )
            {
// remove old half tipping for children
//                        if (document.CruiseInfo.childFull.checked == true)
//                                    {
//                                                document.CruiseInfo.childFull.checked = false;
//                                                document.CruiseInfo.ckbxSave.checked=false;
//                                    }

                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Waiter";
                        document.StaffInfo.TPPPD1.value="3.65";
                        document.StaffInfo.Staff2.value="Assistant Waiter";
                        document.StaffInfo.TPPPD2.value="2.10";
                        document.StaffInfo.Staff3.value="Dining Room Management";
                        document.StaffInfo.TPPPD3.value="1.00";
                        document.StaffInfo.Staff4.value="Stateroom Service";
                        document.StaffInfo.TPPPD4.value="3.50";
                        document.StaffInfo.Staff5.value="Other Service Personnel";
                        document.StaffInfo.TPPPD5.value="1.25";

                        for (i=6; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCelebrityCC ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Waiter";
                        document.StaffInfo.TPPPD1.value="3.65";
                        document.StaffInfo.Staff2.value="Assistant Waiter";
                        document.StaffInfo.TPPPD2.value="2.10";
                        document.StaffInfo.Staff3.value="Dining Room Management";
                        document.StaffInfo.TPPPD3.value="1.00";
                        document.StaffInfo.Staff4.value="Stateroom Service";
                        document.StaffInfo.TPPPD4.value="4.00";
                        document.StaffInfo.Staff5.value="Other Service Personnel";
                        document.StaffInfo.TPPPD5.value="1.25";

                        for (i=6; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCelebritySuite ( )
            {
                        ResetCelebrity ( );
                        document.StaffInfo.Staff6.value="Butler (suites)";
                        document.StaffInfo.TPPPD6.value="3.50";
            }

function ResetRCCL ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Waiter";
                        document.StaffInfo.TPPPD1.value="3.50";
                        document.StaffInfo.Staff2.value="Assistant Waiter";
                        document.StaffInfo.TPPPD2.value="2.00";
                        document.StaffInfo.Staff3.value="Stateroom Attendant";
                        document.StaffInfo.TPPPD3.value="3.50";
                        document.StaffInfo.Staff4.value="Headwaiter";
                        document.StaffInfo.TPPPD4.value="0.75";

                        for (i=5; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetRCCLSuite ( )
            {
                        ResetRCCL ( );
                        document.StaffInfo.Staff3.value="Suite Attendant";
                        document.StaffInfo.TPPPD3.value="5.75";
            }

function ResetAzamara ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Gratuities";
                        document.StaffInfo.TPPPD1.value="12.25";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetPrincess ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Hotel and Dining charge";
                        document.StaffInfo.TPPPD1.value="10.50";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetPrincessSuite ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Hotel and Dining charge";
                        document.StaffInfo.TPPPD1.value="11.00";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetHAL ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Hotel Service Charge";
                        document.StaffInfo.TPPPD1.value="11.00";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetNCL ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Service Charge";
                        document.StaffInfo.TPPPD1.value="12.00";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCostaE ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Gratuities";
                        document.StaffInfo.TPPPD1.value="7.50";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCostaC ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Stateroom Steward/ess";
                        document.StaffInfo.TPPPD1.value="3.00";
                        document.StaffInfo.Staff2.value="Waiter";
                        document.StaffInfo.TPPPD2.value="3.00";
                        document.StaffInfo.Staff3.value="Waiter's Assistant";
                        document.StaffInfo.TPPPD3.value="1.50";
                        document.StaffInfo.Staff4.value="Head Waiter";
                        document.StaffInfo.TPPPD4.value="1.00";

                        for (i=5; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetOceania ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Gratuity";
                        document.StaffInfo.TPPPD1.value="12.50";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetOceaniaButler ( )
            {
                        ResetOceania ( );
                        document.StaffInfo.Staff2.value="Butler";
                        document.StaffInfo.TPPPD2.value="4.00";
            }

function ResetCunard ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Hotel and Dining charges";
                        document.StaffInfo.TPPPD1.value="11.00";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCunardGrill ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Hotel and Dining charges";
                        document.StaffInfo.TPPPD1.value="13.00";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCustom ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Enter custom staff and";
                        document.StaffInfo.TPPPD1.value="tips";
                        document.StaffInfo.RecTip1.value="";
                        document.StaffInfo.ActTip1.value="";

                        for (i=2; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCarnival ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Dining Team Service";
                        document.StaffInfo.TPPPD1.value="5.50";
                        document.StaffInfo.Staff2.value="Bistro Service";
                        document.StaffInfo.TPPPD2.value="1.00";
                        document.StaffInfo.Staff3.value="Cabin Services";
                        document.StaffInfo.TPPPD3.value="3.50";
                        document.StaffInfo.Staff4.value="Maître d'";
                        document.StaffInfo.TPPPD4.value="";

                        for (i=5; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ClearActual ( )
            {
                        for (i=1; i <= 8; i++)
                                    {
                                    document.StaffInfo["ActTip" + i].value="";
                                    }
            }

function CheckCrystal ( )
            {
                        if (gAdults == 1)
                                    {
                                                document.StaffInfo.TPPPD1.value="5.00";
                                    }
                        else
                                    {
                                                document.StaffInfo.TPPPD1.value="4.00";
                                    }
            }

function ResetCrystal ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Stewardess";
                        CheckCrystal();
                        document.StaffInfo.Staff2.value="Waiter";
                        document.StaffInfo.TPPPD2.value="4.00";
                        document.StaffInfo.Staff3.value="Assistant Waiter";
                        document.StaffInfo.TPPPD3.value="2.50";
                        document.StaffInfo.Staff4.value="Maître d'";
                        document.StaffInfo.TPPPD4.value="";
                        document.StaffInfo.Staff5.value="Headwaiter";
                        document.StaffInfo.TPPPD5.value="";
                        document.StaffInfo.Staff6.value="Assistant Stewardess";
                        document.StaffInfo.TPPPD6.value="";

                        for (i=7; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function ResetCrystalPenthouse ( )
            {
                        ResetCrystal ( );
                        document.StaffInfo.Staff7.value="Butler (Penthouse)";
                        document.StaffInfo.TPPPD7.value="4.00";
            }


function ResetDisney ( )
            {
                        if (document.CruiseInfo.childFull.checked == false)
                                    {
                                                document.CruiseInfo.childFull.checked = true;
                                                document.CruiseInfo.ckbxSave.checked=false;
                                    }

                        document.StaffInfo.Staff1.value="Dining Room Server";
                        document.StaffInfo.TPPPD1.value="4.00";
                        document.StaffInfo.Staff2.value="Assistant Server";
                        document.StaffInfo.TPPPD2.value="3.00";
                        document.StaffInfo.Staff3.value="Head Server";
                        document.StaffInfo.TPPPD3.value="1.00";
                        document.StaffInfo.Staff4.value="Stateroom Host/Hostess";
                        document.StaffInfo.TPPPD4.value="4.00";
                        document.StaffInfo.Staff5.value="Dining Manager";
                        document.StaffInfo.TPPPD5.value="";
                        document.StaffInfo.Staff6.value="Room Service";
                        document.StaffInfo.TPPPD6.value="";

                        for (i=6; i <= 8; i++)
                                    {
                                    document.StaffInfo["Staff" + i].value="";
                                    document.StaffInfo["TPPPD" + i].value="";
                                    document.StaffInfo["RecTip" + i].value="";
                                    }
                        ClearActual();
            }

function toBills ( theNumber )
            {
                        if((theNumber) == 0)
                                    {
                                    return "";
                                    }
                        else
                                    {
                                    return theNumber;
                                    }
            }

function formatCurrency(num)        // got most of this from a javascript example site
            {
                        num = num.toString().replace(/\$|\,/g,'');
                        if(isNaN(num))
                        num = "0";
                        sign = (num == (num = Math.abs(num)));
                        num = Math.floor(num*100+0.50000000001);
                        cents = num%100;
                        num = Math.floor(num/100).toString();
                        if(cents<10)
                                    cents = "0" + cents;
                        for (var 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));
                        return (((sign)?'':'-') + num + '.' + cents);
            }

function GetCookie (name)           // got these cookie functions from a javascript example site
            {
                        var arg = name + "=";
                        var alen = arg.length;
                        var clen = document.cookie.length;
                        var i = 0;
                        while (i < clen)
                                    {
                                                var j = i + alen;
                                                if (document.cookie.substring(i, j) == arg)
                                                return getCookieVal (j);
                                                i = document.cookie.indexOf(" ", i) + 1;
                                                if (i == 0) break;
                                    }
                        return null;
            }

function SetCookie (name, value)
            {
                        var argv = SetCookie.arguments;
                        var argc = SetCookie.arguments.length;
                        var expires = (argc > 2) ? argv[2] : null;
                        var path = (argc > 3) ? argv[3] : null;
                        var domain = (argc > 4) ? argv[4] : null;
                        var secure = (argc > 5) ? argv[5] : false;
                        document.cookie = name + "=" + escape (value) +
                        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
                        ((path == null) ? "" : ("; path=" + path)) +
                        ((domain == null) ? "" : ("; domain=" + domain)) +
                        ((secure == true) ? "; secure" : "");
            }

function DeleteCookie (name)
            {
                        var exp = new Date();
                        exp.setTime (exp.getTime() - 1);
                        var cval = GetCookie (name);
                        document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
            }




var gDiscount;
var gAdults;
//var gLine;
var expDays = 366;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal(offset)
            {
                        var endstr = document.cookie.indexOf (";", offset);
                        if (endstr == -1)
                        endstr = document.cookie.length;
                        return unescape(document.cookie.substring(offset, endstr));
            }
