// 配置
// 当前域
var d_a = document.domain.split(".");
var _domain = d_a[d_a.length-2]+'.'+d_a[d_a.length-1];
var _web_url = 'http://www.' + _domain;	// 当前网址
var _img_url = 'http://img.' + _domain;
// 处理浏览器
var Browser = 'Unknown';
if (navigator.appName.indexOf("Microsoft")!= -1) {
	Browser = "IE";
}
if (navigator.appName.indexOf("Netscape")!= -1){
	Browser = "FF";
}
String.prototype.trim = function() { return this.replace(/(^(\s|　)*)|((\s|　)*$)/g, ""); }
String.prototype.reallength = function(){return this.replace(/[^\x00-\xff]/g,"^^").length;}
var js_root_url = 'http://www.'+_domain;
var js_file_list = new Array();
function loadJS(js_url){
	js_url = js_url.trim();
	if( js_url=="" ){
		return false;
	}
	js_url = js_root_url+js_url;
	if( inArray(js_url,js_file_list) ){
		return true;
	}
	document.write('<script type="text\/javascript" src="'+js_url+'"></scr'+'ipt>');
	js_file_list[js_file_list.length] = js_url;
	return true;
}
function inArray(v,a){
	for(var i=0;i<a.length;i++){
		if(a[i]==v){
			return true;
		}
	}
	return false;
}
// 随机串
function randomString(){
	return parseInt(Math.random()*999999);
}
// 评估密码强度
function ass_pwd_strength(pwd){
	var level = -1;
	if ( pwd.match(/[a-z]/ig) ){
		level++;
	}
	if ( pwd.match(/[0-9]/ig) ){
		level++;
	}
	if ( pwd.match(/(.[^a-z0-9])/ig) ){
		level++;
	}
	if ( pwd.length<6 && level>0 ){
		level--;
	}
	return level;
}
// 验证邮件格式是否正确
function checkEmail(email){
	return email.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)
}

// 根据跟定的月份和日期，获取星座数据
function getAstro(v_month, v_day){
	v_month = parseInt(v_month,10)
	v_day = parseInt(v_day,10);
	if ((v_month==12&&v_day>=22) || (v_month==1&&v_day<=20)){
		return "魔羯座";
	}
	else if ((v_month == 1 && v_day >= 21) || (v_month == 2 && v_day <= 19)){
		return "水瓶座";
	}
	else if ((v_month == 2 && v_day >= 20) || (v_month == 3 && v_day <= 20)){
		return "双鱼座";
	}
	else if ((v_month == 3 && v_day >= 21) || (v_month == 4 && v_day <= 20)){
		return "白羊座";
	}
	else if ((v_month == 4 && v_day >= 21) || (v_month == 5 && v_day <= 21)){
		return "金牛座";
	}
	else if ((v_month == 5 && v_day >= 22) || (v_month == 6 && v_day <= 21)){
		return "双子座";
	}
	else if ((v_month == 6 && v_day >= 22) || (v_month == 7 && v_day <= 22)){
		return "巨蟹座";
	}
	else if ((v_month == 7 && v_day >= 23) || (v_month == 8 && v_day <= 23)){
		return "狮子座";
	}
	else if ((v_month == 8 && v_day >= 24) || (v_month == 9 && v_day <= 23)){
		return "处女座";
	}
	else if ((v_month == 9 && v_day >= 24) || (v_month == 10 && v_day <= 23)){
		return "天秤座";
	}
	else if ((v_month == 10 && v_day >= 24) || (v_month == 11 && v_day <= 22)){
		return "天蝎座";
	}
	else if ((v_month == 11 && v_day >= 23) || (v_month == 12 && v_day <= 21)){
		return "射手座";
	}
	return "";
}

// 获取字符串的所占字节数
function b_strlen(fData){
	var intLength=0;
	for (var i=0;i<fData.length;i++){
		if ((fData.charCodeAt(i) < 0) || (fData.charCodeAt(i) > 255)){
			intLength=intLength+2;
		}
		else{
			intLength=intLength+1;
		}
	}
	return intLength;
}

// 获取指定月份的天数
function getDays(year , month){
	year = parseInt(year,10);
	month = parseInt(month,10);
	var dayarr = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

	if(month == 2){
		if((year%4 == 0 && year%100 != 0) || year%400 == 0 || year < 1900){
			return 29;
		}
		else{
			return dayarr[month-1];
		}
	}
	else{
		return dayarr[month-1];
	}
}
// 根据年和月的控件，设置日的控件
function setMonthDay(y_id,m_id,d_id,d_v){
	var year = $F(y_id);
	var month = $F(m_id);
	var days = getDays(year,month);
	var obj = $(d_id);
	d_v = parseInt(d_v,10);
	var last_v = obj.value;
	clearSelectOptions(obj);
	var s = 0;
	for(var i=1;i<=days;i++){
		var j = i<10?'0'+i:i;
		obj.options[obj.length] = new Option( j , j );
		if( (isNaN(d_v)&&i==last_v)||i==d_v ){
			s = i-1;
		}
	}
	obj.options[s].selected = true;
}

function getpos(element){
	if ( arguments.length != 1 || element == null ){
		return null;
	}
	var elmt = element;
	var offsetTop = elmt.offsetTop;
	var offsetLeft = elmt.offsetLeft;
	var offsetWidth = elmt.offsetWidth;
	var offsetHeight = elmt.offsetHeight;
	while( elmt = elmt.offsetParent ){
		// add this judge
		if ( elmt.style.position == 'absolute' || elmt.style.position == 'relative'
            || ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) ) {
            break;
        }
		offsetTop += elmt.offsetTop;
		offsetLeft += elmt.offsetLeft;
	}
	return {top:offsetTop, left:offsetLeft, right:offsetWidth+offsetLeft, bottom:offsetHeight+offsetTop };
}

// 判断child_node是否是parent_node的子节点或孙子节点
function isChild(child_node,parent_node){
	var elmt = $(child_node);
	while( elmt=elmt.offsetParent ){
		if( elmt==parent_node ){
			return true;
		}
	}
	return false;
}

function goBack(deep){
	window.history.go(deep);
}

//显示对象
function show(el){
	if( typeof(el)=='object' ){
		el.style.display = '';
	}
	else if( typeof(el)=='string' ){
		$(el).style.display = '';
	}
}

// 隐藏对象
function hidden(el){
	if( typeof(el)=='object' ){
		el.style.display = 'none';
	}
	else if( typeof(el)=='string' ){
		$(el).style.display = 'none';
	}
}

// 删除节点
function remove_node(d){
	if ($(d)){
		$(d).parentNode.removeChild($(d));
	}
}
//清空一个元素的所有节点
function removeChildren(obj){
	while(obj.hasChildNodes()){
		obj.removeChild(obj.firstChild);
	}
}
//清空select的选项
function clearSelectOptions(obj){
    while(obj.length>0)
		obj.remove(0);
	obj.length=0;
}
// 复制到剪切板
function copyToClipboard(text){
	if (window.clipboardData) {
		window.clipboardData.setData("Text",text);
	}
	else {
		var flash_copy = null;
		if( !$('flash_copy') ){
			var flash_copy = document.createElement("div");
			flash_copy.id = 'flash_copy';
			document.body.appendChild(flash_copy);
		}
		flash_copy = $('flash_copy');
		flash_copy.innerHTML = '<embed src="/images/flash/_clipboard.swf" FlashVars="clipboard='+escape(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	}
	return true;
}
//===============================================弹窗处理=============================================
var bgDiv,frameShim,messageDiv;
/** 遮罩弹窗
 * @param title		窗口标题
 * @param content	内容区域内容
 * @param default_menu 信息下面是否自动带“确定
 * @param width		窗口宽度		可留空
 * @param height	内容区域高度	可留空
 * @param top		窗口位置（上）可留空
 * @param left		窗口位置（左）可留空
**/
function MessageBox(title,content,bottom_menu,height,width,top,left){
	if( bgDiv!=null ){
		return false;
	}
	// 处理高度
	var offsetWidth = parseInt(document.body.offsetWidth,10);
	var offsetHeight = parseInt(document.body.offsetHeight,10);
	var scrollHeight = parseInt(document.body.scrollHeight,10);
	var default_message_width = 320;
	var default_message_height = 300;
	var win_width = offsetWidth;
	var win_height = Math.max(offsetHeight,scrollHeight,screen.availHeight-100)+20;
	//var win_height = offsetHeight + 20;
	scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
	//
	width = parseInt(width,10);
	height = parseInt(height,10);
	top = parseInt(top,10);
	left = parseInt(left,10);
	if( isNaN(width) ){
		width = default_message_width;
	}
	if (isNaN(height) ){
		height = default_message_height;
	}
	width = width<100?default_message_width:width;
	height = height<30?default_message_height:height;
	if( isNaN(top) ){
		top = 100;
	}
	top = scrollTop+100;
	if( isNaN(left) ){
		left = (offsetWidth-width-20)/2;
	}
	// 创建背景
	bgDiv = document.createElement("div");
	bgDiv.setAttribute('id','bgDiv');
	bgDiv.style.position	= "absolute";
	bgDiv.style.zIndex		= "9998";
	bgDiv.style.top			= "0";
	bgDiv.style.background	= "#000";
	bgDiv.style.filter		= "progid:DXImageTransform.Microsoft.Alpha(style=1,opacity=30,finishOpacity=70)";
	bgDiv.style.opacity		= "0.7";
	bgDiv.style.left		= "0";
	bgDiv.style.width		= "100%";
	bgDiv.style.height		= win_height + "px";
	//bgDiv.style.height		= '100%';
	document.body.appendChild(bgDiv);
	// 创建shim frame
	frameShim = document.createElement('iframe');
	frameShim.setAttribute('id','frameShim');
	frameShim.setAttribute("src","about:blank",0);
	frameShim.style.width	= bgDiv.style.width;
	frameShim.style.height	= bgDiv.style.height;
	frameShim.style.top		= bgDiv.style.top;
	frameShim.style.left	= bgDiv.style.left;
	frameShim.style.position	= "absolute";
	frameShim.frameBorder	= 0;
	frameShim.scrolling		= "no";
	frameShim.style.filter	= "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=30)";
	frameShim.style.opacity	= "0.4";
	frameShim.style.zIndex	= '9997';
	frameShim.style.display	= "block";
	document.body.appendChild(frameShim);
	// 处理内容区域
	messageDiv = document.createElement("div");
	messageDiv.setAttribute('id','messageDiv');
	messageDiv.style.position	= "absolute";
	messageDiv.style.zIndex		= "9999";
	messageDiv.style.left		= left+'px';
	messageDiv.style.width		= width+'px';
	messageDiv.style.top		= top+'px';
	/*
	var html = '<div class="s2_w_box_t"><span>'+title+'</span><a href="javascript:void(0);" onclick="closeMessageBox();"><img id="close_window_s" src="/images/bg10.gif" width="8" height="8" alt="关闭" /></a></div>';
	html += '<div class="s2_w_box_1">';
	html += '<div class="s_scroll" style="height:'+height+'px;">'+content+'</div>';
	if( bottom_menu!=undefined ){
		html += '<div class="blank10"></div><div class="s_w_box_1_box2">'+bottom_menu+'</div>';
	}
	html += '<div class="clear"></div></div><div class="s2_w_box_b"></div>';
	document.body.appendChild(messageDiv);
	messageDiv.innerHTML = '<div class="s2_w_box">'+html+'</div>';
	*/
	var html = '<div class="tBorder" style="width:'+width+'px">\
                	<div class="tBorder1">\
                    	<h2 class="tBoxH2"><span class="right"><a href="javascript:void(0);" onclick="closeMessageBox();"><img id="close_window_s" src="'+_img_url+'/images/bg10.gif" width="8" height="8" alt="关闭" /></a></span>'+title+'</h2>\
                        <div class="tBox">\
                        <div class="s_scroll" style="height:'+height+'px;">'+content+'</div>\
                        ';
	if( bottom_menu!=undefined ){
		html += '<div class="blank10"></div><div class="s_w_box_1_box2">'+bottom_menu+'</div><div class="clear"></div>';
	}
    html += '			</div>\
    				</div>\
                </div>';
	document.body.appendChild(messageDiv);
	messageDiv.innerHTML = html;
	//bgDiv.appendChild(messageDiv);
}
//关闭遮罩弹窗
function closeMessageBox(){
	if( messageDiv!=null ){
		document.body.removeChild(messageDiv);
	}
	if( bgDiv!=null ){
		document.body.removeChild(bgDiv);
	}
	if( frameShim!=null ){
		document.body.removeChild(frameShim);
	}
	bgDiv		= null;
	frameShim	= null;
	messageDiv	= null;
	window.focus();
}
// 快捷弹窗处理，类似Alert
function MyAlert(msg,title){
	if( title==undefined ){
		title = "提示信息";
	}
	var bottom_menu = '<input name="s_close_btn" id="s_close_btn" value="确定" type="button" class="btn_4" onclick="closeMessageBox();" />';
	MessageBox(title,msg,bottom_menu,50);
}

// ==========================================弹窗结束==========================================

// ==========================================获取短消息的定时器=================================
/**
 * 重写setTimeout，使其可以接收参数
 */
/*
var _st = window.setTimeout;
window.setTimeout = function(fRef, mDelay) {
	if(typeof fRef == 'function'){
		var argu = Array.prototype.slice.call(arguments,2);
		var f = (function(){ fRef.apply(null, argu); });
		return _st(f, mDelay);
	}
	return _st(fRef,mDelay);
}
*/
var ori_web_title = '';
var cron_msg_title_flash = null;
/**
 * 读取最新的消息信息
 */
function cronNewMessage(timeout){
	if( timeout==undefined ){
		timeout = 20000;
	}
	if( ori_web_title=='' ){
		ori_web_title = document.title;
	}
	var pars = '_do=new_msg&timeout='+timeout+'&rid='+randomString();
	var url = '/interface/message.php';
	new Ajax.Request(
		url,{
			method:'get',
			evalJS : true,
			parameters:pars,
			onComplete:function(xmlRequest){
				// 处理函数
				var ret = xmlRequest.responseText;
				eval('ret = ' + ret + ';');
				var timeout = ret['timeout'];
				cronNewMessageResult(ret);
				timeout = parseInt(timeout,10);
				if( timeout<1 ){
					timeout = 20000;
				}
				window.setTimeout(cronNewMessage,timeout);
			}
		}
	);
}
// 窗口标题闪现
function cronNewMessageSetTitle(){
	var now_title = document.title;
	if( ori_web_title==now_title ){
		document.title = '【有新消息】'+ori_web_title;
	}
	else{
		document.title = ori_web_title;
	}
}

// 设置消息
function cronNewMessageResult(num_result){
	var html = '';
	// 总数量
	var new_num = parseInt(num_result['new'],10);
	var msg_num = parseInt(num_result['msg'],10);
	var sys_num = parseInt(num_result['sys'],10);
	var gbook_num = parseInt(num_result['gbook'],10);
	var gbook_reply_num = parseInt(num_result['gbook_reply'],10);
	//群组回复
	//var group_num = parseInt(num_result['group_reply'],10);
	var comment_num = parseInt(num_result['comment'],10);
	var comment_reply_num = parseInt(num_result['comment_reply'],10);

	//团队回复
	//var new_team_reply_count = parseInt(num_result['new_reply_count'],10);
	// 页面顶部总数量
	var top_obj = $('new_msg_top');
	var top_msg_obj = $('top_msg_msg');
	var top_sys_obj = $('top_msg_sys');
	var top_comment_obj = $('top_msg_comment');
	var top_comment_reply_obj = $('top_msg_comment_reply');
	//var top_group_obj = $('top_msg_group');
	//var top_team_reply_obj = $('top_msg_team_reply');
	var top_gbook_obj = $('top_msg_gbook');
	var top_gbook_reply_obj = $('top_msg_gbook_reply');

	// 首页中间的消息显示
	var new_msg_msg = $('new_msg_msg');
	var new_msg_sys = $('new_msg_sys');
	var new_msg_comment = $('new_msg_comment');
	var new_msg_comment_reply = $('new_msg_comment_reply');
	//var new_msg_group = $('new_msg_group');
	var new_msg_gbook = $('new_msg_gbook');
	var new_msg_gbook_reply = $('new_msg_gbook_reply');

	// 设置顶部
	if( top_obj ){
		if( new_num>0 ){
			top_obj.innerHTML = '<font color="red">('+new_num+')</font>';
		}
		else{
			top_obj.innerHTML = '';
		}
	}

	if( top_msg_obj ){
		if( msg_num>0 ){
			top_msg_obj.innerHTML = '<a href="/message/box.php">短消息<font color="red">('+msg_num+')</font></a>';
		}
		else{
			top_msg_obj.innerHTML = '<a href="/message/box.php">短消息</a>';
		}
	}
	if( top_sys_obj ){
		if( sys_num>0 ){
			top_sys_obj.innerHTML = '<a href="/message/sys.php">系统消息<font color="red">('+sys_num+')</font></a>';
		}
		else{
			top_sys_obj.innerHTML = '<a href="/message/sys.php">系统消息</a>';
		}
	}


	if( top_comment_obj ){
		if( comment_num > 0 ){
			top_comment_obj.innerHTML = '<a href="/comment/">评论<font color="red">('+comment_num+')</font></a>';
		}
		else{
			top_comment_obj.innerHTML = '<a href="/comment/">评论</a>';
		}
	}


	if( top_comment_reply_obj ){
		if( comment_reply_num>0 ){
			top_comment_reply_obj.innerHTML = '<a href="/comment/?_do=send">评论回复<font color="red">('+comment_reply_num+')</font></a>';
		}
		else{
			top_comment_reply_obj.innerHTML = '<a href="/comment/?_do=send">评论回复</a>';
		}
	}

	if( top_gbook_obj ){
		if( gbook_num > 0 ){
			top_gbook_obj.innerHTML = '<a href="/comment/?_do=guestbook">留言<font color="red">(' + gbook_num + ')</font></a>';
		}
		else{
			top_gbook_obj.innerHTML = '<a href="/comment/?_do=guestbook">留言</a>';
		}
	}

	if( top_gbook_reply_obj ){
		if( gbook_reply_num>0 ){
			top_gbook_reply_obj.innerHTML = '<a href="/comment/?_do=guestbookreply">留言回复<font color="red">（'+gbook_reply_num+'）</font></a>';
		}
		else{
			top_gbook_reply_obj.innerHTML = '<a href="/comment/?_do=guestbookreply">留言回复</a>';
		}
	}

	// 设置首页
	if( new_msg_msg ){
		if( msg_num>0 ){
			new_msg_msg.className = 'red index_msg_ddr grey';
		}
		else{
			new_msg_msg.className = 'index_msg_ddr grey';
		}
		new_msg_msg.innerHTML = '<a href="/message/box.php">'+msg_num+'条新</a>';
	}
	if( new_msg_sys ){
		if( sys_num>0 ){
			new_msg_sys.className = 'red index_msg_ddr grey';
		}
		else{
			new_msg_sys.className = 'index_msg_ddr grey';
		}
		new_msg_sys.innerHTML = '<a href="/message/sys.php">'+sys_num+'条新</a>';
	}
	if( new_msg_comment ){
		if( comment_num>0 ){
			new_msg_comment.className = 'red index_msg_ddr grey';
		}
		else{
			new_msg_comment.className = 'index_msg_ddr grey';
		}
		new_msg_comment.innerHTML = '<a href="/comment/">'+comment_num+'条新</a>';
	}
	if( new_msg_comment_reply ){
		if( comment_reply_num>0 ){
			new_msg_comment_reply.className = 'red index_msg_ddr grey';
		}
		else{
			new_msg_comment_reply.className = 'index_msg_ddr grey';
		}
		new_msg_comment_reply.innerHTML = '<a href="/comment/?_do=send">'+comment_reply_num+'条新</a>';
	}
	if( new_msg_gbook ){
		if( gbook_num > 0 ){
			new_msg_gbook.className = 'red index_msg_ddr grey';
		}
		else{
			new_msg_gbook.className = 'index_msg_ddr grey';
		}
		new_msg_gbook.innerHTML = '<a href="/comment/?_do=guestbook">'+gbook_num+'条新</a>';
	}

	if( new_msg_gbook_reply ){
		if( gbook_reply_num>0 ){
			new_msg_gbook_reply.className = 'red index_msg_ddr grey';
		}
		else{
			new_msg_gbook_reply.className = 'index_msg_ddr grey';
		}
		new_msg_gbook_reply.innerHTML = '<a href="/comment/?_do=guestbookreply">'+gbook_reply_num+'条新</a>';
	}
	/*
	if( new_msg_group ){
		if( group_num>0 ){
			new_msg_group.className = 'red index_msg_ddr grey';
		}
		else{
			new_msg_group.className = 'index_msg_ddr grey';
		}
		new_msg_group.innerHTML = '<a href="/group/?_do=reply_new">'+group_num+'条新</a>';
	}
	*/


	if( new_num>0 ){
		document.title = '有新消息 '+ori_web_title;
		if( !cron_msg_title_flash ){
			cron_msg_title_flash = window.setInterval("cronNewMessageSetTitle()",1000);
		}
	}
	else{
		if( cron_msg_title_flash ){
			window.clearInterval(cron_msg_title_flash);
			document.title = ori_web_title;
		}
		cron_msg_title_flash = null;
	}
	if( new_num>0&&num_result['sound']==1 ){
		// 有提示音
		/*
		html = '\
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="1" height="1">\
<param name="movie" value="/images/flash/sys_msg_sound.swf" />\
<param name="quality" value="high" />\
<param name="allowscriptaccess" value="always" />\
<param name="wmode" value="opaque" />\
<param name="menu" value="false" />\
<param name="autoplay" value="0" />\
<param name="flashvars" value="&amp;save_action=/account/as/face_save.php&amp;image_path=/account/as/this.jpg&amp;upload_action=/account/as/face_upload.php&amp;" />\
<embed src="/images/flash/sys_msg_sound.swf" width="1" height="1" quality="high" allowscriptaccess="always" wmode="opaque" menu="false" autoplay="0" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" flashvars=""></embed>\
</object>';
*/
		html = '<object id="MediaPlayer1" width="0" height="0" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" align="baseline" border="0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject"><param name="URL" value="/images/msg.mid"><param name="autoStart" value="true"><param name="volume" value="100"><param name="invokeURLs" value="false"><param name="playCount" value="1"><param name="defaultFrame" value="datawindow"><embed src="'+_img_url+'/images/msg.mid" align="baseline" border="0" width="0" height="0" type="application/x-mplayer2"pluginspage="" name="MediaPlayer1" showcontrols="1" showpositioncontrols="0" showaudiocontrols="1" showtracker="1" showdisplay="0" showstatusbar="1" autosize="0" showgotobar="0" showcaptioning="0" autostart="1" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" enablecontextmenu="1" playcount="1" clicktoplay="0" defaultframe="datawindow" invokeurls="0" volume="100"></embed></object>';
	}
	$('top_msgsound_div').innerHTML = html;
}

// ============================================短消息定时器结束==================================

// ============================================加好友处理========================================
// 加f_uid为好友
function f_addFriend(f_uid){
	// 获取f_uid的好友设置
	var pars = '_do=check_to_add&f_uid='+f_uid+'&rid='+randomString();
	var url = '/interface/friend.php';
	new Ajax.Request(
		url,{
			method:'post',
			evalJS : true,
			parameters:pars,
			onComplete:function(xmlRequest){
				// 处理函数
				var ret = xmlRequest.responseText;
				eval('ret = ' + ret + ';');
				if( ret['success'] ){
					f_addFriendPanle(ret['f_user_info']);
				}
				else{
					alert(ret['desc']);
				}
			}
		}
	);
}
// 填写好友请求信息的面板
function f_addFriendPanle(user){
	// 创建分组面板
	var title = '请求加'+user['gender_ta']+'为好友';
	var html = '\
	<div class="add_friend_l">\
		<div class="PT_span head_img_bg mauto"><img src="'+user['photo_50_url']+'" width="50" height="50" alt="'+user['name']+'" /></div>\
	</div>\
	<div class="add_friend_r">\
		<p class="lh24">需通过'+user['name']+'的验证才能加'+user['gender_ta']+'为好友。<br />给'+user['gender_ta']+'的附加信息：</p>\
		<textarea name="add_friend_remark" id="add_friend_remark" rows="15" cols="36" class="t_in1" onfocus="this.className=\'t_in2\';" onblur="this.className=\'t_in1\';" style="width:215px; height:60px" ></textarea>\
		<div class="blank10"></div>\
	</div>';
	var bottom_menu = '<div class="btnBox"><div class="btn_4 right"  onclick="closeMessageBox();" style="cursor:pointer;">取消</div><div><input name="m_btn" value="确定" type="button" class="btn_4 left" onclick="f_addFriendSave('+user['uid']+');" /></div></div>';
	MessageBox(title,html,bottom_menu,130,360);
}

function f_addFriendSave(f_uid){
	var remark = $F('add_friend_remark').trim();
	if( !remark ){
		alert('请输入好友附加信息！');
		$('add_friend_remark').focus();
		return false;
	}
	closeMessageBox();
	// 加好友
	var pars = '_do=add_friend&f_uid='+f_uid+'&remark='+encodeURIComponent(remark)+'&rid='+randomString();
	var url = '/interface/friend.php';
	new Ajax.Request(
		url,{
			method:'post',
			evalJS : true,
			parameters:pars,
			onComplete:function(xmlRequest){
				// 处理函数
				var ret = xmlRequest.responseText;
				eval('ret = ' + ret + ';');
				if( ret['success'] ){
					alert('你已经申请加'+ret['f_user_info']['name']+'为好友，请等待'+ret['f_user_info']['gender_ta']+'审核');
				}
				else{
					alert(ret['desc']);
				}
			}
		}
	);
}

// ==============================================加好友处理结束========================================

// ==============================================统一的提示处理，3秒钟自动隐藏===========================
// 显示提示层
function showNotice(msg,success,longchar){
	var notice_div = $('notice_div');
	if( success!=1 ){
		success = 1;
	}
	if( longchar!=1 ){
		longchar = 0;
	}
	if( notice_div ){
		var html = '';
		if( success==1 ){
			var class_name = 'remind_bg_5';
			if( longchar==0 ){
				class_name = 'remind_bg_5 a_m_nav_remind';
			}
			// 成功提示框
			var html = '\
			<div class="'+class_name+'">\
				<div class="remind_bg_5_box">\
				<img src="'+_img_url+'/images/bg35.gif" width="22" height="16" alt="成功" align="absmiddle" /> '+msg+'\
				</div>\
				<div class="remind_bg_5_bot"></div>\
				<div class="blank10"></div>\
			</div>\
			';
		}
		else{
			var class_name = 'wront_remind';
			if( longchar==0 ){
				class_name = 'wront_remind a_m_nav_remind';
			}
			// 失败提示框
			var html = '\
			<div class="'+class_name+'">\
				<div class="wront_remind_box">\
					<img src="'+_img_url+'/images/bg35_w.gif" width="16" height="16" alt="失败" align="absmiddle" />　'+msg+'\
				</div>\
				<div class="wront_remind_bot"></div>\
			</div>\
			';
		}
		notice_div.innerHTML = html;
		notice_div.style.display = 'block';
		// 设置几秒后自动隐藏成功提示框
		window.setTimeout(hiddenNotice,3000);
	}
}
// 隐藏消息提示层
function hiddenNotice(){
	var notice_div = $('notice_div');
	if( notice_div ){
		notice_div.style.display = 'none';
	}
}

// ==============================================统一的提示处理，3秒钟自动隐藏 结束===========================

/**
 * 初始化并回置联动菜单数据
 */
function dselect_set_back( name1 , array1 , name2 , array2 , value2 , N )
{
	//ini_select( name1 , array1  );
	//add_event( name1 , "change" , function(){ adjust_select( name1 , name2 , array2 } );
	dselect_set_ini( name1 , array1 , name2 , array2 , N );
	if( value2 != '' )
	{
		set_select_by_2( name1 , name2 , array2 , value2  );
	}
}

/**
 * 初始化联动菜单
 * @param string|obj 下拉一选项
 * @param array 下拉二选项
 */
function dselect_set_ini( select1 , array1 , select2 , array2 , N  )
{
	ini_select( select1 , array1 , N );
	Event.observe ( $(select1), 'change', function(){ adjust_select( select1 , select2 , array2 ) } );
}

/**
 * 初始化select下拉框
 * @param string 下拉菜单名
 * @param
 */
function ini_select( name , Karray , N  )
{
	var selObj = $( name );
	for(var key in Karray )
	{
		//document.write key;
		if (key == 0 && N == 1)
		{
			//alert( Karray[key] );
			continue;
		}

		if ( (typeof(Karray[key]) != 'function') && (Karray[key].toString().indexOf('(object)')==-1) )
		{
			selObj.options[selObj.length]=new Option( Karray[key] , key );
			selObj.options[selObj.length-1].title = Karray[key];
		}
	}
}

/**
 * adjust_select用于保持二级联动之间的一致性
 *
 * 由1级选项自动调整2级选项
 * array2是和array1相对应的一个关联数组
 * 详细格式见city.js
 */
function adjust_select( name1 , name2 , array2 , N )
{
	var obj1 = $( name1 );
	var obj2 = $( name2 );

	// 取得obj1被选中的项
	var str = parseInt( obj1.options[obj1.selectedIndex].value );

	if (!str)
	{
		//当一级菜单选择了默认（value为空）的项目时，处理二级菜单
		obj2.innerHTML="";
		//alert (name2);
		switch (name2) {
			case 'city':
				add_option (name2, "选择地区", '');
				break;
			default:
		}
	}
	else if( str != NaN )
	{
		obj2.innerHTML="";
		if (name2 == 'school_s')
			add_option (name2, '不限', '');
		ini_select( name2 , array2[str] , N );
	}
	else
	{
		obj2.innerHTML="";
	}
}


/**
 * 由二级菜单的值直接推算一级菜单
 */
function set_select_by_2( name1 , name2 , array2 , value2 )
{
	value2 = value2 + '';
	var pcode = value2.substr( 0 , 2 );
	set_select( name1 , pcode );
	adjust_select( name1 , name2 , array2 );
	set_select( name2 , value2 );
}

/**
 * 回置下拉框
 *
 * select 的回置必须指定value，如果该option没有value，则显示为空白
 * select回置为数值时，firefox会把01变成1，而ie不会，必须精确匹配
 */
function set_select( name , value )
{
	var sel = getElement( name );
	var ops = sel.options;
	for( var i = 0 ; i < ops.length ; i++ )
	{
		if( ops[i].value == value  )
		{
			try
			{
				if( i != ops.selectedIndex )
				{
					ops.selectedIndex = i;
					ops[i].selected = true;
				}

			}
			catch( e )
			{
				// alert( e.description );
				// ie对于动态生成的下拉框会抛出一个“不能设置selected属性，未指明的错误”的异常
				// 原因不明，先不做处理
			}


		}
	}
}


function select_set_back( name , array , value , N )
{
	ini_select( name , array , N );
	if( value != '' )
	{
		set_select( name , value );
	}
}

/**
 * JS回置函数群
 *
 */

 function getElement( name )
 {
	var el = document.getElementsByName( name );
	if( el[0] == null )
	{
    var e2 = document.getElementById( name );
    if(e2 == null)
    {
		alert( 'cannot find ' + name + ' ! ' );
    }
    else
    {
      return e2;
    }
	}
	else
	{
		return el[0];
	}

 }
/**
 * 添加select的option项
 *
 */
function add_option( name , texts , value )
{
	var selObj = $( name );
	selObj.options[selObj.length]=new Option( texts , value );
}

var dmsg_depth = 0;
var dmsg_obj = null;
function dmsg(msg, pre){
	if( !$('dmsg') ){
		dmsg_obj = document.createElement("div");
		dmsg_obj.setAttribute('id','dmsg');
		dmsg_obj.style.display = 'none';
		dmsg_obj.style.backgroundColor = '#ddd';
		dmsg_obj.style.padding = '5px';
		dmsg_obj.style.textAlign = 'left';
		dmsg_obj.style.position = 'absolute';
		dmsg_obj.style.zIndex  = '1000';
		dmsg_obj.style.rigth = '50px';
		dmsg_obj.style.width = '200px';
		document.body.appendChild(dmsg_obj);
	}
	$('dmsg').show();
	if ($('dmsg')){
		dmsg_depth++;
		if ( (typeof msg == 'object') && ( dmsg_depth < 3) ){
			dmsg( ( (typeof pre != 'undefined') ? (pre + ' => ' ) : 'Object' ) + ' {');
			for( var a in msg){
				dmsg(msg[a], a);
			}
			dmsg('}');
		}
		else{
			$('dmsg').innerHTML += ( (typeof pre != 'undefined') ? (pre + ' => ' ) : '' ) + msg + "<br />\n";
		}
		dmsg_depth--;
	}
	else{
		alert(msg);
	}
}