
function validateContent(content_tag) {
	tinyMCE.get(content_tag).save();	
	var content = $('#'+content_tag).val();
	if (!content || content.replace(/^\s*|\s*$/g, "").length == 0) {
		alert('正文不能为空');
		$('#content').focus();
		return false;
	}
	return true;
}

function validatePostForm() {
	var title = $('#topic_title').val();
	if (title.length < 2) {
		alert('标题不能少于2个字符');
		return false;
	}
	tinyMCE.get('content').save();	
	var content = $('#content').val();
	if (!content || content.replace(/^\s*|\s*$/g, "").length == 0) {
		alert('正文不能为空');
		$('#content').focus();
		return false;
	}
	return true;
}

function addBookmark(id) {
	var w = window.open('/posts/to_bookmark/' + id, 'bookmark_add', 'width=700, height=240, scrollbars=no'); 
	w.focus();
}

function disable(obj) {
	obj.attr('disabled',true);
}

function enable(obj) {
	obj.attr('disabled',false);
}

function next_topic(topic_id) {
	window.location = "/posts/next_topic/"+topic_id;
}
function pre_topic(topic_id) {
	window.location = "/posts/pre_topic/"+topic_id;
}
function download(url) {
	if (confirm("确定要下载该附件？"))
		window.location = url;
}

function goBoard(board_id) {
	var url = '/forums/show/'+board_id;
	window.location = url;
}

var cmt_dialog = null;
function ShowSelectForm() {
	if (cmt_dialog==null) {
		$(document.body).append("<div id='cmt_dialog' class='jqmWindow jqmWindowCmt'> \
		                         <div class='jq-title'><span class='jq-title-name'>请选择发帖板块</span><a href='#' class='jqmClose jq-title-close'></a></div>  \
                                 <div id='cmt_context'></div></div>");
        cmt_dialog = $('#cmt_dialog'); 								 
		cmt_dialog.jqm({modal:true});
		if (arguments.length == 0) {
			$('#cmt_context').load('/forums/board_to_topic/', '', function(){
				cmt_dialog.jqmShow();
			});
		} else {
			var from = arguments[0];
			$('#cmt_context').load('/forums/board_to_topic?fs='+from, '', function(){
				cmt_dialog.jqmShow();
			});
		}		
	} else {
		cmt_dialog.jqmShow();
	}
}

function ShowSubMenu(obj) {
	$(obj).children('div').show();
}

function HideSubMenu(obj) {
	$(obj).children('div').hide();
}

$(document).ready(function(){
    $("input.go_page_btn").click(function(){
        goPage($(this).prev().val());
    }).prev().bind("keyup",function(event){
       if (event.keyCode==13) {
           goPage($(this).val());
       }
    });
    function goPage(page) {
        if (!/\d+/.test(page)) {
            alert("请输入数字");
            return false;
        }
        var url = ''+window.location;
        if (url.indexOf('page=') != -1) {
            window.location = url.replace(/page=\d+/,"page="+page);
        } else {
            if (m = url.match(/\/\d+\/\d+/)) {
                str = " " + m[0];
                ds = str.split(/\//);
                var cp = '/' + ds[1] + '/' + page;
                window.location = url.replace(/\/\d+\/\d+/,cp);
            } else if (url.indexOf('?') != -1) {
                window.location = url + '&page=' + page;
            } else {
                window.location = url + '?page=' + page;
            }
        }        
    }
});

