/*
Final Exodus.NET Script Index
01 - Chromless Windows for Qualifications Pahe
02 - Field Highlighter for the form
03- Arrays for client side date and time
*/

//-------------------------------------------------------------------------
//  Function:	Chromeless Windows
//  Purpose:	Creation of Pop up windows
//  Input:		User clicking on links
//  Output:		New browser window using DOM and iFrames
//  Author:		Steven Andrews
//  Date:		21/04/2007
//  Notes:		This script is used in conjunction with CSS and DIV tags on the following pages
//				 - aboutme.php
//				
//
//-------------------------------------------------------------------------	
<!--

// these global variables store the X and Y position of the pop-up box //

var oldX, oldY;

// variable to hold the status of window dragging //

var dragIt = false;



// a wee bit of short-hand for browser checking routines //

var ie=document.all&&document.getElementById;

var ns=document.getElementById&&!document.all;



function openPopUp(url,w,h,caption)

{

	if (!ie&&!ns)

		// if viewed with an older browser, open a standard pop-up window //

		window.open(url,caption,"width="+w+",height="+h);



	else {

		// sets up the pop-up box element ready to display some content //

		document.getElementById("popWin").style.display='';

		// sets the width of the pop-up box //

		document.getElementById("popWin").style.width=w+"px";

		// sets the height of the pop-up box //

		document.getElementById("popWin").style.height=h+"px";



		// check to see if the window has been opened before //

		if(oldX == null)

		{

			// if not, position it in the middle of the browser window //

			// first, get the horizontal centre of browser window //

        	cw = (getBrowserWidth() / 2) - w/2;

			// now, position the pop-up box centrally and 25 pixels from the top of the main window //

			document.getElementById("popWin").style.left = cw+"px";

			document.getElementById("popWin").style.top = 25+"px";

		}

		// pop the right page caption in the mover bar //

		temp = document.getElementById("winTitle");  

		temp.firstChild.nodeValue = caption;

		

		// finally, load the page specified into the iframe //

		document.getElementById("contentiFrame").src=url;

	}



}



function closePopUp()

{

	// retain the last position of the window ready to open it again in the same place

	oldX = document.getElementById("popWin").style.left;

	oldY = document.getElementById("popWin").style.top;

	// setting the display style to none renders the element invisible	

	document.getElementById("popWin").style.display="none";

}



function startDrag(e)

{

	offsetx=ie? event.clientX : e.clientX;

	offsety=ie? event.clientY : e.clientY;

	tempx=parseInt(document.getElementById("popWin").style.left);

	tempy=parseInt(document.getElementById("popWin").style.top);

	dragIt = true;

	document.getElementById("popWin").onmousemove=DragNDrop;

}



function DragNDrop(e){

	// move the pop-up window script for Internet Explorer //

	if (ie&&dragIt&&event.button==1){

		document.getElementById("popWin").style.left=tempx+event.clientX-offsetx+"px";

		document.getElementById("popWin").style.top=tempy+event.clientY-offsety+"px";

	}

	// move the pop-up window script for Netscape //

	else if (ns&&dragIt){

		document.getElementById("popWin").style.left=tempx+e.clientX-offsetx+"px";

		document.getElementById("popWin").style.top=tempy+e.clientY-offsety+"px";

	}

}



function stopDrag(){

	dragIt=false;

	document.getElementById("popWin").onmousemove=null;

}





function getBrowserWidth()

{

	if (navigator.userAgent.indexOf("MSIE") > 0)

		return(document.body.clientWidth);

    else

		return window.outerWidth;

}
//-------------------------------------------------------------------------
//  Function:	Form Field Highlighting
//  Purpose:	To highlight the current text field on the contact form
//  Input:		User interacting with form
//  Output:		CSS properties of textfields are altered via the OnBlur Event
//  Author:		Steven Andrews, based on Steve Tucker
//  Date:		21/04/2007
//  Notes:		This script is used in conjunction with CSS on the following pages
//				 - contact.php
//				
//
//-------------------------------------------------------------------------	
/*

Hi there!

I've fully documented the small portion of code in this example (at the bottom
of the page). Before delving in I would first recommend reading through the
html document and stylesheet, so that you are familiar with the context.

Okay. Our main function, which controls the form's behaviour, is called
prepareFieldHighlighting. The second function is anonymous and simply executes
the prepareFieldHighlighting fuction when the page finishes loading.


prepareFieldHighlighting
------------------------
I've first declared the new fuction with the reserved word 'function' and given
it a name, followed by a set of empty parentheses. My first two statements within
the function fetch all the <input> and <textarea> elements using the document
object method getElementsByTagName. References to these are stored in two
appropriately named variables. I've then performed a loop on the first variable
$input_boxes. This will loop through every element (input box) in the array
sequentially. Within the loop I first create a variable aptly named $input_box
(singular of 'boxes') and give it the value of the current input box, using the
variable $i (for increment) to locate it within the $input_boxes numeric array.

Following this I perform a conditional statement, fetching the attribute 'type'
from the current input box. Remember, one of our <input> boxes is a submit button
and we do not want to give this element behaviour. The conditional statement tests
that the value of attribute type is equal to 'text'. If it is then the script
enters the conditional statement curly braces and equips the input box with two
JavaScript events; and onfocus and onblur. These activate when the text box is
focused on and unfocused on, respectively. The value of these events are two
anonymous functions. First, within these functions, look at the reserved word
'this'. It automatically becomes a reference to the element which called it - in
this case any one of the <input> boxes that is focused on or unfocused from.
The statement in onfocus simply sets the class to 'highlighted', whilst the
statement in onblur removes it. This class is picked up by the stylesheet,
rendering the visual change.

After this I carry out the same process on the textarea array (which will contain
just one element). Only I do not need to do a test for the 'type' attribute,
because this is not applicable for <textarea>s, which serve only the one purpose.

And that's it. Read through this code, the stylesheet and the markup and
experiment. Try new things, mess around and see what works and what does not.
If you do end up breaking it then you can always get another copy from the CD.

Steve

*/
function prepareFieldHighlighting() {
	
	var $input_boxes = document.getElementsByTagName('input');
	var $textareas = document.getElementsByTagName('textarea');
	
	for (var $i=0; $i<$input_boxes.length; $i++) {
		var $input_box = $input_boxes[$i];
		if ($input_box.getAttribute('type') == 'text') {
			$input_box.onfocus = function() {
				this.className = 'highlighted';
			}
			$input_box.onblur = function() {
				this.className = '';
			}
		}
	}
	
	for (var $i=0; $i<$textareas.length; $i++) {
		var $textarea = $textareas[$i];
		$textarea.onfocus = function() {
			this.className = 'highlighted';
		}
		$textarea.onblur = function() {
			this.className = '';
		}
	}
}


window.onload = function() {
	prepareFieldHighlighting();
}

//-------------------------------------------------------------------------
//  Function:	Declaring Arrays for inserting date into webpages
//  Purpose:	Date Insertion
//  Input:		None
//  Output:		Time via Javascript / CSS output
//  Author:		Steven Andrews
//  Date:		21/04/2007
//  Notes:		This script is used in conjunction with CSS on the following pages
//				.PHP (All) 
//				
//
//-------------------------------------------------------------------------	

dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

	now = new Date
