$(function(){
	//顶部搜索
	text_tip = '请输入搜索关键字';
	text_val = $('#header_search_txt').val();
	$('#header_search_txt').bind('click',function(){
		if(text_val == text_tip){
			$(this).val('');
		}
	});
	$('#header_search_txt').bind('blur',function(){
        if($(this).val() == ''){
			$(this).val(text_tip);
		}
	});
	
	//首页中部左中右高度调整
    if($('#indexCenterContent').html()!=null){
        center_height = $('#indexCenterContent').height();
	    $('.doctor_online').css({'height':center_height-49});
    }
    //处理等不登陆文字预加载
    $('.header>ul li').show();
    
    //首页疾病症状下拉
    $('#indexDisMore').toggle(
    	function(){
    		$('#indexDisContent').animate({'height':89},300);
    		$(this).attr({'class':'t_dis_more_up','title':'收起内容'});
    	},
    	function(){
    		$('#indexDisContent').animate({'height':50},300);
    		$(this).attr({'class':'t_dis_more','title':'展开更多'});
    	}
    )
})


//留言
function messageAdd(message){
	if(message=="")
	{
		alert("你忘记写留言内容了吧？~呵呵");
	}
	else
	{
		$("#newSuggestion input").attr("disabled","disabled");
		$("#newSuggestion textarea").attr("disabled","disabled");
		$("#newSuggestion h4").html("正在提交留言数据...");
		$.ajax({
			type: "POST",
			url: "ajax/message_add.php",
			data: "message="+message+"",
			success: function(data){
				$("#newSuggestion h4").fadeIn(1000).html("留言成功！你可以再写一条留言~");
				$("#newSuggestion input").removeAttr("disabled");
				$("#newSuggestion textarea").removeAttr("disabled").val("");
				tmp_html = $("#suggestionList ol").html();
				$("#suggestionList ol").html(data).append(tmp_html);
			},
			error: function(){
				$("#newSuggestion h4").html("留言失败，请重试！");
				$("#newSuggestion input").removeAttr("disabled");
				$("#newSuggestion textarea").removeAttr("disabled");
			}
		});
	}
}
//评论
function commentAdd(comment,id){
	if(comment=="")
	{
		alert("你忘记写评论内容了吧？~呵呵");
	}
	else
	{
		$("#newSuggestion input").attr("disabled","disabled");
		$("#newSuggestion textarea").attr("disabled","disabled");
		$("#newSuggestion h4").html("正在提交留言数据...");
		$.ajax({
			type: "POST",
			url: "ajax/comment_add.php",
			data: "message="+comment+"&id="+id,
			success: function(data){
				$("#newSuggestion h4").fadeIn(1000).html("评论成功！你可以再写一条留言~");
				$("#newSuggestion input").removeAttr("disabled");
				$("#newSuggestion textarea").removeAttr("disabled").val("");
				tmp_html = $("#suggestionList ol").html();
				$("#suggestionList ol").html(data).append(tmp_html);
			},
			error: function(){
				$("#newSuggestion h4").html("评论失败，请重试！");
				$("#newSuggestion input").removeAttr("disabled");
				$("#newSuggestion textarea").removeAttr("disabled");
			}
		});
	}
}
//搜索验证
function checkSearch()
{
	//tmp_val = $("#sugSearch input[@type=text]").val();
	tmp_val = $("#sugSearch input[type=text]").val();
	if(tmp_val == "" || tmp_val == "再此输入意见反馈关键字...")
	{
		alert("请输入一些你要搜索的文字");
		return false;
	}
}

   function vote(){
	alert("xxxxxx");
   }

//交通位置图 最大宽度设定
function set_image_width(fix_width)
{
	var image=new Image();
	image.src=$(".traffic_image img").attr("src");
	if( image.width > fix_width )
	{
		$(".traffic_image").html("<a href=\""+image.src+"\" target=\"_blank\"><img width=\""+fix_width+"\" src=\""+image.src+"\" title=\"点击查看完整交通位置图\" alt=\"点击查看完整交通位置图\" \/><\/a>");	
	}
}

/*选项卡切换*/
function selCat(name,obj,n)
{
	for(i=1;i<=n;i++)
	{
		eval("document.getElementById('"+name+i+"').className=''");
	}
	eval("document.getElementById('"+name+obj+"').className='tst_current'");
}

//搜索action转换
function changeAction(st){
	var st_array = new Array();
	st_array['doc'] = '/doctors.php';
	st_array['ask'] = '/ask.php';
	st_array['dis'] = '/disease.php';
	st_array['sym'] = '/symptom.php';
	$('#search_form input[@name=st]').removeAttr('checked');
	$('#search_form input[@value='+st+']').attr('checked','checked');
	$('#search_form').attr('action',st_array[st]);
}

function addBookmark(title,url) {
	if (window.sidebar){
		window.sidebar.addPanel(title, url,"");
	}else if(document.all){
		window.external.AddFavorite( url, title);
	}else if(window.opera && window.print){
		return true;
	}
}
function setHomepage(url)
{
    if (document.all)    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(url);
    }else if (window.sidebar){
        if(window.netscape){
            try{
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }catch(e){
                alert("this action was aviod by your browser，if you want to enable，please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
            }
         }
         var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
         prefs.setCharPref('browser.startup.homepage',url);
     }
}