﻿var mask;
var targetLayer;
var s_popupframe="0";
    function $(id){
return document.getElementById(id);
}
function alertwindow()
{
    popup_close();
    openwindow(3,'','/template/aspx/email/emailwindow.aspx?emailstate=2');
}
function openwindow(index,title,url)
{

	 var w=window.screen.width; 
	 //var h=document.body.scrollTop;
	 var h=document.documentElement.scrollTop;
	if(index==1)
	{
		$("divpop").style.background="url('/template/images/tc2.gif') no-repeat";
		$('popupFrame').style.width=350+ 'px';
		$('popupFrame').style.height=250+ 'px';
		$('popupFrame').style.marginLeft=8+ 'px';
		$('popupFrame').style.marginRight=7+ 'px';
		$('popupFrame').style.marginTop=6+ 'px';
		$('popupFrame').style.marginBottom=20+ 'px';
		popup_open(url,title,381,335,100+h,(w-381)/2);
		
	}
	if(index==2)
	{
		$("divpop").style.background="url('/template/images/tanchu.png')";
		$('popupFrame').style.width=252+ 'px';
		$('popupFrame').style.height=340+ 'px';
		$('popupFrame').style.marginLeft=9+ 'px';
		$('popupFrame').style.marginRight=7+ 'px';
		$('popupFrame').style.marginTop=5+ 'px';
		$('popupFrame').style.marginBottom=20+ 'px';
		popup_open(url,title,280,430,150+h,(w-280)/2);
	}
	if(index==3)
	{
		$("divpop").style.background="url('/template/images/tc5.gif')";
		$('popupFrame').style.width=260+ 'px';
		$('popupFrame').style.height=120+ 'px';
		$('popupFrame').style.marginLeft=40+ 'px';
		$('popupFrame').style.marginRight=7+ 'px';
		$('popupFrame').style.marginTop=10+ 'px';
		$('popupFrame').style.marginBottom=20+ 'px';
		popup_open(url,title,317,213,300+h,(w-236)/2);
		
		
	}
	if(index==4)
	{
		$("divpop").style.background="url('/template/images/tc4.gif') no-repeat";
		$('popupFrame').style.width=256+ 'px';
		$('popupFrame').style.height=190+ 'px';
		$('popupFrame').style.marginLeft=0+ 'px';
		$('popupFrame').style.marginRight=0+ 'px';
		$('popupFrame').style.marginTop=0+ 'px';
		$('popupFrame').style.marginBottom=20+ 'px';
		popup_open(url,title,256,190,200+h,(w-236)/2);
	}
	$("img").className="img"+index;

}
function popup_open(url, title,width,height,top,left){

  s_popupframe="0";
	$('popup_title').innerHTML = title;
	$('popupFrame').src = url;
	$('divpop').style.width=(width)+"px";

    $("divpop").style.height=height-10+ 'px';
	$('popupFrame').style.display = '';
	targetLayer = 'divpop';
	$(targetLayer).style.display = '';
	
	if(typeof(top)!="undefined")
	{
		$(targetLayer).style.left=left+ 'px';
		$(targetLayer).style.top=top+ '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';
	
	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 = top + '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(){
	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("<div id=\"divpop\" style=\"position: absolute; z-index: 300;display:none;background-repeat:no-repeat;\">\r\n    <h5 style=\"cursor: move;\" onmousedown=\"initdrag(this.parentNode, event)\" >\r\n  <a id='img' onclick=\"popup_close()\"   border=\"0\" style=\"cursor:pointer;text-decoration:none;border:none;display:block;width:27px;Height:20px;\"   /></a>\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\"  allowtransparency=\"true\"></iframe>\r\n    </div>\r\n</div>") 

}

initializePop();
