
var Tim;

function show_inner(id){	//alert(id)
	var elem1 = document.getElementById(id);
	var elem2 = document.getElementById('inner'+id);
	
	elem2.style.display = 'block';

	elem2.onmouseover = function() {window.clearTimeout(Tim)};
	
	elem1.onmouseout = function () {
			Tim = window.setTimeout(function() { hide_inner(id) }, 200);
		};
	elem2.onmouseout = function() {
			Tim = window.setTimeout(function() { hide_inner(id) }, 200);
		};
	window.clearTimeout(Tim);
}

function hide_inner(id){
	$('inner'+id).style.display = 'none';
}

function pomen(id, email){

	var active = $(id).hasClassName('active');
	
	if (!active) {
		
		$(id).addClassName('active');
		
		$A($(id).nextSiblings()).each(function(item) {
			if($(item).hasClassName('img')) $(item).removeClassName('active');
		});
		
		$A($(id).previousSiblings()).each(function(item) {
			if($(item).hasClassName('img')) $(item).removeClassName('active');
		});
		
		$('who').value = email;
		
		SetCookie('auto', id);
	} 
}

function SetCookie(sName, sValue){
	document.cookie = sName + "=" + escape(sValue) + ";expires=30 Dec 2999 23:59:59 UTC; path=/";
}


function preloadImg(src) {
	if (document.images) {
		var image = new Image();
		image.src = src;
		images.push(image);
	}
}

function showClientName(elem, e){
	 var div = document.getElementById('file'+elem.id);
	 div.style.display = 'block';	
	 elem.onmouseout = function() {
	 	div.style.display = 'none';
	}
}

function cheakFileForm(){
	var required = {
		"name"		:	"Вы не ввели название файла",
//		"opis"		:	"Вы не ввели описание файла",
		'file'		:	'Вы не выбрали файл'
	};

	for (i in required) {
		var el = document.getElementById(i);
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}


function toActive(elem, image){
	elem.className = 'menu_active';
	var img = $(elem).down('a').down('img');
	img.src = site_url + 'files/' + image;
}

function toNoActive(elem, image){
	elem.className = 'menu';
	var img = $(elem).down('a').down('img');
	img.src = site_url + 'files/' + image;
}

function checkSubscribeForm(){
	var email = document.getElementById('email');
	if(!checkEmail(email.value)){
			alert('Не введен или введен некорректный e-mail');
			email.focus();
			return false;
		}
	else return true;
}

function checkFormVakancy(){
	var required = {
		"fio"		:	"Вы не ввели Ваше ФИО",
		"tel"		:	"Вы не ввели телефон",
		"email"		:	"Не введен или введен некорректный e-mail",
		"prim"		:	"Вы не ввели примечание",
		"userfile"	:	"Вы не оставили резюме"
	};
	

	for (i in required) {
		var el = document.getElementById(i);
		if(el.id == 'email' && el.value && !checkEmail(el.value)){
			alert(required['email']);
			el.focus();
			return false;
		};
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}

function checkEmail(email) {
	if(!email) return email;
	if(!email.match(/^[\w\.\-]+@[\w\.\-]+\.[a-zA-Z]{2,}$/i, "")) return false;
	return true;
}

function checkFeedbackForm(){
	var required = {
		"name"		:	"Вы не ввели Ваше ФИО",
		"email"		:	"Не введен или введен некорректный e-mail",
		"msg"		:	"Вы не ввели сообщение"
	};

	for (i in required) {
		var el = document.getElementById(i);
		if(el.id == 'email' && el.value && !checkEmail(el.value)){
			alert(required['email']);
			el.focus();
			return false;
		};
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}

function checkServiseForm(){
	var required = {
		"name"		:	"Вы не ввели Ваше ФИО",
		"vin"		:	"Вы не введи VIN номер автомобиля",
		"tel"		:	"Вы не ввели телефон",
		"mod"		:	"Вы не указали молель",
		"year"		:	"Вы не указали год выпуска"
	};

	for (i in required) {
		var el = document.getElementById(i);
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}

function checkFeed(){
	var required = {
		"mes"		:	"Вы не ввели сообщение",
		"name"		:	"Вы не ввели Ваше ФИО",
		"email"		:	"Не введен или введен некорректный e-mail"
	};

	for (i in required) {
		var el = document.getElementById(i);
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
		if(el.id == 'email' && el.value && !checkEmail(el.value)){
			alert(required['email']);
			el.focus();
			return false;
		};
	}
	return true;
}


function checkStrSearch() {
	var str = document.getElementById('srch');
	if((str.value.length) < 3) {
		alert('Длина поисковой фразы должна быть больше 3 символов');
		str.focus();
		return false;
	} 
	else return true;
}

function showAnsver(id, elem){
	var div = document.getElementById(id);
	if(elem.id == 0){
		div.style.display = 'block';
		elem.id = 1;
	}
	else{
		div.style.display = 'none';
		elem.id = 0;
	}
}

function showform(elem){
	var div = document.getElementById('form_file');
	if(div.style.display == 'none') {
		div.style.display = 'block';
		elem.innerHTML = '<h2 style="padding-top: 5px;">Скрыть форму</h2>';
		return true;
	}
	if(div.style.display == 'block') {
		div.style.display = 'none';
		elem.innerHTML = '<h2 style="padding-top: 5px;">Закачать файл</h2>';
		return true;
	}
}

function checkFaqForm() {
	var required = {
		"fio"		:	"Вы не ввели Ваше имя",
		"email"		:	"Вы не ввели E-mail",
		"qw"		:	"Вы не ввели вопрос",
		"code"		:	"Вы не ввели контрольный номер либо ввели его неверно"
	};
	for (var i in required) {
		var el = document.getElementById(i);
		if(el.id == 'code' && el.value && !isFinite(el.value))
		{
			alert(required['code']);
			el.focus();
			return false;
		};
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}



function Show(fname, width, height) {
	if (screen.height<=550 && screen.width<=700) { 
		document.location = fname;
	} else {
		if(!height) height = 800;
		if(!width) width = 600;		
		newHeight = height + 20;
		PopupWin = window.open(fname, "_blank", "height="+newHeight+",width="+width+",menubar=no,status=no,titlebar=no,toolbar=no,location=no,resizable=no,scrollbars=yes"); }
	return false;
}


var isDOM = document.getElementById //DOM1 browser 
var isO   = isO5 = window.opera && isDOM; //Opera 5+
var isO6  = isO && window.print //Opera 6+
var isO7  = isO && document.readyState //Opera 7+
var isIE  = document.all && document.all.item && !isO //Microsoft Internet Explorer 4+
var isIE5 = isIE && isDOM //MSIE 5+
var isMZ  = isDOM && (navigator.appName=="Netscape")
