// Footer and other general page functions


function footer(CopyrightYear,PublicationDate)
{
// ¦:-)
if ( CopyrightYear.length>4 )
	{CopyrightYear = CopyrightYear.substring(CopyrightYear.length-4)}


// this section strips the protocol and host off the url
// you may need to add an if statement for your local configuration

DLH = document.location.href;
UrlPrefix='';

// main site
if(DLH.substring(0,22)=='http://www.abd.org.uk/')
	{SitePath=DLH.substring(22)}

// remote sites
if(DLH.substring(0,35)=='http://www.rivals.talktalk.net/abd/' || DLH.substring(0,34)=='http://www.rx7-uk.co.uk/~abdcambs/' || DLH.substring(0,40)=='http://homepage.virgin.net/stockton.abd/' || DLH.substring(0,34)=='http://www.rx7-uk.co.uk/~abdherts/' || DLH.substring(0,25)=='http://www.gal54.com/abd/')
	{UrlPrefix="http://www.abd.org.uk/"}


// local Virtual Host
IsLocal=DLH.search('.local/')
if(IsLocal)
	{
	SitePath=DLH.substring(IsLocal+7);
	}

// this will eventually obliviate all this code anyway :-)

// cmw local pc
if(DLH.substring(0,32).toLowerCase()=='file://localhost/d:/abd/nildram/')
	{
	SitePath=DLH.substring(32);
	IsLocal==true;
	}

// cmw local mac
if(DLH.substring(0,43).toLowerCase()=='file://localhost/users/chrisward/sites/abd/')
	{
	SitePath=DLH.substring(43);
	IsLocal==true;
	}

// set site UrlPrefix if not already done
if(UrlPrefix== '')
	{
   while(SitePath.indexOf('/')!=-1)
   	{
   	SitePath = SitePath.substring(SitePath.indexOf('/')+1)
   	UrlPrefix = UrlPrefix + '../'
   	}
	}


if (PageWidth()>840)
	{
	// show left side banner
	document.writeln('<TABLE CLASS=FOOTER BORDER=0 CELLSPACING=0 CELLPADDING=0><TBODY><TR><TD CLASS=DoNotPrint WIDTH=144>&nbsp;</TD><TD STYLE="text-align:center;">');
	}

lmtime=new Date(document.lastModified);
lmyear=lmtime.getYear();

if (lmyear<10) {lmyear="200" + lmyear}
if (lmyear<100) {lmyear="20" + lmyear}
if (lmyear>=100 && lmyear<=999) {lmyear=1900+lmyear}

lmmonth=lmtime.getMonth()+1;
if (lmmonth<10) {lmmonth="0"+lmmonth}

lmdate=lmtime.getDate();
if (lmdate<10) {lmdate="0" + lmdate}

document.writeln('<SMALL CLASS=FOOTER>');

document.writeln('Copyright &copy; Pro-Motor Ltd ' + CopyrightYear);

if (PublicationDate!=null)
	{document.writeln(' &bull; First published ' + PublicationDate);}

// trap remote servers that don't return a mod date
if(lmyear!=2070)
	{document.writeln(' &bull; Last updated ' + lmyear + "-" + lmmonth + "-" + lmdate);}

document.writeln('<BR>');

// Only display URL if on main site, or local drive (i.e. not on a remote local site)
if (location.href.substring(0,21)=="http://www.abd.org.uk" || IsLocal || location.href.substring(0,7)=="file://")
   {
   document.writeln('URL:&mdash; ');
	//document.writeln('<BR>');
   document.writeln('<A HREF="' + location.href + '" CLASS=FOOTER>');
   document.writeln(location.href);
   document.writeln('</A><BR>');
   }

Moment = new Date()
document.writeln('<SPAN CLASS=PrintOnly>Printed ' + Moment.toLocaleString() + ' UTC<BR></SPAN>');

// share buttons

document.writeln('<SPAN CLASS=DoNotPrint>&nbsp;<BR>Share:&mdash; &nbsp;');

document.writeln('<A HREF="http://del.icio.us/post?url=' + location.href + '" TITLE="Share on Delicious" TARGET="_blank"><IMG SRC="' + UrlPrefix + 'images/icons/delicious_16x16.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALIGN=MIDDLE></A> &nbsp;');

document.writeln('<A HREF="http://digg.com/submit?url=' + location.href + '" TITLE="Share on Digg" TARGET="_blank"><IMG SRC="' + UrlPrefix + 'images/icons/digg_16x16.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALIGN=MIDDLE></A> &nbsp;');

document.writeln('<A HREF="http://www.facebook.com/sharer.php?u=' + location.href + '" TITLE="Share on Facebook" TARGET="_blank"><IMG SRC="' + UrlPrefix + 'images/icons/facebook_16x16.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALIGN=MIDDLE></A> &nbsp;');

document.writeln('<A HREF="http://reddit.com/submit?url=' + location.href + '" TITLE="Share on Reddit" TARGET="_blank"><IMG SRC="' + UrlPrefix + 'images/icons/reddit_16x16.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALIGN=MIDDLE></A> &nbsp;');

document.writeln('<A HREF="http://www.stumbleupon.com/submit?url=' + location.href + '" TITLE="Share on Stumbleupon" TARGET="_blank"><IMG SRC="' + UrlPrefix + 'images/icons/stumbleupon_16x16.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALIGN=MIDDLE></A> &nbsp; ');

document.writeln('<A HREF="http://twitter.com/home?status=' + escape(location.href) + '" TITLE="Tweet" TARGET="_blank"><IMG SRC="' + UrlPrefix + 'images/icons/twitter_16x16.png" WIDTH=16 HEIGHT=16 BORDER=0 ALIGN=MIDDLE></A>');

document.writeln('</SPAN>');

if (PageWidth()>840)
	{
	// show right side banner
	BannerPoint=new Date()
	DeciSeconds=BannerPoint/100
	choices=2
	BannerNumber=Math.floor(choices*(DeciSeconds/choices-Math.floor(DeciSeconds/choices)));
   // enable to test latest
   //BannerNumber=choices-1
   switch(BannerNumber)
      {
      case 0:
   		// Facebook
   		document.writeln('</TD><TD CLASS=DoNotPrint WIDTH=144><A HREF="http://www.facebook.com/associationofbritishdrivers" TARGET="_blank" TITLE="Support the ABD on Facebook" STYLE="float:right;z-index:-1;"><IMG SRC="' + UrlPrefix + 'images/find_us_on_facebook_badge.gif" WIDTH=144 HEIGHT=44 BORDER=0></A></TD></TR></TBODY></TABLE>');
   		break;
      case 1:
   		// Twitter
   		document.writeln('</TD><TD CLASS=DoNotPrint WIDTH=144><A HREF="http://twitter.com/TheABD" TARGET="_blank" TITLE="Follow the ABD on Twitter" STYLE="float:right;z-index:-1;"><IMG SRC="' + UrlPrefix + 'graphics/logos/twitter.png" WIDTH=144 HEIGHT=44 BORDER=0></A></TD></TR></TBODY></TABLE>');
   		break;
   	}
	}

}

// ============================================================================================

function setStatus(StatusString)
 {
 window.defaultStatus = "";
 window.status = StatusString;
 return true;
 }

// ============================================================================================

function PageWidth()
{
if (window.innerWidth != null)
	{w = window.innerWidth}
else
	{
	if (document.documentElement && document.documentElement.clientWidth)
		{w = document.documentElement.clientWidth}
	else
		{
		if (document.body != null)
			{w = document.body.clientWidth}
		else
			{w = null}
		}
	}
return w;
}

// ============================================================================================

function SetEmail(EmailPrefix)
{
dlh = document.location.href

// strip any # off
if(dlh.indexOf('#')!=-1)
	{dlh=dlh.substring(0,dlh.indexOf('#'))}

if(dlh.substring(dlh.length-3)=='htm')
	{
	Page = document.location.href.substring(document.location.href.lastIndexOf('/')+1,document.location.href.indexOf('.htm'))
	}

// South Yorks remote pages http://www.26seven.co.uk/abd/barnsley/
if(dlh.substring(0,24)=='http://www.26seven.co.uk')
	{Page = dlh.substring(29,document.location.href.lastIndexOf('/'))}

Page = Page.substring(0,1).toUpperCase() + Page.substring(1) + ' '


if(Page=='Contacts ')
	{Page=''}

switch(EmailPrefix)
	{
	case "#LAB":
		document.getElementById('EMAIL').innerHTML='<A HREF="mailto:office@legalactionbureau.co.uk?Subject=ABD Legal Helpline 0906-598-2570">office@legalactionbureau.co.uk</A>'
		break;
	case "#LA":
		document.getElementById('EMAIL').innerHTML='<A HREF="mailto:legaladvice@abd.org.uk?Subject=ABD%20Free%20Legal%20Advice&Body=%0AName:%0A%0APhone:%0A%0AEmail:%0A%0AOffence%20alleged:%0A%0ARoad%20Traffic%20Offence%20question:">legaladvice@abd.org.uk</A>'
		break;
	default:
		document.getElementById('EMAIL').innerHTML='<A HREF="mailto:' + EmailPrefix + '@abd.org.uk?Subject=' + Page + 'enquiry via ABD website">' + EmailPrefix + '@abd.org.uk</A>'
		break;
	}

if(Page=='')
	// reposition page to assist mobile device users
	{window.location.href='#emailbox';}
}

// ============================================================================================

function Hex16(Decimal) {
Sixteens=Math.floor(Decimal/16)
if (Sixteens==10) {Hex1="A"} else {
 if (Sixteens==11) {Hex1="B"} else {
  if (Sixteens==12) {Hex1="C"} else {
   if (Sixteens==13) {Hex1="D"} else {
    if (Sixteens==14) {Hex1="E"} else {
     if (Sixteens==15) {Hex1="F"} else {
      Hex1=Sixteens}}}}}}
return Hex1}

// ============================================================================================

function HexUnits(Decimal) {
Units=Decimal-(16*Sixteens)
if (Units==10) {Hex2="A"} else {
 if (Units==11) {Hex2="B"} else {
  if (Units==12) {Hex2="C"} else {
   if (Units==13) {Hex2="D"} else {
    if (Units==14) {Hex2="E"} else {
     if (Units==15) {Hex2="F"} else {
      Hex2=Units}}}}}}
return Hex2}

// ============================================================================================

function NewFader(YYYY_MM_DD)
// creates NEW flash that fades as it ages
{
NewBackRed=255;NewBackGreen=255;NewBackBlue=0;
OldBackRed=227;OldBackGreen=227;OldBackBlue=224;
NewForeRed=0;NewForeGreen=0;NewForeBlue=0;
OldForeRed=221;OldForeGreen=221;OldForeBlue=223;
DaysToFade=100;
DateNew = new Date(YYYY_MM_DD.substring(0,4),YYYY_MM_DD.substring(5,7)-1,YYYY_MM_DD.substring(8))
DateNow = new Date()
RealAge = Math.floor((DateNow-DateNew)/86400000)
switch(RealAge)
	{
	case 0: SayAge='Today';break;
	case 1: SayAge='Yesterday';break;
	default: SayAge = RealAge + ' days ago';break;
	}
FadeAge = Math.min(RealAge,DaysToFade)
BackRed = Math.floor(NewBackRed -  FadeAge/DaysToFade *(NewBackRed-OldBackRed))
BackGreen = Math.floor(NewBackGreen -  FadeAge/DaysToFade *(NewBackGreen-OldBackGreen))
BackBlue = Math.floor(NewBackBlue -  FadeAge/DaysToFade *(NewBackBlue-OldBackBlue))
ForeRed = Math.floor(NewForeRed +  FadeAge/DaysToFade *(OldForeRed-NewForeRed))
ForeGreen = Math.floor(NewForeGreen +  FadeAge/DaysToFade *(OldForeGreen-NewForeGreen))
ForeBlue = Math.floor(NewForeBlue +  FadeAge/DaysToFade *(OldForeBlue-NewForeBlue))
Back = '#'+Hex16(BackRed)+HexUnits(BackRed)+Hex16(BackGreen)+HexUnits(BackGreen)+Hex16(BackBlue)+HexUnits(BackBlue)
Fore = '#'+Hex16(ForeRed)+HexUnits(ForeRed)+Hex16(ForeGreen)+HexUnits(ForeGreen)+Hex16(ForeBlue)+HexUnits(ForeBlue)
document.writeln('&nbsp;<SPAN CLASS=NEW STYLE="color:' + Fore + ';background-color:' + Back + '" TITLE="New ' + YYYY_MM_DD + ' (' + SayAge + ')">&nbsp;NEW&nbsp;</SPAN>');
}
