function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function loadURL(page){

  location.href = page.options[page.selectedIndex].value

}

function hideAll(){
  divs = document.getElementsByTagName('DIV');
  for (i=0;i<divs.length;i++) {
    if (divs[i].id.indexOf('SEL_')!=-1) divs[i].style.display = 'none'
  }
}

function show(id){
  hideAll();
  document.getElementById(id).style.display='';
}

function checkForm(frm){
	
	var oForm = document.getElementById(frm); 
		
			var text1 = "korisničko ime";
			var text2 = "lozinku";
			var text3 = "Molimo Vas da upišete sljedeće podatke:";
	
	var correct = true
	var error = "";
	if (oForm.hjvgdfjhgv.value.length <1){
		error += "\n - " + text1;
	}
	if (oForm.vgrebgfdbdf.value.length <1){
		error += "\n - " + text2;
	}
	if (error != ""){
		alert(text3 + error);
		return false;
	}
	return true;
}

function setDefaultUsername(el) {
	
	var userField = document.getElementById("hjvgdfjhgv");
	var pwdField = document.getElementById("vgrebgfdbdf");
	
	if (userField.value == 'korisničko ime') userField.value='';
			
}

function clearText(field){

    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}

function checkSearchForm(){

	var field = document.getElementById("q");
	
    if ((field.defaultValue == field.value) || (field.value.length <2)) {
    	
    	alert("GREŠKA: Pojam ne smije biti kraći od 4 znaka!");
    	return false;
    }
    else {
    	return true;
    }
	
}

function submitSearch(){

	var frm = document.getElementById("srch_form");
	var field = document.getElementById("q");
	
    if (field.defaultValue == field.value) {
    	
    	alert("GREŠKA: Nije unesen pojam!");
    	
    }
    else if (field.value.length <4) {
    	
    	alert("GREŠKA: Pojam ne smije biti kraći od 4 znaka!");
    	
    }
    else {
    	
    	frm.submit();
    }
	
}

function setPwdField(field){

    if ((field.defaultValue == field.value) && (field.type == 'text')) {
    	
    	field.value = '';
    	field.type='password';
    	field.focus();
    }
    else if ((field.value == '') && (field.type == 'password')) {
    	
    	field.type='text';
    	field.value = field.defaultValue;
    	
    }
}

Array.prototype.max = function() {
	var max = this[0];
	var len = this.length;
	for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
	return max;
}


function allocateSidebarHeight() {
	
	var sidebarDom = document.getElementById("side_content");
	var contentDom = document.getElementById("center_content");	
	var rightDom = document.getElementById("right_content");
	
	var sidebarDom_height = sidebarDom.offsetHeight;
	var contentDom_height = contentDom.offsetHeight;	
	var rightDom_height = rightDom.offsetHeight;
	
	array = [sidebarDom_height, contentDom_height, rightDom_height];
	
	max = array.max();
	sidebarDom.style.height = (max ) +"px";
	contentDom.style.height = (max ) +"px";
	rightDom.style.height = (max ) +"px";
	
	/*
	//content big
	if((contentDom.offsetHeight-800) > sidebarDom.offsetHeight) {
		sidebarDom.style.height = (contentDom.offsetHeight-800)+"px"; 
	}
	if((contentDom.offsetHeight-800) > rightDom.offsetHeight) {
		rightDom.style.height = (contentDom.offsetHeight-800)+"px"; 
		
	}
	
	//sidebar big
	if((sidebarDom.offsetHeight-800) > contentDom.offsetHeight) {
		contentDom.style.height = (sidebarDom.offsetHeight-800)+"px"; 
	}
	
	if((sidebarDom.offsetHeight-800) > rightDom.offsetHeight) {
		rightDom.style.height = (sidebarDom.offsetHeight-800)+"px"; 
		
	}
	
	//rightbar big
	if((rightDom.offsetHeight-800) > sidebarDom.offsetHeight) {
		sidebarDom.style.height = (rightDom.offsetHeight-800)+"px"; 
	}
	
	if((rightDom.offsetHeight-800) > contentDom.offsetHeight) {
		contentDom.style.height = (rightDom.offsetHeight-800)+"px"; 
		
	}
	*/
	
}

	startList = function() {
		
		if (document.all&&document.getElementById) {
			
			
			if (document.getElementById("browser")) {	
				navRoot = document.getElementById("browser");
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
						if (node.nodeName=="LI") {
							node.onmouseover=function() { this.className+=" over"; }
							node.onmouseout=function() { this.className=this.className.replace(" over", ""); } 
					} 
				}
			}	
		
			if (document.getElementById("newsArchive")) {	
				navRoot = document.getElementById("newsArchive");
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
						if (node.nodeName=="LI") {
							node.onmouseover=function() { this.className+=" over"; }
							node.onmouseout=function() { this.className=this.className.replace(" over", ""); } 
					} 
				}
			}
			
			if (document.getElementById("linkovi")) {
				navRoot = document.getElementById("linkovi");
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
						if (node.nodeName=="LI") {
							node.onmouseover=function() { this.className+=" over"; }
							node.onmouseout=function() { this.className=this.className.replace(" over", ""); } 
					} 
				}
			}
			if (document.getElementById("galerije")) {
				navRoot = document.getElementById("galerije");
				for (i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
						if (node.nodeName=="LI") {
							node.onmouseover=function() { this.className+=" over"; }
							node.onmouseout=function() { this.className=this.className.replace(" over", ""); } 
					} 
				}
			}
		}
		allocateSidebarHeight(); 
	}

	window.onload=startList;

