﻿
var mask;
var targetLayer;

function popup_open(url, title,width,height,top){
	/*
    with(window.frames["popupFrame"].document.body){
        innerHTML = '<table align="center" height="170"><tr><td valign=center style="font-size:12px;"><img src="' + (location.href.replace(/\/[^\/]*$/, '/')) + 'img/ajax-loader.gif" align="absmiddle" /> 读取中…</td></tr></table>';
        style.backgroundColor = '#FFF6D4';
    }
  */
    
	$('popup_title').innerHTML = title;
	$('popupFrame').src = url;
	$('divpop').style.width=(width+45)+"px";
	$('popupFrame').style.width=width+ 'px';
  $('popupFrame').style.height=height+ 'px';
	
	mask = document.createElement('DIV');
	mask.style.cssText = 'position:absolute; background-color:#ff0; display:inline; filter:alpha(opacity=40);-moz-opacity:.40;opacity:.40; top:0; left:0; width:100%; height:100%;' + (document.body.scrollHeight + 19) + 'px;';
	mask.innerHTML = '&nbsp;';
	document.body.appendChild(mask);
	var sh = document.body.scrollHeight || document.documentElement.scrollHeight;
	if(sh >= mask.clientHeight)
		mask.style.height = (sh + 0) + 'px';
	mask.style.backgroundColor = '#333';
	targetLayer = 'divpop';
	$(targetLayer).style.display = '';
	moveToCenter(top);
	
	DisplaySelect(0);
	
}

function DisplaySelect(i_sel)
{
	var selsobj = document.getElementsByTagName("SELECT");
	for(i=0;i<selsobj.length;i++)
	{
		if(i_sel==0)
		{
			selsobj[i].style.visibility ="hidden";
		}
		else
		{
			selsobj[i].style.visibility ="visible";
		}
	}	
}

var o_select=new Array();
function popup_close()
{
	DisplaySelect(1);
	$(targetLayer).style.display = 'none';
	
	if(mask)
		mask.parentNode.removeChild(mask);
	mask = null;
	window.open("/common/noframe.html","popupFrame");
}

function moveToCenter(i_top){
	var ttop=document.documentElement.scrollTop;
	if(typeof(i_top)=="undefined")
	{
			
		//居中
		if(document.documentElement.clientHeight>$('divpop').offsetHeight)
		{
			ttop+=(document.documentElement.clientHeight-$('divpop').offsetHeight)/2;
		}
		else
			{
				ttop+=0;
			}
	}	
	else
		ttop+=i_top;	
	
	
	
	$(targetLayer).style.left = ((document.body.clientWidth - $(targetLayer).clientWidth) /2) + 'px';
	$(targetLayer).style.top = ttop + 'px';
}

var cObj, sdX, sdY;
function initdrag(obj){
		if(arguments.length>1)
			try{event = arguments[1];}catch(e){}
		cObj = obj
		sdX = parseInt(obj.style.left)-event.clientX;
		sdY = parseInt(obj.style.top)-event.clientY;
	if(document.body.setCapture)document.body.setCapture();
	else if(window.captureEvents)window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
function startdrag(){
		if(arguments.length>0)	event = arguments[0];
		if (!cObj)	return;
		cObj.style.left=(sdX+event.clientX) + 'px';
		cObj.style.top=(sdY+event.clientY) + 'px';
}
function enddrag(){
		cObj=null;
	if(document.releaseCapture)document.releaseCapture();
	else if(window.releaseEvents)window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
