//开始LI内切换UL显示计时变量
y_ = 0;
//页面初始化
$(function(){
	$.get('/templates/public/login_new/check_log.php',function(data){$('#hearderLogin').html(data).show();if_exsits_tips()});
	//$('#hearderLogin').load('/templates/public/login_new/check_log.php').show();
	//给所有带样式odd_even的UL列表的偶数行添加li_even样式
    $('ul.odd_even').each(function(i){
        $(this).children('li:odd').addClass('li_even');
    })
	//LI内切换UL显示
    $('ul.over_show_details>li').mouseover(function(){
		o = $(this);
        y_ = setTimeout(
		function() {
			if(o.children('ul').css('display') == 'none'){
				o.parent().find('li>ul').slideUp();
				o.find('ul').slideDown();
			}
		},500);
        $(this).mouseout(function(){
             clearBlock();
        })
     })
})
//清楚LI内切换UL显示计时
function clearBlock(){
   if(y_){
	clearTimeout(y_);
	y_=0;
   }
}
function headerLoginOut(){
var yynet_domain_full;
    var hes_domain = (hes_domain == undefined) ? false : hes_domain;
    var logout_url = (hes_domain == false) ? '/templates/public/login_new/check_log.php' : '/admin/login.php?action=logout';
	//alert(hes_domain+' + '+yynet_domain_full);
    var yynet_domain_full = (yynet_domain_full == undefined) ? '' : yynet_domain_full;
    $('#hearderLogin').html('&#27491;&#22312;&#36864;&#20986;...');
    $.get(yynet_domain_full+'/account/?c=logout&a=true&r='+Math.random(),function(){$('#hearderLogin').load(logout_url).show();$('#user_space').remove();delCookie('content_user_show');});
}
//头部下拉菜单及搜索切换
jQuery(function($) {
	$("#gnq_dis,#gnq_hpt,#gnq_dpt").hover(
		function () {
			$(this).addClass("show_gn");
		},
		function () {
			$(this).removeClass("show_gn");
		}
	);
	$("#sel-j").click( function(){
			$('#jkm-ask-search-box').css('display','block');
			$('#cse-search-box').css('display','none');
			$('#gn_search').removeAttr('class');
			$('#gn_search>form>h2').removeAttr('class');
	});
	$("#sel-g").click( function(){
			$('#jkm-ask-search-box').css('display','none');
			$('#cse-search-box').css('display','block');
			$('#gn_search').removeAttr('class');
			$('#gn_search>form>h2').removeAttr('class');
	});
	$("#gn_search>form>h2").mousedown( function(){
			$('#gn_search').toggleClass('show_gn');
			$(this).toggleClass('gns_down');
	});
}); 





// need_login.new.js
//调用此JS，就需要登录
//如果form有属性lang=zh，则认为这个form需要登录
$(function(){
	//确认需要登录的form是否存在
	mark = $('body form[lang=zh]').length;
	//alert(mark);
	if(mark > 0){
		$.ajax({
			type: "GET",
			url: "/templates/public/login/need_login.php",
			data: {'action':'check_login_status'},
			success: function(data){
				if(data != 1){
					//$('body form[lang=zh] :input').attr('disabled','disabled');
					$('body form[lang=zh] :input').bind('click',function(){
						openLoginWindow();
					});
					$('body form[lang=zh]').bind('submit',function(){return false;});
					openLoginWindow();
				}else{
					//alert('已经登录了！');
				}
			},
			error: function(){
				alert('致命错误.99');
			}
		});
	}else{
		//alert('不需要登录！');
	}
})

//ajax登录过程
//to_do登录成功后要做的事情：urlencode格式，需要urldeincode
function Login(where_do,what_do){
	//清除临时提示框
	$('#login_tmp').remove();
	var options_login = {
		type:'POST',
		url:'/templates/public/login/need_login.php',
		data: {'action':'login'},
		beforeSubmit:function(){
			$('#login :input').attr('disabled','disabled');
			//创建临时提示框
			$('#login h4').after('<div id="login_tmp" class="error"></div>');
			$('#login_tmp').html('&#27491;&#22312;&#30331;&#24405;...');
		},
		success:function(data){
			//alert(data);
			if(data == 1){
				$('#login_tmp').html('&#30331;&#24405;&#25104;&#21151;&#65292;&#27491;&#22312;&#36820;&#22238;&#32487;&#32493;&#25805;&#20316;...');
				$('body form[lang=zh]').unbind('submit');
				$('body form[lang=zh] :input').unbind('click');
				if(what_do == '' || what_do == undefined){
					setTimeout("Logined()",2000);
				}else{
					//what_do = '/ajax_login.php';
					ajaxLogined(where_do,what_do);
                    tb_remove();
				}
			}else{
				$('#login_tmp').html(data);
				$('#login :input').removeAttr('disabled');
			}
		},
		error:function(){
			alert('致命错误.141');
		}
	};
	$('#login').ajaxSubmit(options_login);
}

//ajax注册并登录
function Register(where_do,what_do){
	//清除临时提示框
	$('#register_tmp').remove();
	var options_register = {
		type:'POST',
		url:'/templates/public/login/need_login.php',
		data: {'action':'register'},
		beforeSubmit:function(){
			$('#register :input').attr('disabled','disabled');
			//创建临时提示框
			$('#register h4').after('<div id="register_tmp" class="error"></div>');
			$('#register_tmp').html('&#27491;&#22312;&#25805;&#20316;...');
		},
		success:function(data){
			//alert(data);
			if(data == 1){
				$('#register_tmp').html('&#27880;&#20876;&#12289;&#30331;&#24405;&#25104;&#21151;&#65292;&#27491;&#22312;&#36820;&#22238;&#32487;&#32493;&#25805;&#20316;...');
				$('body form[lang=zh]').unbind('submit');
				$('body form[lang=zh] :input').unbind('click');
				if(what_do == '' || what_do == undefined){
					setTimeout("Logined()",2000);
				}else{
					//what_do = '/ajax_login.php';
					ajaxLogined(where_do,what_do);
                    tb_remove();
				}
			}else{
				$('#register_tmp').html(data);
				$('#register :input').removeAttr('disabled');
			}
		},
		error:function(){
			alert('致命错误.180');
		}
	};
	$('#register').ajaxSubmit(options_register);
}
//登录之后默认操作
function Logined(){
	tb_remove();
	window.location.reload();
}
//登陆之后ajax刷新
function ajaxLogined(where_do,what_do){
//	alert(where_do+'++++++++++'+what_do);
	$('#'+where_do).html('<span style="color:red">&#27491;&#22312;&#35013;&#36733;&#29992;&#25143;&#30331;&#24405;&#20449;&#24687;...</span>');
	//modify by Yan.Gf 2009/12/01 for miaoxh
	//$('#'+where_do).load(what_do,null,if_exsits_tips);
	$('#'+where_do).load(what_do);
}
//打开登录窗口
function openLoginWindow(title,ext){
	if(title == undefined) title = '&#24744;&#30340;&#25805;&#20316;&#38656;&#35201;&#27880;&#20876;&#25110;&#30331;&#24405;...';
	if(ext == undefined){
		ext='';
	}else{
		ext = 'ext='+ext;
	}
	TB_show(title,'/templates/public/login/login.php?height=260&width=560&to_do=abcdefg'+ext);
}

//tips.new.js

/****************************************************************\
*	弹出用户（包括医生）登录后相关提示信息
*	此js基于jquery内核
*	登录框显示在有ID为currentLoginUser的下方
*	完成调用还须引入CSS样式表：
*	可以调用默认：	/templates/public/login_tips/tips.css
\****************************************************************/

//$(function(){if_exsits_tips();})
function if_exsits_tips(){
	//初始化，寻找有ID为currentLoginUser的标签，如果有，弹出用户相关信息
	//顶部弹出用户信息
	if($('#currentLoginUser').html() != null){
		get_cookie = getCookie('content_user_show');
        //alert(get_cookie);
        e = document.getElementById('currentLoginUser');
		user_offset = $('#currentLoginUser').offset('body');
		window_width = document.body.clientWidth;
		user_offset_x = getLeft(e);
		user_offset_y = getTop(e);
        user_offset_y += $('#currentLoginUser').height();
		user_offset_w = user_offset.width;
		us_up_x = user_offset_x + user_offset_w/2;
		$('body').append('<div id="user_space"></div>');
		$('#user_space').css({left:user_offset_x-60,'top':user_offset_y}).hide().load('/templates/public/login_new/tips.php');
		$('#user_space span.us_up').css({left:us_up_x});
        if(get_cookie == 'hide'){
			$('#user_space').hide();
		}else{
			$('#user_space').show();
		}
	}else{
		delCookie('content_user_show');//如果未登录或已退出登录，删除cookie
	}
	$('#currentLoginUser').click(function(){
		$('#user_space').fadeIn(700);
	})
}
//关闭个性化提示
function closeUserSpace(){
	$('#user_space').fadeOut(700);
	addCookie('content_user_show','hide',0.5,'','');
}
//设置cookie
function addCookie(name,value,expires,path,domain){
	var str=name+"="+escape(value);
	if(expires!=""){
		var date=new Date();
		date.setTime(date.getTime()+expires*24*3600*1000);//expires单位为天
		//date.setTime(date.getTime()+expires);//expires单位为天
		str+=";expires="+date.toGMTString();
	}
	if(path!=""){
		str+=";path="+path;//指定可访问cookie的目录
	}
	if(domain!=""){
		str+=";domain="+domain;//指定可访问cookie的域
	}
	document.cookie=str;
}
//取得cookie
function getCookie(name){
	var str=document.cookie.split(";")
	for(var i=0;i<str.length;i++){
		var str2=str[i].split('=');
        if(jQuery.trim(str2[0])==name) return unescape(str2[1]);
	}
}

//取得cookie, 和PHP兼容
function getCookie2(name){
	var str=document.cookie.split(";")
	for(var i=0;i<str.length;i++){
		var str2=str[i].split('=');
        if(jQuery.trim(str2[0])==name) return decodeURIComponent(str2[1]);
	}
}

//删除cookie
function delCookie(name){
	var date=new Date();
	date.setTime(date.getTime()-10000);
	document.cookie=name+'=null;expire='+date.toGMTString();
}
function getTop(e){
    var offset=e.offsetTop;
    if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
    return offset;
}

function getLeft(e){
    var offset=e.offsetLeft;
    if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
    return offset;
}


