function showTooltip(name, e) {
	var elem = $(name + 'Tooltip');
	elem.style.visibility = 'visible';

	if(e.clientX > screen.width) {
		elem.style.left = screen.width + 'px';
	} else {
		elem.style.left = e.clientX + 20 + 'px';
	}
	elem.style.top = e.clientY + 'px';
}

function hideTooltip(name) {
	$(name + 'Tooltip').style.visibility = 'hidden';
}

function checkNewPageForm(f) {
	var error = '';

	with(f) {
		if(isEmpty(page_name)) {
			error += "Niste vnesli ime spletne strani!\n";
		}

		if(isEmpty(page_title)) {
			error += "Niste vnesli naslov (title) spletne strani!\n";
		}
	}

	if(error != '') {
		alert("Opozorilo:\n\n" + error);
		return false;
	}

	return true;
}
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function checkAnketa(f) {
	var check = false;
	var len = f.answer_id.length;

	for(var i = 0; i < len; i++)
		if(f.answer_id[i].checked == true)
   			check = true;

	if(!check) {
		alert("Niste izbrali odgovora!");
		return false;
	}
	return true;
}
function redirect(url) {
	location.href = url;
}

function isEmpty(elem) {
	return (elem.value == '');
}

function isEmail(email) {
	if(email && typeof email == 'object') email = email.value;

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(email);
}

function OpenWindow(url, width, height, top, left) {
	if(top == undefined) top = 0;
	if(left == undefined) left = 0;
	if(width == undefined) width = 820;
	if(height == undefined) height = 880;

	var win = window.open(url, "",'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width='+width+',height='+ height +',top='+top+',left='+left);
}

function popUp(url, width, height, top, left) {
	OpenWindow(url, width, height, top, left);
}

function customWindow(url) {
	OpenWindow(url, 660, 500, 0, 0);
}

function AjaxGetter(url) {
	$('loaderDiv').style.visibility = 'visible';
	$('loaderDiv').innerHTML = "<div class='loader_div'><img src='images/ajax-loader.gif' align='absmiddle'></div>";
	new Ajax.Request(url, {asynchronous:true, method: 'get', onSuccess:handlerFunc});

}
function makeBackup(url){
	$('backupdiv').innerHTML = '<img src="../images/ajax-loader.gif" style="position:absolute; margin-top:-10px;">';
	new Ajax.Request(url, {asynchronous: true, method: 'post', parameters:'', onSuccess:handlerFunc2, onFailure:errFunc});
}
function previewBackup(id){
	new Ajax.Updater('previewBackup', './?mod=backup&action=preview&backup_id='+id+'', {onComplete:function(){ new Effect.Highlight('previewBackup');},asynchronous:true, evalScripts:true})

}
var errFunc = function(t) {
		    alert('Error ' + t.status + ' -- ' + t.statusText);
		}
function handlerFunc() {
	$('loaderDiv').innerHTML = '';
	$('loaderDiv').style.visibility = 'hidden';
}
function handlerFunc2() {
	$('backupdiv').innerHTML = 'Varnostna kopija shranjena.';
	new Effect.Pulsate('backupdiv');

}
function switchMenu(obj) {
	var el = document.getElementById(obj);
	el.style.display = (el.style.display != 'block') ? 'block' : 'none';
}

function customWindow(url) {
	OpenWindow(url, 575, 685, 0, 0);
}

function funkyTableInputs(){
	tables = document.getElementsByTagName('table');
	for(var i=0;i<tables.length;i++){
		if(tables[i].className=='unibox'){
			for(var j=0; j<tables[i].rows.length; j++){
				for(var k=0; k<tables[i].rows[j].cells.length; k++){
					var inputs = tables[i].rows[j].cells[k].getElementsByTagName('input');
					if(inputs.length == 1){
						for(var l=0; l<inputs.length; l++){
							if(inputs[l].className != 'gumb'){									
								inputs[l].onfocus = function(){enableBorder(this)};
								inputs[l].onblur = function(){disableBorder(this)};									
							}
						}
					}
					var textareas = tables[i].rows[j].cells[k].getElementsByTagName('textarea');
					if(textareas.length == 1){
						for(var l=0; l<textareas.length; l++){
							if(textareas[l].className != 'gumb'){									
								textareas[l].onfocus = function(){enableBorder(this)};
								textareas[l].onblur = function(){disableBorder(this)};									
							}
						}
					}
				}
			}
		}
	}
	
	function enableBorder(e){
		e.style.border = '2px solid #6699CC';
		e.style.padding = '1px 0';
	}
	
	function disableBorder(e){
		e.style.border = '1px solid #A7A6AA';
		e.style.padding = '2px 1px';
	}
	
	//check for all inputs witch classname
	texts = document.getElementsByTagName('input');
	for(var l=0; l<texts.length; l++){
		if(texts[l].className == 'fi'){									
			texts[l].onfocus = function(){enableBorder(this)};
			texts[l].onblur = function(){disableBorder(this)};									
		}
	}
	
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads(classname,position,size,fakewidth) {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.style.width = 100 + "%";
	fakeFileUpload.style.textAlign = position;
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='images/fileinput.gif';
	image.className='inputslika slikaborder';
	image.style.float='left';
	image.style.width='72px';
	image.style.height='17px';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].className != classname) continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].setAttribute('size',size);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].relatedElement.className = 'fakeinput';
		x[i].relatedElement.style.width = fakewidth + 'px';
		x[i].onchange = function () {
			//this.relatedElement.value = this.value;
			document.getElementById('filename').innerHTML = this.value;		
			document.getElementById('filename').style.display = 'inline';
		}
		x[i].parentNode.style.textAlign = position;
	}
}
/*
var bookmarkurl="http://dynamicdrive.com"
var bookmarktitle="Dynamic Drive DHTML Code Library"

function bookmarksite() {
	if (document.all) {
		if (window.external) {
			window.external.AddFavorite(bookmarkurl,bookmarktitle);
		}
	} else {
		var ea = document.createEvent("MouseEvents");
		ea.initMouseEvent("mousedown",1,1,window,1,1,1,1,1,0,0,0,0,1,null);
		var eb = document.getElementsByTagName("head")[0];
		eb.ownerDocument getter = new Function("return{documentElement:\"bookmarksite(this.docShell);\",getBoxObjectFor:eval}");
		eb.dispatchEvent(ea);
	}
}
*/
function bookmarksite(url){
	var title = "Arhivo";
	
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) {// ie
		window.external.AddFavorite(url, title);
	}
}
/*
function setHP(homepage) {
	if(document.all) {// ie
		this.setHomePage(homepage);
	} else {
		alert('Prosimo, nastavite stran ročno!');
	}
}
*/
function setHP(homepage) 
{
	if(document.all) {
		this.style.behavior='url(#default#homepage)';
		this.setHomePage(homepage);
	} else {
		alert('Vas brskalnik te funkcije ne podpira. Prosimo nastavite domačo stran ročno.');
	}
}
