// JavaScript Document
// jquery config


// ニュースリリースの初期フィルタリング（トップページ）
function InitShow(){
	//クッキー取得
	ckl = CookieChk("CKline");
	catlst = CookieChk("CKcatlist");
//alert(catlst);
    //2008.09.05 保存してあるクッキーの変換作業
    wk = "";
    if ( catlst.length == 5 ) { //古いまま
        if ( catlst.substr(0,1) == "1" ) {
            wk = "1000000";
        } else {
 		    aryWK = new Array(7); //編集領域をクッキーより初期値編集
    		for ( i=0;i<catlst.length;i++ ) {
			    if ( i == 0 ) {
				    aryWK[0] = "0";
			    } else {
                    switch ( i )
                    {
                        case 1://旧NEWS
                            aryWK[4] = catlst.substr(i,1);
                            break;
                        case 2://旧IR
                            aryWK[2] = catlst.substr(i,1);
                            break;
                        case 3://旧EVENT
                            aryWK[5] = catlst.substr(i,1);
                            break;
                        case 4://旧Recruit
                            aryWK[6] = catlst.substr(i,1);
                            break;
                    }
                }
            }
		    aryWK[1] = "0";//新ニュースリリース
		    aryWK[3] = "0";//CSR
		    for ( i=0;i<7;i++ ) {
			    wk += aryWK[i];
            }
       }
       catlst = wk;
       setCookie("CKcatlist", catlst, d);

    } else {

	    if ( catlst.length == 6 ) { //古いまま
	        if ( catlst.substr(0,1) == "1" ) {
	            wk = "1000000";
	        } else {
	 		    aryWK = new Array(7); //編集領域をクッキーより初期値編集
	    		for ( i=0;i<catlst.length;i++ ) {
				    if ( i == 0 ) {
					    aryWK[0] = "0";
				    } else {
	                    switch ( i )
	                    {
	                        case 1://旧NEWS
	                            aryWK[1] = catlst.substr(i,1);
	                            break;
	                        case 2://旧IR
	                            aryWK[2] = catlst.substr(i,1);
	                            break;
	                        case 3://旧INFO
	                            aryWK[4] = catlst.substr(i,1);
	                            break;
	                        case 4://旧EVENT
	                            aryWK[5] = catlst.substr(i,1);
	                            break;
	                        case 5://旧Recruit
	                            aryWK[6] = catlst.substr(i,1);
	                            break;
	                    }
	                }
	            }
			    aryWK[3] = "0";//CSR
			    for ( i=0;i<7;i++ ) {
				    wk += aryWK[i];
	            }
	       }
	       catlst = wk;
	       setCookie("CKcatlist", catlst, d);
	    }
	}

	//記事の表示を変更
	ShowArticle(ckl,catlst);

	return true;
}
$j(document).ready(InitShow);

function ShowArticle(ckl,catlst){

	aryDispFlg = new Array();
	aryCatId = new Array();
	//aryIX = new Array("0","5","2","1","3","4"); //カテゴリIDXを設定
	aryIX = new Array("0","5","2","6","1","3","4"); //カテゴリIDXを設定 //2010.06.23 "6"(CSRを追加)
	var showclass;

	$j("dt","#news-top").each(function(i) {
		showclass = $j("#"+"dt"+i).attr("class");
		switch ( showclass )
		{
			case "info":
				aryCatId.push("1");
				break;
			case "ir":
				aryCatId.push("2");
				break;
			case "event":
				aryCatId.push("3");
				break;
			case "recruit":
				aryCatId.push("4");
				break;
			case "news":
				aryCatId.push("5");
				break;
			case "csr":
				aryCatId.push("6");
				break;
		};
	})

	writecnt = 0;
	for ( i=0;i<aryCatId.length;i++)
	{
		if ( writecnt >= ckl ) {
			aryDispFlg.push("0");
			continue;
		}
		if ( catlst.substr(0,1) == "1" ) {
			aryDispFlg.push("1");
			writecnt++;
		} else {
			//j = aryCatId[i];
			j = 0;
			for ( k=0;j<aryIX.length;k++ ) {
			    if ( aryIX[k] == aryCatId[i] ) {
			        j = k;
			        break;
                }
			}
			if ( catlst.substr(j,1) == "1" ) {
				aryDispFlg.push("1");
				writecnt++;
			} else {
				aryDispFlg.push("0");
			}
		}
	}
	$j("dt","#news-top").each(function(i) {
		if(aryDispFlg[i] == "1"){
			$j(this).css("display","block");
		}else{
			$j(this).css("display","none");
		}
	})
	$j("dd","#news-top").each(function(i) {
		if(aryDispFlg[i] == "1"){
			$j(this).css("display","block");
		}else{
			$j(this).css("display","none");
		}
	})
	
	for ( i=0;i<6;i++ ) {
		if ( catlst.substr(i,1) == "1" ) {
			$j("#"+"toplcmenu"+aryIX[i]).attr("checked", true);
		} else {
			$j("#"+"toplcmenu"+aryIX[i]).attr("checked", false);
		}
	}

	$j("#showline"+ckl).attr("selected", true);

	return true;
}

