/* my own lightbox solution 
*/

function showBox(objID, showImage, hideContent) {
	//
	var content = $(objID);
	var overlay = $('overlay');
	
	
	rePosMe(content);
	centerMe(content);
	
	if (showImage) {
		theImg = $(showImage);
		if(theImg) {
			theImg.style.display="block";
		} else {
//			var imgString = "<img src=\"/code/common/ctltLightBox/images/waiting.gif\" border=\"0\" id=\"waitingImg\" />";
//			content.innerHTML = imgString+"<br>"+content.innerHTML;
			var waitingImg = document.createElement('IMG');
			var breaker = document.createElement('div');
			breaker.id = "waitingImg";
			breaker.style.width = "auto";
			breaker.style.marginTop = "10px";
			//waitingImg.src = "/code/common/ctltLightBox/images/waiting.gif";
			waitingImg.src = showImage;
			waitingImg.border = 0;
			waitingImg.alt = "waiting";
			breaker.zIndex = 902;
			content.insertBefore(breaker, content.firstChild);
			breaker.appendChild(waitingImg);
			//alert(waitingImg.src);
			//breaker.innerHTML ="<IMG SRC =\""+showImage+"\" border=0 alt=\"waiting\" />";
		}
	}
		
	
	
	if(overlay) {
		fullsizeMe(overlay);

	} else {
		createOverlay(content);
		overlay =$('overlay');
	}
	
	//followWindow(objID);	
	window.onresize = function() {
		centerMe(content);
		fullsizeMe(overlay);
	}
	window.onscroll = function() {
		centerMe(content);
		fullsizeMe(overlay);
	}	
	
	hideSelectBoxes();

}

function centerMe(theObj) {;
	var oWidth;
	var oHeight;
	var oTop;
	var oLeft;
	var bleh;
	if (self.innerHeight) {// all except Explorer
		oHeight = self.innerHeight;
		oWidth = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		oHeight = document.documentElement.clientHeight;
		oWidth = document.documentElement.clientWidth;
	}
	else if (document.body) { // other Explorers 	
		oHeight = document.body.clientHeight;
		oWidth = document.body.clientWidth;
	}
	
	if (document.documentElement && document.documentElement.scrollTop) {
		oTop = document.documentElement.scrollTop;
		oLeft = document.documentElement.scrollLeft;
	} else {
		oTop = document.body.scrollTop; 
		oLeft = document.body.scrollLeft;
	}
	if(theObj.offsetHeight && theObj.offsetWidth) {
	theObj.style.top=(oHeight/2 - theObj.offsetHeight/2+oTop) + "px";
	theObj.style.left=(oWidth/2 -theObj.offsetWidth/2+oLeft*1) + "px";
	//parentWin.window.status= oWidth/2+":"+theObj.offsetWidth/2+":"+oLeft+":"+ (oWidth/2 +theObj.offsetWidth/2+oLeft*1);	
	}
}


function hideBox(objID) {
	var theObj = $(objID);
	if(theObj) {
		theObj.style.display="none";
	}
	
	var theImg = $('waitingImg');
	if(theImg) {
		theImg.style.display="none";	
	}
	
	var overlay= $('overlay');
	if(overlay) {
		overlay.style.display = "none";	
		
	}
	
	window.onresize = function() {
	}
	window.onscroll = function() {
	}		
	
	//show select boxes
	showSelectBoxes();
}

function followWindow(objID) {
	var overlay = $('overlay');
	var theObj = $(objID);
	var theObjT, theObjL, overlayT, overlayL;
	if(overlay && theObj) {
		var posX;
		var posY;
		if (document.documentElement && document.documentElement.scrollTop) {
			posY = document.documentElement.scrollTop;
			posX = document.documentElement.scrollLeft;
		} else {
			posY = document.body.scrollTop; 
			posX = document.body.scrollLeft;
		}


		var winX,winY;
		if (self.innerHeight) // all except Explorer
		{
			winX = self.innerWidth;
			winY = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
			// Explorer 6 Strict Mode
		{
			winX = document.documentElement.clientWidth;
			winY = document.documentElement.clientHeight;
		}
		else if (document.body) // other Explorers
		{
			winX = document.body.clientWidth;
			winY = document.body.clientHeight;
		}	
		

		
		
		
		theObjL = (theObj.style.width.replace("px", ""))/2;
		theObjT = (theObj.style.height.replace("px", ""))/2;
		overlayL = (overlay.style.width.replace("px", ""))/2;
		overlayT = (overlay.style.height.replace("px", ""))/2;
		theObj.style.top = posY+(winY/2)-theObjT+"px";
		theObj.style.left = posX+(winX/2)-theObjL+"px";
		//overlay.style.top = posY+(winY/2)-overlayT;
//		overlay.style.left = posX+(winX/2)-overlayL;
		//overlay.style.top = posY;
		//overlay.style.left = posX;
		//window.status=overlay.style.top+","+overlay.style.left;
		fullsizeMe(overlay);
		
	}
	
	
	
}

function findMainParent(windowObj) {
	var counter = 0;
	var thisWindow = windowObj;
	var parentWindow = windowObj.parent;
	var tempVar;
	
	while(parentWindow != thisWindow) {
		thisWindow = parentWindow;
		parentWindow = thisWindow.parent;
		counter ++
	
	}
	
	return parentWindow;
}



function rePosMe(content) {
		var offsetW;
		var offsetH;
		content.style.display = "block";
		//if there are no width/height set on this div, force the div to have a 200x200 dimension, then set it.
		if(!content.style.width || !content.style.height) {
			content.style.position = "absolute";
			//content.style.margin = "-100px 0px 0px -100px";
			//content.style.marginTop = "-100";
			content.style.width = "600px";
			content.style.height = "600px";
			offsetW = 100;
			offsetH = 100;
			content.style.zIndex="999";
		} else {
			content.style.position = "absolute";
			var contentWidth = content.style.width.replace("px", "");
			var contentHeight = content.style.height.replace("px", "");
			offsetW = contentWidth/2;
			offsetH = contentHeight/2;
			content.style.zIndex="999";
		}
		content.style.textAlign = "center";
		centerMe(content);

}



function createOverlay(theObj) {
	var overlay  = document.createElement('div');
	var mainBody = document.getElementsByTagName('body')[0];
	overlay.className = "overlay";
	overlay.id = "overlay";
	overlay.style.zIndex = theObj.style.zIndex-1;
	mainBody.appendChild(overlay);
	fullsizeMe(overlay);
}



function fullsizeMe(theObj) {
	var winW;
	var winH;
	var hPos;
	var vPos;
	var docH;
	var docW;
	
	if (self.innerHeight) // all except Explorer
	{
		if (document.documentElement.scrollHeight > self.innerHeight) {
			docH = document.documentElement.scrollHeight;
		} else {
			docH = self.innerHeight;
		}
		if (document.documentElement.scrollWidth < self.innerWidth) {
			docW = document.documentElement.scrollWidth;
		} else {
			docW = self.innerWidth;
		}		
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		docH = document.documentElement.clientHeight;
		docW = document.documentElement.clientWidth;
	}
	else if (document.body) // other Explorers
	{
		docH = document.body.clientHeight;
		docW = document.body.clientWidth;
	}
	var posX;
	var posY;
	if (document.documentElement && document.documentElement.scrollTop) {
		posY = document.documentElement.scrollTop;
		posX = document.documentElement.scrollLeft;
	} else {
		posY = document.body.scrollTop; 
		posX = document.body.scrollLeft;
	}

	
	if (theObj) {
		
		theObj.style.display="block";
		theObj.style.width = docW+"px";
		theObj.style.height = docH+"px";
		//theObj.style.left = posX+"px";
		//theObj.style.top = posY+"px";
		theObj.style.left = posX+"px";
		if(self.innerHeight) {
			theObj.style.top = 0;
		} else {
			theObj.style.top = posY+"px";
		}
	}
}
	
function showSelectBoxes(){
	selects = document.getElementsByTagName("SELECT");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "";
	}
	checkFrames(window, "");
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
	checkFrames(window, "hidden");
}

function checkFrames(documentObj, state) {
	framesA = documentObj.frames;
	if(framesA.length > 0){
		for(i=0;i<framesA.length;i++) {
			framedDoc = framesA[i].document;
			framedDocSelects = framedDoc.getElementsByTagName("select");
			for(j=0;j<framedDocSelects.length;j++) {
			//	alert(framedDocSelects[j].style);
			//	framedDocSelects[j].style.visibility = "none";
			//	framedDocSelects[j].style.display = state;
				framedDocSelects[j].style.visibility = state;
			}
		checkFrames(framesA[i], state);	
		}
	}
	
}
	
