﻿//
// 使用方法：
// 1、页面引用此脚本文件： <SCRIPT language=JavaScript src="Tip.js" type=text/JavaScript></SCRIPT>
// 2、Aspx文件内用此功能的块必须 runat=server
// 3、在后置代码文件内用 Attributes.Add 方法 添加属性
//   A、Tip  主要内容文件，可以包括Html内容
//   B、其他各属性值 注释见下面
// 4、切记如果产生的效果混乱，检查是否有Css等文件里是否有position非absolute的设置！！

// 以下定义样式的初始值 Start
var Tip_BorderColor="#ADACAC";     //整体边框的颜色
var Tip_TitleBgColor="#E5E4E2";    //标题部分背景色
var Tip_TitleFontSize="12";   //标题部分字体大小
var Tip_TitleFontColor="#545252";  //标题部分字体颜色
var Tip_MsgBgColor="#FFFFFF";      //内容部分背景色
var Tip_MsgFontSize="12";     //内容部分字体大小
var Tip_MsgFontColor="#636363";    //内容部分字体颜色
// End

var pltsPop=null;
var pltsoffsetX = 10;
var pltsoffsetY = 15;
var pltsTitle="";

document.write('<div id=pltsTipLayer style="display: none;position: absolute; z-index:10001;border:0px;"></div>');

function pltsinits()
{
    document.onmouseover   = plts;
    document.onmousemove = moveToMouseLoc;
}

function plts()
{  
    var o=event.srcElement;
    if(o.alt!=null && o.alt!=""){o.Tip=o.alt;o.alt=""};
    if(o.title!=null && o.title!=""){o.Tip=o.title;o.title=""};
    pltsPop=o.Tip;
    
    //取得样式 Start
    if(o.Tip_BorderColor!=null && o.Tip_BorderColor!=""){Tip_BorderColor=o.Tip_BorderColor;};
    if(o.Tip_TitleBgColor!=null && o.Tip_TitleBgColor!=""){Tip_TitleBgColor=o.Tip_TitleBgColor;};
    if(o.Tip_TitleFontSize!=null && o.Tip_TitleFontSize!=""){Tip_TitleFontSize=o.Tip_TitleFontSize;};
    if(o.Tip_TitleFontColor!=null && o.Tip_TitleFontColor!=""){Tip_TitleFontColor=o.Tip_TitleFontColor;};
    if(o.Tip_MsgBgColor!=null && o.Tip_MsgBgColor!=""){Tip_MsgBgColor=o.Tip_MsgBgColor;};
    if(o.Tip_MsgFontSize!=null && o.Tip_MsgFontSize!=""){Tip_MsgFontSize=o.Tip_MsgFontSize;};
    if(o.Tip_MsgFontColor!=null && o.Tip_MsgFontColor!=""){Tip_MsgFontColor=o.Tip_MsgFontColor;};
    //End
    
    if(pltsPop!=null&&pltsPop!=""&&typeof(pltsPop)!="undefined")
    {
	    pltsTipLayer.style.left=-1000;
	    pltsTipLayer.style.display='';
	    var Msg=pltsPop.replace(/\n/g,"<br>");
	    Msg=Msg.replace(/\0x13/g,"<br>");
	    var re=/\{(.[^\{]*)\}/ig;
	    if(!re.test(Msg)) pltsTitle="<b>[WWW.MZDOL.COM] 梦之岛在线</b>";
	else
	{
	  re=/\{(.[^\{]*)\}(.*)/ig;
  	  pltsTitle=Msg.replace(re,"$1")+"&nbsp;";
	  re=/\{(.[^\{]*)\}/ig;
	  Msg=Msg.replace(re,"");
	  Msg=Msg.replace("<br>","");}
      var content =
      	'<table style="FILTER:alpha(opacity=95); font size:12px;" id=toolTipTalbe border=1 BorderColor='+Tip_BorderColor+'>'+
      	'<tr id=pltsPoptop BgColor='+Tip_TitleBgColor+' style="font size:'+Tip_TitleFontSize+'px;color:'+Tip_TitleFontColor+';"><th height=12 valign=bottom><p id=topleft align=left>↖'+pltsTitle+'</p><p id=topright align=right style="display:none">'+pltsTitle+'↗</font></th></tr>'+
      	'<tr><td style="padding-left:10px;padding-right:10px;padding-top: 4px;padding-bottom:4px;line-height:135%;font size:'+Tip_MsgFontSize+';color:'+Tip_MsgFontColor+'" bgcolor='+Tip_MsgBgColor+'>'+Msg+'</td></tr>'+
      	'<tr id=pltsPopbot style="display:none;font size:'+Tip_TitleFontSize+'px;color:'+Tip_TitleFontColor+';" BgColor='+Tip_TitleBgColor+'><th height=12 valign=bottom><p id=botleft align=left>↙'+pltsTitle+'</p><p id=botright align=right style="display:none">'+pltsTitle+'↘</font></th></tr>'+
      	'</table>';
       	pltsTipLayer.innerHTML=content;
       	toolTipTalbe.style.width=Math.min(pltsTipLayer.clientWidth,document.body.clientWidth/2.2);
       	moveToMouseLoc();
       	return true;
    }
    else
    {
    	pltsTipLayer.innerHTML='';
      	pltsTipLayer.style.display='none';
       	return true;
    }
}

function moveToMouseLoc()
{
	if(pltsTipLayer.innerHTML=='')return true;
	var MouseX=event.x;
	var MouseY=event.y;
	var popHeight=pltsTipLayer.clientHeight;
	var popWidth=pltsTipLayer.clientWidth;
	if(MouseY+pltsoffsetY+popHeight>document.body.clientHeight)
	{
	  	popTopAdjust=-popHeight-pltsoffsetY*1.5;
	  	pltsPoptop.style.display="none";
	  	pltsPopbot.style.display="";
	}
	 else
	{
	   	popTopAdjust=0;
	  	pltsPoptop.style.display="";
	  	pltsPopbot.style.display="none";
	}
	if(MouseX+pltsoffsetX+popWidth>document.body.clientWidth)
	{
		popLeftAdjust=-popWidth-pltsoffsetX*2;
		topleft.style.display="none";
		botleft.style.display="none";
		topright.style.display="";
		botright.style.display="";
	}
	else
	{
		popLeftAdjust=0;
		topleft.style.display="";
		botleft.style.display="";
		topright.style.display="none";
		botright.style.display="none";
	}
	pltsTipLayer.style.left=MouseX+pltsoffsetX+document.body.scrollLeft+popLeftAdjust;
	pltsTipLayer.style.top=MouseY+pltsoffsetY+document.body.scrollTop+popTopAdjust;
  	return true;
}

pltsinits();