function Elem(sObj){
	var oElem=document.getElementById(sObj);
	if(oElem){return(oElem)}
}
jQuery.noConflict();
jQuery(function(){
	
	jQuery('li.menu-h-d-li').hover(
		function(){
			var color=jQuery(this).attr('color');
			jQuery(this).find('ul.menu-h-d-li-ul li').css('background-color',color);
			jQuery(this).css('background-color',color);
			jQuery(this).find('a.menu-h-d-a').css('color','#ffffff');
			jQuery(this).find('ul.menu-h-d-li-ul').show();
		},
		function(){
			jQuery(this).css('background','none repeat scroll 0 0 transparent');
			jQuery(this).find('a.menu-h-d-a').css('color','#333333');
			jQuery('ul.menu-h-d-li-ul','ul.menu-h-d').hide();
		}
	);
	jQuery('.menu-h-d-li-ul-li').hover(
		function(){
			var hover_color=jQuery(this).attr('hover_color');
			jQuery(this).css('background-color',hover_color);
		},
		function(){
			var color=jQuery(this).attr('color');
			jQuery(this).css('background-color',color);
		}
	)
});

/*Авторизация*/
function submitlogin(){
	var lgn=$('#lgn').val();
	var pwd=$('#pwd').val();
	var data={
		ctrl:'auth',
		cmd:'logon',
		login:lgn,
		password:pwd,
		param:Math.round(Math.random()*100000)
	}
	if(lgn!='' && pwd!=''){
		$.post("/ctrl.html",data,function(data){
			if(data=='ok'){
				document.location='/cabinet/';
			}else{
				$('#error_log').html('<div style="border: 1px solid #FF9C4F; padding: 7px 10px 7px 10px ; width: 200px;">Неверная пара логин / пароль</div>');
				$('#error_log').show();
				$('#mail_res').hide();
			}
		});
	}
}

/*Функции скрытия-появление тектса в input по умолчанию*/
function focusTxt(id,sTxt){
		if(jQuery('#'+id).val()== sTxt ){
			jQuery('#'+id).val('');
		}	
}

function blurTxt(id,sTxt){
		if(jQuery('#'+id).val()==''){
			jQuery('#'+id).val(sTxt+'');
		}
}

/*Функиця проверки пароля на совпадение и ввода обязательных полей*/
function validateFormSubmit(){
	if($('#name').val() == ''){
		$('#error').html('Введите Ваше имя');
		alert('Введите имя!');
		return false;
	};
	if($('#email').val() == ''){
		$('#error').html('Введите Ваш e-mail');
		alert('Введите e-mail');
		return false;
	};
	var password1=$('#password').val();
	var password2=$('#password2').val();
	if(password1==''){
		$('#error').html('Пароль не может быть пустым!');
		alert('Пароль не может быть пустым!');
		return false;
	}
	if(password1!=password2){
		$('#error').html('Введенные пароли не совпадают!');
		alert('Введенные пароли не совпадают!');
		return false;
	};
	if($('#postform_captcha').val() == ''){
		$('#error').html('Введите контрольные цифры');
		alert('Введите контрольные цифры');
		return false;
	};
};

function validateForgotFormSubmit(){
	if($('#email').val() == ''){
		$('#error').html('Введите Ваш e-mail');
		alert('Введите e-mail');
		return false;
	};
};

function validateChangePassSubmit(){
	if($('#password').val() == ''){
		$('#error').html('Пароль не может быть пустым');
		alert('Пароль не может быть пустым');
		return false;
	};
};

/*Функция для коректной работы hover в меню в IE6.*/
stuHover = function() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") >= 0)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var getElm = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" iehover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);


/*Ответы на вопросы викторины*/
function answer(id,iType){
	if(id && iType){
		var sValue='';
		var tre=jQuery('div.opros div.detail');
		switch(iType){
			case 1:
				var oElem=Elem('q'+id);
				if(oElem){
					sValue=oElem.value;
				}
			break;

			case 2:
				var aElems=document.getElementsByName('q'+id);
				if(aElems){
					for(var i=0;i<aElems.length;i++){
						var oElem=aElems[i];
						if(oElem.checked==true){
							sValue=oElem.value;
						}
					}
				}
			break;
		}
		if(sValue){
			var req=new JsHttpRequest();
			req.onreadystatechange = function(){
				if(req.readyState==4){
					if(req.responseJS && req.responseJS.id){
/* Тут пишем код */
						var oDiv=Elem('div_q'+req.responseJS.id);
						if(oDiv){
							oDiv.innerHTML='Спасибо за ответ!';
						}
/* Тут пишем код */
					}
				}
			}
			req.open('POST', '/ctrl/opros/update_ajax.html', true);
			req.send({id:id, iType:iType, sValue:sValue});
		}
	}
	$(tre).show();
}

///*крутилка для иконок услуг*/
//
//function x_scroll(){
//	var $slide1 = jQuery('#slideshow');
//$slide1.serialScroll({
//		prev:'#move_block a.next',
//		next:'#move_block a.prev',
//		items:'td.slide',
//		duration:2000,
//		force:true,
//		axis:'x',
//		stop:true,
//		lock:false,
//		step:1,
//		interval:5000
//	});
//}

/*отправка письма с главной*/
function sub_mail(){
	var q = jQuery('#dispatch_email').val();
	jQuery.post('/ctrl/sub_mail/index.html', {dispatch_email: dispatch_email}, function(data){
	})
}

function postform_hide(){
	var b=$('.forum_postform');
	b.hide();
}

/*Капча*/
function captcha(){
	var oElem=Elem('captcha_img');
	if(oElem){
		oElem.src='/ctrl.html?ctrl=captcha&rnd='+Math.round(10000*Math.random());
		var oElem=Elem('postform_captcha');
		if(oElem){
			oElem.value='';
		}
	}
}

/* Меню */

var timeoutMouseOut;
function show(obj,id){
	clearTimeout(timeoutMouseOut);
	jQuery(obj).find('#sub_menu_'+id).hide();
	jQuery('.sub_menu').hide();
	jQuery('.subdomain_sub_menu').hide();
	jQuery('#sub_menu_'+id).show();
}
function hide(){
	timeoutMouseOut = setTimeout("jQuery('.sub_menu').hide();jQuery('.subdomain_sub_menu').hide();",100);
}

/*карты*/

function open_win ( addr, width, height, title )
 {
 r = window.open( addr, '', "width="+width+", height="+height+", location=0, menubar=0, resizable=0, scrollbars=1, status=0, titlebar=0, toolbar=0, screenX=100, left=100, screenY=30, top=60 ");
// return r;
 }
 function openPic(image, width, height) {
	 var win;
	 if( win ) {
	 	win.close();
	 }
	 win = window.open( '', 'win', 'location=0, toolbar=0, menubar=0, scrollbars=0, height='+height+', width='+width+', status=0' );
	 win.document.write( '<html><head><title>ЯузаМоторс</title></head>' );
	 win.document.write( '<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">' );
	 win.document.write( '<a href="javascript: window.close()" title="Закрыть окно"><img src="http://www.yauzamotors.ru/'+image+'" width="'+width+'" height="'+height+'" border="0" /></a>' );
	 win.document.write( '</body></html>' );
	 win.document.close();
 }
 
	function carousel(){
		$(".main .jCarouselLite").jCarouselLite({
			btnNext: ".main .next",
			btnPrev: ".main .prev",
			mouseWheel:true,
			speed: 500,
			easing: "easeinout",
			auto:5000
		});
	}
	
	function ChangeForum(obj){
		var id = $(obj).attr('value');
//		var splits = id.split('_');
		$('#forum_id').attr('value',id);
//		$('#thread_id').attr('value',splits[1]);
	}

function checkRepair(){
	var data = {
		order_num:jQuery('#order_num').val(),
		auto_num:jQuery('#auto_num').val()
	}
	jQuery('#repair').html("<img id='wait' src='/_img/loading.gif' border='0' style='left:50%;margin-left:-16px;margin-top:-16px;position:absolute;top:50%;' />");
	jQuery.post("/repair_state.html",data,function(json){
		jQuery('#repair').html(json);
	});

};