function validate(element_id, regular, regular_error, error_id, main_error, min_len, min_len_error, max_len, max_len_error){
	$("#"+element_id).blur(function () {
		error = $("#"+main_error);
		l = $("#"+element_id).val().length;
		$("#"+error_id).addClass("validation-error"); 

		$("#"+element_id).addClass('input-error');
		if (min_len > 0){
			if (l < min_len){
				error.html(min_len_error);
				error.show();
				return false;
			}
		}
		if (max_len){
			if (l > max_len){
				$("#"+error_id).addClass("validation-error");
				error.html(max_len_error);
				error.show();
				return false;
			}
		}
		
		if (regular){
			var reg = new RegExp(regular);
			test = reg.test($("#"+element_id).val());
			if ( !test ){
				error.html(regular_error);
				error.show();
				return false;
			}
		}
		error.hide();
		$("#"+error_id).removeClass("validation-error");
		$("#"+element_id).removeClass('input-error');
	});
	$("#"+element_id).focus(function () { $("#"+error_id).removeClass("validation-error"); $("#"+element_id).removeClass('input-error'); });
	return true;
}

function validate_ret(element_id, regular, regular_error, error_id, hide_error, main_error, min_len, min_len_error, max_len, max_len_error){
	error = $("#"+main_error);
	l = $("#"+element_id).val().length;
	$("#"+error_id).addClass("validation-error");
	if (hide_error){
		$("#"+error_id).show();
	}

	$("#"+element_id).addClass('input-error');
	if (min_len > 0){
		if (l < min_len){
			error.html(min_len_error);
			error.show();
			return false;
		}
	}
	if (max_len){
		if (l > max_len){
			$("#"+error_id).addClass("validation-error");
			error.html(max_len_error);
			error.show();
			return false;
		}
	}
	
	if (regular){
		var reg = new RegExp(regular);
		test = reg.test($("#"+element_id).val());
		if ( !test ){
			error.html(regular_error);
			error.show();
			return false;
		}
	}
	error.hide();
	if (hide_error){
		$("#"+error_id).hide();
	}
	$("#"+error_id).removeClass("validation-error");
	$("#"+element_id).removeClass('input-error');
	$("#"+element_id).focus(function () { $("#"+error_id).removeClass("validation-error"); $("#"+element_id).removeClass('input-error'); });
	return true;
}

function open_window(url, w_width, w_height, w_top, w_left, scrollbars, resizable){
	if (resizable === 1){
		resizable = "yes";
	} else {
		resizable = "no";
	}
	if (scrollbars === 1){
		scrollbars = "yes";
	} else {
		scrollbars = "no";
	}
	win=window.open(url,"","width="+w_width+", height="+w_height+", left="+w_left+", top="+w_top+", scrollbars="+scrollbars+", resizable="+resizable);
}

function beforeTopChange(){

}
function afterTopChange(){
	var id = $("#current_top_id").val();
	var img_id = "timg_" + id;
	id++;
	var rows = $("#"+img_id).attr('rows');
	$("#current_top_id").val(id);
	$("#tnt-text-link").html($("#"+img_id).attr('alt'));
	$("#tnt-text-link").attr('href', $("#"+img_id).attr('rel'));
	$("#tnt-text-link-2").html($("#"+img_id).attr('alt'));
	$("#tnt-text-link-2").attr('href', $("#"+img_id).attr('rel'));
	var row = $("#"+img_id).attr('rows');
	if (row == 1){
		$("#top-news-title").css('display', '');
		$("#top-news-title-2").css('display', 'none');
	} else {
		$("#top-news-title").css('display', 'none');
		$("#top-news-title-2").css('display', '');
	}
	if (id == 6){
		$("#current_top_id").val(1);
	}
}

