var slt_tp_tag_status;

function input_p_tag() {

	document.form_post.contents.value = document.form_post.contents.value + " [p:人(著者、アーティストなど)]";

	return;
}

function input_t_tag() {

	document.form_post.contents.value = document.form_post.contents.value + " [t:タイトル(店名、映画の名前など)]";

	return;
}

function add_tp_tag() {
	
	var i =  document.form_post.slt_tp_tag.selectedIndex;
	var opt = document.form_post.slt_tp_tag.options[i].value;


	// 次へ(ぐるナビ)
	if (opt == 'go_next_gnavi') {
		next_gnavi_page();
		return;
	}

	// 前へ(ぐるナビ)
	if (opt == 'go_prev_gnavi') {
		prev_gnavi_page();
		return;
	}
	
	// 次へ(アマゾン)
	if (opt == 'go_next_amazon') {
		next_amazon_page();
		return;
	}

	// 前へ(アマゾン)
	if (opt == 'go_prev_amazon') {
		prev_amazon_page();
		return;
	}

	// Tタグ挿入
	if (opt.match(/(\[t:[^\]]+\])/)) {
		var t = RegExp.$1;
	 } else {
		var t = '';
	}

	// Pタグ挿入
	if (opt.match(/(\[p:[^\]]+\])/)) {
		var p = RegExp.$1;
	 } else {
		var p = '';
	}

	// asin挿入
	if (opt.match(/(\[asin:[^\]]+\])/)) {
		var asin = RegExp.$1;
	} else {
		var asin = '';
	}

	// 住所挿入
	if (opt.match(/\[@:([^\]]+)\]/)) {
		var a = RegExp.$1;
	} else {
		var a = '';
	}


	document.form_post.slt_tp_tag.selectedIndex = 0;

	document.form_post.contents.value = document.form_post.contents.value + t + p + asin;
	document.form_post.addr.value = a;

	return;
}

function add_question() {
	if (document.form_inv_user_mail.i_question.selectedIndex != 8 ) {
		var i =  document.form_inv_user_mail.i_question.selectedIndex;
		document.form_inv_user_mail.i_question_t.value = document.form_inv_user_mail.i_question.options[i].value;
	
		document.form_inv_user_mail.i_question.selectedIndex = 0;
	}
	return;
}

function add_n_tag() {
	var i =  document.form_post.add_tag.selectedIndex;
	document.form_post.contents.value = document.form_post.add_tag.options[i].value + document.form_post.contents.value;
	return;
}

function add_addr() {
	var i =  document.form_post.place.selectedIndex;
	document.form_post.addr.value = document.form_post.place.options[i].value;
	return;
}


function get_comment(star_no,id,session,form,del) {

	var e=encodeURIComponent;

	// 書き込み時
	if (!form) {
		comment = "";
	} else {
		comment = form.comment.value;
	}
	
	// 削除時
	if (!del) del="";
	
    //  リクエストを投げる。
	$("#comment2_"+star_no).load(
		"././get_comment.cgi",{'star_no': star_no, 'id': id, 
		'session': session, 'comment': comment, 'del_comment': del},
		function(responseText, status, response) {
			if (status == 'success' && (comment != "" || del != "")) {
				var count = Number($("#comments_"+star_no).html());
				if (comment != "") {
					$("#comments_"+star_no).html(count + 1);
					form.comment.value = "";
				} else if (del != "") {
					if ( count == 1 ) {
						$("#comments_"+star_no).html("0");
					} else {		
						$("#comments_"+star_no).html(count - 1);
					}
				}
			}
		}
	);
	
	if (comment == "" && del == "") {
		if(document.getElementById('comment_'+star_no).style.display == 'none'){ 
			document.getElementById('comment_'+star_no).style.display = 'block';
			document.getElementById('comment2_'+star_no).style.display = 'block';
	
		} else{
			document.getElementById('comment_'+star_no).style.display = 'none';
			document.getElementById('comment2_'+star_no).style.display = 'none';
		}
	}

}



function show_friends() {
	if(document.getElementById('more_friends').style.display == 'none'){
		document.getElementById('more_friends').style.display = 'block';
		document.getElementById('more_friends_btn').innerHTML = '▲CLOSE';
	 } else{
		document.getElementById('more_friends').style.display = 'none';
		document.getElementById('more_friends_btn').innerHTML = '▼MORE';
	 }
}

function add_option(text,value) {
	if (typeof(value) != "string") {
		value = text;
	}

	var opt = document.createElement("option");
	opt.text = text
	opt.value = value;

	try {  
		document.form_post.slt_tp_tag.add(opt,null);  // DOM標準  
	}  
	catch(ex) {  
		document.form_post.slt_tp_tag.add(opt);       // IE固有  
	}  
}

// twitter連携
function twitter(id,passwd,status,del) {
	if (!status) status = "";
	if (!del) del="";
	
	document.getElementById('twitter').innerHTML = "読み込み中";

    //  リクエストを投げる。
	$("#twitter").load(
		"./twitter.php",{'id': id, 'passwd': passwd, 'status': status, 'del': del},
		function(responseText, status, response) {
			if (status == 'success') {
				document.getElementById('twitter_status').value = "";
			}
		}
	);
}

// twitter reply
function twitter_reply(screen_name) {
	document.getElementById('twitter_status').value = "@" + screen_name + " " + document.getElementById('twitter_status').value;
	
}

// テキストボックス拡大
function open_textarea(contents) {
	var oWindow = window.open("", "", "width=400, height=150, menubar=no, toolbar=no, scrollbars=no, resizable=yes"); 
	with (oWindow.document) {
		write("<html>");
		write("<head>");
		write("<title>タイケンを入力<\/title>");
		write("<\/head>");
		write("<body>");

		write("<form name=\"input_contents\" onSubmit=\"var text=this.contents.value; text=text.replace(/[\\r\\n]/ig,''); window.opener.document.form_post.contents.value=text;window.close(); return false;\">");
		write("<textarea name=\"contents\" style=\"width:350px;height:110px\" wrap=\"hard\">");
		write(contents);
		write("<\/textarea><br />");
		write("<input type='submit' value='Close'></form>");
		write("<\/body>");
		write("<\/html>");
		close(); 
      }
}

// 確認ボックス
function confirm_msg(msg) {
	var ret = confirm(msg);
	
	return ret;
}
