
var HintBgColor="#FFFFE6";
var HintTextColor="black";
var HintTextSize="11px";
var HintBorderWidth="1";
var HintBorderColor="black";
var MaxHintWidth=250;
var withiFrame=false;
var hoff=0;
var voff=0;
function trim(s){
      return s != null ? s.replace(/(^\s*)|(\s*$)/,"") : s;
}
function WriteShowDisBeg(AId,ACapt,ACanDiv, W, abgimg, aclr)
{
var xw = 150;
var clr;
if (aclr)clr = "color:"+aclr+";";
else clr = "";
if (!isNaN(W)) xw = W;
if (ACanDiv)
document.write('<div align="left"><span id="PL'+AId+'_show">');
else
document.write('<span id="PL'+AId+'_show">');
if (abgimg != null)
document.write('<input style="cursor:pointer; border: none;'+clr+'width: '+String(xw)+'px;background-image: url('+abgimg+');" value="'+ACapt+'" name="SubmitEn" type="button"');
else
document.write('<input style="cursor:pointer; border: none;'+clr+'width: '+String(xw)+'px;" value="'+ACapt+'" name="SubmitEn" type="button"');
document.write(' onclick="document.all.PL'+AId+'.style.');
document.write("display='';document.all.PL"+AId+"_show.style.display='none';");
document.write('">');
};
function WriteShowEnd(ACanDiv)
{
if (ACanDiv)
document.write('</span></div>');
else
document.write('</span>');
};

function WriteShowEnBeg(AId,ACapt,ACanDiv, W, abgimg, aclr)
{
var xw = 150;
var clr;
if (aclr)clr = "color:"+aclr+";";
else clr = "";
if (!isNaN(W)) xw = W;
if (ACanDiv)
document.write('<div align="left"><span id="PL'+AId+'" style="display:none;">');
else
document.write('<span id="PL'+AId+'" style="display:none;">');
if (abgimg != null)
document.write('<input style="cursor:pointer;border: none;'+clr+'width: '+String(xw)+'px;background-image: url('+abgimg+');" value="'+ACapt+'" name="SubmitDis" type="button"');
else
document.write('<input style="cursor:pointer;border: none;'+clr+'width: '+String(xw)+'px;" value="'+ACapt+'" name="SubmitDis" type="button"');
document.write(' onclick="document.all.PL'+AId+'.style.display=');
document.write("'none';document.all.PL"+AId+"_show.style.display='';");
document.write('">');
};

function InitAllHints(useIframe, maxWidth, bgColor, txtColor, txtSize, borderWidth, borderColor) {
var node;
if (useIframe != null) withiFrame=useIframe;
if (maxWidth != null) MaxHintWidth=maxWidth;
if (bgColor != null) HintBgColor=bgColor;
if (txtColor != null) HintTextColor=txtColor;
if (txtSize != null) HintTextSize=txtSize+"px";
if (borderWidth != null) HintBorderWidth=borderWidth;
if (borderColor != null) HintBorderColor=borderColor;
for (var j = 0; (node = document.getElementsByTagName("*")[j]); j++) {
if (node.getAttribute("hint") != null ) addHint(node);
if (node.getAttribute("hintex") != null ) addHintEx(node);
}
}

function addHint(obj) {
if (obj==null) return;
if (obj.addEventListener) {obj.addEventListener("mouseover", showHint, false);
obj.addEventListener("mouseout", hideHint, false);  
obj.addEventListener("mousemove", dragHint, false);  }
else if (obj.attachEvent){obj.attachEvent("onmouseover", showHint);
obj.attachEvent("onmouseout", hideHint);   
obj.attachEvent("onmousemove", dragHint);   }
}

function addHintEx(obj) {
if (obj==null) return;
if (obj.addEventListener) {obj.addEventListener("mouseover", showHint, false);}
else if (obj.attachEvent){obj.attachEvent("onmouseover", showHint);}
}

function HintBody() {
var str="";
var b="border:"+HintBorderColor+" solid "+HintBorderWidth+"px;";
str+='<table cellspacing=0 cellpadding=4 style="width:100%" ><tr><td style="'+b+'cursor:default;background:'+HintBgColor+';" id="hintHolder" align=center>';
if (withiFrame) str+='<iframe style="margin:0px;width:100%" name="hintFrame" id="hintFrame" frameborder=0 scrolling=no ></iframe>';
str+='</td></tr></table>';
return str;
}

function hintStyle() {
return "<style type='text/css'>\n .hint {background:"+HintBgColor+";color:"+HintTextColor+";font-size:"+HintTextSize+";text-align:justify;}</style>\n";
}

function hintHeader() {
return "<html><head>\n"+hintStyle()+"\n</head>\n<body style='margin:5px;cursor:default;' >\n";
}

function resizeHint(obj, frobj, flag) { //flag:  0- use iframe 1- dont use iframe as holder for hint
if (obj==null) obj=document.getElementById("HintLayer");
if(!obj) return;
if (frobj==null) frobj=(flag)?document.getElementById("hintHolder"):document.getElementById("hintFrame");
if(!frobj) return;

if (flag) var fr=document.getElementById("mt"); 
else {
var fr= (frobj.contentDocument) ? frobj.contentDocument : (window.frames) ? window.frames["hintFrame"].document:document.frames["hintFrame"].document; 
fr=fr.getElementById("mt");
}
if(!fr) return;

var  ContentWidth = (document.clientWidth) ? fr.clientWidth : fr.offsetWidth ;
var  ContentHeight = (document.clientHeight) ? fr.clientHeight : fr.offsetHeight;
// alert("w="+ContentWidth+"     h="+ContentHeight);

// Изменение ширины подсказки     
var curWidth= parseInt(obj.style.width,10); 
if ( isNaN(curWidth) == true) {curWidth=0;}
if (ContentWidth< curWidth || curWidth==0) { obj.style.width=ContentWidth+10+"px";
frobj.style.width=ContentWidth+"px"; }

// Изменение высоты подсказки     
obj.style.height=ContentHeight+"px";
frobj.style.height=ContentHeight+"px";

var ff = parseInt(obj.style.left)+parseInt(ContentWidth)-parseInt(document.body.scrollLeft);

if (ff+25 > parseInt(window.screen.width)) 
hoff = ff-parseInt(window.screen.width)+50;
else
hoff = 0;

ff = parseInt(obj.style.top)+parseInt(ContentHeight)-parseInt(document.body.scrollTop);
if (ff+150 > parseInt(window.screen.height)) 
voff = ff-parseInt(window.screen.height)+150;
else
voff = 0;
}

function createHint(obj,x,y) {
if (obj==null) return false;
var DivTag=document.createElement("DIV");
DivTag.setAttribute("id","HintLayer");
DivTag.style.position="absolute";
DivTag.style.display="none";
DivTag.style.zIndex="1000";
DivTag.style.left=(!x)?0:x;
DivTag.style.top=(!y)?0:y;
DivTag.style.width=MaxHintWidth;
self.document.body.appendChild(DivTag);
DivTag.innerHTML=HintBody();
return DivTag;   
}

function showHint(e) {
var e = window.event ? window.event : e;
var src = window.event ? e.srcElement : e.target;
if(!src) return;
hideHint(e);
var hintTxt=src.getAttribute("hint");
if (hintTxt==null || trim(hintTxt)=="") 
{
hintTxt=src.getAttribute("hintex");
if (hintTxt==null || trim(hintTxt)=="") return;
}
hintTxt="<table cellspacing=0 id='mt'><tr><td "+((withiFrame)?"class='hint'":"style='font-size:"+HintTextSize+";padding:5px;text-align:justify;color:"+HintTextColor+"'")+">"+hintTxt+"</td></tr></table>";
var x=((e.pageX) ? e.pageX : e.x+document.body.scrollLeft)+15;
var y=((e.pageY) ? e.pageY : e.y+document.body.scrollTop)+10;
stopEvent(e);
var hintDiv=document.getElementById("HintLayer");
if (hintDiv== null)
{ hintDiv=createHint(src,x,y);
if (!hintDiv) return; }

// alert(hintDiv+" x="+hintDiv.style.left+"   y="+hintDiv.style.top+"\n\nwidth="+hintDiv.clientWidth+"  h:"+hintDiv.clientHeight+"\n\n"+hintDiv.innerHTML);

if (withiFrame) {
var hint=hintHeader()+hintTxt+"</body></html>";
hintDiv.style.display="";
var hintObj=document.getElementById('hintFrame');
if (hintObj!=null)  {
var ifrDoc=  (hintObj.contentDocument) ? hintObj.contentDocument : (window.frames) ? window.frames["hintFrame"].document:document.frames["hintFrame"].document; 
if (ifrDoc !=null) {
with(ifrDoc) {
open();
write(hint);
close();
}   
resizeHint(hintDiv,hintObj,0)
}
else hintDiv.style.display="none";
}
}
else {
var hintObj=document.getElementById("hintHolder");
hintObj.innerHTML=hintTxt;
hintDiv.style.display="";
resizeHint(hintDiv,hintObj,1); 
}
}

function dragHint(e) {
var e = window.event ? window.event : e;
var obj=document.getElementById("HintLayer");
if (obj) {
obj.style.left=((e.pageX) ? e.pageX : e.x+document.body.scrollLeft)+15-hoff;
obj.style.top=((e.pageY) ? e.pageY : e.y+document.body.scrollTop)+10-voff;
}
stopEvent(e);
}

function hideHint(e) {
var e = window.event ? window.event : e;
stopEvent(e);
var obj=document.getElementById("HintLayer");
if (obj) {
obj.style.display="none";
self.document.body.removeChild(obj);
}
}


function stopEvent(e) {
if (e) 
{e.cancelBubble=true;
if (e.stopPropagation) e.stopPropagation();}
}
