mydate.getWeek() question

This is not working, it doesn't even bring up the default banner.  I did have it working before when I sorted the new images based on month / day see: http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21192354.html 
but now I want to change it so it switches to images based on weeks. (No need for otherwise)

<SCRIPT>
var mydate=new Date()
var week=mydate.getWeek()+1
if (week<10)
week="0"+week
var newimg="http://home-url.com/Images/Calendar_Banners/banner"+week+".gif"
document.write('<center><img src="'+newimg+'" width="780" height="175" onError="this.src=\'http://home-url.com/Images/Banners/Default_banner.gif\';">')
</SCRIPT>
LVL 2
ALEx604Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GwynforWebCommented:
the date object does not have a getWeek() method.
0
archrajanCommented:
use this script to get the week
function getWeek(year,month,day){
    //lets calc weeknumber the cruel and hard way :D
    //Find JulianDay
    month += 1; //use 1-12
    var a = Math.floor((14-(month))/12);
    var y = year+4800-a;
    var m = (month)+(12*a)-3;
    var jd = day + Math.floor(((153*m)+2)/5) +
                 (365*y) + Math.floor(y/4) - Math.floor(y/100) +
                 Math.floor(y/400) - 32045;      // (gregorian calendar)
    //var jd = (day+1)+Math.Round(((153*m)+2)/5)+(365+y) +
    //                 Math.round(y/4)-32083;    // (julian calendar)
   
    //now calc weeknumber according to JD
    var d4 = (jd+31741-(jd%7))%146097%36524%1461;
    var L = Math.floor(d4/1460);
    var d1 = ((d4-L)%365)+L;
    NumberOfWeek = Math.floor(d1/7) + 1;
    return NumberOfWeek;        
}
0
archrajanCommented:
or you use this one
script type="text/javascript" language="JavaScript"><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function getWeek(year,month,day) {
    var when = new Date(year,month,day);
    var newYear = new Date(year,0,1);
    var offset = 7 + 1 - newYear.getDay();
    if (offset == 8) offset = 1;
    var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) - Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;
    var weeknum = Math.floor((daynum-offset+7)/7);
    if (weeknum == 0) {
        year--;
        var prevNewYear = new Date(year,0,1);
        var prevOffset = 7 + 1 - prevNewYear.getDay();
        if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else weeknum = 52;
    }
    return weeknum;
}

var now = new Date();
document.write('Week number = ' + getWeek(y2k(now.getYear()),now.getMonth(),now.getDate()));
//--></script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ALEx604Author Commented:
I will try this out and if it works I will accept it later sothat there ismore points to give.
0
ALEx604Author Commented:
Ok not working...
I'm not even getting the onError banner now.
Here is the entire html code for the page (unrelated stuff snipped with comment):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<!-- bunch of meta tag stuff here -->
<script type="text/javascript">
function getWeek(year,month,day){
    month += 1; //use 1-12
    var a = Math.floor((14-(month))/12);
    var y = year+4800-a;
    var m = (month)+(12*a)-3;
    var jd = day + Math.floor(((153*m)+2)/5) +
                 (365*y) + Math.floor(y/4) - Math.floor(y/100) +
                 Math.floor(y/400) - 32045;      // (gregorian calendar)
    var d4 = (jd+31741-(jd%7))%146097%36524%1461;
    var L = Math.floor(d4/1460);
    var d1 = ((d4-L)%365)+L;
    NumberOfWeek = Math.floor(d1/7) + 1;
    return NumberOfWeek;        
}
</SCRIPT>
</HEAD>
<BODY>
<!-- Bunch of image map junk -->
<!-- Bunch of ISM Update code junk here (not java all serverside) -->
<!-- MENU CODE / BANNER STARTS -->
<SCRIPT>
var week=mydate.getWeek()
if (week<10)
week="0"+week
var newimg="http://my-url.com/Images/Calendar_Banners/banner"+week+".gif"
document.write('<center><img src="'+newimg+'" width="780" height="175" onError=" this.src=\'http://my-url.com/Images/Banners/Default_banner.gif\';">')
</SCRIPT>
<!-- MENU CODE STUFF HERE -->
<!-- THE REST OF THE BODY TEXT STUFF FOR THE WEBPAGE HERE --></body</html>
0
ALEx604Author Commented:
Trying it the other way.. bbiab (Nov 23. 16:00)
0
ALEx604Author Commented:
The y2k version worked, (although i don't think it was because of y2k :P )

I will wait till I have 125 in points before I award this to archrajan

Thanks a heap!
0
archrajanCommented:
ok... thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.