function browsercheck() {
	this.ver = navigator.appVersion
	this.agent = navigator.userAgent
	this.dom = document.getElementById ? 1 : 0
	this.ff = (this.agent.indexOf("Firefox")>-1) ? 1 : 0
	this.moz = (this.agent.indexOf("Mozilla")>-1) ? 1 : 0
	this.op5 = (this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1) && window.opera 
	this.op6 = (this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1) && window.opera  
	this.op = this.op5 || this.op6
	this.ie5 = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.op) ? 1 : 0
	this.ie55 = (this.ie5 && this.minorver >= 0.5) ? 1 : 0
	this.ie6 = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.op) ? 1 : 0
	this.ie4 = (this.agent.indexOf("MSIE 4")>-1 && document.all && !this.op && !this.ie5 && !this.ie55 && !this.ie6) ? 1 : 0
	this.ie7 = (this.agent.indexOf("MSIE 7") > -1) ? 1 : 0;
	this.ie8 = (this.agent.indexOf("MSIE 8") > -1) ? 1 : 0;
	this.ie = (this.ie4 || this.ie5 || this.ie6 || this.ie7 || this.ie8);
	this.mac = (this.agent.indexOf("Mac")>-1) ? 1 : 0
	this.win = (this.agent.indexOf("Win")>-1) ? 1 : 0
	this.ns7 = (this.agent.search("Netscape/7")>-1) ? 1 : 0
	this.ns6 = (this.agent.search("Netscape/6")>-1 && !this.ns7) ? 1 : 0
	this.ns4 = (document.layers && !this.dom) ? 1 : 0
	this.ns = (this.ns4 || this.ns6 || this.ns7)
	this.bw = (this.ie || this.ns || this.op)
	this.px = this.dom && !this.op5 ? "px" : ""

	return this
}
var bw = new browsercheck()
var px = (bw.ie) ? 0 : "px"

if (!document.getElementById)
    document.getElementById = function() { 
		return null 
	}

// Function to check the inner height/width of the window
function get_window_y() {
	return (bw.ie) ? document.body.clientHeight : window.innerHeight
}

function get_window_x() {
    return (bw.ie) ? screen.width : window.innerWidth; //document.body.clientWidth : window.innerWidth  fix for IE7
}

// open new window
function window_open(url,name,width,height,options) {
	winOptions = "width=" + width + "," + "height=" + height + "," + options
	new_win = window.open(url, name, winOptions)
	new_win.focus()
	//return new_win
}


// get screen width/height
function get_screen_x() {
	return screen.availWidth
}

function get_screen_y() {
	return screen.availHeight
}

// preload images - use urls as arguments
function image_preload() {
    for (var ipc = 0; ipc < image_preload.arguments.length; ipc++) {
       newImg = new Image()
       newImg.src = image_preload.arguments[ipc]
    }
}

// swap image
function image_swap(image_url, image_name) {
	document.images[image_name].src = image_url
}

function openHelp(id,continuationId) {
//	if (continuationId) SetCookie("continuationId",continuationId,false,"/","fenc.org.uk")
	if (continuationId) SetCookie("continuationId",continuationId,false,"/")
	if (id) window_open('/help/?id=' + id,'helpWindow',800,600,'resizable=yes,status=yes')
	else window_open('/help/','helpWindow',800,600,'resizable=yes,status=yes')
}

function openAspager(id) {
	if (id) window_open("/aspager/?articleID=" + id, "aspPagerWindow", 800, 600, "resizable=yes,status=yes");
	else window_open("/aspager/", "aspPagerWindow", 800, 600, "resizable=yes,status=yes");
}

//Replaces a placeholder with the specified string (see C# String.Format() method)
function StringFormat(val)
{
	var str = val;
	var exp = /{\d+}/g;
	var res = exp.exec(val);
		
	while (res != null)
	{
		i = res.toString().slice(1,res.toString().length-1);					
		str = str.replace(new RegExp("\\{"+i+"\\}","g"),StringFormat.arguments[parseInt(i)+1]);			
		res = exp.exec(val);
	}
	
	return str;
}

//Replaces a placeholder with the specified string (see C# String.Format() method)
String.prototype.Format = function(val)
{
	var str = val;
	var exp = /{\d+}/g;
	var res = exp.exec(val);
		
	while (res != null)
	{
		i = res.toString().slice(1,res.toString().length-1);					
		str = str.replace(new RegExp("\\{"+i+"\\}","g"),StringFormat.arguments[parseInt(i)+1]);			
		res = exp.exec(val);
	}
	
	return str;
}

