//identify browser engine
//var is_gecko = /gecko/i.test(navigator.userAgent);
//var is_ie    = /MSIE/.test(navigator.userAgent);


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;
}



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(id,ext)
{
    var inp = document.getElementById(id);
    //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="";
        }
        
    }
}
    
//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;
}
 

//show image from gallery
function showImage_r(i,file,w,h)
{
        var w_w=w+25;
        var w_h=h+30;

        var w_t=Math.floor((screen.height-w_h)/2)-50;
        var w_l=Math.floor((screen.width-w_w)/2);

        myWin=open("showpic.php?i="+i+"&image="+file+"&w="+w+"&h="+h, "displayWindow", "width="+w_w+",  height="+w_h+", resizable=yes, scrollbars=yes, directories=no, location=no, left="+w_l+",top="+w_t);
}


//show image in div with dimmed bg
function showImage(i,file,w,h)
{
        var w_w=w;
        var w_h=h;
        
        //alert(screen.height);

        var w_t=Math.floor((screen.height-w_h)/2)-100;
        var w_l=Math.floor((screen.width-w_w)/2);
        //alert

        //document.write('<div><img src="'+file+'"></div>');
        var wrap=document.getElementById('showImage');
        var dim=document.getElementById('dim');
        wrap.style.top=w_t+'px';
        wrap.style.left=w_l+'px';
        //filter:alpha(opacity=25);-moz-opacity:.25;opacity:.25;
        dim.innerHTML='<div style="width:'+screen.width+'px;height:'+screen.height+'px;background-color:black;filter:alpha(opacity=50);-moz-opacity:.50;opacity:.50;"></div>';
        wrap.innerHTML='<div style=""><a href="javascript:hideLayer(\'dim\');hideLayer(\'showImage\');"><img src="'+file+'" title="Zapri sliko"/></a><br /><a href="javascript:hideLayer(\'dim\');hideLayer(\'showImage\');"><img src="images/icons/delete.gif" /></a> <a href="javascript:hideLayer(\'dim\');hideLayer(\'showImage\');"><b class="black">Zapri sliko</b></a></div>';
    
        showLayer('dim');
        showLayer('showImage');
}

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="";
  }
}


