// 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];
		}
	};


// Funkcije za forme

//Javascript preprecuje vpis cifer v polji za drzavo in kraj

function doClick(event){
	    var keychar;
        var numcheck;
        var key = null;

        if (window.event){
            key = window.event.keyCode; // RM270202007 IE support
        }else{
            key = event.which; // RM270202007 Firefox support
        }

        key = key-48;


        if (key != 0 && key !== 1 && key != 2 && key != 3 && key != 4 && key != 5 && key != 6 && key != 7 && key != 8 && key != 9){
            return true;
        }

        return false;
    }

// Dovoli vpisati samo stevilke v polje

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
	key = window.event.keyCode;
	else if (e)
	key = e.which;
	else
	return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) ||
	(key==9) || (key==13) || (key==27) || (key==46) || (key==39) || (key==37))
	return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	return true;

	// decimal point jump
	else if (dec && (keychar == "."))
	{
		myfield.form.elements[dec].focus();
		return false;
	} else if (key == 96 || key == 97 || key == 98 || key == 99 || key == 100 || key == 101 || key == 102 || key == 103 || key == 104 || key == 105) {
		return true;
	}
	else {
		return false;
	}

}




/**
    Miscellaneous utilities
*/

function $(id) { return document.getElementById(id); }

// See: http://www.joehewitt.com/software/firebug/faq.php
function printfire() {
    /*
    if (document.createEvent) {
        printfire.args = arguments;
        var ev = document.createEvent("Events");
        ev.initEvent("printfire", false, true);
        dispatchEvent(ev);
    }
    */
}

// See: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

// See: http://ejohn.org/projects/flexible-javascript-events/
function addEvent( 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 );
}
function removeEvent( obj, type, fn ) {
    if ( obj.detachEvent ) {
        obj.detachEvent( 'on'+type, obj[type+fn] );
        obj[type+fn] = null;
    } else
        obj.removeEventListener( type, fn, false );
}

/*
    Mini MochiKit
*/

function forEach(list, fn) {
    for (var i=0; i<list.length; i++) fn(list[i]);
}

function filter(fn, list) {
    var rv = [];
    for (var i=0; i<list.length; i++)
        if (fn(list[i]))
            rv[rv.length] = list[i];
    return rv;
}

function map(fn, list) {
    var rv = [];
    for (var i=0; i<list.length; i++) rv[rv.length] = fn(list[i]);
    return rv;
}

function appendChildNodes(parent, nodes) {
    for (var i=0; i<nodes.length; i++) {
        var node = nodes[i];
        if (node.nodeType)
            parent.appendChild(node);
        else if ( (typeof(node) == 'object') && node.length)
            appendChildNodes(parent, node);
        else
            parent.appendChild(document.createTextNode(''+node));
    }
}

function createDOM(name, attrs, nodes) {
    var elem = document.createElement(name);
    if (attrs) for (k in attrs) {
        elem.setAttribute(k, attrs[k]);
        switch(k) {
            // MSIE seems to want this.
            case 'class': elem.className = attrs[k]; break;
        }
    }
    if (nodes) appendChildNodes(elem, nodes);
    return elem;
}

function createDOMFunc(name) {
    return function(attrs) {
        var nodes = [];
        for (var i=1; i<arguments.length; i++)
            nodes[nodes.length] = arguments[i];
        return createDOM(name, attrs, nodes);
    }
}

forEach([
    'A', 'BUTTON', 'BR', 'CANVAS', 'DIV', 'FIELDSET', 'FORM',
    'H1', 'H2', 'H3', 'HR', 'IMG', 'INPUT', 'LABEL', 'LEGEND', 'LI', 'OL',
    'OPTGROUP', 'OPTION', 'P', 'PRE', 'SELECT', 'SPAN', 'STRONG', 'TABLE', 'TBODY',
    'TD', 'TEXTAREA', 'TFOOT', 'TH', 'THEAD', 'TR', 'TT', 'UL'
    ], function(n) { window[n] = createDOMFunc(n); });



// Scripts for 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 $() {
	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+$/,"");
}

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 (!$(el)) return;
		var rows = $(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('basic-table');
	ZebraTable.stripe('equipment');
}
