initie6popup = function() {
	$("#popup-content h2 span").click(function(){
		$("#iepopup").hide();
	});
	
	var s = new String (window.location);
	if (s.indexOf("#") >= 0) {$('.email-price').show();};
	
	$(".coin a").click(function(){
		$('.email-price').toggle();
		return false;
	});
};
/* Ajax Loader*/
/*$('#ajaxLoader').ajaxStart(function() { 
	$('#ajaxLoader').show(); 
}); 
$('#ajaxLoader').ajaxStop(function(){ 
	$('#ajaxLoader').hide(); 
});*/

// find max number in array
MaxNumber = function(s_array){
	var s_array_width = s_array.length;
	var current_max, max = 0;
	for (i=0;i<s_array_width+1;i++){
		current_max = s_array[i];
		if (current_max > max) max = current_max;
	}
	return max;
}

function init(folder, type, color){
	$("html").css({"background":"url(/images/"+folder+"/bg."+type+") left top #"+color});
}

function ShowNextStep(i){
	$("#reg_step"+i+" .reg_buttons .right").click(
			function(){
				$(".reg_steps li").removeClass("this_step");
				$(".reg_steps li:eq("+i+")").addClass("this_step");
				$("#reg_step"+i).hide();
				$("#reg_step"+(i+1)).show();
				return false;
			}
		);
	}
function ShowPrevStep(i){
	$("#reg_step"+i+" .reg_buttons .left").click(
			function(){
				$(".reg_steps li").removeClass("this_step");
				$(".reg_steps li:eq("+(i-1)+")").addClass("this_step");
				$("#reg_step"+i).hide();
				$("#reg_step"+(i-1)).show();
				return false;
			}
		);
	}

function updateStepHeaders() {
		// пользователь
	if ( $('#ufType1').attr('checked') ) {
			// убираем шаг 3
		$('#headerStep_3').hide();
	} else {
		$('#headerStep_3').show();
	}

		// спец
	if ( $('#ufType2').attr('checked') ) {
	}

		// клиник
	if ( $('#ufType3').attr('checked') ) {
		$('#headerStep_5').show();
	} else {
		$('#headerStep_5').hide();
	}

		// бренд
	if ( $('#ufType4').attr('checked') ) {
		$('#headerStep_6').show();
	} else {
		$('#headerStep_6').hide();
	}

	var startNum = 1;
	$('.reg_steps:last li').each(function() {
		if ( this.style.display != 'none' ) {
			this.innerHTML = 'Шаг '+startNum;
			startNum++;
		}
	});
}

function initRegistration() {
	$("p.user_select").hide();
	$("p.user_select").eq(0).show();


	var cbx_flag = false;
	var cbx_flag1 = false;
	$("#ufType1, #sel_tab1").click(
		function(){
			$("p.user_select").hide();
			$("p.user_select").eq(0).show();
			$(".frame_left p").removeClass("this");
			$(this).parents("p").addClass("this");
			if(cbx_flag){
				$("p.user_select").eq(2).show();
			}
			else{
				$("p.user_select").eq(2).hide();
			}
			if(cbx_flag1){
				$("p.user_select").eq(3).show();
				$("#ufType4").attr('checked', 'checked');
			} else {
				$("p.user_select").eq(3).hide();
			}

			updateStepHeaders();
		}
	);
	$("#ufType2, #sel_tab2").click(
		function(){
			$("p.user_select").hide();
			$("p.user_select").eq(1).show();
			$(".frame_left p").removeClass("this");
			$(this).parents("p").addClass("this");
			if(cbx_flag){
				$("p.user_select").eq(2).show();
				$("#ufType3").attr('checked', 'checked');
			}
			else{
				$("p.user_select").eq(2).hide();
			}
			if(cbx_flag1){
				$("p.user_select").eq(3).show();
				$("#ufType4").attr('checked', 'checked');
			} else {
				$("p.user_select").eq(3).hide();
			}

			updateStepHeaders();
		}
	);
	$("#ufType3, #sel_tab3").click(
		function(){
			if($("#ufType3").is(":checked")){
				cbx_flag = true;
				$("p.user_select").eq(2).show();
			}
			else{
				cbx_flag = false;
				$("p.user_select").eq(2).hide();
			}

			updateStepHeaders();
		}
	);
	$("#ufType4, #sel_tab3").click(
		function(){
			if($("#ufType4").is(":checked")){
				cbx_flag1 = true;
				$("p.user_select").eq(3).show();
			}
			else{
				cbx_flag1 = false;
				$("p.user_select").eq(3).hide();
			}

			updateStepHeaders();
		}
	);

	if ( $('#ufType1').attr('checked') )
		$("p.user_select").eq(0).show();
	else
		$("p.user_select").eq(0).hide();
	if ( $('#ufType2').attr('checked') )
		$("p.user_select").eq(1).show();
	else
		$("p.user_select").eq(1).hide();
	if ( $('#ufType3').attr('checked') ) {
		$("p.user_select").eq(2).show();
		cbx_flag = true;
	} else {
		$("p.user_select").eq(2).hide();
		cbx_flag = false;
	}
	if ( $('#ufType4').attr('checked') ) {
		$("p.user_select").eq(3).show();
		cbx_flag1 = true;
	} else {
		$("p.user_select").eq(3).hide();
		cbx_flag1 = false;
	}

	updateStepHeaders();
}


$(document).ready(
	function(){
		initie6popup();
	
		$(".tabs_bottom a").click(
			function(){
				var href_tb = $(this).attr("href");
				
				length_tb = $(this).parents(".tabs_bottom").children("li").length;
				$(this).parents(".tabs_bottom").children("li").removeClass("active")
				$(this).parent("li").addClass("active");
				
				for (i=1;i<=length_tb;i++){
					$(this).parents(".for_tabs_bottom").find(".tab"+i).hide();
				}
				
				$(this).parents(".for_tabs_bottom").find(".tab"+href_tb).show();
				
				return false;
			}
		);
	
		var ul_li_count = new Array();
		var ul_length = 0;
		//Define NewsSliderWidth
		$(".with_slider ul").each(
			function(i){
				ul_li_count[i] = $(".with_slider ul").eq(i).children("li").length;
				if (ul_li_count[i] == 1) ul_li_count[i] = 0;
				$(".with_slider").find("ul").eq(i).css("width", (ul_li_count[i]+1)*290);
			}
		);

		//$(".reg_form_show").fancybox({'frameWidth':860, 'frameHeight':640});
		
		$("a.shmi").click(
			function(){
				$(".PDiv").hide();
				$(this).parents("td").find(".PDiv").show();
				return false;
			}
		);
		$(".close_form a").click(
			function(){
				$(this).parents("td").find(".PDiv").hide();
				return false;
			}
		);
		
		$("#search_words").find("input.text[value='']").attr("value","Поисковые слова в названии");
		$("#search_words").find("input.text").focus(
			function(){
				if ($(this).attr("value") == 'Поисковые слова в названии')
					$(this).attr("value","");
			}
		);
		$("#search_words").find("input.text").blur(
			function(){
				if ($(this).attr("value") == '')
					$(this).attr("value","Поисковые слова в названии");
			}
		);
		
		$(".show_hide h2 span").click(
			function(){
				$(this).parents(".show_hide").toggleClass("active");
			}
		);
		
		/*if ($(".slider_content td").length <= 6){
			$(".scrollbar").hide();
		}*/


		$("a.ask_question").click(
			function(){
				$("#question_popup_form_overlay").show();
				$("#question_popup_form").show();
				return false;
			}
		);
	
		$("#question_popup_form_close").click(
			function(){
				$("#question_popup_form_overlay").hide();
				$("#question_popup_form").hide();
			}
		);

			/* Events calendar */
		/** Replaced to /bitrix/php_interface/ExBitrix/public/js/form.js in docReady function **/
	}
);



function checkNameField ( form ) {
	$(form).find("input.text[value='Поисковые слова в названии']").attr("value","");
}
