/**
 *
 * 帖子管理JS
 *
**/


function showPopupAlert(html) {
	var title='Messages';
	$.fn.jmodal({
		title: title,
		content: function(e) {
			e.html(html);
		},
		fixed: true,
		buttonText: { ok: 'OK', cancel: 'Cancel' },
		okEvent: function(obj, args) {
			$('#threadmanage_submit').click();
			args.complete();
		}
	});
}
function showPopupDiv(html) {
	var title='Thread Manage';
	$.fn.jmodal({
		title: title,
		content: function(e) {
			e.html(html);
		},
		fixed: true,
		buttonText: { ok: 'OK', cancel: 'Cancel' },
		okEvent: function(obj, args) {
			$('#threadmanage_submit').click();
			//args.complete();
		}
	});
}
function showPopupConfirm(str, url) {
	var title='Yes or No';
	$.fn.jmodal({
		title: title,
		content: function(e) {
			e.html(str);
		},
		fixed: true,
		buttonText: { ok: 'OK', cancel: 'Cancel' },
		okEvent: function(obj, args) {
			ajax_submit(url);
			//args.complete();
		}
	});
}

function ajax_get(get_url, after_success_function, cur_form, is_cache) {
	is_cache = false;
	$.ajax({
		url: get_url,
		type: "GET",
		dataType: "json",
		data: cur_form ? $("#" + cur_form + "").serialize() : null,
		success: function(html){
			after_success_function(html);
		}
	}); 
}

function ajax_post(get_url, after_success_function, cur_form, is_cache) {
	is_cache = false;
	$.ajax({
		url: get_url,
		cache: is_cache,
		type: "post",
		dataType: "json",	  
		data: cur_form ? $("#" + cur_form + "").serialize() : null,
		success: function(html){
			after_success_function(html);
		}
	}); 	
}

function show_form(get_url) {
	ajax_get(get_url, show_form_function);
    return false;
}

function show_form_function(ajax_return) {
	if (ajax_return.show_sign == 0) {
		showPopupAlert(ajax_return.info);
	} else {
		showPopupDiv(ajax_return.info);
	}
}

function ajax_submit(get_url, cur_form) {
	ajax_post(get_url, ajax_submit_function, cur_form);
	return false;
}

function ajax_submit_function(ajax_return) {
	if (ajax_return.show_sign == 0) {
		showPopupAlert(ajax_return.info);
	} else if(ajax_return.show_sign == 2){
		window.location.href = ajax_return.info;
	} else {
		window.location.reload();
	}
}
