/**
 * @author goran
 */


Object.extend(Event, {
	wheel:function (event){
		var delta = 0;
		if (!event) event = window.event;
		if (event.wheelDelta) {
			delta = event.wheelDelta/120; 
			if (window.opera) delta = -delta;
		} else if (event.detail) { delta = -event.detail/3;	}
		return Math.round(delta); //Safari Round
	}
});





$("home").observe("mousewheel",function(event) {
		if ($("btnNext_OrgUnit:search").disabled)
		{
			return false;
		}
		if (event.wheelDelta<0)
		{
			moveNext($("home"));
		}
		else
		{
			movePrev($("home"));
		}
		return false;
	});
	$("home").observe("DOMMouseScroll",function(event) {
		if ($("btnNext_OrgUnit:search").disabled)
		{
			return false;
		}
		if (event.detail<0)
		{
			movePrev($("home"));
		}
		else
		{
			moveNext($("home"));
		}
		return false;
	});




var retrievedAll=true;
var currentPage=0;

function moveNext(table)
{
	if (!retrievedAll)
	{
		retrivedAll=true;
		var btnNext=$("btnNext_OrgUnit:search");
		btnNext.disabled=true;
		var btnPrev=$("btnPrev_OrgUnit:search");
		btnPrev.disabled=true;
		new Ajax.Updater("Updater_OrgUnit:search", document.url,
		{parameters:{ajax:'ajax',direction:'next',
		  ORG_UNIT_NAME:'',CITY_NAME:'',
		  currentpage:currentPage},
		 onComplete: function() {
			var workingTable=$("OrgUnit:search");
			var cashTable=$("updated_OrgUnit:search");
			if (document.all)
			{
				for(i=0;i<cashTable.rows.length;i++)
				{
					var row=cashTable.rows(i);
					var newRow=window.parent.document.createElement("tr");
					newRow.style.cssText=row.style.cssText;
					for(j=0;j<row.cells.length;j++)
					{
						var cell=row.cells(j);
						var newCell=window.parent.document.createElement("td");
						newCell.style.cssText=cell.style.cssText;
						newCell.align=cell.align;
						newCell.innerHTML=cell.innerHTML;
						newRow.appendChild(newCell);
					}
					workingTable.tBodies(0).appendChild(newRow);
				}
			}
			else
			{
				workingTable.tBodies.item(0).innerHTML+=cashTable.tBodies.item(0).innerHTML;
			}
			btnNext.disabled=false;
			btnPrev.disabled=false;
			currentPage++;
			retrivedAll=cashTable.getAttribute("retrivedAll")=="true";
		 }
		});
		//var form=$("form_OrgUnit:search");
		//form.submit();
	}
	var i=1;
	while (table.rows.item(i).style.visibility!="visible")
	{
		i++;
	}
	var firstRow=table.rows.item(i);
	while (i<table.rows.length && table.rows.item(i).style.visibility!="hidden")
	{
		i++;
	}
	var lastRow=null;
	if (i<table.rows.length && table.rows.item(i).style.visibility=="hidden")
	{
		lastRow=table.rows.item(i);
	}
	for(i=0;i<5;i++)
	{
		if (lastRow!=null)
		{
			lastRow.style.visibility="visible";
			lastRow.style.display="";
			lastRow=lastRow.nextSibling;
			while (lastRow!=null && (!lastRow.tagName || (firstRow.tagName!="tr" && firstRow.tagName!="TR")))
			{
				lastRow=lastRow.nextSibling;
			}
		}
		else
		{
			break;
		}
		firstRow.style.visibility="hidden";
		firstRow.style.display="none";
		firstRow=firstRow.nextSibling;
		while (!firstRow.tagName || (firstRow.tagName!="tr" && firstRow.tagName!="TR"))
		{
			firstRow=firstRow.nextSibling;
		}
	}
}

function movePrev(table)
{
	var i=1;
	while (table.rows.item(i).style.visibility!="visible")
	{
		i++;
	}
	if (i==1)
	{
		return false;
	}
	var firstRow=table.rows.item(i);
	if (firstRow!=null)
	{
		firstRow=firstRow.previousSibling;
		while (firstRow!=null && (!firstRow.tagName || (firstRow.tagName!="tr" && firstRow.tagName!="TR")))
		{
			firstRow=firstRow.previousSibling;
		}
	}
	while (i<table.rows.length && table.rows.item(i).style.visibility!="hidden")
	{
		i++;
	}
	var lastRow=null;
	if (i<table.rows.length && table.rows.item(i).style.visibility=="hidden")
	{
		lastRow=table.rows.item(i);
		lastRow=lastRow.previousSibling;
		while (!lastRow.tagName || (lastRow.tagName!="tr" && lastRow.tagName!="TR"))
		{
			lastRow=lastRow.previousSibling;
		}
	}
	if (lastRow==null)
	{
		lastRow=table.rows.item(table.rows.length-1);
	}
	for(i=0;i<5;i++)
	{
		if (firstRow!=null && firstRow.id!="header_OrgUnit:search")
		{
			firstRow.style.visibility="visible";
			firstRow.style.display="";
			firstRow=firstRow.previousSibling;
			while (firstRow!=null && (!firstRow.tagName || (firstRow.tagName!="tr" && firstRow.tagName!="TR")))
			{
				firstRow=firstRow.previousSibling;
			}
		}
		else
		{
			break;
		}
		lastRow.style.visibility="hidden";
		lastRow.style.display="none";
		lastRow=lastRow.previousSibling;
		while (!lastRow.tagName || (lastRow.tagName!="tr" && lastRow.tagName!="TR"))
		{
			lastRow=lastRow.previousSibling;
		}
	}
	return false;
}



















$(listings).observe('click', 

function(event)
{
  alert(Event.element(event).innerHTML);
  this.style.backgroundColor='#cc0000';
 }
 
 )
 
 
 

 function goto(url){
window.location=""+url;
}




function gotoTag(tag){

window.location.hash = tag;

}



function periodicalUpdate()
{
	
	$("izlez").disable();
	updatecon("periodicalupdate", "nemanaracka.html");
}


var gCallCount=0;
var pe=null;
function startNotification(){
	pe=new PeriodicalExecuter(function(pe){
	    
		 
		 	
		
		 	
		 	periodicalUpdate();
		 pe.stop();
		
	}, 7)
}






function updatecon(content, url)
{
	
	var e = new Ajax.Updater(content, url, 
	{
		evalScripts:true,
		onComplete: 
		function()
		{
			 $(content).prepare(); 
			 Position.cumulativeOffset($content);
			 
			 
			 //Position.within($content, 200, 200);
			 //$(content).scrollTo();
		} 
	}
		);
	 
	
}

function izbrisi(element)
{
	
	$(element).remove();
	
}

function vizible (element)
{
	$(element).visible();
}

function prikazi(forma)
{
	$(forma).show();
	
}


function dodadi(el,i)
{
	
	
	
		//$(el).insert({after:"<p> sfiovbjspeoihbv </p>"});
	
	//$(el).visible();
	//el.style.visibility = "visible";
	//el.style.display = "block";
	
	//$(el).firstDescendant().style.display="block";
	
	
	
	
	if ( $('home').select('.klasa1')[i+1] )
	{
		$('home').select('.klasa1')[i+1].show();
	}
	else
	{
		$('home').select('.klasa1')[0].show();
	}
	$('home').select('.klasa1')[i].hide();
	
	
	//$('home').getElementsByClassName('klasa1').style.display = "none";
	
	
	//$(el).firstDescendant().setStyle({visibility:'visible'; display = 'block' }) ;
	// $(el).firstDescendant().style.display = "inherit";
	
	
	
}

clickMenu = function(dodadiuser) {
	var getEls = document.getElementById(dodadiuser).getElementsByTagName("div");
	var getAgn = getEls;

	for (var i=0; i<getEls.length; i++) {
			getEls[i].onclick=function() {
				for (var x=0; x<getAgn.length; x++) {
				getAgn[x].className=getAgn[x].className.replace("click", "");
				}
				this.className+="click";
				}
			}
		}




//Example explained - The JavaScript code

var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="js/select_list.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}


//Example explained - The JavaScript code 222222222222222

var xmlhttp;

function showUser2(str)
{
xmlhttp=GetXmlHttpObject2();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="js/select_list2.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged2;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged2()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint2").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject2()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}









