﻿
var Notice={SetLabel:function(target,visible,text,iswarning)
{var label=this.GetLabel(target,iswarning);if(visible)
{label.style.display="";label.innerHTML=text;}
else
{label.style.display="none";}
return!(visible&&iswarning);},GetLabel:function(target,iswarning)
{var label;var ls=target.parentNode.getElementsByTagName("label");if(ls.length==0)
{label=document.createElement("label");label.className="invalid";label.style.display="none";target.parentNode.appendChild(label);}
else
{label=ls[0];}
label.className=iswarning?"invalid":"valid";return label;},CANCELABLE:1,OK:2,CANCEL:4,YES:8,NO:16,Buttons:null,MsgPanel:null,MsgBG:null,MsgBox:null,Callback:null,Alert:function(msg,boxstyle,callback)
{with(Notice)
{if(msg&&msg.constructor==Array)
{var z="";for(var i=0;i<msg.length;i++)
msg[i]="<li>"+msg[i]+"</li>";msg="<ul style='margin:0px;'>"+msg.join(" ")+"</ul>"}
if(!MsgPanel)
{Buttons=[];Buttons[1]=BuildButton("OK","OK");Buttons[2]=BuildButton("Cancel","CANCEL");Buttons[3]=BuildButton("Yes","YES");Buttons[4]=BuildButton("No","NO");MsgPanel=$C("div");MsgPanel.style.visibility="hidden";MsgBG=$C("div");with(MsgBG.style)
{position="absolute";left="0px";top="0px";backgroundColor="Gray";if(isIE)
filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=40)";else
opacity=0.4;}
MsgBox=$C("div",{innerHTML:"<div id='_msgbox' style='line-height: 20px; margin-left: auto; margin-right:auto;'></div><div id='_msgbuttons' style='text-align:center;'></div>"});with(MsgBox.style)
{border="white 3px solid";padding="5px";backgroundColor="#a30000";color="White";width="400px";position="absolute";}
MsgPanel.appendChild(MsgBG);MsgPanel.appendChild(MsgBox);document.body.appendChild(MsgPanel);}
Callback=callback;OpenMsgPanel(msg,boxstyle);}},BuildButton:function(text,cmd)
{var b=$C("input",{type:"button",value:text});with(b.style)
{fontSize="10px";backgroundColor="Black";border="White 1px solid";color="Yellow";fontFamily="Tahoma";margin="3px 5px";}
eval("b.onclick = function(e) { Notice.OnDialogCmd('"+cmd+"'); }");return b;},OpenMsgPanel:function(msg,boxstyle)
{with(Notice)
{with(MsgBG.style)
{width=document.body.scrollWidth+"px";height=document.body.scrollHeight+"px";}
var BoxContent=MsgBox.getElementsByTagName("div")
with(MsgBox)
{var btns=BoxContent[1];if((boxstyle&Notice.CANCELABLE)==Notice.CANCELABLE)
{if(boxstyle==1)
{Notice.MsgBox.onclick=Notice.OnAlternateCancel;Notice.MsgPanel.onclick=Notice.OnAlternateCancel;}
else
{Notice.MsgBox.onclick=null;Notice.MsgBG.onclick=Notice.OnAlternateCancel;}}
if(boxstyle<=1)
{btns.style.display="none";}
else
{btns.style.display="";btns.innerHTML="";var x=0,xx=Math.ceil(Math.log(boxstyle)/Math.log(2)),y=2;while(x<=xx)
{++x;if((boxstyle&y)==y)
btns.appendChild(Notice.Buttons[x]);y<<=1;}}
BoxContent[0].innerHTML=msg;}
MoveMsgBox();MsgPanel.style.visibility="visible";if(boxstyle)
BoxContent[1].getElementsByTagName("input")[0].focus();}
document.onkeydown=Notice.DisableTab;window.onscroll=Notice.MoveMsgBox;},MoveMsgBox:function(e)
{with(Notice.MsgBox)
{var by=(document.documentElement.clientHeight-clientHeight)/2;var bx=(document.documentElement.clientWidth-clientWidth)/2;if(isGecko)
{style.top=(by+window.scrollY)+"px";style.left=(bx+window.scrollX)+"px";}
else
{style.top=(by+document.documentElement.scrollTop)+"px";style.left=(bx+document.documentElement.scrollLeft)+"px";}}},DisableTab:function(e)
{if($E(e).keyCode==9)
$E_C($E(e));},CloseMsgPanel:function()
{if(Notice.MsgPanel)
Notice.MsgPanel.style.visibility="hidden";window.onscroll=null;document.onkeydown=null;},OnDialogCmd:function(cmd)
{Notice.CloseMsgPanel();if(Notice.Callback)
Notice.Callback();},OnAlternateCancel:function()
{Notice.OnDialogCmd("CANCEL");}}