<!--

/* These scripts have been tested with the following browsers.
   Some scripts do not work in all browsers and examples are provided

   Firefox 1.0
   IE 6.0
   Opera 6.01
   Opera 7.54
   Netscape 4.76
   Netscape 6.21
*/

// returns true if the browser is IE
function isIE()
{
	ua = navigator.userAgent.toLowerCase();
	return ua.indexOf('msie') != -1 
		&& ua.indexOf('opera') == -1 
		&& ua.indexOf('webtv') == -1;
}

// returns true if the browser is Opera
function isOpera()
{
	ua = navigator.userAgent.toLowerCase();
	return (ua.indexOf('opera') != -1); 
}


// sets the value of the specified form object
function setTextBox(id, value)
{
	document.forms[0].elements[id].value = value;
}

// returns the value of the specified form object
function getTextBox(id)
{
	return(document.forms[0].elements[id].value);
}

// sets the value of the specified form object
// in the page that opened this one
function setOpeningTextBox(id, value)
{
	window.opener.document.forms[0].elements[id].value = value;
}

// returns the value of the specified form object
// in the page that opened this one
function getOpeningTextBox(id)
{
	return(window.opener.document.forms[0].elements[id].value);
}

// sets the text of an element (e.g. span) on different browsers
// This will not work in Opera 6 or Netscape 4. 
// If this functionality is essential use <input type="text"> and setTextBox()
// apply a style to make the input look more like a label 
function setText(id, text)
{

if (document.all)            
   document.all(id).innerText = text;
else if(document.getElementById)   
	{    
	// Opera 6 falls in here, but neither innerText nor inner HTML work for it      
	x = document.getElementById(id);	
	x.innerHTML= ''; // fix for MAC IE 5.1 or higher 
	x.innerHTML= text;    
	}
else if (document.layers)
   {
   		// Nestcape 4: do nothing. 
		// For this to work in netscape 4, you need to define a layer with absolute position
		// and write to the layer. The layer loses the absolute positioning after being written to
		// so the absolute positioning needs to be applied again. See example below		
		//	lyr = document.layers[id];
		//	positionedTxt = '<P CLASS="layerclass">' + text + '</P>';
		//	lyr.document.open();
		//	lyr.document.write(positionedTxt);
		//	lyr.document.close();		
   }
}
   
// reads the text of an element (e.g. span, or div) on different browsers
// This will not work in Opera 6 or Netscape 4. 
function getText(id)
{
if (document.all)               
	return document.all(id).innerText;
else if(document.getElementById)              
	return document.getElementById(id).innerHTML;                                
else if (document.layers)                    
     return '';// can't read the text here
}

// this function shows or hides the specified element (div, span, input, etc)
// isVisible=0: hidden
//  isVisible=1: visible
// Netscape 4 requires the use of layers with absolute positioning      
function setVisible(id, isVisible) 
{  
	if(document.getElementById)   //gecko(NN6) + IE 5+
	{
        document.getElementById(id).style.visibility = isVisible ? "visible" : "hidden";   
		document.getElementById(id).style.display = isVisible ? "inline" : "none"; 
	}
 	else if(document.all) // IE 4 
 	{   
        document.all[id].style.visibility = isVisible ? "visible" : "hidden";
	}
	else if(document.layers)    //NN4+
       document.layers[id].visibility = isVisible ? "show" : "hide";
}

// this function shows the specified element (div, span, input, etc)
// Netscape 4 requires the use of layers with absolute positioning 
function showElement(id)
{
	setVisible(id, 1);
}
// this function hides the specified element (div, span, input, etc)
// Netscape 4 requires the use of layers with absolute positioning 
function hideElement(id)
{
	setVisible(id, 0);
}

// sets the background colour of the specified element
// Netscape 4 requires the use of layers with absolute positioning 
function setColour(id, colour)
{
	if (document.all)                
    	document.all(id).style.backgroundColor = colour;
    else if(document.getElementById)              
        document.getElementById(id).style.backgroundColor = colour;                               
    // else if (document.layers)
    // to use layers, the style needs to be applied to the layer
}

// reads the bakground colour of the specified element
// Netscape 4 requires the use of layers with absolute positioning 
function getColour(id)
{
	if (document.all)                
    	return document.all(id).style.backgroundColor;
    else if(document.getElementById)              
	
        return document.getElementById(id).style.backgroundColor;                               
    else if (document.layers)
		return ''; // can't deal with netscape 4
}
   
// enables the specified form object
function enable(id)
{
	document.forms[0].elements[id].disabled = false;
}

// disables the specified form object
function disable(id)
{
	return(document.forms[0].elements[id].disabled = true);
}

// Expands the panel to its full size (defined by the containing content
// this does not work in Opera or Netscape
	function expand(id)
	{
		if(document.all(id) != null)
		{
			document.all(id).style.overflow = "visible";
			document.all(id).style.height = "100%";
		}
		else if(document.getElementById(id) != null)
		{
			document.getElementById(id).style.overflow = "visible";
			document.getElementById(id).style.height = "100%";
	    }
	}
	
	// collapses the panel to the height specified for the panel (style="height=60px")
	// if the contents of the panel is more than the height then scrollbars are applied
	// this does not work in Opera or Netscape
	function collapse(id, size)
	{
		if(document.all(id) != null)
		{
			document.all(id).style.overflow = "auto";
			document.all(id).style.height = size;
		}
		else if(document.getElementById(id) != null)
		{
			document.getElementById(id).style.overflow = "auto";
			document.getElementById(id).style.height = size;
		}
	}
	
	
// sets the width of the element
function setTheWidth(id, width)
{

if(document.all)
		document.all(id).style.width = width;
	else if (document.getElementById)
		document.getElementById(id).style.width = width;

}

// replaces all instances of a character sequence within a text string
// For example replaceChars('1&nbsp;2', '&nbsp;', ' ') returns '1 2'
function replaceChars(text, toReplace, replaceWith) {
		temp = "" + text; // temporary holder
		
		while (temp.indexOf(toReplace)>-1) {
			pos= temp.indexOf(toReplace);
			temp = "" + (temp.substring(0, pos) + replaceWith + 
			temp.substring((pos + toReplace.length), temp.length));
		}
		return temp;
	}

// reads the query string parameters and returns them in an array
// for example:
// 		var params = getParams();
//		var colour = params["colour"];
function getParams() {
	url = window.location.href;
	idx = url.indexOf('?');
	params = new Array();
	if (idx != -1) {
		var pairs = url.substring(idx+1, url.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = replaceChars(unescape(nameVal[1]), '+', ' ');
		}
	}
	return params;
}


    // this function hides and displays a panel based on the values of an asp check box
    // add an onClick event to check box to call this function, e.g. onClick="showPanel(this, Panel1)"
    // 
    // checkbox :- the ASP checkbox (this renders as a HTML checkbox wrapped in a span)
    // panel :- the name/id of the panel
	function showPanel(checkbox, panel)
	{
		// the check box is the first child node
		nodeIndex = 0;	
	    box = checkbox.childNodes[nodeIndex]; // check box wrapped in a span
		if(box.checked)
		{
		    showElement(panel);
		}
		else
		{
			hideElement(panel);
		}
	}
	
	// similar to the showPanel method, but the ID of the checkbox is passed in
	function showPanelByID(checkboxID, panel)
	{
		if(document.forms[0].elements[checkboxID].checked)
		{
		    showElement(panel);
		}
		else
		{
			hideElement(panel);
			
		}
	}
	
	// this function enables a control whenever a asp check box is selected
	// and disables it when it is deselected. 
	// this specifically works for an asp check box which renders within a span
	function enableControl(checkbox, control)
    {
		// For IE, the check box is the first child node, for all other browsers
		// a text element surrounds the check box so choose the second child node 
		nodeIndex = 0;
		if(!isIE())
			nodeIndex = 1;
			
	    chkbx = checkbox.childNodes[nodeIndex];
		if(chkbx.checked)
			enable(control);
		else
			disable(control);	
    }

	
// checks the length of the text in the specified multi-line text area 
// to prevent it exceeding the max length on keydown event
function checkMaxLength(textArea, maxLength){
  len = textArea.value.length
  if (len > maxLength) 
		textArea.value = textArea.value.substring(0, maxLength);
}

// sets the remaining number of characters on keyup event
// by comparing the length of the text in the text area against the max length
function setRemainingCharacters(textArea, maxLength, countTxBx) {
	setRemainingCharacters(textArea, maxLength, countTxBx,false)
}

// sets the remaining number of characters on keyup event
// by comparing the length of the text in the text area against the max length
// the boolean value isNameEscaped indicates if the countTxBx is escaped and needs to be unescaped
// this is used in special cases where script is called from user controls on the page
function setRemainingCharacters(textArea, maxLength, countTxBx, isNameEscaped) {
	len = textArea.value.length;
	var cl;

	if ((len == 1) && (textArea.value.substring(0, 1) == " ")) {
		textArea.value = "";
		len = 0
	}
	if (len > maxLength) {
		textArea.value =textArea.value.substring(0, maxLength);
		cl = 0;
	}
	else {
		cl = maxLength - len;
	}
	if(isNameEscaped)	
	    setTextBox(unescape(countTxBx), cl);
	else
	    setTextBox(countTxBx, cl);
}

function restoreImage() { //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 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=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 findObject(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=findObject(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObject(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function emailPage()
    {        
    	window.location = "mailto:?subject=" +document.title 
	+ "&body=I%20thought%20you%20might%20be%20interested%20in%20this%20page%20on%20the%20Mobility%20Data%20Systems%20website%3A%0D%0A%0D%0APage%3A%20%20" 
	+document.title +"%0D%0A%0D%0AAddress%3A%20%20" +window.location;
    }

function printPage()
{
	window.print();
}

function bookmarkPage()
{
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		var url=window.location.href;
		var title=document.title;		
		window.external.AddFavorite(url,title);	
	} else {
		alert("Your browser is prevents automatic bookmarking.\nPress (CTRL-D) to bookmark this page.");
	}
}

function openWindow(sUrl, nWidth, nHeight)
  	{  
	window.open(sUrl, 'popup', 'width=' + nWidth + ',height=' + nHeight + ',scrollbars, resizable');
}



var TodaysDay = new Array('Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday');
var TodaysMonth = new Array('January', 'February', 'March','April', 'May','June', 'July', 'August', 'September','October','November', 'December');
var DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');

function LeapYearTest (Year) 
{
    if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0)) 
    {
        return true;
    }
    else 
    {
        return false;
    }
}

function offsettheDate (offsetCurrentDay) 
{
    if (offsetCurrentDay > 6) 
    {
        offsetCurrentDay -= 6;
        DayOffset = TodaysDay[offsetCurrentDay-1];
        offsettheDate(offsetCurrentDay-1);
    }
    else 
    {
        DayOffset = TodaysDay[offsetCurrentDay];
        return true;
    }
}
function displayDate(dateVal) 
{
    DaystoAdd=dateVal;
    TodaysDate = new Date();
    
    
    CurrentYear = TodaysDate.getYear();
    if (CurrentYear < 2000) 
        CurrentYear = CurrentYear + 1900;
    currentMonth = TodaysDate.getMonth();
    DayOffset = TodaysDate.getDay();
    currentDay = TodaysDate.getDate();
    month = TodaysMonth[currentMonth];
    if (month == 'February') 
    {
        if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) 
        {
            DaysinMonth[1] = 29;
        }
        else 
        {
            DaysinMonth[1] = 28;
        }
    }
    days = DaysinMonth[currentMonth];
    currentDay += DaystoAdd;
    if (currentDay > days) 
    {
        if (currentMonth == 11) 
        {
            currentMonth = 0;
            month = TodaysMonth[currentMonth];
            CurrentYear = CurrentYear + 1;
            }
        else 
        {
            month =
                TodaysMonth[currentMonth+1];
        }
        currentDay = currentDay - days;
    }
    DayOffset += DaystoAdd;
    
    offsettheDate(DayOffset);
	
	TheDate  = DayOffset + ', ';
    TheDate += currentDay + ' '; 
    TheDate += month + ' ';

    if (CurrentYear<100) CurrentYear="19" + CurrentYear;
    TheDate += CurrentYear;
    document.write(' '+TheDate);
}


// adds the specified number of days to the current day and returns the resulting date
	function addDays(numDays)
	{
    TodaysDate = new Date();
    
    
    CurrentYear = TodaysDate.getYear();
    if (CurrentYear < 2000) 
        CurrentYear = CurrentYear + 1900;
    currentMonth = TodaysDate.getMonth();
    DayOffset = TodaysDate.getDay();
    currentDay = TodaysDate.getDate();
    if (currentMonth == 1) 
    {
        if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) 
        {
            DaysinMonth[1] = 29;
        }
        else 
        {
            DaysinMonth[1] = 28;
        }
    }
    days = DaysinMonth[currentMonth];
    currentDay += numDays;
    if (currentDay > days) 
    {
        if (currentMonth == 11) 
        {
            currentMonth = 0;
            CurrentYear = CurrentYear + 1;
            }
        else 
        {
            currentMonth = currentMonth+1;
        }
        currentDay = currentDay - days;
    }
    DayOffset += numDays;
    
	var newTime = new Date();
	newTime.setDate(currentDay); 
	newTime.setMonth(currentMonth);
	newTime.setYear(CurrentYear);
 
	return (newTime);
	}




	function pageScroll() {
    		window.scrollBy(0,2); // horizontal and vertical scroll increments
    		scrolldelay = setTimeout('pageScroll()',200); // scrolls every 100 milliseconds
	}

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];}
}

//-->
