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"
	
	
	var windowProperties = windowProperties ? windowProperties : ""
	
	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}
	
	
	
	height=winPropertyDefaults["height"]
	width=winPropertyDefaults["width"]
	
	
	widthPropertyIndex = windowProperties.indexOf("width=")
	if(widthPropertyIndex>-1) {
		widthProperty = windowProperties.substring(widthPropertyIndex+6,windowProperties.length)
		if(widthProperty.indexOf(",")>-1) {widthProperty = widthProperty.substring(0,widthProperty.indexOf(","))}
		var widthPercent = widthProperty.indexOf("%")>-1
		width=widthPercent ? (parseInt(widthProperty)/100)*screenWidth : parseInt(widthProperty)
		}
		
	heightPropertyIndex = windowProperties.indexOf("height=")
	if(widthPropertyIndex>-1) {
		heightProperty = windowProperties.substring(heightPropertyIndex+7,windowProperties.length)
		if(heightProperty.indexOf(",")>-1) {heightProperty = heightProperty.substring(0,heightProperty.indexOf(","))}
		var heightPercent = heightProperty.indexOf("%")>-1
		height=heightPercent ? (parseInt(heightProperty)/100)*screenHeight : parseInt(heightProperty)
		}
	
	
	windowTop = (screenHeight-height)/2
	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

	if(widthPercent) {
	
		winPropertyDefaults["width"]=width
		wPropIndex = windowProperties.indexOf("width=")
		if(wPropIndex>-1) {
			newWinProperties = windowProperties.substring(0,wPropIndex)
			wnPropIndex = windowProperties.indexOf(",",wPropIndex)
			newWinProperties = wnPropIndex >-1 ? newWinProperties + windowProperties.substr(wnPropIndex+1) : newWinProperties
			windowProperties = newWinProperties
			}
		}
		
	if(heightPercent) {
	
		winPropertyDefaults["height"]=height
		hPropIndex = windowProperties.indexOf("height=")
		if(hPropIndex>-1) {
			newWinProperties = windowProperties.substring(0,hPropIndex)
			hnPropIndex = windowProperties.indexOf(",",hPropIndex)
			newWinProperties = hnPropIndex >-1 ? newWinProperties + windowProperties.substr(hnPropIndex+1) : newWinProperties
			windowProperties = newWinProperties
			}
		}
	
	for(i in winPropertyDefaults) {
		if(windowProperties.indexOf(i+"")<0) {
			windowProperties+=","+i+"="+winPropertyDefaults[i]
			}
		}

	
	popups[popups.length] = window.open(theURL,winRef,windowProperties)
	
	if(returnValue) {return popups[popups.length-1]}
	
	}