// Dohvaæanje stranice u arhivi preko AJAX-a
var GP_navi_dir;
var GP_get_page;
var GP_curr_page;

function get_page(url, navi_dir)
{
	if (GP_curr_page == undefined)
		GP_curr_page = 1;

	if (navi_dir == undefined && GP_navi_dir == undefined)
		var GP_navi_dir = GP_get_page < GP_curr_page ? 'prev' : 'next';
	else
		var GP_navi_dir = navi_dir;

	$(GP_navi_dir + '_navi').className = GP_navi_dir + '-active';

	new ajax(url, { postBody:'ajax=1', onComplete: display_page });
}
function display_page(r)
{
	var response = r.responseText.split('|delimiter|');

	$('sredina').innerHTML = response[0];
	
	if (GP_navi_dir == undefined)
		var GP_navi_dir = GP_get_page < GP_curr_page ? 'prev' : 'next';
	$(GP_navi_dir+'_navi').className = GP_navi_dir;

	GP_curr_page = response[1];
}

// post comments
function get_post_comments(url, post_id, blog_id, design_id)
{
	new ajax(url,
	{
		postBody:'page=blog_post_comments&id=' + post_id + '&blog_id=' + blog_id + '&design_id=' + design_id,
		onComplete: display_post_comments
	});
}

function display_post_comments(r)
{
	var response = r.responseText.split('|delimiter|');
	// respose = [post_id, comments_html]
	
	$('komentari_post_' + response[0]).innerHTML = response[1];
}


// Banners
function get_banners(url, position)
{
	new ajax(url, { postBody:'page=banner&type='+position, onComplete: display_banners });
}
function display_banners(r)
{
	var response = r.responseText;
	var response = response.split('|delimiter|');
	
	var html = response[0];
	var div = response[1];

	$(div).innerHTML = html;
}

function checkEnter(e, form) //e is event object passed from function invocation
{
	var characterCode; //literal character code will be stored in this variable
	
	if(e && e.which) //if which property of event object is supported (NN4)
	{
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if (characterCode == 13) //if generated character code is equal to ascii 13 (if enter key)
	{
		form.submit(); //submit the form
		return false;
	}
	else
		return true;
}

function change_month(url, date, loader_img, direction)
{
	if (url == undefined || url == '')
	{
		alert('ERROR [frontend.js - prev_month()]: URL not defined!');
		return;
	}
	if (date == undefined || date == '')
	{
		alert('ERROR [frontend.js - prev_month()]: Date not defined!');
		return;
	}

	if (direction == 0)
		load_id = 'prev_loader';
	else if (direction == 1)
		load_id = 'next_loader';

	// Prikaz progress bara
	if (direction >= 0)
		$(load_id).src = loader_img;

	new ajax(url, {postBody:'data[date]='+date, onComplete: after_month});
}
function after_month(request)
{
	$('box_calendar').innerHTML = request.responseText;
}

// Photonews
function get_photonews(url)
{
	// Get lists
	$('foto_loader').style.display = 'inline';
	new ajax(url, { postBody:'page=photonews', onComplete: display_photonews });
}
function display_photonews(r)
{
	$('foto_loader').style.display = 'none';
	$('foto').innerHTML = r.responseText;
}

// Tags (category box)
function get_tags(url)
{
	$('tags_loader').style.display = 'inline';
	new ajax(url, { postBody:'page=catbox', onComplete: display_tags });
}
function display_tags(r)
{
	$('tags_loader').style.display = 'none';
	$('tags').innerHTML = r.responseText;
}

// Lists (cool, almost, fresh, izbori)
function get_lists(url)
{
	// Get lists
// 	$('cool_loader').style.display = 'inline';
	$('almost_cool_loader').style.display = 'inline';
	$('fresh_loader').style.display = 'inline';

	new ajax(url, { postBody:'page=lists', onComplete: display_lists });
}
function display_lists(r)
{
	var html = r.responseText.split('|delimiter|');

	// Cool blogs
	if (html[0] != 0)
	{
		$('cool_blogs').innerHTML = html[0];
		$('cool_container').style.display = 'inline';
	}
	//$('cool_loader').style.display = 'none';
	
	// Almost cool blogs
	if (html[1] != 0)
	{
		$('almost_cool_blogs').innerHTML = html[1];
		$('almost_cool_container').style.display = 'inline';
	}
	$('almost_cool_loader').style.display = 'none';

	// Fresh blogs
	if (html[2] != 0)
	{
		$('fresh_blogs').innerHTML = html[2];
		$('fresh_container').style.display = 'inline';
	}
	$('fresh_loader').style.display = 'none';

	// Izbori blogs
	/*
	if ((html[3] != 0) && ($('izbori_blogs') != undefined))
	{
			$('izbori_blogs').innerHTML = html[3];
			$('izbori_container').style.display = 'inline';
	}
	if ($('izbori_loader') != undefined)
		$('izbori_loader').style.display = 'none';
	*/
}

function check_answers(id)
{
	var n = 0;
	var element = id+n;
	var chkd = false;
	while ($(element) != undefined)
	{
		if ($(element).checked)
			chkd = true;

		n++;
		element = id+n;
	}

	if (chkd == false)
		alert(message[82]);

	return chkd;
}

function check_login()
{
	if ($('username').value == '' || $('password').value == '')
	{
		alert(message[83]);
		return false;
	}
	else
		return true;
}

// EOF