var ttd = null;
var tsel = null;
var ttype = "";
var BID = "";
var SID = "";
var titem = null;
var ttitem = null;
var pageSize = "20";

function IValue(objID,objValue)
{
	CValue();SetValue(objID,objValue);
}
function CValue()
{
	$("#CourseName").val("");
	$("#InfoSType1").val("");
	$("#InfoBType1").val("");
	$("#keywords").val("");
}
function SetValue(objID,objValue)
{
	$("#"+objID).val(objValue);
}
function SCSS(objCSS,objID)
{
	$("."+objCSS).removeClass("bb");
	$("#"+objID).addClass("bb");
}
		
function getStatus(bStatus){
	if(bStatus=="3"){
		$("#divck1").get(0).style.display="";
		$("#divck2").get(0).style.display="";
		$("#divck3").get(0).style.display="";
		$("#divck4").get(0).style.display="";
		$("#divck5").get(0).style.display="";
		$("#divck0").get(0).style.display="none";
	}
	else
	{
		$("#divck1").get(0).style.display="none";
		$("#divck2").get(0).style.display="none";
		$("#divck3").get(0).style.display="none";
		$("#divck4").get(0).style.display="none";
		$("#divck5").get(0).style.display="none";
		$("#divck0").get(0).style.display="";
	}
}
function getInfo(){
	$("#InfoList").html("<center><br><b>正在获取数据...</b><br><img src='images/loading.gif' border=0></center>");
	if(ttype=="3"){
		BID = $("#InfoBType1").val();
		SID = $("#InfoSType1").val();
	}
	else{
		BID = getDDL("InfoBType");
		SID = getDDL("InfoSType");
	}
	goPage("1")
}
function goPage(page){
	if(BID=="0" || BID=="null")BID="";
	if(SID=="0" || SID=="null")SID="";
	var BType = BID;
	var SType = SID;
	var key = $("#keywords").val();
	var City = "";
	if(ttype=="3"){
		var tCourseName = $("#CourseName").val();
		var tSchoolName = $("#SchoolName").val();
		var tsite = $("#district").val();
		var tClassType = $("#ClassType").val();
		var tlimit = $("#limit").val();
		var tSchoolTime = $("#SchoolTime").val();
		var tPriceTo = $("#PriceFrom").val();
		var tPriceFrom = $("#PriceTo").val();
		var pars = "oper=gEnroll&A="+ City +"&B="+ BType +"&C="+ SType +"&D="+ escape(key) + 
				"&E=&F="+ escape(tSchoolName) + 
				"&G="+ escape(tsite) + "&H="+ tClassType +"&I="+ tlimit + 
				"&J="+ escape(tSchoolTime) + "&K="+ tPriceFrom +"&L="+ tPriceTo + 
				"&M="+ pageSize +"&N="+ page + "&timeStamp=" + new Date()
	}
	else{
		var pars = "oper=gInfo&A="+ City +"&B="+ ttype +"&C="+ BType +"&D="+ SType + 
				"&E="+ escape(key) +"&F="+ pageSize +"&G="+ page
				
	}

	 $.ajax({
		url: xmlUrl,
		data: pars,
		cache: false,
		success: function(html){
			if(html!=null && html!=""){
			$("#InfoList").html(html);getPageStatus(ttitem);
			}
			else
				$("#InfoList").html("<center><b class='STxt'>对不起，系统没有找到您要查询的信息！</b></center>");
		}
	});
}

function insChar(obj)
{
	getListSatus($("#"+obj));
	getStatus(ttype);
}

function chgPageList(pNum,obj)
{
	if(ttitem!=obj){
		pageSize = pNum;
		ttitem = obj;
		goPage(1);
	}		
}
function getPageStatus(tobj){
	if(tobj==null)
		tobj = "pNum1";
	$("#"+tobj).removeClass("PageList");
	$("#"+tobj+"1").removeClass("PageList");
	$("#"+tobj).addClass("PageListClick");
	$("#"+tobj+"1").addClass("PageListClick");
	if(titem!=null && titem!=tobj){
		$("#"+titem).removeClass("PageListClick");
		$("#"+titem+"1").removeClass("PageListClick");
		$("#"+titem).addClass("PageList");
		$("#"+titem+"1").addClass("PageList");
	}
	titem = tobj;
}

function setDDL(objddl,objtxt){
	/*$("#"+objddl).val(objtxt);*/
	var t = $("#"+objddl).get(0);
	var k = t.options.length;
	t.selectedIndex = -1;
	for (var i = 0; i < k; i++) {
		if (t.options[i].value==objtxt) {
			t.selectedIndex = i;
			break;
		}
	}
}

function getQuery(){
	$("#InfoList").html("<center><br><b>正在获取数据...</b><br><img src='images/loading.gif' border=0></center>");
	var flag = false;
	ttype = getParameter("SType");
	if(ttype==null || ttype=="")
		ttype = getParameter("Stype");
	if(ttype==null || ttype=="")
		ttype = "1";
	getListSatus($("#smenu"+ttype));
	getStatus(ttype);
	flag=true;

	var city = getParameter("c");
	if(city!=null && city!="")
		$("#City").val(city);

	var tCourseName = getParameter("k");
	if(tCourseName!=null && tCourseName!=""){
		$("#CourseName").val(tCourseName);
		$("#keywords").val(tCourseName);
	}

	var tSchoolTime = getParameter("t");
	if(tSchoolTime!=null && tSchoolTime!="")
		$("#SchoolTime").val(tSchoolTime);

	var tSchoolName = getParameter("s");
	if(tSchoolName!=null && tSchoolName!="")
		$("#SchoolName").val(tSchoolName);

	var PriceTo = getParameter("to");
	if(PriceTo!=null && PriceTo!="")
		$("#PriceTo").val(PriceTo);

	var PriceFrom = getParameter("from");
	if(PriceFrom!=null && PriceFrom!="")
		$("#PriceFrom").val(PriceFrom);

	var keytmp = getParameter("keywords");
	if(keytmp!=null && keytmp!="")
		$("#keywords").val(keytmp);

	var tSite = getParameter("tSite");
	if(tSite!=null && tSite!="")
		$("#district").val(tSite);

	var tType = getParameter("tType");
	if(tType!=null && tType!="")
		$("#ClassType").val(tType);

	var tLimit = getParameter("tLimit");
	if(tLimit!=null && tLimit!="")
		$("#limit").val(tLimit);

	BID = getParameter("BID");
	SID = getParameter("SID");
	$("#InfoBType1").val(BID);
	$("#InfoSType1").val(SID);
	initTypeList();
}

function initTypeList()
{
    var pars = 'oper=gType&type='+ ttype +'&A=';
    $.ajax({
		url: xmlUrl,
		data: pars,
		cache: false,
		success: function(html){
			if(html!=null && html!=""){
				$("#InfoBType").html(html);getBType_callback();
			}
			else
				$("#InfoBType").html("error");
		}
	});
}

function getTypeBySID()
{
	var pars = 'oper=gBType&type='+ ttype +'&B=' + SID;
	$.ajax({
		url: xmlUrl,
		data: pars,
		cache: false,
		success: function(html){
			gTypeBySID(html);
		}
	});
}

function gTypeBySID(tID)
{
	BID = tID;
	getBType_callback();
} 

function getBType_callback()
{
	if(BID!=null && BID!=""){
		setDDL("InfoBType",BID);$("#InfoBType1").val(BID);
		var pars = 'oper=gType&type='+ ttype +'&A=' + BID;
		$.ajax({
				url: xmlUrl,
				data: pars,
				cache: false,
				success: function(html){
					if(html!=null && html!=""){
						$("#InfoSType").html(html);
						getSType_callback();
					}
				}
		});
	}
	else {
		if(SID!=null && SID!="")
			getTypeBySID();
		else{
			BID = "";
			SID = "";
			goPage("1");
		}
	}
}

function getSType_callback()
{
	if(SID!=null && SID!="")
		setDDL("InfoSType",SID);
	else
		SID = "";
	$("#InfoSType1").val(SID);
	goPage("1");
}

function SelItem(obj)
{
	obj.removeClass("Menu");
	obj.addClass("MenuSel");
	if(tsel!=null && tsel!=obj){
		obj.removeClass("MenuSel");
		obj.addClass("Menu");
	}
	tsel = obj;
	ttype = obj.get(0).infotype;
}
function getListSatus(obj){
	if(obj==null)return;
	obj.removeClass("MenuItem_inact");
	obj.addClass("MenuItem_active");
	if(ttd!=null && ttd!=obj){
		ttd.removeClass("MenuItem_active");
		ttd.addClass("MenuItem_inact");
	}
	ttd = obj;
	ttype = obj.get(0).infotype;
	$("#lblbtype").html(obj.html()+"大类：");
	$("#lblstype").html(obj.html()+"小类：");
}

function Search(){
	$("#lblbtype").html(tsel.get(0).infotxt+"大类：");
	$("#lblstype").html(tsel.get(0).infotxt+"小类：");
	getStatus(ttype);
	goPage("1");
}

var k=0;
function selClass(obj){
	if(obj.checked){
		getClass();
		if(k==4){alert("班级比较最多只能选择4个！");obj.checked=false;return;}
		var url=readCookie("CmpClass");
		var compareList = document.all["cmpClass"];	
		for (var i = 0,c = compareList.length; i < c; ++i) {
			if (compareList[i].checked) {
				url+="&id="+compareList[i].value;
				k++;
				if (k>4) break;
			}
		}
		writeCookie("CmpClass", url, 24)
	}
	if(obj.checked==false)
	{
		var tmpClass = readCookie("CmpClass");
		tmpClass = tmpClass.replace("&id="+obj.value, "");
		writeCookie("CmpClass", tmpClass, 24)
	}
}
function getClass()
{
	var ClassList = readCookie("CmpClass");
	k = 0;
	if(ClassList!=""){
		ArrClass = ClassList.split("&id=");
		for(var i=0;i<ArrClass.length;i++)
		{
			if(ArrClass[i]!=""){k++;}
		}
	}
}
function doCompare()
{
	getClass();
	if (k<2) {
		alert("请选择两个以上的班级进行比较！");
		return ;
	}
	var AdvanceSearch = 0
	window.open("CompareClass.asp?op=cmp&bFlag="+AdvanceSearch);
}
