
var mask;
var targetLayer;
var s_popupframe="0";
function popup_open(url, title,width,height,top,left){

  s_popupframe="0";
	$('popup_title').innerHTML = title;
	$('popupFrame').src = url;
	$('divpop').style.width=(width+45)+"px";
	$('popupFrame').style.width=width+ 'px';
  $('popupFrame').style.height=height+ 'px';
	
	$('frepopup').style.display = '';
	$('frepopup').style.width=(width+45)+"px";
	$('frepopup').style.height=(height+90)+ 'px';
	
	
	targetLayer = 'divpop';
	$(targetLayer).style.display = '';
	
	if(typeof(top)!="undefined")
	{
		$(targetLayer).style.left=left+ 'px';
		$(targetLayer).style.top=top+ 'px';
		
		$('frepopup').style.left=left+ 'px';
		$('frepopup').style.top=(top+25)+ 'px';
	}	
	else
	{
		moveToCenter(top);
	}	
	
	if(typeof(OpenPopup)=="function")
	{
		OpenPopup();
		
	}
	
	if(typeof(ShowBackground)=="function")
	{
		ShowBackground();
	}
	
	//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';
	$('frepopup').style.display = 'none';
	if(mask)
		mask.parentNode.removeChild(mask);
		
	mask = null;
	
	if(s_popupframe=="0")
	{
		
		window.open("/common/noframe.html","popupFrame");
	}

	
	if(typeof(ClosePopup)=="function")
	{
		ClosePopup();
	}
	
	if(typeof(HideBackground)=="function")
	{
		HideBackground();
		
	}
}

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;	
	
	var i_left=((document.body.clientWidth - $(targetLayer).clientWidth) /2) + 'px';
	
	$(targetLayer).style.left = i_left;
	$(targetLayer).style.top = ttop + 'px';
	
	$('frepopup').style.left = i_left;
	$('frepopup').style.top = (ttop+25) + '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';
		
	$('frepopup').style.left = (sdX+event.clientX) + 'px';
	$('frepopup').style.top =(sdY+event.clientY+25) + 'px';
}


function enddrag(){
	if(cObj!=null)
	{
		cObj=null;
		if(document.releaseCapture)document.releaseCapture();
		else if(window.releaseEvents)window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
	}
}



function initializePop()
{
	document.onmousemove=startdrag;
	document.onmouseup=enddrag;
	document.write("<iframe id=\"frepopup\" style=\"position:absolute;z-index:1;top:10px;left:10px;display:none;\" frameborder=\"0\"></iframe><div id=\"divpop\" style=\"position: absolute; z-index: 3; background-color: #fff;display:none;\">\r\n    <h5 style=\"cursor: move;\" onmousedown=\"initdrag(this.parentNode, event)\" >\r\n                    <img onclick=\"popup_close()\" src=\"/images/close.gif\"  border=\"0\" style=\"cursor:hand;\"  />\r\n            <span id=\"popup_title\"></span>\r\n            </h5>\r\n    <div class=\"text\">\r\n        <iframe id=\"popupFrame\" name=\"popupFrame\" src=\"\" scrolling=\"no\" frameborder=\"0\" height=\"200\" width=\"538\"\r\n           allowtransparency=\"true\"></iframe>\r\n    </div>\r\n</div>") 

}

initializePop();