/* Event Function */
var Event = new Object();

Object.prototype.addEvent=function(element,e,fn){
	if(element.addEventListener){
		element.addEventListener(e,fn,false);
	}
	else{
		element.attachEvent('on'+e,fn);
	}
}

Object.prototype.delEvent=function(element,e,fn){
	if(element.removeEventListener){
		element.removeEventListener(e,fn,false);
	}
	else if(element.detachEvent)
	{
		element.detachEvent('on'+e,fn);
	}
}

var $A = Array.from=function(iterable){
	if (!iterable)return [];
	if (iterable.toArray){
		return iterable.toArray();
	}
	else
	{
		var results=[];
		for(var i=0,length=iterable.length;i<length;i++)results.push(iterable[i]);
		return results;
	}
}

Function.prototype.bind = function()
{
	var __method = this, args = $A(arguments), object = args.shift();
	return function(){return __method.apply(object, args.concat($A(arguments)));}
}

/* SystemInit */
Event.addEvent( window,'load',SystemInit);
var IE = (document.getElementById && document.all) ? true : false;
function SystemInit()
{
	/* PageInit */
	if(typeof(PageInit)=='function')PageInit();
	if(typeof(StartInit)=='function')StartInit();

	if(IE){fixLink();}

	var username_b = getCookie('username_b');
	if(username_b && $('remember'))
	{
		$('username_b').value = username_b;
		$('remember').checked = 'checked';
	}
}

/* GetObject */
function $(str){return document.getElementById(str);}

/* Select Option */
function addItem(obj,text,value)
{
	obj.options.add( new Option(text, value) );
}

function fixLink()
{
	var objs = document.getElementsByTagName('A');
	for(var i in objs)
	{
		objs[i].onfocus = function(){this.blur();};
	}
}

function setCookie(name,value)
{
	var Days = 30;
	var exp  = new Date();
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
function getCookie(name)
{
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)) return unescape(arr[2]);
	else return null;
}
function delCookie(name)
{
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}

/*---------------------------------------- */

var ajax_count=0;function ajax(){var f=arguments.length>0?typeof(arguments[0])=="object"?arguments[0]:{}:{};function a(e,l){return e!=undefined?e:l;}var c=function(){};var h=["url","content","method","timeout","async","isxml","oncomplete","onstart","onend","onchange","ontimeout","onerror","id"];var n=["","","GET",360000,true,false,c,c,c,c,c,c,""],m=h.length;while(m--){this[h[m]]=a(f[h[m]],n[m]);}f=null,h=null,c=null,n=null,m=null;var k=new Date(),u;var s={oncomplete:this.oncomplete,onstart:this.onstart,onend:this.onend,onchange:this.onchange,ontimeout:this.ontimeout,onerror:this.onerror};var r={url:this.url,content:this.content,method:this.method,timeout:this.timeout,id:this.id,isxml:this.isxml,status:0};var o=null;var p=["MSXML2.XMLHTTP","Microsoft.XMLHTTP"];try{o=new XMLHttpRequest;}catch(q){for(i=0;i<p.length;i++){try{o=new ActiveXObject(p[i]);}catch(g){continue;}break;}}if(!o){return false;}this.url+=(this.url.indexOf("?")>0?"&":"?")+"rnd="+Math.random();o.open(this.method,this.url,this.async);if(this.method.toUpperCase()=="POST"){o.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}o.setRequestHeader("X-Requested-With","XMLHttpRequest");this.onstart.call(r);ajax_count++;this.onchange.call(r);var b=false;var j=setTimeout(function(){ajax_count--;s.onchange.call(r);s.ontimeout.call(r);b=true;o.abort();s.onend.call(r);},this.timeout);o.send(this.content);if(!this.async){try{clearTimeout(j);}catch(q){}t();}o.onreadystatechange=t;function t(){u=new Date();if(o.readyState==4&&!b){ajax_count--;s.onchange.call(r);try{clearTimeout(j);}catch(l){}r.status=o.status;try{if(o.status==200){d();}else{s.onerror.call(r);}}catch(l){s.onerror.call(r);}}}function d(){if(r.isxml){var e=o.responseXML;if(e==null){var l=new DOMParser();e=l.parseFromString(o.responseText,"text/xml");}s.oncomplete.call({data:e,id:r.id,time:u-k});}else{s.oncomplete.call({data:o.responseText,id:r.id,time:u-k});}s.onend.call(r);}return true;}

/*---------------------------------------- */

// PNGHandler: Object-Oriented Javascript-based PNG wrapper
// --------------------------------------------------------
// Version 1.1.20031218
// Code by Scott Schiller - www.schillmania.com
// --------------------------------------------------------
// Description:
// Provides gracefully-degrading PNG functionality where
// PNG is supported natively or via filters (Damn you, IE!)
// Should work with PNGs as images and DIV background images.

function PNGHandler() {
  var self = this;

  this.na = navigator.appName.toLowerCase();
  this.nv = navigator.appVersion.toLowerCase();
  this.isIE = this.na.indexOf('internet explorer')+1?1:0;
  this.isWin = this.nv.indexOf('windows')+1?1:0;
  this.ver = this.isIE?parseFloat(this.nv.split('msie ')[1]):parseFloat(this.nv);
  this.isMac = this.nv.indexOf('mac')+1?1:0;
  this.isOpera = (navigator.userAgent.toLowerCase().indexOf('opera ')+1 || navigator.userAgent.toLowerCase().indexOf('opera/')+1);
  if (this.isOpera) this.isIE = false; // Opera filter catch (which is sneaky, pretending to be IE by default)

  this.transform = null;

  this.getElementsByClassName = function(className,oParent) {
    doc = (oParent||document);
    matches = [];
    nodes = doc.all||doc.getElementsByTagName('*');
    for (i=0; i<nodes.length; i++) {
      if (nodes[i].className == className || nodes[i].className.indexOf(className)+1 || nodes[i].className.indexOf(className+' ')+1 || nodes[i].className.indexOf(' '+className)+1) {
        matches[matches.length] = nodes[i];
      }
    }
    return matches; // kids, don't play with fire. ;)
  }

  this.filterMethod = function(oOld) {
    // IE 5.5+ proprietary filter garbage (boo!)
    // Create new element based on old one. Doesn't seem to render properly otherwise (due to filter?)
    // use proprietary "currentStyle" object, so rules inherited via CSS are picked up.

    var o = document.createElement('div'); // oOld.nodeName
    var filterID = 'DXImageTransform.Microsoft.AlphaImageLoader';
    // o.style.width = oOld.currentStyle.width;
    // o.style.height = oOld.currentStyle.height;

    if (oOld.nodeName == 'DIV') {
      var b = oOld.currentStyle.backgroundImage.toString(); // parse out background image URL
      oOld.style.backgroundImage = 'none';
      // Parse out background image URL from currentStyle object.
      var i1 = b.indexOf('url("')+5;
      var newSrc = b.substr(i1,b.length-i1-2).replace('.gif','.png'); // find first instance of ") after (", chop from string
      o = oOld;
      o.style.writingMode = 'lr-tb'; // Has to be applied so filter "has layout" and is displayed. Seriously. Refer to http://msdn.microsoft.com/workshop/author/filter/reference/filters/alphaimageloader.asp?frame=true
      o.style.filter = "progid:"+filterID+"(src='"+newSrc+"',sizingMethod='crop')";
      // Replace the old (existing) with the new (just created) element.
      // oOld.parentNode.replaceChild(o,oOld);
    } else if (oOld.nodeName == 'IMG') {
      var newSrc = oOld.getAttribute('src').replace('.gif','.png');
      // apply filter
      oOld.src = './images/none.gif'; // get rid of image
      oOld.style.filter = "progid:"+filterID+"(src='"+newSrc+"',sizingMethod='crop')";
      oOld.style.writingMode = 'lr-tb'; // Has to be applied so filter "has layout" and is displayed. Seriously. Refer to http://msdn.microsoft.com/workshop/author/filter/reference/filters/alphaimageloader.asp?frame=true
    }
  }

  this.pngMethod = function(o) {
    // Native transparency support. Easy to implement. (woo!)
    bgImage = this.getBackgroundImage(o);
    if (bgImage) {
      // set background image, replacing .gif
      o.style.backgroundImage = 'url('+bgImage.replace('.gif','.png')+')';
    } else if (o.nodeName == 'IMG') {
      o.src = o.src.replace('.gif','.png');
    } else if (!this.isMac) {
      // window.status = 'PNGHandler.applyPNG(): Node is not a DIV or IMG.';
    }
  }

  this.getBackgroundImage = function(o) {
    var b, i1; // background-related variables
    var bgUrl = null;

    if (o.nodeName == 'DIV' && !(this.isIE && this.isMac)) { // ie:mac PNG support broken for DIVs with PNG backgrounds
      if (document.defaultView) {
        if (document.defaultView.getComputedStyle) {
          b = document.defaultView.getComputedStyle(o,'').getPropertyValue('background-image');
          i1 = b.indexOf('url(')+4;
          bgUrl = b.substr(i1,b.length-i1-1);
        } else {
          // no computed style
        }
      } else {
        // no default view
      }
    }
    return bgUrl;
  }
  
  this.supportTest = function() {
    // Determine method to use.
    // IE 5.5+/win32: filter

    if (this.isIE && this.isWin && this.ver >= 5.5) {
      // IE proprietary filter method (via DXFilter)
      self.transform = self.filterMethod;
    } else if (!this.isIE && this.ver < 5) {
      self.transform = null;
      // No PNG support or broken support
      // Leave existing content as-is
    } else if (!this.isIE && this.ver >= 5 || (this.isIE && this.isMac && this.ver >= 5)) { // version 5+ browser (not IE), or IE:mac 5+
      self.transform = self.pngMethod;
    } else {
      // Presumably no PNG support. GIF used instead.
      self.transform = null;
      return false;
    }
    return true;
  }

  this.init = function() {
    if (this.supportTest()) {
      this.elements = this.getElementsByClassName('png');
      for (var i=0; i<this.elements.length; i++) {
        this.transform(this.elements[i]);
      }
    }
  }

}

// Instantiate and initialize PNG Handler

var pngHandler = new PNGHandler();

/*---------------------------------------- */

var Dialog = (function()
{
	var inner;
	var _id;
	var _fulldiv;
	var _show = false;
	return inner = {
		show : function(id,bg)
		{
			bg = typeof(bg)=='undefined' || bg ? true : false;
			if(_show)return;
			_id = $(id);
			if(_id)
			{
				var p = getPageSize();
				var st = getPageScroll()[1];
				var width = p[0];
				var height = p[3];

				_id.style.display = '';
				_show = true;

				var leftPos = width = (width-_id.offsetWidth)/2;
				var topPos = (height-_id.offsetHeight)/2 + st;

				if(leftPos<=0)leftPos=0;
				if(topPos<=0)topPos=0;

				_id.style.left = leftPos+'px';
				_id.style.top = topPos+'px';
				_id.style.zIndex = 100;

				if(bg)
				{
					_fulldiv = $('fulldiv');
					if(!_fulldiv)
					{
						_fulldiv = document.createElement('DIV');
						_fulldiv.id = 'fulldiv';
						_fulldiv.style.position = 'absolute';
						_fulldiv.style.backgroundColor = '#000000';
						_fulldiv.style.left = '0px';
						_fulldiv.style.top = '0px';
						_fulldiv.style.zIndex = '10';
						document.body.appendChild(_fulldiv);
					}
					setOpacity(_fulldiv,60);
					_fulldiv.style.display="";
					_fulldiv.style.width='100%';
					_fulldiv.style.height=p[1]+'px';
				}
				hideSelect( getWindow() );
			}
		},
		hide : function()
		{
			if(_id)
			{
				_id.style.display = 'none';
				_show = false;
				_id = null;
			}
			if(_fulldiv)
			{
				_fulldiv.style.display = 'none';
				_fulldiv = null;
			}

			showSelect( getWindow() );
		}
	}
})();

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight) // all but Explorer Mac
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var winWidth, winHeight;
	if (self.innerHeight) // all except Explorer
	{
		winWidth = self.innerWidth;
		winHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	height = yScroll < winHeight ? winHeight : yScroll;
	width = xScroll < winWidth ? winWidth : xScroll;

	arrayPageSize = new Array(width,height,winWidth,winHeight)
	return arrayPageSize;
}

function setOpacity(obj, opacity) {
	if(obj){
		opacity = (opacity == 100)?99.999:opacity;
		if(document.getElementById && document.all)obj.style.filter = "alpha(opacity:"+opacity+")";// IE/Win
		obj.style.KHTMLOpacity = opacity/100;// Safari<1.2, Konqueror
		obj.style.MozOpacity = opacity/100;// Older Mozilla and Firefox
		obj.style.opacity = opacity/100;// Safari 1.2, newer Firefox and Mozilla, CSS3
	}
}


function hideSelect(doc)
{
	var	slts = doc.getElementsByTagName('SELECT')
	for(var	i=0;i<slts.length;i++)
	{
		if(slts[i].getAttribute('status')!='show' && slts[i].getAttribute('alt')!='always')slts[i].style.visibility = 'hidden';
	}
	var	objs = doc.getElementsByTagName('OBJECT')
	for(var	i=0;i<objs.length;i++)
	{
		if(objs[i].getAttribute('status')!='show')objs[i].style.visibility = 'hidden';
	}
	var	frms = doc.getElementsByTagName('IFRAME');
	for(var	i=0;i<frms.length;i++)
	{
		try{ hideSelect(frms[i].contentWindow.document); }
		catch(e){}
	}
}

function showSelect(doc)
{
	var	slts = doc.getElementsByTagName('SELECT')
	for(var	i=0;i<slts.length;i++)
	{
		if(slts[i].getAttribute('alt')!='always')slts[i].style.visibility = '';
	}
	var	objs = doc.getElementsByTagName('OBJECT')
	for(var	i=0;i<objs.length;i++)
	{
		objs[i].style.visibility = '';
	}
	var	frms = doc.getElementsByTagName('IFRAME');
	for(var	i=0;i<frms.length;i++)
	{
		try{ showSelect(frms[i].contentWindow.document); }
		catch(e){}
	}
}

function getPageScroll()
{
	var yScroll;
	if (self.pageYOffset)
	{
		yScroll = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
	{
		yScroll = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function getWindow()
{
	var	topWindow =	window.parent ;
	while (	topWindow.parent &&	topWindow.parent !=	topWindow )
	{
		try
		{
			if ( topWindow.parent.document.domain != document.domain )
				break ;
			if ( topWindow.parent.document.getElementsByTagName( 'frameset'	).length > 0 )
				break ;
		}
		catch (	e )
		{
			break ;
		}
		topWindow =	topWindow.parent ;
	}
	return topWindow.document ;
}

/*---------------------------------------- */

function openMaxWin(url)
{
	var sh=window.screen.availHeight;
	var sw=window.screen.availWidth-8;
	window.open (url, '', 'height='+sh+', width='+sw+', left=0, top=0, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');
}

function view(id,pid)
{
	var url = e3 + '/ebook/ebook.opener.php';
	var tid = $('subjectId').options[$('subjectId').selectedIndex].getAttribute('title');

	var gid = gradeId;
	var cid = classId;

	if(userAccType==3)
	{
		var gc = $('gradeId').value.split('-');
		gid = gc[0];
		cid = gc[1];
	}

	url += '?CategoryId='+$('subjectId').value+'&ResourceId='+id+'&PResourceId='+pid;
	url += '&SchoolId='+schoolId+'&YearId='+yearId+'&TermId='+$('termId').value+'&GradeId='+gid+'&ClassId='+cid;
	url += '&UserId='+userId+'&InterfaceLanguage='+lang;
	url += '&UserType='+userAccType;
	if(userAccType==2)
	{
		url += '&MyTeacherId='+tid;
	}

	openMaxWin(url);
}

function login()
{
	var username_a = $('username_a').value;
	var username_b = $('username_b').value;
	var userpass = $('userpass').value;

	if(username_a.length==0)
	{
		alert(username_require);
		$('username_a').focus();
		return;
	}
	else if(userpass.length==0)
	{
		alert(userpass_require);
		$('userpass').focus();
		return;
	}

	ajax({url:'service.php',method:'post',content:'act=login&username='+encodeURIComponent(username_a+(username_b.length>0?'@'+username_b:''))+'&userpass='+encodeURIComponent(userpass),oncomplete:function(){																																																
		if(this.data>0)
		{
			if($('remember').checked)
			{
				setCookie('username_b', username_b);
			}
			else
			{
				delCookie('username_b');
			}
			document.location.href = document.location.href;
		}
		else
		{
			if(this.data == '-1') {
				alert(txt_02);
			} else {
				alert(username_or_userpass_error);
				$('userpass').value = '';
			}
		}
	}});
}

var cache_data = {};
function getConfig()
{
	var subjectId = $('subjectId').value;
	var termId = $('termId').value;
	var yearId = $('yearId').value;
	var gradeIdVal = $('gradeId').value;
	var tmpArr = gradeIdVal.split('-');
	var _gradeId = tmpArr[0];
	var _classId = tmpArr[1];

	if($('dayId'))$('dayId').style.display = 'none';
	if($('weekId'))$('weekId').style.display = 'none';
	if($('monthId'))$('monthId').style.display = 'none';

	var data = 'act=config&subjectId='+subjectId+'&termId='+termId+'&yearId='+yearId+'&gradeId='+_gradeId+'&classId='+_classId;
	ajax({url:'service.php',method:'post',content:data,oncomplete:function(){
		try{ var json = eval(this.data); }catch(e){window.status = this.data;}
		if(json)
		{
			var scheduleType = json.scheduleType || 1;
			$('termId').setAttribute('alt',scheduleType);
			
			if(json.scheduleType==1)
			{
				cache_data.termId = json.data;
			}
			else if(json.scheduleType==2)
			{
				cache_data.monthId = json.data;
			}
			else if(json.scheduleType==3)
			{
				cache_data.weekId = json.data;
			}
			else if(json.scheduleType==4)
			{
				cache_data.monthId = json.data[0];
				cache_data.dayId = json.data[1];
			}

			getData($('termId'));
		}
	}});
}

function getResource()
{
	var subjectId = $('subjectId').value;
	var termId = $('termId').value;
	var monthId = $('monthId').value;
	var weekId = $('weekId').value;
	var dayId = $('dayId').value;
	var scheduleType = $('termId').getAttribute('alt');
	var gradeIdVal = $('gradeId').value;
	var tmpArr = gradeIdVal.split('-');
	var _gradeId = tmpArr[0];
	var _classId = tmpArr[1];
	var yearId = $('yearId').value;

	if(subjectId=='')return;

	var data = 'act=resource&subjectId='+subjectId+'&termId='+termId+'&monthId='+monthId+'&weekId='+weekId+'&dayId='+dayId+'&scheduleType='+scheduleType+'&classId='+_classId+'&gradeId='+_gradeId+'&yearId='+yearId;
	
	ajax({url:'service.php',method:'post',content:data,onstart:function(){
		$('content').innerHTML = '<div style="color:#FFFFFF;">Loading ...</div>';
	},oncomplete:function(){
		try{ var json = eval(this.data); }catch(e){window.status = this.data;}

		var content = $('content');
		content.innerHTML = '';
		if(json && json.status==1 && json.course)
		{
			var item = null;
			var str = '';
			for(var i=0;i<json.course.length;i++)
			{
				item = json.course[i];

				var icon = $('subjectId').options[$('subjectId').selectedIndex].getAttribute('alt');

				str = '<div class="citem">';
				str += '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
				str += '<tr><td class="icon">';
				str += '<a href="javascript:view('+item.Id+','+item.presourceId+');"><img src="'+item.icon+'" alt="'+item.resourceTitle+'" title="'+item.resourceTitle+'" class="png" style="width:166px;height:160px;" /></a>';
				str += '</td></tr><tr>';
				str += '<td class="text"><a href="javascript:view('+item.Id+','+item.presourceId+');">'+item.resourceTitle+'</a></td>';
				str += '</tr></table>';
				str += '<div style="margin-top:-186px;margin-left:10px;text-align:left;"><img src="./images/'+json.lang+'/chapter/chapter_'+(i+1)+'.png" class="png" style="width:85px;height:20px;" alt="'+item.resourceTitle+'" /></div>';
				str += '</div>';
				content.innerHTML += str;
			}

			checkImg();
		}
		else if(json && json.status==-1)
		{
			alert(activation_007);
			return;
		}

		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		if(typeof(pngHandler)!='undefined' && IE && version>=5.5 && version<7)pngHandler.init();
	}});
}

function getData(obj)
{
	var type = obj.getAttribute('alt');
	var termId = obj.value;
	
	if(type==1)
	{
		$('monthId').style.display = 'none';
		$('dayId').style.display = 'none';
		$('weekId').style.display = 'none';
		getResource();
	}
	else if(type==2)
	{
		buildTermMonth(termId);
		getResource();
	}
	else if(type==3)
	{
		buildTermWeek(termId);
		getResource();
	}
	else if(type==4)
	{
		buildTermDay(termId);
		getResource();
	}
}

function buildTermMonth(termId)
{
	var testDate1 = null;
	var testStr1 = null;

	var obj = $('monthId');
	obj.innerHTML = '';
	var item = null;

	for(var i=0;i<term_month[termId]['list'].length;i++)
	{
		item = term_month[termId]['list'][i];
		addItem(obj,item,item);
	}

	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value==cache_data.monthId)
		{
			obj.options[i].selected = 'selected';
			break;
		}
	}

	$('weekId').style.display = 'none';
	$('dayId').style.display = 'none';
	obj.style.display = '';
}

function buildTermWeek(termId)
{
	var testDate1 = testDate2 = null;
	var testStr1 = testStr2 = null;

	var obj = $('weekId');
	obj.innerHTML = '';
	var item = null;

	for(var i=0;i<term_week[termId].length;i++)
	{
		item = term_week[termId][i];
		testDate1 = new Date(item.weekStartDate.replace(/-/g,'/'));
		testDate2 = new Date(item.weekEndDate.replace(/-/g,'/'));
		testStr1 = testDate1.format(date_format_js);
		testStr2 = testDate2.format(date_format_js);

		addItem(obj,(item.weekNo<10?'0'+item.weekNo:item.weekNo) + ' ( ' + testStr1+' - '+testStr2+' )',item.weekId);
	}

	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value==cache_data.weekId)
		{
			obj.options[i].selected = 'selected';
			break;
		}
	}

	$('monthId').style.display = 'none';
	$('dayId').style.display = 'none';
	obj.style.display = '';
}

function buildTermDay(termId)
{
	var testDate1 = null;
	var testStr1 = null;

	var obj = $('monthId');
	obj.innerHTML = '';
	var item = null;

	for(var i=0;i<term_month[termId]['list'].length;i++)
	{
		item = term_month[termId]['list'][i];
		addItem(obj,item,item);
	}

	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value==cache_data.monthId)
		{
			obj.options[i].selected = 'selected';
			break;
		}
	}

	obj.style.display = '';

	obj = $('dayId');
	obj.innerHTML = '';
	var item = null;

	for(var i=1;i<=31;i++)
	{
		addItem(obj,(i<10?'0'+i:i),(i<10?'0'+i:i));
	}

	for(var i=0;i<obj.options.length;i++)
	{
		if(obj.options[i].value==cache_data.dayId)
		{
			obj.options[i].selected = 'selected';
			break;
		}
	}

	obj.style.display = '';
	$('dayId').style.display = '';
	$('weekId').style.display = 'none';
}

var is_init = true;
function getSelectOption(obj, targetId)
{
	var yearId = $('yearId').value;
	var termId = $('termId').value;
	var gradeIdVal = $('gradeId').value;
	var tmpArr = gradeIdVal.split('-');
	var _gradeId = tmpArr[0];
	var _classId = tmpArr[1];
	//var classId = $('classId').value;//
	var curValue = obj.id=='termId' ? $('yearId').value : obj.value;

	if(targetId=='subjectId' && !is_init)hideSchedultSelect();

	var data = 'act=getSelect&value='+curValue+'&stValue='+targetId+'&yearId='+yearId+'&gradeId='+_gradeId+'&classId='+_classId+'&termId='+termId+'&type='+obj.id;
	ajax({url:'service.php',method:'post',content:data,async:false,oncomplete:function(){
		try{ var json = eval(this.data); }catch(e){window.status = this.data;}
		
		var targetObj = $(targetId);
		
		for(var i=targetObj.options.length-1;i>0;i--)
		{
			targetObj.options.remove(i);
		}
			
		if(json)
		{
			var sidx = -1;
			for(var j=0; j<json.length; j++)
			{
				if(targetId=='subjectId' && json[j]['eid']==1)
				{
					sidx = j+1;
				}
				addItem(targetObj, json[j]['name'], json[j]['id']);
			}

			if(targetId=='subjectId' && is_init)
			{
				if(sidx>=0)
				{
					targetObj.options[sidx].setAttribute('selected','selected');
				}
				else
				{
					targetObj.options[1].setAttribute('selected','selected');
				}
				is_init = false;
			}
			else if(targetId=='subjectId' && !is_init)
			{
				if(sidx>=0)
				{
					targetObj.options[sidx].setAttribute('selected','selected');
				}
				else
				{
					targetObj.options[1].setAttribute('selected','selected');
				}
				getConfig();
			}
		}
		else if(is_init && targetId=='gradeId')
		{
			is_init=false;
		}

		if(targetId=='gradeId')
		{
			hideSchedultSelect();
			if(targetObj.options.length>1)
			{
				targetObj.options[0].setAttribute('selected','selected');
			}
			
			$('subjectId').style.display = 'none';
		}
		else if(targetId=='subjectId')
		{
			$('subjectId').style.display = '';
		}
	}});
}

function hideSchedultSelect()
{
	if($('dayId'))$('dayId').style.display = 'none';
	if($('weekId'))$('weekId').style.display = 'none';
	if($('monthId'))$('monthId').style.display = 'none';
}

function checkImg(type)
{
	var tid = type ? type : 1;
	var url = './images/';
	switch(parseInt(tid))
	{
		default:
		{
			url += 'nopic.gif';
			break;
		}
	}

	var imgs = document.images;
	for(var i = 0;i < imgs.length;i++){
		if(imgs[i].getAttribute('src')=='')
		{
			imgs[i].src = url;
		}
		imgs[i].onerror = function(){
			this.src = url;
		}
	}
}

function getBackgroud()
{
	var gradeIdVal = $('gradeId').value;
	var tmpArr = gradeIdVal.split('-');
	var gradeId = tmpArr[0];
	var yearId = $('yearId').value;
	var termId = $('termId').value;
	var data = 'act=getBackgroud&gradeId='+gradeId+'&yearId='+yearId+'&termId='+termId;

	if(gradeId=='')return;
	
	ajax({url:'service.php',method:'post',content:data,oncomplete:function(){									 
		try{ var json = eval(this.data); }catch(e){window.status = this.data;}
		var imgUrl = './images/'+json.lang+'/background/'+json.background+'.jpg';
		document.body.style.backgroundImage = 'url("'+imgUrl+'")';
	}});
}

function logout()
{
	ajax({url:'service.php',method:'post',content:'act=logout',oncomplete:function(){
		if(this.data>0)
		{
			document.location.href = document.location.href;
		}
	}});
}

function home()
{
	ajax({url:'service.php',method:'post',content:'act=index',oncomplete:function(){
		if(this.data>0)
		{
			document.location.href = document.location.href;
		}
	}});
}

function kinder()
{
	var scripts = document.getElementsByTagName('SCRIPT');
	for(var i=0;i<scripts.length;i++)
	{
		if(scripts[i].src.indexOf(e3)!=-1)
		{
			scripts[i].parentNode.removeChild(scripts[i]);
		}
	}

	ajax({url:'service.php',method:'post',content:'act=kinder',oncomplete:function(){
		var url = e3 + '/system/index.php/login/?a=chklogin&os=ebook&key=' + this.data;
		var script = document.createElement('SCRIPT');
		script.onload = script.onreadystatechange = function()
		{
			if(!this.readyState || this.readyState=='loaded' || this.readyState=='complete')
			{
				if(typeof(login_status) != 'undefined' && login_status==0)
				{
					openMaxWin(e3+'/system/');
				}
				else
				{
					alert(error_sso);
				}
			}
		}
		script.type = 'text/javascript';
		script.src = url;
		var head = document.getElementsByTagName('head')[0];
		head.appendChild(script);
	}});
}

function explain()
{
	ajax({url:'service.php',method:'post',content:'act=explain',oncomplete:function(){
		if(this.data>0)
		{
			document.location.href = document.location.href;
		}
	}});
}

function result()
{
	ajax({url:'service.php',method:'post',content:'act=result',oncomplete:function(){
		if(this.data>0)
		{
			document.location.href = document.location.href;
		}
	}});
}

function notice()
{
	ajax({url:'service.php',method:'post',content:'act=notice',oncomplete:function(){
		if(this.data>0)
		{
			document.location.href = document.location.href;
		}
	}});
}

function aboutUs()
{
	ajax({url:'service.php',method:'post',content:'act=about',oncomplete:function(){
		if(this.data>0)
		{
			document.location.href = document.location.href;
		}
	}});
}

function contactUs()
{
	Dialog.show('contact');
}

function setLang(lang)
{
	ajax({url:'service.php',method:'post',content:'act=lang&lang='+encodeURI(lang),oncomplete:function(){
		if(this.data>0)
		{
			document.location.href = document.location.href;
		}
	}});
}

function password()
{
	clear();
	Dialog.show('password');
}

function forget_password()
{
	Dialog.show('forget_password');
}

function activation(type)
{
	var activationCode = $('activationCode').value;

	if(type==0)
	{
		activationCode = '';
	}
	else if(type==1)
	{
		if(activationCode.length!=8)
		{
			alert(error_activation_code_length);
			$('activationCode').focus();
			return;
		}
	}

	var activation_select = false;
	var obj = $('yearId_activation');
	if($('activation_select').style.display=='')
	{
		var txt =obj.options[obj.selectedIndex].text;

		if(!confirm(activation_004+txt))
		{
			return;
		}
		activation_select = true;
	}

	if(activationCode.length==8 || activationCode.length==0)
	{
		var data = 'act=activation&code=' + encodeURI(activationCode) + (activation_select ? '&yearId=' + obj.value : '');
		ajax({url:'service.php',method:'post',content:data,oncomplete:function(){
			try{ var json = eval(this.data); }catch(e){window.status = this.data;}

			if(json.status==-2)
			{
				alert(error_activation_code_not_exist);
			}
			else if(json.status==-3)
			{
				alert(error_activation_code_fail);
			}
			else if(json.status==-4)
			{
				alert(error_activation_code_be_used);
			}
			else if(json.status==-5)
			{
				document.location.href = document.location.href;
			}
			else if(json.status==-1)
			{
				alert(error_activation_limit);
			}
			else if(json.status==1)
			{
				Dialog.hide();
				Dialog.show('activation_select');
			}
			else if(json.status==2)
			{
				Dialog.hide();
				alert(error_activation_code_success);
				logout();
				//document.location.href = document.location.href;
			}
			else
			{
				alert(error_activation_code_not);
				document.location.href = document.location.href;
			}
		}});
	}
	else if(activationCode.length>0)
	{
		alert(error_activation_code_length);
	}
}

function changePassword()
{
	var p1 = $('oldpassword').value;
	var p2 = $('newpassword1').value;
	var p3 = $('newpassword2').value;

	if(p1.length==0)
	{
		alert(error_password_01);
		$('oldpassword').focus();
		return;
	}
	else if(p1.length<4 || p1.length>16)
	{
		alert(error_password_02);
		$('oldpassword').focus();
		return;
	}
	else if(p2.length==0)
	{
		alert(error_password_03);
		$('newpassword1').focus();
		return;
	}
	else if(p2.length<4 || p2.length>16)
	{
		alert(error_password_02);
		$('newpassword1').focus();
		return;
	}
	else if(p3.length==0)
	{
		alert(error_password_04);
		$('newpassword2').focus();
		return;
	}
	else if(p3.length<4 || p3.length>16)
	{
		alert(error_password_02);
		$('newpassword2').focus();
		return;
	}
	else if(p2!=p3)
	{
		alert(error_password_05);
		$('newpassword1').value='';
		$('newpassword2').value='';
		$('newpassword1').focus();
		return;
	}

	var data = 'act=password&p1='+encodeURIComponent(p1)+'&p2='+encodeURIComponent(p2)+'&p3='+encodeURIComponent(p3);
	ajax({url:'service.php',method:'post',content:data,oncomplete:function(){
		if(this.data==-1)
		{
			alert(error_password_06);
		}
		else if(this.data==-2)
		{
			alert(error_password_05);
		}
		else if(this.data==1)
		{
			alert(error_password_07);
			clear();
			Dialog.hide();
		}
		else
		{
			alert(error_password_08);
			clear();
			Dialog.hide();
		}
	}});
}

function clear()
{
	$('oldpassword').value='';
	$('newpassword1').value='';
	$('newpassword2').value='';
}

Date.prototype.format = function(format)
{
	var o = {
		'y+' :  this.getFullYear(),  //year
		'M+' :  this.getMonth()+1,  //month
		'd+' :  this.getDate(),     //day
		'h+' :  this.getHours(),    //hour
		'm+' :  this.getMinutes(),  //minute
		's+' :  this.getSeconds(), //second
		'q+' :  Math.floor((this.getMonth()+3)/3),  //quarter
		'S'  :  this.getMilliseconds() //millisecond
	}

	if(/(y+)/.test(format))
	{
		format = format.replace(RegExp.$1, (this.getFullYear()+'').substr(4 - RegExp.$1.length));
	}

	for(var k in o)
	{
		if(new RegExp("("+ k +")").test(format))
		{
			format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ('00'+ o[k]).substr((''+ o[k]).length));
		}
	}
	return format;
}

/*---------------------------------------- */
