var webroot = "";
var blogfile = webroot + "tintinblog.php";

function show_advance_search_box()
{
	if (document.getElementById('advanced_search_box').style.display == 'none')
	{
		document.getElementById('show_advance_search_label').innerHTML = '隱藏搜尋選項';
		document.getElementById('advanced_search_box').style.display = 'block';
	}
	else
	{
		document.getElementById('show_advance_search_label').innerHTML = '顯示搜尋選項';
		document.getElementById('advanced_search_box').style.display = 'none';
	}
}

function ActiveDropDownList(menuBar) // for use for top frame
{
  menuBar.onmouseover = function(){
    menuBar.getElementsByTagName('span')[1].style.display = 'block';  
  }
  menuBar.onmouseout = function(){
    menuBar.getElementsByTagName('span')[1].style.display = 'none'; 
  }
}

function ActiveUserDropDownList(menuBar) // for use for user block
{
  menuBar.onmouseover = function(){
    menuBar.getElementsByTagName('span')[1].style.display = 'block';  
  }
  menuBar.onmouseout = function(){
    menuBar.getElementsByTagName('span')[1].style.display = 'none'; 
  }
}

function OnSelectChange(selecter)
{
	if (selecter.selectedIndex == 0)
	{
		document.getElementById('form1').action = '?module=piano_sheet';
		document.getElementById('form1').target = '_self';
	}
	else if (selecter.selectedIndex == 1)
	{
		document.getElementById('form1').action = '/include/google_search.php';
		document.getElementById('form1').target = '_blank';
		if (document.getElementById('advanced_search_box').style.display = 'block')
		{
			document.getElementById('advanced_search_box').style.display = 'none';
			document.getElementById('search_username').value = '';
			document.getElementById('show_creative').checked = false;
			document.getElementById('media').checked = false;
		}
	}
}

function convert_keyword() // called in topframe.php
{
	document.getElementById('word').value = convert(1, document.getElementById('word').value);
}

function convert(zcs, word)
{
	switch ( zcs ) 
	{ 
		case 1:
			return traditionalized(word); // traditionalized is defined in conve.js
		case 0:
			return simplized(word); // simplized is defined in conve.js
	}
}

/**
* Submit Search Form
*/
function check(pgnum,class_id,order,word,user_id,show_creative,type,media,forum_id,word_code,search_username) 
{	
	if(pgnum=='1') pgnum= '';
	var str = blogfile + "?module=piano_sheet";
	if(pgnum!='') str += "&pgnum=1";
	if(class_id!='') str += "&class_id="+class_id;
	if(order!='') str += "&order="+order;
	if(word!='') 
	{
		str += "&word="+ window.encodeURIComponent(word);
	}
	if(user_id!='') str += "&user_id="+user_id;
	/*
	else
	{
		if(document.getElementById('search_user_id').value != '')
			str += "&user_id="+document.getElementById('search_user_id').value;
	}
	*/
	if(type!='') str += "&type="+type;
	if(show_creative!='') str += "&show_creative="+show_creative;
	if(media!='') str += "&media="+media;
	if(forum_id!='') str += "&forum_id="+forum_id;
	if(word_code!='') str += "&word_code="+word_code;
	if(search_username!='') str += "&search_username="+window.encodeURIComponent(search_username);
	location.href= str;
}

function KeywordSearchPianoScore()
{
	if(document.getElementById('word').value == '' && 
		document.getElementById('search_username').value == '' && 
		!document.getElementById('show_creative').checked  &&
		!document.getElementById('media').checked
	)
	{
		{
			alert('請輸入關鍵字');
			return false;
		}
	}
	else
	{
		//if (document.getElementById('type').selectedIndex == 1) // 搜尋論壇
		//{
		//	document.forms['form1'].submit();
		//}
		//else if (document.getElementById('type').selectedIndex == 0) // 搜尋琴譜
		{
			document.getElementById('search_botton').disabled = true;
			
			document.getElementById('pgnum').value = 1;
			document.getElementById('class_id').value = '';
			document.getElementById('order').value = '';
			//document.getElementById('show_creative').checked ? 'on' : ''
			document.getElementById('user_id').value = '';
			document.getElementById('forum_id').value = '';
			/*check(
			'1',
			'',
			'',
			document.getElementById('word').value,
			'',
			document.getElementById('show_creative').checked ? 'on' : '',
			document.getElementById('type').value,
			document.getElementById('media').checked ? 'on' : '',
			'',
			document.getElementById('word_code').value,
			document.getElementById('search_username').value
			);*/
		}
	}
}

function goto_user_page(user_id)
{
	location.href= blogfile + "?module=piano_sheet&user_id=" + user_id;	
}

function view_detail_comment(id, post_id)
{
	window.open(webroot + "module/detail.php?id=" + id + "&view_comment=1#" + post_id);
}
