var popwindow
var tisurl
var tiswidth
var tisheight
var thismargin=10
var tistopposition=thismargin
var tisleftposition=thismargin
var pause=20
var step=20
var screenwidth
var screenheight
var endposition_x
var endposition_y
var timer

function openpopup(thisurl,thiswidth,thisheight) {
	tisurl=thisurl
	tiswidth=thiswidth
	tisheight=thisheight

	popwindow=window.open(tisurl, "newwindow", "toolbar=no,width="+tiswidth+",height="+tisheight+",top="+tistopposition+",left="+(tisleftposition)+"");

	screenwidth=window.screen.width
	screenheight=window.screen.height
	endposition_x=screenwidth-thiswidth-thismargin
	endposition_y=screenheight-thisheight-thismargin
	movedown()
}

function movedown() {
	if (tistopposition<=endposition_y-50) {
		popwindow.moveTo(tisleftposition,tistopposition)
		tistopposition+=step
		timer= setTimeout("movedown()",pause)
	}
	else {
		clearTimeout(timer)
		tistopposition=endposition_y-50
		popwindow.moveTo(tisleftposition,tistopposition)
		moveright()
	}
}

function moveright() {
	if (tisleftposition<=endposition_x) {
		popwindow.moveTo(tisleftposition,tistopposition)
		tisleftposition+=step
		timer= setTimeout("moveright()",pause)
	}
	else {
		clearTimeout(timer)
		tisleftposition=endposition_x
		popwindow.moveTo(tisleftposition,tistopposition)
		moveup()
	}
}

function moveup() {
	if (tistopposition>=thismargin) {
		popwindow.moveTo(tisleftposition,tistopposition)
		tistopposition-=step
		timer= setTimeout("moveup()",pause)
	}
	else {
		clearTimeout(timer)
		tistopposition=thismargin
		popwindow.moveTo(tisleftposition,tistopposition)
		moveleft()
	}
}

function moveleft() {
	if (tisleftposition>=thismargin) {
		popwindow.moveTo(tisleftposition,tistopposition)
		tisleftposition-=step
		timer= setTimeout("moveleft()",pause)
	}
	else {
		clearTimeout(timer)
		tisleftposition=thismargin
		popwindow.moveTo(tisleftposition,tistopposition)
	}
}