//获取医生标签信息，调用注意：
//必须引入jquery
//<a href="http://zhangq.u.ysnet.cn/" rel="showDoctorDetails" rev="zhangq">张琪</a>
//rel必须
//rev为医生ID
var h = 0;
$(function(){
	$('a[rel=showDoctorDetails]').mouseover(function(){
		user = $(this).attr('rev');
		o_left = ElementPos.GetLeft(this);
		o_top = ElementPos.GetTop(this)+14;
		window_width = document.body.clientWidth;
		if(window_width-o_left <290){
			o_left = o_left-275
			adjust_left = o_left + 195;
		}else{
			o_left = o_left;
			adjust_left = o_left;
		}
		$('#showTabDetails').remove();
		h = setTimeout('timeplay("'+user+'",'+o_left+','+o_top+','+adjust_left+')',500);
	}).bind('mouseout',function(){
		Clear();
		Close();
	})
})
function showDoctorDetails(user,o){
	o_left = ElementPos.GetLeft(o);
	o_top = ElementPos.GetTop(o)+14;
	window_width = document.body.clientWidth;
	if(window_width-o_left <290){
		o_left = o_left-275
		adjust_left = o_left + 195;
	}else{
		o_left = o_left;
		adjust_left = o_left;
	}
	$('#showTabDetails').remove();
	h = setTimeout('timeplay("'+user+'",'+o_left+','+o_top+','+adjust_left+')',500);
}
function hideDoctorDetails(){
	Clear();
	Close();
}
function timeplay(user,Left,Top,adjustLeft){
	//alert(adjustLeft + '---' + Left);
	loading_content = '<dl id="showTabDetailsLoading" style="top:'+Top+'px;left:'+adjustLeft+'px;position:absolute;padding-right:8px; margin:0; color:#222; border:1px solid;border-color:#95b0c7 #637eaa #637eaa #95b0c7; background: url(/skins/default/images/info_card_BG.gif) no-repeat #e4f5ff; font-size:12px; line-height:20px; text-indent:0;">正在读取数据...</dl>';
	$('html>body').append(loading_content);
	$.ajax({
	 	type:'get',
	 	url: '/xml/doctor_info.php',
		data: {'user_id':user},
		success: function(xml){
			var xml = $(xml).find("doctor");
            name = xml.children('name').text();//姓名
            title = xml.children('title').text();//职称
            dpt_name = xml.children('dpt_name').text();//真实科室
            hpt_name = xml.children('hpt_name').text();//真实医院
            ask_count = xml.children('ask_count').text();//咨询数
            ask_reply_count = xml.children('ask_reply_count').text();//回复数
            shanchang = DelHtmlTag(xml.children('shanchang').text());//擅长疾病
            url = xml.children('url').text();//诊室地址
            icon = xml.children('icon').text();//头像地址
            dpt_url = xml.children('dpt_url').text();//真实科室地址
            hpt_url = xml.children('hpt_url').text();//医院地址
            //sdp_url = xml.children('sdp_url').text();//所在标准科室地址
            can_reg = xml.children('can_reg').text();//能否挂号 0为不能 1为能
            can_reg = (can_reg !=0) ? '<a href="'+url+'reg.php?ctrl=add" style="text-decoration:none; color:#069; background-color:#fff; padding:3px 10px 2px; border:1px solid; border-color:#74cbd6 #67bad6 #67bad6 #74cbd6;">预约挂号</a>' : '';
			Height = 178,
			Width = 290,
			Content = ' \
					            <dt style="height:30px; line-height:30px; padding:1px 0 0 13px;"><span onclick="javascript:Close()" style="float:right; width:40px; height:28px; margin-right:-8px; cursor:pointer" title="关闭"></span><strong>'+name+'</strong> <span style="color:#666">('+title+')</span> \
					            <dd style="margin:11px 10px 0 0; padding-left:13px; float:left; width:68px; text-align:center; line-height:16px;"> \
					            	<a href="'+url+'" style="color:#039; background:none"><img src="'+icon+'" alt="'+name+'" width="68" height="95" alt="'+name+'" border="0" /></a> \
					            </dd> \
					            <dd style="margin-top:8px;">被咨询 <strong style="color:green">'+ask_count+'</strong> 次,回复 <strong style="color:#f60">'+ask_reply_count+'</strong> 次</dd> \
					            <dd style="height:21px; overflow:hidden;"><span style="color:#666;">医院:</span> <a href="'+hpt_url+'" style="color:#039; background:none" title="'+hpt_name+'">'+hpt_name+'</a></dd> \
				            	<dd style="height:21px; overflow:hidden;"><span style="color:#666;">科室:</span> <a href="'+dpt_url+'" style="color:#039; background:none" title="'+dpt_name+'">'+dpt_name+'</a></dd> \
				            	<dd style="height:40px; overflow:hidden; white-space:normal;" title="'+shanchang+'"><span style="color:#666;">擅长:</span>'+shanchang+'</dd> \
				            	<dd style="padding:8px 0 2px; text-align:right"><a href="'+url+'ask.php?ctrl=add" style="text-decoration:none; color:#069; background-color:#fff; padding:3px 10px 2px; border:1px solid; border-color:#74cbd6 #67bad6 #67bad6 #74cbd6;">诊室咨询</a> '+can_reg+'</dd>';
			BoxTips = '<dl id="showTabDetails" onmouseover="keepShow()" onmouseout="Close()" style="position:absolute;top:'+Top+'px;left:'+Left+'px;height:'+Height+'px;width:'+Width+'px;padding-right:8px; margin:0; color:#000; border:1px solid; border-color:#95b0c7 #637eaa #637eaa #95b0c7; background: url(http://www.yynet.cn/skins/default/images/info_card_BG_2.gif) no-repeat #fff; font-size:12px; line-height:20px; z-index:999999;">'+Content+'</dl>';
			$('#showTabDetailsLoading').remove();
			$('html>body').append(BoxTips);
		},
		error: function(xml){
			//alert('XML Load Failed!');
		}
	})
}
function Clear(){   
   if(h){
	clearTimeout(h);
	//alert('clear successful!');
	h=0;
   }
}

function keepShow(){
	$('#showTabDetails').show();
}
function Close(){
	$('#showTabDetails').hide();
}

//获取元素坐标
var ElementPos = {
	GetTop:function(e){
		var offset = e.offsetTop;
	    if (e.offsetParent != null)
	        offset += this.GetTop(e.offsetParent);
	    return offset;
	},
	GetLeft:function(e){
		var offset = e.offsetLeft;
	    if (e.offsetParent != null)
	        offset += this.GetLeft(e.offsetParent);
	    return offset;
	}
}

function DelHtmlTag(e){
	return e.replace(/<[^>]+>/g,"");
}
