var xkb = {};
/* ajax得到数据 */
xkb.in_ajax = false;
xkb.bodyTop = function() {
	var bodyTop = 0;
	if (typeof window.pageYOffset != 'undefined') {
		bodyTop = window.pageYOffset;
	} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
		bodyTop = document.documentElement.scrollTop;
	} else if (typeof document.body != 'undefined') {
		bodyTop = document.body.scrollTop;
	}
	return bodyTop;
}
xkb.onajax = function() {
	xkb.in_ajax = true;
	var bodyTop = xkb.bodyTop();
	if(typeof $("#xkbLoading").attr("id") == 'undefined') {
		$("body").append('<div id="xkbLoading" style="position: absolute; display:none;"><img src="/main/Public/shgao/images/loading.gif" alt="处理中……" /></div>');
	}
	$("#xkbLoading").css("display", "block");
	$("#xkbLoading").css("left", (document.body.clientWidth - 140)+'px');
	$("#xkbLoading").css("top", bodyTop);
}
xkb.delajax = function() {
	xkb.in_ajax = false;
	$("#xkbLoading").css("display", "none");
}
xkb.ajax = function(obj) {
	if(xkb.in_ajax) {
		alert("数据处理中..请稍等...") ;
		return false;
	}
	if(typeof obj != "object") return false;
	xkb.onajax();
	$.ajax({
		type: typeof obj.type != 'undefined' ? obj.type : "POST",
		dataType: typeof obj.dataType != 'undefined' ? obj.dataType : "json",
		url: obj.url,
		data: obj.data,
		success: function(s) {
			xkb.delajax();
			obj.success(s);
		},
		error: function(s) {
			alert("通信错误..请刷新页面尝试!");
			xkb.delajax();
		}
	});
}

/* 显示登录框 */
xkb.showlogin = function(info, callback) {
	var bodyTop = 0;
	if (typeof window.pageYOffset != 'undefined') {
		bodyTop = window.pageYOffset;} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
		bodyTop = document.documentElement.scrollTop;
	}
	else if (typeof document.body != 'undefined') {
		bodyTop = document.body.scrollTop;
	}

    xkb.bgShow();
	$("#tcdiv_login").css("top", bodyTop+100).css("left", (window.screen.availWidth/2 - 180) +"px").fadeIn();
	
	$("#topUserLogin").unbind("click");
	$("#topUserLogin").click(function() {
		/* 顶部用户登录 */
		var top_username = $.trim($("#top_username", "#tcdiv_login").val());
		var top_password = $.trim($("#top_password", "#tcdiv_login").val());
		if(top_username == '') {
			alert("请填写用户名!");
			$("#top_username", "#tcdiv_login").focus();
			return false;
		}
		if(top_password == '') {
			alert("请填写密码!");
			$("#top_password", "#tcdiv_login").focus();
			return false;
		}
		xkb.ajax({
			url: "user,dologin.html",
			data: "action=ajax&username="+top_username+"&passwd="+top_password,
			success: function(s) {
				if(!s.info.success) {
					alert(s.info.msg);
					return false;
				}
				//VIP2010
				if(s.info.user.VIP2010) {
					xkb.hidelogin();
					xkb.vip2010Show();
					return false;
				}
				if(callback && (typeof callback == 'object' || typeof callback == 'function')){
					xkb.hidelogin();
					callback();
					return true;
				}else {
					window.location.reload();
				}
			}
		});
	});
}
/* 登录 */
xkb.topgologin = function(info, maintype) {

}
/* 隐藏登录框 */
xkb.hidelogin = function() {
	xkb.bgHide();
	$('#tcdiv_login').fadeOut();
}

/* xkb.ajaxlogin */
xkb.ajaxlogin = function(callback) {
	xkb.ajax({
		url: "user,showlogin.html",
		success: function(s) {
			if(s.status == 0) {
				window.location.reload();
			} else {
				if( typeof $("#tcdiv_login").attr("id") == 'undefined') $("body").append(s.info);
				xkb.showlogin(s.info,callback);
			}
		}
	});
}
/* xkb.fogetpasswd */
xkb.ajaxfogetpasswd = function() {
	xkb.ajax({
		url: "user,fogetpasswd.html",
		success: function(s) {
			if(s.status == 0) {
				window.location.reload();
			} else {
				if( typeof $("#tcdiv_fogetpasswd").attr("id") == 'undefined') $("body").append(s.info);
				xkb.showfogetpasswd(s.info);
			}
		}
	});
};

/* 顶部忘记密码 */
xkb.majaxfogetpasswd = function() {
	xkb.hidelogin();
	xkb.ajaxfogetpasswd();
};

//初始化诊断预约
xkb.mfty=function(){};
//显示
xkb.mfty.show=function(e){
	xkb.bgShow();
	$("#mfty").css("width", 0).css("left", $(this).offset().left+$(this).attr("width")).css("top", $(this).offset().top-157).show(200).animate({width: 530},500);
}
//关闭
xkb.mfty.close=function(){
	$("#mfty").animate({width: 0},500);
	$("#mfty").hide(200);
	xkb.bgHide();
}
//数据验证
xkb.mfty.check=function(e) {
var phoneReg=/^\d{3,4}-\d{7,8}(-\d{3,4})?$/;
   if($("#name").val()==""){
	 showNoAuth("请填写您的真实姓名！",$("#mfty_sub").offset().left-39,$("#mfty_sub").offset().top-167,5000);
	 return false; 
   }else if($("#phone").val()==""){
	 showNoAuth("请填写您的联系电话！",$("#mfty_sub").offset().left-39,$("#mfty_sub").offset().top-167,5000);
	 return false; 
   }else if($("#grade").val()==""){
	 showNoAuth("请选择您现在的年级！",$("#mfty_sub").offset().left-39,$("#mfty_sub").offset().top-167,5000);
	 return false; 
   }else if($("#description").val().indexOf('在这里写下您的具体需求')!=-1){
	 $("#description").val("");
   }else{
	 return true;
   }
}
//提交数据
xkb.mfty.submit=function(){
   if(this.check()){
	   xkb.ajax({
			url: 'index,reserve.html',
			data: $("#mfty_form").serialize()+"&type=1",
			type: 'post',
			cache: false,
			dataType: 'json',
			success: function(xhr){
				$('#mfty_img').click();
				showNoAuth(xhr.data,384,$("#mfty_img").offset().top+5);
				
			},
			error: function(xhr){
			   showNoAuth(xhr.statusText,384,$("#mfty_img").offset().top);
		   }
		   });
   }
}
//提交数据
xkb.mfty.reset=function(){
  $("#name","#mfty_form").val("");
  $("#phone","#mfty_form").val("");
  $("#grade","#mfty_form").val("");
  $("#subject","#mfty_form").attr("checked",false);
  $("#description","#mfty_form").val("在这里写下您的具体需求。如：我想提高英语语法or我数学函数搞不懂……");
}

//VIP初始化诊断预约
xkb.mfty4=function(){};
//显示
xkb.mfty4.show=function(e){
	xkb.bgShow();
	$("#mfty4").css("width", 0).css("left", $(this).offset().left+$(this).attr("width")).css("top", $(this).offset().top-157).show(200).animate({width: 530},500);
}
//关闭
xkb.mfty4.close=function(){
	$("#mfty4").animate({width: 0},500);
	$("#mfty4").hide(200);
	xkb.bgHide();
}
//初始化网上报名
var	mfty5=function(){};
	//显示
	mfty5.show=function(obj){

	    xkb.bgShow();
	    $("#mfty5").css("width", 0).css("left", $(obj).offset().left+$(obj).width()).css("top", $(obj).offset().top-157).show(300).animate({width: 530},500);
	}
	//关闭
	mfty5.close=function(){
	    xkb.bgHide();
	    $("#mfty5").animate({width: 0},500).hide(200);
	}
	//数据验证
	mfty5.check=function(e){
	var phoneReg=/^\d{3,4}-\d{7,8}(-\d{3,4})?$/;
	   if($("#mfty5_name").val()==""){
	     showNoAuth("请填写您的真实姓名！",$("#mfty5_sub").offset().left-39,$("#mfty5_sub").offset().top-26,5000);
		 return false; 
	   }else if($("#mfty5_phone").val()==""){
	     showNoAuth("请填写您的联系电话！",$("#mfty5_sub").offset().left-39,$("#mfty5_sub").offset().top-26,5000);
		 return false; 
	   }else if($("#mfty5_grade").val()==""){
	     showNoAuth("请填写您的年级！",$("#mfty5_sub").offset().left-39,$("#mfty5_sub").offset().top-26,5000);
		 return false; 
	   }else{
	     return true;
	   }
	}
	//提交数据
	mfty5.submit=function(){
	   if(this.check()){
		   $.ajax({
				url: 'index,reserve.html',
				data: $("#mfty5_form").serialize()+"&type=3",
				type: 'post',
				cache: false,
				dataType: 'json',
				success: function(xhr){
					showNoAuth(xhr.data,$('#mfty_img').offset().left+$('#mfty_img').width(),$('#mfty_img').offset().top,5000);
					mfty5.close();
					xkb.bgShow();
				},
				error: function(xhr){
				   showNoAuth(xhr.statusText,$('#mfty_img').offset().left+$('#mfty_img').width(),$('#mfty_img').offset().top,5000);
			   }
			   });
	   }
	}
	mfty5.reset=function(){
	  $("#mfty5_name","#mfty5_form").val("{$userInfo.name}");
	  $("#mfty5_phone","#mfty5_form").val("{$userInfo.tel}");
	  $("#mfty5_grade","#mfty5_form").val("");
	  $("#mfty5_subject","#mfty5_form").attr("checked",false);
      $("#mfty5_description","#mfty5_form").val("在这里写下您的需求和建议。如：我想提高英语语法or我数学函数搞不懂……");
	}
//显示提示框
function showNoAuth(_str,_left,_top,_time){
	xkb.bgShow();
	if($("#noauth").css("display")=="block"){
		hideNoAuth();
		return;
	}
	if(!_left){
	   _left="";
	}
	if(!_top){
	   _top="";
	}
	if(_str){
		$("#noauth_str").html(_str);
	}
	var height=$("#noauth").height();
	if($.browser.msie && $.browser.version=="6.0"){
		var _obj={height: height,top:_top};
	}else{
		var _obj={height: height,opacity:"show",top:_top};
	}
	$("#noauth").height(0).css("left",_left).css("top",_top+height).show().animate(_obj,500,'',function(){if(_time)setTimeout(function(){hideNoAuth()},parseInt(_time));});
}
//隐藏提示框
function hideNoAuth(){
    if($("#noauth").css("display")=="none"){
		return;
	}
	var height=$("#noauth").height();
	if($.browser.msie && $.browser.version=="6.0"){
		var _obj={height: 0,top:$("#noauth").offset().top+height};
	}else{
		var _obj={height: 0,opacity:"hide",top:$("#noauth").offset().top+height};
	}
	$("#noauth").animate(_obj,500,"",function(){ $("#noauth").hide().css("height",height);});
	xkb.bgHide();
}
//隐藏callBack

//显示背景
xkb.bgShow=function(){
	if(typeof $("#bodybg").attr("id") == 'undefined') {
			$("body").append('<div id="bodybg" style="z-index:3;display:none; position:absolute; background:#000000;"></div>');
	}
		$("#bodybg").css("top", 0).css("left", 0).css("width", document.body.scrollWidth ).css("height", document.body.scrollHeight ).css("opacity", 0.5).fadeIn();
	if($.browser.msie && $.browser.version=="6.0"){
		if(typeof $("#bodybg_iframe").attr("id") == 'undefined') {
				$("body").append('<iframe id="bodybg_iframe" src="javascript:false;" style="opacity:0.1;display:none; position:absolute; background:#000000; z-index:2;"></iframe>');
		}
		$("#bodybg_iframe").css("top", 0).css("left", 0).css("width", document.body.scrollWidth ).css("height", document.body.scrollHeight ).css("opacity", 0).fadeIn();
	}
}
//隐藏背景
xkb.bgHide=function(){
    $("#bodybg").fadeOut();
	if($("#bodybg_iframe")){
		$("#bodybg_iframe").fadeOut();
	}
}

/*online chart*/
xkb.onlineChart = function() {
	var bodyTop = xkb.bodyTop();
	if(typeof $("#chatonlinep").attr("id") == 'undefined') {
		$("body").append('<div class="chatonlinep" id="chatonlinep"><a href="javascript:xkb.closeonlineChart();" class="clcolose"></a><a href="javascript:openZoosUrl(\'chatwin\');" class="onclicktochat"></a></div>');
	}
	$("#chatonlinep").css("left", '0px').css("top", bodyTop + document.documentElement.clientHeight - 76 + "px");
	setTimeout("xkb.onlineChart();", 300);
};
/* close Online Chart*/
xkb.closeonlineChart = function() {
	$("#chatonlinep").fadeOut();
};
$(document).ready(function() {
	xkb.onlineChart();
});

//首页头图切换板块 select插件
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
function _$s(id) {
    return document.getElementById(id);
}

function stopBubbling (ev) {
    ev.stopPropagation();
}

function rSelects() {
	$("#ubox").hide();
	select_tag = document.createElement('div');
	select_tag.id = 'select_' + $("#ubox").attr("name");
	select_tag.className = 'select_box';
	$("#ubox")[0].parentNode.insertBefore(select_tag,$("#ubox")[0]);
	
	select_info = document.createElement('div');
	select_info.id = 'select_info_' + $("#ubox").attr("name");
	select_info.className='tag_select';
	select_info.style.cursor='pointer';
	select_tag.appendChild(select_info);
	
	select_ul = document.createElement('ul');
	select_ul.id = 'options_' + $("#ubox").attr("name");
	select_ul.className = 'tag_options';
	select_ul.style.position='absolute';
	select_ul.style.display='none';
	select_ul.style.zIndex='999';
	select_tag.appendChild(select_ul);
	
	rOptions($("#ubox").attr("name"));
	mouseSelects($("#ubox").attr("name"));
	
	if (isIE){
		$("#ubox")[0].onclick = new Function("clickLabels3('"+$("#ubox").attr("name")+"');window.event.cancelBubble = true;");
	}
	else if(!isIE){
		$("#ubox")[0].onclick = new Function("clickLabels3('"+$("#ubox").attr("name")+"')");
		$("#ubox")[0].addEventListener("click", stopBubbling, false);
	}
	$("#uboxstyle").show();
}


function rOptions( name) {
	var options = $("#ubox")[0].getElementsByTagName('option');
	var options_ul = 'options_' + name;
		for (n=0;n<$("#ubox")[0].options.length;n++){
			option_li = document.createElement('li');
			option_li.style.cursor='pointer';
			option_li.className='open';
			_$s(options_ul).appendChild(option_li);
			
			option_text = document.createTextNode($("#ubox")[0].options[n].text);
			option_li.appendChild(option_text);
			
			option_selected = $("#ubox")[0].options[n].selected;
			
			if(option_selected){
				option_li.className='open_selected';
				option_li.id='selected_' + name;
				_$s('select_info_' + name).appendChild(document.createTextNode(option_li.innerHTML));
			}
			
			option_li.onmouseover = function(){ this.className='open_hover';}
			option_li.onmouseout = function(){
				if(this.id=='selected_' + name){
					this.className='open_selected';
				}
				else {
					this.className='open';
				}
		   }
		   option_li.onclick = new Function("clickOptions("+n+",'"+$("#ubox").attr("name")+"')");
		}
}

function mouseSelects(name){
	var sincn = 'select_info_' + name;
	_$s(sincn).onmouseover = function(){ if(this.className=='tag_select') this.className='tag_select_hover'; }
	_$s(sincn).onmouseout = function(){ if(this.className=='tag_select_hover') this.className='tag_select'; }
	if (isIE){
	   _$s(sincn).onclick = new Function("clickSelects('"+name+"');window.event.cancelBubble = true;");
	}
	else if(!isIE){
	   _$s(sincn).onclick = new Function("clickSelects('"+name+"');");
	   _$s('select_info_' +name).addEventListener("click", stopBubbling, false);
	}
}

function clickSelects(name){
	var sincn = 'select_info_' + name;
	var sinul = 'options_' + name;
	if($("#ubox").attr("name") == name){    
		if( _$s(sincn).className =='tag_select_hover'){
			 _$s(sincn).className ='tag_select_open';
			 _$s(sinul).style.display = '';
		}
		else if( _$s(sincn).className =='tag_select_open'){
			 _$s(sincn).className = 'tag_select_hover';
			 _$s(sinul).style.display = 'none';
		}
	}
	else{
		_$s('select_info_' + $("#ubox").attr("name")).className = 'tag_select';
		_$s('options_' + $("#ubox").attr("name")).style.display = 'none';
	}
}

function clickOptions(n, name){  
	var li = _$s('options_' + name).getElementsByTagName('li');
	
	_$s('selected_' + name).className='open';
	_$s('selected_' + name).id='';
	li[n].id='selected_' + name;
	li[n].className='open_hover';
	_$s('select_' + name).removeChild(_$s('select_info_' + name));
	select_info = document.createElement('div');
    select_info.id = 'select_info_' + name;
    select_info.className='tag_select';
    select_info.style.cursor='pointer';
	_$s('options_' + name).parentNode.insertBefore(select_info,_$s('options_' + name));
	
	mouseSelects(name);
	
	_$s('select_info_' + name).appendChild(document.createTextNode(li[n].innerHTML));
	_$s( 'options_' + name ).style.display = 'none' ;
	_$s( 'select_info_' + name ).className = 'tag_select';
	$("#ubox")[0].options[n].selected = 'selected';
	xkb.Sitechange($("#ubox")[0],{left:$("#select_ubox").offset().left-445,top:$("#select_ubox").offset().top+25});
}