// JavaScript Document

// checkboxes to radio buttons
var array = [
	['idform84674d540a28c7dbb', 'idform10914d540a28c7d5f', 'idform33874d540a28c7d04', 'idform86754d540a28c7caa', 'idform32904d540aa5d35d9'],
	['idform89264d5409a7c9113', 'idform21844d5409a7c90b5'],
	['idform53284d5409a7c8bd9', 'idform51594d5409a7c8b73', 'idform48994d5409a7c8b06'],
	['idform17884d53ee807e4b5', 'idform72414d53ee807e510'],
	['idform57364d5402ce8bdb2', 'idform22684d5402ce8be0c'],
	['idform38824d5402ce8bfce', 'idform11824d5402ce8c028'],
	['idform73294d5402ce8c140', 'idform49254d5402ce8c19b'],
	['idform90694d5402ce8c3b8', 'idform46334d5402ce8c412'],
	['idform82344d54041201604', 'idform24174d5404120165e'],
	['idform60854d54087d90969', 'idform36404d54087d90910'],
];

// Filter int and float input
var int_array = [
	'idform98454d5402ce8be66', 'idform76944d5402ce8bf76', 'idform20584d5402ce8c1f4', 'idform82534d5402ce8c2a6', 'idform89954d5402ce8c303', 'idform70914d5402ce8c46c'
]

function trombinoscope(element){
	document.getElementById('light3').style.display='block';
	document.getElementById('fade').style.display='block';
	
	$('lb_trombi').innerHTML = $(element).innerHTML;
}

function changeActivePage(elm) {
	var id = elm.substring(3);
	$j('.tab span').removeClass('selectTab');
	$j('#' + elm).addClass('selectTab');
	$j('#html_print_span .text').css('display', 'none');
	$j('#' + id).css('display', 'block');
}

function radioCheck(elm) {
	var index = -1;
	for (var i = 0; i < array.length; i++) {
		for (var j = 0; j < array[i].length; j++) {
			if (elm == array[i][j]) {
				index = i;
				break;
			}
		}
	}
	if (index != -1) {
		for (var i = 0; i < array[index].length; i++) {
			$j('#' + array[index][i]).attr('checked', false).val('');
		}
		
		$j('#' + elm).attr('checked', true);
	}
}

function filter(type, elm) {
	switch (type) {
		case 'int':
			$j('#' + elm).val($j('#' + elm).val().replace(/[^\d\.]/, ''));
			break;
	}
}

var gup = function( name ) {
	var results = (new RegExp("[\\?&]"+name+"=([^&#]*)")).exec(window.location.href);
	if ( results == null ) {return ""}
	else {return results[1]}
};

var menu_entries = {}

$j(function() {
	$j('.tab span').click(function() {
		changeActivePage($j(this).attr('id'));
	});
	$j('#attr_cat_2').change(function() {	
	//	var selected_cat = $j(this).find('option:selected').val();
	//	document.location.href = document.location.href.replace(/news_cat=(\d*)&/, "news_cat=" + selected_cat + "&");
	});

	if (gup("articles")==1 || gup("offset")!="") changeActivePage("id_articles");
	
	var fading = $j("#fading").clone();
	$j("#fading").remove();
	$j("body").append(fading);
	
	var dlight3 = $j("#light3").clone();
	$j("#light3").remove();
	$j("body").append(dlight3);

	$j("#topMenu .content UL LI").mouseover(function() {
		clearTimeout(menu_entries[$j("SPAN",this).text()]);
		$j("UL",this).show();
	});


	$j("#topMenu .content UL LI A").mouseover(function() {
		clearTimeout(menu_entries[$j("SPAN",this).text()]);
		$j("UL",this).show();
	});

	$j("#topMenu .content UL LI A").css("position","relative");
	$j("#topMenu .content UL LI A").css("z-index","9998");

	$j("#topMenu .content UL LI").mouseout(function() {
		var cc = $j("SPAN",this).text();
		if ($j.browser.msie && $j.browser.version=="7.0") {
			menu_entries[$j("SPAN",this).text()] = setTimeout('$j("UL SPAN:contains(\''+cc+'\')").next().hide()',1000);
		} else {
			menu_entries[$j("SPAN",this).text()] = $j("UL",this).hide();
		}
	});
	
	$j("form input").click(function() {
		radioCheck($j(this).attr('id'));
	});
	
	for (var i = 0; i < int_array.length; i++) {
		$j('#' + int_array[i]).keyup(function() {
			filter('int', $j(this).attr('id'));
		});
	}
});

