//定义变量
var YHC_AlphaDown = 0;
var YHC_AlphaUp = 0;
var TmpDivAlphaUp,TmpDivAlphaDown;
var TheFun = function (){};
var YHC_DivFrameName = "LKF_DivFrame"; //遮罩下拉列表层
var YHC_DivBackGroundName = "LKF_DivBG"; //背景层
var YHC_DivBackGroundColor = "#000"; //背景层颜色
var YHC_DivBackGroundAlpha = "0.47"; //背景层透明度
var YHC_DivShowName = "LKF_DivShow"; //显示层
var YHC_DefaultWidth = 350; //显示层默认宽度
var YHC_DefaultHeight = 160; //显示层默认高度
var YHC_DivShowSpeed = 1.5; //层显示速度
var YHC_DivHideSpeed = 1.1; //层隐藏速度



//显示层内容
var YHC_ShowBodyHead = "<div id=" + YHC_DivShowName + " class=YHC_DivShow>";
YHC_ShowBodyHead = YHC_ShowBodyHead + "<div class=YHC_DivShowTitle ><input type=button hidefocus=true title='按空格键或Enter键可以关闭此消息框 :)' class=YHC_DivShowCloseButton id=YHC_CloseButton onclick='CloseMSG();' onmouseover=\"this.className='YHC_DivShowCloseButton2'\" onmouseout=\"this.className='YHC_DivShowCloseButton'\" onmousedown=\"this.className='YHC_DivShowCloseButtonDown'\"  /></div>";
YHC_ShowBodyHead = YHC_ShowBodyHead + "<table height='100%' width='100%' cellpadding=0 cellspacing=0><tr><td class=YHC_DivShowBody>";
var YHC_ShowBodyLast = "</td></tr></table></div>";

//创建层对象
function CreateDiv()
{
  var nowBodyWidth = document.body.scrollLeft + document.body.clientWidth;
  var nowBodyHeight = document.body.scrollTop + document.body.clientHeight;

  //创建遮罩层对象
  var FrameObj = document.createElement("iframe");
  FrameObj.id = YHC_DivFrameName;
  FrameObj.style.position = "absolute";
  FrameObj.frameBorder = "0";
  FrameObj.style.top = "0";
  FrameObj.style.left = "0";
  FrameObj.style.filter = "Alpha(Opacity = 0)";
  FrameObj.style.width = nowBodyWidth;
  FrameObj.style.height = nowBodyHeight;
  FrameObj.style.zIndex = "1000";
  document.body.appendChild(FrameObj);

  //创建背景层对象
  var DivBGObj = document.createElement("div");
  DivBGObj.id = YHC_DivBackGroundName;
  DivBGObj.style.position = "absolute";
  DivBGObj.style.top = "0";
  DivBGObj.style.left = "0";
  DivBGObj.style.backgroundColor = YHC_DivBackGroundColor;
  DivBGObj.style.MozOpacity = YHC_DivBackGroundAlpha;
  DivBGObj.style.width = nowBodyWidth;
  DivBGObj.style.height = nowBodyHeight;
  DivBGObj.style.zIndex = "1001";
  document.body.appendChild(DivBGObj);

  //创建显示层对象
  var DivObj = document.createElement("div");
  DivObj.id = YHC_DivShowName;
  DivObj.style.position = "absolute";
  DivObj.style.height = YHC_DefaultHeight;
  DivObj.style.width = YHC_DefaultWidth;
  DivObj.style.top = (nowBodyHeight - YHC_DefaultHeight)/2;
  DivObj.style.left = (nowBodyWidth - YHC_DefaultWidth)/2;
  DivObj.style.zIndex = "1002";
  document.body.appendChild(DivObj);
  document.getElementById(YHC_DivShowName).innerHTML =  YHC_ShowBodyHead + YHC_ShowBodyLast;

  document.getElementById(YHC_DivFrameName).style.display = "none";
  document.getElementById(YHC_DivBackGroundName).style.display = "none";
  document.getElementById(YHC_DivShowName).style.display = "none";
}

//添加WindowReSize到onload事件
if(document.all)
{
  //IE
  window.attachEvent('onload',JSinit);
  window.attachEvent('onresize',WindowReSize);
} 
else
{
  //火狐
  window.addEventListener('load',JSinit,true);
  window.addEventListener('resize',WindowReSize,false);
}

//初始化
function JSinit()
{
  //加载样式文件
  if(document.createStyleSheet)
  {
    document.createStyleSheet("/css/main.css");
  }
  else
  {
    var cssObj = document.createElement("link");
    cssObj.href = "/css/main.css";
    cssObj.type = "text/css";
    cssObj.rel = "stylesheet";
    document.getElementsByTagName('head')[0].appendChild(cssObj);
  }

  document.body.style.overflow = "auto";
  CreateDiv();

  //var PLTS_js = document.createElement('script');
  //PLTS_js.src = "/js/PLTS.JS";
  //document.body.appendChild(PLTS_js);
}

//
function StyleForName(StyleName)
{

  for(var i=0;i<document.styleSheets.length;i++)
  { 
    var rules;
    if(document.styleSheets[i].cssRules)
    {
      rules = document.styleSheets[i].cssRules;
    }
    else
    { 
    rules = document.styleSheets[i].rules;
    }
  }
  
  for(var j=0;j<rules.length;j++)
  {
    if(rules[j].selectorText == StyleName)
    {
      return rules[j].style;
    }
  } 
}

//窗口改变调整
function WindowReSize()
{
  NewSize();
}

//位置重新设置
function NewSize()
{
  var nowBodyWidth = document.body.scrollLeft + document.body.clientWidth;
  var nowBodyHeight = document.body.scrollTop + document.body.clientHeight;
  document.getElementById(YHC_DivShowName).style.top = document.body.scrollTop + document.body.clientHeight/2 - YHC_DefaultHeight/2;
  document.getElementById(YHC_DivShowName).style.left = document.body.scrollLeft + document.body.clientWidth/2 - YHC_DefaultWidth/2;
  document.getElementById(YHC_DivBackGroundName).style.width = nowBodyWidth;
  document.getElementById(YHC_DivBackGroundName).style.height = nowBodyHeight;
  document.getElementById(YHC_DivFrameName).style.width = nowBodyWidth;
  document.getElementById(YHC_DivFrameName).style.height = nowBodyHeight;
}

//显示层
function ShowMSG(TheMSG)
{
  document.body.style.overflow = "hidden";
  document.getElementById(YHC_DivShowName).style.filter = "alpha(opacity=0)";
  document.getElementById(YHC_DivBackGroundName).style.filter = "alpha(opacity=0)";
  NewSize();
  document.getElementById(YHC_DivShowName).innerHTML =  YHC_ShowBodyHead + TheMSG + YHC_ShowBodyLast;
  document.getElementById(YHC_DivShowName).style.display = "block";
  document.getElementById(YHC_DivBackGroundName).style.display = "block";
  document.getElementById(YHC_DivFrameName).style.display = "block";
  document.getElementById("YHC_CloseButton").focus();
  YHC_AlphaUp = 0;
  TmpDivAlphaUp = window.clearInterval(TmpDivAlphaUp);
  TmpDivAlphaDown = window.clearInterval(TmpDivAlphaDown);
  TmpDivAlphaUp = setInterval("DivAlphaUp()");
}

//显示层(Big)
function ShowDivBig(TheMSG,TheButton)
{
  document.body.style.overflow = "hidden";
  document.getElementById(YHC_DivShowName).style.width = "350px";
  document.getElementById(YHC_DivShowName).style.height = "200px";
  var DivBody;
  DivBody = "";
  DivBody = DivBody + "<table cellpadding=0 cellspacing=0 width='350' height='200' bgcolor='#ffffff'>\n";
  DivBody = DivBody + "  <tr>\n";
  DivBody = DivBody + "    <td align=right background='/images/MSGTitleBG01.gif' height=30>\n";
  DivBody = DivBody + "      <input type=button hidefocus=true title='按空格键或Enter键可以关闭此消息框 :)'\n";
  DivBody = DivBody + "        style='background-color:#ECF5FF;width:13px;height:13px;margin-right:13px;\n";
  DivBody = DivBody + "        background-image:url(\"/images/MSGCloseButtonFace.gif\");border:0;'\n";
  DivBody = DivBody + "        id=closebutton onclick='CloseMSG();'\n";
  DivBody = DivBody + "        onmouseover='this.style.backgroundImage=\"url(/images/MSGCloseButtonBack.gif)\"'\n";
  DivBody = DivBody + "        onmouseout='this.style.backgroundImage=\"url(/images/MSGCloseButtonFace.gif)\"'\n";
  DivBody = DivBody + "      />\n";
  DivBody = DivBody + "    </td>\n";
  DivBody = DivBody + "  </tr>\n";
  DivBody = DivBody + "  <tr>\n";
  DivBody = DivBody + "    <td align=center style='line-height:250%;font-size:12px;'>\n";
  DivBody = DivBody + "      " + TheMSG
  DivBody = DivBody + "    </td>\n";
  DivBody = DivBody + "  </tr>\n";
  if(TheButton != "")
  {
    DivBody = DivBody + "  <tr>\n";
    DivBody = DivBody + "   <td align=center height=50 style='padding-bottom:10px;'>\n";
    for(var i=0;i<TheButton.length;i++)
    {
      DivBody = DivBody + "      <a href='" + TheButton[i][1] + "' class=button001>" + TheButton[i][0] + "</a>\n";
    }
    DivBody = DivBody + "    </td>\n";
    DivBody = DivBody + "  </tr>\n";
  }
  DivBody = DivBody + "</table>";
  document.getElementById(YHC_DivShowName).innerHTML =  DivBody;
  document.getElementById(YHC_DivShowName).style.filter = "alpha(opacity=0)";
  document.getElementById(YHC_DivShowName).style.MozOpacity = 0;
  document.getElementById(YHC_DivBackGroundName).style.filter = "alpha(opacity=0)";
  document.getElementById(YHC_DivBackGroundName).style.MozOpacity = 0;
  document.getElementById(YHC_DivShowName).style.display = "block";
  NewSize();
  document.getElementById(YHC_DivBackGroundName).style.display = "block";
  document.getElementById(YHC_DivFrameName).style.display = "block";
  document.getElementById("closebutton").focus();
  YHC_AlphaUp = 0;
  TmpDivAlphaUp = window.clearInterval(TmpDivAlphaUp);
  TmpDivAlphaDown = window.clearInterval(TmpDivAlphaDown);
  TmpDivAlphaUp = setInterval("DivAlphaUp()");
}

//显示加载
function ShowLoading()
{
  ShowMSG("Loading...");
  document.getElementById(YHC_DivShowName).innerHTML = "<table style='width:" + YHC_DefaultWidth + "px;height:" + YHC_DefaultHeight + "px;'><tr><td align=center><img src='/images/Doing.gif' /></td></tr></table>";
  document.getElementById(YHC_DivShowName).style.backgroundColor = "";
}

//隐藏层
function CloseMSG()
{
  if(TheFun != null){TheFun();}
  YHC_AlphaDown = YHC_DivBackGroundAlpha*100;
  TmpDivAlphaDown = setInterval("DivAlphaDown()");
  TheFun = function (){};
}

//层渐显
function DivAlphaUp()
{
  TmpDivAlphaDown = window.clearInterval(TmpDivAlphaDown);
  if(YHC_AlphaUp > (99 - YHC_DivBackGroundAlpha * 100))
  {
    document.getElementById(YHC_DivBackGroundName).style.filter = "alpha(opacity=" + (YHC_AlphaUp-(99 - YHC_DivBackGroundAlpha * 100)) + ")";
    document.getElementById(YHC_DivBackGroundName).style.MozOpacity = (YHC_AlphaUp-(99 - YHC_DivBackGroundAlpha * 100))/100;
  }
  document.getElementById(YHC_DivShowName).style.filter = "alpha(opacity=" + YHC_AlphaUp + ")";
  document.getElementById(YHC_DivShowName).style.MozOpacity = YHC_AlphaUp/100;
  YHC_AlphaUp = YHC_AlphaUp + Math.ceil((100 - YHC_AlphaUp)/YHC_DivShowSpeed);
  if(YHC_AlphaUp >= 100)
  {
    document.getElementById(YHC_DivBackGroundName).style.filter = "alpha(opacity=" + YHC_DivBackGroundAlpha*100 + ")";
    document.getElementById(YHC_DivBackGroundName).style.MozOpacity = YHC_DivBackGroundAlpha;
    document.getElementById(YHC_DivShowName).style.filter = "alpha(opacity=100)";
    document.getElementById(YHC_DivShowName).style.MozOpacity = "1";
    TmpDivAlphaUp = window.clearInterval(TmpDivAlphaUp);
  }
  else
  {
    TmpDivAlphaUp = setInterval("DivAlphaUp()");
  }
}
//层渐隐
function DivAlphaDown()
{
  TmpDivAlphaUp = window.clearInterval(TmpDivAlphaUp);
  document.getElementById(YHC_DivBackGroundName).style.filter = "alpha(opacity=" + YHC_AlphaDown + ")";
  document.getElementById(YHC_DivBackGroundName).style.MozOpacity = YHC_AlphaDown/100;
  document.getElementById(YHC_DivShowName).style.filter = "alpha(opacity=" + YHC_AlphaDown + ")";
  document.getElementById(YHC_DivShowName).style.MozOpacity = YHC_AlphaDown/100;
  YHC_AlphaDown = YHC_AlphaDown - Math.ceil(YHC_AlphaDown/YHC_DivHideSpeed);
  if(YHC_AlphaDown <= 0)
  {
    document.body.style.overflow = "auto";
    TmpDivAlphaDown = window.clearInterval(TmpDivAlphaDown);
    document.getElementById(YHC_DivShowName).style.display = "none";
    document.getElementById(YHC_DivBackGroundName).style.display = "none";
    document.getElementById(YHC_DivFrameName).style.display = "none";
  }
  else
  {
    TmpDivAlphaDown = setInterval("DivAlphaDown()");
  }
}
