/*************************************************************************/
/*External JavaScript functions to accompany the Berkshire ACF website*/
/*The following newWindow() functions have been adapted from JavaScript - A Beginners Guide by John Pollock*/
/*and JavaScript for the World Wide Web by Negrino and Smith*/
/*************************************************************************/
function newWindow(imagejpg)   //New window for landscape view images
{
imageWindow = window.open(imagejpg, "imgWin", "width=648,height=486,screenX=70,left=70,screenY=70,top=70")
imageWindow.focus()
}

function newWindow2(imagejpg)  //New window for portrait view images
{
imageWindow = window.open(imagejpg, "imgWin", "width=486,height=648,screenX=80,left=80,screenY=80,top=80")
imageWindow.focus()
}

function newWindow2a(imagejpg)  //New window for smaller portrait view images
{
imageWindow = window.open(imagejpg, "imgWin", "width=410,height=530,screenX=80,left=80,screenY=80,top=80")
}

function newWindow3(texthtml)  //New window for Detachment info
{
imageWindow = window.open(texthtml, "imgWin", "width=800,height=500,screenX=0,left=0,screenY=0,top=0")
imageWindow.focus()
}

function newWindow4(imagejpg)   //New window for Privacy Statement
{
imageWindow = window.open(imagejpg, "imgWin", "width=650,height=750,screenX=0,left=0,screenY=0,top=0")
imageWindow.focus()
}

function newWindow5(texthtml)	//New window for A Company Map
{
imageWindow = window.open(texthtml, "imgWin", "width=845,height=830,screenX=0,left=0,screenY=0,top=0")
imageWindow.focus()
}

function newWindow6(texthtml)	//New window for B Company Map
{
imageWindow = window.open(texthtml, "imgWin", "width=880,height=550,screenX=0,left=0,screenY=0,top=0")
imageWindow.focus()
}

function newWindow7(texthtml)	//New window for C Company Map
{
imageWindow = window.open(texthtml, "imgWin", "width=900,height=550,screenX=0,left=0,screenY=0,top=0")
imageWindow.focus()
}

function newWindow8(imagejpg)	//New window for extra-wide portrait view images
{
imageWindow = window.open(imagejpg, "imgWin", "width=880,height=480,screenX=0,left=0,screenY=0,top=0")
}


/*************************************************************************/
/*Function to display a slideshow of images with captions.                                              */
/*Adapted from "JavaScript for the World Wide Web by Negrino & Smith"               */
/*************************************************************************/
captionText = new Array("","")

thisImg = 0
imgCt = captionText.length

function newSlide(direction) {
	if (document.images) {
		thisImg = thisImg + direction
		if (thisImg < 0) {
			thisImg = imgCt-1
		}
		if (thisImg == imgCt) {
			thisImg = 0
		}
	document.slideshow.src = "images/slideImg" + thisImg + ".jpg"
	document.imgForm.imgText.value = captionText[thisImg]
	}
}
/*************************************************************************/
/*Greeting function adapted from http://www.dynamicdrive.com/                                 */
/*************************************************************************/
d = new Date();
dateText = "";
dayValue = d.getDay();
if (dayValue == 0)
    dateText += "Sunday";
else if (dayValue == 1)
    dateText += "Monday";
else if (dayValue == 2)
    dateText += "Tuesday";
else if (dayValue == 3)
    dateText += "Wednesday";
else if (dayValue == 4)
    dateText += "Thursday";
else if (dayValue == 5)
    dateText += "Friday";
else if (dayValue == 6)
    dateText += "Saturday";

monthValue = d.getMonth();
dateText += " "
if (monthValue == 0)
    dateText += "January";
if (monthValue == 1)
    dateText += "February";
if (monthValue == 2)
    dateText += "March";
if (monthValue == 3)
    dateText += "April";
if (monthValue == 4)
    dateText += "May";
if (monthValue == 5)
    dateText += "June";
if (monthValue == 6)
    dateText += "July";
if (monthValue == 7)
    dateText += "August";
if (monthValue == 8)
    dateText += "September";
if (monthValue == 9)
    dateText += "October";
if (monthValue == 10)
    dateText += "November";
if (monthValue == 11)
    dateText += "December";

if (navigator.appName.indexOf('Microsoft') != -1)
dateText += " " + d.getDate() + ", " + (0000 + d.getYear());
else if (navigator.appName.indexOf('Netscape') != -1)
dateText += " " + d.getDate() + ", " + (1900 + d.getYear());

minuteValue = d.getMinutes();
if (minuteValue < 10)
    minuteValue = "0" + minuteValue

hourValue = d.getHours();
if (hourValue < 12)
    {
    greeting = "Good morning!";
    timeText = " at " + hourValue + ":" + minuteValue + 
" a.m.";
    }
else if (hourValue == 12)
    {
    greeting = "Good afternoon!";
    timeText = " at " + hourValue + ":" + minuteValue + 
" p.m.";
    }
else if (hourValue < 17)
    {
    greeting = "Good afternoon!";
    timeText = " at " + (hourValue-12) + ":" + minuteValue +
 " p.m.";
    }
else
    {
    greeting = "Good evening!";
    timeText = " at " + (hourValue-12) + ":" + minuteValue + 
" p.m.";
    }

/*************************************************************************/
/* No rightclick script v.2.5 (c) 1998 barts1000  barts1000@aol.com                             */
/*************************************************************************/
var message="Sorry, that function is disabled.\n\nAll contents of this website are Copyright: The Royal County of Berkshire Army Cadet Force.\n\nOur work is not Public Domain, and should NOT be taken from this site unless otherwise stated."; // Message for the alert box

// Don't edit below!

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

/********************************************************************/
/*isJavaEnabled function adapted from JavaScript for the World Wide Web    */
/*by Negrino and Smith                                                                                               */
/********************************************************************/
function isJavaEnabled() {
document.write("JavaScript is")
if (!navigator.javaEnabled()) {
document.write("not ")
}
document.write(" enabled.");
}

/********************************************************************/
/*Message arrays for the Stop Press scrollers - © Dynamic Drive (www.dynamicdrive.com)*/
/********************************************************************/

/*Message arrays for the multi-line scroller*/
var pausecontent=new Array()
pausecontent[0]='<h3>Recent Events......!!</h3>'
pausecontent[1]='<b>More from the Cadet Sergeants Dinner Night.....</b>'
pausecontent[2]='<b>Cadet Sergeants Dinner Night, 20th June.....</b>'
pausecontent[3]='<b>\'B\' Company Weekend, 4th & 5th June.....</b>'
pausecontent[4]='<b>National ACF Athletics, 13th June......</b>'
pausecontent[5]='.....follow the link over on the left to Recent Events 2009.....'

/*Message array for the single line scroller*/
var pausecontent2=new Array()
pausecontent2[0]='<h3>Stop press......stop press......!!</h3>'
pausecontent2[1]='<b>A (Guards) Company Spring Bank Camp 2009..........</b>'
pausecontent2[2]='.....follow the new link on the left to Recent Events 2009.....'


/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}
