var tchint = 0;
if(u_sex == 0){
	$("#iam_sel").change(function(){
		showTipPopup("iam");
	});
}

if(u_orient == 0){
	$("#who_sel").change(function(){
		showTipPopup("who");
	});
}

if(u_townid == 0){
	$("#ts").change(function(){
		showTipPopup("town");
	});
	
}

function showTipPopup(tp){
	$(".tipPopupCont a.yes").click();
	$(".tipPopupCont").remove();
	
	if(tp == "iam"){
		s = $("#iam_sel").val();
		if(s>0){
			
			$.ajax({url: "register.php", data: "aj=1&showiam=1", dataType: "script" });
			
			if(s == 1 || s == 4 || s == 16){
				stxt = "парень";
				usex = 1;
			}
			
			if(s == 2 || s == 8){
				stxt = "девушка";
				usex = 2;
			}
			
			popup = jQuery(getIamWrapper(usex,stxt));
			popup.css("margin-top","-77px");
			$("#iam_sel").before(popup);
			$("#iam_sel").unbind("change");
		}

	}
	
	if(tp == "who"){
		w = $("#who_sel").val();
		if(w>0){
			
			$.ajax({url: "register.php", data: "aj=1&showwho=1", dataType: "script" });
			
			if(w == 1){
				wtxt = "парня";
			}
			
			if(w == 2){
				wtxt = "девушку";
			}
			
			if(w == 4){
				wtxt = "пару М+Ж";
			}
			
			if(w == 8){
				wtxt = "пару М+М";
			}
			
			if(w == 16){
				wtxt = "пару Ж+Ж";
			}
			
			
			popup = jQuery(getWhoWrapper(w,wtxt));
			popup.css("margin-top","-77px");
			$("#who_sel").before(popup);
			$("#who_sel").unbind("change");
		}

	}
	
	if(tp == "town"){
		clearTimeout(tchint);
		
		t = $("#ts").val();
		
		if(t == 0){
			tchint = setTimeout("showTipPopup('town')",1000);
		}
		else{
			$.ajax({url: "register.php", data: "aj=1&showtown=1", dataType: "script" });
			
			ttxt = $("#ts option:selected").text();
			popup = jQuery(getTownWrapper(t,ttxt));
			popup.css("margin-top","-88px");
			$("#ts").before(popup);
			//$("#ts").unbind("change");
		}

	}
}


function getIamWrapper(s,stxt){
	html = "<div class='tipPopupCont'><div><b class='b1'><div>Вы "+stxt+"?</div><div class='tipBtnCont'><a href='#' class='tipYesBtn yes' onclick='changeSex("+s+",1);return false;'>Да</a><a href='#' onclick='changeSex("+s+",0);return false;' class='tipNoBtn'>Нет</a></div></b><b class='b2'></b></div><div style='display:table;width:100%;border-spacing: 0px;text-indent: 0px;'><b class='b3'>&nbsp;</b><b class='b4'>&nbsp;</b></div></div>";
	return html;
}

function getWhoWrapper(w,wtxt){
	html = "<div class='tipPopupCont'><div><b class='b1'><div>Хотите найти "+wtxt+"?</div><div class='tipBtnCont'><a href='#' class='tipYesBtn yes' onclick='changeWho("+w+",1);return false;'>Да</a><a href='#' onclick='changeWho("+w+",0);return false;' class='tipNoBtn'>Нет</a></div></b><b class='b2'></b></div><div style='display:table;width:100%;border-spacing: 0px;text-indent: 0px;'><b class='b3'>&nbsp;</b><b class='b4'>&nbsp;</b></div></div>";
	return html;
}

function getTownWrapper(t,ttxt){
	html = "<div class='tipPopupCont'><div><b class='b1'><div>Твой город<br/> "+ttxt+"?</div><div class='tipBtnCont'><a href='#' class='tipYesBtn yes' onclick='changeTown("+t+",1);return false;'>Да</a><a href='#' onclick='changeTown("+t+",0);return false;' class='tipNoBtn'>Нет</a></div></b><b class='b2'></b></div><div style='display:table;width:100%;border-spacing: 0px;text-indent: 0px;'><b class='b3'>&nbsp;</b><b class='b4'>&nbsp;</b></div></div>";
	return html;
}

function changeSex(s,tp){
	$(".tipPopupCont").remove();
	$.ajax({url: "register.php", data: "aj=1&ch_sex=1&sex="+s+"&tp="+tp, dataType: "script" });
}

function changeWho(w,tp){
	$(".tipPopupCont").remove();
	$.ajax({url: "register.php", data: "aj=1&ch_who=1&who="+w+"&tp="+tp, dataType: "script" });
}

function changeTown(t,tp){
	$(".tipPopupCont").remove();
	if(tp){
		$.ajax({url: "register.php", data: "aj=1&ch_town=1&t="+t, dataType: "script" });
	}	
}
