var IE4 = (document.all && !document.getElementById) ? true : false;
var NS4 = (document.layers) ? true : false;
var IE5 = (document.all && document.getElementById) ? true : false;
var NS6  = (document.getElementById && !document.all) ? true : false;

var isIE = false;
var isNS = false

if(IE5 || IE4)
	isIE = true;

if(NS6)
	isNS = true;


// script to get the time and date for display on the page
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var time = new Date();
var hour = time.getHours();
var mins = time.getMinutes();
var secs = time.getSeconds();
var minString = mins.toString();
var minCorrect = '';
var digit = /\d{2}/
if (digit.test(minString) == false) minCorrect='0' + minString;
else minCorrect = minString;
var lmonth = months[time.getMonth()];
var month = time.getMonth() + 1;
var date = time.getDate();
var year = time.getYear();
if (year < 2000) year = year + 1900;


function loadMainHelp(pageName) {
	var h = 550;
	var w = 750;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	helpWindow = window.open( "/oaa/help/" + pageName, "help_Window", "height=" + h + ",width=" + w + ",top=" + TopPosition + ",left=" + LeftPosition + ",scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no");
	if (window.focus) {setTimeout('helpWindow.focus()',0)};
}

function loadHelp(pageName) {
	var h = 400;
	var w = 600;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	helpWindow = window.open( "/oaa/help/" + pageName + ".html", "help_Window", "height=" + h + ",width=" + w + ",top=" + TopPosition + ",left=" + LeftPosition + ",scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no");
	if (window.focus) {setTimeout('helpWindow.focus()',0)};
}

function loadRules(pageName) {
	if (!pageName) return;
	var h = 400;
	var w = 600;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	rulesWindow = window.open( "/oaa/help/" + pageName + ".html", "rules_Window", "height=" + h + ",width=" + w + ",top=" + TopPosition + ",left=" + LeftPosition + ",scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no");
	if (window.focus) {setTimeout('rulesWindow.focus()',0)};
}

function contactUs() {
	var h = 250;
	var w = 330;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	contactWindow = window.open( "/oaa/help/contactUs.html", "contact_Window", "height=" + h + ",width=" + w + ",top=" + TopPosition + ",left=" + LeftPosition + ",scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no");
	if (window.focus) {setTimeout('contactWindow.focus()',0)};
}

function openChromeslessWindow(openUrl, winName, wWidth, wHeight, wPosx, wPosy, wTIT, windowBORDERCOLOR, windowBORDERCOLORsel, windowTITBGCOLOR, windowTITBGCOLORsel, bCenter, sFontFamily, sFontSize, sFontColor){
	openchromeless(openUrl,winName, wWidth, wHeight, wPosx, wPosy, wTIT, wTIT , windowBORDERCOLOR, windowBORDERCOLORsel, windowTITBGCOLOR, windowTITBGCOLORsel, bCenter, sFontFamily, sFontSize, sFontColor);
}


// variable to use for checking if things are undefined
var undefined;

var isMac = false;
if (navigator.platform.indexOf("Mac") != -1) {
	isMac = true;
}

var submitting = false;

// set the global variable for debug.  'true' for debug, 'false' for normal application flow
var IN_DEV_DEBUG_MODE = false;

// function for linking to another page via a service (to be used instead of 'window.location')
// default behaviour is to disable, unless 'true' is passed in
function nextPage(theService, theForm, leaveButtons) {
	// ensure we have a working form.  Default to the first one on the page
	if(!theForm) { theForm = document.forms[0]; }
	// show debug info to the user if in debug mode
	if(IN_DEV_DEBUG_MODE) {
		if(!theService) {
			theService = theForm.service.value;
		}
		var nextPageField = theForm.next_page;
		var nextPageValue = "not set";
		if(nextPageField) {
			nextPageValue = nextPageField.value;
		}
		var message = "service [" + theService + "], next_page[" + nextPageValue + "]\n\nPress 'OK' to submit, 'Cancel' to return.";
		if(!confirm(message)) { return;}
	}
	// if the form is being submitted then do nothing
	if (submitting) { return; }
	// if the buttons are to be disabled then do it
	if (!leaveButtons) { disableAllButtons(); }
	// if a service has been passed in then set it
	if (theService) { theForm.service.value = theService; }
	// set the cachebuster value
	theForm.cacheBuster.value = year+""+month+""+date+""+hour+""+mins+""+secs;
	// submit the form
	theForm.submit();
	// if the form target is the frame we're in then set the 'submitting' flag to true
	if (theForm.target == "" || theForm.target == "_self") { submitting = true; }
}

//disables all buttons on a page
function disableAllButtons() {
	var allInputs = document.getElementsByTagName("input");
	for (i=0; i<allInputs.length; i++) {
		if (allInputs[i].type == "button") allInputs[i].disabled = true;
	}
}


function getWindowHeight() {
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') {
		windowHeight=window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body&&document.body.clientHeight) {
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number') {
		windowWidth=window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body&&document.body.clientWidth) {
				windowWidth=document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}


/*
 *  function to remove all the options from a dropdown list
 *  default behaviour is to leave the first option in place
 *  removeLast is an optional argument which removes all options if set to true
 *  addSelect is an optional argument which adds in a select option if set to true
 */
function clearDropdown(theField, removeLast, addSelect) {
	var last = 1;
	if (removeLast == true) { last = 0; }
	for (var i=theField.options.length; i>=last; i--) {
		theField.remove(i);
	}
	if (addSelect == true) {
		theField.options[theField.options.length] = new Option("-- Select --", "-1");
	}
}


/*
 *  Generic function to populate a dropdown from an array of objects
 *  fieldName is just a string (not a name object)
 *  optionsArray must be an array of objects which have "name" and "id" attributes
 *  noSelect is optional, if true then the select option is not inserted
 */
function populateDropdown(fieldName, optionsArray, noSelect) {
	var theField = document.getElementById(fieldName);
	// remove all existing options first
	clearDropdown(theField, true, !noSelect);
	// create new options
	for (var i=0; i<optionsArray.length; i++) {
		var optionName = optionsArray[i].name;
		if (optionName == undefined) { optionName = optionsArray[i].Name; }
		var optionId = optionsArray[i].id;
		if (optionId == undefined) { optionId = optionsArray[i].ID; }
		theField.options[theField.options.length] = new Option(optionName, optionId);
	}
}


