// JavaScript Document

var arrMonths = new Array("January", "February","March", "April", "May", "June", "July", "August","September", "October", "November", "December");

//cookie is set in default.asp but should be set in global.asa
function isSmallScreen(){return (GetCookie("pref","screen")=="small")?true:false;};

function setFocussed(e){
 var tbl = document.getElementById("menuTbl") 
 var cntCells = tbl.rows[0].cells.length //Now CntCells used in menu
 for (c=tbl.rows[0].cells.length;c>0;c--){ if (tbl.rows[0].cells[c-1].className == "menuSpan") cntCells = c -1 }
 for (c=0;c<cntCells;c++){
 	if (e == tbl.rows[0].cells[c]){ //Clicked Cell is located
		tbl.rows[0].cells[c].className = "menuOn"
		if (c==1) tbl.rows[0].cells[c-1].className = "menuOnLeftEnd"
		else tbl.rows[0].cells[c-1].className = "menuOffOn"
		if (c+2==cntCells) tbl.rows[0].cells[c+1].className = (tbl.rows[0].cells.length==cntCells)?"menuOnRightEnd":"menuOnNearRightEnd"; //Last Cell
		else tbl.rows[0].cells[c+1].className = "menuOnOff"
		c++ //Force loop to skip the next cell as it has aleady been set.
	}
	else {
	 	if (c==0) tbl.rows[0].cells[0].className = "menuOffLeftEnd"; //First cell					
	 	else if (c+1==cntCells) tbl.rows[0].cells[c].className = (tbl.rows[0].cells.length==cntCells)?"menuOffRightEnd":"menuOffNearRightEnd"; //Last Cell
		else if (c%2!=0) tbl.rows[0].cells[c].className = "menuOff"; //odd number 
		else if (c%2==0) tbl.rows[0].cells[c].className = "menuOffJoin"; //Even number ie Join
	}	
 }
}

function setLeftFocussed(e){
 var tbl = document.getElementById("menuTbl");
 var cntRows = tbl.rows.length; //Now CntCells used in menu
 for (c=0;c<cntRows;c++){ 
 	if (e == tbl.rows[c].cells[0]){ tbl.rows[c].cells[0].className = "menuOn"}
	else {tbl.rows[c].cells[0].className = "menuOff"}	
 }
}


function subWin(loc,W,H,winName) {
	var X = (screen.width/2)-(W/2);
	var Y = (screen.height/2)-(H/2);	
	var winPrefs  = "width=" + W + ",height=" + H
				  + ",innerWidth=" + W + ",innerHeight=" + H
				  + ",left=" + X + ",top=" + Y
				  + ",screenX=" + X + ",screenY=" + Y
				  + ",resizable=0,menubar=0,titlebar=0,toolbar=0,location=0,scrollbars=1";         
    top.newWin = window.open(loc, winName, winPrefs);
    top.newWin.focus();
}

function hilite(obj){
	obj.style.border = "1px solid red"; 
	window.top.frames["frSetEngine"].resetIdle();  //<-- Changed for Small Screen see next line
	//parent.parent.resetIdle()
}

function lolite(obj){
 if (obj.id == "today"){obj.style.border = "1px solid blue"}
 else 	if (obj.id == "selDate"){}
 		else obj.style.border = "1px solid #CCCCCC"
}

//Use for the computer to interpret.
function time24Hr(dateObj){	return dateObj.getHours() + ":" + dateObj.getMinutes();}

//Use to display in the interface for the user.
function time12Hr(dateObj){
	e = (dateObj.getHours()<12)?" am":" pm";
	adj = (dateObj.getHours()<=12)?0:12;
	mins = (dateObj.getMinutes()<10)?"0" + dateObj.getMinutes():dateObj.getMinutes();
	return (dateObj.getHours()-adj)+ ":" + mins + e;
}

//allows only numeric plus backspace . NEEDS MORE WORK. SHOULD ALSO ALLOW A CHARCODE WHICH IS PASSED AS AN ARGUMENT.
//EG onkeypress="return isNumberKey(event);"
function isNumberKey(evt, useDecimal){
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (useDecimal && charCode == 46) return true;	
 if (charCode > 31 && (charCode < 48 || charCode > 57 ))	return false;
 return true;
}


//Report Errors
/*window.onerror=function(msg, url, linenumber){
	alert("Error Occured");
	var err = new Error;
	err.message = msg;
	err.url = url;
	err.line = linenumber;
	var data =''; 
	for(var z in err) {	data +=	'&' + z + '=' + err[z];}
	data = data.replace("'","").replace(/ /g,"+").substr(1);
	if (window.XMLHttpRequest) request = new XMLHttpRequest();
	else if (window.ActiveXObject) request = new ActiveXObject("Microsoft.XMLHTTP");
	else return; // throw up our hands in despair
	request.open("POST", window.location.protocol + "//" + window.location.host + "/error/clientErrorLogger.asp");
	// set the request headers. REFERER will be the top-level
	request.setRequestHeader('REFERER', location.href);
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", data.length);
	request.setRequestHeader("Connection", "close");
	//prompt('',data)
	request.send(data);
}*/

