/******************************************************

	main.js

	毎日プレミアモール向けJavaScript

(c)Takashi Shinmura, T.Schinmullar, TAFWORKS 2001-2004.

******************************************************/


// 商品一覧のための商品別情報を配列に格納する．そのときの添え字．
var prosum = -1;

// 陳列棚に商品を並べるための配列
var lstProductID = new Array;
var lstProductName = new Array;
var lstProductDesc = new Array;
var lstProductImage = new Array;

// Webページ識別用変数
var THISIS = new String;

function DispLeftWingTriangleJob(){		// 左メニュー展開部の残骸 2004/05/29/Sa
	return(true);
}



/*
	2004/04/13/Tu: T.Schinmullar
	読み込まれた画像を指定の枠内に縮小して収める．
	
	引数:
		imgObj := 処理対象となる画像オブジェクト
		timgXmax := 横サイズ
		timgYmax := 縦サイズ
	返値:
		常に True
*/
function AdjustImage( imgObj, timgXmax, timgYmax ){
	var x;
	var y;
	
	with( imgObj ){
		if( width > timgXmax ){		// 横 timgXmaxpx以内におさめる．
			height = height * ( timgXmax / width );
			width = timgXmax;
		}
		if( height > timgYmax ){		// 縦 timgYmaxpx以内におさめる．
			width = width * ( timgYmax / height );
			height = timgYmax;
		}
	}
	
	return(true);
}



/*
	2004/04/13/Tu: T.Schinmullar
	「ショッピングカートに入れる」ボタンを表示する
	
	引数:
		sizesw := 表示するボタンの種類( "LARGE" | "SMALL" )
		pid := 商品ID
*/
function WriteIntoCart( sizesw, pid ){
	var ddesc = new String;
	var wd;
	var imgw;
	var imgh;
	var imgSrc = "/premo/shop/img/intocart.gif";
	var intoCartCgi = "/cgi-bin/premo/sc/intocart.cgi?PID=";

	switch( sizesw ){
		case "LARGE":
			ddesc = "ショッピングカートに入れる";
			wd = 15;
			imgw = 31;
			imgh = 24;
			break;
		case "SMALL":
			ddesc = "カートに入れる";
			wd = 9;
			imgw = 19;
			imgh = 14;
			break;
	}

	document.write( "<div style='text-align: right; vertical-align: baseline;'><div class='cssIntoCart' style='width: " + wd + "em;'><a href='" + intoCartCgi + pid + "'><img src='" + imgSrc + "' class='cssIntoCart' style='width: " + imgw + "px; height: " + imgh + "px;'>" + ddesc + "</a></div></div>\n");

	return(true);
}


/*
	2004/04/13/Tu: T.Schinmullar
	陳列棚に商品を並べて表示する．
*/
function WriteRegularShowcase(){
	var p;
	var f;
	var fldCnt = 0;
	var fldPos = 3;		// 何列のテーブルにするか
	
	with( document ){
		write('<table class="cssRegularShowcase">');
		for(p=0; p<=prosum; p++ ){
			fldCnt++;
			
			if( fldCnt == 1 ){		// 行のはじまり
				write('<tr class="cssRegularShowcase">');
			}
			
			write('<td class="cssRegularShowcase">');
				write('<div class="cssProductName">');
					write( lstProductName[p] );
				write('</div>');
				write('<img class="cssProductImage" src="/premo/shop/html/showcase/img/' + lstProductImage[p] + '" onload="AdjustImage(this, 40, 50);">');
				write('<div class="cssProductDesc">');
					write(lstProductDesc[p]);
						WriteDispDetail( lstProductID[p] );
					write('</div>');
				write('</div>');
				write('<script type="text/javascript" language="JavaScript">WriteIntoCart("SMALL", "' + lstProductID[p] + '");</script>');
				write('<div style="clear: both;"></div>');
			write('</td>');
			
			if( fldCnt == fldPos ){		// 行のおわり
				fldCnt = 0;
				write('</tr>');
			}
			
			if(p == prosum){		// 最後の商品だ……
				if(fldCnt < fldPos){		// 折り返す場所より手前で並べるべき商品が終わってしまった……
					for(f=fldCnt+1; f<=fldPos; f++){
						write('<td></td>');
					}
					write('</tr>');
				}
			}
		}
		write('</table>');
	}
	
	return(true);
}



/*
	2004/04/14/We: T.Schinmullar
	商品の "詳細画面へアイコン" を描く
	引数:
		pid := 商品ID
*/
function WriteDispDetail( pid ){
	document.write("<a href='#' onclick='MoveToDispDetail(\"" + pid + "\");'>&gt;&nbsp;詳細</a>");
	return(true);
}



/*
	2004/04/16/Fr: T.Schinmullar
	商品の詳細画面を開く
	引数:
		pid := 商品ID
*/
function MoveToDispDetail( pid ){
	SetCookie("PID", pid);
	location.href="/premo/shop/html/showcase/detail.html";
	return(true);
}


/*
	2004/04/15/Th: T.Schinmullar
	Cookieをセット
	
	引数:
		kname := 要素名
		kval := 要素値
	返値:
		常に真
*/
function SetCookie( kname, kval ){
	document.cookie = kname + "=" + kval + ";";
//	document.cookie = kname + "=" + kval + "; expires=Wed, 31 Dec 2031 23:59:59 GMT;";
	return(true);
}



/*
	2004/04/15/Th: T.Schinmullar
	Cookieを取得
	
	引数:
		kname := 取得すべき要素の要素名
	返値:
		取得すべき要素の値
*/
function GetCookie( kname ){
	var cook = ' ' + document.cookie;
	var cc = new Array;
		cc = cook.split(';');
	
	var c;
	for(c=0; c<=cc.length-1; c++){
		if( cc[c].indexOf( ' ' + kname + '=' ) == 0 ){
			return( unescape( cc[c].substr(kname.length+2) ) );
		}
	}
	
	return('');
	
}



/*
	2004/04/16/Fr: T.Schinmullar
	商品の詳細を表示する
	
	引数:
		pid := 商品ID
*/
function DispProductDetail( pid ){

	document.write('<!--#include virtual="/premo/shop/detail/' + pid + '.txt" -->');
	
	
	
	
	
	return(true);
}


/*
	2006/04/13/Th: iwami
	サブウィンドウを開く
*/

function winOpen(winName,url,W,H){
  var WinD11=window.open(url,winName,'scrollbars=0,alwaysraised=yes,width='+W+',height='+H+'');
  WinD11.document.close()
}


/*
	2006/04/13/Th: iwami
	LeftPane
*/

			var frm = document.MAINFORM;
			
			// ユーザのIDを見せる
			function ShowIdJob(){
				document.write('ID: ' + GetCookie('ID') );
				return(true);
			}
			
			
			// 指定された名前のブロックを開く
			function OpenBlock( bName ){
				var i;
				
				with(document){
					for(i=0; i<=all.length-1; i++){
						with(all[i]){
							if(name == bName){ style.display = 'block'; break;}
						}
					}
				}
				
				return(true);
			}

			// 別窓を開く
			function winOpen2(winName,url,W,H){
 		 var 			WinD2=window.open(url,winName,'scrollbars=yes,alwaysraised=yes,width='+W+',height='+H+'');
  WinD2.document.close()
}


