/**
 *
 * 帖子管理JS
 *
**/


function showPopupAlert(html) {
	var title='معلومات التشغيل';
	html = '<div style="padding:20px 0;text-align:center;">'+html+'</div>';
	
	var dg = new J.dialog({
		title:title, 
		iconTitle:false, 
		cancelBtn:false, 
		width: 350,
		height: 100,
		autoSize:true, 
		maxBtn:false, 
		timer:10, 
		html:html
	});
	dg.ShowDialog();
}
function showPopupDiv(html, title) {
	if(typeof(title) == "undefined"){
		var title = 'ادارة الموضوع';
	}
	var dg = new J.dialog({
		title:title, 
		html:html, 
		iconTitle:false, 
		width: 350,
		height: 100,
		autoSize:true, 
		maxBtn:false, 
		fixed:true, 
		autoPos:{left:'center',top:'center'}, 
		cancelBtnTxt:'تأكيد', 
		onCancel:function(){$('#threadmanage_submit').click();}
	});
	dg.ShowDialog();
}
function showPopupConfirm(html, url, isreload) {
	var title='هل تأكد التشغيل؟';
	html = '<div style="padding:20px 0;text-align:center;">'+html+'</div>';
	
	var dg = new J.dialog({
		title:title, 
		html:html, 
		iconTitle:false, 
		width: 350,
		height: 100,
		autoSize:true, 
		maxBtn:false, 
		fixed:true, 
		cancelBtnTxt:'تأكيد', 
		onCancel:function(){ajax_submit(url, isreload);}
	});
	dg.ShowDialog();
}

function ajax_get(get_url, after_success_function, title, 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, title);
		}
	}); 
}

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,title) {
	ajax_get(get_url, show_form_function, title);
    return false;
}

function show_form_function(ajax_return, title) {
	if (ajax_return.show_sign == 0) {
		showPopupAlert(ajax_return.info);
	} else {
		showPopupDiv(ajax_return.info, title);
	}
}

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 if(ajax_return.show_sign == 3){
		showPopupDiv(ajax_return.info);
	} else {
		window.location.reload();
	}
}


function updatestampimg(value) {
	if(value == 0){
		document.getElementById('threadstamp').innerHTML = '<img src="'+STB_STATIC_IMAGE_HOST+'/images/stamp/none.gif">';
	}else{
		document.getElementById('threadstamp').innerHTML = '<img src="'+STB_STATIC_IMAGE_HOST+'/images/stamp/00' + value + '.gif">';
	}
}
function updatepoststampimg(post_id,value) {
	if(value == 0){
		document.getElementById(post_id+'threadstamp').innerHTML = '<img src="'+STB_STATIC_IMAGE_HOST+'/images/stamp/none.gif">';
	}else{
		document.getElementById(post_id+'threadstamp').innerHTML = '<img src="'+STB_STATIC_IMAGE_HOST+'images/stamp/p00' + value + '.gif">';
	}
}

function show_top_form() {
	var myDate = new Date();
	myDate.setDate(myDate.getDate()+1);
    $('#top_end_date').datetimepicker({minDate: new Date(), defaultDate: myDate});
	$('#datetimepicker_div').css('z-index','10008');
}
