function viewobj(obj){
	var Str="";
	for(var i in obj){
		Str+="\n"+i+"\t\t"+obj[i]+"";
	}
	return Str;
}
if (typeof o != 'function') {
	function o(obj) {
		return document.getElementById(obj);
	}
}
function reply_comment(commentid, cancel) {
	var post_form;
	var last_commentid = $('#comment_parent').val();
	var post_form_obj;
	if (cancel != 'cancel') {
		// 回复
		if ($('#comment_parent').val() == 0) {
			// 未添加时才使用
			post_form = $('#post_form');
			post_form.appendTo('#comment-div-'+commentid);
			$('#comment_parent').val(commentid);
			$('#cancel_comment').css({display:''});
		} else {
			$('#post_form').appendTo('#comment-div-'+commentid);
			$('#comment_parent').val(commentid);
		}
		$('.comment-post-container').css({display:'none'});
		document.location.href = "#comment"+commentid;
	} else {
		//取消回复
		$('#post_form').appendTo('.comment-post-container');
		$('#comment_parent').val('0');
		$('#cancel_comment').css({display:'none'});
		$('.comment-post-container').css({display:''});
		document.location.href = "#post_comment";
	}
}
//运行代码
function runcode(btnobj) {
	var code = btnobj.parentNode.childNodes[0].value;//即要运行的代码。
	var runcodewin = window.open('','_blank','');  //打开一个窗口并赋给变量newwin。
	runcodewin.document.open('text/html', 'replace');
	runcodewin.opener = null; // 防止代码对原页面修改
	runcodewin.document.write(code);  //向这个打开的窗口中写入代码code，这样就实现了运行代码功能。
	runcodewin.document.close();
}
// 高亮代码相关
var arrCode = new Array();
function changeCodeTxt(cid) {
    var ocode = document.getElementById('con-'+cid);
    arrCode[cid] = ocode.innerHTML;
    textCode = getTagCode(ocode);
    textCode = igEncodeHTML(textCode);
    textCode = doCleanUp(textCode);
    ocode.innerHTML = '';
    ocode.innerHTML = '<textarea rows="5" cols="60" class="textcode">'+textCode+'</textarea>';
    document.getElementById('clnk-'+cid).innerHTML = '<a href="javascript:changeCodeHL('+cid+')" title="改为高亮模式">切换</a>';
}
function changeCodeHL(cid) {
    var ocode = document.getElementById('con-'+cid);
    ocode.innerHTML = '';
    ocode.innerHTML = arrCode[cid];
    document.getElementById('clnk-'+cid).innerHTML = '<a href="javascript:changeCodeTxt('+cid+')" title="改为文本模式">切换</a>';
}
function igEncodeHTML(igHTML) {
	var regExLT = /</g;
	var regExGT = />/g;
	igHTML = igHTML.replace(regExLT, "&lt;");
	igHTML = igHTML.replace(regExGT, "&gt;");
	return igHTML;
}
function doCleanUp(sTxt) {
	sTxt = sTxt.replace(/(\r\n|\r|\n)/g, "\n");
	var arrTxt = sTxt.split("\n");
	for(i=0; i<arrTxt.length; i++) {
		if(arrTxt[i].substr((arrTxt[i].length-1), 1)==" ") {
			arrTxt[i] = arrTxt[i].substr(0, (arrTxt[i].length-1));
		}
		if(arrTxt[i].substr((arrTxt[i].length-1), 1)=="	") {
			arrTxt[i] = arrTxt[i].substr(0, (arrTxt[i].length-1));
		}
	}
	sTxt = arrTxt.join("\n");
	var regExNL1a = /([\n]{2,})/g;			//to find two consecutive 'newlines'
	var regExNL1b = /([ ]{1,})\n/g;			//to find more than 1 whitespace before 'newline'
	var regExNL1c = /([	|\t]{1,})\n/g;		//to find more than 1 tab before 'newline'
	var regExNL1d = /\n([ ]{1,})\n/g;		//to find a line with only spaces
	var regExNL1e = /\n([	|\t]{1,})\n/g;	//to find a line with only tabs
	var regExNL1g = / {4}/g;				//to find 4 space chars
	sTxt = sTxt.replace(regExNL1g, "	");
	sTxt = sTxt.replace(regExNL1d, "\n").replace(regExNL1e, "\n");
	sTxt = sTxt.replace(regExNL1b, "\n").replace(regExNL1c, "\n");
	sTxt = sTxt.replace(regExNL1a, "\n");
	if(sTxt.substr(0, 1)=="\n") {
		sTxt = sTxt.substr(1, sTxt.length);
	}
	if(sTxt.substr((sTxt.length-1), 1)=="\n") {
		sTxt = sTxt.substr(0, (sTxt.length-1));
	}
	return sTxt;
}
function getTagCode(oDoc) {
	var getTxt = "";
	if(typeof(oDoc.innerText) != 'undefined') {
		getTxt = strTrim(oDoc.innerText);
	} else {
		getTxt = strTrim(oDoc.innerHTML);	//textContent doesn't keep \n with <LI>, so use innerHTML
		var regExLi = /<\/li>/gi;		//RegEx to find </li>
		var regExHTML = /<\S[^>]*>/g;	//RegEx to find HTML Tags
		var regExAnd = /&amp;/g;		//to find ampersand as HTML entity
		var regExSpace = /&nbsp;/g;		//to find whitespace as HTML entity
		var regExLT = /&lt;/g;			//to find < as HTML entity
		var regExGT = /&gt;/g;			//to find > as HTML entity
		getTxt = getTxt.replace(regExLi, "\n");		//replace </li> with \n
		getTxt = getTxt.replace(regExHTML, "");		//strip out all HTML Tags
		getTxt = getTxt.replace(regExAnd, "&");		//replace &amp; with &
		getTxt = getTxt.replace(regExSpace, " ");	//replace &nbsp; with simple whitespace
		getTxt = getTxt.replace(regExLT, "<");		//replace &lt; with <
		getTxt = getTxt.replace(regExGT, ">");		//replace &gt; with >
	}
	return getTxt;
}
function strTrim(str) {
	var i,j;
	i = 0;
	j = str.length-1;
	str = str.split("");
	while(i < str.length) {
		if(str[i]==" ") {
			str[i] = "";
		} else {
			break;
		}
		i++;
	}
	while(j > 0) {
		if(str[j]== " ") {
			str[j]="";
		} else {
			break;
		}
		j--;
	}
	return str.join("");
}
function replyAt(commid, aut) {
    var cmt = '[' + commid + '@' + aut + ']';
    commtxt = jQuery('#comment_content').val();
    if ( '' == commtxt ) {
        jQuery('#comment_content').val(cmt + ' ');
    } else if ( commtxt.indexOf(cmt) < 0 ) {
        commtxt = jQuery('#comment_content').val() + "\r\n" + cmt;
        jQuery('#comment_content').val(commtxt + ' ');
    }
    //DotRoll('commentpostform');
    jQuery('#comment_content').focus();
}
function DotRoll(elm) {
    var scrobj;
    if ( jQuery("a[name='"+elm+"']").length > 0) {
        scrobj = jQuery("a[name='"+elm+"']");
    } else if ( jQuery("li#"+elm).length > 0 ) {
        scrobj = jQuery("li#"+elm);
    }
    jQuery("body,html").animate({scrollTop:scrobj.offset().top}, 500);
    
}
function crreplyat() {
    $('.atreply').live('click', function(){
        anchor = jQuery(this).attr('href').slice(1);
        DotRoll(anchor);
        return false;
    });
}
function PostCommentResponse(resp, status) {
    var json_resp = eval('('+resp+')');
    
    if ( 'success_submit' == json_resp.response ) {
        $('#postcommentmsg').hide();
        if ( $('#noextcmt').length > 0 ) {
            $('#noextcmt').remove();
        }
        $('#commollist').append(json_resp.text);
        $('#smt_btn').attr('disabled', false);
        $('#comment_content').val('').focus();
    } else {
        $('#postcommentmsg').html(json_resp.text).removeClass('postmsgwait').addClass('postmsgfail');
        $('#smt_btn').attr('disabled', false);
    }
    return true;
}