popups=new Array()

function launchPopup(theURL,windowProperties, returnValue, winRef) {
	
	var winRef = winRef ? winRef : ""
	
	winPropertyDefaults = new Array()
	
	winPropertyDefaults["width"]=200
	winPropertyDefaults["height"]=200
	winPropertyDefaults["left"]=100
	winPropertyDefaults["top"]=100
	winPropertyDefaults["directories"]="no"
	winPropertyDefaults["location"]="no"
	winPropertyDefaults["menubar"]="no"
	winPropertyDefaults["resizable"]="yes"
	winPropertyDefaults["screenX"]=100
	winPropertyDefaults["screenY"]=100
	winPropertyDefaults["scrollbars"]="auto"
	winPropertyDefaults["status"]="no"
	winPropertyDefaults["toolbar"]="no"
	
	
	windowProperties = windowProperties ? windowProperties : new Object()
	
	screenWidth = 400
	screenHeight = 300
	
	if(screen.width) {screenWidth=screen.width;winPropertyDefaults["width"]=screenWidth/2}
	if(screen.height) {screenHeight=screen.height;winPropertyDefaults["height"]=screenHeight/2}
	
	if(screen.availWidth) {screenWidth=screen.availWidth;winPropertyDefaults["width"]=screenWidth/2}
	if(screen.availHeight) {screenHeight=screen.availHeight;winPropertyDefaults["height"]=screenHeight/2}
	
	
	
	var height=winPropertyDefaults["height"]
	var width=winPropertyDefaults["width"]
	
	
	
	if(windowProperties.width) {
		var widthProperty = windowProperties.width+""
		var widthPercent = widthProperty.indexOf("%")>-1
		width=widthPercent ? (parseInt(widthProperty)/100)*screenWidth : parseInt(widthProperty)
		}
		
	if(windowProperties.height) {
		var heightProperty = windowProperties.height+""
		var heightPercent = heightProperty.indexOf("%")>-1
		height=heightPercent ? (parseInt(heightProperty)/100)*screenHeight : parseInt(heightProperty)
		}																				 
	
	if(windowProperties.minWidth) {
		windowProperties.minWidth = parseInt(windowProperties.minWidth)
		if(width<windowProperties.minWidth) {width=windowProperties.minWidth}
		delete windowProperties.minWidth
	}
	
	if(windowProperties.minHeight) {
		windowProperties.minHeight = parseInt(windowProperties.minHeight)
		if(height<windowProperties.minHeight) {height=windowProperties.minHeight}
		delete windowProperties.minHeight
	}
	
	if(width>screenWidth) {width=screenWidth-20}
	if(height>screenHeight) {height=screenHeight-20}
	
	var windowTop = (screenHeight-height)/2
	var windowLeft = (screenWidth-width)/2
	
	if(windowTop<0) {windowTop=0}
	if(windowLeft<0) {windowLeft=0}
	
	winPropertyDefaults["screenX"]=windowLeft
	winPropertyDefaults["screenY"]=windowTop
	winPropertyDefaults["left"]=windowLeft
	winPropertyDefaults["top"]=windowTop

	windowProperties.height = height
	windowProperties.width = width
	
	for(var i in windowProperties) {
		winPropertyDefaults[i] = windowProperties[i]
	}
	
	var sWindowProperties = ""
	
	for(i in winPropertyDefaults) {
		
		sWindowProperties+=(sWindowProperties ? "," : "")+i+"="+winPropertyDefaults[i]
			
	}

	
	popups[popups.length] = window.open(theURL,winRef,sWindowProperties)
	
	if(returnValue) {return popups[popups.length-1]}
	
	}
	
function launchPreview() {
	launchPopup("/demo/",{width:900,height:"80%",scrollbars:"yes",minHeight:600})
}

function launchRegister() {
	opener.location.href = "/register.shtml"
	opener.focus()
	window.close()
}

function launchComparison() {
	launchPopup("/content/pages/learn_more/finance_types/finance_comparison.shtml",{width:1200,height:700})
}


function closeInfoLayer() {
	document.getElementById("infoLayer").style.visibility="hidden"
	document.getElementById("infoLayerBG").style.visibility="hidden"
}

function centreInfoLayer() {
	
	
	var infoLayer = document.getElementById("infoLayer")
	if(infoLayer) {
		var docHeight
		var bodyHeight
		if(document.documentElement) {
			docHeight = document.documentElement.clientHeight
		}
		
		bodyHeight = document.body.clientHeight
		
		if(bodyHeight) {
			
			docHeight = docHeight ? docHeight : bodyHeight
			
			var maxWinHeight = docHeight>bodyHeight ? docHeight : bodyHeight
			var minWinHeight = docHeight<bodyHeight ? docHeight : bodyHeight
			
			var infoLayerHeight = infoLayer.clientHeight
			
			var newLayerTop = Math.floor((minWinHeight-infoLayerHeight)/2)
			newLayerTop = newLayerTop>0 ? newLayerTop : 10
			infoLayer.style.top = newLayerTop
			
			var layerBackground = document.getElementById("infoLayerBG")
			layerBackground.style.height = maxWinHeight
			
			infoLayer.style.visibility = "visible"
			layerBackground.style.visibility = "visible"
			
		}
	}
}
		
		
