function deleteText(object)
{	
	if(!object.dlt)
	{
		object.value="";
		object.dlt=true;
	}
}

function addBookmark(title){
	if (window.sidebar) //Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, location.href, '');
	else if (window.external) //IE bookmark
		external.AddFavorite(location.href, title);
	else if(window.opera && window.print) //Opera Hotlist
		return true;
}

function closePopup(id) {
	var pop=document.getElementById(id);
	if (pop) {
		pop.style.display="none";
	}
}

function showPopup(id) {
	var pop=document.getElementById(id);
	if (pop) {
		pop.style.display="block";
	}
}

function togglePopup(id) {
	var pop=document.getElementById(id);
	if (pop) {
		if (pop.style.display=="none") 
			pop.style.display=""; 
		else 
			pop.style.display="none";
	}
}

function togglePopupSingle(name, id) {
	var pop=document.getElementById(id);
	if (pop) {
		//var x=document.getElementsByTagName(name);
		var x = document.getElementById('tblIEholder').getElementsByTagName('table');
		for (var i = 0; i < x.length; i++){ 
			x[i].style.display="none";
			
			var img =document.getElementById('img_'+x[i].id.split('_')[2]);

			if(img && img.src.indexOf('toggle.exp.gif')>-1)
			{
				img.src=img.src.replace(/toggle.exp.gif/, 'toggle.col.gif');
			}
		}
		
		if (pop.style.display=="none") 
			pop.style.display=""; 
		else 
			pop.style.display="none";
		var img=document.getElementById('img_'+id.split('_')[2]);
		if(img)
			img.src=img.src.replace(/toggle.col.gif/, 'toggle.exp.gif');
	}
}


function execute(e,command)
{	
	if(e && command)
	{
		var key=e.keyCode;
		if(key && key==13)
			eval(command);
	}
}

function setFormAction(object,action,target)
{	
	while(object && object.nodeName.toLowerCase()!="form" && (object.parentNode ||object.parentElement))
	{
		if(object.parentNode)
			object=object.parentNode;
		else if(object.parentElement)
			object=object.parentElement;
	}
	if(object)
	{
		object.action=action;
		object.target=target;
		
	}
}

function DisableWindow(id)
{
	var object=document.getElementById(id);
	if(object)
	{
		object.disabled=true;
	}
}





function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

var currentIncrease=0;
function increaseText(id,increase)
{
	//alert(currentIncrease);
	if((currentIncrease>2 && increase>0) || (currentIncrease<-2 && increase<0))
		{
			return;
		}
	
	if(increase==0)
		currentIncrease=0;
	else
		currentIncrease+=increase;
	
	//setCookie("textincrease",currentIncrease,null,"/");
		

	var o=document.getElementById(id);
	if(o)
	{
		if (o.hasChildNodes() || (o.childNodes && o.childNodes.length>0) ) {
			var el;
		    if(document.all)
				el= o.children;
			else
				el= o.childNodes;
				
			
			for (var i=0; i<el.length; i++)
				if(el[i].nodeName.toLowerCase()!="#text")
					handleIncrease(el[i], increase);
		}
			
	}	
}


function getStyle(x,styleProp)
{
	var y=null;

	if (document.defaultView && document.defaultView.getComputedStyle)
		y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	else if (x.currentStyle)
		y = eval('x.currentStyle.' + styleProp);
	
	return y;
}


function handleIncrease(o, increase)
{

	if(o)
	{
		if (o.hasChildNodes() || (o.childNodes && o.childNodes.length>0) ) {
			var el;
		    if(document.all)
				el= o.children;
			else
				el= o.childNodes;
					
			for (var i=0; i<el.length; i++)
			{ //alert(el[i].nodeName.substr(0,1));
				if(el[i].nodeName.substr(0,1)!="#")
					handleIncrease(el[i], increase);
			}
		}
			
		var newval=null;
		
		if(o.style && o.style.fontSize)
			newval=o.style.fontSize;
		else
			newval=getStyle(o,(document.all ? "fontSize" : "font-size") );
			
		if(newval && newval!="")
		{
//			alert(newval);
			var extension=newval.match(/[a-z]+$/i);
//			alert("ext: " + extension);
			newval=newval.match(/^[\d\.]+/i);
//			alert("\nnewval: " + newval + "\nincrease: " + increase + "\nextension: " + extension);
//			alert("" + (parseFloat(newval) + increase) + extension);
//			throw("x");
			
			try {
				o.style.fontSize=(parseFloat(newval) + increase) + extension;			
			} catch (e) {
				alert("Napaka v cookieincrease!\n" + e + "\nnewval: " + newval + "\nincrease: " + increase + "\nextension: " + extension);
				throw(e);
			}
		}
	
	}	

}

//post na poljubno stran
//!!POZOR - viewstate se ne prenese - se pa zato vse drugo  
function __doRedirectPostBack(targeturl, target)
{	
	if(!targeturl || targeturl=='') return false;
	
	// save action and target
	document.tempTarget = document.forms["Form1"].target;
	document.tempAction = document.forms["Form1"].action;
	
	document.forms["Form1"].__VIEWSTATE.value=''; //spraznimo viewstate (da ne pošilja brezveznih podatkov)
	document.forms["Form1"].__VIEWSTATE.name='NOVIEWSTATE'; //pozabimo na viewstate
	document.forms["Form1"].action=targeturl; //nastavi novi URL
	document.forms["Form1"].target=target;
	document.forms["Form1"].submit(); //pošlji podatke
	
	// reset action and target
	document.forms["Form1"].target = document.tempTarget;
	document.forms["Form1"].action = document.tempAction;
	
	// clear
	document.tempTarget = null;
	document.tempAction = null;
	
	return false;
}

function changeProperties(sourceobj, targetobj)
{
	if(sourceobj.href && targetobj.href) //povezava
		targetobj.href = sourceobj.href;	
}

function changePropertiesImg(sourceobj, targetobj)
{
	if(sourceobj.src && targetobj.src) //slika
		targetobj.src = sourceobj.src;
	if(sourceobj.alt && targetobj.alt) //slika alt
	{
//		alert("old: " + targetobj.alt + ",  new: " + sourceobj.alt);
		targetobj.alt = sourceobj.alt;		
//		alert("change alert!!!  ->   " + targetobj.alt);
	}
}

/*[OBSOLUTE - use animClass2]*/
var animClass = Class.create();
animClass.prototype = {
	initialize: function(container, prefix){
		this.elements = document.getElementById(container).getElementsByTagName("a");
		this.prefix = prefix;
		this.imageIndex = 0;
		this.animInterval = null;
		this.delay = 2000;		
		this.doAnimEvent = this.doAnim.bind(this);
		this.start();
	},
	
	start: function(){		
		if(!this.animInterval)
			this.animInterval = setTimeout(this.doAnimEvent, this.delay);
	},
	
	end: function(){
		if(this.animInterval){
			clearTimeout(this.animInterval);
			this.animInterval=null;
		}
	},
	
	aTagMouseOverEvent: function(ele){
		this.end();
		changeProperties(ele, document.getElementById(this.prefix+'_publink'));
		changeProperties(ele, document.getElementById(this.prefix+'_listaj'));
		document.getElementById(this.prefix+'_title').innerHTML=ele.title;
	},
	
	imgTagMouseOverEvent: function(ele){
		this.end();
		changePropertiesImg(ele, document.getElementById(this.prefix+'_slikca'));
	},
	
	doAnim: function(){
		if(this.imageIndex >= this.elements.length) this.imageIndex=0;
		this.aTagMouseOverEvent(this.elements[this.imageIndex]);
		this.imgTagMouseOverEvent(this.elements[this.imageIndex].getElementsByTagName("img")[0]);
		this.imageIndex++;
		this.animInterval = setTimeout(this.doAnimEvent, this.delay);
	}
};

/*
 * Anim class 2 (funny effect :))
 */
var animClass2 = Class.create({
	initialize: function(container){
		this.obj = $(container);
		this.title = $(this.obj.id.replace("_parent","_title"));
		this.big = this.obj.select(".big")[0];
		this.items = this.obj.select(".item img");
		
		if(this.obj && this.title && this.big && this.items.length>0)
			this.init();
	},
	
	init: function(){
		this.big.defaultDim = this.big.getDimensions();		
		this.big.hide();
		this.big.style.left="48px";
		this.imageIndex = 0;
		this.animInterval = null;
		this.delay = 6500;
		
		this.changeEvent = this.onChange.bind(this);
		this.puffEvent = this.onPuff.bind(this);
		this.startEvent = this.start.bind(this);
		this.endEvent = this.end.bind(this);
		
		this.obj.observe("mouseover", this.test.bind(this));

		setTimeout(this.startEvent, 3000);
	},
	
	test: function(){
		this.end();
		clearTimeout(window.tx);
		window.tx = setTimeout(this.startEvent, 3000);
	},
	
	start: function(){
		this.onChange();
		this.animInterval = setInterval(this.changeEvent, this.delay);
	},
	
	end: function(){
		this.big.hide();
		clearInterval(this.animInterval);
	},
	
	onPuff: function(){
		this.big.puff({duration:0.0});
	},
	
	onChange: function(){
		this.big.src=this.items[this.imageIndex].src;
		this.title.update(this.items[this.imageIndex].alt);
		
		this.big.appear({duration:0.5});
		setTimeout(this.puffEvent,4000);
		
		this.imageIndex++;
		if(this.imageIndex >= this.items.length) this.imageIndex=0;
	}
});


var scrollJS = Class.create({
    initialize: function(scrollerID, speed){
        this.scroller = $(scrollerID);
		this.speed = speed;
        if(this.scroller) this.init.bind(this).delay(0.1);
    },
    
    init: function(){
		this.onMove = this.move.bind(this);
        this.start();
        
        Event.observe(this.scroller, "mouseover", this.stop.bind(this));
        Event.observe(this.scroller, "mouseout", this.cont.bind(this));    
    },

    start: function(){
        this.tableTemp = this.scroller.select("table")[0];
        this.contentHeight = this.tableTemp.getDimensions().height;
        this.scroller.appendChild(this.tableTemp.cloneNode(true));
        setInterval(this.onMove, this.speed);
    },
    
    stop: function () {
		this.stopex=true;
    },
    
    cont: function () {
		this.stopex=false;
    },

    move: function()
    {
		if(this.stopex) return;
		this.scroller.prevScroll=this.scroller.scrollTop;
		this.scroller.scrollTop++;
		if(this.scroller.scrollTop >= this.contentHeight || this.scroller.prevScroll==this.scroller.scrollTop)
		{
			this.scroller.appendChild(this.tableTemp.cloneNode(true));
			this.scroller.removeChild(this.scroller.select("table")[0]);
			this.scroller.scrollTop=0;
		}
    }
});