function submitenter(myfield,e,type)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   if (type == 2)
   {
      document.login_form_content.submit();
   }
   if (type == 1)
   {
      document.login_form.submit();
   }
   return false;
   }
else
   return true;
}
  function write_swf(filename,id,width,height,extra) {
	document.write('<object type="application/x-shockwave-flash" data="'+filename+(id!=null?'?cid='+id:'')+'" width="'+width+'" height="'+height+'">');
	document.write('<param name="movie" value="'+filename+(id!=null?'?cid='+id:'')+'" />');
	
	document.write('<param name="quality" value="autohigh" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="menu" value="false" />');
	
	
	embedvars = '';
	
	for (i in extra) {
			document.write('<param name="'+extra[i][0]+'" value="'+extra[i][1]+'" />');
			embedvars += ' '+extra[i][0]+'="'+extra[i][1]+'"';
	}
	document.write('<embed name="simplemovie" src="'+filename+'" quality="high" wmode="transparent" swliveconnect="true" width="'+width+'" height="'+height+'" '+embedvars+' name="'+filename+'" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" />');
	
	document.write('</object>');
}

/*
* PROTOTYPES for IE and other older browsers
*/
// in array function
function inArray(needle, haystack) {
	for (h in haystack) {
		if (haystack[h] == needle) {
			return true;
		}
	}
	return false;
}
// indexOf function
if (!Array.prototype.indexOf) {
  Array.prototype.indexOf = function(elt /*, from*/) {
    var len = this.length;
    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++) {
      if (from in this && this[from] === elt)
	  return from;
    }
    return -1;
  };
} 

/* toggle font / line size */
/* set cookie */
//function setCookie(name, value, expires, path, domain, secure) {
function setCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/* get cookie */
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/* delete cookie */
function deleteCookie( name, path, domain ) {
	if ( getCookie(name) ) 
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

var text_sizes		= [12, 14, 16];
var line_heights	= [1.4, 1.6, 1.8];

var def_text_size = 0;
var def_line_height = 0;

var current_lh = false;
var current_ts = false;

var first_page = false;

var content_placeholder = 'middleblock';

function change_line_height() {

	if (!current_lh)
	current_lh = getCookie('line_height');

	if (!current_lh) current_lh = def_line_height;
	current_lh ++;
	if (current_lh == line_heights.length) current_lh = 0;

	setCookie('line_height', current_lh, 365);
	if (first_page) {
		document.getElementById('push_news').style.lineHeight = line_heights[current_lh] + "em";
		document.getElementById('push_strokovnjak').style.lineHeight = line_heights[current_lh] + "em";
	} else {
		document.getElementById('middleblock').style.lineHeight = line_heights[current_lh] + "em";
	}
}

function change_text_size() {
	if (!current_ts)
		current_ts = getCookie('text_size');
	if (!current_ts) current_ts = def_text_size;
	current_ts ++;
	if (current_ts == text_sizes.length) current_ts = 0;
	setCookie('text_size', current_ts, 365);
	if (first_page) {
		document.getElementById('push_news').style.fontSize = text_sizes[current_ts] + "px";
		document.getElementById('push_strokovnjak').style.fontSize = text_sizes[current_ts] + "px";
	} else {
		document.getElementById('middleblock').style.fontSize = text_sizes[current_ts] + "px";
	}
}

/* returns the x,y coordinates of the current screen (for multi monitor setup) */
function get_top_left(width, height){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
	  		winW = window.innerWidth;
	  		winH = window.innerHeight;
	 		winL = window.screenX;
	 		winT = window.screenY;
	 	} else {
	  		winW = document.body.offsetWidth;
	  		winH = document.body.offsetHeight;
	  		winL = window.screenLeft;
	  		winT = window.screenTop;
	 	}
	}
	
	var scroll = 0;
	var l = winL + winW/2 - width/2;
	var t = winT + winH/2 - height/2;
	
	
  	if(screen.width <= width){
  		width=screen.width;
  	}
  	if(screen.height <= height){
  		height=screen.height;
 	 	var t = 0;
  		var scroll = 1;
  	}
	return Array(t,l);
}


/* generic window opener */
function openwin(uri,title,w,h){
	if(w){wwidth = w;}else{	wwidth = 380;}
	if(h){wheight = h; }else{ wheight = 380;}
	xy = get_top_left(wwidth, wheight);
	wleft = xy[1];
	wtop = xy[0];
	wnd = window.open(uri, title, "width="+wwidth+", height="+wheight+", left="+wleft+", top="+wtop+", toolbar=no, location=no, scrollbars=yes, status=no, menubar=no, resizable=no, directories=no");
}

//Moj_profil form script
function check_myprofile_form(obj){

	var errTxt="";
	var ok=true;


	if(obj.Email.value=='') {
		errTxt+='Polja z zvezdico so obvezna. \n';
		ok=false;
	}
	if (!is_valid_email(obj.Email.value)) {
		errTxt+='Nepravilen e-mail naslov \n';
		ok=false;
	}
	if (!is_valid_email(obj.RepeatEmail.value) && obj.RepeatEmail.value != '') {
		errTxt+='Nepravilna Potrditev e-mail naslova \n';
		ok=false;
	}
	if(ok) {
		return true;
	} else {
		alert(errTxt);
		return false;
	}
}

function is_valid_email(str){

	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(str)) valid = true;
	else valid = false;

	return valid;

}


function check_avatar_field(obj){
	var errTxt="";
	var ok=true;
	
	if(obj.file.value=='') {
		errTxt+='Izbrati morate datoteko, ki jo �elite nalo�iti na stre�nik. \n';
		ok=false;
	}
	
	if(ok) {
		return true;
	} else {
		alert(errTxt);
		return false;
	}
	
}
// End of Moj_profil form script

// add / edit post form check
var image_upload = false;
var file_upload = false;

function check_post_form(obj_frm) {

	if  (image_upload) return true;
	if  (file_upload) return true;

	var check_form = $(obj_frm);
	var error = Array();
	var error_msg = "Izpolniti je potrebno polja z zvezdicami:\n";
	
	check_form.find(".required").each(function() {
		if ($(this).val() == '') {
			txt = $('label[for=' + $(this).attr('id') + ']').text();
			error.push("- " + txt + "\n");
		}
	});
	
	if (error.length) {
		for (i=0; i< error.length; i++)
			error_msg += error[i];
			
		alert(error_msg);
		
		return false;
	} else {
		return true;
	}

}


function check_img_field(obj){
	
	var errTxt="";
	var ok=true;
	
	if(obj.file.value=='') {
		errTxt+='Izbrati morate datoteko, ki jo �elite nalo�iti na stre�nik. \n';
		ok=false;
	}
	
	if(ok) {
		return true;
	} else {
		alert(errTxt);
		return false;
	}
	
}

function check_file_field(obj){
	var errTxt="";
	var ok=true;
	
	if(obj.file1.value=='') {
		errTxt+='Izbrati morate datoteko, ki jo �elite nalo�iti na stre�nik. \n';
		ok=false;
	}
	
	if(ok) {
		return true;
	} else {
		alert(errTxt);
		return false;
	}
	
}


//Change images
function change_image(pic) {
	var curr_big_pic = $('#big_pic').attr('src');
	var curr_big_rel = $('#big_gal_link').attr('rel');
	var curr_small_pic = $('#pic' + pic).attr('src');
	var curr_small_rel = $('#small_gal_link' + pic).attr('rel');
	var big_img_repl = curr_small_pic.replace(/th1_/, "gal1_")
	var small_img_repl = curr_big_pic.replace(/gal1_/, "th1_")
	$('#pic' + pic).attr('src', small_img_repl);
	$('#big_pic').attr('src', big_img_repl);
	$('#big_gal_link').attr('rel', curr_small_rel);
	$('#small_gal_link' + pic).attr('rel', curr_big_rel);
}



function show_div(id) {
	
	$("#archive-docs-"+id).toggleClass("hidden");
	
}

	
function show_video_file(videofile,previewfile,sizex,sizey,autoplay,fullscr) {
	
	auto_play = false;
	full_screen = false;
	if (autoplay != null && autoplay != false){
		auto_play = true;
	}
	if (fullscr != null){
		full_screen = true;
	}
	var vars = {
		width:sizex,
		height:sizey,
		file:videofile,
		image:previewfile,
		fullscreen:full_screen,
		javascriptid:'video',
		enablejs:'true',
		backcolor:'fc0000',
		frontcolor:'FFFFFF',
		lightcolor:'FFFFFF',
		screencolor:'000000',
		autostart:auto_play,
		controlbar:'over'
	};
	
	var params = {
		allowscriptaccess:'always',
		allowfullscreen:full_screen,
		wmode:'transparent'
	};
	
	swfobject.embedSWF("flash/player.swf", "video", sizex, sizey, "9.0.0",'', vars, params);
	
}