function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(switchImg);

function switchImg(){
    if (!document.getElementById) return false;
	if (!document.getElementById("majstorMenu")) return false;    
	div = document.getElementById("majstorMenu");
     
    var links = div.getElementsByTagName("a");
    for (i = 0; i < links.length; i++) {
        var link = links[i];
        link.onmouseover = function(){
            hoverImg(this);
        }
        link.onmouseout = function(){
            eraseImg(this);
        }
    } 
}

function hoverImg(which){
    var text = which.lastChild.nodeValue;
    var img = document.getElementById("slika");
    imgSource = img.getAttribute("src");
    img.setAttribute("src", which.rel);
    paraf = document.getElementById("naslovKategorije");
    
    var newText = document.createTextNode(text);
    paraf.appendChild(newText);
}

function eraseImg(which){
    var img = document.getElementById("slika");
    img.setAttribute("src", imgSource);
    paraf.lastChild.nodeValue = "";
    
}

function checkForm() {
	var ok = true;
	if( !submitted ) return ok;
	$( "table.forma .error" ).removeClass( "error" );
	$( "table.forma .obavezno").each( function()
	{
		if( $( this ).val() == "" ) {
			$( this ).parents( "tr" ).addClass( "error" );
			ok = false;
		}
	} );

	if( ok ) $( "#upute" ).hide(); else $( "#upute" ).show();
	return ok;
}


var submitted = false;

$( function() {
	$( "form" ).submit( function(evt) {
		submitted = true;
		if( ! checkForm() ) evt.preventDefault();
	} );
	$( "table.forma input.obavezno" ).change( checkForm );
} );

function shdivs( s ) {
	if( !document.getElementById ) return;
	s = document.getElementById( s );
	if( s ) s.style.display = "block";
	for( var i=1; i<arguments.length; i++ ) {
		s = document.getElementById( arguments[ i ] );
		if( s ) s.style.display = "none";
	};
}

//step-by-step
$(document).ready(function() {
        $('ul.tabs li.step1 a').addClass('tabActive'); 
        $('ul.tabs li a').click(function() {
            $('ul.tabs li a').removeClass('tabActive');
            $(this).addClass('tabActive');
        });
    });

