var bIsIE = false;
var bIsIE5 = false;
var bIsIE6 = false;
var bIsIE7 = false;
var bIsIE8 = false;
var bIsFF = false;
var bIsFF1 = false;
var bIsFF2 = false;
var bIsFF4 = false;
var bIsSafari = false;
var bIsSafari3 = false;

try {
	if (navigator.userAgent.search("MSIE") != -1) {
		bIsIE = true;
	}
	if (navigator.userAgent.search("MSIE 5.") != -1) {
		bIsIE5 = true;
	}
	if (navigator.userAgent.search("MSIE 6.") != -1) {
		bIsIE6 = true;
	}
	if (navigator.userAgent.search("MSIE 7.") != -1) {
		bIsIE7 = true;
	}
	if (navigator.userAgent.search("MSIE 8.") != -1) {
		bIsIE8 = true;
	}
	if (navigator.userAgent.search("Firefox/") != -1) {
		bIsFF = true;
	}
	if (navigator.userAgent.search("Firefox/1.") != -1) {
		bIsFF1 = true;
	}
	if (navigator.userAgent.search("Firefox/2.") != -1) {
		bIsFF2 = true;
	}
	if (navigator.userAgent.search("Firefox/3.") != -1) {
		bIsFF3 = true;
	}
	if (navigator.userAgent.search("Safari") != -1) {
		bIsSafari = true;
	}
	if (navigator.userAgent.search("3.0 Safari") != -1) {
		bIsSafari3 = true;
	}
}
catch (e) { }

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function clearCookie(name) {
	setCookie(name,"",-1);
}

function showButtonTooltip(sTooltip) {
	var oTooltip = document.getElementById("tooltip_inner");
	oTooltip.innerHTML = sTooltip;
	if (sTooltip.length > 0) {
		oTooltip.style.display = "block";
	}
	else {
		oTooltip.style.display = "none";
	}
}

function isNumeric(sText) {
	var ValidChars = "0123456789";
	var IsNumber = true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function showPrintChoices() {
	oPrintChoices = document.getElementById("printchoices");
	oPrintChoices.style.display = "block";
	if (bIsIE || bIsFF || bIsSafari) {
		oPrintChoices.style.left = Math.round((document.body.clientWidth - oPrintChoices.clientWidth) / 2) + "px";
	}
}
function hidePrintChoices() {
	oPrintChoices = document.getElementById("printchoices");
	oPrintChoices.style.display = "none";
}
function printSelectedPages() {
	var bValid = true;
	oPrintFirstPage = document.getElementById("print_first_page");
	oPrintLastPage = document.getElementById("print_last_page");
	iPrintMaxPage = eval(document.getElementById("print_page_max").value);
	if (bValid && !(isNumeric(oPrintFirstPage.value) || oPrintFirstPage.value == "i" || oPrintFirstPage.value == "ii")) {
		bValid = false;
		alert(oPrintFirstPage.value + " is not a valid page number.");
		oPrintFirstPage.focus();
	}
	if (bValid && !(isNumeric(oPrintLastPage.value) || oPrintLastPage.value == "i" || oPrintLastPage.value == "ii")) {
		bValid = false;
		alert(oPrintLastPage.value + " is not a valid page number.");
		oPrintLastPage.focus();
	}
	if (bValid && isNumeric(oPrintFirstPage.value) && eval(oPrintFirstPage.value) > iPrintMaxPage) {
		bValid = false;
		alert("Page range must be between i and " + iPrintMaxPage + ".");
		oPrintFirstPage.focus();
	}
	if (bValid && isNumeric(oPrintLastPage.value) && eval(oPrintLastPage.value) > iPrintMaxPage) {
		bValid = false;
		alert("Page range must be between i and " + iPrintMaxPage + ".");
		oPrintLastPage.focus();
	}
	if (bValid && isNumeric(oPrintFirstPage.value) && isNumeric(oPrintLastPage.value) && eval(oPrintFirstPage.value) > eval(oPrintLastPage.value)) {
		bValid = false;
		alert("The first page in the range must come before the last page in the range.");
		oPrintFirstPage.focus();
	}
	if (bValid) {
		setTimeout("hidePrintChoices();", 500);
		var oWindow = window.open("print.asp?first=" + oPrintFirstPage.value + "&last=" + oPrintLastPage.value,"_print","top=100,left=100,width=200,height=100");
		oWindow.focus();
	}
}

function printPDF() {
	hidePrintChoices();
	var iWidth = Math.round(screen.availWidth * 0.9);
	var iHeight = Math.round(screen.availHeight * 0.9) - 30;
	var iLeft = Math.round((screen.availWidth - iWidth) / 2);
	var iTop = Math.round((screen.availHeight - iHeight) / 2) - 30;
	var oWindow = window.open("pdf.asp", "_pdf","width=" + iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop + ",channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0,zoominherit=0",false);
	oWindow.focus();
}

function unloadPage() {
	if (bIsIE) {
		window.scroll(0,0);
	}
}

function preLoadImages() {
	setTimeout("_preLoadImages();", 500);
}

function _preLoadImages() {
	var oNextPage1 = document.getElementById("nextpage1");
	var oNextPage2 = document.getElementById("nextpage2");
	var oPreviousPage1 = document.getElementById("previouspage1");
	var oPreviousPage2 = document.getElementById("previouspage2");
	try {
		oNextPage1.src = oNextPage1.getAttribute("page");
		oPreviousPage1.src = oPreviousPage1.getAttribute("page");
		oNextPage2.src = oNextPage2.getAttribute("page");
		oPreviousPage2.src = oPreviousPage2.getAttribute("page");
	}
	catch(e) {}
}

function maximiseWindow() {
	window.moveTo(0,0);
	if (document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth) {
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}
