var popUpWin=0;

function popUpWindow(url, width, height, scrollOption) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	var left = (screen.width-width)/2;
	var top = (screen.height-height)/2;
	popUpWin = window.open(url, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbars='+scrollOption+',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function changeURL(url) {
	window.location.href=url;
}

function openExternalLink(url) {
	window.open(url);
}

function windowResize() {
	// Get access to styles, assumes pageDiv is set by index page or contentAllie/Nick.js
	var bodyStyle = document.body.style;
	
	if (document.getElementById) {
		var pageStyle = document.getElementById(pageDiv).style;
	} else if (document.all) {
		var pageStyle = document.all[pageDiv].style;
	} else if (document.layers) {
		var pageStyle = document.layers[pageDiv].style;
	}
	
	if ((getBrowserWidth() > 980) && (getBrowserHeight() > 585)) {
		bodyStyle.textAlign = 'center';
	
		pageStyle.top = '50%';
		pageStyle.left = '50%';
		pageStyle.marginTop = '-291px';
		pageStyle.marginLeft = '-490px';
	} else {
		bodyStyle.textAlign = 'left';
		
		pageStyle.top = 0;
		pageStyle.left = 0;
		pageStyle.marginTop = '0px';
		pageStyle.marginLeft = '0px';	
	}
}

/* Helper functions */

function getBrowserWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth != 0) {
		return document.documentElement.clientWidth;
	} else if (document.body) {
		return document.body.clientWidth;
	}
	return 0;
}

function getBrowserHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight != 0) {
		return document.documentElement.clientHeight;
	} else if (document.body) {
		return document.body.clientHeight;
	}
	return 0;
}

/* Flash functions */

function flashEvent(inSwf, inEvent, inParams) {	
	var divcontainer = "flash_setvariables_" + inSwf;	
	if (!document.getElementById(divcontainer)) {
		var divholder = document.createElement("div");
		divholder.id = divcontainer;
		document.body.appendChild(divholder);
	}
	var divinfo = "<embed src='../js/gateway.swf' FlashVars='lc=" + inSwf + "&ev=" + escape(inEvent) + "," + escape(inParams) + "' width='0' height='0' type='application/x-shockwave-flash'></embed>";
	document.getElementById(divcontainer).innerHTML = "";
	document.getElementById(divcontainer).innerHTML = divinfo;
}
