﻿//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;
}



//submit once
function show_gallery(id,file)
{
    var container=document.getElementById(id);
    var html;
    
    if(file!='')
        html='<br /><center><img src="'+file+'" alt=""/><br />&nbsp;</center><div align="right"><img src="images/icons/delete.gif" alt=""/><a class="red1" href="javascript:show_gallery(\'gallery\',\'\')">Zapri galerijo</a></div>';
    else
        html='';

    container.innerHTML=html;
}


//submit once
function submitonce(theform)
{
    //if IE 4+ or NS 6+
    if (document.all||document.getElementById)
    {
        //screen thru every element in the form, and hunt down "submit" and
        "reset"
        for (i=0;i<theform.length;i++)
        {
            var tempobj=theform.elements[i]
            if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
            //disable em
            tempobj.disabled=true
        }
    }
}

//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="";
        }
        
    }
}

//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;
}
 
//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;
    }
}

//insert link
function insert_link(frm)
{
    var e = eval('document.'+frm);

    var url_link = prompt("Vpiši URL povezave: ","http://");
    var url_name = prompt("Vpiši ime povezave: ","");
    if ((url_link != "")&&(url_link != null))
    {
        if((url_name == "")||(url_name == null))
            url_name=url_link;
        var valu = "[url=\""+url_link+"\"]"+url_name+"[/url]";
        insertAtCursor(e,valu);
        //e.value=valu;

    }
}

//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)-20;
        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);
}
      



function show(sel,id)
{
    var ni = document.getElementById(id);
    var content='<object type="application/x-shockwave-flash" data="'+sel+'" width="320" height="240"><param name="movie" value="'+sel+'" /></object>';
    ni.innerHTML = content;
    
    
}

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 = "";
	  	}
}

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 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 toggleStyle(id)
{
    var object=document.getElementById('l'+id);
	/*if(object.style.fontWeight=='bold')
    {
    	object.style.fontWeight='';
    	object.style.fontFamily='verdana';
	}
	else*/
    {
    	//alert(pnav);
    	//var tmp=document.getElementById('l'+pnav);
    	//tmp.style.fontWeight='';
    	//tmp.style.fontFamily='verdana';
    	//hideLayer('c'+pnav);
    	//pnav=id;
    	for(ii=0;ii<1000;ii++)
    	{
    		var tmp=document.getElementById('l'+ii);
    		if(tmp)
    		{
    			tmp.style.fontWeight='';
    			tmp.style.fontFamily='verdana';
    			//hideLayer('c'+ii);
    		}
    	}
    	object.style.fontWeight='bold';
    	object.style.fontFamily='trebuchet ms';
    	//showLayer('c'+id);
		    	
	}
}

function toggleImage(element,img1,img2)
{
	//alert(element);
	if(element!='[object HTMLImageElement]')
    	var element=document.getElementById(id);
    	
	if(element.src.indexOf(img1)==-1)
    {
    	element.src=img1;
	}
	else
    {
    	element.src=img2;
	}
}

//submit once
function changeOrder(ac,id1,id2)
{
    var container=document.getElementById(id);
    var html;
    
    if(file!='')
        html='<br /><center><img src="'+file+'" alt=""/><br />&nbsp;</center><div align="right"><img src="images/icons/delete.gif" alt=""/><a class="red1" href="javascript:show_gallery(\'gallery\',\'\')">Zapri galerijo</a></div>';
    else
        html='';

    container.innerHTML=html;
}



