
function rd$(d){ return document.getElementById(d);}

$(document).ready(function(){
	
	$(".notify-close").click(function(){
		$("#notify-container").hide();
		$(".top_nav").css("margin-top","0px");
	});
	$("#navshow").click(function(){
		var position=$(this).position();
		//alert( "left: " + position.left + ", top: " + position.top );

		$('div.sub_nav').css("left",position.left-480).slideToggle('medium');

		return false;
	});
	$(".tagsa li:first").addClass("selectTag");
	$(".tag_contenta div:not(:first)").hide();
	$(".tagsa li").mouseover(function(){
		$(".tagsa li").removeClass("selectTag");
		$(this).addClass("selectTag");
		$(".tag_contenta div").hide();
		$("."+$(this).attr("id")).fadeIn("slow");
	});


	$(".tagsb li:first").addClass("selectTag");
	$(".tag_contentb div:not(:first)").hide();
	$(".tagsb li").mouseover(function(){
		$(".tagsb li").removeClass("selectTag");
		$(this).addClass("selectTag");
		$(".tag_contentb div").hide();
		$("."+$(this).attr("id")).fadeIn("slow");
	});

	//$("#tagsc li:first").addClass("selectTag");
	//$(".tag_contentc div:not(:first)").hide();
	$("#tagsc li").click(function(){
		$("#tagsc li").removeClass("selectTag");
		$(this).addClass("selectTag");
		$(".tag_contentc div").hide();
		$("."+$(this).attr("id")).show();
	});


	$("#tagse li:first").addClass("selectTag");
	$(".tag_contente div:not(:first)").hide();
	$("#tagse li").mouseover(function(){
		$("#tagse li").removeClass("selectTag");
		$(this).addClass("selectTag");
		$(".tag_contente div").hide();
		$("."+$(this).attr("id")).show();
	});
	
	function formatItem(row) {
		return row[0] + " (<strong>id: " + row[1] + "</strong>)";
	}
	function formatResult(row) {
		return row[0].replace(/(<.+?>)/gi, '');
	}

	$("#companyname").autocomplete("/ajax/ajax_data.php?typeid=3", {
		width: 260,
		max: 20,
		selectFirst: false,
		mustMatch: false,
		highlight: false
		/*formatResult: function(data) {
			return data[1];
		}*/
	});

	/*$("#companyname").result(function(event, data, formatted) {
		$("#companyid").val(data[1]);
		if(data[1])
		{
			$("#companyid").val(data[1]);
		}else
		{
			$("#companyid").val(0);
		}
	});
	*/
	$("#getcom").click(function(){
		//alert($("#companyid").val());
	});

	//jobtitle 自动获取
	$("#jobtitle").autocomplete("/ajax/ajax_data.php?typeid=4", {
		width: 260,
		max: 20,
		selectFirst: false,
		mustMatch: false,
		highlight: false
		/*formatResult: function(data) {
			return data[1];
		}*/
	});
	
	$('img.help_img').mouseover(function(){
		$('.helpMouse').show();	
	}).mouseout(function(){
		$('div.helpMouse').hide();
	});
	
	//taglist 中点击 问题
	$('.taglist a[rel="taglist"]').click(function(){
			var id = $(this).attr('id');
			$("#tag_content"+id).slideToggle('200');
		});
	
	//taglist  expandall
	$("#expandall").click(function(){
		if($(".tag_list .tag_content").last().css("display")=='none')
		{
			$(".tag_list .tag_content").slideDown('200');
		}else
		{
			$(".tag_list .tag_content").slideUp('200');
		}
		
	});

	//问题列表 点击 全部保存
	$("#saveall").click(function(){
		var aids='';
		$(".tag_list .tagtitle >a").each(function(i){
			if(i>0) aids=aids+',';
			aids=aids+$(this).attr('id');
		});
		
		if(aids)
		{
			question_fav_all(aids);
		}
	});
	//点击后面的保存
	$('.taglist a[rel="save"]').click(function(){
			var id = $(this).attr('id');
			question_fav(id);
	});
	
	//详细页面内容
	$("#acontent").focus(function () {

		var d=$(this);
		var s=d.val().substring(0,10);
		var s1=d.attr("title").substring(0,10);
		
		if( this.value!="" && s1==s) 
		{
			this.value=""
		}
	}).blur(function () {
		if(this.value=="") 
		{
			this.value=$(this).attr("title");
		}
	});
	
	//show-rating1
	$('#rating1').mouseover(function(){
		$("#start1").css("width",'0');
	}).mouseout(function(){
		var num1=$("#start1").attr("num");
		$("#start1").css("width",num1);
	});

	$('#rating1 li a').click(function(){
		var score=$(this).attr('id');
		var qid  =$("#start1").attr('qid');
		
		send_rate(qid,score,1);
	});
	//show-rating2
	$('#rating2').mouseover(function(){
		$("#start2").css("width",'0');
	}).mouseout(function(){
		var num1=$("#start2").attr("num");
		$("#start2").css("width",num1);
	});
	$('#rating2 li a').click(function(){
		var score=$(this).attr('id');
		var qid  =$("#start2").attr('qid');

		send_rate(qid,score,2);
	});

	//show-guide more
	
	$('#showguide').click(function(){
		
		var qid=$(this).attr('qid');
		showguide(qid);
	});
	
	//回答保存
	$('#savep').click(function(){
		if(checkanswer())
		{
			$("#atypeid").val(1);
			$("#answeradd").submit();
		}
	});

	$('#savea').click(function(){
		if(checkanswer())
		{
			$("#atypeid").val(2);
			$("#answeradd").submit();
		}
	});
	
	//-----dialog login--
	$('.win1_r dl dd .link_blue_13_').live('click',function () {
		$('ul.win1_r_forgot').slideToggle();
	});

	//-------live -save--

	$(".win4_body dd a").live('mouseover', function() {
		$(this).css('position','relative')
		var id=$(this).attr('id');
		$("#x"+id).show();
	}).live('mouseout',function(){
		var id=$(this).attr('id');
		$("#x"+id).hide();
		$(this).css('position','');
	});

	$('.win4 .bt13').live('click',function () {
		$('dl.win4_a').slideToggle();
	});
	$("#addnew").live('click',function(){
		$("#addf").slideToggle();
	});

	$("#addfolder").live('click',function(){
		var d=$("#foldername");
		if(d.val()=='')
		{
			alert("pleasse input foldername");
			return false;
		}
		if(d.val().length<2||d.val().length>60) 
		{
			alert("foldername must 2-60 chars");
			return false
		}
		var foldername=d.val();
		$.ajax({
			type:"post",
			url:"/ajax/folder_add.php",
			data: "foldername="+foldername,
			dataType:"json",
			success:function (a) {
				if(a.result==-1) {
					alert("have exists!");
				}else if(a.result==-2) {
					alert("出错了！");
				}else if(a.result==3) {
					d.val('');
					$("#addf").hide();
					show_folder();
				}
			}
		});		
	});

	//show  samore 点击
	$('#samore').bind('click',function(){
		var qid=$(this).attr('qid');
		show_samore(qid);
	});
	
	$('#dialogcancel').live('click',function(){
		delWinD(1);
	});

	
	//advice save
	$('.tags_a .float_r .b a').click(function(){
			var aid = $(this).attr('aid');
			advice_fav(aid);
	});

	$('.tags_a .float_r .a a').click(function(){
			var aid = $(this).attr('aid');
			show_advice_comment(aid);
	});

	
	//right ask add
	
	$("#askcontent").focus(function () {

		var d=$(this);
		var s=d.val()
		var s1=d.attr("title");
		
		if( this.value!="" && s1==s) 
		{
			this.value=""
		}
	}).blur(function () {
		if(this.value=="") 
		{
			this.value=$(this).attr("title");
		}
	});

	$("#askadd").live('click',function(){
		var d=$("#askcontent");
		if(d.val()=='' || d.val()==d.attr('title'))
		{
			alert("pleasse input question");
			return false;
		}
		if(d.val().length<2||d.val().length>127) 
		{
			alert("content must 2-128 chars");
			return false
		}
		var content=d.val();
		var catename=$("#acatename").val();
		
		$.ajax({
			type:"post",
			url:"/ajax/ask_add.php",
			data: "content="+content+'&catename='+catename,
			dataType:"json",
			success:function (a) {
				if(a.result==0) {
					pop_login(12);
				}else if(a.result==-1) {
					alert("data wrong!！");
				}else if(a.result==1) {
					d.val(d.attr('title'));
					$("#acatename").val('');
					alert("successful!");
				}
			}
		});		
	});
	

});


function showtag(divid)
{
	$("#tagsc li").removeClass("selectTag");
	$("#"+divid).addClass("selectTag");
	
	$(".tag_contentc div").hide();
	$("."+divid).show();
}
