// 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 = 1007;
var firstIssueDate = new Date(2002, 0, 10); // 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 FormatDate(TempDate){
var FormatedDate, TempSplit

var TempMonth	= new Array("January","February","March","April","May","June","July","August","September","October","November","December")	

var TempSplit=TempDate.split("/");

FormatedDate = TempSplit[0]+" "+TempMonth[TempSplit[1]-1]+" "+TempSplit[2];

return(FormatedDate)
}

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

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

function calculateCurrentIssue(testDate) {
  // Get the current date
  var now = new Date();
  if ( testDate ) {
    now = testDate;
    document.writeln('Testing date ' + now + '... ');
  }

  // Calculate the issue number
  iIssueNumber = firstIssueNumber + ( now - firstIssueDate ) / msPerWeek; // Dates work in milliseconds
  iIssueNumber = parseInt(iIssueNumber); // Chop off any remainder (i.e. round down)

  // Calculate the issue date
  dIssueDate = now;
  while ( dIssueDate.getDay() != firstIssueDate.getDay() ) {
    dIssueDate.setDate( dIssueDate.getDate() -1 );}

  // Build the strings to display from the numerical variables
  sIssueNumber = ''+iIssueNumber; // Convert integer to string (for what it's worth)

  sIssueDate = '';
  if ( dIssueDate.getDate() < 10 ) { sIssueDate += '0'; }
  sIssueDate += dIssueDate.getDate();
  sIssueDate += '/';
  if ( dIssueDate.getMonth() < 9 ) { sIssueDate += '0'; }
  sIssueDate += (dIssueDate.getMonth() + 1); // +1 is because January is zero
  sIssueDate += '/';
  sIssueDate += ('' + dIssueDate.getFullYear() ); // last two digits

  cIssueDate = dIssueDate;
  cIssueDate.setDate( dIssueDate.getDate() +7 );
  
  nIssueDate = '';
  if ( cIssueDate.getDate() < 10 ) { nIssueDate += '0'; }
  nIssueDate += cIssueDate.getDate();
  nIssueDate += '/';
  if ( cIssueDate.getMonth() < 9 ) { nIssueDate += '0'; }
  nIssueDate += (cIssueDate.getMonth() + 1); // +1 is because January is zero
  nIssueDate += '/';
  nIssueDate += ('' + cIssueDate.getFullYear() ); // last two digits
}

// 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]+"'");
}
function SeachbyTown(ID){
window.location="agents.php?ListType=Town&SearchID="+ID+"";
}

function validatesearch(){
if((document.searchform.searchtext.value=="")||(document.searchform.searchtext.value==" ")||(document.searchform.searchtext.value=="Enter search text..."))
{
alert('Please enter your Search text.');
document.searchform.searchtext.focus();
document.searchform.searchtext.select();
return;
}

if(document.searchform.searchtext.value.length<=3)
{
alert('Please enter at least 3 characters in your your Search text.');
document.searchform.searchtext.focus();
document.searchform.searchtext.select();
return;
}

document.searchform.SearchButton.disabled = true;
window.location="agents.php?ListType=Search&SearchID=%"+document.searchform.searchtext.value+"%";
}