var SchoolSelector={inited:false,type:"university",bind:"",id:"",loadFaculty:false,init:function(id,bind){if(SchoolSelector.inited==true){}
SchoolSelector.bind=bind;SchoolSelector.loadProvince();SchoolSelector.id=id;SchoolSelector.show();SchoolSelector.adjustPosition();SchoolSelector.inited=true;$j("#main").css('overflow',"visible");$j(window).resize($j.proxy(SchoolSelector.adjustPosition,SchoolSelector));},clearEvents:function(){var school=$j('#'+SchoolSelector.id);school.unbind("schoolselector:changetype").unbind("schoolselector:selectschool").unbind("schoolselector:department");},adjustPosition:function(){var el=$j.type(SchoolSelector.bind)=='string'?$j('#'+SchoolSelector.bind):$j(SchoolSelector.bind);var offset=$j(el).offset();var left=offset.left-10;var top=offset.top+20;$j('#'+SchoolSelector.id).css({top:top+"px",left:left+"px"});},reset:function(){h("location_county_box");h("location_city_box");h("location_school_box");},onlyEnableTypes:function(types){for(var i=0;i<4;i++){if(types.indexOf(i)==-1){var li=$j("#"+SchoolSelector.id+" .cs_nav li").eq(i);li.html(li.find('a:first').html()).css({color:"#ccc",cursor:"default"});}}},getTypeStr:function(intType)
{var maps=["university","highschool","vocationalschool","juniorschool","elementary"];return maps[intType];},getTypeVal:function(type)
{var maps={"university":0,"highschool":1,"vocationalschool":2,"juniorschool":3,"elementary":4};return maps[type];},buildTypes:function(){var html="";var klass="cs_off";var type="university";var typename="大学";if(type==SchoolSelector.type)
{klass="cs_on";}
html+='<li class="'+klass+'"><a onclick="javascript:SchoolSelector.changeType('+"'"+type+"'"+', this);" class="s12">'+typename+'</a></li>';var type="highschool";var typename="高中";var klass="cs_off";if(type==SchoolSelector.type)
{klass="cs_on";}
html+='<li class="'+klass+'"><a onclick="javascript:SchoolSelector.changeType('+"'"+type+"'"+', this);" class="s12">'+typename+'</a></li>';var type="vocationalschool";var typename="技校";var klass="cs_off";if(type==SchoolSelector.type)
{klass="cs_on";}
html+='<li class="'+klass+'"><a onclick="javascript:SchoolSelector.changeType('+"'"+type+"'"+', this);" class="s12">'+typename+'</a></li>';var type="juniorschool";var typename="初中";var klass="cs_off";if(type==SchoolSelector.type)
{klass="cs_on";}
html+='<li class="'+klass+'"><a onclick="javascript:SchoolSelector.changeType('+"'"+type+"'"+', this);" class="s12">'+typename+'</a></li>';$j("#cs_nav").html(html);},changeType:function(type,obj){var el=$j(obj),school=$j('#'+SchoolSelector.id);if(el.parent().is(".cs_on")){return;}
SchoolSelector.type=type;school.find(".cs_on").attr('class','cs_off');el.parent().attr('class',"cs_on");SchoolSelector.clearData();SchoolSelector.loadProvince();if(typeof(SchoolTypeChange)=="function"){SchoolTypeChange(type);}
school.trigger("schoolselector:changetype",[type]);},clearData:function(){$j("#location_city_box").html("").hide();$j("#location_county_box").html("").hide();$j("#location_school_box").html("").hide();},show:function()
{SchoolSelector.reset();SchoolSelector.buildTypes();targetSchool=$j('#'+SchoolSelector.id);targetSchool[0].style.display="block";targetSchool.trigger("schoolselector:changetype",[SchoolSelector.type]);},hide:function()
{if(SchoolSelector.id)
{$j('#'+SchoolSelector.id).hide();}},loadProvince:function()
{SchoolSelector.showLoading("location_province_box");$j.get("/interface/suggestlocation.php?type=0",SchoolSelector.showProvince);},showLoading:function(id){$j('#'+id).show().html('<div class="tac p20"><img src="http://img1.kaixin001.com.cn/i2/diary/loading.gif"/></div>');},showProvince:function(trans){var data=$j.parseJSON(trans);var html="";for(var i=0;i<data.length;i++)
{if(SchoolSelector.type=="university"){if(data[i].name=="海外"){continue;}}
else{if(data[i].name=="海外"||data[i].name=="香港"||data[i].name=="澳门"){continue;}}
html+='<span><a class="sl2" onclick="SchoolSelector.selectProvince('+data[i].id+','+data[i].type+",'"+data[i].name+"'"+', this);">'+data[i].name+'</a></span>';}
$j("#location_province_box").html(html);},selectProvince:function(id,type,name,obj){SchoolSelector.clearData();if(SchoolSelector.type=="university"){SchoolSelector.loadUniversity(id);}
else{if(type==-1){SchoolSelector.loadCounty(0,id);}
else{SchoolSelector.loadCity(id);}}
var nodes=$j('#'+SchoolSelector.id).find(".curr");nodes.each(function(){var el=$j(this);if(el.parent().attr('id')=="location_province_box"){el.attr('class','');}});$j(obj).parent().attr('class',"curr");},loadCity:function(pid){SchoolSelector.showLoading("location_city_box");$j.get("/interface/suggestlocation.php?type=1&id="+pid,SchoolSelector.showCity);},showCity:function(trans){var data=eval('('+trans+')');var html="";for(var i=0;i<data.length;i++){html+='<span><a class="sl2" onclick="SchoolSelector.selectCity('+data[i].id+','+data[i].type+",'"+data[i].name+"'"+', this);">'+data[i].name+'</a></span>';}
$j("#location_city_box").html(html);},selectCity:function(id,type,name,obj){$j("#location_county_box").html("").hide();$j("#location_school_box").html("").hide();SchoolSelector.loadCounty(id,0);var nodes=$j('#'+SchoolSelector.id).find(".curr");nodes.each(function(){var el=$j(this);if(el.parent().attr('id')=="location_city_box"){el.attr('class',"");}});$j(obj).parent().attr('class',"curr");},loadUniversity:function(pid){SchoolSelector.showLoading("location_school_box");$j.get("/interface/suggestlocation.php?type=4&id="+pid,SchoolSelector.showUniversity);},showUniversity:function(trans){var data=eval('('+trans+')');var html="";for(var i=0;i<data.length;i++)
{html+='<p><a class="sl" onclick="SchoolSelector.selectSchool('+data[i].id+",'"+data[i].name+"'"+');">'+data[i].name+'</a></p>';}
html+='<div class="c"></div>';html+='<div class="c6" style="padding:5px 0 5px 10px;">其他：';html+='<input type="text" style="width:160px; height:12px;"/>';html+='<input type="button" value="" class="com_but" onclick="javascript:SchoolSelector.selectSchool(0, this.previousSibling.value);" />';html+='</div>';$j("#location_school_box").html(html);},loadCounty:function(pid,ppid){var type=2;var id=pid;if(pid==0){type=3;id=ppid;}
SchoolSelector.showLoading("location_county_box");$j.get("/interface/suggestlocation.php?type="+type+"&id="+id,SchoolSelector.showCounty);},showCounty:function(trans){var data=eval('('+trans+')');var html="";for(var i=0;i<data.length;i++){html+='<span><a class="sl2" onclick="SchoolSelector.selectCounty('+data[i].id+",'"+data[i].name+"'"+', this);">'+data[i].name+'</a></span>';}
if(data.length==0){html="";html+='<div class="c"></div>';html+='<div class="c6" style="padding:5px 0 5px 10px;">其他：';html+='<input type="text" style="width:160px; height:12px;"/>';html+='<input type="button" value="" class="com_but" onclick="javascript:SchoolSelector.selectSchool(0, this.previousSibling.value);" />';html+='</div>';}
$j("#location_county_box").html(html);},selectCounty:function(id,name,obj){$j("#location_school_box").html("").hide();if(SchoolSelector.type=="highschool"){SchoolSelector.loadHighschool(id);}
else if(SchoolSelector.type=="vocationalschool"){SchoolSelector.loadVocationalschool(id);}
else if(SchoolSelector.type=="juniorschool"){SchoolSelector.loadJuniorschool(id);}
var nodes=$j('#'+SchoolSelector.id).find(".curr");nodes.each(function(){var el=$j(this);if(el.parent().attr('id')=="location_county_box"){el.removeClass();}});$j(obj).parent().attr('class',"curr");},selectSchool:function(id,name){if($j.type(SchoolSelector.bind)=='string'){$j('#'+SchoolSelector.bind).val(name);}else{$j(SchoolSelector.bind).val(name);}
$j('#'+SchoolSelector.id).trigger("schoolselector:selectschool",[name]);SchoolSelector.hide();if(SchoolSelector.type=="university"&&id>0&&(typeof(showDepartment)=="function"||SchoolSelector.loadFaculty)){SchoolSelector.loadDepartment(id);}
else if(SchoolSelector.type=="university"&&id==0&&typeof(emptyDepartment)=="function"){emptyDepartment();}},loadDepartment:function(id){var xhr=$j.get("/interface/suggestlocation.php?type=8&id="+id,function(data){if(typeof(showDepartment)=="function"){showDepartment(xhr);}
$j('#'+SchoolSelector.id).trigger("schoolselector:department",[data]);});},loadHighschool:function(id){SchoolSelector.showLoading("location_school_box");$j.get("/interface/suggestlocation.php?type=5&id="+id,SchoolSelector.showHighschool);},showHighschool:function(trans){var data=eval('('+trans+')');var html="";for(var i=0;i<data.length;i++){html+='<p><a class="sl" onclick="SchoolSelector.selectSchool('+data[i].id+",'"+data[i].name+"'"+');">'+data[i].name+'</a></p>';}
html+='<div class="c"></div>';html+='<div class="c6" style="padding:5px 0 5px 10px;">其他：';html+='<input type="text" style="width:160px; height:12px;"/>';html+='<input type="button" value="" class="com_but" onclick="javascript:SchoolSelector.selectSchool(0, this.previousSibling.value);" />';html+='</div>';$j("#location_school_box").html(html);},loadVocationalschool:function(id){SchoolSelector.showLoading("location_school_box");$j.get("/interface/suggestlocation.php?type=7&id="+id,SchoolSelector.showVocationalschool);},showVocationalschool:function(trans){var data=eval('('+trans+')');var html="";for(var i=0;i<data.length;i++){html+='<p><a class="sl" onclick="SchoolSelector.selectSchool('+data[i].id+",'"+data[i].name+"'"+', this);">'+data[i].name+'</a></p>';}
html+='<div class="c"></div>';html+='<div class="c6" style="padding:5px 0 5px 10px;">其他：';html+='<input type="text" style="width:160px; height:12px;"/>';html+='<input type="button" value="" class="com_but" onclick="javascript:SchoolSelector.selectSchool(0, this.previousSibling.value);" />';html+='</div>';$j("#location_school_box").html(html);},loadJuniorschool:function(id){SchoolSelector.showLoading("location_school_box");$j.get("/interface/suggestlocation.php?type=6&id="+id,SchoolSelector.showVocationalschool);},showJuniorschool:function(trans){var data=eval('('+trans+')');var html="";for(var i=0;i<data.length;i++)
{html+='<p><a class="sl" onclick="SchoolSelector.showJuniorschool('+data[i].id+",'"+data[i].name+"'"+');">'+data[i].name+'</a></p>';}
html+='<div class="c"></div>';html+='<div class="c6" style="padding:5px 0 5px 10px;">其他：';html+='<input type="text" style="width:160px; height:12px;"/>';html+='<input type="button" value="" class="com_but" onclick="javascript:SchoolSelector.selectSchool(0, this.previousSibling.value);" />';html+='</div>';$j("#location_school_box").html(html);}};
