Array.prototype.unique = function () {
	var r = new Array();
	o:for(var i = 0, n = this.length; i < n; i++) {
		for(var x = 0, y = r.length; x < y; x++) {
			if(r[x]==this[i]) {
				continue o;
			}
		}
		r[r.length] = this[i];
	}
	return r;
}
$(function() {
	// Test scripts
	// get all checked radio buttons, read their value and summerize them. 
	if ($("#run_test").length = 1) {
		// check button on clicking on span
		$("input[name^=uromax_]").next("span").css('cursor','default').click(function(){
			$(this).prev().attr("checked", "checked");
		});
		
		$("#run_test").click(function(){
			$("#test_results li.error").slideUp(500,function(){$(this).remove();});
			$("#test_results li").slideUp(500);

			// count how many questions wasn't answered
			// HOW IT WORKS: Creates array of elements' name attrs, checks all elements of equal name
			// if zero of elements with one name are checked - sum_not_checked++. 
			// Count at the end - if sum_not_checked>0, then there were unanswered elements.
			var x=new Array(); i=0; checked=0; sum_not_checked=0;
			$("input[name^=uromax_test]").each(function(){ // create array of all name attributes
				x[i++]=$(this).attr('name');
			})
			elements=x.unique() //leave only unique name attrs
			for (k=0;k<elements.length;k++) { // iterate through all elemets with one name
				$("input[name="+elements[k]+"]").each(function(){
					$(this).is(":checked") == true ? checked=1 : checked=0;
					//console.log(elements[k] + ": " +checked);
					if (checked==1) { return false; }
				})
				checked==0 ? sum_not_checked++ : '';
			}
			//console.log('not: '+sum_not_checked);
			if (sum_not_checked > 0) {
				$("#test_results li:last").after("<li class='error'>Пожалуйста, ответьте на все вопросы. Надо ответить еще на <b>"+sum_not_checked+"</b> вопросов.</li>")
				$("#test_results li.error").slideDown(500)	// show li.error
			} else {
				total=0;
				$("input[name^=uromax_test]:checked").each(function(){
					total += parseInt( $(this).val() );
				});

				$("#test_results li").each(function() {
					range=$(this).attr('title');
					range=range.split('-');
					if (total >= range[0] && total <= range[1]) {
						$(this).parent("ul").slideDown(500);
						$(this).slideDown(500);
					}
				});
			} //if (sum_not_checked > 0) {
			try { //run custom test function
				custom_test(total);
			} catch(err) {}
		}); //button.click()
	} //  if ($("#run_test").length = 1) 
}); //.ready()
