
function selectCategories_news(type, obj, id)
{
	if (id == first_block || id == second_block || id == third_block) return;
	
	if (type == "over") {
		obj.className = "news_categories_hrefs_select";	
	} else {
		obj.className = "news_categories_hrefs";
	}
	$('.scroll_news').jScrollPane({showArrows:true, scrollbarWidth: 18});
}

var selectcatserch_news = 0;
function selectCategorySearch_news()
{
	var obj = getObj("indicators_select");
	if (selectcatserch_news > 0) {
		var select = "category_items_" + _getSelect(obj);
		
		getObj("category_items_0").style.display = "none";
		getObj("category_items_1").style.display = "none";
		getObj("category_items_2").style.display = "none";
		getObj("category_items_3").style.display = "none";
		
		getObj(select).style.display = "block";
	}
	selectcatserch_news = selectcatserch_news + 1;
	$('.scroll_news').jScrollPane({showArrows:true, scrollbarWidth: 18});
}

function showAllCategories(box)
{
	if (box == 'box_left') {
		getObj("box_left_div").innerHTML = first_block_content;
		getObj("category_ukraine_select").style.display = "none";
		getObj("category_ukraine").style.display = "block";
	}
	if (box == 'box_center') {
		getObj("box_center_div").innerHTML = second_block_content;
		getObj("category_ukr_market_select").style.display = "none";
		getObj("category_ukr_market").style.display = "block";
	}
	if (box == 'box_right') {
		getObj("box_right_div").innerHTML = third_block_content;
		getObj("category_world_market_select").style.display = "none";
		getObj("category_world_market").style.display = "block";
	}
	
	var elem = getObj(box + "_table");
	var template_element = elem.getElementsByTagName("div");

	for(i = 0; i < template_element.length; i++){
		if (template_element[i].className == "news_categories_hrefs" || template_element[i].className == "news_categories_hrefs_select") {
			template_element[i].className = "news_categories_hrefs";
		}
	}
	$('.scroll_news').jScrollPane({showArrows:true, scrollbarWidth: 18});
}

var loadingNews = false;
var boxNews;
var first_block = 0;
var second_block = 0;
var third_block = 0;
var second_block_content = "";
var third_block_content = "";
var first_block_content = "";
function loadCategories_news(category, box, obj)
{
	if (category == 4 || category == 5 || category == 6) {
		if (first_block == 0) {
			first_block_content = getObj("box_left_div").innerHTML;
		}
		first_block = category;
		getObj("category_ukraine_select").style.display = "block";
		getObj("category_ukraine").style.display = "none";
	}
	if (category == 7 || category == 8 || category == 9) {
		if (second_block == 0) {
			second_block_content = getObj("box_center_div").innerHTML;
		}
		second_block = category;
		getObj("category_ukr_market_select").style.display = "block";
		getObj("category_ukr_market").style.display = "none";
	}
	if (category == 10 || category == 11 || category == 12) {
		if (third_block == 0) {
			third_block_content = getObj("box_right_div").innerHTML;
		}
		third_block = category;
		getObj("category_world_market_select").style.display = "block";
		getObj("category_world_market").style.display = "none";
	}
	if (loadingNews == true) {
		$('.scroll_news').jScrollPane({showArrows:true, scrollbarWidth: 18});
		return false;
	}
	boxNews = box + "_div";

	var table_name = box + "_table";

	var elem = getObj(table_name);
	var template_element = elem.getElementsByTagName("div");

	for(i = 0; i < template_element.length; i++){
		if (template_element[i].className == "news_categories_hrefs" || template_element[i].className == "news_categories_hrefs_select") {
			template_element[i].className = "news_categories_hrefs";
		}
	}
	obj.className = "news_categories_hrefs_select";
	
	var link = "/news/show/ajax/id/" + category + "/";
	
	getObj("ajax_flex_form").action = link;
	submitForm_ajax("ajax_flex_form", "loadedContent_news", "GET");
	$('.scroll_news').jScrollPane({showArrows:true, scrollbarWidth: 18});
}

function loadedContent_news(Content)
{
	pasteContent(boxNews, Content);
	$('.scroll_news').jScrollPane({showArrows:true, scrollbarWidth: 18});
}


function searchNews_news()
{
	var word = encodeURIComponent(getObj("word").value);
	var category = _getSelect("indicators_select");
	
	var link = "/news/show/search/word/" + word + "/";
	
	if (category > 0) {
		link += "category/" + category + "/";
		
		var in_category = _getSelect(getObj("indicators_select_" + category));
		if (in_category > 0) {
			link += "incategory/" + in_category + "/";
		}
	}
	
	window.location.href = link;
}

function _getSelect(select)
{
	if (is_object(select) == false) select = getObj(select);
	for (var i = 0; i < select.options.length; ++i) { 
		if(select.options[i].selected == true) return select.options[i].value;
	}
	
	return NULL;
}

function deleteNews_news(id)
{
	if (confirm("Are you sure want to delete this news?")){
		getObj("ajax_news_form").action = "/admin/news/delete-news/id/" + id + "/type/die/";
		submitForm_ajax("ajax_news_form", "deleteComplite");
		
		getObj("news_block").removeChild(getObj("news_item_" + id));
	}else{
		return false;
	}
}
function deleteComplite(){}
