// button rollovers

if (document.images) {
	homeOff = new Image;
	homeOn = new Image;
	deliveryOff = new Image;
	deliveryOn = new Image;
	infoOff = new Image;
	infoOn = new Image;
	aboutOff = new Image;
	aboutOn = new Image;
	customersOff = new Image;
	customersOn = new Image;

	homeOff.src = "/images/apc-logo-off.png";
	homeOn.src = "/images/apc-logo-on.png";
	deliveryOff.src = "/images/delivery-off.png";
	deliveryOn.src = "/images/delivery-on.png";
	infoOff.src = "/images/info-off.png";
	infoOn.src = "/images/info-on.png";
	aboutOff.src = "/images/about-off.png";
	aboutOn.src = "/images/about-on.png";
	customersOff.src = "/images/customers-off.png";
	customersOn.src = "/images/customers-on.png";
	
	trackOff = new Image;
	trackOn = new Image;
	downloadsOff = new Image;
	downloadsOn = new Image;
	manageOff = new Image;
	manageOn = new Image;
	logoutOff = new Image;
	logoutOn = new Image;
	
	trackOff.src = "/images/track-off.png";
	trackOn.src = "/images/track-on.png";
	downloadsOff.src = "/images/downloads-off.png";
	downloadsOn.src = "/images/downloads-on.png";
	manageOff.src = "/images/manage-off.png";
	manageOn.src = "/images/manage-on.png";
	logoutOff.src = "/images/logout-off.png";
	logoutOn.src = "/images/logout-on.png";
}

function chgImg(imgField,newImg) {
	if (document.images) {
		document[imgField].src= eval(newImg + ".src")
	}
}


// home page random ads

function rand_number(n){
	var x;
	x=Math.round(Math.random()*100);
	x%=n;
	return x;
}
function tips(){
	var tip = new Array();
	tip[0]='<div id="random"><img src="/images/random1.jpg" width="212" height="142" alt=""><p>&ldquo;I had to find a courier at 6pm for an urgent next day delivery&hellip;APC immediately sprang into action, and we&rsquo;ve stayed ever since.&rdquo;<strong>Warwickshire County Cricket Club</strong></p></div>';
	tip[1]='<div id="random"><img src="/images/random2.jpg" width="212" height="142" alt=""><p>&ldquo;APC Overnight has been with us since the start. Speedy delivery works extremely well for us and ensures freshness.&rdquo;<strong>Dylan Bean,<br>Kernowsashimi Fish</strong></p></div>';
	tip[2]='<div id="random"><img src="/images/random3.jpg" width="212" height="142" alt=""><p>&ldquo;We tell our customers that they will get their orders tomorrow and APC Overnight makes sure it happens.&rdquo;<strong>Gari Phillips,<br>Stormguard</strong></p></div>';
	tip[3]='<div id="random"><img src="/images/random4.jpg" width="212" height="142" alt=""><p>&ldquo;We&rsquo;ve never needed the tracking service because APC Overnight has provided a 100% accurate next day delivery service&rdquo;<strong>Gareth Sharples,<br>PWS Direct Ltd</strong></p></div>';
	tip[4]='<div id="random"><img src="/images/random5.jpg" width="212" height="142" alt=""><p>&ldquo;We know precisely who signed for the items and when, and the secure service gives added peace of mind for us and our customers.&rdquo;<strong>Kevin Mileson,<br>Gas &amp; Environmental</strong></p></div>';
	tip[5]='<div id="random"><img src="/images/random6.jpg" width="212" height="142" alt=""><p>&ldquo;Last year we shipped 3.5 million books&hellip;working with APC Overnight has transformed the way we do business.&rdquo;<strong>Ray Dyer,<br>Peters Bookselling Services</strong></p></div>';
	tip[6]='<div id="random"><img src="/images/random7.jpg" width="212" height="142" alt=""><p>&ldquo;We needed a courier that could work with us to ensure that we fulfil our daily orders, and APC Overnight stepped up to the mark.&rdquo;<strong>Simon Waters,<br>Roadnet</strong></p></div>';
	tip[7]='<div id="random"><img src="/images/random8.jpg" width="212" height="142" alt=""><p>&ldquo;Our customers are very happy with the delivery service and it has been instrumental to the growth of our internet sales.&rdquo;<strong>John Mettrick,<br>J W Mettrick &amp; Son</strong></p></div>';
	var n=rand_number(tip.length);
	document.write(tip[n]);
}

// popups

function openWin(URL) {
	aWindow = window.open(URL,'thewindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=375,height=450');
	if(window.focus) 	{
 		setTimeout('aWindow.focus();',250);
	}
}

function openWide(URL) {
	aWindow = window.open(URL,'wideWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=575,height=450');
	if(window.focus) 	{
 		setTimeout('aWindow.focus();',250);
	}
}

//find DOM

var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById) {
	isID = 1; isDHTML = 1;
} else {
	if (document.all) {
		isAll = 1; isDHTML = 1;
	} else {
	browserVersion = parseInt(navigator.appVersion);
	if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
		isLayers = 1; isDHTML = 1;
		}
	}
}

function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) {
			return (document.getElementById(objectID).style);
		} else { 
			if (isAll) {
				return (document.all[objectID].style);
			} else {
				if (isLayers) {
					return (document.layers[objectID]);
				}
			}
		}
	}
	else {
		if (isID) {
			return (document.getElementById(objectID));
		} else {
			if (isAll) {
				return (document.all[objectID]);
			} else {
				if (isLayers) { return (document.layers[objectID]); }
			}
		}
	}
}

//faqs

// start by getting all the questions and answers
// these will be put into arrays
var questions = document.getElementsByTagName('dt');
var answers = document.getElementsByTagName('dd');
// function for the link that turns them all off
function toggleAllOff(){
	for (var i = 0; i < answers.length; i++) {  // turns off all the dd's
		answers[i].className = 'hide';
	}
}
// function for the link that turns them all on
function toggleAllOn(){
	for (var i = 0; i < answers.length; i++) {  // turn on all the dd's
		answers[i].className = 'show';
	}
}
function toggleNext(element) {
	var next = element.nextSibling;
	while(next.nodeType != 1) next=next.nextSibling; // if it gets to a non-element node, go to the next one
	next.className=((next.className=="hide") ? "show" : "hide");
}
//makes the definition lists click-able
function displayToggle(){
	toggleAllOff(); // calls the toggle all off function to turn all the answers off when the page is loaded	 
	for (i=0; i<questions.length; i++) { // loops through the questions 
		questions[i].onclick=function() { // shows the answers onclick
			toggleNext(this);
		}
	}
}

// date

var montharray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var now = new Date();
var myyear = now.getYear();
var mymonth = now.getMonth();
var myday = now.getDay();
var mydate = now.getDate();

if (myyear < 1000) {
	myyear += 1900;
}
// home page
var timetext = mydate;
timetext += " " + montharray[mymonth];
timetext += " " + myyear;
// news page
var newsdate = montharray[mymonth];
newsdate += " " + myyear;

