function G(id)
{
	return document.getElementById?document.getElementById(id):null;
}
function GN(name)
{
	return document.getElementsByName?document.getElementsByName(name):new Array();
}


//设置innerText(火狐下也能实现innerText)
function js_fn_set_InnerText(obj,Text)
{

	if(document.all)
	{
		obj.innerText = Text;
	}
	else
	{
		obj.textContent = Text;
	}

}

//返回innerText(火狐下也能实现innerText)
function js_fn_get_InnerText(obj)
{
	return document.all?obj.innerText:obj.textContent;
}


//去除字符串空格

function fn_js_trim(s_string)
{
	return s_string.replace(/(^\s*)|(\s*$)/g, "");
}

//去除字符串左空格
function fn_js_ltrim(s_string)
{
	return s_string.replace(/(^\s*)/g, "");
}

//去除字符串右空格
function fn_js_rtrim(s_string)
{
	return s_string.replace(/(\s*$)/g, "");
}


//对分隔符“；”,“、”转换为“，”

function fn_js_change_compart(s_string)
{
	if(s_string.length>0)
	{
		s_string = s_string.replace(";",",");
		s_string = s_string.replace("、",",");
	}
	return s_string;

}

//转化为汉字长度计算长度

function fn_byteLength(s_string)
{
	return s_string.replace(/[^\u0000-\u007f]/g,"\u0061\u0061").length;
}


//输入框只能输入数字判断事件

function js_fn_KeyPress(obj)
{
	var txtval = obj.value;
	var key = event.keyCode;
	if((key < 48 || key >57))
	{
		event.keyCode = 0;
	}
}


//检查邮件格式是否符合规格

//返回值： -1 ----地址为空  0----地址格式不正确  1---正确
//创建时间：2007年12月26日

function js_fn_check_email(email)
{
	var b_return = 1;
	email = fn_js_trim(email);

	if(email.length ==0)
	{
		b_return = -1;
	}
	else if(email!="" && !email.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig))
	{
		b_return = 0;
	}

	return b_return;
}


//登陆后返回

function fn_js_LoginReback(url)
{
	window.location.href="/login.aspx?url="+url;
}


//判断是否为数字
function BASEisNotNum(theNum)
{
	//判断是否为数字
	if (fn_js_trim(theNum)=="")
	return true;

	for(var i=0;i<theNum.length;i++)
	{
		oneNum=theNum.substring(i,i+1);
		if (oneNum<"0" || oneNum>"9")
		return true;
	}
	return false;
}



//判断是否为整数
function BASEisNotInt(theInt)
{
	//判断是否为整数
	theInt=fn_js_trim(theInt);

	if ((theInt.length>1 && theInt.substring(0,1)=="0") || BASEisNotNum(theInt))
	{
		return true;
	}
	return false;
}

/* 图片缩放 */
function ResizeImage(image, maxwidth, maxheight)
{
        w = image.width;
        h = image.height;
                
        if( w == 0 || h == 0 )
        {
            image.width = maxwidth;
            image.height = maxheight;
        }
        else if (w > h)
        {
            if (w > maxwidth) image.width = maxwidth;
        }
        else
        {
            if (h > maxheight) image.height = maxheight;
        }
}

/*公共礼物*/
function showGiftList(category_id,comment_type,postid) {
	jQuery('#gift_all_' + category_id + '_' + comment_type + '_' + postid).load('/common/comment/get_gift.php?category_id=' + category_id + '&comment_type=' + comment_type + '&postid=' + postid);
}
function setGift(url,list_id,comment_type,postid){
	jQuery('#cur_gift_img_'+comment_type + '_' + postid).attr({ src: url,list_id:list_id});
//	jQuery("#gift_msg")[0].firstChild.replaceWholeText("已选中礼物");
	jQuery("#gift_msg_text").html("已选中礼物");
}


/*评论公用方法开始*/
function showCommentList(uid,comment_type, postid,disable_gift,display_type,startpos) {
	var comment_div = jQuery('.comment_all_' + comment_type+"_" + postid);
	if(comment_div.length > 0){
		comment_div.load('/common/comment/list.php?uid=' + uid +'&comment_type=' + comment_type + '&postid=' + postid + '&disable_gift=' + disable_gift + '&display_type=' + display_type + '&startpos=' + startpos);
	}else{
		window.location.reload();
	}

	if(jQuery('#comment_iframe').length > 0){
		 var height = jQuery("#comment_iframe").contents().find("body").attr('scrollHeight') + 200; 
		 console.log("height3=" + height);
		jQuery("#comment_iframe").height( height < 400 ? 400 : height );
	}
}
function showReplyList(clubid, bbsType, postid, parentSeq) {
	jQuery('#reply_' + parentSeq).load('/common/comment/reply.php?clubid=' + clubid + '&bbs_type=' + bbsType + '&postid=' + postid + '&parent_seq=' + parentSeq);
}

function setComment(uid,comment_type,postid){
	if(post_right==0){
		getModalDiv('/common/comment/comment_notice.php');
		return false;
	}
	var content = eval('content_editor_'+comment_type+'_'+postid+'.getHtml();');
	content = content.replace('<p>', '');
	//content = content.replace(/<.*?>/g,"");
	content = content.replace(/&nbsp;/g, '');
	if(!verifycontent(content)){
		jQuery.facebox.close();
		return false;
	}
	var gift_url = jQuery('#cur_gift_img_'+comment_type+"_"+postid).attr('src');
	var list_id = jQuery('#cur_gift_img_'+comment_type+"_"+postid).attr('list_id');
	if(content.length<=0){
		_alert('请输入内容');
		return false;
	}
	if(content.length>800){
		_alert('内容过长');
		return false;
	}
	//对comment_type做不同处理
	//日报的评论不需要礼物
	//if(comment_type != 10 || (typeof(gift_url) == "undefined")){
	if(typeof(gift_url) != "undefined"){
		if(gift_url == '../images/bbsli1.gif' || gift_url == '/images/noli.gif'){
			_alert('请选择礼物');
			return false;
		}
	}
	var display_type = jQuery('#display_type_'+comment_type+"_"+postid).val();

	jQuery.ajax({
		type: "POST",
		url: "/common/comment/write_proc.php",
		data: "uid="+uid+"&postid="+postid+"&content="+content+"&comment_type="+comment_type+"&gift_url="+gift_url+"&list_id="+list_id,

		success: function(res){
			if (res=="0"){
				alert("参数错误或者含有非法字符！！");
				return false;
			}else if(res=="3"){
				_alert('你已被对方拉入黑名单，无法进行此操作');
				return false;
			}
			eval('content_editor_'+comment_type+'_'+postid+'.init("");');
			if(comment_type == 11){
				window.location.reload();
			}else{
				var r=/.*miniblog=.*ok$/i
				if(r.test(res)){
					a=/.*miniblog=/i
					b=/ok$/i
					res=res.replace(a,"")
					res=res.replace(b,"")
					window.location.replace("/blog/view_miniblog_detail.php?_pt="+res+"&uid="+uid+"&blog_id="+postid);
				}
				if(typeof(display_type) != "undefined" && display_type == "DAILY"){
					showCommentList(uid, comment_type, postid,false,"DAILY",1);
				}else{
					showCommentList(uid, comment_type, postid);
				}
			}	
		}
	});
}

function setReply(uid,comment_type,postid,parent_seq,curpage){
	if(post_right==0){
		getModalDiv('/common/comment/comment_notice.php');
		return false;
	}
	var content = eval('content_editor_'+parent_seq+'.getHtml();');
	content = content.replace('<p>', '');
	//content = content.replace(/<.*?>/g,"");
	content = content.replace(/&nbsp;/g, '');
	if(content.length<=0){
		alert('请输入内容');
		return false;
	}
	if(content.length>800){
		alert('内容过长');
		return false;
	}
	if(!verifycontent(content)){
		jQuery.facebox.close();
		return false;
	}
	jQuery.ajax({
		type: "POST",
		url: "/common/comment/write_proc.php",
		data: "uid="+uid+"&postid="+postid+"&content="+content+"&comment_type="+comment_type+"&parent_seq="+parent_seq,

		success: function(res){
			if (res=="0"){
				alert("参数错误或者含有非法字符！！");
				return false;
			}else if(res=="3"){
				_alert('你已被对方拉入黑名单，无法进行此操作');
				return false;
			}
			showCommentList(uid, comment_type, postid,'','',curpage);
		}
	});
}

function setDailyReply(uid,comment_type,postid,parent_seq,div_id){
	if(post_right==0){
		getModalDiv('/common/comment/comment_notice.php');
		return false;
	}
	var content = eval('content_editor_'+div_id+'.getHtml();');
	content = content.replace('<p>', '');
	content = content.replace(/<.*?>/g,"");
	content = content.replace(/&nbsp;/g, '');
	if(content.length<=0){
		alert('请输入内容');
		return false;
	}
	if(content.length>800){
		alert('内容过长');
		return false;
	}
	jQuery.ajax({
		type: "POST",
		url: "/common/comment/write_proc.php",
		data: "uid="+uid+"&postid="+postid+"&content="+content+"&comment_type="+comment_type+"&parent_seq="+parent_seq,

		success: function(res){
			if(res=='ok'){
			}else if (res=="0"){
				alert("参数错误或者含有非法字符！！");
				return false;
			}else if(res=="3"){
				_alert('你已被对方拉入黑名单，无法进行此操作');
				return false;
			}else{
				eval(res);
			}
			showCommentList(uid, comment_type, postid,"","DAILY",1);
		}
	});
}

function replyComment(member_uid,comment_type,postid,comment_seq,curpage){
	jQuery("#reply_txt_"+comment_seq).hide();
	var html = '<div class="wauto">';
	html += '<div id="commentcontent_'+comment_seq+'" name="commentcontent_'+comment_seq+'"></div>';
	html += '<div class="wauto pt10">';
	html += '<input type="button" class="repost mr15" id="commentbtn_'+comment_seq+'"  onclick="setReply('+member_uid+','+comment_type+','+postid+','+comment_seq+','+curpage+')" title="回复" value="回复" />';
	html += '<input type="button" class="quxiao" onclick="cancelReply('+comment_seq+')" title="取消" value="取消"/>';
	html += '</div>';
	html += '</div>';
	document.getElementById("reply_"+comment_seq).innerHTML = html;
	eval('content_editor_'+comment_seq+' = new webEditor("content_editor_'+comment_seq+'" , document.getElementById("commentcontent_'+comment_seq+'") , 396, 100, "");');
	eval('content_editor_'+comment_seq+'.init("");');
}

function replyDailyComment(member_uid,comment_type,postid,comment_seq,div_id){
	var html = '<div class="wauto">';
	html += '<div id="commentcontent_'+div_id+'" name="commentcontent_'+div_id+'"></div>';
	html += '<div class="wauto pt10">';
	html += '<input type="button" class="repost mr15" id="commentbtn_'+div_id+'"  onclick=setDailyReply('+member_uid+','+comment_type+','+postid+','+comment_seq+',"'+div_id+'") title="回复" value="回复" />';
	html += '<input type="button" class="quxiao" onclick=cancelReply("'+div_id+'") title="取消" value="取消"/>';
	html += '</div>';
	html += '</div>';
	document.getElementById("reply_"+div_id).innerHTML = html;
	eval('content_editor_'+div_id+' = new webEditor("content_editor_'+div_id+'" , document.getElementById("commentcontent_'+div_id+'") , 396, 100, "");');
	eval('content_editor_'+div_id+'.init("");');
}

function replyDaily(member_uid,comment_type,postid,comment_seq,div_id){
	showCommentTrue(div_id);
	var html = '<div class="wauto">';
	html += '<div id="commentcontent_'+div_id+'" name="commentcontent_'+div_id+'"></div>';
	html += '<div class="wauto pt10">';
	html += '<input type="button" class="repost mr15" onclick="setDailyReply('+member_uid+','+comment_type+','+postid+','+comment_seq+',\''+div_id+'\')" title="回复" value="回复" />';
	html += '<input type="button" class="quxiao" onclick="cacelCommentTrue(\''+div_id+'\')" title="取消" value="取消"/>';
	html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
	html += '</div>';
	html += '</div>';
	document.getElementById("comment_true_"+div_id).innerHTML = html;
	eval('content_editor_'+div_id+' = new webEditor("content_editor_'+div_id+'" , document.getElementById("commentcontent_'+div_id+'") , 396, 100, "");');
	eval('content_editor_'+div_id+'.init("");');
}

function cancelReply(comment_seq){
	eval('comment_editor_'+comment_seq+'=null;');
	jQuery("#reply_"+comment_seq).html(" ");
	jQuery("#reply_txt_"+comment_seq).show();
}

function delComment(uid,comment_type,postid,comment_seq,curpage){
	var ok = "delCommentProc("+uid+","+comment_type+","+postid+","+comment_seq+","+curpage+")";
	_confirm('确定删除这条评论以及下面的回复吗？','系统提示',ok);
}
function delReply(uid,comment_type,postid,comment_seq,curpage){
	var ok = "delCommentProc("+uid+","+comment_type+","+postid+","+comment_seq+","+curpage+")";
	_confirm('确定删除这条回复吗？','系统提示',ok);
}
function delCommentProc(uid,comment_type,postid,comment_seq,curpage){
	var url = "/common/comment/delete_proc.php";
		
	var arrdata = {'member_uid':uid,'comment_type':comment_type,'postid':postid,'seq':comment_seq};
	jQuery.post(url,arrdata,
	function(res){
		jQuery.facebox.close();
		showCommentList(uid, comment_type, postid,'','',curpage);
	}
	);
}


function friendRequest(friend_uid){
	jQuery.ajaxSetup({
		cache: false
	});
	//var url = "/friend/friend_request.php";
	//jQuery.facebox({'ajax' : url, 'data' : {'friend_uid' : friend_uid}});
	getModalDiv('/friend/friend_request.php?friend_uid='+friend_uid);
}
function sendFriendRequest(friend_uid){
	var url = "/friend/friend_request_proc.php";
	var arrdata = {'friend_uid':friend_uid};
	jQuery.post(url,arrdata,
	function(res){
		//jQuery.facebox.close();
		removeModalDiv();
		_alert("请求发送成功，请耐心等待");
	}
	);
}