﻿/*!
 * Storm JavaScript
 * 
 * 广州海军粤海医院男科中心
 * Date: 20010-02-01
 */
$(function() {
	$("#artList li:nth-child(5n)").addClass("select");
	$("#searchBar input").inputPrompts();
	$("#focusNews").focusPhoto(1000,4000,4);
	$("#iNews").sNav(".classGroup li",".titleGroup ul",1);
	$("#iNews .titleGroup ul li a").limit(20,"...");
	if(document.getElementById("iDoctor")){
		$("#iDoctor").contentScroll(1000,4);
	}
	$("#sideNewsList a").limit(14,"...");
	$("#iCharges").atp(500,1000,1);
});

//输入框文字提示
jQuery.fn.inputPrompts = function() {
	$(this).focus(function(){
		$(this).addClass("select");
		this.value = this.value==="请输入您要查询的内容"? "":this.value;
	}).blur(function(){
		$(this).removeClass("select");
		this.value = this.value==="" ? "请输入您要查询的内容":this.value;
	});
}

//内容自动切换
jQuery.fn.sw = function(){
	var c = 1;
	var t = this;
	var l = t.length-2;
	var h = setInterval(
		function(){
			t.hide().eq(c).show();
			c = c > l ? 0:c+1;
		}, 6000);
}

//当前日期
jQuery.fn.myDate = function(){
	var time = new Date();
	var date = time.getDate();
	var day = time.getDay();
	var year = time.getFullYear();
	var month = time.getMonth()+1;
	switch (day)
  	{
		case 1: day = "星期一"
			break;
		case 2: day = "星期二"
			break;
		case 3: day = "星期三"
			break;
		case 4: day = "星期四"
			break;
		case 5: day = "星期五"
			break;
		case 6: day = "星期六"
			break;
		case 7: day = "星期天"
			break;
		}
	 this.html(year+"年,"+month+"月"+date+"日,"+day);
}
//复制内容
jQuery.fn.cp=function(n){
	var ot = this.html();
	var ct = "";
	for(i=0;i<=n-1;i++){
		ct = ct + '<li>'+this.children().eq(i).html()+'</li>'
	}
	this.html(ot+ct);
}
//内容滚动(纵向)
jQuery.fn.atp =function(speed,frequency,perPage){
	var con = this
	var _h = 0;
	var currentPage = 1 //当前页
	var fragment_width = 24; //单个图片容器宽度
	var fragments_count=con.find('li').length; //图片容器数量
	var numPages = Math.ceil(fragments_count / perPage); //翻页次数 
	var stepMove = fragment_width*perPage;//翻页的宽度
	var firstPosition = 0; //第一张图片容器的位置
	
	play();
	con.hover(function(){clearInterval(_h)}, function(){play()});

	function play(){
		_h = setInterval(scrollMove,frequency)
	}
	
	function scrollMove() {
		currentPage ++;
		if(currentPage > numPages){
			currentPage = 1;
			con.find("ul").animate({'top': firstPosition},speed);
			return;
		}else{
			con.find("ul").animate({'top': -((currentPage-1)*stepMove)},speed);
			return;
		}
	}
}

//内容滚动(横向)-vol 2
jQuery.fn.contentScroll = function(speed,perPage){
	var currentPage = 1;//当前位置
	var mover = $(this).find("ul");
	var cell = mover.find("li");
	var cmd = $(this).find(".button");
	var fragments_count = cell.length;//获取数量
	var fragmet_width = parseInt(cell.width())+parseInt(cell.css("margin-right").match(/\d*/));//获取宽度
	var perPage = (perPage)? perPage:1;//一次移动的数量
	var numPages = Math.ceil(fragments_count/perPage); //总页数 
	var stepMove = fragmet_width*perPage;//一次移动的宽度
	var firstPosition = 0; //首页位置
	var lastPosition = -((numPages-1)*stepMove); //末页位置
	
	mover.moveL = function(){
		this.animate({'left': -((currentPage-1)*stepMove)},speed);
	};
	
	cmd.live('click', function() {
		if ($(this).hasClass('tRight')) {
				currentPage +=1;
					if (currentPage > numPages) {
						currentPage = 1;
							mover.animate({'left': firstPosition},speed);
						return;
				};
				mover.moveL();
		};
		if ($(this).hasClass('tLeft')) {
				currentPage -=1;
				if (currentPage < 1) {
						currentPage = numPages;
						mover.animate({'left': lastPosition},speed);
						return;
				};
				mover.moveL();
		}
	})
}

//文字截取
jQuery.fn.limit=function(num,word){  //num为需要截取的文字数量
	var self = this;
	self.each(function(){
		var objString = $(this).text();
		var objLength = $(this).text().length;
		if(objLength > num){
		$(this).attr("title",objString);
		$(this).text(objString.substring(0,num) + word);
		}
	})
}

<!--调整字号 -->
jQuery.fn.fsize=function(t) {
	var _c = this;
	var _t = $(t);
	_c.css("cursor","pointer").click(
		function(){
			var i = $(this).attr('title');
			_t.css('font-size',i+'px').css('text-indent',2*i+'px');
		});
}

//文章预览
jQuery.fn.preview=function(a){
	var _f = this;
	var _s = $(a);
	_f.hover(
		function(){
			$(this).parent().parent().addClass('select');
			var ind = _f.index(this);
			_s.hide().eq(ind).show();
		},
		function(){
			_s.hide();
			$(this).parent().parent().removeClass('select');
		}
	);
}

//二级菜单
jQuery.fn.sNav = function(firstnav, secnav, ev){
	var _f = this.find(firstnav);
	var _s = this.find(secnav);
	if (ev){
		_f.click(
			function(){
				_f.removeClass('select');
				$(this).addClass('select');
				var ind = _f.index(this);
				_s.hide().eq(ind).show();
			}
		)
	} else {
		_f.hover(
			function(){
				_f.removeClass('select');
				$(this).addClass('select');
				var ind = _f.index(this);
				_s.hide().eq(ind).show();
			}
		)
	}
}

//图片新闻
jQuery.fn.focusPhoto = function(speed,frequency,prePage,pG,tG){
	var _c = _h = 0;
	var _p = this.find(".photoGroup li"); //图片组
	var _t = this.find(".titleGroup li"); //控制按钮组
	var _n = prePage-2;

	swphoto();
	_t.click(function(){
			clearInterval(_h);
			if($(this).attr('class')!='select'){
				_c = _t.index(this);
				change();
				play();
			}
	});
	
	_p.hover(function(){clearInterval(_h)}, function(){play()});

	function swphoto(){
		_p.hide().eq(0).show();
		play();
	}
	function play(){
		_h = setInterval(auto, frequency);
	}
	function auto(){    
		_c = _c > _n ? 0 : _c + 1;
		change();
	}
	function change(){
		_p.fadeOut(speed).eq(_c).fadeIn(speed);
		_t.removeClass('select').eq(_c).addClass('select');
	}
}

function checkF() {
	
	if ($("#qTitle").attr("value") == '' || $("#qTitle").attr("value") == '输入咨询标题') {
		alert('请输入您所要咨询的问题');
		$("#qTitle").focus();
		return false;
	}
	
	if ($("#qKs").attr("value") == '') {
		alert('请选择您所要咨询的科室');
		$("#qKs").focus();
		return false;
	}
	
	if ($("#qZj").attr("value") == '' ) {
		alert('请选择您要咨询的专家');
		$("#qZj").focus();
		return false;
	}
	
	if ($("#qName").attr("value") == '' || $("#qName").attr("value") == '您的名字') {
		alert('请输入您的姓名');
		$("#qName").focus();
		return false;
	}
	
	if ($("#qPhone").attr("value") == '' || $("#qPhone").attr("value") == '联系电话') {
		
		alert('请输入您的电话');
		$("#qPhone").focus();
		return false;
	}
	
	if ($("#qText").attr("value") == '' || $("#qText").attr("value") == '请输入咨询内容') {
		alert('请输入您所要咨询的内容');
		$("#qText").focus();
		return false;
	}
	
	if ($("#qCode").attr("value") == '') {
		alert('请输入验证码');
		$("#qCode").focus();
		return false;
	}
	
	return true;
}


function checkGh() {
	
	if ($("#ghName").attr("value") == '') {
		alert('请输入您的姓名');
		$("#ghName").focus();
		return false;
	}
	

	if ($("#ghAge").attr("value") == '' ) {
		alert('请输入您的年纪');
		$("#ghAge").focus();
		return false;
	}
	
	
	if ($("#ghPhone").attr("value") == '') {
		alert('请输入您的电话');
		$("#ghPhone").focus();
		return false;
	}
	
	if ($("#ghKs").attr("value") == '') {
		alert('请选择您预约的科室');
		$("#ghKs").focus();
		return false;
	}
	
	
	if ($("#ghContent").attr("value") == '' ) {
		alert('请输入您的病情描述');
		$("#ghContent").focus();
		return false;
	}
	
	return true;
}

//<!--
//var LiveAutoInvite0='您好，来自%IP%的朋友';
//var LiveAutoInvite1='来自首页的对话';
//var LiveAutoInvite2='<img src=\\"http://www.yhnk.net/images/1.jpg\\"> ';
////-->
//
//document.write("<scr"+"ipt language=\"javascript\" src=\"http://kht.zoosnet.net/JS/LsJS.aspx?siteid=KHT67535503&float=1\"></scr"+"ipt>");
