// JavaScript Document
var iens6=document.all||document.getElementById;
var intervalLightFade;
var widthComplete=false;
var heightComplete=false;
var resultText;

function ietruebody()
{
  return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
function fadeLight()
{
    var windowPositionFromTop;
	var windowPositionFromLeft;
    var winWidth;
    var winHeight;
    var topPosition;
	var leftPosition;
    var theObj;
	
	theObj=document.getElementById?document.getElementById("overlay"):document.all.overlay;
	if(iens6&&document.all) // ini adalah IE
	{
	  windowPositionFromTop=!window.opera? ietruebody().clientHeight : document.body.clientHeight;
  	  windowPositionFromLeft=!window.opera? ietruebody().clientWidth : document.body.clientWidth;
	  winWidth=ietruebody().clientWidth;
	  winHeight=ietruebody().clientHeight;
	  topPosition=ietruebody().scrollTop+windowPositionFromTop;
	  leftPosition=ietruebody().scrollLeft+windowPositionFromLeft;
	  theObj.style.filter="alpha(opacity=60)";
	}
	if(iens6&&!document.all) // ini adalah FF
	{
	  windowPositionFromTop=window.innerHeight;
	  windowPositionFromLeft=window.innerWidth;
	  winWidth=ietruebody().offsetWidth;
	  winHeight=ietruebody().offsetHeight;
	  topPosition=window.pageYOffset+windowPositionFromTop;
	  leftPosition=window.scrollLeft+windowPositionFromLeft;
   	  winHeight=ietruebody().scrollHeight;
   	  //winWidth=ietruebody().scrollWidth;	  
	}
	//alert(winWidth);
	winWidth=(ietruebody().scrollLeft+winWidth);
	theObj.style.width=(winWidth)+"px";
	//theObj.style.height=winHeight+"px";
	theObj.style.height=document.body.parentNode.scrollHeight+"px";
	//theObj.style.top=(topPosition-winHeight)+"px";
	//theObj.style.left=(leftPosition-winWidth)+"px";
	//theObj.style.top="0px";
	theObj.style.display="block";
	intervalLightFade=setTimeout("fadeLight()",0);
}

function getPageSize()
{
    var windowPositionFromTop;
	var windowPositionFromLeft;
    var winWidth;
    var winHeight;
    var topPosition;
	var leftPosition;
    var theObj;
	
	if(iens6&&document.all) // ini adalah IE
	{
	  windowPositionFromTop=!window.opera? ietruebody().clientHeight : document.body.clientHeight;
  	  windowPositionFromLeft=!window.opera? ietruebody().clientWidth : document.body.clientWidth;
	  winWidth=ietruebody().clientWidth;
	  winHeight=ietruebody().clientHeight;
	  topPosition=ietruebody().scrollTop+windowPositionFromTop;
	  leftPosition=ietruebody().scrollLeft+windowPositionFromLeft;
	}
	if(iens6&&!document.all) // ini adalah FF
	{
	  windowPositionFromTop=window.innerHeight;
	  windowPositionFromLeft=window.innerWidth;
	  winWidth=ietruebody().offsetWidth;
	  winHeight=ietruebody().offsetHeight;
	  topPosition=window.pageYOffset+windowPositionFromTop;
	  leftPosition=window.scrollLeft+windowPositionFromLeft;
   	  winHeight=ietruebody().scrollHeight;
   	  //winWidth=ietruebody().scrollWidth;	  
	}
	winWidth=(ietruebody().scrollLeft+winWidth);
	var arrayPageSize=new Array(winWidth,winHeight);
	return arrayPageSize;
}

function startLight(path)
{
	fadeLight();
	var mvibox=document.getElementById("mvibox");
	var innermvi=document.getElementById("innermvibox");
	mvibox.onclick=function()
	{
		//endmvilight();
	};
	//innermvi.onclick=function()
	//{
		//endmvilight();
	//};
	var req=AJAXXMLHttp.createRequest();
	req.open("post",path,true);
	req.onreadystatechange=function()
	{
		req.onreadystatechange=function()
		{
			if(req.readyState==4)
			{
				if(req.status==200||req.status==304)
				{
					var rObj=req.responseText;
					resultText=rObj;
					var objBody = document.getElementsByTagName("body").item(0);
					var tObj=document.createElement("div");
					tObj.setAttribute('id','tt');
					tObj.style.visibility = 'hidden';
					tObj.style.position='absolute';
					objBody.appendChild(tObj);
					var t=document.getElementById("tt");
					t.innerHTML=rObj;
					var tWidth=t.offsetWidth;
					var tHeight=t.offsetHeight;
					objBody.removeChild(tObj);
					window.scrollTo(0,0);
					
					var arrPageSize=getPageSize();
					//mvibox.style.left=mviLeft+"px";
					mvibox.style.width=tWidth+"100px";
					mvibox.style.height="50px";
					mvibox.style.visibility='visible';
					innermvi.innerHTML='';
					innermvi.style.height='0px';
					innermvi.style.width="0px";
					//innermvi.style.widtht='60px';
					innermvi.style.display='block';
					mvibox.style.display="block";

					
					mvibox.style.width=tWidth+"px";
					mvibox.style.left=((getPageSize()[0]-mvibox.offsetWidth)/2)+"px";
					resize_mvibox(tWidth,tHeight);
				}else
				{
					resultText='';
					endmvilight();
				}
			}else
			{
				// still loading
			}
		}
	}
	req.send('data');
}

function resize_mvibox(boxWidth,boxHeight)
{
	  widthComplete=false;
	  heightComplete=false;
	  resizeWidth(boxWidth,boxHeight);
}

function resizeWidth(boxWidth, boxHeight)
{
	var mvibox=document.getElementById("mvibox");
	if((mvibox.offsetWidth)>=boxWidth)
	{
		widthComplete=true;
		resizeHeight(boxWidth,boxHeight);
		return;
	}
	if((boxWidth-mvibox.offsetWidth)<20)
	{
		mvibox.style.width=(mvibox.offsetWidth+(boxWidth-mvibox.offsetWidth))+"px";
	}else
	{
		mvibox.style.width=(mvibox.offsetWidth+20)+"px";
	}
	mvibox.style.left=((getPageSize()[0]-mvibox.offsetWidth)/2)+"px";
	setTimeout("resizeWidth("+boxWidth+","+boxHeight+");",0);
}
function resizeHeight(boxWidth, boxHeight)
{
	var mvibox=document.getElementById("mvibox");
	//var innerbox=document.getElementById("innermvibox");
	if((mvibox.offsetHeight)>=boxHeight)
	{
		heightComplete=true;
		pageComplete();
		return;
	}
	if((boxHeight-mvibox.offsetHeight)<20)
	{
		mvibox.style.height=(mvibox.offsetHeight+(boxHeight-mvibox.offsetHeight))+"px";
	}else
	{
		mvibox.style.height=(mvibox.offsetHeight+20)+"px";
	}
	setTimeout("resizeHeight("+boxWidth+","+boxHeight+");",0);
}
function pageComplete()
{
	var innerbox=document.getElementById("innermvibox");
	innerbox.innerHTML=resultText;
	correctPNG();
}
function endmvilight()
{
	var mvibox=document.getElementById("mvibox");
	//var innermvibox=document.getElementById("innermvibox");
	//mvibox.style.width='100px'
	mvibox.style.height='50px'
	//innermvibox.style.width='0px';
	//innermvibox.style.height='0px';	
	mvibox.style.display="none";
	//innermvibox.style.display="none";
	endFade();
}
function endFade()
{
	clearTimeout(intervalLightFade);
	var overlay=document.getElementById("overlay");
	overlay.style.height='0px';
	overlay.style.width='0px';
	overlay.style.display="none";
}

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}
