// Ensure we can use getElementById even in older browsers
if( !document.getElementById ) {
	document.getElementById = function( objId ) {
		if( document.all && document.all(objId) ) { return document.all(objId); }
		else if( document.forms  && document.forms[objId] )  { return document.forms(objId); }
		else if( document.images && document.images[objId] ) { return document.images(objId); }
		else if( document.layers && document.layers[objId] ) { return document.layers[objId]; }
		else { return false; }
	}
}

// popup window for the answer page
var answerWindow = '';
function popanswer( url )
{
	if (!answerWindow.closed && answerWindow.location) {
		answerWindow.location.href = url;
	}
	else {
		answerWindow = window.open(url, 'answer', 'width=450, height=250');
		if (!answerWindow.opener) {
			answerWindow.opener = self;
		}
	}
	if (window.focus) {
		answerWindow.focus()
	}
	return false;
}

// popup window for the calendar page
var calendarWindow = '';
function popCalendar( targetField )
{
	if (!calendarWindow.closed && calendarWindow.location) {
		calendarWindow.location.href = url;
	}
	else {
		calendarWindow = window.open('index.php?page=calendar&targetBox=' + targetField, 'calendar', 'width=300,height=250');
		if (!calendarWindow.opener) {
			calendarWindow.opener = self;
		}
	}
	if (window.focus) {
		calendarWindow.focus()
	}
	return false;
}

// Make text safe for use in url (may have small differences from php's urlencode)
function urlencode(str)
{
	str = str.replace(/\+/g, "%2B");
	str = escape(str);
	return str;
}

// Decode text made safe for use in url (may have small differences from php's urldecode)
function urldecode(str)
{
	str = unescape(str);
	str = str.replace(/%2B/g, "+");
	return str;
}

// *** possibly deprecated / never got as far as being used
// *** May still be useful if the submit form gets fancier
function autoInfo(formName)
{
	alert('here is an alert for ' + formName);
	var theForm = eval('document.'+formName);
	var idNum = theForm.filmId.value;
	alert('nexto ... ');
	alert('filmid is: '+idNum);
	
	pageURL = new
      java.net.URL
        ("http://egmc.org.uk/index.html");

  // step 1, open the URL
  var openConnection = pageURL.openConnection;
  theConnection = openConnection()

  // step 2, connect to server
  var t=theConnection.connect
  t()

  // step 3, read the file using HTTP protocol
  var getContent = theConnection.getContent
  var theURLStream = getContent()

  // step 4, get an handle and fetch the content length
  var readStream = theURLStream.read
  var gcl = theConnection.getContentLength
  gcLen = gcl()

  // and finally, read into a variable
  theText =""
  for (i = 1; i <gcLen; i++) {
   theText += new java.lang.Character(readStream())
   }

  // for demonstration
  alert(theText);
}
