function reloadCaptcha(img_id){
    $("img#"+img_id).attr("src", "/includes/codegen/cms_codegen.php?"+Math.random());
}
$(document).ready(function() {
    setTimeout(function() {
    var h = $('#left').height();
    var d = $('#heig1').height();
    if (h>(d+50)) {
    $('div#heig1').css('min-height', h+'px');
    $('div#heig2').css('min-height', h+'px'); }
     }, 100)
});
function centerLink(href){

	$.post(href, {'of_ajax': 1}, function(data){
		$('div#heig2').html(data);
	});
    setTimeout(function() {
    var h = $('#left').height();
    var d = $('#heig1').height();
    if (h>(d+50)) {
    $('div#heig1').css('min-height', h+'px');
    $('div#heig2').css('min-height', h+'px'); }
     }, 150)

}
function searchTitle(page){
	var title = $('input.title').val();
	var page = page || 1
	if (title.length > 3){
		$('#s_page').val(page);
		$('form.search_form').submit();
	} else {
		alert('Ошибка! Запрос должен быть не менее 3-х символов.');
	}
	$('.title').focus();
}

function modalInit(url, width, height){

	$('body').prepend('<div id="redactor_imp_modal_overlay" style="display: none;"></div>');
	$('#redactor_imp_modal_overlay').show();
	$('#redactor_imp_modal_overlay').click(function() { modalClose(); });

	if ($('#redactor_imp_modal').size() == 0){
		$('body').append('<div id="redactor_imp_modal" style="display: none;"><div id="redactor_imp_modal_close"></div><div id="redactor_imp_modal_header"></div><div id="redactor_imp_modal_inner"></div></div>');
	}

	$('#redactor_imp_modal_close').click(function() { modalClose(); });
	$(document).keyup(function(e) { if( e.keyCode == 27) modalClose(); });
	$(this.doc).keyup(function(e) { if( e.keyCode == 27) modalClose(); });			

	$.ajax({
		url: url,
		type: "POST",
		data: {of_ajax : 1},
		success: function(data){		

			$('#redactor_imp_modal_inner').html(data);
			
			if (height === false) theight = 'auto';
			else theight = height + 'px';
			
			$('#redactor_imp_modal').css({ width: width + 'px', height: theight, marginTop: '-' + height/2 + 'px', marginLeft: '-' + width/2 + 'px' }).fadeIn('fast');					

		}
	});
}

function modalClose(){

	$('#redactor_imp_modal_close').unbind('click', function() { modalClose(); });

	$('#redactor_imp_modal').fadeOut('fast', function(){
		$('#redactor_imp_modal_inner').html('');			
		
		$('#redactor_imp_modal_overlay').hide();		
		$('#redactor_imp_modal_overlay').unbind('click', function() { modalClose(); });					
		
		$(document).unbind('keyup', function(e) { if( e.keyCode == 27) modalClose(); });
		$(this.doc).unbind('keyup', function(e) { if( e.keyCode == 27) modalClose(); });
		
	});

}
