$(document).ready(function(){
	//$(".login1").css("display","block");
	//$(".login2").css("display","none");
	if($('.checkbox_bg input').val()=="on"){
		$(".checkbox_bg").css("background","url(/bitrix/templates/sushi/images/checkbox_selected.gif) no-repeat center");
	}
	else{
		$(".checkbox_bg").css("background","url(/bitrix/templates/sushi/images/checkbox.gif) no-repeat center");
	}
	
	$('.checkbox_bg').click(function() {
		if($('.checkbox_bg input').val()=="on"){
			$('.checkbox_bg input').val("off");
			$(".checkbox_bg").css("background","url(/bitrix/templates/sushi/images/checkbox.gif) no-repeat center");
		}
		else{
			$('.checkbox_bg input').val("on");
			$(".checkbox_bg").css("background","url(/bitrix/templates/sushi/images/checkbox_selected.gif) no-repeat center");
		}
	});
	
});

$(document).ready(function() {
$("a:contains('Под заказ')").parent("div.btn_to_basket_bg").addClass("green_to_basket_bg");
});

$(document).ready(function() {
$("a:contains('отсутствует')").parent("div.btn_to_basket_bg").addClass("green_to_basket_bg1");
});

$(document).ready(function() {
$("a:contains('О НАС')").parent("ul.top_menu").addClass("left_child");
});

$(document).ready(function() {
$("a:contains('ПОСУДА')").parent("li").addClass("hidden");
});

function simple_tooltip(target_items, name, what,el_width,new_name){
 $(target_items).each(function(i){
 $("body").append("<div class='tooltip' id='"+new_name+"'><p>"+$("."+what).html()+"</p></div>");
 var my_tooltip =$("#"+new_name);

 $(this).removeAttr("title").mouseover(function(){
 my_tooltip.css({opacity:1, display:"none"}).fadeIn(1);
 }).mousemove(function(kmouse){
 var offset=15;
 if(kmouse.pageX+offset>1000-el_width){
	offset=-el_width;
 }
 my_tooltip.css({left:kmouse.pageX+offset, top:kmouse.pageY+15});
 
 
 }).mouseout(function(){
 my_tooltip.fadeOut(1);
 });
 });
}
$(document).ready(function(){
 //simple_tooltip(".delivery_href","tooltip","popup_delivery",500);
});

//функция для проверки обязательных полей заказа
function checkFields() {
	var res = true;
	if(getIdStep('current') == 'step2') {
		var orderForm = $('#ORDER_FORM_ID_NEW');
		if(!$('#ORDER_FORM_ID_NEW select[name=COUNTRY_ORDER_PROP_1] option:selected').val()) {
			alert('не заполнено поле "Местоположение"');
			res = false;
		}
		if(!$('#ORDER_FORM_ID_NEW select[name=ORDER_PROP_1] option:selected').val()) {
			alert('не заполнено поле "Город"');
			res = false;
		}
		if(!$('#ORDER_FORM_ID_NEW textarea[name=ORDER_PROP_5]').val()) {
			alert('не заполнено поле "Адрес доставки"');
			res = false;
		}
	}
	return res;
}
//функция для отображения и скрытия шагов заказа
function hideSteps(id) {

		$('.step-order').hide();
		$(id).fadeIn(600);
		$('.steps-order .step').removeClass('current-step');
		$('.steps-order .step[href="'+id+'"]').addClass('current-step active-step');
	return true;
}

//функция для определения id текущего или следующего шага
function getIdStep(typestep) {

	var curindex = $('.step-order').index( $('.step-order:visible')[0]);
	
	if(curindex >= 0 && curindex <=4) {
		if(typestep == 'next') {
			var IdStep = $('.step-order').eq(curindex+1).attr('id');
		}else{
			var IdStep = $('.step-order').eq(curindex).attr('id');
		}
	}else{
		return false;
	}
	
	return IdStep;
}

//Разделение формы заказа на шаги
$(function() {
	
	$('.steps-order .step[href="#step1"]').addClass('current-step active-step');
	$('.step-order').hide();
	$('#step1').show();
		
	$('#next-step, .steps-order .active-step').live('click', function(){
	
		if($(this).attr('id') == 'next-step') {
			if(!checkFields()) {
				return false;
			}
		}
		var nextStepId = getIdStep('next');
		if(nextStepId) {
			$('#next-step').attr('href', "#"+nextStepId);
		}
		hideSteps($(this).attr('href'));
		return false;
	});
	
});
	
//обработчик результата ajax-запроса формы заказа
function handlerForm(data) {
	
	var currentid = getIdStep('current');
	$('#order_form_div').replaceWith(data);
	hideSteps("#"+currentid);
	return true;
}
