// Scripts for representatives


function submit(url) {
	document.frm_searched.action = url;
	document.frm_searched.JSsubmit.name = "sb_search";
	document.frm_searched.submit();
}

function regionSelect()
{
	var i;
	var index = document.frm_search.elements[0].selectedIndex;
	var reg = document.frm_search.elements[0].options[index].value;

	if (reg == '')
	{
		len = document.frm_search.elements[1].options.length;
		for (i=0; i<len; i++)
		{
			document.frm_search.elements[1].options[1] = null;
		}
		len = cityAll.length;
		var j=1;
		for (i=1; i<len; i++)
		{
			if (cityAll[i] != undefined){
				document.frm_search.elements[1].options[j] = new Option(cityAll[i],cityID[i]);
				j++;
			}
		}
	} else
	{
		len = document.frm_search.elements[1].options.length;
		for (i=0; i<len; i++)
		{
			document.frm_search.elements[1].options[1] = null;
		}
		len = region[reg].length;
		var j=1;
		for (i=0; i<len; i++)
		{
			if (region[reg][i] != undefined){
				document.frm_search.elements[1].options[j] = new Option(region[reg][i],i);
				j++;
			}
		}
	}
}






// Scripts for movies


	// some variables to save
	var currentPosition;
	var currentVolume;
	var currentItem;

	// these functions are caught by the JavascriptView object of the player.
	function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
	function getUpdate(typ,pr1,pr2,pid) {
		if(typ == "time") { currentPosition = pr1; }
		else if(typ == "volume") { currentVolume = pr1; }
		else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
		var id = document.getElementById(typ);
		id.innerHTML = typ+ ": "+Math.round(pr1);
		pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
		if(pid != "null") {
			document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
		}
	};

	// These functions are caught by the feeder object of the player.
	function loadFile(obj) { thisMovie("mpl").loadFile(obj); };
	function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); }
	function removeItem(idx) { thisMovie("mpl").removeItem(idx); }
	function getItemData(idx) {
		var obj = thisMovie("mpl").itemData(idx);
		var nodes = "";
		for(var i in obj) { 
			nodes += "<li>"+i+": "+obj[i]+"</li>"; 
		}
		
	};

	// This is a javascript handler for the player and is always needed.
	function thisMovie(movieName) {
	    if(navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	};

function newWindow(mypage,myname,w,h,features) {
  if(screen.width){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  }else{winl = 0;wint =0;}
  if (winl < 0) winl = 0;
  if (wint < 0) wint = 0;
  var settings = 'height=' + h + ',';
  settings += 'width=' + w + ',';
  settings += 'top=' + wint + ',';
  settings += 'left=' + winl + ',';
  settings += features;
  win = window.open(mypage,myname,settings);
  win.window.focus();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function OpenWindow(url,name,width,height,align,valign) 
{
    var option = "width="+width+",height="+height;
    var x="",y="";
    
    if (align=="center") x=(screen.width-width)/2
    else if (align=="left") x=0;
    else if (align=="right") x=(screen.width-width);

    if (valign=="center") y=(screen.height-height)/2
    else if (valign=="top") y=0;
    else if (valign=="bottom") y=(screen.height-height);

    option+=",left="+x+",top="+y;

    var win = window.open(url,name,option);
 
    focus();
    win.focus();
}


// skript za drop down glavni meni

function sfHoverEvents(ulid) {
	var sfEls = document.getElementById(ulid).getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(" sfhover", "");
		}
	}
}
function sfHover() {
	if (document.getElementById('menu')) {
 	 sfHoverEvents('menu');
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


// skript za Zebra Tables 

var Event = {
	add: function(obj,type,fn) {
		if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn](window.event); }
			obj.attachEvent('on'+type,obj[type+fn]);
		} else
		obj.addEventListener(type,fn,false);
	},
	remove: function(obj,type,fn) {
		if (obj.detachEvent) {
			obj.detachEvent('on'+type,obj[type+fn]);
			obj[type+fn] = null;
		} else
		obj.removeEventListener(type,fn,false);
	}
}

function getElement() {
	var elements = new Array();
	for (var i=0;i<arguments.length;i++) {
		var element = arguments[i];
		if (typeof element == 'string') element = document.getElementById(element);
		if (arguments.length == 1) return element;
		elements.push(element);
	}
	return elements;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+getElement/,"");
}

function addClassName(el,className) {
	removeClassName(el,className);
	el.className = (el.className + " " + className).trim();
}

function removeClassName(el,className) {
	el.className = el.className.replace(className,"").trim();
}

var ZebraTable = {
	bgcolor: '',
	classname: '',
	stripe: function(el) {
		if (!getElement(el)) return;
		var rows = getElement(el).getElementsByTagName('tr');
		for (var i=1,len=rows.length;i<len;i++) {
			if (i % 2 == 0) rows[i].className = 'alt';
			Event.add(rows[i],'mouseover',function() { ZebraTable.mouseover(this); });
			Event.add(rows[i],'mouseout',function() { ZebraTable.mouseout(this); });
		}
	},
	mouseover: function(row) {
		this.bgcolor = row.style.backgroundColor;
		this.classname = row.className;
		addClassName(row,'over');
	},
	mouseout: function(row) {
		removeClassName(row,'over');
		addClassName(row,this.classname);
		row.style.backgroundColor = this.bgcolor;
	}
}

window.onload = function() {
	ZebraTable.stripe('cenik');
	ZebraTable.stripe('oprema');
	ZebraTable.stripe('newslist-izpis');
}
