//identify browser engine
//var is_gecko = /gecko/i.test(navigator.userAgent);
//var is_ie    = /MSIE/.test(navigator.userAgent);

//submit form on Ctrl + S press
function CtrlS(elm,event) {
    if (!(event.which == 115 && event.ctrlKey)) return true;  
    event.preventDefault();
    elm.submit();
    return false;
}

//insert into textarea
function insertAtCursor(myField, myValue)
{
    if (document.selection)
    {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    }
    else if (myField.selectionStart || myField.selectionStart == '0')
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
    }
    else
    {
        myField.value += myValue;
    }
}

function set_checkboxes(class_name)
{	
	var all = document.all ? document.all:document.getElementsByTagName('*');
	for (var i = 0; i < all.length; i++)
		if(all[i].className == class_name)
		{
				all[i].checked='checked';					
		}	
}

function clear_checkboxes(class_name)
{	
	var all = document.all ? document.all:document.getElementsByTagName('*');
	for (var i = 0; i < all.length; i++)
		if(all[i].className == class_name)
		{
				all[i].checked='';					
		}	
}


function CountLeft(field, count, max)
{
    // if the length of the string in the input field is greater than the max value, trim it
    if (field.value.length > max)
        field.value = field.value.substring(0, max);
    else
    // calculate the remaining characters
        count.value = max - field.value.length;
}


//check extension
function check_ext(elm,ext)
{
    var inp = elm;
    //var inp2 = document.getElementByName(id);
    var string = inp.value;
    
    //alert(string);
    
    if(string!='')
    {

        var temp = new Array();
        temp = string.split('.');
        var file_ext=temp[temp.length-1].toLowerCase();
        

        var exts = new Array();
        exts = ext.split('-');
        
        
        var f=false;
        var ext_s='';

        for(var i=0;i<exts.length;i++)
        {
            if(file_ext==exts[i])
            {
                f=true;
            }
            if(i==0)
                ext_s+='"'+exts[i]+'"';
            else
                ext_s+=', "'+exts[i]+'"';
        }
        
        if(f===false)
        {
            alert('Napačen tip datoteke! Izberete lahko le datoteke s končnico '+ext_s+'.');
            inp.value="";
        }
        
    }
}

function toggleImage(elm,img1,img2,title1,title2)
{
	var loc=window.location+'';
	loc=loc.substr(0,loc.lastIndexOf("/")+1);
	
	if(elm.src==loc+img1)
	{
		elm.src=img2;
		elm.title=title2;
	}
	else
	{
		elm.src=img1;
		elm.title=title1;
	}
	
}

function toggleLayer(whichLayer)
{
    if (document.getElementById)
    {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display = style2.display? "":"none";
    }
    else if (document.all)
    {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display = style2.display? "":"none";
    }
    else if (document.layers)
    {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display = style2.display? "":"block";
  }
}

function hideLayer(whichLayer)
{
    if(document.getElementById)
    {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display="none";
    }
    else if (document.all)
    {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display="none";
    }
    else if (document.layers)
    {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display="block";
  }
}

function showLayer(whichLayer)
{
    if(document.getElementById)
    {
    // this is the way the standards work
    var style2 = document.getElementById(whichLayer).style;
    style2.display="";
    }
    else if (document.all)
    {
    // this is the way old msie versions work
    var style2 = document.all[whichLayer].style;
    style2.display="";
    }
    else if (document.layers)
    {
    // this is the way nn4 works
    var style2 = document.layers[whichLayer].style;
    style2.display="";
  }
}
