function show_im_bg(id, im)
{
	$(id).style.backgroundImage = "url("+im+")";
}

function hide_im_bg(id)
{
	$(id).style.backgroundImage = "url(/img/spacer.gif)";
}


function check_login(value)
{
	new Ajax.Request('/ajax.php', {method: 'get', parameters:'action=check_login&login='+value,
		onSuccess:function(req){
     	 var i;
     	 	var a;
     	 	a = $('log_in_div');
     		if (a != undefined)
     		{
     			a.innerHTML = req.responseText;
     				
     		}

    	}, 
		onFailure:function()
		{
		}
		});
}


function list_photo(block_id, page, cur_photo)
{
	new Ajax.Request('/ajax2.php', {method: 'get', parameters:'C='+page+'&news='+block_id+'&cur_photo='+cur_photo,
		onSuccess:function(req){
     	 var i;
     	 	var a;
     	 	a = $('gal'+block_id);
     		if (a != undefined)
     		{
     			a.innerHTML = req.responseText;
     		}

    	}, 
		onFailure:function()
		{
		}
		});
}

function clearList(lst) {
  while (lst.options.length > 0) {
    lst.options[0] = null;
  }
}


function gen_region_select_by_country(country_id, region_select_id, city_select_id, region_div_id, city_div_id, city_else_id, region_id, city_id)
{
	new Ajax.Request('/ajax.php', {method: 'get', parameters:'action=gen_region_select_by_country&country_id='+country_id + "&region_select_id=" + region_select_id,
		onSuccess:function(req){
     	 var i;
     		$(region_div_id).innerHTML = req.responseText;
     		if (region_id)
     		{
     			setRegion(region_id, region_select_id);
				gen_city_select_by_region(region_id, city_select_id, city_div_id, city_else_id, city_id)
     		}

    	}, 
		onFailure:function()
		{
		}
		});
}

function AddRubricSelect()
{
	var t = document.getElementById("news_edit_table");
	  
	for(var c=0; c<t.childNodes.length; c++)
	{
		if(t.childNodes[c].tagName != undefined)
		if(t.childNodes[c].tagName.match(/tbody/gi))
		{
			var tb = t.childNodes[c];
			
		}
	}
	
	var s = $("news_add_rubric");
	 
	var f = document.forms.blockedit;
	
	var Cnt = parseInt($('subrubrics_count').value);
	
	select_name = Cnt+1;	
	
	new Ajax.Request('/ajax.php', {method: 'post', parameters:'action=gen_rubricss&select_name=' + select_name,
		onSuccess:function(req){
     		var row = document.createElement("tr");
			var col = document.createElement("td");
			col.setAttribute("style", "padding-right: 20px;"); 
			col.innerHTML = req.responseText;
			row.appendChild(col);
			
			var col1 = document.createElement("td");
			col1.setAttribute("id", "child_div["+select_name+"]");
			col1.innerHTML = "";
			row.appendChild(col1); 
			
			tb.insertBefore(row, s);
			$('subrubrics_count').value = select_name;					
    	}, 
		onFailure:function()
		{
			alert('error');
		}
		});
}



function gen_city_select_by_region(region_id, city_select_id, city_div_id, city_else_id, city_id)
{
	$('r_id').value=region_id;
	
	new Ajax.Request('/ajax.php', {method: 'get', parameters:'action=gen_city_select_by_region&region_id='+region_id + "&city_select_id=" + city_select_id,
		onSuccess:function(req){
     	 var i;
     		$(city_div_id).innerHTML = req.responseText;
  			if (city_id != 0)
  			{
  				setCity(city_id, city_select_id, city_else_id);
  				change_city(city_id, city_select_id, city_else_id);
  			}

    	}, 
		onFailure:function()
		{
		}
		});
}


function show_cities(region_select_id, city_select_id, city_div_id, city_id)
{
	var region_id = $(region_select_id).options[$(region_select_id).selectedIndex].value;
	if (region_id)
	{  
		new Ajax.Request('/ajax.php', {method: 'get', parameters:'action=gen_city_select_by_region&region_id='+region_id + "&city_select_id=" + city_select_id,
		onSuccess:function(req){
     	 var i;
     		$(city_div_id).innerHTML = req.responseText;
  			if (city_id != 0)
  				setSimpleCity(city_id, city_select_id);
    	}, 
		onFailure:function()
		{
		}
		});
	}
}

function show_cities2(region_select_id, city_select_id, city_div_id, city_id, cat_id)
{
	var region_id = $(region_select_id).options[$(region_select_id).selectedIndex].value;
	if (region_id)
	{  
		new Ajax.Request('/ajax.php', {method: 'get', parameters:'action=gen_city_select_by_region2&tp=2&region_id='+region_id + "&cat_id=" + cat_id + "&city_select_id=" + city_select_id,
		onSuccess:function(req){
     	 var i;
     		$(city_div_id).innerHTML = req.responseText;
  			if (city_id != 0)
  				setSimpleCity(city_id, city_select_id);
    	}, 
		onFailure:function()
		{
		}
		});
	}
}



function change_city(val, city_select_id, city_else_id)
{
	$('c_id').value=val;
	if (val == '0')
	{
		$(city_else_id).disabled = false;
	}
 	else
 	{
		$(city_else_id).disabled = true;
		$(city_else_id).value = ''; 
	}
}

function change_country(country_select_id, region_select_id, city_select_id, region_div_id, city_div_id, city_else_id, region_id, city_id)
{
	var c = document.getElementById(country_select_id);
	gen_region_select_by_country(c.options[c.selectedIndex].value, region_select_id, city_select_id, region_div_id, city_div_id, city_else_id, region_id, city_id);
	
	//var d = document.getElementById(region_select_id);
	//gen_city_select_by_region(d.options[d.selectedIndex].value, city_select_id, city_div_id, city_else_id, city_id)
	setCity(city_id, city_select_id, city_else_id);
	change_city(city_id, city_select_id, city_else_id);
}

function setCity(city_id, city_select_id, city_else_id)
{	
	var lst;
	lst = $(city_select_id);
	var i = 0;
	$('c_id').value=city_id;
	
	for (i=0; i<lst.options.length; i++)
	{
		if (lst.options[i].value == city_id)
			lst.selectedIndex = i;
	}
}

function setSimpleCity(city_id, city_select_id)
{	
	
	lst = $(city_select_id);
	var i = 0;
	for (i=0; i<lst.options.length; i++)
	{
		if (lst.options[i].value == city_id)
			lst.selectedIndex = i;
	}
}


function setRegion(region_id, region_select_id)
{
	var lst;
	var kuku = 0;
	lst = $(region_select_id);
	var i = 0;
	$('r_id').value=region_id;
	
	for (i=0; i<lst.options.length; i++)
	{
		if (lst.options[i].value == region_id)
		{
			lst.selectedIndex = i;
		}
   }
}

function repl(main_rub, idid, real_val)
{
	new Ajax.Request('/ajax.php', {method: 'get', parameters:'action=gen_rub_childs&rubric_id='+main_rub + "&select_id=child_block_rubric[" + idid + "]&real_val="+real_val,
		onSuccess:function(req){
     	 var i;
     		$('child_div['+idid+']').innerHTML = req.responseText;
    	}, 
		onFailure:function()
		{
		}
		});
}

function AddPhoto()
{
	var t = document.getElementById("photos_tab");
	
	for(var c=0; c<t.childNodes.length; c++)
	{
		if(t.childNodes[c].tagName != undefined)
		if(t.childNodes[c].tagName.match(/tbody/gi))
		{
			var tb = t.childNodes[c];
		}
	}
	
	
	
	var s = $("add_row");
	
	 
	var f = document.forms.blockedit;
	
	var Cnt = 0;
	for(var c=0; c<f.elements.length; c++)
	{
		if(f.elements[c].type == 'file')
			Cnt++;
	}
	
	if (Cnt)
		Cnt = Cnt / 2;
	
	
	if (Cnt < 30)
	{
		var row = document.createElement("tr");
		var col0 = document.createElement("td"); 
		col0.appendChild(document.createTextNode("Подпись"));
		col0.setAttribute("class", "cms_header_left");
		col0.setAttribute("valign", "top");
		row.appendChild(col0);
		var col1 = document.createElement("td"); 
		col1.setAttribute("valign", "top");
		var inp = document.createElement("input");
		inp.setAttribute("type", "text");
		inp.setAttribute("name", "names[" + Cnt + "]");
		inp.setAttribute("class", "cms_input");
		inp.setAttribute("size", "60");   
		col1.appendChild(inp);
		row.appendChild(col1); 
		tb.insertBefore(row, s);
		
			
		
		var row2 = document.createElement("tr");
		var col2 = document.createElement("td"); 
		col2.setAttribute("class", "cms_header_left");
		col2.setAttribute("valign", "top");
		col2.appendChild(document.createTextNode("Фото"));
		row2.appendChild(col2);
		var col3 = document.createElement("td"); 
		
		col3.setAttribute("valign", "top");
		var inp2 = document.createElement("input"); 
		inp2.setAttribute("type", "file");
		inp2.setAttribute("name", "photos[" + Cnt + "]");
		inp2.setAttribute("class", "cms_input");
		inp2.setAttribute("size", "60");   
		col3.appendChild(inp2);
		row2.appendChild(col3); 
		
		tb.insertBefore(row2, s);		
		
		
		var row3 = document.createElement("tr");
		var col4 = document.createElement("td"); 
		col4.setAttribute("class", "cms_header_left");
		col4.setAttribute("valign", "top");
		col4.appendChild(document.createTextNode("Фото для скачивания"));
		row3.appendChild(col4);
		var col5 = document.createElement("td"); 
		
		col5.setAttribute("valign", "top");
		var inp3 = document.createElement("input"); 
		inp3.setAttribute("type", "file");
		inp3.setAttribute("name", "big_photos[" + Cnt + "]");
		inp3.setAttribute("class", "cms_input");
		inp3.setAttribute("size", "60");   
		col5.appendChild(inp3);
		row3.appendChild(col5); 
		
		tb.insertBefore(row3, s);		
		
	}		
	
	
	
}


function get_articles(bid)
{
	new Ajax.Request('/ajax.php', {method: 'get', parameters:'action=get_articles&block_id='+bid,
		onSuccess:function(req){
     	 var i;
     	 	var a;
     	 	a = $('art_sel_div');
     		if (a != undefined)
     		{
     			a.innerHTML = req.responseText;
     				
     		}

    	}, 
		onFailure:function()
		{
		}
		});
}


function show_p(bid, book)
{
	if (bid)
	{
		$('comm'+bid).style.display = 'none';
		$('program'+bid).style.display = 'none';
		$('pay'+bid).style.display = 'none';
		
		$('book_comm'+bid).className = 'navi no_und marg_right_20';
		$('book_program'+bid).className = 'navi no_und marg_right_20';
		$('book_pay'+bid).className = 'navi no_und marg_right_20';
		
		$('book_'+book+bid).className = 'btnnn';
		
		$(book+bid).style.display = 'block';
		
	}
	
}

function generate_author_list_by_news_cat(div, select_id, news_cat_id)
{
	new Ajax.Request('/admin/ajax.php', {method: 'get', parameters:'action=gen_select_by_news_cat&item=author&news_cat_id='+news_cat_id + "&select_id=" + select_id + "&div=" + div,
		onSuccess:function(req){
     	 var i;
     		$(div).innerHTML = req.responseText;
    	}, 
		onFailure:function()
		{
		}
	});
}

function generate_region_list_by_news_cat(div, select_id, news_cat_id)
{
	new Ajax.Request('/admin/ajax.php', {method: 'get', parameters:'action=gen_select_by_news_cat&item=region&news_cat_id='+news_cat_id + "&select_id=" + select_id + "&div=" + div,
		onSuccess:function(req){
     	 var i;
     		$(div).innerHTML = req.responseText;
    	}, 
		onFailure:function()
		{
		}
	});
}

function generate_tag_list_by_news_cat(div, select_id, news_cat_id)
{
	new Ajax.Request('/admin/ajax.php', {method: 'get', parameters:'action=gen_select_by_news_cat&multiple=1&item=tag&news_cat_id='+news_cat_id + "&select_id=" + select_id + "&div=" + div,
		onSuccess:function(req){
     	 var i;
     		$(div).innerHTML = req.responseText;
    	}, 
		onFailure:function()
		{
		}
	});
}
