var ns4=document.layers
var ie4=document.all
var ns6=document.getElementById&&!document.all

var dragswitch=0
var nsx
var nsy
var nstemp

//var showimage[i]
//i=1
//i=2

function drag_dropns(name){
if (!ns4)
return
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
if (dragswitch==1){
debugger;
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

function drag_drop(e){
if (ie4&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx+"px"
crossobj.style.top=tempy+event.clientY-offsety+"px"
showIframe(document.getElementById('showimage'),true)

return false
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
showIframe(document.getElementById('showimage'),true)

return false
}
}

function initializedrag(e){
event.srcElement.runtimeStyle.cursor = "move";
crossobj=ns6? document.getElementById("showimage") : document.all.showimage
var firedobj=ns6? e.target : event.srcElement
var topelement=ns6? "html" : document.compatMode && document.compatMode!="BackCompat"? "documentElement" : "body"
while (firedobj.tagName!=topelement.toUpperCase() && firedobj.id!="dragbar"){
firedobj=ns6? firedobj.parentNode : firedobj.parentElement
}

if (firedobj.id=="dragbar"){
offsetx=ie4? event.clientX : e.clientX
offsety=ie4? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left) 
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}
document.onmouseup=new Function("dragapproved=false")
document.onmouseout=new Function("dragapproved=false")

////drag drop functions end here//////

function hidebox(){
document.getElementById("showimage").style.left='200px'
document.getElementById("showimage").style.top='180px'
document.getElementById("showimage").style.display='none'
showIframe(document.getElementById("showimage"),false)

if (showimageCloseEvent!=null&&typeof(showimageCloseEvent)!="undefined")
	eval(showimageCloseEvent)

}

function openbox(showTitle,OpenWin){
//採用iframe方式，指定src開啟視窗
//showimage:固定，不改

//winTitle:視窗標題
//OpenWin:要開啟之視窗位址

//============= DIV位置 ==============================================
	var ph=document.getElementById("showimage").parentElement.offsetHeight;
	var pw=document.getElementById("showimage").parentElement.offsetWidth;
	//水平間距
	var cw=(pw-cusw)/2;
	if (cw<=0){	cw=0 }
	document.getElementById("showimage").style.cssText="DISPLAY: block; Z-INDEX: 99; LEFT: 10px; WIDTH: 100px; POSITION: absolute; TOP:10px;LEFT:"+cw+";"
//====================================================================
	

document.getElementById('dragbar').style.cursor="move";
document.getElementById('winTitle').innerHTML=showTitle;
document.getElementById("showimage").style.display='block'
 document.getElementById("OpenIm").src=OpenWin;
showIframe(document.getElementById("showimage"),true)
}

function openboxCustom(showTitle,OpenWin,cusw,cush)
{
	openboxCustom(showTitle,OpenWin,cusw,cush,null)	

}

function openboxCustom(showTitle,OpenWin,cusw,cush,closeEvent)
{
	//============= DIV位置 ==============================================
	var ph=document.getElementById("showimage").parentElement.offsetHeight;
	var pw=document.getElementById("showimage").parentElement.offsetWidth;
	//水平間距
	var cw=(pw-cusw)/2;
	if (cw<=0){	cw=0 }
	document.getElementById("showimage").style.cssText="DISPLAY: block; Z-INDEX: 99; LEFT: 80px; WIDTH: 100px; POSITION: absolute; TOP:20px;LEFT:"+cw+";"
	//====================================================================
	
	document.getElementById('dragbar').style.cursor="move";
	document.getElementById('winTitle').innerHTML=showTitle;
	document.getElementById("showimage").style.display='block'
	document.getElementById("OpenIm").src=OpenWin;
	document.getElementById("OpenIm").width=cusw;
	document.getElementById("OpenIm").height=cush;
	showIframe(document.getElementById("showimage"),true);
	
	
	if (closeEvent!=null && typeof(closeEvent)!="undefined")
		showimageCloseEvent = closeEvent;
	else
		showimageCloseEvent = null;
}



