

window.onload=init;
// toto sa spusti po nacitani okna
function init(){
	startMouseWatching();
	//setAllHeightsFromStore();
}
 var allLists = new Array();
function search(listId,value,waitForKeyup)		
 {
   if(allLists[listId])
   window.clearTimeout(allLists[listId]);
   if(waitForKeyup == true)
   {
   	//alert('waitForKeyup');    
    allLists[listId]=window.setTimeout("search('"+listId+"','"+value+"');",550);
    return false;
   }
   
	
	switch(listId)
	{
		case 'tag':
			runPhpScript('/web/ajax/tags.php','&tag='+value,'tags');
		break;
		case 'author':
			runPhpScript('/web/ajax/authors.php','&author='+value,'authors');
		break;
	}
	
 }



/* ------------------------------------------------------------------------------------------------------------
	UniScript - univerzalne funkcie na pracu s layermi a dokumentom
	zalozene na 1K DHTML API (http://www.dithered.com/experiments/1kdhtml/index.html)
	modifikoval, rozsiril a dopolnil Riki Fridrich (http://acid.nfo.sk)
--------------------------------------------------------------------------------------------------------------- */
d=document;l=(d.layers)?1:0;op=navigator.userAgent.toLowerCase().indexOf('opera')!=-1;ie=(d.all)?1:0;
function gE(e,f){if(l){f=(f)?f:self;var V=f.document.layers;if(V[e])return V[e];for(var W=0;W<V.length;)t=gE(e,V[W++]);return t;}if(d.all)return d.all[e];return d.getElementById(e);}
/*
function hE(e){if(l)e.visibility='hide';else e.style.visibility='hidden'; e.style.display='none';}
function sE(e){if(l)e.visibility='show';else e.style.visibility='visible'; e.style.display='';}
*/function sEb(e){if(l)e.visibility='show';else e.style.visibility='visible'; e.style.display='block'; }
function sEi(e){if(l)e.visibility='show';else e.style.visibility='visible'; e.style.display='inline';}

function sE(e){if(l)e.visibility='show';else e.style.display='block';return false;}
function siE(e){if(l)e.visibility='show';else e.style.display='inline';return false;}
function hE(e){if(l)e.visibility='hide';else e.style.display='none';return false;}

function sX(e,x){if(l)e.left=x;else if(op)e.style.pixelLeft=x;else e.style.left=x+'px';}
function gX(e){if(l)return e.left;else if(op)return e.style.pixelLeft;else return parseInt(e.style.left);}
function sY(e,y){if(l)e.top=y;else if(op)e.style.pixelTop=y;else e.style.top=y+'px';}
function gY(e){if(l)return e.top;else if(op)return e.style.pixelTop;else return parseInt(e.style.top);}
function sW(e,w){if(l)e.clip.width=w;else if(op)e.style.pixelWidth=w;else e.style.width=w;}
function gW(e){if(l)return e.clip.width;else if(op)return e.style.pixelWidth;else return parseInt(e.style.width);}
function sH(e,h){if(l)e.clip.height=h;else if(op)e.style.pixelHeight=h;else e.style.height=h;}
function gH(e){if(l)return e.clip.height;else if(op)return e.style.pixelHeight;else return parseInt(e.style.height);}

function mT(e,x,y){sX(e,x);sY(e,y);}
function mB(e,x,y){sX(e,gX(e)+x);sY(e,gY(e)+y);}


function wH(e,h){if(l){Y=e.document;Y.write(h);Y.close();}if(e.innerHTML)e.innerHTML=h;}
function wHa(e,h){if(l)	{Y=e.document;Y.write(h);Y.close();}if(e.innerHTML)	e.innerHTML=e.innerHTML+h;
						}
function sC(e,t,r,b,x){if(l){X=e.clip;X.top=t;X.right=r;X.bottom=b;X.left=x;}else e.style.clip='rect('+t+'px '+r+'px '+b+'px '+x+'px)';}

function winW(){if(window.innerWidth)return window.innerWidth;else return d.body.clientWidth;}
function winH(){if(window.innerHeight)return window.innerHeight;else return d.body.clientHeight;}
function winL(){if(ie)return d.body.scrollLeft;else return window.pageXOffset;}
function winT(){if(ie)return d.body.scrollTop;else return window.pageYOffset;}



// ---------------------------------------------------------------------------------------------------------------------
// dalsie univerzalne funkcie  ------------------------------------------------------------------------------------------

function backgray(elid)
	{
		pom=document.getElementById(elid);
		pom.style['background']='rgb(200,200,200)';
	}
	function backtrans(elid)
	{
		pom=document.getElementById(elid);
		pom.style['background']='transparent';
	}

function addCls(elm,cls)
{
    if(elm)
    {
		var isok=1;
    	var clses = new Array();
    	clses=elm.className.split(" ");
		for(var i=0;i<clses.length;i++)
			if(cls==clses[i])
				isok=false;
    	if(isok==1)
    		elm.className+=" "+cls;
		//elm.setAttribute(elm.getAttribute('class')+" "+cls);
    }
}

function remCls(elm,cls)
{
	if(elm)
	{

		//elm.setclass=this.className.replace(new RegExp(" "+cls), "");
    	elm.className=elm.className.replace(new RegExp(""+cls), "");
    	//elm.setAttribute(elm.getAttribute('class').replace(new RegExp(" "+cls), ""));
	}
}




function chE(e)
{
	if(e)e.checked=true;
}

function unchE(e)
{
	if(e)e.checked=false;
}



// ---------------------------------------------------------------------------------------------------------------------
// cookie handling  ------------------------------------------------------------------------------------------

function saveCookie(name,value,days) {
     if (days) {
           var date=new Date();
          date.setTime(date.getTime()+(days*24*60*60*1000))
          var expires="; expires="+date.toGMTString()
     } else expires=""
     document.cookie=name+"="+value+expires+"; path=/";
     //window.alert("document.cookie:'"+document.cookie+"'");
}



function readCookie(name) {
     var nameEQ=name+"="
     var ca=document.cookie.split(';')
     for(var i=0;i<ca.length;i++) {
          var c=ca[i];
          while (c.charAt(0)==' ') c=c.substring(1,c.length)
          if (c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length)
     }
     return null
}



// ---------------------------------------------------------------------------------------------------------------------
// akoze ajax -spustanie php skriptov  ----------------------------------------------------------------------------------

function showRequest(http_request,intoDivId) {

		//alert('Chyba'+http_request.responseText);
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				document.getElementById(intoDivId).innerHTML=http_request.responseText;
               //alert(http_request.responseText);
            } else {
                //alert('Chyba');
            }
        }
    }

    
    function runPhpScript(url,postRequest,intoDivId)
{
	 	var http_request = false;
        //var postRequest = "string="+string;
		var r='';
        if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            try {
              http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (eror) {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
		if(intoDivId!='')
        	http_request.onreadystatechange = function() { showRequest(http_request,intoDivId); };

        http_request.open('POST', url, true);
        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http_request.send(postRequest);
}




/*
============================================================
Capturing The Mouse Position in IE4-6 & NS4-6
(C) 2000 www.CodeLifter.com
Free for all users, but leave in this  header */

// ---------------------------------------------------------------------------------------------------------------------
//  pozicia mysi a presuvanie okien -------------------------------------------------------------------------------------
// Temporary variables to hold mouse x-y pos.s
var currentMouseX = 0
var currentMouseY = 0
var differemceOnDragStartX=new Array();
var differemceOnDragStartY=new Array();
function startMouseWatching(){
	if (l) {document.captureEvents(Event.MOUSEMOVE);}
	document.onmousemove = moveHandler;
}

function moveHandler(e) {   // Main function to retrieve mouse x-y pos.s
  if (e) {
    currentMouseX = e.pageX
    currentMouseY = e.pageY
  } else {
    currentMouseX = event.clientX + getLeft_scrolled();
    currentMouseY = event.clientY + getTop_scrolled();
  }
  // catch possible negative values in NS4
  if (currentMouseX < 0){currentMouseX = 0}
  if (currentMouseY < 0){currentMouseY = 0}
  return true;
}


function getTop_scrolled()
{
	if (window.innerHeight)
	  pos = window.pageYOffset
	else if (document.documentElement && document.documentElement.scrollTop)
		pos = document.documentElement.scrollTop
	else if (document.body)
		  pos = document.body.scrollTop
	return pos;
}


function getLeft_scrolled()
{
	if (window.innerWidth)
		  pos = window.pageXOffset
	else if (document.documentElement && document.documentElement.scrollLeft)
		pos = document.documentElement.scrollLeft
	else if (document.body)
		  pos = document.body.scrollLeft
	return pos;
}







// ---------------------------------------------------------------------------------------------------------------------
//  minimize divs : vars nd functons ------------------------------------------------------------------------------------------
var allHeights= new Array();
var allHeightsTemp= new Array();
var allOpacitiesTemp= new Array();
var ourInterval=new Array();

function setAllHeightsFromStore()
{
	var nameEQ="elmid";

     var castr=allHeightsString;//document.cookie.split(';');
     var ca=castr.split(';');
     var elm;
     for(var i=0;i<ca.length;i++) {

          var c=ca[i];
          while (c.charAt(0)==' ')
          	c=c.substring(1,c.length)
          //window.alert('i= '+i+' c'+c);
          if (c.indexOf(nameEQ)==0)
          {
          	var two=c.split('=');
          	var elmid=two[0].substring(nameEQ.length,c.length);
          	var vl=two[1];
          	if((vl>0)&&(elm=document.getElementById(elmid)))
          	{
          		allHeights[elmid]=elm.clientHeight;//vl;
          		//window.alert(elmid+': '+elm.clientHeight+' / '+vl);
          		allHeightsTemp[elmid]=0;
          		elm.style.height='0px';
          		elm.style.display='none';
          		//elm.style._height=vl+'px';
          	}
          }	//return c.substring(nameEQ.length,c.length)
     }
     return null;
}



function minimize(elid)
{

	var elm=gE(elid);
	var currentH=0;
	if(allHeights[elid])
		currentH=allHeightsTemp[elid];
	else
		currentH=elm.clientHeight;
	allHeightsTemp[elid]=currentH;
	//window.alert(currentH);
	elm.style.height=currentH+'px';
	if (currentH>0)
		allOpacitiesTemp[elid]=1;
	else
		allOpacitiesTemp[elid]=0;
	if (!allHeights[elid])
		allHeights[elid]=currentH;
	//allObjcts[elid]=elm;

	clearInterval(ourInterval[elid]);
	if (currentH>0)
	{
		//window.alert('ide sa zmensovat');
		//window.alert('makeDisapear(\''+elid+'\','+Math.ceil(allHeights[elid]/4)+','+(1/4)+')');
		ourInterval[elid] = setInterval('makeDisapear(\''+elid+'\','+Math.ceil(allHeights[elid]/4)+','+(1/4)+')',10);
	}
	else
	{
		//window.alert('ide sa zvacsovat');
		ourInterval[elid] = setInterval('makeShow(\''+elid+'\','+Math.ceil(allHeights[elid]/4)+','+(1/4)+')',10);
	}

	//elm.style.height;
}

function makeDisapear(elid,minusHeight,minusVisib)
{
	var elm=gE(elid);
	if (allHeightsTemp[elid]>0)
	{
		allHeightsTemp[elid]=Math.max(allHeightsTemp[elid]-minusHeight,0);
		allOpacitiesTemp[elid]=Math.max(allOpacitiesTemp[elid]-minusVisib,0);
		elm.style.height=String(allHeightsTemp[elid])+'px';
		//elm.style.opacity=String(allOpacitiesTemp[elid]);
		//elm.style.filter='alpha(opacity='+String(allOpacitiesTemp[elid]*100)+')';
		//window.alert('zmensovanie '+allHeightsTemp[elid]+' - '+minusHeight+' - '+minusVisib);
	}

	else
	{
		//window.alert('zmenesene '+allHeightsTemp[elid]);
		clearInterval(ourInterval[elid]);
		allHeightsTemp[elid]=0;
		elm.style.height='0px';
		elm.style.display='none';
		//elm.style.opacity=0;
		//elm.style.filter='alpha(opacity=0)';
		//saveCookie('elmid'+elid,allHeights[elid],2);
		runPhpScript('/postget/settings.php','&type=minimize&subtype=elmid'+elid+'&value='+allHeights[elid],'');
	}


}


function makeShow(elid,plusHeight,plusVisib)
{
	var elm=gE(elid);
	if (allHeightsTemp[elid]<allHeights[elid])
	{
		allHeightsTemp[elid]=allHeightsTemp[elid]+plusHeight;
		allOpacitiesTemp[elid]=allOpacitiesTemp[elid]+plusVisib;
		elm.style.height=String(allHeightsTemp[elid])+'px';
		//elm.style.opacity=String(allOpacitiesTemp[elid]);
		//elm.style.filter='alpha(opacity='+String(allOpacitiesTemp[elid]*100)+')';
		elm.style.display='block';
	}

	else
	{
		clearInterval(ourInterval[elid]);
		allHeightsTemp[elid]=allHeights[elid];
		elm.style.height=allHeights[elid]+'px';
		//elm.style.opacity=1;
		//elm.style.filter='alpha(opacity=100)';
		//saveCookie('elmid'+elid,0,2);
		runPhpScript('/postget/settings.php','&type=minimize&subtype=elmid'+elid+'&value=0','');
	}

}






// ---------------------------------------------------------------------------------------------------------------------
//  zobrazenie a skryvanie + pohyb tinywindows  ------------------------------------------------------------------------------------------
function tinywindow_open(elid,inhtmlText,setPosition)
{
	var elmt=gE(elid);
	elmt.style.display='block';
	if (setPosition>0)
	{
		//window.alert('left:'+currentMouseX+"\n top"+currentMouseY);
		elmt.style.left=(currentMouseX+5)+'px';
		elmt.style.top=(currentMouseY+5)+'px';
		if (inhtmlText!='')
			elmt.innerHTML=inhtmlText;

	}
  	//tinywindow_close(elid,9000);
  	return 0;
}


function tinywindow_refresh(elid)
{
	var elmt=gE(elid);
		elmt.style.left=(currentMouseX+5)+'px';
		elmt.style.top=(currentMouseY+5)+'px';
  	return 0;
}

function tinywindow_move(elid,actn)
{
	var elmt=gE(elid);
	switch (actn)
	{
		case 'start':
		//window.alert(elmt.style.top.slice(0,-2));
		differemceOnDragStartY[elid]=currentMouseY-Number(elmt.style.top.slice(0,-2));
		differemceOnDragStartX[elid]=currentMouseX-Number(elmt.style.left.slice(0,-2));
		elmt.style.cursor='move';
	break;
	case 'move':
		if (differemceOnDragStartY[elid]>0)
		{
			elmt.style.top=String(currentMouseY-differemceOnDragStartY[elid])+'px';
			elmt.style.left=String(currentMouseX-differemceOnDragStartX[elid])+'px';
		}
	break;
	case 'end':	default:
		differemceOnDragStartY[elid]=0;
		differemceOnDragStartX[elid]=0;
		elmt.style.cursor='default';
	break;
	}

	//elmt.style.top=(currentMouseY-4)+'px';

}


function tinywindow_close(elid,delay)
{
	if (delay>0)
	{
		window.setTimeout('tinywindow_close(\''+elid+'\',0)',delay);
		return 0;
	}
	else
	{
		var elmt=gE(elid);
		elmt.style.display='none';
	  	return 0;
	}
}






// ---------------------------------------------------------------------------------------------------------------------
//  dates functions ------------------------------------------------------------------------------------------

function setdatetoday(obj_id){
		obj=gE(obj_id);
		var d = new Date()
		year=d.getFullYear()+'';
		month=(d.getMonth() + 1);
		if (month<10)month="0"+month;
		date=d.getDate();
		if (date<10)date="0"+date;
		hours=d.getHours();
		if (hours<10)hours="0"+hours;
		minutes=d.getMinutes();
		if (minutes<10)minutes="0"+minutes;
		obj.value=year+'-'+month+'-'+date+' '+hours+':'+minutes+':00';
}



// ---------------------------------------------------------------------------------------------------------------------
//  string functions ------------------------------------------------------------------------------------------
function strToInt2(strx)
{
  zero="0";r=0;
	for (i=strx.length-1;i>=0;i--)
	 {r=r +  ( Math.pow(10,(strx.length)-i-1) * (strx.charCodeAt(i)-zero.charCodeAt(0)) );}
	return r;
}







// ---------------------------------------------------------------------------------------------------------------------
//  rozne fcie na pracu s objektami ------------------------------------------------------------------------------------------

function clearDefaultVal(elm,val,addClas)
{
	if(elm.value==val)
		elm.value='';
	if (addClas)
		addCls(elm,addClas);
}

function filltextinput(objid,val)
{
	//window.alert('dfdf');
	d=gE(objid);
	d.value=val;
}


function showhide(objid)
  {
		el=gE(objid);
		if ((el.style.display=='block')||(el.style.display==''))
		     el.style.display='none';
		else
		   el.style.display='block';
	}

function showobj(objid)
{
	el=gE(objid);
		sE(el);
}
function hideobj(objid)
{
	el=gE(objid);
		hE(el);
}

function showhide_fakt(objid,checkid,fromid,toid)
 {
		el=gE(objid);
		el2=gE(checkid);
		el3=gE(fromid);
		el4=gE(toid);
		if (el2.checked==true)
		{el.style.display='table-row';
		     el4.value=el3.value;
		}
		else
		{
		   el.style.display='none';
		   el4.value='0';
		}
}


function disable_if(boolv,elid){ //window.alert("shit");
  pom2=gE(elid);
  if (boolv)
  	{pom2.disabled=true;}
  else {pom2.disabled=false;}
}


function fill_fields(vlue,idsarr)
{
	vluesarr=vlue.split("#");
	for(i=0;i<idsarr.length;i++){
    	fld=gE(idsarr[i]);
    	fld.value=vluesarr[i];
	}
}


function checkfields(chngby,str_allids)
{
	allids=str_allids.split('#');
	for (i=0;i<allids.length;i++)
	{
		if (elmnt=gE(allids[i]))
			if (chngby.checked)
				elmnt.checked=true;
			else
				elmnt.checked=false;
	}
	return;
}


function quickadd_win(text1,title,projid)
{
	var inhtmlText=text1;
	inhtmlText=inhtmlText.replace('##id',projid);
	inhtmlText=inhtmlText.replace('##id',projid);
	inhtmlText=inhtmlText.replace('##id',projid);
	inhtmlText=inhtmlText.replace('##title',title);
	tinywindow_open('window1',inhtmlText,1);
  	return 0;
}

function open_taskwindow(params)
{

	var randomnumber=Math.floor(Math.random()*1001)
	//window.alert('dd'+String(randomnumber));
	window.open('task/task_add.php'+params,'addtask'+String(randomnumber),'left=100,top=100,width=600,height=550,menubar=no,directories=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,status=yes');

}




function addKodexPart(fromElmId,toElmId)
{
    fromElm=gE(fromElmId);
    toElm=gE(toElmId);

    if((!toElm)||(!fromElm))
    {alert('aa'); return false;}
    toElm.value=toElm.value+fromElm.innerHTML;
}

// ---------------------------------------------------------------------------------------------------------------------
//  validacia formularu ------------------------------------------------------------------------------------------

function valForm_Staznost(form,jump2topOfpage)
{
	var f=document.getElementById(form),item;
	var valid=true;
	//zoznam poloziek na validaciu
	switch(form)
	{
		case 'appeal':	
			var itemList=new Array('name','street','city','num','zip','mail','more-info','appeal-text');
			break;
		case 'atest-form':	
			var itemList=new Array('zadavatel','street','city','num','zip','person','ico','dic','phone','mail','campaign','campaign-desc','campaign-label','medium');
			break;
		default:
			var itemList=new Array();
			break;
	}
	var formItems_default_border="1px solid #7d7d7d"; //povodna hodnota ramceku inputov
	for(var i=0;i<itemList.length;i++)
	{
		item=document.getElementById(itemList[i]);
		item.style.border=formItems_default_border; //vrat povodny border. pre pripad ze bol zmeneny
		switch(item.type)
		{
			case 'textarea':	
				if(item.value.length<2) {
					valid=false; item.style.border='1px solid #f00'; }
				break;
			default:
				if(item.value.length==0) {
					valid=false; item.style.border='1px solid #f00'; }
				break;
		}
	}
	if(!valid) //ak nastala chyba vypis pop up spravu
	{
		alert("Položky vyznačené červeným rámčekom sú povinné !");
		if(jump2topOfpage) scroll(0,0);	//skok na vrch stranky
	}
	return valid;
}