// Name:	issue.js
// Purpose:	This script calculates and displays the number and date of the current issue.
// Syntax:	writeCurrentIssue(target) or writeCurrentIssue()
// 		target = target document; defaults to the current document if unspecified
// Author:	This script was written by Will Hesse and Tim Cole - Inspired Web Design.

// Constants

// The date and number of the first issue
// (although in practise it can be any issue number/date combination)
// Note that the issue date is put on the same day
// of the week as this date, so it should be a Friday.
var firstIssueNumber = 0;
var firstIssueDate = new Date(1993, 2, 01); // YYYY, M(M), D(D)
// NOTE that January is month zero - 
// so you have to subtract one from the month number.
// Uncomment the next line to check it's a Friday
// if ( firstIssueDate.getDay() != 5 ) { alert('Warning!\nThe first issue date is not a Friday:\n' + firstIssueDate); }

// The number of milliseconds per week
var msPerWeek = 1000 * 60 * 60 * 24 * 7;

// Use global variables to store these so they are only calculated once
// and can be accessed from elsewhere
var iIssueNumber; // as an integer
var dIssueDate = new Date(); // as a date
var cIssueDate = new Date(); // next issue as date
var sIssueNumber; // as a string
var sIssueDate; // as a string
var nIssueNumber; // next issue as a string
var nIssueDate; // next issue date as a string




function writeCurrentIssue(target) {
  if ( ! target ) { target = document; }
  target.writeln(sIssueNumber + ' - ' + sIssueDate);
}

function writeNextIssue(target) {
  if ( ! target ) { target = document; }
  nIssueNumber = (sIssueNumber*1)+1; // Convert current issue to integer and increment
  target.writeln(nIssueNumber + ' - ' + nIssueDate);
}

function calculateCurrentIssue(testDate) {
  // Get the current date
  var now = new Date();
  
  var D0, D1, DD, DM, DY, LM = 365.25/12
  
  D0 = firstIssueDate
  D1 = new Date()
  DD = Math.round((D1-D0)/864e5)
  DM = DD/LM|0 
 
 
sIssueNumber = DM;

var months = new Array(13);
			months[1] = "January";
			months[2] = "February";
			months[3] = "March";
			months[4] = "April";
			months[5] = "May";
			months[6] = "June";
			months[7] = "July";
			months[8] = "August";
			months[9] = "September";
			months[10] = "October";
			months[11] = "November";
			months[12] = "December";
	
			
			var Smonth = months[new Date().getMonth() + 1]
	
	if (new Date().getMonth()+1==12)
	{
		Nmonth = months[1];
		NYear = (new Date().getFullYear())+1;
	}
	else
	{
		Nmonth = months[new Date().getMonth() + 2];
		NYear = new Date().getFullYear();
	}



sIssueDate =  Smonth + " " + new Date().getFullYear();
  
  
nIssueNumber=sIssueNumber +1; // next issue as a string
nIssueDate= Nmonth + " " + NYear;
  

  
}

// Calculate the current issue once (when the script loads)
// so we don't have to recalculate it each time
// calculateCurrentIssue(new Date(2002, 0, 11)); // test mode
calculateCurrentIssue(); // normal mode
// If you want to override the default settings (without modifying the script)
// you can always call this function again (from the HTML) with a different parameter.

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function browserCheck(){
var browser = (((navigator.appName == "Netscape") &&
(parseInt(navigator.appVersion) <= 4 )) || 
((navigator.appName == "Microsoft Internet Explorer") && 
(parseInt(navigator.appVersion) >= 5 )))
if (browser) {
alert('Sorry. This site is designed for IE 5 or NS 6 and above.\nThe site will still function but the design will not display correctly\nWe suggest you upgrade your browser.')}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
