// 絞込み検索
function resetAdditional(){
	for(i=0; i<6; i++){
		document.searchInputForm.elements["refineStr"+i].value = "";
	}
}


function inputSync(tarObj,syncInputNum){
	document.searchInputForm.elements["refineStr"+syncInputNum].value = tarObj.value;
}

function transInput(tarObj){
	
	function inputRefineValue(){
		for(i=0; i<3; i++){
			if(!document.searchInputForm.elements["refineStr"+i].value){
				document.searchInputForm.elements["refineStr"+i].value = tarWord;
				flag =true;
			}
			
			if(flag) break;
		}
		
		flag = false;
		
		for(i=3; i<6; i++){
			if(!document.searchInputForm.elements["refineStr"+i].value){
				document.searchInputForm.elements["refineStr"+i].value = tarWord;
				flag = true;
			}
			
			if(flag) break;
		}
	}
	
	
	flag = false;
	tarWord = tarObj.innerHTML.toLowerCase();
	if(tarWord.indexOf("/>") !== -1){
		tarWord = tarWord.replace("/>",">");
	}
	
	if(tarWord.indexOf("br") !== -1){
		tarWord = tarWord.replace("<br>(",",");
		tarWord = tarWord.replace(")","");
		tarWordArray = tarWord.split(",");
		
		for(h=0; h<tarWordArray.length; h++){
			flag = false;
			tarWord = tarWordArray[h];
			inputRefineValue();
		}
	}else{
		inputRefineValue();
	}

}



// キーワード軍表示
function showKeyword(tarAnchor){
	tarObj = document.getElementById('topKeywordList');
	
	if(tarAnchor.className == "closed"){
		tarObj.style.display = "block";
		tarAnchor.className = "open";
		tarAnchor.innerHTML = "<img src=\"/precedent/img_cmn/removeMarker.png\" />絞込み検索キーワード候補一覧を閉じる（キーワードをクリックしてみてください）";
	}else if(tarAnchor.className == "open"){
		tarObj.style.display = "none";
		tarAnchor.className = "closed";
		tarAnchor.innerHTML = "<img src=\"/precedent/img_cmn/addMarker.png\" />絞込み検索キーワード候補一覧を開く";
	}
}




// tabインタフェース
Event.observe(window, 'load', function(){
  var start = new TabMaker();
  start.create();
});

var TabMaker = Class.create()
TabMaker.prototype = {
  initialize: function() {
    this.tabLnegth = document.getElementsByClassName('tab').length;
  },
  create: function() {
    var menu = new TabIndex();
    for (var i = 0; i < this.tabLnegth; i++) {
      menu.appendTab(new Tab('Tab' + i, (i==0)));
    }
    menu.setTab();
  }
}

var Tab = Class.create();
Tab.prototype = {
  initialize: function(name, open) {
    this.name = name;
    this.page = name + 'Page';
    this.open = (open);
  },
  styleTab: function() {
    if (this.open)
      this.setStyle('visible', '', 'open');
    else
      this.setStyle('hidden', 'absolute', 'close');
    this.open = false;
  },
  setStyle: function(visibility, position, className){
    var page = $(this.page).style;
    var name = $(this.name);
    page.visibility = visibility;
    page.position = position;
    name.className = className;
  }
}

var TabIndex = Class.create();
TabIndex.prototype = {
  initialize : function() {
    this.last = 0;
    this.tabs = new Array();
  },
  getTabAt : function(index) {
    return this.tabs[index];
  },
  appendTab : function(tab) {
    this.tabs[this.last] = tab;
    document.getElementsByClassName('tab')[this.last].id = tab.name;
    document.getElementsByClassName('tabBox')[this.last].id = tab.page;
    this.last++;
    $(tab.name).onclick = function(){
      tab.open = true;
      this.setTab();
    }.bind(this);
  },
  getLength : function() {
    return this.last;
  },
  each : function(func) {
    for (var i = 0; i < this.getLength(); i++) {
      func(this.getTabAt(i));
    }
  },
  setTab: function() {
    this.each(function(tab) {
        tab.styleTab();
    });
  }
};





// テキストボックスに事前に文字を入れる
var input1 = new inputDefault(document.getElementById('portfolioName'), '新しいポートフォリオ名を入力してください');
input1.set();
