﻿
	var panel_visible = 0;
	var namemarca = "";
	var name_marca = "";
	var name_model = "";
	var name_price = "";
	var name_god = "";
	var price_scroll = 0;
	var change_f = 0;
	var fz = 0;
	var fest_change_addvod = 0;
	var mx;
	var my;	
	var par_show_list_year = 0;	
	
	function show_marcaseach()
	{		
		$("#marcaseach").val(name_marca+"   "+name_model+"    ");
		
		if(name_god>"")
			$("#marcaseach").val($("#marcaseach").val()+name_god+" года    ");		
				
		if(name_price>"")
			$("#marcaseach").val($("#marcaseach").val()+name_price+"  руб.");
			
		$("#car_marka").val(name_marca);
		$("#car_model").val(name_model);
		$("#car_year").val(name_god);
		$("#car_price").val(name_price);
	}
	
	function shcon()
	{	
		$("#voditel").css({ display:"none" });
		$("#col_contact").addClass("activ");
		select_contact();
	}
	
	function addvod2()
	{
		$("#col_signal").addClass("activ");
		$("#sig").css({ display:"none" });
		$("#col_voditel").addClass("activ");
		$("#voditel").css({ display:"block" });
	}
	
	function dalee3()
	{
		$("#col_contact").addClass("activ");
		$("#voditel").css({ display:"none" });
		$("#contact").css({ display:"block" });
	}
	
	var pazzap = 0;
	function submintrun()
	{			

	}
	var colvod = 0;
	
	function delvod()
	{
		 $('#v'+$(this).attr("id")).empty();
	}
	function addvod()
	{	
		colvod++;
		
		var temp = $("#voditel #field").html();	
		temp = temp+$("#voditel_add").html();
		$("#voditel #field").append('<tr><td colspan="3" id="vod'+colvod+'">'+$("#voditel_add").html()+'<div class="psevdolink" id="od'+colvod+'"><img src="images/del.png"></div></td></tr>');
		$('#'+'od'+colvod).click(delvod);

		
		name_price = $("#fieldprice").attr("value");
		show_marcaseach();
	}
	function check(inputCode) {
  var ok = true;
  for (var i = 0; i < inputCode.length; i++) {
    var chr = inputCode.charAt(i);
    var found = false;
    for (var j = 1; j < check.length; j++) {
      if (chr == check[j]) found = true;
    }
    if (!found) ok = false;
  }
return ok;
}

	var tooo = 0;
var reg_mail = /[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i;	
var reg_tel = /[0-9, +]{7,15}/;
	function change_namem()
	{	
		/*if (reg_tel.exec($("#contact #namet").val()) == null) {
			alert("Ошибка ввода номера телефона");		
		}*/
	
		if(reg_mail.exec($("#contact #namem").val()) == null)
		{
			//alert('Ошибка ввода e-mail');
		}
		else
		{
			change_f ++;

		}
		show_bg_gozak();
	}
	
	function change_namet()
	{
		/*if(reg_mail.exec($("#contact #namem").val()) == null)
		{
			alert('Ошибка ввода e-mail');
		}*/
		var str = $("#contact #namet").val();
		if (reg_tel.exec(str) == null) {
			//alert("Ошибка ввода номера телефона");		
		}
		else
		{
			change_f ++;
		}
		show_bg_gozak();
	}
	function change_namep()
	{	
		change_f ++;
show_bg_gozak();
	}
	
	function show_bg_gozak()
	{

var str = $("#contact #namet").val();str=str.substr(5,3)+str.substr(9,2)+str.substr(12,2);
		if(reg_mail.exec($("#contact #namem").val()) != null && reg_tel.exec(str) != null && $("#contact #namep").val()!='' && $("#contact #namep").val()!='Ваше имя' && str != '1234567' && str != '7654321' && str != '1111111' && str != '0000000' && str != '2222222' && str != '3333333' && str != '4444444' && str != '5555555' && str != '6666666' && str != '7777777' && str != '8888888' && str != '9999999' && ($('#idplanBuy').val() != 'buy_0') && ($('#idplanBuy').val() != ''))
		{
			$(".zakaz input").css({"background-image": "url(images/btnnew.png)"});
			$(".zakaz input").css({ cursor:"pointer" });
		}
	}
	
	function change_field()
	{
var str = $("#contact #namet").val();str=str.substr(5,3)+str.substr(9,2)+str.substr(12,3);
		if((reg_mail.exec($("#contact #namem").val()) != null) && (reg_tel.exec(str) != null) && (str !='') && (str != '1234567') && (str != '7654321') && (str != '1111111') && $("#contact #namep").val()!='' && $("#contact #namep").val()!='Ваше имя' && (str != '2222222') && (str != '0000000') && (str != '3333333') && (str != '4444444') && (str != '5555555') && (str != '6666666') && (str != '7777777') && (str.length == 7) && (str != '8888888') && (str != '9999999') && ($('#idplanBuy').val() != 'buy_0') && ($('#idplanBuy').val() != ''))
		{		
			//alert("Заказ отправлен");
			//alert(str);
			document.getElementById("submit1").submit();
			//submit();
		}
		else
		{
			var s= 'Ошибка ввода: '
			if(reg_mail.exec($("#contact #namem").val()) == null)
			s= s+' "e-mail"';
			if(reg_tel.exec(str) == null || str == '1234567' || str == '7654321' || str == '1111111' || str == '2222222' || str == '3333333' || str == '4444444' || str == '5555555' || str == '6666666' || str == '7777777' || str == '0000000' || str == '8888888' || str == '9999999'|| (str.length != 7) )
			s= s+' "номер телефона"';
			if(($("#contact #namep").val()=='') || ($("#contact #namep").val()=='Ваше имя'))
			s= s+' "имя"';
			if (($('#idplanBuy').val() == 'buy_0') || ($('#idplanBuy').val() == ''))
			s= s+' "оформление полиса"';
			alert(s);
		}

	}
	
	var field1 = 0;
	function clear_field1()
	{
		if(field1 == 0)
		{
			$(this).attr({value: ""});
			$(this).focus();
			field1 = 1;
		}
	}
	
	var field2 = 0;
	function clear_field2()
	{
		if (document.getElementById('namep').value == '') {document.getElementById('namep').value='Ваше имя';field2=0;}
		if (document.getElementById('namet').value == '') {document.getElementById('namet').value='Телефон';field3=0;}
		if (document.getElementById('namem').value == '') {document.getElementById('namem').value='E-mail';field4=0;}
		if(field2 == 0)
		{
			$(this).attr({value: ""});
			$(this).focus();
			field2 = 1;
		}
	}
	
	var field3 = 0;
	function clear_field3()
	{
		if (document.getElementById('namep').value == '') {document.getElementById('namep').value='Ваше имя';field2=0;}
		if (document.getElementById('namet').value == '') {document.getElementById('namet').value='Телефон';field3=0;}
		if (document.getElementById('namem').value == '') {document.getElementById('namem').value='E-mail';field4=0;}
		if(field3 == 0)
		{
			$(this).attr({value: ""});
			$(this).focus();
			field3 = 1;
		}
	}
	var field3_2 = 0;
	function clear_field3_2()
	{
		if (document.getElementById('namep').value == '') {document.getElementById('namep').value='Ваше имя';field1=0;}
		if (document.getElementById('namet').value == '') {document.getElementById('namet').value='Телефон';field2=0;}
		if (document.getElementById('namem').value == '') {document.getElementById('namem').value='E-mail';field3=0;}
		if(field3_2 == 0)
		{
			$(this).attr({value: ""});
			$(this).focus();
			field3_2 = 1;
		}
	}
	
	var field4 = 0;
	function clear_field4()
	{
		if (document.getElementById('namep').value == '') {document.getElementById('namep').value='Ваше имя';field2=0;}
		if (document.getElementById('namet').value == '') {document.getElementById('namet').value='Телефон';field3=0;}
		if (document.getElementById('namem').value == '') {document.getElementById('namem').value='E-mail';field4=0;}
		if(field4 == 0)
		{
			$(this).attr({value: ""});
			$(this).focus();
			field4 = 1;
		}
	}
	
	var field5 = 0;
	function clear_field5()
	{
		if(field5 == 0)
		{
			$(this).attr({value: ""});
			$(this).focus();
			field5 = 1;
		}
	}
	
	function hide_all()
	{
		$("#panel #price").css({ display:"none" });	
		$("#panel #year").css({ display:"none" });
		$("#panel #marca").css({ display:"none" });
		$("#panel #model").css({ display:"none" });
		$("#panel #sig").css({ display:"none" });
		$("#panel #voditel").css({ display:"none" });
		$("#panel #contact").css({ display:"none" });
	$("#params").hide(0);
	$("#params2").hide(0);
	$("#params3").hide(0);
	}
	
	function show_list_price()
	{
		hide_all();
		if($("#panel #price").css("display") == "none")
			$("#panel #price").css({ display:"inline" });
		else
			$("#panel #price").css({ display:"none" });	
	}	
	
	var par_show_list_price = 0;	
	
	function show_fieldprice()
	{
		$("#col_signal").addClass("activ");
				name_price = $("#fieldprice").attr("value");
		show_marcaseach();
		//$("#panel #price .title").html("Цена: "+$("#panel #price #fieldprice").val());
		if(par_show_list_price == 0)
		{
			$("#panel #price .title").click(show_list_price);	
			par_show_list_price =1;
		}
		
		$("#panel #price").css({ display:"none" });	
	}

	function select_sig()
	{
	
		if (((document.getElementById("fieldprice").value) >= 15000) && ((document.getElementById("fieldprice").value) <= 15000000) ) {
		$("#col_signal").addClass("activ");
		name_price = $("#fieldprice").attr("value");
		show_marcaseach();
		hide_all();
		$("#sig").show(1);	
	}
	}
	
	function click_price()
	{
		if (((document.getElementById("fieldprice").value) >= 15000) && ((document.getElementById("fieldprice").value) <= 15000000) ) {
			$("#dalee").css({"background-image": "url(images/dalee000.png)"});
		} else {
			$("#dalee").css({"background-image": "url(images/dalee200.png)"});
		}
	}	
	
	function select_contact()
	{
		
		$("#contact").show(1);

		
		

		
		$("#price #fieldprice").mousedown(clear_field1);
		$("#contact #namep").mousedown(clear_field2);
		$("#contact #namet").mousedown(clear_field3);
		$("#contact #namet2").mousedown(clear_field3_2);	
		$("#contact #namem").mousedown(clear_field4);	
		$("#chek9 #bkred").mousedown(clear_field5);	
		
		name_price = $("#fieldprice").attr("value");
		show_marcaseach();
	}
	
	function show_list_year()
	{
		par_show_list_year = 1;
		hide_all();
		if($("#panel #year").css("display") == "none")
			$("#panel #year").css({ display:"block" });
		else
			$("#panel #year").css({ display:"none" });
	}	
	
	function show_list_signal()
	{
		hide_all();
		if($("#panel #sig").css("display") == "none")
			$("#panel #sig").css({ display:"block" });
		else
			$("#panel #sig").css({ display:"none" });
	}	
	
	function select_price()
	{
		$("#col_price").addClass("activ");
		$("#price").show(0);
		
		//$("#panel #year .title").html("Год выпуска: "+$(this).html());
		
		if(par_show_list_year == 0)
			$("#panel #year .title").click(show_list_year);

		
		$("#panel #year").css({ display:"none" });
		
		$("#price #fieldprice").mousedown(clear_field1);
		$("#contact #namep").mousedown(clear_field2);
		$("#contact #namet").mousedown(clear_field3);	
		$("#contact #namem").mousedown(clear_field4);	
		$("#chek9 #bkred").mousedown(clear_field5);	
		
		$("#sig li").click(show_fieldprice);

		$("#fieldprice").mousedown(click_price);
		$("#fieldprice").mousemove(click_price);
		$(this).css({  fontWeight:"bolder", color:"#000"  });

		name_god = $(this).html();

		$("#panel #year li").click(function(){
											name_god = $(this).html();
											$("#panel #year ul li").css({  fontWeight:"normal", color:"#636365"  });
											$(this).css({  fontWeight:"bolder", color:"#000"  });
											show_marcaseach();
											});
		$("#panel #model li").click(function(e){
											name_model = $(this).html();
											$("#panel #model ul li").css({  fontWeight:"normal", color:"#636365"  });
											$(this).css({  fontWeight:"bolder", color:"#000"  });
											show_marcaseach();
											});
		show_marcaseach();
	}	
	var par_show_list_model = 0;
	function show_list_model()
	{
		par_show_list_model = 1;
		hide_all();
		if($("#panel #model").css("display") == "none")
			$("#panel #model").css({ display:"block" });
		else
			$("#panel #model").css({ display:"none" });
	}
	function select_year()
	{
		$("#col_year").addClass("activ");
	$("#params").hide(0);
	$("#params2").hide(0);
	$("#params3").hide(0);
		//$("#panel #model .title").html("Модель: "+$(this).html());
		
		if(par_show_list_model == 0)
			$("#panel #model .title").click(show_list_model);
		
		$("#panel #model").css({ display:"none" });
		$("#year").show(0);	
		$(this).css({  fontWeight:"bolder", color:"#000"  });

		name_model = $(this).html();
		
		$("#year li").click(select_price);
		name_god = $("#year li").html();
		show_marcaseach();
	}	
	var par_show_list_marca = 0;
	function show_list_marca()
	{
		par_show_list_marca = 1;
		hide_all();
		if($("#panel #marca").css("display") == "none")
		{
			$("#panel #marca").css({ display:"block" });
		}
		else
			$("#panel #marca").css({ display:"none" });
	}		
	function select_marca(car)
	{
		namemarca = car;	
		$("#col_model").addClass("activ");
	//	$("#marca").hide(1);
		
		//$("#panel #marca .title").html("Марка: "+$("#marca #c"+car).html());
		$("#model div").css({ display:"none" });
		if(par_show_list_marca == 0)
			$("#panel #marca .title").click(show_list_marca);
		
		$("#panel #marca").css({ display:"none" });
		
		$("#model").show(1);
		$("#model .title").show(1);
		$("#"+car).show(1);	
		name_marca = $("#marca #c"+car).html();
		$("#"+car+" li").click(select_year);
		show_marcaseach();
	}
	function show_panel_key()
	{
		if(panel_visible == 0){			 		 
        	$("#panel").show(1);
			panel_visible = 1;	
		}

		goto_panel_html();
	}	
	
	function show_panels()
	{
		if(fz==0)
		{
			if(panel_visible == 0)
			{
				$("#panel").show(1);
				panel_visible = 1;
			}
			goto_panel_html();
			
			fz = 1;
		}
	}
	
	function goto_panel_html()
	{	$("#marca").show(0);
		$("#model").hide(0);
		$("#price").hide(0);	
		$("#contact").hide(0);
		$("#sig").hide(0);
		$("#year").hide(0);
		
		$("#voditel").hide(0);
		$("#chek9").hide(0);
		$("#model div").css({ display:"none" });
	}
	function chec_c1(chek)
	{
	 	if($("#"+chek).attr("checked"))
		{
			$("#"+chek).removeAttr("checked");
			$("#"+chek).val("checked");
		}
 		else{
			
 			$("#"+chek).attr("checked","checked");
			$("#"+chek).val("checked");
			}
		
	}
	
	function chec_c2(chek)
	{
	 	if($("#"+chek).attr("checked"))
		{
			$("#"+chek).removeAttr("checked");
			$("#chek9").hide(0);
		}
 		else
		{
 			$("#"+chek).attr("checked","checked");
			$("#chek9").show(0);
		}
	}
	
	function chec_c3()
	{
		
	 	if($("#chek8").attr("checked"))
		{
				$("#chek9").show(0);
				$("#chek8").val("checked");
			
		}
 		else
		{	
			$("#chek9").hide(0);
			$("#chek8").val();
		}
	}
	
	function show_myp()
	{
		if($(this).hasClass("activ"))
		{
			var idobj = $(this).attr("id");
			
			if(idobj == 'col_marca')
				show_list_marca();
				
			if(idobj == 'col_model')
				show_list_model();
				
			if(idobj == 'col_year')
				show_list_year();
				
			if(idobj == 'col_price')
				show_list_price();
				
			if(idobj == 'col_signal')
				show_list_signal();
			
		}

	}
	
	function showparams() {
		$("#marca").hide(0);
	$("#col_model").addClass("activ");
		$("#params").show(0);
	}
	function showparams2() {
		$("#marca").hide(0);
	$("#col_model").addClass("activ");
		$("#params2").show(0);
	}
	function showparams3() {
		$("#marca").hide(0);
	$("#col_model").addClass("activ");
		$("#params3").show(0);
	}
	function paramsreset1() {
	if (document.getElementById('fieldparams1').value == '') document.getElementById('fieldparams1').value = '(введите марку)';
	if (document.getElementById('fieldparams2').value == '') document.getElementById('fieldparams2').value = '(введите модель)';
	}
	function paramsreset2() {
	if (document.getElementById('fieldparams3').value == '') document.getElementById('fieldparams3').value = '(введите марку)';
	if (document.getElementById('fieldparams4').value == '') document.getElementById('fieldparams4').value = '(введите модель)';
	if (document.getElementById('fieldparams5').value == '') document.getElementById('fieldparams5').value = '(кол-во мест)';
	}
	function paramsreset3() {
	if (document.getElementById('fieldparams6').value == '') document.getElementById('fieldparams6').value = '(введите марку)';
	if (document.getElementById('fieldparams7').value == '') document.getElementById('fieldparams7').value = '(введите модель)';
	if (document.getElementById('fieldparams8').value == '') document.getElementById('fieldparams8').value = '(грузоподъемность)';
	}
$(document).ready(function(){	   

	//$("#panel").hide(0);
	$("#panel_html").hide(0);	
	$("#model").hide(0);
	$("#params").hide(0);
	$("#params2").hide(0);
	$("#params3").hide(0);
	$("#price").hide(0);	
	$("#sig").hide(0);
	$("#year").hide(0);
	$("#voditel").hide(0);
	$("#chek9").hide(0);
	$("#contact").hide(0);
	$("#marca").show(0);
	$("#col_marca").addClass("activ");
	
	function show_panel()
	{
		panel_visible = 0;
		namemarca = "";
		name_marca = "";
		name_model = "";
		name_price = "";
		name_god = "";
		price_scroll = 0;
		change_f = 0;
		fz = 0;
		fest_change_addvod = 0;	
		
		
		
		$("#marcaseach").val("Выберите автомобиль");
		
		if(panel_visible == 0){			 
			panel_visible = 1;			 
        	$("#panel").show(1);
		}
		else
		{
			$("#panel").hide(1);
	 		panel_visible = 0;
		}
		goto_panel_html();
	}	

	function code_validate() {
		var str = ($('#namet').attr("value"));
		if ((str.length == 3) && (str.substr(0,1) != '(')) {
			document.getElementById('namet').value = ('('+str.substr(0,1)+str.substr(1,1)+str.substr(2,1)+')');
		}
		if ((str.length == 8) && (str.substr(7,1) != '-')) {
			document.getElementById('namet').value = str + '-';
		}
		if ((str.length == 11) && (str.substr(10,1) != '-')) {
			document.getElementById('namet').value = str + '-';
		}
	}
	
	//$("#marca").hide(0);
	$("#col_marca").click(show_myp);
	$("#col_model").click(show_myp);
	$("#col_year").click(show_myp);
	$("#col_price").click(show_myp);
	$("#col_signal").click(show_myp);
	$("#namet").keypress(code_validate);
	$("#contact #namem").change(change_namem);
	$("#contact #namet").change(change_namet);
	$("#contact #namep").change(change_namep);
    $("#btn").click(show_panel);	
	$("#contact").mousemove(show_bg_gozak);	
	$("#gozak").mousemove(show_bg_gozak);
    $("#gozak").click(change_field);
});	

