isVisible = false;
Xpos = 0;
Ypos = 0;

// The following variables are used to customize user perference
// -1 means infinite
//boolPrintDes = 0;
//boolPrintImg = 0;
//boolPrintAV  = 0;
//intImgAlign = 1;
//intCountSubCat = -1;
//intMaxStory = -1;
//intMaxWidth = -1;
//intMaxHeight = -1;

content = new Array;

optionSelected = -1;

isNetscape = navigator.appName=="Netscape";

// Capture event from browser
if (isNetscape) {
	document.captureEvents(Event.MOUSEMOVE)
	document.onMouseMove = MoveHandler;
} else {
	document.onmousemove = MoveHandlerIE;
}

function MoveHandler(e){
    Xpos = e.pageX;
    Ypos = e.pageY;
	return true;
}

function MoveHandlerIE() {
    Xpos = window.event.x + document.body.scrollLeft;
    Ypos = window.event.y + document.body.scrollTop;
}


function setContentValue() {
	var i;
	if (isNetscape) {
		for (i = 0; i < content.length; i++) {
				document.frmPost.elements[i].value = content[i];
		}
	} else {
		for (i = 0; i < content.length; i++) {
			frmPost.elements[i].value = content[i];
			//alert(frmPost.elements[i].value);
		}
	}
	return true;
}
// Show Layer1, triggered by pressing down_arrow.gif
function showLayer() {
	if (navigator.appName=="Netscape") {
		document.Layer1.left = Xpos;
		document.Layer1.top = Ypos;
		document.Layer1.visibility  = "show";
	} else {
		Layer1.style.posLeft = Xpos;
		Layer1.style.posTop = Ypos;
		Layer1.style.visibility="visible";
		isVisible = true;
	}
}

// Hide all layers, triggered by press "Close Me"
function hideLayer(boolClose){
	if (isNetscape) {
		document.LayerOptionTrueFalse.visibility = "hidden";
		document.LayerOptionAlign.visibility = "hidden";
		document.LayerOptionSize.visibility = "hidden";
		document.Layer1.visibility = "hidden";
		if (boolClose) { 
			setContentValue();
			document.frmPost.submit();
		}
		return true;
	} else {
		LayerOptionSize.style.visibility = "hidden";
		LayerOptionAlign.style.visibility = "hidden";
		LayerOptionTrueFalse.style.visibility = "hidden";
		Layer1.style.visibility="hidden";
		if (boolClose) {
			setContentValue();
			frmPost.submit();
		}
	}
}

// Set different value for CountSubCat, intMaxStory, intMaxWidth, intMaxHeight
function setDifValue(option, value) {
	var i, msg = "";
	
	if (option >= 0 && option <= 2) {
		if (isNetscape) {
			if (value == 1) {
				document.LayerOptionTrueFalse.document.images["print"].src = printOn.src
				document.LayerOptionTrueFalse.document.images["notPrint"].src = notPrintOff.src
			} else {
				document.LayerOptionTrueFalse.document.images["print"].src = printOff.src
				document.LayerOptionTrueFalse.document.images["notPrint"].src = notPrintOn.src
			}		
		} else {
			if (value == 1) {
				document.images["print"].src = printOn.src
				document.images["notPrint"].src = notPrintOff.src
			} else {
				document.images["print"].src = printOff.src
				document.images["notPrint"].src = notPrintOn.src
			}		
		}
	}

	if (option == 3) {
		if (isNetscape) {
			document.LayerOptionAlign.document.images["imgLeft"].src = imgLeftOff.src
			document.LayerOptionAlign.document.images["imgCenter"].src = imgCenterOff.src
			document.LayerOptionAlign.document.images["imgRight"].src = imgRightOff.src
			switch (value) {
				case 1: document.LayerOptionAlign.document.images["imgLeft"].src = imgLeftOn.src; break;
				case 2: document.LayerOptionAlign.document.images["imgCenter"].src = imgCenterOn.src; break;
				case 3: document.LayerOptionAlign.document.images["imgRight"].src = imgRightOn.src; break;
			}			
		} else {
			document.images["imgLeft"].src = imgLeftOff.src
			document.images["imgCenter"].src = imgCenterOff.src
			document.images["imgRight"].src = imgRightOff.src
			switch (value) {
				case 1: document.images["imgLeft"].src = imgLeftOn.src; break;
				case 2: document.images["imgCenter"].src = imgCenterOn.src; break;
				case 3: document.images["imgRight"].src = imgRightOn.src; break;
			}
		}
	}

	content[option] = value;

	for (i = 0;i <content.length; i++) {
		msg += content[i] + " ";
	}
//	alert(msg);

}

// Argument : NA
// Output : Either alert() user or set for different value (by calling setDifValue())
// Function peform checking on :
// 1. Input NaN type (e.g. alphetic)
// 2. Input negative value
// 3. Input Null
function setSizeValue() {
	if (isNetscape) {
		if (!isNaN(document.LayerOptionSize.document.f.txtSize.value) || document.LayerOptionSize.document.f.txtSize.value == ""){
			if (parseInt(document.LayerOptionSize.document.f.txtSize.value) < 0) {
				alert("Number should not be negative!!");
			} else {
				if (document.LayerOptionSize.document.f.txtSize.vlaue != "") {
					setDifValue(optionSelected, document.LayerOptionSize.document.f.txtSize.value);
				}
				document.LayerOptionSize.visibility = "hidden";
				document.LayerOptionSize.document.f.txtSize.value = "";
			}
		} else {
			alert ("Enter numeric number please!!");
		}	
	} else {
		if (!isNaN(f.txtSize.value) || (f.txtSize.value == "")){
			if (parseInt(f.txtSize.value) < 0) {
				alert("Number should not be negative!!");
			} else {
				if (f.txtSize.value != "") {
					setDifValue(optionSelected, f.txtSize.value);
				} else if (parseInt(f.txtSize.value) < 0) {
					alert("Number should not be negative!!");
				}
				LayerOptionSize.style.visibility = "hidden";
				f.txtSize.value = "";
			}
		} else {
			alert ("Enter numeric number please!!");
		}
	}
}

function showAlignLayer(option) {
	optionSelected = 3;

	if (isNetscape) {
		document.LayerOptionSize.visibility = "hidden";
		document.LayerOptionTrueFalse.visibility = "hidden";

		document.LayerOptionAlign.left = document.Layer1.left + 50;
		document.LayerOptionAlign.top = document.Layer1.top + option * 14;
		document.LayerOptionAlign.visibility = "visible";

		document.LayerOptionAlign.document.images["imgLeft"].src = imgLeftOff.src
		document.LayerOptionAlign.document.images["imgCenter"].src = imgCenterOff.src
		document.LayerOptionAlign.document.images["imgRight"].src = imgRightOff.src
		switch (content[3]) {
			case 1: document.LayerOptionAlign.document.images["imgLeft"].src = imgLeftOn.src; break;
			case 2: document.LayerOptionAlign.document.images["imgCenter"].src = imgCenterOn.src; break;
			case 3: document.LayerOptionAlign.document.images["imgRight"].src = imgRightOn.src; break;
		}
	} else {
		LayerOptionSize.style.visibility = "hidden";
		LayerOptionTrueFalse.style.visibility = "hidden";
		LayerOptionAlign.style.posLeft = Layer1.style.posLeft + 50;
		LayerOptionAlign.style.posTop = Layer1.style.posTop + option * 14
		LayerOptionAlign.style.visibility = "visible";

		document.images["imgLeft"].src = imgLeftOff.src
		document.images["imgCenter"].src = imgCenterOff.src
		document.images["imgRight"].src = imgRightOff.src
		switch (content[3]) {
			case 1: document.images["imgLeft"].src = imgLeftOn.src; break;
			case 2: document.images["imgCenter"].src = imgCenterOn.src; break;
			case 3: document.images["imgRight"].src = imgRightOn.src; break;
		}

	}

}

// Show the layer of Print/Not print for Description, AV, or Image
// Set optionSelected so that we know which value we are setting now
function showTrueFalseOptionLayer(option) {
	optionSelected = option;

	if (isNetscape) {
		document.LayerOptionSize.visibility = "hidden";
		document.LayerOptionAlign.visibility = "hidden";
		document.LayerOptionTrueFalse.left = document.Layer1.left + 50;
		document.LayerOptionTrueFalse.top = document.Layer1.top + option * 14;
		document.LayerOptionTrueFalse.visibility = "visible";

		if (content[optionSelected]) {
			document.LayerOptionTrueFalse.document.images["print"].src = printOn.src
			document.LayerOptionTrueFalse.document.images["notPrint"].src = notPrintOff.src
		} else {
			document.LayerOptionTrueFalse.document.images["print"].src = printOff.src
			document.LayerOptionTrueFalse.document.images["notPrint"].src = notPrintOn.src
		}
	} else {
		LayerOptionSize.style.visibility = "hidden";
		LayerOptionAlign.style.visibility = "hidden";
		optionSelected = option;
		LayerOptionTrueFalse.style.posTop = Layer1.style.posTop + option * 14
		LayerOptionTrueFalse.style.posLeft = Layer1.style.posLeft + 50;
		LayerOptionTrueFalse.style.visibility = "visible";
		if (content[optionSelected]) {
			document.images["print"].src = printOn.src
			document.images["notPrint"].src = notPrintOff.src
		} else {
			document.images["print"].src = printOff.src
			document.images["notPrint"].src = notPrintOn.src
		}
	}
}

// Show the layer for setting size of different attribute
// Set optionSelected so that we know which value we are setting now
function showSizeOptionLayer(option, dummy) {
	optionSelected = option;
	if (isNetscape) {
		document.LayerOptionTrueFalse.visibility = "hidden";
		document.LayerOptionAlign.visibility = "hidden";
		document.LayerOptionSize.left = document.Layer1.left + 50;
		document.LayerOptionSize.top = document.Layer1.top + option * 14;
		document.LayerOptionSize.document.f.txtSize.value = content[optionSelected];
		document.LayerOptionSize.visibility = "visible";
	} else {
		LayerOptionTrueFalse.style.visibility = "hidden";
		LayerOptionAlign.style.visibility = "hidden";
		LayerOptionSize.style.posTop = Layer1.style.posTop + option * 14;
		LayerOptionSize.style.posLeft = Layer1.style.posLeft + 50;
		f.txtSize.value = content[optionSelected];
		LayerOptionSize.style.visibility = "visible"
	}
}

