
//
// da.js (c) Dmitry Apukhtin, ada@dacoder.com
//
//<script>
var omoColor="#efefe0";
//
// popups
//
function popHint(s,time,anchor,x,y){
    if(s==null)
        s="todo:Under construction...", time=750;
    var i=s.indexOf(":"),icon;
    if(i>0){
		icon=s.substr(0,i);
		if(icon.indexOf(".")==-1)
			icon+=".ico";
		s=s.substr(i+1);
	}
    return _popUp("margin:3 4;font:8pt verdana;border:1 outset;background:infobackground;cursor:default",
           "<span>"+(icon?"<img src='i/"+icon+"' align=absmiddle style='width:16;height:16;margin-right:4'>"+s:s)+"</span>",
           time,anchor,x,y);
}
function popMenu(s,anchor){
	if(event){
		event.returnValue=false;
		event.cancelBubble=true;
	}
    if(!s)return popHint("stop:popMenu(\"func_prefix[_]:menu_item|[...]\", anchor)");
    var noui=s.substr(0,1)=="#",func=noui?s.substr(1):s,i=func.indexOf(":"),menu;
    if(i==-1)return popHint("stop:popMenu: no func?");
    menu=func.substr(i+1); func=func.substr(0,i);
    s="<table cellpadding cellspacing style='font:8pt tahoma;text-transform:capitalize'>";
    var a=menu.split("|"),sepbg="gray",sa;
    for(i in a)
        if(a[i]=="-")
            s+="<tr style='background:"+sepbg+"'><td></td></tr>"
        else{
            sa=(noui?a[i]:a[i].split("#")[0]).replace(/'/g,"&amp;");
            s+="<tr><td nowrap style='padding:3 12'"+
               " onmouseover='with(this.runtimeStyle){background=\"highlight\";color=\"white\";}'"+
               " onmouseout ='with(this.runtimeStyle){background=\"\";color=\"\";}'"+
               " onmouseup='parent."+func+(/_$/.test(func)?sa+"()":"_ACTION(\""+sa+"\")")+"'>"+(noui?a[i]:UI(a[i])).toLowerCase()+
               "</td></tr>";
        }
    s+="</table>";
    return _popUp("margin:0;font:8pt tahoma;border:2 outset;background:buttonface;cursor:default",s,
                  0,anchor,-2,-2);
}
var oPop,oPop_tm,ctx;
function _popUp(css,html,time,anchor,x,y){
    if(!oPop){
        oPop=window.createPopup();
        oPop_tm=0;
    }
    oPop.hide();
    var w,h;
    with(oPop.document.body){
        scroll="no";
        style.cssText=css;
        innerHTML=html;
        firstChild.onclick=oPop.hide;
        onselectstart=oncontextmenu=ondrag=shutup;
        clearTimeout(oPop_tm);
        if(time)oPop_tm=setTimeout(oPop.hide,time);
        oPop.show(0,0,1024,0);
        w=parseInt(style.marginLeft)+firstChild.offsetWidth+parseInt(style.marginRight)+parseInt(style.borderWidth)*2;
        h=parseInt(style.marginTop)+firstChild.offsetHeight+parseInt(style.marginBottom)+parseInt(style.borderWidth)*2;
    }
    if(!anchor){
        var e=event?event:document.createEventObject();
        x=e.screenX+(x==null?16:x);
        y=e.screenY+(y==null?16:y);
    }
    oPop.show(x,y,w,h,anchor);
    return oPop;
}
function cursorHint(s){
	document.body.insertAdjacentHTML("beforeEnd","<span class='cursorHint'></span>")
	var span=document.body.lastChild,ls;
	this.show=function(s,x,y){
		if(!s)return span.runtimeStyle.display="none";
		if(s!=ls)ls=span.innerHTML=s;
		span.runtimeStyle.posLeft=x?x:event.x+12;
		span.runtimeStyle.posTop=y?y:event.y+10;
		span.runtimeStyle.display="inline";
	}
	this.removeNode=function(){
		span.removeNode(true);
	}
	this.show(s)
}
//
// UI
//
function UI(s){
    return s.replace(/_/g," ");
}
//
// misc
//
function getCookie(key,def){
    try{
        return RegExp("(^|;| )"+key+"=([^=;]+)","i").exec(document.cookie)?unescape(RegExp.$2):def;
    }catch(e){
        alert("No cookies?\n"+e.description);
    }
}
function setCookie(key,val,noexp){
    document.cookie=key+"="+(val?escape(val):"")+(noexp?"":";Expires='Wed, 1 Jan 2020 00:00:00 GMT'");
}
function newXML(url){
	var x=new ActiveXObject("MSXML2.DOMDocument");
	x.async=false; x.resolveExternals=false; x.validateOnParse=false;
	x.setProperty("SelectionLanguage","XPath");
	if(url){
		var b=url.charAt(0)=="<"?x.loadXML(url):x.load(url);
		if(!b)
			if(confirm("?newXML: "+x.parseError.reason+"\n"+url+"\n\nclick Ok to open it"))
				window.open(url);
	}
	return x;
}
function dragE(o){
    var dx=event.x-o.offsetLeft,dy=event.y-o.offsetTop;
    o.setCapture();
    o.onmousemove=function(){
        o.style.posLeft=event.x-dx;
        o.style.posTop=event.y-dy;
    }
    o.onmouseup=function(){
        o.releaseCapture();
        o.onmousemove=o.onmouseup=null;
    }
    event.cancelBubble=true;
}
function _f(s){
	var a=arguments;
	return s.replace(/@(\d)/g,function($1,$2){return a[$2]});
}
function shutup(){
    if(event)event.cancelBubble=true;
    return false;
}
function eTag(name){
    var e=event.srcElement;
    while(e && e.tagName!=name)e=e.parentElement;
    return e;
}
function omo(e){
	if(!e||!event)return;
	e.runtimeStyle.backgroundColor=event.type=="mouseover"?omoColor:"";
}
function rnd(max){
    return Math.round(Math.random()*max);
}
function _info(s){
	if(window.da_info){
		if(!da_info.tm && da_info.scrollHeight>da_info.clientHeight)
			da_info.tm=setTimeout("da_info.tm=null;da_info.scrollTop="+da_info.scrollHeight,100);
	}else
		document.body.insertAdjacentHTML("beforeEnd","<xmp id=da_info ondblclick=removeNode(true) onselectstart='event.cancelBubble=true' oncontextmenu='event.cancelBubble=true'></xmp>");
	da_info.insertAdjacentText("beforeEnd",s);
	da_info.insertAdjacentText("beforeEnd","\n");
}
function _exec(fs){
	if(fs)
		try{
			if(typeof(fs)=="string")
				eval(fs);
			else
				fs();
		}catch(err){
			alert("?_exec("+fs+"): "+err.description);
		}
}
//
// "da_*" classes
//
for(var a=document.body.all,i=0,e; e=a[i]; i++)
    if(e.className){
		var as=e.className.split(" "),ii=0,s;
		while(s=as[ii++])
			if(s.substr(0,3)=='da_')
				try{
				    window[s](e);
				}catch(e){
				    alert("?da_*: "+s+": "+e.id)
				}
	}
function da_bar(o){
    var a=o.all.tags("Q"),i=0,e;
    while(e=a[i++]){
        if(e.nextSibling.nodeValue==" ")
            e.nextSibling.removeNode();
        e.onmouseover=function(){
            this.over=true;
        }
        e.onmouseout=function(){
            this.over=this.down=false;
        }
        e.onmousedown=function(){
            this.down=true;
        }
        e.onmouseup=function(){
            this.down=false;
        }
        e.setExpression("className","(this.over?'over':'')+(this.down||this.on?' down':'')");
    }
    o.ondrag=o.onselectstart=o.oncontextmenu=o.onmousedown=shutup;
    var e=o.all.tags("LABEL")[0];
    if(e)e.onmousedown=function(){
        dragE(o);
    };
}

function da_cols(o){
    o.newCol=function(oc){
        var s="<table id=col height=100% border=1 cellspacing=0 cellpadding=0 style='display:inline'>"+
              "<tr height=1%><th nowrap><img id=arr src=i/qrg.gif hspace=0 vspace=1 align=right><span id=caption style='padding-right:20'>"+oc.caption+"</span></th></tr>"+
              "<tr><td><div nowrap id=content>"+oc.content+"</div></td></tr>"+
              "</table>";
        o.insertAdjacentHTML("beforeEnd",s);
        var col=o.lastChild;
        col.next=oc.next;
        col.index=o.childNodes.length;
        col.setExpression("width","nextSibling?'':offsetParent.clientWidth-offsetLeft");
        try{
			col.all.content.firstChild.style.borderBottom="1 dotted gray";
		}catch(err){
		}
        return(col);
    }
    o.load=function(col,oc){
        if(col){
            col.all.caption.innerHTML=oc.caption;
            var ai=col.all.tags("INPUT"),a=new Array(),i=-1,nof=true;
            while(ai[++i])
				a.push(ai[i].value);
            col.all.content.innerHTML=oc.content;
            if(a.length){
				ai=col.all.tags("INPUT"),i=-1;
				while(ai[++i]){
					if(ai[i].value=a[i])
						nof=false;
				}
				if(!nof)o.applyFilters(col);
			}
        }else
            col=o.newCol(oc);
        while(col.nextSibling)
            col.nextSibling.removeNode(true);
        col.next=oc.next;
        setTimeout(col.scrollIntoView);
        var i=col.all.tags("INPUT")(0);
        if(i)
            setTimeout(i.select);
        else
            setTimeout(col.all.content.focus);
    }
    o.onclick=function(){
        var tr=_tr(); if(!tr||tr.parentElement.tagName!="TBODY") return;
        var col=_col(tr); if(!col)return;
        if(col.selTR)col.selTR.bgColor="";
        (col.selTR=tr).bgColor="silver";
        tr.fireEvent("onmouseout");
        col.next(col,tr);
    }
    o.onmouseover=o.onmouseout=function(){
        omo(_tr());
    }
    o.onkeyup=function(){
        var e=event.srcElement; if(e.tagName!="INPUT")return;
        var col=_col(e); if(!col)return;
        if(e.s==null || e.s!=e.value){
            o.applyFilters(col);
            e.s=e.value;
        }
    }
    o.applyFilters=function(col){
        var ai=col.all.tags("INPUT"),are=new Array();
        for(var i=0; ai[i]; i++)
            are.push(_re(ai[i].value));
        var row=col.all.content.firstChild.tBodies[0].rows(0);
        while(row){
			var cell=row.firstChild,c=0,b=true;
            while(cell){
                if(!are[c].test(row.cells[c].innerText)){
                    b=false;
                    break;
                }
                cell=cell.nextSibling;
                c++;
            }
            row.runtimeStyle.display=b?"":"none";
            row=row.nextSibling;
        }
    }
	o.onselectstart=function(){
		if(event.srcElement.tagName=="INPUT")
			event.cancelBubble=true;
	}
    function _re(s){
        var re=new RegExp();
        try{
            re.compile("^"+s.replace(/(\[|\]|\(|\)|\.|\*|\\|\?)/g,"\\$1"),"i");
        }catch(err){
            alert("?_re: "+err.description);
        }
        return re;
    }
    function _tr(){
        var tr=eTag("TR");
        return tr.offsetParent.parentElement.id=="content"?tr:null;
    }
    function _col(e){
        var col=e.offsetParent;
        while(col && col.id!="col")
            col=col.offsetParent;
        return col;
    }
}

function da_tabs(o){
	var a=o.innerText.split("|"),i=-1,s="",ss,aa;
	while(ss=a[++i]){
		aa=ss.split(":");
		s+="<q tab='"+aa[0]+"'>"+aa[1]+"</q>";
	}
	o.innerHTML="<table class=fixed height=100% cellspacing cellpadding><tr height=1%><td id=bar>"+s+"</td></tr><tr><td><div id=content></div></td></tr></table>";
	var bar=o.all.bar,q=bar.firstChild,div=o.all.content,e;
	while(q){
		if(e=window[q.tab])
			div.appendChild(e).style.display="none";
		q=q.nextSibling;
	}
	bar.onclick=function(){
		var q=eTag("Q"),f; if(!q)return;
		try{
			window[f=o.id+"_click"](q);
		}catch(err){
			alert("?da_tabs: "+f+"(...): "+err.description);
		}
	}
	bar.onmouseover=o.onmouseout=function(){
		var q=eTag("Q"); if(!q||q.className=="sel")return;
		q.className=event.type=="mouseover"?"hil":"";
	}
	o.select=function(selq){
		var q=bar.firstChild;
		while(q){
			var e=window[q.tab];
			if(q==selq){
				q.className="sel";
				if(e){
					e.style.display="";
					_exec(e.ontabshow);
				}
			}else{
				q.className="";
				if(e)
					if(e.style.display!="none"){
						e.style.display="none";
						_exec(e.ontabhide);
					}
			}
			q=q.nextSibling;
		}
		o.curTab=selq;
	}
	o.select(null);
}
//</script>