//identify browser engine
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie    = /MSIE/.test(navigator.userAgent);





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;
}


function flash(id,file,w,h)
{

    var container=document.getElementById(id);
    var html='<object type="application/x-shockwave-flash" data="'+file+'" width="'+w+'" height="'+h+'"><param name="movie" value="'+file+'" /></object>';
    container.innerHTML=html;
}




//check extension
function check_ext(elm,ext)
{
    var inp = elm;
    //var inp2 = document.getElementByName(id);
    var string = inp.value;
    
    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="";
        }
        
    }
}

//insert into textarea
function insertInForm(myField,c1,c2)
{
    if(is_ie)
    {
        var element=myField;
        //myField.focus();

        if(document.selection)
        {
          // The current selection
          var range = document.selection.createRange();

          // We'll use this as a 'dummy'
          var stored_range = range.duplicate();

          // Select all text
          stored_range.moveToElementText( element );

          // Now move 'dummy' end point to end point of original range
          stored_range.setEndPoint( 'EndToEnd', range );

          // Now we can calculate start and end points
          element.selectionStart =stored_range.text.length - range.text.length;
          element.selectionEnd = element.selectionStart + range.text.length;
        }
    }

    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;

    var hl=myField.value.substring(startPos, endPos);

    if(hl!='')
        myField.value = myField.value.substring(0, startPos)+c1+hl+c2+ myField.value.substring(endPos, myField.value.length);
    else
    {
        alert('Ozna\u010Dite tekst!');
    }

}
    
//confirm delete
function confirmLink(theLink, message)
{
    if (message == '' || typeof(window.opera) != 'undefined')
    {
        return true;
    }

    var is_confirmed = confirm(message);
    /*if (is_confirmed)
    {
        theLink.href += '&is_js_confirmed=1';
    }*/

    return is_confirmed;
}

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="";
  }
}


