window.onload = onLoadDoc;
window.onresize = doResize;
document.ondragstart=doDrag;

var hMx,hMy;
var helperBub=null;
var helperBody=null;
var helperIfr=null;
var helperIE6=null;
function httpReciver(){
	if ((xmlhttp.readyState!=4)||(xmlhttp.status!=200))
			return;
	var txt=xmlhttp.responseText;
	var cw=document.body.offsetWidth-4;
	var w=(txt.length>250)?300:200;
	if (w>cw)
		w=cw;
	helperBub.style.width=w+'px';
	helperBody.innerHTML=txt;
	if (helperIfr){
		helperBub.style.height=helperIE6.style.height=helperIfr.style.height=12+helperBody.offsetHeight+'px';
		helperIE6.style.width=helperIfr.style.width=helperBub.style.width;
	}
	if (hMx+w>cw)
		hMx=cw-w;
	if(hMx<0)
		hMx=0;
	cw=document.body.offsetHeight-4;
	w=helperBub.offsetHeight
	if (hMy+w>cw)
		hMy=cw-w;
	if(hMy<0)
		hMy=0;
	helperBub.style.left=hMx+'px';
	helperBub.style.top=hMy+'px';
	helperFade(5);
}
var curAlf=0;
var faderT=0;
function helperFade(n){
	clearTimeout(faderT);
	curAlf+=n;
	curAlf=(curAlf>100)?100:(curAlf<0)?0:curAlf;
	helperBub.style.filter='alpha(opacity='+curAlf+')';
	helperBub.style.opacity=curAlf/100;
	if (!curAlf){
		helperBody.innerHTML='';
		helperBub.style.left='-400px';
	}else if (curAlf<100)
	 faderT=setTimeout("helperFade("+n+")",20);		
}
function helperFadeOut(){
	helperFade(-5);
}
var xmlhttp=-1;
function showHelp(evt,nam){
	if (!xmlhttp)
		return;
	if (typeof(xmlhttp)=='number'){
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				xmlhttp = null;
				return;
			}
		}
		var hat=document.createElement('div');
		hat.className="title";
		hat.appendChild(document.createTextNode('X'));
		if (document.addEventListener){ 
			hat.addEventListener('click',helperFadeOut,false);
			hat.addEventListener('mouseout',helperFadeOut,false);
		}else{
			hat.attachEvent('onclick',helperFadeOut);
			hat.attachEvent('onmouseout',helperFadeOut);
		}
		helperBub=document.body.appendChild(document.createElement('div'))
		helperBub.className="helpbub";
		if (navigator.userAgent.indexOf('MSIE 6')>0){
			helperIfr=document.createElement('iframe');
			var put = document.createAttribute('frameborder');
			put.value = '0';
			helperIfr.setAttributeNode(put);
			helperBub.appendChild(helperIfr);
			helperIE6=document.createElement('div');
			helperIE6.className="ie6";
			helperBub.appendChild(helperIE6);
			helperIE6.appendChild(hat);
			helperBody=document.createElement('div');
			helperBody.className="body";
			helperIE6.appendChild(helperBody);
		}else{
			helperBub.appendChild(hat);
			helperBody=document.createElement('div');
			helperBody.className="body";
			helperBub.appendChild(helperBody);
		}
	}
	hMx=evt.clientX+10;
	hMy=evt.clientY-20;
	xmlhttp.open("GET", "?"+nam,true);
	xmlhttp.onreadystatechange=httpReciver;
	xmlhttp.send(null);
}




function doDrag() {	
	if (window.event && window.event.srcElement.nodeName=='A'){
		window.event.returnValue=false;
    	window.event.cancelBubble=true;	
		return false;
	}
}

var old_pos=0;
var pos_mode=0;
function getScroll(){
	var pos=0;
	if(pos_mode==1)
		pos=top.pageYOffset;
	else if(pos_mode==2)
		pos=top.document.documentElement.scrollTop;
	else if(pos_mode==3)
		pos=top.document.body.scrollTop;
	pos=(pos<=100)?0:pos-100;
	if (pos!=old_pos){
		old_pos=pos;
		positaja.style.top=pos+"px";
	}
}
function closeTeated(){
	oTeated.appendChild(positaja.firstChild);
	clearInterval(poller);
	positaja.style.visibility='hidden';
	setTimeout('doResize()',10);
}
var notHost=false;
var wh_measurer;
var positaja;
var oTeated;
var poller;
function onLoadDoc(){
	if (wh_measurer)
		return;
	var put=document.body.appendChild(document.createElement('div'));
	wh_measurer=put.appendChild(document.createElement('img'));
	wh_measurer.style.width="1px";
	wh_measurer.style.height="1px";
	wh_measurer.src="pildid/empty.gif";
	oTeated=document.getElementById("docTeated");
	if (oTeated){
		if(typeof(window.pageYOffset)=='number')
			pos_mode=1;
		else if(typeof(document.documentElement.scrollTop)=='number')
			pos_mode=2;
		else if(typeof(document.body.scrollTop)=='number')
			pos_mode=3;
		if (pos_mode){
			positaja=document.body.appendChild(document.createElement('div'));
			positaja.style.top='0';
			positaja.style.left='20%';
			positaja.style.position='absolute';
			positaja.style.width="60%";
			if (document.addEventListener)
				positaja.addEventListener('click',closeTeated,false);
			else
				positaja.attachEvent('onclick',closeTeated);
			var c= oTeated.firstChild;
			while(c.nodeName!='DIV')
				c = c.nextSibling;
			positaja.appendChild(c);
			poller=setInterval('getScroll()',200);
		}
	}
	if (!parent||(parent==window)|| 
			typeof(parent.toggleWidth)!='function'||typeof(parent.setHeight)!='function')
		notHost=true;
	if (!notHost) parent.toggleWidth(0, 1);
	if ((typeof(wh_measurer.scrollWidth)=='number') && document.getElementById("form_ShowWide")){
		var tbs = document.getElementsByTagName('DIV');
		if (tbs.length>0){
			var w = 0;
			for (var i=0;i<tbs.length;i++){
				w = Math.max(w,tbs.item(i).scrollWidth);
				if (tbs.item(i).className=='dataTable')
					tbs.item(i).style.overflow = 'visible';
			}
			if (!notHost) parent.toggleWidth(w + 6, 0);
		}
	}
	setTimeout('doResize()',10);
}
function doResize(){
	if (!wh_measurer)
		return onLoadDoc();
	if (notHost)
		return;
//alert(document.body.firstChild.offsetHeight + ' ' + wh_measurer.offsetTop);
	var xh = wh_measurer.offsetTop+1;
	setTimeout('parent.setHeight('+xh+')',5);
}

function flipflop(e){
	var evt=e?e:event;
	var cSrc=evt.target?evt.target:evt.srcElement;
	while(cSrc.nodeName!="TD")
		cSrc=cSrc.parentNode;
	cSrc=cSrc.parentNode;
	while(cSrc.nodeName!="TD")
		cSrc=cSrc.parentNode;
	var sRow=cSrc.parentNode;
	var tds=sRow.childNodes;
	var N=0;
	for (;N<tds.length;N++)
		if (tds.item(N)==cSrc)
			break;
	cSrc=sRow.parentNode;
	tds=cSrc.childNodes
	for (var i=2;i<tds.length;i++){
		sRow=tds.item(i).childNodes;
		if (sRow.length<N-1)
			continue;
		cSrc=sRow.item(N);
		while(cSrc.nodeName!="INPUT"){
			cSrc=cSrc.firstChild;
			if (!cSrc)
				break;
		}
		if (cSrc)
			cSrc.checked=!cSrc.checked;
	}
}
function getMyForm(el){var par=el.parentNode;while(par.nodeName!='FORM')par=par.parentNode;return par;}


