Need some help with JS. Wrote this script a few years ago. Worked fine in IE.
Now, it endlessly loops in Fx, and just doesn't work in IE.
Can someone look through it, and let me know what methods are bad, and what they should be replaced with. I can explain it a little more in detail to anyone who wants the challenge. Frih$500 to the fixer.
.
Now, it endlessly loops in Fx, and just doesn't work in IE.
Can someone look through it, and let me know what methods are bad, and what they should be replaced with. I can explain it a little more in detail to anyone who wants the challenge. Frih$500 to the fixer.
.
| Code: |
|
<html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin /* -- This script will calculate the surfing beach for any date from ------- */ /* -- May 29, 2004 until Sept 15, 2399. Scarry, huh? ---------------------- */ /* -- Script by: Ben Davis (18 Mar 2004)------------------------------------- */ function openWindow(url,name) { popupWin = window.open(url,name, 'status=0,scrollbars=1, width=300,height=600,left=25,top=25') } /* These functions move the date up or down, according to the button pushed-- */ function plusday(form) { var CCC = new Date(formx.ans.value); formx.ans.value = new Date(CCC.setDate(CCC.getDate() + 1)); formx.LXXX.value = 'up' calcSB(this.form) } function plusmonth(form) { var CCC = new Date(form.ans.value); CCC.setMonth(CCC.getMonth() + 1); formx.ans.value = new Date(CCC); formx.LXXX.value = 'up' calcSB(this.form) } function lessday(form){ var CCC = new Date(formx.ans.value); formx.ans.value = new Date(CCC.setDate(CCC.getDate() - 1)); formx.LXXX.value = 'down' calcSB(this.form) } function lessmonth(form){ var CCC = new Date(formx.ans.value); formx.ans.value = new Date(CCC.setMonth(CCC.getMonth() - 1)); formx.LXXX.value = 'down' calcSB(this.form) } function maketoday(form){ var now = new Date(); formx.ans.value = now; formx.LXXX.value = 'now' calcSB(this.form) } /*------------------------- end of button functions -----------------------*/ function calcSB(form) { /* changing the below values can have very dire consequences!!!!!!*/ // The value MemSat is a reference date. This is the lowest possible date. var MemSat = new Date("29 May 2004"); // On the above date, where was the surfing beach? This is the starting number. var startSB = 43; /*------------------------- Now, make sure the date is inside our season ----*/ /*----- Our season is memorial weekend saturday through september 15th. ----*/ var CCC = new Date(formx.ans.value); // CCC stores the date we are checking on. /*--- Step one, the date can be no less than 29 May 2004 */ if(CCC.getTime() < MemSat.getTime()) { CCC = MemSat; formx.ans.value = new Date(MemSat); } /*--- Step two, if the date is during the off season (Sept 15 through Memorial Saturday), then adjust it ---*/ // First, lets define the last day in the season for the year we are checking on. var topday = new Date("15 Sep " + CCC.getYear()); // Set the date to september 15 of the calculating year. // Next, lets find memorial day saturday, for the year we are checking // Memorial day is defined as last monday in may. So find memorial day first var lowday = new Date("31 May " + CCC.getYear()); // Construct May 31st of the calculating year. while (lowday.getDay() != 1) // Then subtract days until we get to monday { lowday.setDate(lowday.getDate() - 1); // .getDay() returns the day of week as a number }; lowday.setDate(lowday.getDate() - 2); // Then subtract two days, to get to saturday. if ((CCC.getTime() > topday.getTime()) || (CCC.getTime() < lowday.getTime())) // || = `OR' { // This routine is true if the date is over winter var LA=formx.LXXX.value; // The action taken will depend on what the user was trying to do. if (LA=='down') // If they were decreasing the date, set it to sept 15 of previous year. { var lessone = (CCC.getYear() - 1); // not sure why I need to do this... but it works. construct = new Date("15 Sep " + lessone); CCC = construct; formx.ans.value = new Date(CCC); }; if (LA=='up') { // If they were increasing the date, set it to next memorial day saturday. var NextMS = new Date("31 May" + (CCC.getYear() + 1)); // Determine next memorial saturday. Set to the 31st of may, the next year. while (NextMS.getDay() != 1) // Then subtract days until we get to monday != is not equal to { NextMS.setDate(NextMS.getDate() - 1); // .getDay() returns the day of week as a number }; NextMS.setDate(NextMS.getDate() - 2); // Then subtract two days, to get to saturday. CCC = NextMS; formx.ans.value = new Date(NextMS); }; if (LA=='now') { /* If the user pushed today, and that gave it an offseason date */ /* if the month is may or less, set it to memorial day saturday */ /* if the month is june or greater, set to memorial day next year */ if(CCC.getMonth() <= 4) { var findmem = CCC.getYear(); } else { var findmem = (CCC.getYear() + 1); }; var NextMS = new Date("31 May " + findmem); // Determine next memorial saturday. Set to the 31st of may, the next year. while (NextMS.getDay() != 1) // Then subtract days until we get to monday != is not equal to { NextMS.setDate(NextMS.getDate() - 1); // .getDay() returns the day of week as a number }; NextMS.setDate(NextMS.getDate() - 2); // Then subtract two days, to get to saturday. CCC = new Date(NextMS); formx.ans.value = new Date(NextMS); }; }; /* -- Next, if the location is more than one year ahead of current date, show disclaimer ----- */ var ritenow = new Date() var warningshown = formx.warningshown.value if((CCC.getYear() > ritenow.getYear()) & (warningshown != 1) & (LA=='up')) { alert('Warning: Surfing beach locations for ' + (ritenow.getYear() + 1) + ' and beyond are current predictions only. \n These predictions are subject to change by the Mayor and City Council.'); formx.warningshown.value = 1; }; /* ------------------------- Now that the date is valid, we will count the days -------------------- */ /*-------------------------- from the starting location, and place the surfing beach accordingly ---- */ calcing = new Date(formx.ans.value); // Essentially the same as CCC, but plucked fresh. // If the value was increased, lowday is for last year. // so, make sure it's correct first. var lowday = new Date("31 May " + calcing.getYear()); // Construct May 31st of the calculating year. while (lowday.getDay() != 1) // Then subtract days until we get to monday { lowday.setDate(lowday.getDate() - 1); // .getDay() returns the day of week as a number }; lowday.setDate(lowday.getDate() - 2); // Then subtract two days, to get to saturday. var diff = calcing.getTime() - lowday.getTime(); // First, how many days from memorial day sat in this year. var days = Math.floor(diff / (1000 * 60 * 60 * 24)); // .getTime returns the time in MILLISECONDS since 1 Jan 1970!!! // For each year from the reference date, calculate the number of // days from that season if (calcing.getYear() != MemSat.getYear()) { for(x=0 ; (MemSat.getYear() != (calcing.getYear() - x)); x=x+1) { thisLD = new Date("15 Sep " + (calcing.getYear() - x)); // make last day of season thisFD = new Date("31 May " + (calcing.getYear() - x)); // make 1st day of season /* do { thisFD.setDate(thisFD.getDate() - 1); } ; while (thisFD.getDay() != 1) // find monday thisFD.setDate(thisFD.getDate() - 2); // -2 days to saturday */ while (thisFD.getDay() != 1) { thisFD.setDate(thisFD.getDate() - 1); }; // find monday thisFD.setDate(thisFD.getDate() - 2); // -2 days to saturday var thisdiff = thisLD.getTime() - thisFD.getTime(); // find time diference var thisdays = Math.floor(thisdiff / (1000 * 60 * 60 * 24)); // convert time to days if(((calcing.getYear() - x)%4 == 0) & ((calcing.getYear()-x)%100 != 0)) { // If this is a leap year, subtract one day(?) var thisdays = thisdays - 1; // Not sure why, but it works! }; // Every 4th year is a leap year, except for // years divisible by 100 (& not divisible by 400) var days = days + thisdays; // add this years days to the total , and loop }; }; var todays = days + startSB; // Add in where the surfing beach was on the reference date while (todays > 69) // 'Todays' is the total number of days from the { // reference date (plus the starting reference #) todays=todays-70; // Since it rotates on a 70 day cycle, subtract 70 } // until the number is less than 70 (0-69) /* String table of all the possible surfing beaches */ var SSBS = new Array("63rd Street" , "61st Street" , "59th Street" , "57th Street" , "55th Street" , "53rd Street" , "51st Street" , "49th Street" , "47th Street" , "45th Street" , "43rd Street" , "41st Street" , "39th Street" , "37th Street" , "35th Street" , "33rd Street" , "31st Street" , "29th Street" , "27th Street" , "25th Street" , "23rd Street" , "21st Street" , "19th Street" , "17th Street" , "15th Street" , "13th Street" , "11th Street" , "9th Street" , "7th Street" , "5th Street" , "3rd Street" , "1st Street" , "Caroline Street" , "Dorchester Street" , "South Division St" , "64th Street" , "62nd Street" , "60th Street" , "58th Street" , "56th Street" , "54th Street" , "52nd Street" , "50th Street" , "48th Street" , "46th Street" , "44th Street" , "42nd Street" , "40th Street" , "38th Street" , "36th Street" , "34th Street" , "32nd Street" , "30th Street" , "28th Street" , "26th Street" , "24th Street" , "22nd Street" , "20th Street" , "18th Street" , "16th Street" , "14th Street" , "12th Street" , "10th Street" , "8th Street" , "6th Street" , "4th Street" , "2nd Street" , "North Division St" , "Talbot Street" , "Worcester Street"); // The longest line ever! var NSBS = new Array("146th Street", "144th Street" , "142nd Street", "140th Street", "138th Street", "136th Street", "134th Street", "132nd Street", "130th Street", "128th Street", "126th Street", "124th Street", "122nd Street", "120th Street", "Carousel" , "Seawatch" , "Rainbow " , "Golden Sands", "Sheraton" , "Plaza" , "Flying Cloud", "93rd Street" , "91st Street" , "89th Street" , "87th Street" , "85th Street" , "83rd Street" , "81st Street", "79th Street", "77th Street", "75th Street", "73rd Street", "71st Street" , "69th Street" , "67th Street" , "145th Street", "143rd Street", "141st Street", "139th Street", "137th Street", "135th Street", "133rd Street", "131st Street", "129th Street", "127th Street", "125th Street", "123rd Street", "121st Street", "119th Street", "Fountain Head", "High Point N", "Capri" , "Quay" , "English Towers", "Pyramid" , "94th Street" , "92nd Street" , "90th Street" , "88th Street" , "86th Street" , "84th Street" , "82nd Street" , "80th Street" , "78th Street" , "76th Street", "74th Street", "72nd Street", "70th Street" , "68th Street" , "66th Street" ); formx.south.value = SSBS[todays]; // lastly, display the location formx.north.value = NSBS[todays]; // All you bases are belonging to us! formx.ref.value = todays; // a hidden value, useful for troubleshooting /*--- Then, let us put a prety date up, ------------------------ */ var this_month = new Array(12); this_month[4] = "May"; this_month[5] = "June"; this_month[6] = "July"; this_month[7] = "August"; this_month[8] = "September"; this_month[9] = "October"; var this_day = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); var day = calcing.getDate(); var month = calcing.getMonth(); var year = calcing.getYear(); var dow = calcing.getDay() formx.nicedate.value = this_day[dow]+", "+ this_month[month] + " "+ day + ", " +year; /*---- end of function ! -------*/ } // End --> </SCRIPT> <BODY> <CENTER> <FORM name="formx"> <input type='hidden' value='' name="ans" size="20"> <input type="hidden" value="" name="LXXX"> <input type='hidden' value='' name="warningshown"> <input type="hidden" name="ref" size="20"> <table cellSpacing="0" cellPadding="0" width="239" border="1" height="102"> <tr> <td align="middle" colspan="2" bgcolor="#8B0000" width="235" height="9"><b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" color="#FFFFFF" size="2"> Surfing</font><font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="1" color="#FFFFFF"> </font> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" color="#FFFFFF" size="2"> Beaches</font></b></td> </tr> <tr> <td align="middle" bgColor="#FFFFFF" width="61" height="15"><b><font size="1"> <font face="Arial">For</font>: </font></b></td> <td align="middle" width="172" height="15"><font size="1"> <input name="nicedate" size="30" style="font-size: 8pt; word-spacing: 0; border-style: solid; border-width: 0; margin: 0; padding: 0"></font></td> </tr> <tr> <td align="middle" bgColor="#8b0000" width="61" height="15"><b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="1" color="#FFFFFF"> North</font></b></td> <td align="middle" width="172" height="15"> <input name="north" size="20" style="font-size: 8pt; border-style: solid; border-width: 0" id="fp1"></td> </tr> <tr> <td align="middle" width="118" height="20" bgcolor="#8B0000"><b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" size="1" color="#FFFFFF"> South</font></b></td> <td align="middle"> <input name="south" size="20" style="font-size: 8pt; border-style: solid; border-width: 0" id="fp2"></td> </tr> <tr> <td align="middle" colspan="2" width="235" height="33"> <p style="margin-top: 0; margin-bottom: 0"><input type="button" value=" < " onClick="lessday(this.form)" style="font-size: 8pt"><input type="button" value="Today" onClick="maketoday(this.form)" style="font-size: 8pt"><input type="button" value=" > " onClick="plusday(this.form)" style="font-size: 8pt"><input type="button" value=">> " onClick="plusmonth(this.form)" style="font-size: 8pt"></p> <p style="margin-top: 0; margin-bottom: 0"><font size="1"> <a href="javascript:alert('Warning: Surfing beach locations for next season and beyond are current predictions only. \n These predictions are subject to change by the Mayor and City Council.');">Disclaimer</a> <a href="javascript:openWindow('condos_map.htm','Condo_Row_Surfing_Beach_Location');"> Condo Locations</a></font></td> </tr> </table> <p style="margin-top: 0; margin-bottom: 0"> </p> <p style="margin-top: 0; margin-bottom: 0"> </p> </FORM> </CENTER> <script language = "javascript"> maketoday() </script> </body> </html> |
