var path = document.location.pathname;		
if ( path.charAt(path.length-1) != '/' ) path = path+'/';
var epos = document.location.pathname.indexOf('/',1) == -1 ? document.location.pathname.length : document.location.pathname.indexOf('/',1)-1;
var section = document.location.pathname.substr(1, epos );
	
$(document).ready(init);

function init() {			
	$("#section-image").attr({src:"/images/titles/"+section+".gif"});
	
	if ( path != '/' ) {
		hlCurrentMenuItem();
	}
	
	$(".menu li").hover(
		function () {			
					
			$(".submenu", $(this)).show();
			if ( $(this).hasClass('have-submenu') ) {
				$("a", $(this)).addClass("selected");				
				$("a img", $(this)).replaceWith("<img src='/images/menu/selected/"+$(this).attr('rel')+".gif'/>");				
			}
			else 
				$("a", $(this)).addClass("hover");
		},
		function () {
			$(".submenu", $(this)).hide();
			if ( $(this).hasClass('have-submenu') ) {
				$("a", $(this)).removeClass("selected");
				$("a img", $(this)).replaceWith("<img src='/images/menu/default/"+$(this).attr('rel')+".png'/>");
				//$("a img", $(this)).attr("src", $("a img", $(this)).attr("src").replace("selected","default").replace("gif","png"));
			}
			else 
				$("a", $(this)).removeClass("hover");
			
			if ( path != '/' ) { hlCurrentMenuItem(); }
		}
	);
	
	try {
		$("table.params tr:nth-child(odd)").addClass("grey");
	}
	catch ( e ) {}
}

function hlCurrentMenuItem() {
	$(".menu a[href^='/"+section+"']").addClass("selected");
	//$(".menu a[href^='/"+section+"'] img").attr("src", $(".menu a[href^='/"+section+"'] img").attr("src").replace("default","selected").replace("png","gif"));	
	//$(".menu a[href^='/"+section+"'] img").attr("src", $(".menu a[href^='/"+section+"'] img").attr("src").replace("png","gif"));
	$(".menu a[href^='/"+section+"'] img").replaceWith("<img src='/images/menu/selected/"+section+".gif'/>");
}

function checkForm ( name ) {
	var res = true;	
	var block = $("#"+name);
	$("#"+name+" input:enabled, #"+name+" textarea:enabled").each(
		function () {			
			if ( ($(this).hasClass("required") && $(this).val() == '') || ($(this).hasClass("required") && $(this).val() == $(this).attr('rel')) ) {
				res = false;
				//$("label[for='"+$(this).attr("id")+"']", block).css({color: '#f00'});
				$(this).addClass("error");				
			}
			else if ( $(this).hasClass("email") && $(this).val() != '' ) {
				var emailTest = '^[_\\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+\\.)+[a-z]{2,4}$';
				var regex = new RegExp(emailTest);
				if ( !regex.test( $(this).val() ) ) {
					res = false;
					//$("label[for='"+$(this).attr("id")+"']", block).css({color: '#f00'});
					$(this).addClass("error");
				}
			}
		}
	);
	setTimeout("$('#"+name+" input, #"+name+" textarea').removeClass('error');",3000);
	return res;
}