/**
 * 製品一覧の表示
 * @param element 描画先タグ要素。ここで指定した要素のinnerHTMLとして処理されます。
 * @param productListVo のサーバーから取得した製品情報
 * @param baseURL 製品詳細等のリンク先のベースURL(通常はhttp://find-it.jp)
 * @param isLinkTargetBkank リンクを"target=_blank"にするならば真
 */
function showProductList(element, productListVo, baseURL, isLinkTargetBkank) {
	var target = ' ';
	var showLine = "";
	var productIds = null;
	if (isLinkTargetBkank) {
		target = ' target="_blank" ';
	}

	if(productListVo == null || productListVo.productList.length == 0) {
		showLine += '<table class="item_list">' + "\n";
		showLine += '        <div class="noresult">' + "\n";
		showLine += '          <p>ご指定の検索条件に該当する製品はありませんでした。</p>' + "\n";
		showLine += '          <p>以下のことをお試しください。</p>' + "\n";
		showLine += '            <ul>' + "\n";
		showLine += '              <li>キーワードに間違いが無いか確認してください。</li>' + "\n";
		showLine += '              <li>スペックなどの絞り込み条件をご確認ください。</li>' + "\n";
		showLine += '              <li>カテゴリーを指定して絞り込んでいる場合、より上位のカテゴリーで検索するか、その他のカテゴリーへ移動してください。</li>' + "\n";
		showLine += '            </ul>' + "\n";
		showLine += '        </div>' + "\n";
		showLine += '</table>' + "\n";
	} else {
		productList = productListVo.productList;
		/** 全て選択チェックボックス */
		showLine += '        <div class="list_top clearfix">' + "\n";
		showLine += '        <div class="all_request clearfix" id="linkDocumentsArea-Top">' + "\n";
		showLine += '          <div class="check">' + "\n";
		showLine += '          	<input type="checkbox" class="yui-dt-checkbox" name="allCheck" onclick="BoxChecked(this);" />すべてを選択' + "\n";
		showLine += '          </div>' + "\n";
		showLine += '          <div class="text">選択した製品をまとめて</div>' + "\n";
		showLine += '          <div class="button">' + "\n";
		showLine += '              <span class="yui-button yui-link-button">' + "\n";
		showLine += '              	<span class="first-child">' + "\n";
		showLine += '              		<a class="link-button request_doc" ' + target + 'shape="rect" href="'+ baseURL + productListVo.documentRequestHref + '" id="linkDocuments-Top" onclick="return ParamSet(this)">' + "\n";
		showLine += '              		<span>一括資料請求</span></a>' + "\n";
		showLine += '              	</span>' + "\n";
		showLine += '              </span>' + "\n";
		showLine += '          </div>' + "\n";
		showLine += '        </div>' + "\n";
		showLine += '      </div>' + "\n";
		showLine += '' + "\n";

		showLine += '<table class="item_list">' + "\n";
		/** 製品一覧 */
		for (var i = 0; i < productList.length; i++) {

			p = productList[i];

			//開く
			showLine += '            <tbody><tr class="firstline"><td colspan="1" class="checkbox" rowspan="2">';
			if(p.isEnableAd) {
				showLine += '              <input type="checkbox" id="productId" name="productId" value="'+ p.productId+ '" onclick="ClickCheck();"/>' + "\n";
			}

			showLine += '              </td><td colspan="1" class="img" rowspan="1" valign="top">' + "\n";
			showLine += '              <span class="item_wrapper">' + "\n";

			//製品イメージ
			showLine += '                  <span class="item_img">' + "\n";
			if(p.isProductLogoExist) {
				showLine += '				<a target="_blank" href="'+ baseURL + p.productLogoLHref +'" id="linkProductLogoL"><img id="pathProductLogoS" src="'+ baseURL + p.productLogoSHref+'" alt="製品image" /></a>' + "\n";
			} else {
				showLine += '				<img src="'+ baseURL +'/common/images/product_image80x80.png" alt="製品image" />' + "\n";
			}
			showLine += '                  </span>' + "\n";
			showLine += '                  </span>' + "\n";
			showLine += '                  </td>';
			showLine += '                  <td colspan="1" rowspan="1" valign="top">'

			//製品所属カテゴリ
			showLine += '<p class="category">';
			for (var j = 0; j < p.categoryList.length; j++) {
				cate = p.categoryList[j];
				showLine += '<a id="linkProductCategory" ' + target + 'shape="rect" href="'+ baseURL + cate.href +'"><span id="productCategoryName">' + cate.categoryName + '</span></a>';
				showLine += '&nbsp;;&nbsp';
			}
			showLine += '                </p>' + "\n";
			showLine += '                  <div class="item_ttl">' + "\n";
			showLine += '                    <h2>' + "\n";

			//製品名
			showLine += '                    	<a id="linkProductDetailTitle" ' + target + 'shape="rect" href="'+ baseURL + p.productHref +'">'+ p.productName +'</a>' + "\n";

			//New!!
			if(p.isNewCreatedProduct) {
				showLine += '                    	<span id="isNewCreatedProduct" style="color:red; font-size: 10px;">&nbsp;&nbsp;New!</span>' + "\n";
			} else if(p.isNewUpdatedProduct) {
				showLine += '                    	<span id="isNewUpdatedProduct" style="color:red; font-size: 10px;">&nbsp;&nbsp;update!</span>' + "\n";
			}
			showLine += '                    </h2>' + "\n";

			//プレイヤー名
			showLine += '                    <h3><a id="linkPlayer" ' + target + 'shape="rect" href="'+ baseURL  + p.playerHref + '">'+ p.playerName +'</a></h3>' + "\n";

			//スポンサーロゴ
			for (var k = 0; k < p.sponsorLogoList.length; k++) {
				spLogo = p.sponsorLogoList[k];
				showLine += '                  <span><img id="playerSpLogoSImg" src="'+ baseURL + spLogo.sponsorLogoSHref +'" alt="'+ spLogo.sponsorName +'" /></span>' + "\n";
			}


			showLine += '                  </div>' + "\n";
			//概要
			showLine += '    <p>'+ p.productNote +'</p></td><td colspan="1" rowspan="1" valign="top"><dl><dt>企業規模</dt><dd>'+ p.productTargetVolume +'</dd><dt>製品形態</dt><dd>'+ p.productType +'</dd><dt>最多導入価格帯</dt><dd>'+ p.productPriceRange +'</dd></dl></td></tr>' + "\n";

			showLine += '<tr><td colspan="3" rowspan="1" class="button">' + "\n";

			//製品詳細
			showLine += '    <span class="yui-button yui-link-button"> <span class="first-child"> <a id="linkProductDetail" class="link-button product_detail" ' + target + 'shape="rect" href="'+ baseURL + p.productHref +'"> <span>製品詳細</span> </a> </span> </span>' + "\n";
			//資料請求
			if(p.isEnableAd) {
				showLine += '      <span class="yui-button yui-link-button"> <span class="first-child"> <a class="link-button request_doc" ' + target + 'shape="rect" href="'+ baseURL +p.documentRequestHref+'" id="linkProductDoc"> <span>資料請求</span> </a> </span> </span>' + "\n";
			}
			//資料ダウンロード
			if(p.isWhitePaperExist) {
				showLine += '    <span class="yui-button yui-link-button" id="isWhitePaperExist"> <span class="first-child"> <a class="link-button white_paper" ' + target + 'shape="rect" href="'+ baseURL +p.wpRequestHref+'"  id="linkProductPageWp"> 資料ダウンロード </a> </span> </span>' + "\n";
			}
			//問合せ
			if(p.isEnableAd) {
				showLine += '            <span class="yui-button yui-link-button"> <span class="first-child"> <a class="link-button pvt_message" ' + target + 'shape="rect" href="'+ baseURL +p.pMessageHref+'" id="linkProductPm"> <span>問合せ</span> </a> </span> </span>' + "\n";
			}
			//ブックマーク
			showLine += '    <span class="yui-button yui-link-button"> <span class="first-child"> <a id="linkProductBm" class="link-button bookmark"  ' + target + 'shape="rect" href="'+ baseURL +p.bookmarkHref+'"> <span>ブックマーク</span> </a> </span> </span>' + "\n";

			//閉じる
			showLine += '    </td></tr></tbody>' + "\n";
		}
		showLine += '</table>' + "\n";
		showLine += '        <div class="list_bottom clearfix">' + "\n";
		showLine += '        <div class="all_request clearfix" id="linkDocumentsArea-Under">' + "\n";
		showLine += '          <div class="check">' + "\n";
		showLine += '          	<input type="checkbox" class="yui-dt-checkbox"  name="allCheck" onclick="BoxChecked(this);" />すべてを選択' + "\n";
		showLine += '          </div>' + "\n";
		showLine += '          <div class="text">選択した製品をまとめて</div>' + "\n";
		showLine += '          <div class="button">' + "\n";
		showLine += '              <span class="yui-button yui-link-button">' + "\n";
		showLine += '              	<span class="first-child">' + "\n";
		showLine += '              		<a class="link-button request_doc"  ' + target + 'shape="rect" href="'+ baseURL + productListVo.documentRequestHref +'?" id="linkDocuments-Under" onclick="return ParamSet(this)">' + "\n";
		showLine += '              		<span>一括資料請求</span></a>' + "\n";
		showLine += '              	</span>' + "\n";
		showLine += '              </span>' + "\n";
		showLine += '          </div>' + "\n";
		showLine += '        </div>' + "\n";
		showLine += '        </div>' + "\n";
	}
	element.innerHTML = showLine;
}
/**
 * 「全てを選択」チェックボックスの挙動
 * @param obj
 * @return
 */
function BoxChecked(obj){
	if(obj.checked){
		check = true;
		for(count = 0; count < document.getElementsByName('allCheck').length; count++){
			document.getElementsByName('allCheck')[count].checked = check;	//チェックボックスをON/OFFにする
		}
	}else{
		check = false;
		for(count = 0; count < document.getElementsByName('allCheck').length; count++){
			document.getElementsByName('allCheck')[count].checked = check;	//チェックボックスをON/OFFにする
		}
	}
	for(count = 0; count < document.getElementsByName('productId').length; count++){
		document.getElementsByName('productId')[count].checked = check;	//チェックボックスをON/OFFにする
	}
	ClickCheck();
}
/**
 * 一括資料請求の実行
 * @param obj
 * @return
 */
function ParamSet(obj){
	var param = "?";
	var numChecked = 0;
	for(count = 0; count < document.getElementsByName('productId').length; count++){
		if( document.getElementsByName('productId')[count].checked ){
			param += '&productId='+ document.getElementsByName('productId')[count].value;
			numChecked++;
		}
	}
	if (numChecked > 0) {
		obj.href += param;
		return true;
	}
	return false;
}
/**
 * 資料請求対象が指定されない限り、一括資料請求ボタンは押せない。
 * @return
 */
function ClickCheck(){
	var numChecked = 0;
	for(count = 0; count < document.getElementsByName('productId').length; count++){
		if( document.getElementsByName('productId')[count].checked ){
			numChecked++;
		}
	}
	if (numChecked > 0) {
		//ボタンを押せるようにして、色を黒に
		document.getElementById('linkDocuments-Top').disable = false;
		document.getElementById('linkDocuments-Under').disable = false;
		document.getElementById('linkDocuments-Top').style.color = "#000000";
		document.getElementById('linkDocuments-Under').style.color = "#000000";
	} else {
		//ボタンを押せなくして、色を灰色に
		document.getElementById('linkDocuments-Top').disable = true;
		document.getElementById('linkDocuments-Under').disable = true;
		document.getElementById('linkDocuments-Top').style.color = "#bbbbbb";
		document.getElementById('linkDocuments-Under').style.color = "#bbbbbb";
	}
}
/**
 * 資料請求できる製品が無い場合には、一括資料請求欄を消す。
 * @return
 */
function InitCheckUpdate() {
	ClickCheck();
	if (document.getElementsByName('productId').length == 0) {
		document.getElementById('linkDocumentsArea-Under').style.display='none';
		document.getElementById('linkDocumentsArea-Top').style.display='none';
	}
}

