// Friday, March 13, 2009 G1SYSTEMS INC OKTEI


/*===============================================================================
	トップページのエフェクト処理
-------------------------------------------------------------------------------*/

// 情報リストのクリック時の処理

function InfoSection(link)
{
	ColoredSection(link);
	// WhiteboardSection(link);
}

// インフォメーションのエフェクト処理 jQueryを利用

var currentInfo = "splash-line"; // The default loaded section on the line
var infoLine = "-line";

function ColoredSection(link)
{
	if (currentInfo == link) {
		return;
	}
	lastInfo = currentInfo;
	currentInfo = link;

	// Change the line highlight.

    coloredInfo = currentInfo.split("-")[0] + infoLine;
    document.getElementById(coloredInfo).className = "active";

    if (lastInfo) {
	    colorlessInfo = lastInfo.split("-")[0] + infoLine;
	    if(colorlessInfo != "splash-line"){document.getElementById(colorlessInfo).className = "inactive";}
	}

}

// ホワイトボードのエフェクト処理 jQueryを利用

var currentWhiteboard = "splash-whiteboard"; // The default loaded section on the whiteboard
var whiteboardPane = "-whiteboard";

function WhiteboardSection(link)
{
	if (currentWhiteboard == link) {
		return;
	}
	lastWhiteboard = currentWhiteboard;
	currentWhiteboard = link;

	// Change the whiteboard.

	if(lastWhiteboard == "splash-whiteboard"){
		$("#whiteboard").slideDown("slow");
	}

    roolingWhiteboard = currentWhiteboard.split("-")[0] + whiteboardPane;
    //document.getElementById(roolingWhiteboard).className = "active";
    //$("#"+roolingWhiteboard).slideDown("slow");
    $("#"+roolingWhiteboard).fadeIn("slow");

    if (lastWhiteboard) {
	    roolingWhiteboard = lastWhiteboard.split("-")[0] + whiteboardPane;
	    if(roolingWhiteboard != "splash-whiteboard"){
	    	//document.getElementById(roolingWhiteboard).className = "invisible";
	    	//$("#"+roolingWhiteboard).slideUp("slow");
	    	$("#"+roolingWhiteboard).hide();
	    }
	}
}

/*===============================================================================
	検索インデックスの処理
-------------------------------------------------------------------------------*/

	//フィルター条件抽出
	var checkstr;
	var currentstr;

	var newmap;

	function filterConditions(side,path){

		newmap = 0;

		var f = document.searchFilter;
		var c = "";
		var s = "";
		if(!path){path="";}

		if(!side){ //検索ページからの呼び出し以外
		for (i=0; i<f.length; i++){
		if(f.elements[i].tagName=="SELECT" && f.elements[i].value){
				c += $('#' + f.elements[i].id).val() + ",";
			}
		}
		}

		s = document.getElementById('search').value;
		//s = encodeURIComponent(s);
		if(s == "検索" || !s){s = "";}
		checkstr = c + s;
		if((c || s)&&(checkstr != currentstr)){//alert("?s=" + s + "&c=" + c);
		
			if ($("#res").is(":visible")) {$("#res").hide();}
			$("#res").html("");
			if ($("#page").is(":visible")) {$("#page").hide();}
			if(side){ //サイドナビからの呼び出し
				if ( $("body").is(".mt-main-index") ){
					$("#ta-towa").hide();
					$("#information").hide();
				}
				$("#welcome").hide();
				$("#welcome-block").hide();
				$("#col-left .columnwrap").hide();
				$("#contentarea").addClass("col-left-bg-white");
			}

			$("#indicator").show();
		
			//検索データの読み込み　$.get("search-res.php?s=" + s + "&c=" + c,
			$.get(path+"search-res.php", { s: s, c: c },
						function(data){
							$("#indicator").hide();
							$("#res").html(data);
							currentstr = c + s;	
						}

			);
		}

		if ($("#res:first").is(":hidden")) {
			if(side && currentstr){
				if ( $("body").is(".mt-main-index") ){
					$("#ta-towa").hide();
					$("#information").hide();
				}
				$("#welcome").hide();
				$("#welcome-block").hide();
				$("#col-left .columnwrap").hide();
				if ( $("body").is(".layout-3column") ){
					$("#contentarea").addClass("col-left-bg-white");
				}
				$("#res").fadeTo("slow", 1);
			} else {
				$("#res").fadeTo("slow", 1);
			}
		}

	}

	//resを閉じるボタン $('#res').fadeTo('slow', 0);$('#res').hide();
	function closeres(){
		$('#res').hide();
		if ( $("body").is(".mt-main-index") ){
			$("#ta-towa").show();
			$("#information").show();
		}
		$("#welcome").show();
		$("#welcome-block").show();
		$("#col-left .columnwrap").fadeTo("slow", 1);
		if ( $("body").is(".layout-3column") ){
			$("#contentarea").removeClass("col-left-bg-white");
		}
		
	}

	//フィルター条件表示
	function filterConditionsDisplayVals() {
		var f = document.searchFilter;
		var s = document.getElementById('search').value;
		if(s == "検索" || !s){s = "";}
		var str = "";
    	for (i=0; i<f.length; i++){
			if(f.elements[i].tagName=="SELECT" && f.elements[i].value){
				$("#reset-" + f.elements[i].id.split("-")[1]).removeClass("hide");
	    		str += '<span class="vals-text">';
				$('#' + f.elements[i].id + " option:selected").each(function () { str += $(this).text() + '<span class="t-ccc"> + </span>'; });
				str = str.replace(/<span class="t-ccc"> \+ <\/span>$/, "");
				//alert(str);
				str += "</span>";
			} else if(f.elements[i].tagName=="SELECT" && !f.elements[i].value) {
			$("#reset-" + f.elements[i].id.split("-")[1]).addClass("hide");
			}
		}
		if(str){
			$("#display-vals").html(str);
		} else {
			$("#display-vals").html("")	
		}
		if(!s && !str){
			$("#reset-all").addClass("hide");
			$("#reset-input-search").addClass("hide");
		} else {
			$("#reset-all").removeClass("hide");
			if(!s){$("#reset-input-search").addClass("hide");}
		}
	}
	
	//フィルタークリアー
	function clearFilter(id){
		$("#filter-"+id).children().each(function(i){ $(this).removeAttr('selected') });
		filterConditionsDisplayVals();
		$("#filter-"+id).focus();
	}

	//オールリセット
	function allReset(){
		document.searchFilter.reset();
		document.searchWord.reset();
		document.searchWord.search.focus();
		filterConditionsDisplayVals();
	}

/*===============================================================================
	ブログ記事（カタログアイテムページのタグ検索の読み込み）
-------------------------------------------------------------------------------*/

	var currenttag="";
	function tag(geturl){
		if(currenttag != geturl){
			$("#indicator-tag").show();
			$("#entry-tags-content").fadeTo("slow", 0);
		
			$.get(geturl,
						function(data){
							$("#indicator-tag").hide();
							$("#entry-tags-content").html(data);
							$("#entry-tags-content").fadeTo("slow", 1);
						}
                    
			);
			currenttag = geturl;
		}
	}

/*===============================================================================
	フォントサイズの変更処理
-------------------------------------------------------------------------------*/

// Font size change

var rememberSize = readCookie("fontsize"); // The remember cookie fontsize
var currentSize = "small"; // The default loaded fontsize
function ChangeFontSize(fontsize)
{
	if (currentSize == fontsize) {
		return;
	}
	currentSize = fontsize;
	if ( !$("body").is(".mt-search") ){
	document.getElementById('col-left').className = currentSize;
	document.getElementById('thirdlynav').className = currentSize;
	document.getElementById('menu').className = currentSize;
	}
	document.getElementById('footer').className = currentSize;
	createCookie("fontsize", currentSize, 365);

}

// 保存されているサイズを適用

var rememberSize = readCookie("fontsize"); // The remember cookie fontsize
var currentSize = "small"; // The default loaded fontsize
function ChangeFontSize(fontsize)
{
	if (currentSize == fontsize) {
		return;
	}
	currentSize = fontsize;
	if ( !$("body").is(".mt-search") ){
	document.getElementById('col-left').className = currentSize;
	document.getElementById('thirdlynav').className = currentSize;
	document.getElementById('menu').className = currentSize;
	}
	document.getElementById('footer').className = currentSize;
	createCookie("fontsize", currentSize, 365);

}

/*===============================================================================
	クッキー操作
-------------------------------------------------------------------------------*/

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

/*===============================================================================
	レディファンクション
-------------------------------------------------------------------------------*/
$(document).ready(function(){
    
    $("#admin").click(function () {
    	if ($(".admin-edit-link:first").is(":hidden")) {
			$(".admin-edit-link").show("slow");
		} else {
			$(".admin-edit-link").hide("slow");
		}
    });

});

/*===============================================================================
	オンロードファンクション
-------------------------------------------------------------------------------*/

var timerID;
window.onload = function() {
	
	$('#tabsjj').tabsj({event: 'click'});

	//サイドメニューのタブ
	$('#tabsj').tabsj({event: 'click'});

	//alert("window.onload");

	//トップページの読み込み処理（mt-main-index）
	if ( $("body").is(".mt-main-index") ){
		//alert("hasClass = mt-main-index");
		$("#alpha-info").slideDown("slow"); // 情報リスト用 エフェクト jQuery codaにスプラッシュのifを設定　これを外すときは削除する事
		timerID = setTimeout("ScrollSection('alpha-pane', 'scroller', 'splash-pane')",15000);
	}

	//検索ページの読み込み処理（mt-search-index）
	if ( $("body").is(".mt-search") ){
		//alert("hasClass = mt-search-index");
		filterConditionsDisplayVals();
	}

	//クッキーに保存されている文字サイズの変更を適用する
	if (rememberSize != "small" && rememberSize != null){
		ChangeFontSize(rememberSize);
	}

	//カタログページの
	/*if ( $("body").is(".mt-catalog") ){
		$("#indicator").hide();
		$("#indicator-tag").hide();
	}*/

	//トピックページの
	/*if ( $("body").is(".mt-topics") ){
		$("#indicator").hide();
		$("#indicator-tag").hide();
	}*/

	//検索フィール出現文字の操作
//if ( $("body").is(".mt-search") ){
	//$("#indicator").hide();
	var sfstr = "検索";
	var sf=document.getElementById('search');
	var sel=document.getElementById('searchButton');
	//sf.value=sfstr;
	sf.onfocus=function(){
		if(sf.value==sfstr){
			sf.value="";
			sf.style.color="#000";
		}else{
			if($("body").is(".mt-search")){
				$("#reset-input-search").removeClass("hide");
			}
		}
	}
	sf.onblur=function(){
		if(sf.value==""){
			sf.value=sfstr;
			sf.style.color="#999";
		}else{
			if($("body").is(".mt-search")){
				$("#reset-input-search").removeClass("hide");
			}
		}
	}
	sf.onkeydown=function(){
		if(sf.value==""){
			//sf.value=sfstr;
			//sf.style.color="#999";
			if($("body").is(".mt-search")){
				$("#reset-input-search").addClass("hide");
			}
		}else{
			if($("body").is(".mt-search")){
				$("#reset-input-search").removeClass("hide");
			}
		}
	}
//}
	//右カラムの検索フィール出現文字の操作
	/*var sfstr = "検索";
	var sf=document.getElementById('search');
	var sel=document.getElementById('searchButton');
	//sf.value=sfstr;
	sf.onfocus=function(){if(sf.value==sfstr){sf.value="";sf.style.color="#000";}};
	sf.onblur=function(){if(sf.value==""){sf.value=sfstr;sf.style.color="#999";}};
	sel.onclick=function(){document.sitesearch.submit();};*/

	//カタログページの検索フィール出現文字の操作（予定）
	/*var pfstr = "検索";
	var pf=document.getElementById('sideSearch');
	var fpl=document.getElementById('sideSearchButton');
	//pf.value=pfstr;
	pf.onfocus=function(){if(pf.value==pfstr){pf.value="";pf.style.color="#000";}};
	pf.onblur=function(){if(pf.value==""){pf.value=pfstr;pf.style.color="#999";}};
	fpl.onclick=function(){document.productssearch.submit();};*/

	//sel.onclick=function(){if(sf.value!=sfstr){document.sitesearch.submit();}};
	//fpl.onclick=function(){if(pf.value!=pfstr){document.sitesearch.submit();}};

}











