var j_area;
var j_value;

function end_slide()
{
    location.href="/gallery.php";
}

function onclick_recommend(post_no, item, count) {
	j_area = document.getElementById('r'+item+'_'+post_no);
	j_value =  (parseInt(count)+1);
	var url = '/ajax_exe.php';
	pars = 'mode=recommend';
	pars += '&slid='+form.slid.value;
	pars += '&type='+form.type.value;
	pars += '&post_no='+post_no;
	pars += '&item='+item;
	var myAjax = new Ajax.Request(url, { method: 'post', postBody: pars, onComplete: onclick_recommend_result });
}

function onclick_recommend_result(originalRequest) {
	var result = originalRequest.responseText.substring(0,1);
	if (result == '9') { alert('評価されました。'); j_area.innerHTML = j_value; }
	if (result == '0') { alert('ログインしてください。'); }
	if (result == '1')
	{
		var kk = originalRequest.responseText.substring(1, originalRequest.responseText.length);
		kk = "すでに評価されています。(" + kk + ")";
		alert(kk);
	}
	if (result == '2') { alert('自分の書き込みは評価できません。'); }
}


function onclick_toggle_comment(post_no) {
	var obj = document.getElementById('comment_area_'+post_no);
	if (obj.style.display == 'none') show_comment(post_no);
	else obj.style.display = 'none';
}

function show_comment(post_no) {
	var obj = document.getElementById('comment_area_'+post_no);
	form.j_no.value = post_no;
	var url = '/ajax_exe.php';
	pars = 'mode=list';
	pars += '&slid='+form.slid.value;
	pars += '&type='+form.type.value;
	pars += '&post_no='+post_no;
	var myAjax = new Ajax.Request(url, { method: 'post', postBody: pars, onComplete: show_comment_draw });
}

function show_comment_draw(originalRequest) {
	var result = originalRequest.responseText;
	var obj = document.getElementById('comment_area_'+form.j_no.value);
	obj.innerHTML = result;
	obj.style.display = 'block';
}


function onclick_add_comment(post_no) {
	trim_all(form);
	if (is_null(document.getElementById('body_'+post_no), '内容を入力してください')) return false;
	var is_secret=0; if (document.getElementById('is_secret_'+post_no).checked) is_secret = 1; else is_secret = 0;
	form.j_no.value = post_no;
	var url = '/ajax_exe.php';
	pars = 'mode=insert';
	pars += '&slid='+form.slid.value;
	pars += '&type='+form.type.value;
	pars += '&post_no='+post_no;
	pars += '&is_secret='+is_secret;
	pars += '&body='+url_encode(document.getElementById('body_'+post_no).value);
	var myAjax = new Ajax.Request(url, { method: 'post', postBody: pars, onComplete: show_comment_draw });
	document.getElementById('is_secret_'+post_no).checked = false;
	document.getElementById('body_'+post_no).value = '';
}

function onclick_delete_comment(post_no, comment_no) {
	if (!confirm('本当に削除しますか？')) return false;
	form.j_no.value = post_no;
	var url = '/ajax_exe.php';
	pars = 'mode=delete';
	pars += '&slid='+form.slid.value;
	pars += '&type='+form.type.value;
	pars += '&post_no='+post_no;
	pars += '&comment_no='+comment_no;
	var myAjax = new Ajax.Request(url, { method: 'post', postBody: pars, onComplete: show_comment_draw });
}

function onclick_reply_comment(post_no, comment_no) {
	window.open('/pop_exe.php?mode=reply&slid='+form.slid.value+'&type='+form.type.value+'&post_no='+post_no+'&comment_no='+comment_no,'a_c','width=510,height=310');
}

function onclick_edit_comment(post_no, comment_no) {
	window.open('/pop_exe.php?mode=edit&slid='+form.slid.value+'&type='+form.type.value+'&post_no='+post_no+'&comment_no='+comment_no,'a_c','width=510,height=310');
}

function onclick_delete_post(post_no) {
	var url = '/ajax_exe.php';
	pars = 'mode=delete_post';
	pars += '&slid='+form.slid.value;
	pars += '&type='+form.type.value;
	pars += '&post_no='+post_no;
	var myAjax = new Ajax.Request(url, { method: 'post', postBody: pars, onComplete: onclick_delete_post_result });
}

function onclick_delete_post_result(originalRequest) {
	var result = originalRequest.responseText;
	if (result == 1) window.location.href='/blog.php';
	if (result == 2) window.location.href='/gallery.php';
	if (result == 3) window.location.href='/scrap.php';
}

