// 配置
// 当前域
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 checkMobile(mobile){
  
	var a = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15\d{9}|18[89]\d{8}$/;  
	if( mobile.length!=11||!mobile.match(a) )
	{  
		return false; 
	}
	else
	{
		return mobile.match(a);  
	}  
}  
// 根据跟定的月份和日期，获取星座数据
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_5" 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为好友,王恩东2009-11-24修改
function f_addFriend(f_uid,uid,url){
	// 获取f_uid的好友设置
	if(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']);
				}
			}
		}
	);
 }
 else
 {
	alert("您还没有登录，不能加他(她)为您的好友");
	return window.location.href="http://home.shenmo.com/login.php?referer="+url;
 }
}
// 填写好友请求信息的面板
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_5 right"  onclick="closeMessageBox();" style="cursor:pointer;">取消</div><div><input name="m_btn" value="确定" type="button" class="btn_5 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);
	}
}

//删除select 的 option
function del_option( name ){
	var selObj = $( name );
	for(var i=Number(selObj.options.length) ; i > 0  ; i--){  	
          
          selObj.options[i - 1]= null  ;
     	
    } 
}

// JavaScript Document
function resizeimg(ImgD,iwidth,iheight) {
      var image=new Image();
      image.src=ImgD.src;
      if(image.width>0 && image.height>0){
         if(image.width/image.height>= iwidth/iheight){
            if(image.width>iwidth){
                ImgD.width=iwidth;
                ImgD.height=(image.height*iwidth)/image.width;
            }else{
                   ImgD.width=image.width;
                   ImgD.height=image.height;
                 }
                ImgD.alt=ImgD.width+"×"+ImgD.height;
         }
         else{
                 if(image.height>iheight){
                        ImgD.height=iheight;
                        ImgD.width=(image.width*iheight)/image.height;
                 }else{
                         ImgD.width=image.width;
                         ImgD.height=image.height;
                      }
                 ImgD.alt=ImgD.width+"×"+ImgD.height;
             }
　　　//　　ImgD.style.cursor= "pointer"; //改变鼠标指针
　　　//　　ImgD.onclick = function() { window.open(this.src);} //点击打开大图片
　　　　if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器，如果是IE
　　　　//　　ImgD.title = "请使用鼠标滚轮缩放图片，点击图片可在新窗口打开";
　　　　　　ImgD.onmousewheel = function img_zoom() //滚轮缩放
　　　　　 {
　　　　　　　　　　var zoom = parseInt(this.style.zoom, 10) || 100;
　　　　　　　　　　zoom += event.wheelDelta / 12;
　　　　　　　　　　if (zoom> 0)　this.style.zoom = zoom + "%";
　　　　　　　　　　return false;
　　　　　 }
　　　   } else { //如果不是IE
　　　　　　　  //    ImgD.title = "点击图片可在新窗口打开";
　　　　　　    }
     }
}


// 实现可拖动的div
    /*-------------------------鼠标拖动---------------------*/    
function drag(dragid){ 
    var od = document.getElementById(dragid);    
    var dx,dy,mx,my,mouseD;
    var odrag;
   // var isIE = document.all ? true : false;
	var isIE = (document.all) ? true : false; //document.all 只有ie支持此属性
	//var ieVersion = 7; //IE版本，默认为7
	//if (isIE)	ieVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);
    document.onmousedown = function(e){
        var e = e ? e : event;
        if(e.button == (document.all ? 1 : 0))
        {
            mouseD = true;            
        }
    }
    document.onmouseup = function(){
        mouseD = false;
        odrag = "";
        if(isIE)
        {
            od.releaseCapture();
           // if(ieVersion<7) od.filters.alpha.opacity = 100;
			od.style.filter = "alpha(opacity=100)";
			//else od.style.opacity = 1;
        }
        else
        {
            window.releaseEvents(od.MOUSEMOVE);
            od.style.opacity = 1;
        }  
		od.style.cursor = 'default';      
    }
    
    
    //function readyMove(e){    
    od.onmousedown = function(e){
        odrag = this;
        var e = e ? e : event;
        if(e.button == (document.all ? 1 : 0))
        {
            mx = e.clientX;
            my = e.clientY;
            od.style.left = od.offsetLeft + "px";
            od.style.top = od.offsetTop + "px";
			od.style.cursor = 'move';
            if(isIE)
            {
                od.setCapture();                
               // if(ieVersion<7) od.filters.alpha.opacity = 50;
				od.style.filter = "alpha(opacity=50)";
				//else od.style.opacity = 0.5;
            }
            else
            {
                window.captureEvents(Event.MOUSEMOVE);
                od.style.opacity = 0.5;
            }
            
            //alert(mx);
            //alert(my);
            
        } 
    }
    document.onmousemove = function(e){
        var e = e ? e : event;
        
        //alert(mrx);
        //alert(e.button);        
        if(mouseD==true && odrag)
        {        
            var mrx = e.clientX - mx;
            var mry = e.clientY - my;    
            od.style.left = parseInt(od.style.left) +mrx + "px";
            od.style.top = parseInt(od.style.top) + mry + "px";            
            mx = e.clientX;
            my = e.clientY;
            
        }
    }
}

//根据对象位置弹出层,obj,pos{1上2右3下4左}
function popDivWithObj(id,mask,width,height,title,content,close,obj,pos){
	  var xy,left,top;
	  if (obj == null){
		throw new Error("object of html is necessary");
	  }	 
	  xy = getAbsPoint(obj);
	  
	 // timeout = timeout || 3000;	
	  pos = pos || 3;		  
	  switch(pos)
	  {
	  	 case 1://上
		 	 left = xy.x;top = (xy.y-height);break;
		 case 2://右
		 	 left = (xy.x + obj.offsetWidth); top = xy.y;break;	
		 case 3://下		 	
		 	 left = xy.x;
			 top = xy.y+obj.offsetHeight;		
			 break;				 	 
		 case 4://左
		 	 left = (xy.x -width); top = xy.y;break;
		 case 5://下右对齐
		 	 left = xy.x+obj.offsetWidth-width; top = xy.y+obj.offsetHeight; break;		
	  	 default://下中
		 	 left = (xy.x- width/2 + obj.offsetWidth/2);top = (xy.y + obj.offsetHeight);//alert(top+'*'+left);
	  }	
	 
	  if(top<0 || left<0) top = left = 0;
	  openNewDiv(id,mask,width,height,title,content,close,left,top);   
	 //t =  setTimeout("openNewDiv('"+id+"','"+mask+"',"+width+","+height+",'"+title+"','"+content+"','"+close+"',"+left+","+top+")",timeout);   
}
//根据事件弹出层
function popDivWithEvent(id,mask,width,height,title,content,close,evt){
	  if (evt == null){
		throw new Error("event is necessary");
	  }
	  var evt = window.event?window.event:evt; 
	  var left= evt.clientX; 
	  var top = evt.clientY+5;
	  openNewDiv(id,mask,width,height,title,content,close,left,top);   
}
//在指定位置弹出层，并可移动,xpos,ypos都为0时 居中位置
function openNewDiv(_id,m,width,height,title,content,close,xpos,ypos){
	
    var isIE = (document.all) ? true : false; //document.all 只有ie支持此属性
	var ieVersion = 7; //IE版本，默认为7
	if (isIE)	ieVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);
	
  XY = getPageXY(); 
  m = m || "";
  title = title || "";
  close = close || "关闭";
  xpos = xpos || (parseInt(XY[0]) - width) / 2  // 屏幕居中
  ypos = ypos || (parseInt(XY[1]) - height) / 2 // 屏幕居中
  if (docEle(_id)) document.body.removeChild(docEle(_id));
  if (m && docEle(m)) document.body.removeChild(docEle(m));
  // 新激活图层
  var newDiv = document.createElement("div");
  newDiv.id = _id;
  newDiv.style.position = "absolute";
  newDiv.style.zIndex = "9999";
  newDiv.style.width = width+"px";
  newDiv.style.height = height+"px";
  newDiv.style.top = ypos + "px"; // 屏幕居中;
  //newDiv.style.textAlign = "center";
  newDiv.style.left = xpos + "px"; // 屏幕居中
  newDiv.style.background = "#ffffff";
  newDiv.style.border = "1px solid #860001";
  newDiv.style.overflow = "auto";
  //newDiv.style.padding = "5px";  
 
  if(m){
	  // mask图层
	  var newMask = document.createElement("div");
	  newMask.id = m;
	  newMask.style.position = "absolute";
	  newMask.style.zIndex = "1";
	//  newMask.style.width = document.body.scrollWidth+"px";
//	  newMask.style.height = document.body.scrollHeight+ "px";
	  newMask.style.width = XY[0]+"px";
	  newMask.style.height = XY[1]+ "px";
	  newMask.style.top = "0px";
	  newMask.style.left = "0px";
	  newMask.style.background = "#000";
	  newMask.style.filter = "alpha(opacity=40)";
	  newMask.style.opacity = "0.40";
	  document.body.appendChild(newMask); 
  }
  //将所有select置为不可用
  if (ieVersion < 7) { 
        var oSelects = document.getElementsByTagName("select");
        for (var i = 0; i < oSelects.length; i++) {
            oSelects[i].disabled = true;
            oSelects[i].style.visibility = "hidden";
        }
    }
 
  //title height:30px
  if(title){
	  header = "<div style='width:"+width+"px;background:#cccccc;line-height:30px' onmousedown=\"drag('"+_id+"');\"><div style='float:left;font-weight:bold;padding-left:10px;background:#cccccc;width:"+(width-40-10-10)+"px'>"+title+"</div><span  onclick=\"closeLightBox('"+_id+"','"+m+"')\" style=\"cursor: pointer; color: Blue; width:40px;background:#cccccc; float:right;padding-right:10px\">"+close+"</span></div>";	  
	  newDiv.innerHTML = header;	 
  }else{
	  newDiv.onmousedown = function(){drag(_id);}//可移动
  }
 
  //内容层
  var  contentDiv = document.createElement("div");
 
  contentDiv.style.height = (title) ? height-40+"px" : height+"px";
  contentDiv.style.width = width+"px";
/*  contentDiv.style.paddingLeft = "5px";  
  contentDiv.style.paddingRight = "5px"; */ 
  contentDiv.style.clear = "both";
  contentDiv.innerHTML = content;
  newDiv.appendChild(contentDiv);
  document.body.appendChild(newDiv);//alert("dd");
}
/**************************************************** 
获取坐标 
*******************************************************/ 
function getPageXY() { 
var xScroll, yScroll; 
if (window.innerHeight && window.scrollMaxY) { 
xScroll = document.body.scrollWidth; 
yScroll = window.innerHeight + window.scrollMaxY; 
}else if (document.body.scrollHeight > document.body.offsetHeight){ 
xScroll = document.body.scrollWidth; 
yScroll = document.body.scrollHeight; 
}else { 
xScroll = document.body.offsetWidth; 
yScroll = document.body.offsetHeight; 
} 

var windowWidth, windowHeight; 
if (self.innerHeight) { 
windowWidth = self.innerWidth; 
windowHeight = self.innerHeight; 
}else if (document.documentElement && document.documentElement.clientHeight) { 
windowWidth = document.documentElement.clientWidth; 
windowHeight = document.documentElement.clientHeight; 
}else if (document.body) { 
windowWidth = document.body.clientWidth; 
windowHeight = document.body.clientHeight; 
} 

if(yScroll < windowHeight){ 
pageHeight = windowHeight; 
}else { 
pageHeight = yScroll; 
} 

if(xScroll < windowWidth){ 
pageWidth = windowWidth; 
}else { 
pageWidth = xScroll; 
} 

var arrayPageXY = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
return arrayPageXY; 
} 
function docEle(id) {
 // return document.getElementById(arguments[0]) || false;
  return document.getElementById(id) || false;
}
 //点击关闭lightbox
function closeLightBox(_id,m) {
   if (_id && docEle(_id) )document.body.removeChild(docEle(_id));
   if (m && docEle(m)) document.body.removeChild(docEle(m));
   var isIE = (document.all) ? true : false; //document.all 只有ie支持此属性
	var ieVersion = 7; //IE版本，默认为7
	if (isIE) {
		ieVersion = parseFloat(navigator.appVersion.split("MSIE")[1]);
	}
   //将所有select置为可用
     if (ieVersion < 7) { 
        var oSelects = document.getElementsByTagName("select");
        for (var i = 0; i < oSelects.length; i++) {
            oSelects[i].disabled = false;
            oSelects[i].style.visibility = "visible";
        }
    }	
   return false;
}
//取得HTML控件绝对位置,e为html元素
function getAbsPoint(e){
	var x = e.offsetLeft;
	var y = e.offsetTop;
	while(e = e.offsetParent){
		x += e.offsetLeft;
		y += e.offsetTop;
	}
	return {"x": x, "y": y};
}

//显示弹出层
function showDivById(showDiv,obj,pos){

	var xy,left,top;
	  if (obj == null){
		throw new Error("object of html is necessary");
	  }	 
	  xy = getAbsPoint(obj);	  
	  pos = pos || 3;		  
	  switch(pos)
	  {
	  	 case 1://上
		 	 left = xy.x;top = (xy.y-height);break;
		 case 2://右
		 	 left = (xy.x + obj.offsetWidth); top = xy.y;break;	
		 case 3://下		 	
		 	 left = xy.x;
			 top = xy.y+obj.offsetHeight;		
			 break;				 	 
		 case 4://左
		 	 left = (xy.x -width); top = xy.y;break;
		 case 5://下右对齐
		 	 left = xy.x+obj.offsetWidth-width; top = xy.y+obj.offsetHeight; break;		
	  	 default://下中
		 	 left = (xy.x- width/2 + obj.offsetWidth/2);top = (xy.y + obj.offsetHeight);//alert(top+'*'+left);
	  }		 
	  if(top<0 || left<0) top = left = 0;
	
	  
	  document.getElementById(showDiv).style.position = "absolute";
	  document.getElementById(showDiv).style.zIndex = "9999";	
	  document.getElementById(showDiv).style.top = top + "px"; 
	  document.getElementById(showDiv).style.left = left + "px";
	  document.getElementById(showDiv).style.display = '';

}
