/*==========================================================================*/
/* 商品クラス																*/
/*==========================================================================*/
function Product(
		id,					// 商品ＩＤ（画像のベース名と同じ）
		dirName,			// ディレクトリ名（相対パス）
		title,				// タイトル
		price,				// 価格
		spec,				// 商品仕様
		comment,			// 商品コメント
		fsquare,			// 正方形イメージは true
		sizeVarriation,		// サイズバリエーション（セールストークコメント）
		countImage,			// イメージファイル数（２番目以降は _%d で枝番付き画像）
		status				// 状態（0: 通常／1: 新製品／2: 入荷待ち／3〜: 未定義
	)
{
	/* プロパティ */
	this.id = id;
	this.dirName = dirName;
	if( sizeVarriation ) {
		this.sizeVarriation = sizeVarriation;
	}
	else {
		this.sizeVarriation = "";
	}
	this.title = title;
	this.price = price;
	this.spec = spec;
	this.comment = comment;
	this.fsquare = fsquare;
	this.countImage = countImage;
	this.status = status;
	/* サイズ選択コントロール作成 */
	this.makeSizeControl=function( id ) {
		return this.sizeVarriation;
	}
	/* 画像パス : type 0:商品リスト／1:拡大表示／2:トップ／3:注文 */
	this.getImagePath=function( type) {
		if( type == 2) {
			return (dirName + "/TOP_" + id + ".jpg");
		}
		else {
			return (dirName + "/" + id + ".jpg");
		}
	}
	this.getImagePath2=function( no) {
		return (dirName + "/" + id + "_" + no + ".jpg");
	}
	/* 画像サイズ文字列 : type 0:商品リスト／1:拡大表示／2:トップ／3:注文 */
	this.getImageSize=function( type) {
		if( type == 1) {
			return "";
		}
		else if( type == 2) {
			return "width=136 height=102";
		}
		else {
			return "height=120";
		}
	}
	/* エントリ文字列取得 : type 0:商品リスト／1:拡大表示／2:トップ／3:注文 */
	this.getEntryString=function( type ) {
		imagePath = this.getImagePath(type);
		imageSize = this.getImageSize(type);
		if( type == 0) {
			statusText = "";
			if( this.status == 1) {
				/* 1: 新製品 */
				statusText = "<FONT size=2 color='#cc0000'><strong>New！</strong></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
			else if( this.status == 2) {
				/* 2: 入荷待ち */
				statusText = "<FONT size=-2 color='#000080'>入荷待ち</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			}
			selId = "sel_size_" + id;
			sizeControl = this.makeSizeControl( selId );
			if( sizeControl.length > 0 ) {
				statusText = "<FONT size=2 color='#cc0000'><strong>" + sizeControl + "</strong></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
			}
			return	"<TABLE cellpadding=0 cellspacing=0 width=160><TR><TD align='center'>"
				+ "<A name='#" + id + "'><A href='javascript:onClickProduct(\"" + id + "\")'>"
				+ "<IMG border=1 " + imageSize + " src='" + imagePath + "' alt='" + this.title + "'></A>"
				+ "</TD></TR><TR><TD align='center'><FONT size=-1>"
				+ this.id + "&nbsp;&nbsp;￥" + this.price
				+ "</TD></TR><TR><TD align='right'><FONT size=-1>"
				+ statusText
				+ "" + "<INPUT type='button' value='購入' onClick='onClickBuy(\"" + id + "\", \"\")'>"
				+ "</TD></TR></TABLE>";

		}
		else if( type == 3) {
			apendix = "";
			if( this.comment != "") {
				apendix += "<BR>";
				apendix += this.comment;
			}
			return	"<TABLE cellpadding=0 cellspacing=1 bgcolor=black><TR><TD align=center width=120>"
					+ "<IMG border=0 " + imageSize + " src='" + imagePath + "'>"
					+ "</TD><TD width=240 bgcolor=white>"
					+ "<TABLE><TR>"
					+ "<TD width=60><FONT size=-1>品番</TD>"
					+ "<TD width=220><FONT size=-1>" + this.id + "</TD>"
					+ "</TR><TR>"
					+ "<TD width=60><FONT size=-1>価格</TD>"
					+ "<TD width=220><FONT size=-1>￥" + this.price + "</TD>"
					+ "</TR><TR>"
					+ "<TD width=60><FONT size=-1>仕様</TD>"
					+ "<TD width=220><FONT size=-1>" + this.spec + "</TD>"
					+ "</TR><TR>"
					+ "<TD width=60><FONT size=-1>&nbsp;</TD>"
					+ "<TD width=220><FONT size=-1>" + this.title + apendix + "</TD>"
					+ "</TR></TABLE>"
					+ "</TD></TR></TABLE>"
					;
		}
		else {
			apendix = "";
			if( this.comment != "") {
				apendix += "<BR>";
				apendix += this.comment;
			}
			if( this.sizeVarriation != "") {
				apendix += "<BR><FONT color='#cc0000'><STRONG>";
				apendix += this.sizeVarriation;
				apendix += "</STRONG></FONT>";
			}
			imageBlock = "<IMG border=0 " + imageSize + " src='" + imagePath + "'>";
			for( no = 2; no <= this.countImage; no++) {
				imageBlock += "<BR><IMG border=0 " + imageSize + " src='" + this.getImagePath2(no) + "'>";
			}
			return	"<TABLE><TR><TD align=center width=450>"
					+ imageBlock
					+ "</TD></TR><TR><TD>"
					+ "<TABLE><TR>"
					+ "<TD width=40><FONT size=-1>&nbsp</TD>"
					+ "<TD width=60><FONT size=-1>品番</TD>"
					+ "<TD width=220><FONT size=-1>" + this.id + "</TD>"
					+ "</TR><TR>"
					+ "<TD width=40><FONT size=-1>&nbsp</TD>"
					+ "<TD width=60><FONT size=-1>価格</TD>"
					+ "<TD width=220><FONT size=-1>￥" + this.price + "</TD>"
					+ "</TR><TR>"
					+ "<TD width=40><FONT size=-1>&nbsp</TD>"
					+ "<TD width=60><FONT size=-1>仕様</TD>"
					+ "<TD width=220><FONT size=-1>" + this.spec + "</TD>"
					+ "</TR><TR>"
					+ "<TD width=40><FONT size=-1>&nbsp</TD>"
					+ "<TD width=60><FONT size=-1>&nbsp;</TD>"
					+ "<TD width=220><FONT size=-1>" + this.title + apendix + "</TD>"
					+ "</TR></TABLE>"
					+ "</TD></TR></TABLE>"
					;
		}
	}
	this.writeEntry=function() {
		imagePath = this.getImagePath(1);
		document.write( this.getEntryString(0));
	}
}
/*==========================================================================*/
/* 商品テーブル																*/
/*==========================================================================*/
g_Products = new Array(
/* ↓↓↓ */
new Product("DI-0001","display","飾り棚【ホワイト】4×4　計16マス", 16000, "W65×H65×D18", "ディスプレイ用飾り棚です。", false, "", 2, 0),
new Product("DI-0002","display","飾り棚【ダークブラウン】2×8　計16マス", 18000, "W33×H129×D18", "ディスプレイ用飾り棚です。", false, "", 2, 0),
new Product("DI-0003","display","飾り棚【アイボリー】計8マス", 9000, "W17×H129×D18", "ディスプレイ用飾り棚です。", false, "", 2, 0),
new Product("DI-0004","display","飾り棚【アンティーク調】", 5800, "W46×H71×D13", "ディスプレイ用飾り棚です。", false, "NEW", 2, 0),
new Product("BO-0001","book","ネームプレート付きブックスタンド", 8000, "W47.5×H33.5×D28", "", false, "", 2, 0),
new Product("BO-0002","book","3段マガジンラック", 9000, "W50×H60×D19.5", "", false, "", 2, 0),
new Product("BO-0003","book","マガジンラック", 6000, "", "", false, "", 2, 0),
new Product("BO-0004","book","マガジンラック", 7000, "", "", false, "", 2, 0),
new Product("CA-0001","cabinet","扉付き収納棚【ホワイト】金具【ゴールド】", 20000, "W65×H65×D17", "", false, "", 2, 0),
new Product("CA-0002","cabinet","ファイル収納棚 【仕切り取外し可】", 24000, "W49×H141×D25", "", false, "", 2, 0),
new Product("CA-0003","cabinet","靴収納棚　　【仕切り取外し可】", 24000, "W49×H141×D28", "", false, "", 2, 0),
new Product("TV-0001","tv","引き出し付ＴＶ台", 28000, "W80×H40×D30", "【ホワイト】", false, "", 2, 0),
new Product("TV-0002","tv","引き出し付ＴＶ台", 28000, "W80×H40×D30", "【ホワイト×ダークブラウン】", false, "", 2, 0),
new Product("SA-0001","sale","", 1000, "", "", false, "", 2, 0),
new Product("SA-0002","sale","", 1000, "", "", false, "", 2, 0),
/* ↑↑↑ */
new Product("", "", "", "")
);
/*==========================================================================*/
/* 商品テーブル出力															*/
/*==========================================================================*/
function writeProductTable( dirName, methodName, actionUrl)
{
	countHorz = 4;
	document.write("<FONT size=-1><A name='_page_top'><FORM name='ProductForm' action='" + actionUrl + "' method='" + methodName + "'>\n");
	document.write("<TABLE>\n");
	
	toTop = "<TR><TD align='right' colspan=" + countHorz + "><FONT size=-1><A href='#_page_top'>top↑</A></TD></TR>";

	countCol = 0;
	for( i = 0; g_Products[i].dirName != ""; i++) {
		if((dirName == "") || (g_Products[i].dirName == dirName)) {
			if( countCol % countHorz == 0) {
				document.write("<TR>\n");
			}
			document.write("<TD valign=top>\n");
			g_Products[i].writeEntry();
			document.write("</TD>\n");
			if( countCol % countHorz == countHorz - 1) {
				document.write("</TR>\n");
				document.write( toTop);
			}
			countCol++;
		}
	}
	if( countCol % countHorz != 0) {
		document.write( toTop);
	}
	document.write("</TABLE></FORM>\n");

}
/*==========================================================================*/
/* ピックアップ商品画像表示（ＩＤ指定）										*/
/*==========================================================================*/
function showPickupProductImage( id)
{
	index = searchIndex(id);
	document.write("<A href='" + g_Products[index].dirName + ".html' target='SS_BODY'><IMG border=0 src='" + g_Products[index].getImagePath(2) + "' " + g_Products[index].getImageSize(2) + "></A>");
}
/*==========================================================================*/
/* インデックス検索（ＩＤから）												*/
/*==========================================================================*/
function searchIndex( id)
{
	for( i = 0; g_Products[i].dirName != ""; i++) {
		if( g_Products[i].id == id) {
			return i;
		}
	}
	return -1;
}
/*==========================================================================*/
/* イベントハンドラ：商品クリック											*/
/*==========================================================================*/
function onClickProduct( id)
{
	index = searchIndex( id);

	width = 456;
	if( g_Products[index].countImage < 3) {
		height = 200 + g_Products[index].countImage * 240;
	}
	else {
		height = 200 + g_Products[index].countImage * 180;
	}
	w=window.open("space.html", "SS_RefWin", "width=" + width + ",height=" + height + ",left=50,top=50");
	w.resizeTo(width,height);
	w.title = id;

	w.document.write("<HTML><HEAD><TITLE>" + id + "</TITLE><META http-equiv=Content-Type content=\"text/html; charset=x-sjis\"></HEAD>");
	w.document.write("<BODY leftmargin=0 topmargin=0>");
	w.document.write( g_Products[index].getEntryString(1));
	w.document.write("</BODY>");
	w.document.write("</HTML>");
}
