//Copyright © 2000 PAULGRANT.CA
//http://actionfigurechecklist.com

function Ok_Prop()
{
	var oForm = document.getElementById("frmProperties");
	if(!oForm)
		return false;

	var oQuantity	= oForm.txtQuantity;
	var oComment	= oForm.txtComment;
	var oFigureType	= oForm.selFigureType;

	var iJoeQuantity= ((oQuantity	!= null) ? oQuantity.value									: 1);
	var iJoeType	= ((oFigureType	!= null) ? oFigureType[ oFigureType.selectedIndex ].value	: 0);

	if(isNaN(iJoeQuantity) == true)
	{
		alert("Enter a number for Quantity");

		if(oQuantity)
		{
			oQuantity.focus();
			oQuantity.select();
		}
		return false;
	}

	iJoeQuantity = ((iJoeQuantity > 0) ? iJoeQuantity : 1);
	iJoeQuantity = ((iJoeQuantity <= this.iMaxQuantity) ? iJoeQuantity : this.iMaxQuantity);

	this.oJoe.iJoeType		= iJoeType;
	this.oJoe.iJoeQuantity	= iJoeQuantity;

	this.oJoe.bChecked			= true;
	this.oJoe.bModifiedProperty	= true;

	SetCheckImage(this.oJoe.iJoeId, this.oJoe.iJoeType, true);

	var sDiv	= "divQ" + this.oJoe.iJoeId;
	var oDiv	= document.getElementById(sDiv);
	if(oDiv)
		oDiv.innerHTML = ((iJoeQuantity > 1) ? iJoeQuantity : "__");

	this.Hide();

	return true;
}

function Cancel_Prop()
{
	this.Hide();

	return true;
}

function Hide_Prop()
{
	document.getElementById("layerProperties").style.visibility = "hidden";

	return true;
}

function Open_Prop(oJoe)
{
	if(!oJoe)
		return false;

	this.oJoe = oJoe;

	var oProp = document.getElementById("layerProperties");
	if(!oProp)
		return false;

	//var iWinWidth	= ((window.innerWidth)	? window.innerWidth		: ((document.body.clientWidth) ? document.body.clientWidth : document.documentElement.clientWidth));
	iWinWidth = "800";
	var oContent = document.getElementById("main_content");
	if(oContent)
	{
		if(oContent.width)
			iWinWidth = oContent.width;
	}

	var iWinHeight	= ((window.innerHeight)	? window.innerHeight	: 480);
	//document.body.clientWidth
	//((document.body.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight)

	var iOffsetLeft	= ((window.scrollX)	? window.scrollX : ((document.body.scrollLeft) ? document.body.scrollTop : document.documentElement.scrollLeft));
	var iOffsetTop	= ((window.scrollY)	? window.scrollY : ((document.body.scrollTop) ? document.body.scrollTop : document.documentElement.scrollTop));

	oProp.style.width		= this.iWidth + "px";
	oProp.style.height		= this.iHeight + "px";
	oProp.style.left		= (((iWinWidth - this.iWidth) / 2) + iOffsetLeft) + "px";
	oProp.style.top			= (((iWinHeight - this.iHeight) / 2) + iOffsetTop) + "px";

	var oFigName = document.getElementById("layerFigName");
	if(!oFigName)
		return false;

	oFigName.innerHTML = this.oJoe.sJoeName;

	oProp.style.visibility		= "visible";

	var oForm = document.getElementById("frmProperties");
	if(!oForm)
		return false;

	var oQuantity	= oForm.txtQuantity;
	var oFigureType	= oForm.selFigureType;

	if(oQuantity != null)
	{
		oQuantity.value	= this.oJoe.iJoeQuantity;
		oQuantity.focus();
		oQuantity.select();
	}

	var i		= 0;
	var oType	= null;

	for(i = 0; i < oFigureType.options.length; i++)
	{
		oType = oFigureType.options[ i ];
		if(!oType)
			break;

		if(oType.value == this.oJoe.iJoeType)
			oType.selected = true;
	}

	return true;
}

function HtmlBaseTag_Prop()
{
	var i				= 0;
	var sString 		= "";
	var oType			= null;

	sString = "<div name='layerProperties' id='layerProperties' style='position:absolute;visibility:hidden;'>\n"
	+ "<form name='frmProperties' id='frmProperties' onSubmit='return false;'>\n"
	+ "<table border='0' cellpadding='2' cellspacing='0' bgcolor='black'><tr><td>\n"
	+ "<table border='0' cellpadding='0' cellspacing='0' width='" + this.iWidth + "' height='" + this.iHeight + "' bgcolor='" + gsBgColor +"'>\n"
	+ "<tr><td align='center' valign='middle'>\n"
	+ "<table border='0' cellpadding='0' cellspacing='1'>\n"
	+ "<tr><td class='fontBold' align='right' valign='top' width='85' height='19'>Figure</td><td>&nbsp;</td><td align='left' valign='top' width='140'><span class='fontBold' id='layerFigName'>&nbsp;</span></td></tr>\n"
	+ "<tr><td class='fontBold' align='right' valign='top' height='22'>Quantity</td><td>&nbsp;</td><td align='left' valign='top'><input type='text' name='txtQuantity' SIZE='15' MAXLENGTH='3' style='width:100px;'></td></tr>\n"
	+ "<tr><td class='fontBold' align='right' valign='top'>Figure Type</td><td>&nbsp;</td><td align='left' valign='top'>\n"
	+ "<select name='selFigureType' style='width:104px;'>\n";

	for(i = 0; i < gaFigureTypes.length; i++)
	{
		oType = gaFigureTypes[ i ];
		if(!oType)
			break;

		sString += "<option value='" + oType[ 0 ] + "'>" + oType[ 1 ] + "</option>\n";
	}

	sString +=
	  "</select></td></tr>\n"
	+ "<tr><td>&nbsp;</td><td>&nbsp;</td><td align='left' valign='bottom' height='25'>\n"
	+ "<input type='submit' value=' Ok ' onClick='oProperties.Ok();'>&nbsp;\n"
	+ "<input type='button' value=' Cancel ' onClick='oProperties.Cancel();'>\n"
	+ "</td></tr></table></td></tr></table></td></tr></table>\n"
	+ "</form></div>\n";

	document.write(sString);
	//var oDiv = document.getElementById("layerProperties");
	//if(oDiv)
		//oDiv.innerHTML = sString;

	return true;
}

function PropertiesClass()
{
	this.oJoe			= null;

	this.iWidth			= 350;
	this.iHeight		= 150;

	this.iMaxQuantity	= 100;

	this.Ok				= Ok_Prop;
	this.Cancel			= Cancel_Prop;
	this.Hide			= Hide_Prop;
	this.Open			= Open_Prop;
	this.HtmlBaseTag	= HtmlBaseTag_Prop;

	return this;
}

var oProperties	= new PropertiesClass();

//End.
