isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;

function ddInit(e){
	if (isIE&&event.srcElement.id=="dragbar"||isNN&&e.target.id=="dragbar"){
		offsetx=isIE? event.clientX : e.clientX
		offsety=isIE? event.clientY : e.clientY
		
		tempx=parseInt(crossobj.style.left)
		tempy=parseInt(crossobj.style.top)
		ddEnabled=true
		document.onmousemove=drag_drop
	}
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body
}

function enlarge(title, which, e, position, imgwidth, imgheight){
	var divOpacity=document.createElement("div")
	divOpacity.setAttribute("id", "divOpacity")
	document.body.appendChild(divOpacity)
	
	var showimage=document.createElement("div")
	showimage.setAttribute("id", "showimage")
	document.body.appendChild(showimage)

	var ifrMask=document.createElement("iframe")
	ifrMask.setAttribute("id", "ifrMask")
	document.body.appendChild(ifrMask)

	if (isIE||isNN){
		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
		opacityobj=document.getElementById? document.getElementById("divOpacity") : document.all.divOpacity
		ifrobj = document.getElementById? document.getElementById("ifrMask") : document.all.ifrMask
		if (position=="center"){
			pgyoffset=isNN? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
			horzpos=isNN? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
			vertpos=isNN? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
			if (window.opera && window.innerHeight) //compensate for Opera toolbar
			vertpos=pgyoffset+window.innerHeight/2-imgheight/2
			vertpos=Math.max(pgyoffset, vertpos)
		}
		else{
			var horzpos=isNN? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
			var vertpos=isNN? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
		}
		//coded by PhongTran
		ifrobj.style.width = document.body.scrollWidth-5;
		ifrobj.style.height = document.body.scrollHeight;
		
		crossobj.style.left=horzpos+"px"
		crossobj.style.top=vertpos+"px"
		ifrobj.style.left="0px"
		ifrobj.style.top="0px"
		var strHTML = '<table border="0" cellpadding="0" style="border-collapse: collapse">'
		strHTML = strHTML + '<tr><td><table border="0" cellpadding="0" style="border-collapse: collapse" width=100%>'
		strHTML = strHTML + '<tr><td id="dragbar">&nbsp;'+title+'</td><td width="20" align="center" id="closetext" onClick="closepreview()"><img alt="Close" border="0" src="images/i_close.gif" width="16" height="16"></td></tr></td></tr></table>'
		strHTML = strHTML + '<tr><td title="Close" onClick="closepreview()"><img src="'+which+'"></td></tr></table>'

		crossobj.innerHTML= strHTML
		crossobj.style.visibility="visible"
		ifrobj.style.display=''
		ifrobj.style.visibility="visible"
		//coded by PhongTran
		opacityobj.style.width = document.body.scrollWidth+"px";
		opacityobj.style.height = document.body.scrollHeight+"px";
		opacityobj.style.visibility="visible";
		document.getElementById("dragbar").onmousedown=ddInit;
		document.getElementById("dragbar").onmouseup=Function("ddEnabled=false");
		
		return false
	}
	else //if NOT IE 4+ or NS 6+, simply display image in full browser window
		return true
}

function closepreview(){ //coded by PhongTran
	opacityobj.style.display="none"
	document.body.removeChild(crossobj)
	document.body.removeChild(ifrobj)
	document.body.removeChild(divOpacity)
}

function drag_drop(e){
	if (isIE&&ddEnabled){
		crossobj.style.left=tempx+event.clientX-offsetx+"px"
		crossobj.style.top=tempy+event.clientY-offsety+"px"
	}
	else if (isNN&&ddEnabled){
		crossobj.style.left=tempx+e.clientX-offsetx+"px"
		crossobj.style.top=tempy+e.clientY-offsety+"px"
	}
	return false
}

