/********************************************************************************
Copyright (C)  2001-2003 Datarroba
All rights reserved. Unauthorized usage, reproduction, modification and
distribution of this software is strictly prohibited.
Company....: Datarroba - Consultoria Informática, Lda.
Author.....: Paulo Matos
File.......: utilGUI.js
Version....: 3.1
Description: Functions for interface facilities
********************************************************************************/

/***************  ONLOAD FUNCTIONS  **************/
var imgObjsOver	= new Array();
var imgOverIdx	= 0;
var lastBtnPressed;
var outsetStr = "#FFFFFF #000000 #000000 #FFFFFF";
var insetStr  = "#000000 #FFFFFF #FFFFFF #000000";

/***************  DIV INTERACTION  ***************/
var divExtName	= "divExt";
var imgExtName	= "imgExt";
var divPopName	= "divPop";
var imgExtend	= "../images/btn_extend.gif";
var imgReduce	= "../images/btn_reduce.gif";
var btnExt	= "<a style='position: relative; top: 3;' href='javascript:' onclick='expandList(true);' onfocus='blur();'><img id='" + imgExtName + "' width='9' height='9' border='0' src='" + imgExtend + "' style='margin-left: 2px;'></a><br>";


/**************************************************
 *		x PROPERTIES
 **************************************************/

// myObj é do tipo Image Object ou Input Object (button ou image)
function getXImgMouseOver(myObj) {
	return (myObj.getAttribute("xImgMouseOver") != null);
}

// myObj é do tipo Image Object ou Input Object (button ou image)
function getXImgClick(myObj) {
	return myObj.getAttribute("xImgClick");
}

// myObj é do tipo Image Object ou Input Object (button ou image)
function getXImgEventIdx(myObj) {
	return myObj.getAttribute("xImgEventIdx");
}

// myObj é do tipo Image Object ou Input Object (button ou image)
function getXImgEventsObjs(myObj) {
	if(myObj.getAttribute("xImgEventsObjs") != null)
		return myObj.getAttribute("xImgEventsObjs").split(",");
	else
		return [];
}

// myObj é do tipo Button Object
function getXBtnMouseOver(myObj) {
	return myObj.getAttribute("xBtnMouseOver");
}


/**************************************************
 *		GENERIC FUNCTIONS
 **************************************************/

// imgSrc é do tipo String
function newImage(imgSrc) {
	imgObj = new Image();
	imgObj.src = imgSrc;
	return imgObj;
}

// className, styleName e mediaType são do tipo String
function getClassStyle(className, styleName, mediaType) {
	var styleSheetsLength = document.styleSheets.length;

	for(var j = 0; j < styleSheetsLength; j++) {
		var styleSheet = document.styleSheets[j];

		if((!mediaType && !styleSheet.media) || (styleSheet.media == mediaType)) {
			var rulesLength = styleSheet.rules.length;

			for(var k = 0; k < rulesLength; k++)
				if(styleSheet.rules[k].selectorText == className)
					return styleSheet.rules[k].style.getAttribute(styleName);
		}
	}

	return "";
}

// className, styleName, value e mediaType são do tipo String
function setClassStyle(className, styleName, value, mediaType) {
	var styleSheetsLength = document.styleSheets.length;

	for(var j = 0; j < styleSheetsLength; j++) {
		var styleSheet = document.styleSheets[j];

		if((!mediaType && !styleSheet.media) || (styleSheet.media == mediaType)) {
			var rulesLength = styleSheet.rules.length;

			for(var k = 0; k < rulesLength; k++)
				if(styleSheet.rules[k].selectorText == className) {
					styleSheet.rules[k].style.setAttribute(styleName, value);
					return;
				}
			styleSheet.addRule(className, styleName + ": " + value);
			return;
		}
	}

	document.createStyleSheet();
	if(mediaType != null)
		document.styleSheets[document.styleSheets.length - 1].media = mediaType;
	setClassStyle(className, styleName, value, mediaType);
}

// myObj é do tipo Object
function toggleDisplay(myObj) {
	if(myObj.style.display == "none")
		myObj.style.display = "block";
	else
		myObj.style.display = "none";
}

// myObj é do tipo Object
function toggleOverflow(myObj) {
	if(myObj.style.overflow == "hidden")
		myObj.style.overflow = "visible";
	else
		myObj.style.overflow = "hidden";
}

// imgObj é do tipo imgObj
// imgSrc1 e imgSc2 são do tipo String
function toggleImage(imgObj, imgSrc1, imgSrc2) {
	if(imgObj.src.indexOf(imgSrc1.substr(imgSrc1.indexOf("/"))) != -1)
		imgObj.src = imgSrc2;
	else
		imgObj.src = imgSrc1;
	imgObj.outerHTML = imgObj.outerHTML;
}

// btnObj é do tipo Input Object (button ou image)
// enable é do tipo boolean
function enableBtn(btnObj, enable) {
	if(enable) {
		btnObj.disabled = false;
		btnObj.style.filter = "";
	}
	else {
		btnObj.disabled = true;
		btnObj.style.filter = "Alpha(Opacity='50')";
	}
}

// linkObj é do tipo A Object
// enable é do tipo boolean
function enableLink(linkObj, enable) {
	if(!linkObj.nextSibling ||
	   (linkObj.nextSibling.id != "linkDisabled" + linkObj.sourceIndex))
		linkObj.insertAdjacentHTML("afterEnd", "<A disabled id='linkDisabled" + linkObj.sourceIndex +
						       "'>" + linkObj.innerHTML + "</A>");

	if(enable) {
		linkObj.style.display = "";
		linkObj.nextSibling.style.display = "none";
	}
	else {
		linkObj.style.display = "none";
		linkObj.nextSibling.style.display = "";
	}
}


/**************************************************
 *		ONLOAD FUNCTIONS
 **************************************************/

// imgObj é do tipo Image Object ou Input Object (button ou image)
function getImgSrc(imgObj) {
	if(imgObj.src)
		return imgObj.src;
	else if(imgObj.style.backgroundImage)
		return imgObj.style.backgroundImage.replace(/url\((.*)\)/, "$1");
	else
		return getClassStyle("INPUT." + imgObj.className, "backgroundImage").replace(/url\((.*)\)/, "$1");
}

// imgObj é do tipo Image Object ou Input Object (button ou image)
// imgSrc é do tipo String
function setImgSrc(imgObj, imgSrc) {
	if(imgObj.src)
		imgObj.src = imgSrc;
	else
		imgObj.style.backgroundImage = "url(" + imgSrc + ")";
}

// imgObj é do tipo Image Object ou Input Object (button ou image)
// isOver e isClick são do tipo boolean
function changeImgSrc(imgObj, isClick, isOver) {
	var imgSrc = getImgSrc(imgObj).replace(/(_click)?(_over)?\.([^\.]*)$/g,
			       ((isClick == null)?"$1":isClick?"_click":"") +
			       ((isOver == null)?"$2":isOver?"_over":"") + ".$3");

	setImgSrc(imgObj, imgSrc);
}

// imgObj é do tipo Image Object ou Input Object (button ou image)
// doNotEvents é do tipo boolean
function reloadImgMouseEvents(imgObj, doNotEvents) {
	if(!doNotEvents) {
		imgObj.onmouseover = function() {
					if(!this.disabled)
						changeImgSrc(this, null, true);
				     }
		imgObj.onmouseout  = function() {
					if(this != document.activeElement) {
						this.hadmousedown = false;
						changeImgSrc(this, null, false);
					}
				     }
	}
	else {
		imgObj.onmouseover = null;
		imgObj.onmouseout  = function() {
					if(this != document.activeElement)
						this.hadmousedown = false;
				     }
	}
}

// imgObj é do tipo Image Object ou Input Object (button ou image)
// isToBeClicked é do tipo boolean
function imgOnMouseUp(imgObj, isToBeClicked) {
	var ifImgMouseOver = getXImgMouseOver(imgObj);
	var idxImg	   = parseInt(getXImgEventIdx(imgObj));
	var ifImgClick	   = getXImgClick(imgObj);
	var isClicked	   = false;
	var hasClickOver   = false;

	if(ifImgClick != null) {
		hasClickOver = (ifImgClick.toUpperCase() == "TRUE");
		isClicked = (getImgSrc(imgObj).indexOf("_click") != -1);
		if(isClicked) {
			if((isToBeClicked == null) || !isToBeClicked)
				changeImgSrc(imgObj, false, (ifImgMouseOver && (isToBeClicked == null)));
		}
		else {
			if((isToBeClicked == null) || isToBeClicked)
				changeImgSrc(imgObj, true, (hasClickOver && (isToBeClicked == null)));
		}
	}

	if(isToBeClicked != null)
		return;

	if((idxImg > 0) && lastBtnPressed && (lastBtnPressed != imgObj)) {
		changeImgSrc(lastBtnPressed, false, false);
		reloadImgMouseEvents(lastBtnPressed, !ifImgMouseOver);

		lastBtnPressed = imgObj;
	}

	if(ifImgMouseOver && !hasClickOver)
		reloadImgMouseEvents(imgObj, !(isClicked || (idxImg < 0)));
	else if(!ifImgMouseOver && hasClickOver)
		reloadImgMouseEvents(imgObj, isClicked);
}

// imgObj é do tipo Image Object ou Input Object (button ou image)
// hasMouseOver é do tipo boolean
// strClick e imgSrc são do tipo String
function loadImgMouseEvents(imgObj, hasMouseOver, strClick, imgSrc) {
	var imgSrc = getImgSrc(imgObj);

	if(hasMouseOver) {
		imgObjsOver[imgOverIdx++] = newImage(imgSrc.replace(/\.([^\.]*)$/,"_over.$1"));
		reloadImgMouseEvents(imgObj);
	}

	if(strClick != null) {
		imgObjsOver[imgOverIdx++] = newImage(imgSrc.replace(/\.([^\.]*)$/,"_click.$1"));
		if(strClick.toUpperCase() == "TRUE")
			imgObjsOver[imgOverIdx++] = newImage(imgSrc.replace(/\.([^\.]*)$/,"_click_over.$1"));
	}

	// se calhar, por o onclick numa funcao pq o expandDivs vai ter q mudar a img tb
	imgObj.onmouseup   = function() {
				if((event.button != 2) && this.hadmousedown) {
					this.hadmousedown = false;
					imgOnMouseUp(this);
				}
			     }
	imgObj.onmousedown = function() {
				// o atributo hadmousedown serve para prevenir o evento dblclick
				// porque este é precedido por 1 chamada ao mousedown e 2 ao mouseup
				if((event.button != 2) && !this.disabled)
					this.hadmousedown = true;
			     }
	imgObj.onfocus     = function() {
				if(this.onmouseover)
					this.onmouseover();
				/* Para se poder utilizar o TAB, esta funcionalidade tem que estar inactiva */
				// this.blur();
			     }
	imgObj.onblur      = function() {
				this.onmouseout();
			     }
	imgObj.onkeypress  = function() {
				if((event.keyCode == 13) || (event.keyCode == 32)) {
					this.onmousedown();
					this.onmouseup();
				}
			     }
}

// imgObj é do tipo Image Object ou Input Object (button ou image)
function loadImgObjsMouseEvents(imgObj) {
	var imgObjObjs	     = getXImgEventsObjs(imgObj);
	var imgObjObjsLength = imgObjObjs.length;
	var myObj;

	for(var i = 0; i < imgObjObjsLength; i++) {
		myObj = eval(imgObjObjs[i]);
		myObj.onmouseover = function() {
					if((this == event.srcElement) && (imgObj.onmouseover))
						imgObj.onmouseover();
				    }
		myObj.onmouseout  = function() {
					if(this == event.srcElement)
						imgObj.onmouseout();
				    }
		myObj.onmouseup   = function() {
					if(this == event.srcElement)
						imgObj.onmouseup();
				    }
		myObj.onmousedown = function() {
					if(this == event.srcElement)
						imgObj.onmousedown();
				    }
		myObj.style.cursor = "hand";
	}
}

// btnObj é do tipo Button
// notDone é do tipo boolean
function loadBtnMouseEvents(btnObj, notDone) {
	btnObj.style.borderColor = "";

	btnObj.onmouseover = function() {
				if((this.style.borderColor.toUpperCase() != insetStr) && !this.disabled)
					this.style.borderColor = outsetStr;
			     }
	btnObj.onmouseout  = function() {
				var btnObjIdx = parseInt(getXBtnMouseOver(this));

				if((btnObjIdx == -2) || (this != document.activeElement))
					this.style.borderColor = "";
			     }
			     
	if(notDone) {
		btnObj.onmouseup   = function() {
					if((event.button != 2) &&
					   (this.style.borderColor.toUpperCase() == insetStr) &&
					   this.hadmousedown) {
					   	this.hadmousedown = false;
						var btnObjIdx = parseInt(getXBtnMouseOver(this));
						if(btnObjIdx != -1) {
							if(btnObjIdx == -2) {
								this.style.borderColor = outsetStr;

								return;
							}
							else if(btnObjIdx != 0) {
								if(lastBtnPressed && (lastBtnPressed != this))
									loadBtnMouseEvents(lastBtnPressed);

								lastBtnPressed = this;
							}
							else if(this.onmouseover == null) {
								this.style.borderColor = outsetStr;
								loadBtnMouseEvents(this);

								return;
							}

							this.onmouseover = null;
							this.onmouseout  = function() {};
						}
					}
				     }
		btnObj.onmousedown = function() {
					if((event.button != 2) && !this.disabled) {
						this.style.borderColor = insetStr;
						// o atributo hadmousedown serve para prevenir o evento dblclick
						// porque este é precedido por 1 chamada ao mousedown e 2 ao mouseup
						this.hadmousedown = true;
					}
				     }
		btnObj.onfocus     = function() {
					if(this.onmouseover)
						this.onmouseover();
					/* Para se poder utilizar o TAB, esta funcionalidade tem que estar inactiva */
					// this.blur();
				     }
		btnObj.onblur	   = function() {
					this.onmouseout();
				     }
		btnObj.onkeypress  = function() {
					if((event.keyCode == 13) || (event.keyCode == 32)) {
						this.onmousedown();
						this.onmouseup();
					}
				     }

//if className and background ou so background ???
/*
		var xpto = btnObj.value + "Img";
		//<img src='" + getImgSrc(btnObj) + "' tabindex='-1' style='vertical-align: middle;'>
		btnObj.insertAdjacentHTML("BeforeBegin", "<div id='" + xpto + "' tabindex='-1' style='position: absolute; width: " + (btnObj.offsetWidth - 2) + "; height: " + (btnObj.offsetHeight - 2) + "; z-index: 10; clip: rect(1 " + (btnObj.offsetWidth - 1) + " " + (btnObj.offsetHeight - 1) + " 1); background-image: url(" + getImgSrc(btnObj) + ");'></div>");
		var iii = document.all(xpto);

		btnObj.style.backgroundImage = "none";
		iii.style.filter = "DXImageTransform.Microsoft.Alpha(style=1,opacity=50,finishOpacity=100,startX=0,finishX=4,startY=0,finishY=100);";
		//getClassStyle("INPUT." + btnObj.className, "filter");
		//alert(iii.id + ": " + iii.style.filter);
		iii.innerHTML = " &#160; &#160; "+btnObj.value;

		iii.onclick = function() { btnObj.click();}
		iii.onmouseover = function() { if(btnObj.onmouseover) btnObj.onmouseover();}
		iii.onmouseout  =function() { btnObj.onmouseout();}
		iii.onmouseup=function() { btnObj.onmouseup();}
		iii.onmousedown =function() { btnObj.onmousedown();}
		iii.onfocus  =function() { btnObj.focus();}
		iii.onblur	=function() { btnObj.onblur();}
		iii.onkeypress =function() { btnObj.onkeypress();}
*/
	}
}

// btnObj é do tipo Button
function loadBtnImgMouseEvents(btnObj) {
	var borderLight	= getClassStyle("INPUT." + btnObj.className, "borderTop");
	var borderDark	= getClassStyle("INPUT." + btnObj.className, "borderBottom");

	btnObj.onmousedown = function() {
				this.style.borderLeft	= borderDark;
				this.style.borderTop	= borderDark;
				this.style.borderRight	= borderLight;
				this.style.borderBottom	= borderLight;
			     }
	btnObj.onmouseup = function() {
				this.style.borderLeft	= borderLight;
				this.style.borderTop	= borderLight;
				this.style.borderRight	= borderDark;
				this.style.borderBottom	= borderDark;
			     }
	btnObj.onmouseout = btnObj.onmouseup;
}

// imgObj é do tipo Image Object ou Input Object (button ou image)
// divObj é do tipo Div Object
function loadImgDivEvents(imgObj, divObj) {
	if(getXImgClick(imgObj) != null) {
		divObj.onpropertychange = function() {
						imgOnMouseUp(imgObj, (this.style.display != "none"));
						if((imgObj == lastBtnPressed) && imgObj.onmouseover) {
							imgObj.onmouseover();
							lastBtnPressed = null;
						}
					  }
		imgObj.onmouseup	= function() {
						lastBtnPressed = this;
					  }
	}
	else if(getXImgMouseOver(imgObj)) {
		divObj.onpropertychange = function() {};
	}
}

function onLoadGUI(docObj) {
	if(!docObj)
		docObj = document;

	var imgObj;
	var imgObjs	  = docObj.images;
	var imgObjsLength = imgObjs.length;
	var ifImgMouseOver;
	var ifImgClick;

	for(var i = 0; i < imgObjsLength; i++) {
		imgObj = imgObjs[i];

		ifImgMouseOver	= getXImgMouseOver(imgObj);
		ifImgClick	= getXImgClick(imgObj);
		if(ifImgMouseOver || (ifImgClick != null)) {
			loadImgMouseEvents(imgObj, ifImgMouseOver, ifImgClick);
			loadImgObjsMouseEvents(imgObj);
		}
	}

	var btnObj;
	var btnObjs	  = docObj.all.tags("INPUT");
	var btnObjsLength = btnObjs.length;

	for(var i = 0; i < btnObjsLength; i++) {
		btnObj = btnObjs[i];

		ifImgMouseOver	= getXImgMouseOver(btnObj);
		ifImgClick	= getXImgClick(btnObj);
		if(ifImgMouseOver || (ifImgClick != null)) {
			loadImgMouseEvents(btnObj, ifImgMouseOver, ifImgClick);
			loadImgObjsMouseEvents(btnObj);
		}

		if(getXBtnMouseOver(btnObj) != null)
			loadBtnMouseEvents(btnObj, true);

		/*
		 * This cannot be here because it break the loadImgMouseEvents.
		 * loadBtnImgMouseEvents is a different way of loadBtnMouseEvents
		 * but with effects only. What can be done is to do a single function
		 * with a choice from the 2 effect styles and with something to say
		 * if there is going to be anything more like loadBtnMouseEvents does.
		 * Then xBtnMouseEvents would have 2 values (which style, click functions).
		 *
		else
			if(btnObj.type == "image")
				loadBtnImgMouseEvents(btnObj);
		 */
	}

	imgObjs		  = objectToArray(docObj.all(imgExtName));
	imgObjsLength	  = imgObjs.length;
	var divObjs	  = objectToArray(docObj.all(divExtName));
	var divObjsLength = divObjs.length;

	if(imgObjsLength == divObjsLength)
		for(var i = 0; i < divObjsLength; i++)
			loadImgDivEvents(imgObjs[i], divObjs[i]);
}


/**************************************************
 *		DIV INTERACTION
 **************************************************/

// srcObj é do tipo Object
// tagName, currentDisplay e currentOverflow são do tipo String
function expandObjDiv(srcObj, tagName, currentDisplay, currentOverflow) {
	var parentObj;

	if(srcObj)
		parentObj = getParentObject(srcObj, tagName);
	else
		if(document.all(divExtName))
			parentObj = getParentObject((document.all(divExtName).length)?
						    document.all(divExtName)[0]:
				 		    document.all(divExtName), tagName);
		else
			return;

	if(parentObj.tagName.toUpperCase() != "HTML") {
		var divExt;
		var imgExt;
		var divExtLength;
		var imgExtLength;

		divExt	= (parentObj.id == divExtName)?
			  objectToArray(parentObj):
			  objectToArray(parentObj.all(divExtName));
		imgExt	= objectToArray(parentObj.all(imgExtName));

		divExtLength = divExt.length;
		imgExtLength = imgExt.length;

		for(var j = 0; j < divExtLength; j++) {
			if(divExt[j].style.display &&
			   (!currentDisplay ||
			    (divExt[j].style.display == currentDisplay))) {
				if((j < imgExtLength) && !divExt[j].onpropertychange)
					toggleImage(imgExt[j], imgExtend, imgReduce);
				toggleDisplay(divExt[j]);
			}
			if(divExt[j].style.overflow &&
			   (!currentOverflow ||
			    (divExt[j].style.overflow == currentOverflow))) {
				if((j < imgExtLength) && !divExt[j].onpropertychange)
					toggleImage(imgExt[j], imgExtend, imgReduce);
				toggleOverflow(divExt[j]);
			}
		}
	}
}

// tagName, currentDisplay e currentOverflow são do tipo String
function expandDiv(tagName, currentDisplay, currentOverflow) {
	if(event && event.srcElement)
		expandObjDiv(event.srcElement, tagName, currentDisplay, currentOverflow);
	else
		expandObjDiv(null, tagName, currentDisplay, currentOverflow);
}

// divParentTagName e divsParentTagName são do tipo String
function expandDivs(divParentTagName, divsParentTagName) {
	event.cancelBubble = true;

	if(!event.ctrlKey) {
		expandDiv(divParentTagName);
	}
	else {
		var divExt	= getObjArrayById(divExtName, event.srcElement, divParentTagName);
		var objDisplay  = divExt[0].style.display;
		var objOverflow = divExt[0].style.overflow;;

		if(!objOverflow)
			if(objDisplay == "none")
				objOverflow = "hidden";
			else
				objOverflow = "visible";
		if(!objDisplay)
			if(objOverflow == "hidden")
				objDisplay = "none";
			else
				objDisplay = "block";

		expandDiv(divsParentTagName,
			  objDisplay,
			  objOverflow);
	}
}

// parentObj é do tipo Object
function popupDiv(parentObj) {
	var divObj = parentObj.all(divPopName);

	// Quando se faz object.all, convém verificar tb uma propriedade
	// pq ele pode assumir que object.all = document.all
	if(divObj && divObj.id) {
		divObj.style.left  = parentObj.offsetLeft + 2;
		//divObj.style.top = parentObj.offsetTop - 4;
		divObj.style.width = parentObj.offsetWidth;
	}
	else
		return false;

	return true;
}

// parentObj é do tipo Object
function popoutDiv(parentObj) {
	var divObj = parentObj.all(divPopName);

	// Quando se faz object.all, convém verificar tb uma propriedade
	// pq ele pode assumir que object.all = document.all
	if(divObj && divObj.id)
		divObj.style.width = 0;
	else
		return false;

	return true;
}

// tagName é do tipo String
function popup(tagName) {
	var myObj = getParentObject(event.srcElement, tagName);

	if(myObj.parentElement)
		if(myObj.parentElement.rowIndex != 0) {
			popupDiv(myObj);
		}
		else {
			rows      = getParentObject(myObj, "TABLE").rows;
			cellIndex = myObj.cellIndex;

			popupDiv(myObj);
	        	for(i = 1; i < rows.length; i++) {
				myObj = rows[i].cells[cellIndex];
				if(myObj)
					popupDiv(myObj);
			}
		}
}

// tagName é do tipo String
function popout(tagName) {
	var myObj = getParentObject(event.srcElement, tagName);

	if(myObj.parentElement)
		if(myObj.parentElement.rowIndex != 0) {
			popoutDiv(myObj);
		}
		else {
			rows      = getParentObject(myObj, "TABLE").rows;
			cellIndex = myObj.cellIndex;

			popoutDiv(myObj);
	        	for(i = 1; i < rows.length; i++) {
				myObj = rows[i].cells[cellIndex];
				if(myObj)
					popoutDiv(myObj);
			}
		}
}

// tagName é do tipo String
function loadDivPopStyle(tagName) {
	var divPop = document.all(divPopName);
	var className;

	if(!divPop.length)
		divPop = new Array(divPop);

	for(var i = 0; i < divPop.length; i++) {
		className = getParentObject(divPop[i], tagName).className;
		if(className) {
			divPop[i].className = className;
			divPop[i].style.backgroundColor = "";
			divPop[i].style.color = "";
		}
	}
}


/**************************************************
 *		PRINTING FUNCTIONS
 **************************************************/

// myFrame é do tipo Window Object
function printWindow(myWindowObj, mySrc, myAlert) {
	if(!myWindowObj)
		myWindowObj = window;

	if(!mySrc || (myWindowObj.location.href.indexOf(mySrc) == -1))
	{
		myWindowObj.focus();
		myWindowObj.print();
	}
	else {
		if(mySrc != null)
			alert(myAlert);
	}
}

// isExtended é do tipo boolean
function printConfig(isExtended) {
	var printExt = parent.main.document.all('isPrintExtended');
	var printRed = parent.main.document.all('isPrintReduced');

	if(printExt && !printExt.length)
		printExt = new Array(printExt);
	if(printRed && !printRed.length)
		printRed = new Array(printExt);

	if(isExtended) {
		if(printExt && (printExt[0].style.display == 'none'))
			 for(var i = 0; i < printExt.length; i++)
			 	printExt[i].style.display = '';
		if(printRed && (printRed[0].className.substr(0,8) != 'notprint'))
			 for(var i = 0; i < printRed.length; i++)
			 	printRed[i].className = 
			 		printRed[i].className = 'notprint' + printRed[i].className;
	}
	else {
		if(printExt && (printExt[0].style.display != 'none'))
			 for(var i = 0; i < printExt.length; i++)
			 	printExt[i].style.display = 'none';
		if(printRed && (printRed[0].className.substr(0,8) == 'notprint'))
			 for(var i = 0; i < printRed.length; i++)
			 	printRed[i].className = 
			 		printRed[i].className.substr(8,printRed[i].className.length);
	}
}


/**************************************************
 *		OVO IMPLEMENTATION
 **************************************************/

var eeTimeout;
var eeText = "";
var eeTd;

function ee(myEvent) {
	eeTd = getParentObject(myEvent.srcElement, "TD");

	if(myEvent.shiftKey && myEvent.altKey && myEvent.ctrlKey &&
	   (myEvent.offsetY < 20) && ((myEvent.srcElement.width - myEvent.offsetX) < 20)) {
	   	eeTd.onkeypress = function() {
	   				eeText += String.fromCharCode(top.frames("top").event.keyCode);
	   				if(eeText == "puzzle")
	   					/*window.showModalDialog(
	   						"../util/puzzle.html",
	   						"",
	   						"dialogWidth:414px;" +
							"dialogHeight:459px;" +
							"dialogLeft:50;" +
							"dialogTop:50;" +
							"status:no;" +
							"help:no;" +
							"minimize:no;" +
							"maximize:no;" +
							"border:thick;");*/
	   					top.frames("main").location.replace("../layout/puzzle.html");
	   			   }
		eeTimeout = setTimeout("eeTd.onkeypress = null; eeText = ''", 5000);
	}
}
