_movePopWindowTrigger = false;
_popWindowOffsetX = 0;
_popWindowOffsetY = 0;
_lastPopWindowLeft = 0;
_lastPopWindowTop = 0;
function popWindow(mypage,w,h,gui){
    w = w ? w : 200;
    h = h ? h : 150;
    if(!document.getElementById('popwindiv')){
	    popwindiv = document.createElement('DIV');
	    popwindiv.id = 'popwindiv';
    	popwindiv.style.position = document.all ? 'absolute' : 'fixed'; //fixed position for MSIE is patched!
	    popwindiv.style.zIndex = 1000000;
	    popwindiv.style.visibility = 'hidden';
        popwindiv.style.backgroundColor = '#000000';
        document.getElementsByTagName('body')[0].appendChild(popwindiv);
		if(gui !== false){
			popwingui = document.createElement('DIV');
			popwingui.id = 'popwingui';
			popwingui.style.textAlign = 'right';
			popwingui.innerHTML = "<a href=\"javascript:void(0);\" onclick=\"javascript:document.getElementById('popwindiv').style.visibility='hidden';\" style=\"text-decoration:none;color:#707070;background-color:#cccccc;border:2px outset #c0c0c0;font-size:10px;font-family:arial;\">Pencereyi Kapat (X)</a>";
			popwindiv.appendChild(popwingui);
		}
	    popwiniframe = document.createElement('IFRAME');
		popwiniframe.id = 'popwiniframe';
		popwiniframe.name = 'popwin';
		popwiniframe.frameBorder = 0;
		if(document.all){
		    popwiniframe.onmouseover = function(){_movePopWindowTrigger=false;};
		}else{
			popwiniframe.setAttribute('onmouseover','_movePopWindowTrigger=false;');
		}
		popwindiv.appendChild(popwiniframe);
    }else{
	    popwindiv = document.getElementById('popwindiv');
	    popwingui = document.getElementById('popwingui');
	    popwiniframe = document.getElementById('popwiniframe');
    }
	ext = mypage.substring(mypage.lastIndexOf('.') + 1);
	if(ext == 'gif' || ext == 'png' || ext == 'jpg' || ext == 'jpeg'){
		popwiniframe.setAttribute('marginWidth','0');
		popwiniframe.setAttribute('marginHeight','0');
	}else{
		popwiniframe.setAttribute('marginWidth','10');
		popwiniframe.setAttribute('marginHeight','10');
	}
    popwindiv.style.width = w + 'px';
    popwindiv.style.height = (h + parseInt(popwingui.offsetHeight)) + 'px';
	popwiniframe.style.width = w + 'px';
	popwiniframe.style.height = h + 'px';
    if(document.all){
		popwindiv.style.top = _lastPopWindowTop = (parseInt((document.body.clientHeight / 2) - (parseInt(popwindiv.style.height) / 2)) + document.body.scrollTop) + 'px';
		popwindiv.style.left = _lastPopWindowLeft = (parseInt((document.body.clientWidth / 2) - (parseInt(popwindiv.style.width) / 2)) + document.body.scrollLeft) + 'px';
        window.onscroll = window.onresize = _MSIEpositionPopWindow;
    }else{
		popwindiv.style.top = ((window.innerHeight / 2) - (h / 2)) + 'px';
		popwindiv.style.left = ((window.innerWidth / 2) - (w / 2)) + 'px';
    }
	popwiniframe.src = mypage;
	document.onmousedown = _movePopWindow;
	document.onmouseup = new Function('_movePopWindowTrigger=false;');
	popwindiv.style.visibility = '';
}
function _MSIEpositionPopWindow(){
	popwindiv = document.getElementById('popwindiv');
	popwindiv.style.top = (parseInt(_lastPopWindowTop) + document.body.scrollTop) + 'px';
	popwindiv.style.left = (parseInt(_lastPopWindowLeft) + document.body.scrollLeft) + 'px';
}
function _movePopWindow(e){
	bar = document.all ? event.srcElement.id : e.target.id;
	if(bar == 'popwingui'){
		_popWindowOffsetX = document.all ? event.clientX : e.clientX;
		_popWindowOffsetY = document.all ? event.clientY : e.clientY;
		popwindiv = document.getElementById('popwindiv');
		tempx = parseInt(popwindiv.style.left);
		tempy = parseInt(popwindiv.style.top);
		_movePopWindowTrigger = true;
		document.onmousemove = _dragPopWindow;
	}
}
function _dragPopWindow(e){
	if(_movePopWindowTrigger == true){
		popwindiv = document.getElementById('popwindiv');
		if(document.all){
			popwindiv.style.left = _lastPopWindowLeft = (tempx + (event.clientX - _popWindowOffsetX)) + 'px';
			popwindiv.style.top = _lastPopWindowTop = (tempy + (event.clientY - _popWindowOffsetY)) + 'px';
		}else{
			popwindiv.style.left = _lastPopWindowLeft = (tempx + (e.clientX - _popWindowOffsetX)) + 'px';
			popwindiv.style.top = _lastPopWindowTop = (tempy + (e.clientY - _popWindowOffsetY)) + 'px';
		}
	}
	return false;
}