function showWait(){return '<span class="wait">Подождите...</span>';}
function showWaitNotext(){return '<span class="wait"></span>';}
function showWaitNoFlow(){return 'Подождите...';}

function citySelect(){
	$(".choosen_city:last").after('<div id="city_chooser"></div>');
	$(".choosen_city").hide();
	$("#city_chooser").html(showWait());

	$.post("../ajax/city_choose.php",
	function(data){
		$("#city_chooser").html(data);
		$(".city").hide();
	});
}

function showCitySelector(sclass){
	$("[name='city']").remove();
	var region=$("#region").attr('value');
	if(region){
		$("#region").after(showWait());
		$.post("../ajax/city_choose.php", {"region":region, "class":sclass},
		function(data){
			$(".wait").remove();
			$("#region").after(data);
			$("select[name='city']").bind("change", function(){
	      		$("#citySelectForm").submit();
	    	});
		});
	}
}

function winop(page, w, h, s) {
	popupWin=window.open(page, "win", "width="+w+", height="+h+", left=40, top=40, scrollbars="+s);
	popupWin.focus();
	return false;
}

function hide(id){$("#"+id).hide();}
function show(id){$("#"+id).show();}
function sel(id){id.value="";}

function manage_myth_note(){
	if($("#myThecus #note").css('display')=='none'){
		show('myThecus #note');
		$.post("../ajax/manage_myth_note.php", {"show":1});
		$("#myThecus #note_lnk a").text('Скрыть этот текст');
	}else{
		hide('myThecus #note');
		$.post("../ajax/manage_myth_note.php", {"show":0});
		$("#myThecus #note_lnk a").text('Показать описание раздела');
	}
}

function respFormSubm(){
	$("#formNotify").html(showWait());
	$("#resp_form").attr("action", "../ajax/resp_form_check.php");
	$("#resp_form").ajaxSubmit(function(data){
		$("#formNotify").html('OK, sending...');
		if(data==1){
				$("#resp_form").attr("action", "../ajax/show_responses.php");
				$("#resp_form").ajaxSubmit(function(data){
					$("#resp_form").attr("action", "");
					$("#responses").html(data);
					$("#formNotify").text('');
					$("textarea").attr('value', '');
					$(".rctr").hide();
				});
			}else{
				$("#formNotify").html(data);
			}
		});
}

function switch_fe(){
	if($("#fight_elephant").css('display')=='none'){
		$("#fight_elephant").css('background-image', 'url('+fe_preload.src+')');
		$("#fight_elephant").css('display', 'block');
		$("#last_z1").attr('value', $("#z1").text());
		$("#last_z2").attr('value', $("#z2").text());
		$("#z1").html('<span style="background:#000;color:#fff;">I`ll catch <span style="color:red;">YOU!</span></span>');
		var js="'../pages/fe.html', 420, 341, 0";
		$("#z2").html('<span style="background:#000;color:#fff;">Everywhere!</span> <a href="javascript:void(0);" onClick="winop('+js+');">+ video</a>');
	}else{
		$("#fight_elephant").css('display', 'none');
		$("#z1").text($("#last_z1").attr('value'));
		$("#z2").text($("#last_z2").attr('value'));
	}
}

function prodRegFormSubm(){	
	var end_step=5;
	var step=Math.round($("[name='step']").attr('value'));
	
	$("#formNotify").html(showWait());
	
		$("#prod_reg_form").attr("action", "../ajax/prod_reg_form_check.php");
		$("#prod_reg_form").ajaxSubmit(function(data){
			if(data==1){
				$("#consolidation").html(showWait());
				$("#prod_reg_form").attr("action", "../ajax/prod_reg_form_consolidation.php");
				$("#prod_reg_form").ajaxSubmit(function(data){
					$("#consolidation").html(data);
					
					if(step<end_step){
						$("input[id='next']").attr('value', 'Продолжить');
						step++;
						if((step==3) && $("input[name='rcode']").attr('value')){step++;}
							$("[name='step']").attr('value', step);
							if(step>1){
								$("#prev").show();
								$("#step"+(step-1)).hide();
								if(step==end_step){$("input[id='next']").attr('value', 'Готово');
								$("#end_step").show();
							}	
						}
						$("#step"+step).show();
						$("#formNotify").text('');
					}else if(step==end_step){
						step++;
						$("[name='step']").attr('value', step);
						prodRegFormSubm();
					}else{
						$("#formNotify").html('OK, sending...');
						$("#prod_reg_form").attr("action", "../ajax/prod_reg_form_send.php");
						var options = { 
						success: showResponse,
						dataType: 'json'
						};
						$('#prod_reg_form').ajaxSubmit(options); 
					}
					
				});
			}else{
				$("#formNotify").html(data);
			}
		});
}

function showResponse(responseText, statusText){
		$("#rc").remove();
		$("#regTd").html(responseText.text);
}


function prodRegFormPrev(){
	var step=Math.round($("[name='step']").attr('value'));
	$("input[id='next']").attr('value', 'Продолжить');
	$("#end_step").hide();
	$("#step"+step).hide();
	$("#formNotify").text('');
	step--;
	if((step==3) && $("input[name='rcode']").attr('value')){step--;}
	$("#step"+step).show();
	$("[name='step']").attr('value', step);
	if(step==1){$("#prev").hide();}
}

function buyFormSubm(){
	$("#formNotify").html(showWait());
	$("#buyForm").attr("action", "../ajax/buy_form_check.php");
	$("#buyForm").ajaxSubmit(function(data){
		$("#formNotify").html('OK, sending...');
		if(data==1){
				action='';
				$("#buyForm").attr("action", action);
				$("#buyForm").submit();
			}else{
				$("#wait").remove();
				$("#formNotify").html(data);
			}
		});
}
