var popwindow
var thistoolbar
var thislocation
var thisdirectories
var thisstatus
var thismenubar
var thisscrollbars
var thisresizable
var thisurl
var thiswidth
var thisheight
var thisdirection
var thistopposition
var thisleftposition
var pause=20
var stepfactor=20
var stepx
var stepy

var marginpadding=23

var startleft=0
var endleft=0
var starttop=0
var endtop=0

var marginleft=0
var margintop=0
var marginright
var marginbottom
var timer

function openpopup() {

	thistoolbar=tistoolbar
	thislocation=tislocation
	thisdirectories=tisdirectories
	thisstatus=tisstatus
	thismenubar=tismenubar
	thisscrollbars=tisscrollbars
	thisresizable=tisresizable
	thisurl=tisurl
	thiswidth=tiswidth
	thisheight=tisheight
	thisdirection=tisdirection
	
	marginright=screen.width
	marginbottom=screen.height

	if (thisdirection=="horitop") {
		startleft=marginleft
		endleft=marginright-thiswidth-marginpadding
		starttop=marginpadding
		endtop=starttop
		stepx=stepfactor
		stepy=0	
	}
	if (thisdirection=="horimiddle") {
		startleft=marginleft
		endleft=marginright-thiswidth-marginpadding
		starttop=Math.round((marginbottom-thisheight)/2)
		endtop=starttop
		stepx=stepfactor
		stepy=0	
	}
	if (thisdirection=="horibottom") {
		startleft=marginleft
		endleft=marginright-thiswidth-marginpadding
		starttop=marginbottom-thisheight-2*marginpadding
		endtop=starttop
		stepx=stepfactor
		stepy=0	
	
	}
	if (thisdirection=="vertileft") {
		startleft=marginleft
		endleft=startleft
		starttop=marginpadding
		endtop=marginbottom-thisheight-2*marginpadding
		stepx=0
		stepy=stepfactor	
	}
	if (thisdirection=="vertimiddle") {
		startleft=Math.round((marginright-thiswidth)/2)
		endleft=startleft
		starttop=marginpadding
		endtop=marginbottom-thisheight-2*marginpadding
		stepx=0
		stepy=stepfactor	
	}
	if (thisdirection=="vertiright") {
		startleft=marginright-thiswidth-marginpadding
		endleft=marginright-thiswidth-marginpadding
		starttop=marginpadding
		endtop=marginbottom-thisheight-2*marginpadding
		stepx=0
		stepy=stepfactor	
	}
	popwindow=window.open(thisurl, "newwindow", "toolbar="+thistoolbar+",location="+thislocation+",directories="+thisdirectories+",status="+thisstatus+",menubar="+thismenubar+",scrollbars="+thisscrollbars+",resizable="+thisresizable+",width="+thiswidth+",height="+thisheight+",top="+starttop+",left="+startleft+"")
	movewindow()
	popwindow.focus()
}

function movewindow() {
	if ((starttop<=endtop) && (startleft<=endleft)){
		popwindow.moveTo(startleft,starttop)
		startleft+=stepx
		starttop+=stepy
		timer=setTimeout("movewindow()",pause)
	}
	else {
		clearTimeout(timer)
		popwindow.moveTo(endleft,endtop)
	}
}

window.onload=openpopup
