  
  $(window).resize(function(){
		header();				
	}); 
  
 $(document).ready(function(){
		//hovers();
		header();
		pictures();
		test_form();
		send_test_results();
		$.updnWatermark.attachAll();		 
	});
 
 function hovers(){
	 	$(".menu li").hover(function(){
			cls = $(this).attr("class");
			if(cls.indexOf('first')!=-1) {$(this).addClass('l_hover')}
			else if(cls.indexOf('last')!=-1) {$(this).addClass('r_hover')}
			else {$(this).addClass('hover')}			
		 },
		function(){
			$(this).removeClass('hover');
			$(this).removeClass('l_hover');
			$(this).removeClass('r_hover');
		});		
		$(".menu li.first.active").attr("class","l_active");
		$(".menu li.last.active").attr("class","r_active");
	 }
	 
 function header(){
	 	w = $(".background").width();
		if(w>1020) $(".header .grad").css("display","block");
		else $(".header .grad").css("display","none");
	 }
 function pictures(){
		if($(".contentdiv img[align=left]").length) $(".contentdiv img[align=left]").addClass('pic_l');
		if($(".contentdiv img[align=right]").length) $(".contentdiv img[align=right]").addClass('pic_r');
	 }
 function test_form(){
		$(".test_form .step1 .s1_next").click(function(){
			if($(".test_form .step1 td .starrequired").parents("tr").find(".input_text[value='']").length==0){
				$(".test_form").addClass("tf_s2");
			} else {
				$(".test_form .step1").addClass("show_err");				
			}
		});
		
		$(".test_form .input_variant .chbox input").change(function(){
			$(this).parents(".input_variant").find(".input_text").attr("value",$(this).val());
			getTestFinal();
	    });
		
		$(".test_form .step2 .s2_prev").click(function(){
			$(".test_form").removeClass("tf_s2");
	    });
		
		$(".test_form .step2 .s2_next").click(function(){				
			//l=0;
			test = getTestFinal();
			/*radio = $(".test_form .step2 td.t_radio");
			if(radio.length) {
				for(i=0;i<radio.length;i++) {
					if($(radio[i]).find('input[type=radio][checked]').length==0) l++;
					}
				}*/
				
			if(test) {
					/*if(test<=1.4) message = "Вероятно, у Вас имеются незначительные нарушения зубочелюстной системы";
					if(test>1.4) message = "Вероятно, Вы имеете значительные нарушения зубочелюстной системы.  Вам необходимо обратиться за помощью к специалисту";
					if(message) {
						$(".test_form .step3 .step3_result div").html(message);
						$(".test_form .step3 .step3_result").css('display','block');
					}				                                    */
					$(".test_form").addClass("tf_s3");
			}
			else {
					$(".test_form .step2").addClass("show_err");
				}
	    });
		function getTestFinal(){
			l=0;
			test=0;
			it = $(".test_form .step2 tr[class!='final'] td .input_text");
			if(it.length) {
				for(i=0;i<it.length;i++) {
						if($(it[i]).attr("value")>=0&&$(it[i]).attr("value")<=3&&$(it[i]).attr("value")) {test+=$(it[i]).attr("value")*1}
						if($(it[i]).parents(".input_variant").find('input[type=radio][checked]').length==0) l++;
						//else {l++;}
					}				
				}			
			test = test/it.length;	
			$(".test_form .formtab tr.final td .input_text").attr("value",test);
			if(l==0) return test; else return false;
		}		
		$(".test_form .step3 .chbox input").change(function(){
			l=0;
			radio = $(".test_form .step3 td.t_radio");
			if(radio.length) {
				for(i=0;i<radio.length;i++) {
					if($(radio[i]).find('input[type=radio][checked]').length==0) l++;
					}
				}	
			if(l) {
					$(".test_form img.submit").css("display","block");
					$(".test_form input.tf_submit").css("display","none");
				}
			else {
					$(".test_form img.submit").css("display","none");
					$(".test_form input.tf_submit").css("display","block");
				}
		});
		$(".test_form img.submit_dis").click(function(){
			$(".test_form .step3").addClass("show_err");
		});
		
	}
	function send_test_results(){
		$(".send_results .button").click(function(){
				url = '/include/send_test_results.php';
				id=$(this).parents(".send_results").find(".id").html();
				email=$(this).parents(".send_results").find(".input_email").val();
				$.get(url,{id:id,email:email}, function(data){
						if(data.indexOf('message')!=-1) $(".send_results .input_email,.send_results .button").css('display','none');
						$(".send_results .answers").html(data);
						$(".send_results .answers").css('display','block');
					});				
		});
	}
