//init globals (DON'T TOUCH!)
_movePopWindowTrigger = false;
_popWindowOffsetX = 0;
_popWindowOffsetY = 0;
_lastPopWindowLeft = 0;
_lastPopWindowTop = 0;
 function deleteyav(gelen)
	{
if(document.getElementById(gelen)){
var objm = document.getElementById(gelen);						   
objm.parentNode.removeChild(objm);
}
	}
function popWindow(mypage,w,h,gui){
    //set defaults
    w = w ? w : 400;
    h = h ? h : 250;

	//get or create element...
    if(!document.getElementById('popwindiv')){
        //create div
	    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.display = 'none';
        popwindiv.style.backgroundColor = '#BFD6F9';
        document.getElementsByTagName('body')[0].appendChild(popwindiv);

			popwingui = document.createElement('DIV');
			popwingui.id = 'popwingui';
			popwingui.innerHTML = "<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"1\"><tr><td width=\"90%\" id=\"xtasi\" style=\"cursor:move\"><img src=\"tema/admin/iex.gif\" width=\"15\" height=\"16\" hspace=\"2\" align=\"absmiddle\" />"+gui+"</td><td width=\"10%\" align=\"right\"><img src=\"tema/admin/bosx.gif\" width=\"28\" height=\"15\" hspace=\"2\" border=\"0\"/><a name=\"astr\" style=\"cursor:pointer\"><img src=\"tema/admin/kapatx.gif\" width=\"28\" height=\"15\" border=\"0\" onclick=\"deleteyav('popwindiv');\" title=\"kapat\" /></a></td></tr></table>";
			popwindiv.appendChild(popwingui);
	   //add iframe
	    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{
    	//get elements
	    popwindiv = document.getElementById('popwindiv');
	    popwingui = document.getElementById('popwingui');
	    popwiniframe = document.getElementById('popwiniframe');
    }

    //resize element...
    popwindiv.style.width = w + 'px';
	popwingui.style.width = w + 'px';
    popwindiv.style.height = (h + 24) + 'px';
	popwiniframe.style.width = w + 'px';
	popwiniframe.style.height = h + 'px';

    //position the popup
    if(document.all){
		//patch position for MSIE
		_lastPopWindowTopx = (parseInt((document.body.clientHeight / 2) - (parseInt(popwindiv.style.height) / 2)));
		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';
    	//emulate fixed position. scroll a beraber kayar
     // window.onscroll = window.onresize = _MSIEpositionPopWindow;
    }else{
		//set position other browsers
		popwindiv.style.top = ((window.innerHeight / 2) - (h / 2)) + 'px';
		popwindiv.style.left = ((window.innerWidth / 2) - (w / 2)) + 'px';
		
    }

	//get page
	popwiniframe.src = mypage;

	//add drag and drop functionality.
	document.onmousedown = _movePopWindow;
	document.onmouseup = new Function('_movePopWindowTrigger=false;');

	//show popup
	popwindiv.style.display = '';
}

function _MSIEpositionPopWindow(){
	popwindiv = document.getElementById('popwindiv');
	 popwindiv.style.top =(parseInt(_lastPopWindowTopx) +document.body.scrollTop) + 'px'; 
	// popwindiv.style.top =(100+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 == 'xtasi'){
		//get start mouse position
		_popWindowOffsetX = document.all ? event.clientX : e.clientX;
		_popWindowOffsetY = document.all ? event.clientY : e.clientY;
//get window position
		popwindiv = document.getElementById('popwindiv');
		tempx = parseInt(popwindiv.style.left);
		tempy = parseInt(popwindiv.style.top);
//do movement
		_movePopWindowTrigger = true;
		document.onmousemove = _dragPopWindow;
	}
}

function _dragPopWindow(e){
	if(_movePopWindowTrigger == true){
		//push to new position
		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;
}
