function changeLanguage(lang)
{
	//alert(lang);
	//alert(window.location.pathname);
	var wl=window.location.pathname;
	wl=wl.substring(wl.lastIndexOf('/')+1);
	wl=wl.replace(/.html/i,"");
	if(wl=='')
	{
		var parts=new Array('home');
	}
	else
	{
		var parts=wl.split('-');
	}

	if(parts.length==3)
	{
		//replace lang
		window.location=parts[0]+'-'+parts[1]+'-'+lang+'.html';
	}
	else if(parts.length==2)
	{
		if(parts[1].match(/p[0-9]+/gi))
		{
			//add lang			
			window.location=parts[0]+'-'+parts[1]+'-'+lang+'.html';
		}
		else
		{
			//replace lang
			window.location=parts[0]+'-'+lang+'.html';
		}
	}
	else
	{
		window.location=parts[0]+'-'+lang+'.html';
	}
}

function changeNewsArchive(archive)
{
	if(archive=='')
	{
		return false;
	}
	
	window.location='news_archive-'+archive+'.html';
}

function setErrfields(form,fields)
{

	errfields_values=new Array();

	
	for(i=0;i<fields.length;i++)
	{
		
		var elm=$("form[name="+form+"] input[name="+fields[i]+"]");
		if(elm.val())
		{
			
		}
		else
		{
			var elm=$("form[name="+form+"] textarea[name="+fields[i]+"]");
		}
		

		
		
		errfields_values[fields[i]]=elm.val();
		
		elm.addClass('input_err');
		elm.focus(function()
		{
			$(this).removeClass('input_err');
		});
		
		elm.blur(function()
		{
			var elm=$(this);
			
			if(elm.val()==errfields_values[elm.attr("name")])
			{
				elm.addClass('input_err');
			}
		});
	}
}

function errField(elm,ac)
{
	if(ac=='set')
	{
		$(elm).addClass('input_err');
		$(elm).focus(function ()
		{
         errField(elm,'clear');
    	});
	}
	else
		$(elm).removeClass('input_err');
}

function toggleValue(variable)
{
	$.ajax({
	type: "POST",
	url: 'toggle.php',
	data: 'variable='+variable,
	success: function(rsp){
			//alert(rsp);
	}
	});
}

function toggleRow(id)
{
	$('#'+id+'Layer').slideToggle();
	toggleValue(id);
	toggleImage(id+'Img','images/icons/ico_minus.png','images/icons/ico_plus.png','','');
}


function toggleImage(id,img1,img2,title1,title2)
{
	var elm=document.getElementById(id);
	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;
	}
	
}

//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="";
        }
        
    }
}


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="";
  }
}



