﻿headerA = {
	Students: new Array({url:'http://www.todayedu.cn/newask/index.php/',name:'名师在线'},{url:'http://www.todayedu.cn/tiantianyilian/',name:'每天一练'},{url:'http://www.todayedu.cn/xuexizidao/',name:'每周精练'},{url:'http://www.todayedu.cn/slhydt/',name:'数理化一点通'},{url:'http://www.todayedu.cn/e/news/',name:'自主学习'},{url:'http://www.todayedu.cn/zuowenzaixian/',name:'作文在线'},{url:'http://www.todayedu.cn/shitixiazai/',name:'名校题库'},{url:'http://www.todayedu.cn/mingshishipinxin/',name:'名师视频'},{url:'http://www.todayedu.cn/english/index.php/',name:'学英语'},{url:'http://www.todayedu.cn/wenxuetiandi/',name:'文学阅读'},{url:'http://www.todayedu.cn/zxks/',name:'同步特训'},{url:'http://www.todayedu.cn/xjztd/xjztd/',name:'小记者站',end:1}),
	Teachers:new Array({url:'http://www.todayedu.cn/newask/index.php/',name:'名师在线'},{url:'http://www.todayedu.cn/tiantianyilian/',name:'每天一练了'},{url:'http://www.todayedu.cn/xuexizidao/',name:'每周精练'},{url:'http://www.todayedu.cn/slhydt/',name:'数理化一点通'},{url:'http://www.todayedu.cn/e/news/',name:'教案下载'},{url:'http://www.todayedu.cn/zuowenzaixian/',name:'作文在线'},{url:'http://www.todayedu.cn/shitixiazai/',name:'名校题库'},{url:'http://www.todayedu.cn/mingshishipinxin/',name:'名师视频'},{url:'http://www.todayedu.cn/lunwentiandi/',name:'论文天地'},{url:'http://www.todayedu.cn/zxks/',name:'组卷考试'},{url:'http://www.todayedu.cn/xjztd/xjztd/',name:'小记者站',end:1})
};
var menuStr = '';
var editor;
var paths = 'drawing';
$(document).ready(function(){
    //检查用户登陆状态
    checklogin();

	var IsSSO = getCookie('isssologin');
	if(IsSSO != "" && IsSSO == "ssologingcookie"){
		$('#h_mid_div_left').find('img').each(function(){
			if($(this).attr('src') == '/skin/default/images/logo.gif'){
				$(this).attr('src','http://www.todayedu.cn/skin/default/images/tb_logo.gif')
			}
		});
	$('#h_mid_div_left2').find('img').each(function(){
			if($(this).attr('src') == '/skin/default/images/zyzximg.gif'){
				$(this).attr('src','http://www.todayedu.cn/skin/default/images/zyzxlogo.gif')
			}
		});
		$("#h_top_right").html('');
		if($('.user_info').html() != ""){
			$('.user_info').html('<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.todayedu.cn/sso/ssologout_response.php" onclick="return confirm(\'确认要退出?\');">退出</a></div>')
		}

		$('.finfo').html('');
		$('.finfoout').html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.todayedu.cn/sso/ssologout_response.php" onclick="return confirm(\'确认要退出?\');">退出</a>');

		if($('.blue_color2')){
    		var NewSSOUser = $('.blue_color2').html();
    		if(NewSSOUser != "" && NewSSOUser != null){
    		  $('.blue_color2').html(NewSSOUser.replace('DJ_',''));
    		}
		}

        //修改网页title
        document.title = "同步助学";
        //隐去脚部链接  * 本站简介 * 联系我们 * 投稿信箱* 招聘信息* 广告资费* 征订指南
        $('#foot > #foot1 > .foot_x > ul').html('<li>&nbsp;</li>')
        //隐去 安徽、河南 报纸链接
        $('#h_mid_div_right > ul > li').eq(2).remove();
        $('#h_mid_div_right > ul > li').eq(1).remove();
        $('#h_mid_div_right > ul > li > a').css("color", "#005d94")
        //修改版权等信息
        $('#foot > #foot1 > .foot_div').eq(0).html('主办：江苏省教育厅    承办：江苏省教育管理信息中心、江苏省电化教育馆    技术支持：江苏三源教育实业有限公司、南京今日教育管理有限责任公司')
        $('#foot > #foot1 > .foot_div').eq(1).html('保留所有权利，未经允许，不得复制、镜像 Copyright © 2010-2012,All Rights Reserved  <a href="http://www.miibeian.gov.cn/" target="_blank" style="color: #005d94">苏ICP备05076602</a>')
        //去除“包年用户”链接
        $('.outtime > a').each(function(){
            if($(this).attr("href") == "/e/member/my"){
                $(this).removeAttr("href")
            }
        })
	}

    $('#nav_ul_main li').each(function(i){
        $(this).click(function(){
            $(this).addClass('active_nav').siblings().removeClass();
            switch(i){
                case 0:
					DeleteCookie('nav');
                    setCookie('nav','1',20);
                    break;
                case 1:
					DeleteCookie('nav');
                    setCookie('nav','2',20);
                    break;
				//余下的栏目自行添加，数据格式上面有例子
            }
        })
    })

    //学习指导导航
    selectnav();

	//提问题脚本
    $('.mszx_button').click(function(){
        if($('#tc_tw2').css('width') != undefined){
            return false;
        }
        str = '';
        str +=('<link href="/skin/default/css/h_autocss.css" rel="stylesheet" type="text/css" />');
        str +=("<div id=\"tc_tw2\">");
        str +=("<div id=\"tc_twa\">");
        str +=("<div id=\"tc_twb\">");
        str +=("  <form action='/newask/index.php/ajax/ajaxcom' method='post' name='askform'><table width=\"100%\" border=\"0\" cellspacing=\"4\" cellpadding=\"0\">");
        str +=("    <tr>");
        str +=("      <td width=\"78\" align=\"right\" class=\"hy_tex5\">标题：<\/td>");
        str +=("      <td width=\"488\"><input name=\"title\" type=\"text\" class=\"shu5\" id=\"textfield\" \/><\/td>");
        str +=("    <\/tr>");
        str +=("    <tr>");
        str +=("      <td align=\"right\" class=\"hy_tex5\">内容：<\/td>");
        str +=("      <td><textarea name='content' rows='15' cols='80' style='width:480px; height:115px; ' id='wymeditor1' class='wymeditor1'></textarea><\/td>");
        str +=("    <\/tr>");
        str +=("    <tr>");
        str +=("      <td align=\"right\" class=\"hy_tex5\">分类：<\/td>");
        str +=("      <td><table width=\"488\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
        str +=("        <tr>");
        str +=("          <td width=\"160\"><select name=\"select3\" id=\"selectclass\" style='width:60px'>");
        str +=("           <option value=1>请选择年级<\/option><option value=1>一年级<\/option><option value=2>二年级<\/option><option value =3>三年级<\/option><option value=4>四年级<\/option><option  value=5>五年级<\/option><option value=6>六年级<\/option><option value=7>初中一年级<\/option><option value=8>初中二年级<\/option><option value=9>初中三年级<\/option><option value=10>高中一年级<\/option><option value=11>高中二年级<\/option><option value=12>高中三年级<\/option>");
        str +=("                    <\/select>");
        str +=("            　");
        str +=("            <span id='kmselect'><select name=\"select\" id=\"select\" style='width:60px'>");
        str +=("              <option value=\"\">请选择<\/option></span>");
        str +=("                        <\/select><\/td>");
        str +=("          <td width=\"254\"><table width=\"219\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
        str +=("            <tr>");
        str +=("              <td width=\"65\" align=\"right\">是否悬赏<\/td>");
        str +=("              <td width=\"27\" align=\"center\"><input type=\"radio\" name=\"radio\" id=\"radio\" checked='checked' value=\"1\" \/><\/td>");
        str +=("              <td width=\"16\" align=\"center\">是<\/td>");
        str +=("              <td width=\"27\" align=\"center\"><input type=\"radio\" name=\"radio\" id=\"radio2\" value=\"0\" \/><\/td>");
        str +=("              <td width=\"16\" align=\"center\">否<\/td>");
        str +=("              <td width=\"68\"><select name=\"score\" class=\"\" id=\"fentext\"><option value=\"0\"> 0 <\/option><option value=\"1\"> 1 <\/option><option value=\"2\"> 2 <\/option><option value=\"3\"> 3 <\/option><option value=\"4\"> 4 <\/option><option value=\"5\"> 5 <\/option><\/td>");
        str +=("            <\/tr>");
        str +=("          <\/table><\/td>");
        str +=("          <td width=\"87\" align=\"right\"><\/td>");
        str +=("        <\/tr>");
        str +=("      <\/table><\/td>");
        str +=("    <\/tr>");
        str +=("    <tr>");
        str +=("      <td>&nbsp;<\/td>");
        str +=("      <td><table width=\"480\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
        str +=("          <tr>");
        str +=("            <td width=\"79\"><img src=\"/newask/media/img/zc_a36.jpg\" width=\"79\" height=\"36\" id=\"sendAnswerImg\" \/><\/td>");
        str +=("            <td width=\"401\" valign=\"bottom\" class=\"hy_tex8\">&nbsp;<span>您可以按CTRL+回车快速提问</span><\/td>");
        str +=("          <\/tr>");
        str +=("      <\/table><\/td>");
        str +=("    <\/tr>");
        str +=("    <tr>");
        str +=("      <td>&nbsp;<\/td>");
        str +=("      <td><div id=\"tc_twc\"><a href=\"javascript:;;\" class='close_wind'>关闭<\/a><\/div><\/td>");
        str +=("    <\/tr>");
        str +=("  <\/table><input type='hidden' name='sid' id='sidinput' /><input type='hidden' name='uid' id='uidinput' /><input type='hidden' name='user' id='userinput' /><input type='hidden' name='act' value='ask' /></form>");
        str +=("<\/div>");
        str +=("<\/div>");
        str +=("<\/div>");
        $('body').append(str);
        pageinit('#wymeditor1','min');

        //=============================
        /*
        $('#selectclass').change(function(){
            $.ajax({
                type:'get',
                url:'/newask/index.php/ajax/ajaxcom?act=select&sid='+$(this).val(),
                dataType:'html',
                cache:false,
            	timeout: 10000,
                beforeSend: function(XMLHttpRequest){
                },
            	success: function(data) {
            	   $('#kmselect').html(data);
            	},
            	error: function() {
            		alert('操作失败');
            	},
                complete: function(XMLHttpRequest, textStatus){
                }
            })
        })
        */
        $('#selectclass').change(function(){
            var grade_subject_arr = [
            	[
            		[58, '视频问答'],
            		[14, '语文'],
            		[15, '数学']
            	],
            	[
            		[16, '语文'],
            		[19, '数学'],
            		[59, '视频问答']
            	],
            	[
            		[17, '语文'],
            		[20, '数学'],
            		[38, '英语'],
            		[60, '视频问答']
            	],
            	[
            		[18, '语文'],
            		[21, '数学'],
            		[39, '英语'],
            		[61, '视频问答']
            	],
            	[
            		[22, '语文'],
            		[23, '数学'],
            		[62, '视频问答']
            	],
                [
            		[24, '语文'],
            		[25, '数学'],
            		[40, '英语'],
            		[63, '视频问答']
            	],
            	[
            		[26, '语文'],
            		[27, '数学'],
            		[41, '英语'],
            		[64, '视频问答']
            	],
            	[
            		[28, '语文'],
            		[33, '数学'],
            		[42, '英语'],
            		[49, '物理'],
            		[65, '视频问答']
            	],
            	[
            		[29, '语文'],
            		[34, '数学'],
            		[43, '英语'],
            		[54, '化学'],
            		[50, '物理'],
            		[66, '视频问答']
            	],
            	[
            		[30, '语文'],
            		[35, '数学'],
            		[44, '英语'],
            		[51, '物理'],
            		[55, '化学'],
            		[67, '视频问答']
            	],
            	[
            		[31, '语文'],
            		[36, '数学'],
            		[46, '英语'],
            		[52, '物理'],
            		[56, '化学'],
            		[68, '视频问答']
            	],
            	[
            		[32, '语文'],
            		[37, '数学'],
            		[47, '英语'],
            		[53, '物理'],
            		[57, '化学'],
            		[69, '视频问答']
            	]
            ]
            var grade = $(this).val() -1;
            var arr =  grade_subject_arr[grade];
            var kmselect_html = "<select name=\"select\" id=\"select\" style='width:60px'>";
            for(var i = 0; i < arr.length; i++){
                var sid = arr[i][0];
                var sub = arr[i][1];
                kmselect_html += '<option value='+sid+'>'+sub+'</option>';
            }
            kmselect_html += '</select>';
            $('#kmselect').html(kmselect_html);
        })

        //=====================================
        $("input[name=radio]").click(function(){
            of = ($(this).val());
            if(of==0){
                $('#fentext').fadeOut();
            }else{
                $('#fentext').fadeIn();
            }
        })
        $('#sendAnswerImg').click(function(){
            title = ''+$('#textfield').val();
            if(title.replace(/\s/g, '') == ''){
                alert('标题不能为空');
                return false;
            }
            content = $('#wymeditor1').val();
            sid = $('#select').val();
            if(sid == ''){
                alert('请选择年级');
                return false;
            }
            score = 0;
            user = getCookie('user');
            uid = getCookie('userid');
            //console.log(user);
            //console.log(uid)
            if($('#radio').attr('checked') == true && $('#fentext').val() != ''){
                score = $('#fentext').val();
            }
            $('#sidinput').val(sid);
            $('#uidinput').val(uid);
            $('#userinput').val(user);
            document.askform.submit();
            /*
            url = 'act=ask&sid='+sid+'&uid='+uid+'&user='+user+'&title='+title+'&content='+content+'&score='+score
            $.ajax({
                url: '/newask/index.php/ajax/ajaxcom',
                type: 'post',
                data: url,
                dataType:'html',
                cache:false,
            	timeout: 10000,
                beforeSend: function(XMLHttpRequest){
                },
            	success: function(data) {
            	   //console.log(data);//return false;
            	   //alert(data); return false;
            	   cid = $('#selectclass').val();
                   window.location='/newask/index.php/askindex?type=1&w=all&sid='+cid;
            	},
            	error: function() {
            		alert('操作失败');
            	},
                complete: function(XMLHttpRequest, textStatus){
                }
            })*/
        })

        point = $(this).offset();
        $('#tc_tw2').css({'top':(point.top)+'px','left':point.left+'px'});
        $('.close_wind').click(function(){
            $('#tc_tw2').remove();
        })
    })

	//同步训练提交
	$('.form_bu #img_ok_send').click(function(){
		c_grade = $('.c_grade').html();
		c_subjects = $('.c_subjects').html();
		c_version = $('.c_version').html();
		c_zj = $('#zj').val();
		if(c_grade==''){
			alert('请选择年级！');
			return false;
		}
		if(c_subjects==''){
			alert('请选择科目！');
			return false;
		}
		if(c_version==''){
			alert('请选择版本！');
			return false;
		}
		if(c_zj==''){
			alert('请选择章节！');
			return false;
		}
		/*
		endb = $('#dbname').val();
		cndb = $('#cndbname').val();
		versionid = $('#version').val();
		versionname = $('input[name="i_vsionname"]').val();
		ajax_win('../skin/default/lib/ajax.php?act=docking&DBselect='+endb+'&DBname='+cndb+'&i_vsionname='+versionname+'&i_vsionID='+versionid,'selectzxks');
		*/
		document.sendsyn.submit();
	})
	
	//同步训练弹出层

	$('.t_button').click(function(){
		var xy = $(this).offset();
		var xtop = xy.top+'px';
		var yleft = xy.left+117+'px';
		$('.openwin').css({'top':xtop,'left':yleft}).fadeIn();
		if($('.openwin2').css('display')=='block'){
			$('.openwin2').fadeOut();
		}		
	})

	//关闭打开的浮动层
	$('.closed').click(function(){
		$(this).parent().parent().parent().fadeOut();
	})

	//删除选中的项
	$('.checkok ul li').find('a').each(function(i){
		$(this).click(function(){
			$(this).parent().html('');
		})
	})
	
	//新版同步训练弹出层开始
	$('.t_buttons').click(function(){
		var xy = $(this).offset();
		var xtop = xy.top+'px';
		var yleft = xy.left+117+'px';
		$('.openwins').css({'top':xtop,'left':yleft}).fadeIn();
		if($('.openwin2').css('display')=='block'){
			$('.openwin2').fadeOut();
		}		
		$.ajax({
			type:'get',
			url:'../ks/modules/newdata_ajax.php?ut=index_n',
			dateType:'html',
			cache:false,
			timeout:10000,
			success:function(msg){
				$('.grades .uls').html(msg);
			}
		});
	});
	
	$('.grades .uls').find('span').each(function(){
		$(this).css('cursor','pointer').click(function(){
			$(this).addClass('active2').siblings().removeClass();
			var grade = $(this).attr('value');
			//alert(grade);
			$('#grade').val($(this).attr('value'));
			//初始化版本
			$('.show_version').html('');
			//初始化章节
			$('.zj_div').html('章节：<select><option>选择课程</option></select>');
			$.ajax({
				type:'get',
				url:'../ks/modules/newdata_ajax.php?ut=index_k&gradeid='+grade,
				dateType:'html',
				cache:false,
				timeout:10000,
				beforeSend:function(XMLHttpRequest){
					divW = $('.openwin').width()-12+'px';
					divH = $('.openwin').height()+'px';
					divTop = '0px';
					$('.openwin').append('<div id="londdiv" style="color:#000;text-align: center;font-size:12px;font-weight:blod;line-height:'+divH+';width:'+divW+';height:'+divH+';background: #fff;position: absolute;;filter:alpha(opacity=70);-moz-opacity:0.7;-kHTML-opacity: 0.7;opacity: 0.7;top:'+divTop+';margin-left:12px;z-index:999">正在加载，请稍后……</div>');				
				},
				success:function(msg){
					//显示版本
					$('.show_subjiect').html(msg);
					//版本事件，版本
					$('.show_subjiect').css('cursor','pointer').find('span').click(function(){
						var km = $(this).html();
						$(this).addClass('active2').siblings().removeClass();
						var i_kemu = $(this).attr('value');
						$('#i_kemu').val($(this).attr('value'));
						//初始化章节
						$('.zj_div').html('章节：<select><option>选择课程</option></select>');
						$('.c_subjects').html(km+'<a href="javascript:;;" value=show_subjiect>X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
						var iarr = i_kemu.split('-'); 
						
						$('#dbname').val(iarr[3]);
						$('#cndbname').val(iarr[2]+iarr[1]+'同步库');						
						$.ajax({
							type:'get',
							url:'../ks/modules/newdata_ajax.php?ut=index_v&i_kemu='+encodeURIComponent(i_kemu),
							dateType:'html',
							cache:false,
							timeout:10000,
							beforeSend:function(XMLHttpRequest){
								divW = $('.openwin').width()-12+'px';
								divH = $('.openwin').height()+'px';
								divTop = '0px';
								$('.openwin').append('<div id="londdiv" style="color:#000;text-align: center;font-size:12px;font-weight:blod;line-height:'+divH+';width:'+divW+';height:'+divH+';background: #fff;position: absolute;;filter:alpha(opacity=70);-moz-opacity:0.7;-kHTML-opacity: 0.7;opacity: 0.7;top:'+divTop+';margin-left:12px;z-index:999">正在加载，请稍后……</div>');				
							},
							success:function(msg){								
								$('.show_version').html(msg);									
								//版本事件，关联章节
								$('.show_version').css('cursor','pointer').find('span').click(function(){
									var vs = $(this).html();
									var i_version = $(this).attr('value');
									$('#version').val($(this).attr('value'));
									$('.c_version').html(vs+'<a href="javascript:;;" value=show_version>X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
									$(this).addClass('active2').siblings().removeClass();
																	
									var dbname = $('#dbname').val();
									var cndbname = $('#cndbname').val();
									var version = $('#version').val();
									var grade = $('#grade').val();
									var i_kemu = $('#i_kemu').val();
									$.ajax({
										type:'get',
										url:'../ks/modules/newdata_ajax.php?ut=index_z&dbname='+dbname+'&cndbname='+encodeURIComponent(cndbname)+'&version='+version+'&grade='+grade+'&i_kemu='+i_kemu+'&i_zhangjie='+i_version,
										dateType:'html',
										cache:false,
										timeout:10000,
										beforeSend:function(XMLHttpRequest){
											divW = $('.openwin').width()-12+'px';
											divH = $('.openwin').height()+'px';
											divTop = '0px';
											$('.openwin').append('<div id="londdiv" style="color:#000;text-align: center;font-size:12px;font-weight:blod;line-height:'+divH+';width:'+divW+';height:'+divH+';background: #fff;position: absolute;;filter:alpha(opacity=70);-moz-opacity:0.7;-kHTML-opacity: 0.7;opacity: 0.7;top:'+divTop+';margin-left:12px;z-index:999">正在加载，请稍后……</div>');				
										},
										//////////////////////////////////////////////////////
										success:function(msg){
											$('.zj_div').html('章节得到：'+msg);
											$('#selectZ').change(function(){
												$('#zj').val($(this).val())
											})
										},
										error: function() {
						    			alert('操作失2败');
						    		},
						    		complete: function(XMLHttpRequest, textStatus){
						            $('#londdiv').remove();
						        }
									});
									delmores();
								});
								
								
								
							},
							error: function() {
			    			alert('操作失2败');
			    		},
			    		complete: function(XMLHttpRequest, textStatus){
			            $('#londdiv').remove();
			        }
						});
						delmores();
					});
				},
				error: function() {
    			alert('操作失1败');
    		},
        complete: function(XMLHttpRequest, textStatus){
            $('#londdiv').remove();
        }
			});			
			$('.c_grade').html($(this).html()+'<a href="javascript:;;" value=uls>X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
			delmores();			
		});	
	});	
	
	
	
	
	//新版同步训练弹出层结束
	
	
	
	//选择年级
	$('.grade ul').find('li').each(function(){
		$(this).css('cursor','pointer').click(function(){
			$(this).addClass('active2').siblings().removeClass();
			grade = $(this).attr('values');
			//$('#cndbname').val(rtrim(ltrim($(this).html())));
            $('#db_head').val($(this).attr('values'))
			switch(grade){
				case 'LC_P':
					$('.subjects').html('科目：<ul><li values="CCH003E">语文</li><li values="OMA000E">数学</li><li values="EEN004E">英语</li></ul>');
					selectsubject();
					break;
				case 'LC_J':
					$('.subjects').html('科目：<ul><li values="CCH033E">语文</li><li values="OMA030E">数学</li><li values="EEN034E">英语</li><li values="OBI037E">生物</li><li values="OGE036E">地理</li><li values="OCE032E">化学</li><li values="OPO038E">政治</li><li values="OHI035E">历史</li><li values="OPH031E">物理</li></ul>');//数学，物理，化学，语文，英语，历史，地理，生物，政治
					selectsubject();
					break;
				case 'LC_H':
					$('.subjects').html('科目：<ul><li values="CCH063E">语文</li><li values="OMA060E">数学</li><li values="EEN064E">英语</li><li values="OBI067E">生物</li><li values="OGE066E">地理</li><li values="OCE062E">化学</li><li values="OPO068E">政治</li><li values="OHI065E">历史</li><li values="OPH061E">物理</li></ul>');//数学，物理，化学，语文，英语，历史，地理，生物，政治
					selectsubject();
					break
			}
			$('.c_grade').html($(this).html()+'<a href="javascript:;;">X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
			delmore();
		})
	})
	function selectsubject(){
		//选择科目
		$('.subjects ul').find('li').each(function(){
			$(this).css('cursor','pointer').click(function(){
				$(this).addClass('active2').siblings().removeClass();
                //dbname = $('#db_head').val()+($(this).attr('values'));
				gradename = '';
                $('#dbname').val($('#db_head').val()+$(this).attr('values'));
				$('.grade ul li').each(function(){
					if($(this).attr('class')=='active2'){
						gradename = rtrim(ltrim($(this).html()));
					}
				})
				$('#cndbname').val(gradename+rtrim(ltrim($(this).html()))+'同步库');
				ajax_win('../skin/default/lib/ajax.php?act=vesion&dbname='+($('#db_head').val()+$(this).attr('values'))+'&cndbname='+$('#cndbname').val(),'syn');
				$('.c_subjects').html($(this).html()+'<a href="javascript:;;">X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
				delmore();
			})
		})
	}

	function selectsubject2(){
		//选择科目
		$('.subjects2 ul').find('li').each(function(){
			$(this).css('cursor','pointer').click(function(){
				$(this).addClass('active2').siblings().removeClass();

				$('.c_subjects2').html($(this).html()+'<a href="javascript:;;">X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
				delmore();
			})
		})
	}

	$('.grade2 ul').find('li').each(function(){
		$(this).css('cursor','pointer').click(function(){
			$(this).addClass('active2').siblings().removeClass();
			grade = rtrim(ltrim($(this).html()));
			switch(grade){
				case '小学':
					$('.subjects2').html('科目：<ul><li values="CCH003E">语文</li><li values="OMA000E">数学</li><li values="EEN004E">英语</li></ul>');
					selectsubject2();
					break;
				case '初中':
					$('.subjects2').html('科目：<ul><li values="CCH033E">语文</li><li values="OMA030E">数学</li><li values="EEN034E">英语</li><li values="OBI037E">生物</li><li values="OGE036E">地理</li><li values="OCE032E">化学</li><li values="OPO038E">政治</li><li values="OHI035E">历史</li><li values="OPH031E">物理</li></ul>');//数学，物理，化学，语文，英语，历史，地理，生物，政治
					selectsubject2();
					break;
				case '高中':
					$('.subjects2').html('科目：<ul><li values="CCH033E">语文</li><li values="OMA030E">数学</li><li values="EEN034E">英语</li><li values="OBI037E">生物</li><li values="OGE036E">地理</li><li values="OCE032E">化学</li><li values="OPO038E">政治</li><li values="OHI035E">历史</li><li values="OPH031E">物理</li></ul>');//数学，物理，化学，语文，英语，历史，地理，生物，政治
					selectsubject2();
					break
			}

			$('.c_grade2').html($(this).html()+'<a href="javascript:;;">X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
			delmore();
		})
	})


	$('.subjects2 ul').find('li').each(function(){
		$(this).css('cursor','pointer').click(function(){
			$(this).addClass('active2').siblings().removeClass();

			$('.c_subjects2').html($(this).html()+'<a href="javascript:;;">X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
			delmore();
		})
	})





	//右边排名图标初始化
	rest();
	rest2();
	rest3();
	rest4();
	//时间初始化
	if($('.times').length > 0){
		$('.times').jclock({withDate:true, withWeek:true});
	}

	$('.start_div').each(function(i){
			$(this).find('ul li').each(function(i){
				$(this).mouseover(function(){
					$(this).addClass('start_active').siblings().removeClass();
					$(this).find('a').css({'background':'url(/skin/default/images/on'+(i+1)+'.gif) no-repeat','height':'19px','display':'block','color':'#ff5e3a','line-height':'19px'});
					rest();
				})
			})
	})

	$('.move_top_list').each(function(i){
			$(this).find('li').each(function(i){
				$(this).mouseover(function(){
					$(this).addClass('start_active').siblings().removeClass();
					$(this).find('a').css({'background':'url(/skin/default/images/on'+(i+1)+'.gif) no-repeat','height':'19px','display':'block','color':'#ff5e3a','line-height':'19px'});
					rest3();
				})
			})
	})


	$('.start_div2 ul li').each(function(i){
		$(this).mouseover(function(){
			$(this).addClass('start2_active').siblings().removeClass();
			$(this).find('a').css({'height':'19px','display':'block','color':'#ff5e3a','line-height':'19px'});
			rest2();
		})
	})
	//代++++++++++++++++++++++++++++++
	$('.move_div .move_top li').each(function(i){
		$(this).mouseover(function(){
			$(this).addClass('start2_active').siblings().removeClass();
			$(this).find('a').css({'height':'18px','display':'block','color':'#ff5e3a','line-height':'18px'});
			rest4();
		})
	})

	//资源显示效果
	$('.psshow ul li').each(function(i){
		$(this).mouseover(function(){
			position = $(this).offset();
			x = position.top-20;
			y = position.left-30;
			$('.active_flash01').remove();
			$('body').append('<div class="active_flash01" style="position:absolute;top:'+x+'px;left:'+y+'px; ">'+$(this).html()+'</div>');
			$('.active_flash01').fadeIn(500);
			$('.active_flash01').mouseout(function(){
				$(this).remove();
			})
		})
	})

})


function ajax_win(url,act){
    $.ajax({
    	type: "get",
    	url: url,
    	dataType: 'html',
    	cache: false,
    	timeout: 10000,
        beforeSend: function(XMLHttpRequest){
            divW = $('.openwin').width()-12+'px';
            divH = $('.openwin').height()+'px';
            divTop = '0px';
            $('.openwin').append('<div id="londdiv" style="color:#000;text-align: center;font-size:12px;font-weight:blod;line-height:'+divH+';width:'+divW+';height:'+divH+';background: #fff;position: absolute;;filter:alpha(opacity=70);-moz-opacity:0.7;-kHTML-opacity: 0.7;opacity: 0.7;top:'+divTop+';margin-left:12px;z-index:999">正在加载，请稍后……</div>');
        },
    	success: function(msg) {
			switch(act){
				case 'syn':
					$('.version').html(msg);
					//选择版本
					$('.version ul').find('li').each(function(){
						$(this).css('cursor','pointer').click(function(){
							$(this).addClass('active2').siblings().removeClass();
							ajax_win('../skin/default/lib/ajax.php?act=zj&dbname='+$('#dbname').val()+'&IndexCode='+$(this).attr('values')+'&vsionname='+$(this).html(),'zj');
							$('.c_version').html(($(this).html()).substr(0,7)+'<a href="javascript:;;">X</a>').css({'margin':'0px 5px','padding':'0px 5px'});
							//$('#version').val($(this).attr('values'));
							//$('input[name="i_vsionname"]').val($(this).html());
							delmore();
						})
					})
				break;
				case 'zj':
				   $('.zj_div').html('章节：'+msg);
				   $('#selectZ').change(function(){
						$('#zj').val($(this).val())
					})
				break;
				case 'selectzxks':	//对接在线考试，将用户选择的数据库，版本，存放session
					if(msg == '1'){
						document.sendsyn.submit();
					}
				break
			}
    	},
    	error: function() {
    		alert('操作失1败');
    	},
        complete: function(XMLHttpRequest, textStatus){
            $('#londdiv').remove();
        }
    })
}

function rest(){
	$('.start_div').each(function(i){
		$(this).find('ul li').each(function(i){
			if($(this).attr('class') ==''){
				$(this).find('a').css({'background':'url(/skin/default/images/off'+(i+1)+'.gif) no-repeat 6px 0px','height':'19px','display':'block','color':'#000','line-height':'19px'});
			}
		})
	})
}

function rest2(){
	$('.start_div2 ul li').each(function(i){
		if($(this).attr('class') ==''){
			$(this).find('a').css({'height':'19px','display':'block','color':'#000','line-height':'19px'});
		}
	})
}

function rest3(){
	$('.move_top_list').each(function(i){
			$(this).find('li').each(function(i){
				if($(this).attr('class') ==''){
					$(this).find('a').css({'background':'url(/skin/default/images/off'+(i+1)+'.gif) no-repeat 6px 0px','height':'19px','display':'block','color':'#000','line-height':'19px'});
				}
			})
	})
}

function delmores(){
	//删除选中的项
	$('.checkok ul li').find('a').each(function(i){
		$(this).click(function(){
			var v = $(this).attr('value');
			$('.'+v).find('span').each(function(){
				$(this).removeClass("active2");
			});
			//初始化章节
			$('.zj_div').html('章节：<select><option>选择课程</option></select>');
			$(this).parent().html('').css({'margin':'0px 0px','padding':'0px 0px'});
		})
	})
}

//代++++++++++++++++++++
function rest4(){
	$('.move_div .move_top li').each(function(i){
		if($(this).attr('class') ==''){
			$(this).find('a').css({'height':'18px','display':'block','color':'#000','line-height':'18px'});
		}
	})
}

function delmore(){
	//删除选中的项
	$('.checkok ul li').find('a').each(function(i){
		$(this).click(function(){
			$(this).parent().html('').css({'margin':'0px 0px','padding':'0px 0px'});;
		})
	})

	$('.checkok2 ul li').find('a').each(function(i){
		$(this).click(function(){
			$(this).parent().html('').css({'margin':'0px 0px','padding':'0px 0px'});;
		})
	})

}

//根据COOKIE选定相应的导航
function selectnav(){
    if(getCookie('navt') == ''){
       // alert(getCookie('navt'));
        $('.navtow_ul li').find('a').eq(0).addClass('current').siblings().removeClass();
    }else{
        switch(getCookie('navt')){
            case '名校题库':
                $('.navtow_ul li').find('a').eq(1).addClass('current').siblings().removeClass();
            break;
            case '天天一练':
                $('.navtow_ul li').find('a').eq(2).addClass('current').siblings().removeClass();
            break;
            case '每周精练':
                $('.navtow_ul li').find('a').eq(3).addClass('current').siblings().removeClass();
            break;
            case '数理化一点通':
                $('.navtow_ul li').find('a').eq(4).addClass('current').siblings().removeClass();
            break;
            case '名师视频':
                $('.navtow_ul li').find('a').eq(5).addClass('current').siblings().removeClass();
            break;
        }
    }
}
//判断用户是否登陆，然后根据身份进入相应的频道
function checklogin(){
	switch(getCookie('nav')){
		case '1':
			$('#nav_ul_main li').eq(0).addClass('active_nav').siblings().removeClass();
			switchzk('0')
		break;
		case '2':
			$('#nav_ul_main li').eq(1).addClass('active_nav').siblings().removeClass();
			switchzk('1')
		break;
		default:
			$('#nav_ul_main li').eq(0).addClass('active_nav').siblings().removeClass();
			switchzk('0');
	}
}

//根据用户标识，切换周刊
function switchzk(isInt){
  switch(isInt){
    case '0':
        $('#h_mid_div_right').html('<ul><li><a target="_blank" href="http://www.todayedu.cn/xszk/">江苏学生周刊<img src="http://www.todayedu.cn//skin/default/images/li_select.gif" class="li_select"></a></li><li><a target="_blank"  href="http://www.ahtodayedu.com/">安徽学生周刊<img src="http://www.todayedu.cn/skin/default/images/li_select.gif" class="li_select"></a></li><li><a target="_blank" href="http://www.hntodayedu.com/">河南成长导报<img src="http://www.todayedu.cn/skin/default/images/li_select.gif" class="li_select"></a></li></ul>');
        break;
    case '1':
        $('#h_mid_div_right').html('<ul><li><a  target="_blank" href="http://www.todayedu.cn/jyzk/">江苏教育周刊<img src="http://www.todayedu.cn//skin/default/images/li_select.gif" class="li_select"></a></li><li><a target="_blank" href="http://ky.ahtodayedu.com/">安徽教育周刊<img src="http://www.todayedu.cn/skin/default/images/li_select.gif" class="li_select"></a></li><li><a target="_blank" href="http://www.hntodayedu.com/">河南成长导报<img src="http://www.todayedu.cn/skin/default/images/li_select.gif" class="li_select"></a></li></ul>');
        break;
  }
}


function setCookie(c_name,value,expiredays){
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/;";
}

function getCookie(c_name){
    if (document.cookie.length>0){
        c_start=document.cookie.indexOf(c_name + "=")
          if (c_start!=-1){
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
               if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))
    }
  }
    return ""
}

function DeleteCookie(name) {
            var date = new Date();
            date.setTime(date.getTime() - 10000); //删除一个cookie，就是将其过期时间设定为一个过去的时间
            document.cookie = name + "=删除" + "; expires=" + date.toUTCString();
            //document.cookie = " " + name + "=删除" + "; expires=" + date.toGMTString();
        }

function ltrim(s){
return s.replace( /^\s*/, "");
}
//去右空格;
function rtrim(s){
return s.replace( /\s*$/, "");
}
//左右空格;
function trim(s){
return rtrim(ltrim(s));
}
function getCookie1(name)
{
    var mycookie=unescape(document.cookie);
    var cindex=mycookie.indexOf(name+"=");
    if(cindex!=-1)
    {
        var cstart=cindex+name.length+1;
        var cend=mycookie.indexOf(";",cstart);
        //如果找不到分号，则取cookie的最后
        if(cend==-1)
        {
            cend=mycookie.length;
        }
        var value= mycookie.substring(cstart,cend);
        if(value.indexOf('~')){
            return value.split('~')[1];
        }
        return value;
    }
}


function submitForm(){$('#sendAnswerImg').click();}
function pageinit(name,act){
	var allPlugin={
		/*drawing:{c:'drawing',t:'画图',e:function(){
			window.showModalDialog("/newask/index.php/switch/showdarwing?act=drawing",window,"dialogLeft:center;dialogTop:center;dialogWidth:540px;dialogHeight:440px;resizable:yes;status:no;help:no");
		}},*/
		drawing:{c:'drawing',t:'画图',e:function(){
			window.showModalDialog("/showdarwing/index.php?act=drawing",window,"dialogLeft:center;dialogTop:center;dialogWidth:567px;dialogHeight:524px;resizable:yes;status:no;help:no");
		}},
		formula:{c:'formula',t:'Flash公式',e:function(){
			window.showModalDialog("/newask/index.php/switch/showdarwing?act=formula",window,"dialogLeft:center;dialogTop:center;dialogWidth:840px;dialogHeight:560px;resizable:yes;status:no;help:no");
		}}
	};
    if(act=='full'){
    	editor=$(name).xheditor({plugins:allPlugin,tools:'Fontface,FontSize,Bold,Italic,Underline,Strikethrough,|,Align,List,|,Link,Img,Cut,Copy,Paste,Pastetext,drawing,formula,|,Flash,Media,Emot,Table,|,Source,Fullscreen',upImgUrl:"http://www.todayedu.cn/skin/default/lib/upload_php.php",upImgExt:"jpg,jpeg,gif,png",shortcuts:{'ctrl+enter':submitForm}});
    }else{
    	editor = $(name).xheditor({plugins:allPlugin,tools:'Fontface,FontSize,Bold,Italic,Underline,Strikethrough,|,Align,List,|,Link,Img,Cut,Copy,Paste,Pastetext,drawing,formula,|,Flash,Media,Emot,|,Source',upImgUrl:"http://www.todayedu.cn/skin/default/lib/upload_php.php",upImgExt:"jpg,jpeg,gif,png",shortcuts:{'ctrl+enter':submitForm}});
    }
}
function drawingFormula(){
	window.showModalDialog(paths+"formula.html",window,"dialogLeft:center;dialogTop:center;dialogWidth:840px;dialogHeight:560px;resizable:yes;status:no;help:no");
}

function drawing(){
	window.showModalDialog(paths+"drawing.html",window,"dialogLeft:center;dialogTop:center;dialogWidth:560px;dialogHeight:470px;resizable:yes;status:no;help:no");
}
function insertFormula(value){
	 editor.pasteHTML(value);
}

function suolve(str,l){
   var sub_length = l ;
    var temp1 = str.replace(/[^\x00-\xff]/g,"**");
    var temp2 = temp1.substring(0,sub_length);
    var x_length = temp2.split("\*").length - 1 ;
    var hanzi_num = x_length /2 ;
    sub_length = sub_length - hanzi_num ;
    var res = str.substring(0,sub_length);
    if(sub_length < str.length ){
        var end  =res+"…" ;
    }else{
        var end  = res ;
    }
    return end ;
}


