$(function() {
	$('.catmenu>li').hover(function() {$('div', this).css('marginLeft', 0);}, function() {$('div', this).css('marginLeft', '-9999px');});
	$('#leftmenu').hover(function() {$(this).animate({left: 0});}, function() {$(this).animate({left: '-85px'});});
});

addEvent(document, 'keydown', function(event) {
	var event = event || window.event;
	if (!event.ctrlKey) return; 
	var link = '';
	switch (event.keyCode || event.which) {
		case 0x25: link = document.getElementById('page_prev'); break;
		case 0x27: link = document.getElementById('page_next'); break;
	}
	if (link && link.href) document.location = link.href;	
});
	
function is_phone(str) {
   return str.match(/^[\s\-\(\)0-9]{7,}$/)?true:false;
}

function is_email(str) {
   return str.match(/^[a-zA-Z\-\._0-9]+\@[a-zA-Z\.\-_0-9]+$/)?true:false;
}

function write_mail(name, domen1, domen2) {
	document.write('<a href="mailto:'+name+'@'+domen1+'.'+domen2+'">'+name+'@'+domen1+'.'+domen2+'</a>');
}

function addEvent(obj, event, func, cascade) {
	if (obj.addEventListener) obj.addEventListener(event, func, cascade);
	else obj.attachEvent('on'+event, func);
}

$(document).ready(function() {
	// Формы
    $('div.form_error').each(function() {
		field_id = this.id.substr(0,this.id.length-6);
		$('#'+field_id).addClass('field_error').one('focus', function() {
		    $(this).removeClass('field_error');
		    $('#'+this.id+'_error').remove();
		});
    });
});

function pr(obj, first) {
	if (typeof(first) == 'undefined') {
		var win = window.open('', 'js_object', 'left=300,top=100,width=600,height=550,scrollbars=yes');
		win.document.write('<html><head><title>SHOW OBJ</title></head><body style="font: 12px tahoma">');
	}
	var out = '';
	for(i in obj) {
		out += '<b>' + i + '</b> (' + typeof(obj[i]) + '): ';
		if (typeof(obj[i])=='object')
			out += '<div style="border-left: 2px solid; margin: 3px 5px 3px 20px; padding-left: 10px;">'+pr(obj[i],1)+'</div>';
		else
			out += obj[i]+'<br>';
	}
	if (typeof(first) == 'undefined') {
		win.document.write('<h1>Object:</h1>'+out+'</body></html>');
		win.focus();
	} else {
		return out;
	}	
}
