// ---------------------------------- it seems it needs to write something
// -------------- to be able to access document.body in Jcreatediv() below
document.write('<div id="dummy" style="display:none;position:absolute;width:200px;height:50px;left:0px;top:0px;padding:16px;background:#FFFFFF;border:2px solid #9292FF">');
//document.write('<form name="pages" action="" onsubmit="return getPage(this)">');
document.write('<b>Enter Page No </b></td>');
document.write('<input type="text" name="pnum" size="3" maxlength="3" value="1">');
document.write('<input type="submit" value="Go">');
//document.write('</form>');
document.write('</div>');
// ----------------------- and it seems it has to be done this way for IE8
// ---------------------------- as just writing the div above doesn't work
var cssString = 'position:absolute;width:225px;height:50px;left:0px;top:0px;padding:10px;background:#ffffff;border:2px solid #9292ff';
var cssString2 = 'font-weight:bold;margin-right:10px';
var cssString3 = 'position:absolute;left:60px;top:40px';
// ------ two global values for Jcreatediv() to communicate with Jselect()
var Pages = 1;
var Register = '';
// -------- NB a button would be simpler, but it does need it to be a form
// ----------------- so it can perform the action associated with the form
function Jcreatediv()
{
//document.write('<form name="pages" action="" onsubmit="return getPage(this)">');
	var div = document.createElement("div")
	div.setAttribute("id", "floatdiv");
// --------- NB 2 statements necessary for assigning a style to an element
// ----------------------- the following is for IE7 and (presumably) below
	if( typeof(div.style.cssText) == 'string' ) {
		div.style.cssText = cssString;
	}
// ------------------- whilst the following statement has no effect in IE7
// ------------------------------------- but is needed for IE8 and FireFox
	div.setAttribute('style', cssString);
	document.body.appendChild(div)
	var formObj = document.createElement('form');
	formObj.setAttribute("id", "goto");
	formObj.setAttribute('action', '');
	div.appendChild(formObj);
	
	var span = document.createElement('span');
	if( typeof(span.style.cssText) == 'string' ) {
		span.style.cssText = cssString2;
	}
	span.setAttribute('style', cssString2);
	span.innerHTML = 'Enter Page No';
	formObj.appendChild(span);

	var inputObj = document.createElement('input');
	inputObj.setAttribute("id", "pnum");
	inputObj.setAttribute("name", "pnum");
	inputObj.setAttribute('size', 3);
	inputObj.setAttribute('type','text');
	inputObj.setAttribute('maxlength', 3);
	inputObj.setAttribute('value','1');
	formObj.appendChild(inputObj);

	formObj.innerHTML += '&nbsp';
	var submit = document.createElement('input');
	submit.setAttribute("id", "submit");
	submit.setAttribute('type','submit');
	submit.setAttribute('value','Go');
	formObj.appendChild(submit);

	formObj.onsubmit = function () {
// ------------------- setting 'id' and getElementbyId doesn't work in IE7
// ---- this uses the 'name' property to access as the element in the form
		var num = this.pnum.value;
		if (isNaN(num) || parseInt(num) < 1 || parseInt(num) > Pages) {
			window.alert("Please enter a page number in the range 1-" + Pages + ".");
			return false;
		}

		var nmod = "000" + num;
		var anchor = nmod.substr(nmod.length-3,3);
		var newPage = Register + anchor;
		if (Register.substr(0,1) == '#') {
// -------------------- check anchor exists (if it's for an internal link)
// http://www.java2s.com/Code/JavaScript/HTML/Listanchorinadocument.htm
			var isOK = false;
			for (var i = 0; i < document.anchors.length; i++) {
				var text = document.anchors[i].name;
				if ((text != null) && (text != '')) {
					if (text == 'p' + anchor) {
						isOK = true;
						break;
					}
				}
			}
			if (!isOK) {
				window.alert("Sorry, this document doesn't have a page number " + num + ".");
				return false;
			}
			document.location.hash = newPage;
			return false;
		}
		document.location.href = newPage;
		return false;
//		this.action = newPage;
//		return true;
	}
	var pageObj = document.createElement('span');
	pageObj.setAttribute('id', 'pages');
	if( typeof(pageObj.style.cssText) == 'string' ) {
		pageObj.style.cssText = cssString3;
	}
	pageObj.setAttribute('style',cssString3);
	pageObj.innerHTML = '(Pages 1-' + Pages + ')';
	div.appendChild(pageObj);
}
// -----------------------------------------------------------------------

function Jselect(reg, page)
{
	Pages = page;
	Register = reg + ".html";

	var href = document.location.href;
	var len = (document.location.hash)?(href.length-document.location.hash.length):href.length;
	var start=href.lastIndexOf('/')+1;
	if (Register == href.substring(start,len)) {
		Register = '#p';
	}
	else {
		Register = Register + "#p";
	}
}
// -----------------------------------------------------------------------

