var ClassDisplayMode=0;
var LevelCount=4;
var CurFcid=null;
var opt,nav,SelectedClassID,zjlistSelect,btnSelector,ClassTable,ClassTableTitle,ClassTableContent;
function getClassInfo_ask(dataType,condition,returnType) {
var db;
switch(dataType){
case 'class': db = classList; break;
case 'brand': db = brandList; break;
case 'area': db = areaList; break;
default: return null;
}
switch(returnType) {
case 'exists':
var c=db[condition];
if(c) return true;else return false;
case 'name':
var c=db[condition];
if(c) return c[1];else return '此分类不存在！';
break;
case 'fathersid':
var c=db[condition];
if(c){
c=c[2].slice(0);
c.unshift(0);
return c;
}else{
return [0];
}
break;
case 'fatherid':
var c=db[condition];
if(c && c[2].length>0) return c[2][c[2].length-1];else return 0;
break;
case 'childrenid':
if(condition==='0' || condition===0 || condition==='' || condition===null || typeof(condition)=='undefined') {
return db['TOP'].slice(0);
}else if (condition=='SEARCH' || condition=='TOP') {
return db[condition].slice(0);
}else if(condition) {
var c=db[condition];
if(c) return c[3].slice(0);else return [];
}else {
return [];
}
break;
case 'fullname':
var c=db[condition];
if(c) {
var value='';
var fathersID=c[2];
for(var i=0;i<fathersID.length;i++) {
value+=getClassInfo_ask(dataType,fathersID[i],'name') + ',';
}
return value+c[1];
}else {
return '';
}
break;
}
}
function UseNewClassMode(mode){
if(!mode){
ClassDisplayMode=0;
G("classopt").style.display="";
}else if(mode==1){
for(var i=0;i<LevelCount;i++){
document.write("<SELECT name='cSelect"+i.toString()+"' rel='" +i.toString()+ "' id='cSelect"+i.toString()+"' size='12' style='display:none; margin-right:10px; min-width:80px;'></SELECT>");
}
G("classopt").style.display="none";
ClassDisplayMode=1;
}else if(mode==2){
G("classopt").style.display="none";
var navObj=$("#classnav");
var navText=navObj.text();
navObj.empty();
navObj.append("<input type='button' value='" +navText+ "' id='selector' /><div id='cTable' style='display:none;'><div class='title' style='float:none;margin:0;'><a href='#' onclick='ClassTable.hide(); btnSelector.show(0); return false;' class='close'>×</a><span id='cTableTitle'></span></div><ul id='cTableContent'></ul><div style='clear:both;'></div></div>");
btnSelector=$("#selector");
ClassTable=$("#cTable");
ClassTableTitle=$("#cTableTitle");
ClassTableContent=$("#cTableContent");
btnSelector.click( function(){EchoClass_2();});
ClassDisplayMode=2;
}else if(mode==3){
for(var i=0;i<LevelCount;i++){
document.write("<SELECT name='cSelect"+i.toString()+"' rel='" +i.toString()+ "' id='cSelect"+i.toString()+"' size='1' style='display:none; margin-right:10px; min-width:80px;'></SELECT>");
}
G("classopt").style.display="none";
ClassDisplayMode=1;
}
}
function ChangeLocation(selid,level){
opt=G("classopt");
nav=G("classnav");
SelectedClassID=G("SelectedClassID");
zjlistSelect=$("#zjlist");
if(zjlistSelect.length==0){
zjlistSelect=$("select:contains('不指定专家')");
}
InitClasses();
if(ClassDisplayMode==0){
return ChangeLocation_0(selid,level);
}else if(ClassDisplayMode==1 || ClassDisplayMode==3){
return ChangeLocation_1(selid,level);
}else if(ClassDisplayMode==2){
return ChangeLocation_2(selid,level);
}
}
function EchoClass_0(cid,selid){
var arr,fcid;
var bShowBack=false;
var iIndex=-1;
var iSelIndex=-1;
opt.options.length=0;
opt.selectedIndex=-1;
if(HaveSubClass(cid)){
fcid=cid;
}else{
selid=cid;
fcid=GetFatherID(cid);
}
var c;
var clist;
var subCids=getClassInfo_ask('class', fcid, 'childrenid');
var subCid;
for(var i=0;i<subCids.length;i++){
subCid=subCids[i]
if(iIndex==-1 && fcid>0){
bShowBack=true;
iIndex++;
opt.options.length=1;
opt.options[0].value=GetFatherID(fcid);
opt.options[0].text="*** 返回上级分类 ***";
opt.options[0].style.color="blue";
}
iIndex++;
opt.options.length=iIndex+1;
opt.options[iIndex].value=subCid;
opt.options[iIndex].text=GetClassName(subCid);
if(subCid==selid) {
iSelIndex=iIndex;
opt.selectedIndex=iIndex;
}
}
opt.hideFocus=false;
opt.selectedIndex=iSelIndex;
if(iIndex>-1 && !bShowBack){try{opt.options[0].style.color="";}catch(e){}}
return (fcid==cid);
}
function ChangeLocation_0(selid,level){
var SelLeastC=false;
var AddToTitleCid=0;
if(typeof(selid)=="undefined"){
if(opt.selectedIndex==-1) return false;
var cid=parseInt(opt[opt.selectedIndex].value,10);
var topic=opt[opt.selectedIndex].text;
var fid;
if(topic=="*** 返回上级分类 ***"){
EchoClass_0(cid,0);
}else{
if(EchoClass_0(cid,0)){
}else{
SelLeastC=true;
}
}
}else{
selid=parseInt(selid,10);
var cid=selid;
var topic=GetClassName(selid);
if(HaveSubClass(cid)==false){
SelLeastC=true;
EchoClass_0(GetFatherID(cid),cid);
}else{
EchoClass_0(cid,0);
}
}
SelectedClassID.value=cid;
var s="";
var cname;
var fstrs=getClassInfo_ask('class', cid, 'fathersid');
if(cid && HaveSubClass(cid)) fstrs.push(cid);
for(var i=0;i<fstrs.length;i++){
cname=GetClassName(fstrs[i]);
if(!cname)cname="分类名称未知"
s=s+"<a href='javascript:ChangeLocation_0(" + fstrs[i] + ");'>" + cname + "</a> >> ";
}
if(SelLeastC==true)s=s+topic;
nav.innerHTML=s;
refreshZjlist(cid);
}
function selectOption_1(level,fcid,cid){
var opt=G('cSelect'+level);
if(!opt){hideClass(level);return false;}
fcid=parseInt(fcid,10);if(isNaN(fcid)) fcid=0;
cid=parseInt(cid,10);if(isNaN(cid)) cid=0;
var arr,iIndex=-1;
opt.options.length=0;
opt.selectedIndex=-1;
iIndex++;
opt.options.length=iIndex+1;
opt.options[iIndex].value=0;
opt.options[iIndex].text='请选择问题分类';
var subCids=getClassInfo_ask('class', fcid, 'childrenid');
var subCid;
for(var i=0;i<subCids.length;i++){
subCid=subCids[i]
iIndex++;
opt.options.length=iIndex+1;
opt.options[iIndex].value=subCid;
opt.options[iIndex].text=GetClassName(subCid);
if(subCid==cid) opt.selectedIndex=iIndex;
}
if(opt.options.length>0){
try{opt.options[0].style.color="";}catch(e){}
if(opt.style.display=="none") opt.style.display="";
return true;
}else{
hideClass(level);
return false;
}
}
function ChangeLocation_1(selid,level){
var iLevel=parseInt(level,10);if(isNaN(iLevel)) iLevel=0;
if(iLevel>0 && selid==0) {
var opt=G('cSelect'+(iLevel-1));
selid=$(opt).val();
SelectedClassID.value=selid;
hideClass(iLevel+1);
refreshZjlist(selid);
return;
}
if(SelectedClassID) SelectedClassID.value=selid;
var curLevel=0;
selid=parseInt(selid,10);
if(typeof(level)=="undefined"){
if(typeof(selid)=="number" && selid>0){
var fstrs=getClassInfo_ask('class', selid, 'fathersid');
if(fstrs.length>0 && fstrs[fstrs.length-1]!=selid) fstrs.push(selid);
for(var i=1;i<fstrs.length;i++){
if(!selectOption_1(i-1,fstrs[i-1],fstrs[i])) return false;
}
curLevel=fstrs.length-1;
}else{
selid=0;
if(!selectOption_1(0,0,0)) return false;
curLevel++;
}
}else{
selectOption_1(level,GetFatherID(selid),selid);
curLevel=level;
curLevel++;
}
if(selid>0 && HaveSubClass(selid)){
selectOption_1(curLevel,selid,0);
curLevel++;
}
hideClass(curLevel);
refreshZjlist(selid);
}
function EchoClass_2(cid){
var arr,fcid;
if(typeof(cid)=="undefined") cid=$("#SelectedClassID").val();
if(HaveSubClass(cid)){
fcid=cid;
}else{
fcid=GetFatherID(cid);
}
if(CurFcid !=fcid){
var c;
var clist="";
var subCids=getClassInfo_ask('class', fcid, 'childrenid');
var subCid;
for(var i=0;i<subCids.length;i++){
subCid=subCids[i]
c="<li><a href='#" +subCid+ "' rel='" +subCid+ "' onclick='ChangeLocation_2(" +subCid+ "); return false;'";
if(subCid==cid){
c+=" class='sel'";
}
c+=">" +GetClassName(subCid)+ "</a></li>";
clist+=c;
}
var fathersID=getClassInfo_ask('class', cid, 'fathersid');
if(cid && cid!='0' && HaveSubClass(cid)) fathersID.push(cid);
var sLinks="";
var cname;
for(var i=0;i<fathersID.length;i++){
cname=GetClassName(fathersID[i]);
if(!cname)cname="分类名称未知"
sLinks+="<a href='javascript:ChangeLocation_2(" + fathersID[i] + ");'>" + cname + "</a> >> ";
}
sLinks+="<span id='TheLeastC'>";
if(fcid!=cid) sLinks+=GetClassName(cid);
sLinks+="</span>"
ClassTableTitle.html(sLinks);
ClassTableContent.html(clist);
}else if (fcid!=cid){
cname=GetClassName(cid);
$("#TheLeastC").text(cname);
$("#cTableContent a.sel").attr("class","");
$("#cTableContent a[rel='" +cid+ "']").attr("class","sel");
}
CurFcid=fcid;
var sTexts=ClassTableTitle.text();
sTexts=sTexts.replace("顶级分类 >> ", "");
if(sTexts=="") sTexts="请选择问题分类"; else sTexts+=" （点击可修改）";
btnSelector.val(sTexts);
btnSelector.hide();
ClassTable.show(0);
}
function ChangeLocation_2(selid,level){
selid=parseInt(selid,10);
SelectedClassID.value=selid;
if(ClassTable && ClassTable.css("display")!="none"){
EchoClass_2(selid);
}else if(selid){
var sTexts=GetFullPathOf(selid);
sTexts=sTexts.replace("顶级分类 >> ", "");
if(sTexts=="") sTexts="请选择问题分类"; else sTexts+=" （点击可修改）";
btnSelector.val(sTexts);
}
refreshZjlist(selid);
}
function SearchClassOf(SearchInput){
hideClass(0);
var optMain=G("classopt");
var s=SearchInput.value;
if(!s){
optMain.style.display="none";
ChangeLocation(0);
return true;
}
var arr;
var iIndex=-1;
optMain.options.length=0;
optMain.selectedIndex=-1;
SelectedClassID.value=0;
var tmpArray=[],ID,item;
for(var ID in classList){
if(ID && ID!='SEARCH' && ID!='TOP'){
item=classList[ID];
if(item[1].indexOf(s)!=-1){
tmpArray.push(item[0]+item[1]+','+ID);
}
}
}
tmpArray.sort();
for(var i=0;i<tmpArray.length;i++){
iIndex++;
optMain.options.length=iIndex+1;
optMain.options[iIndex].value=tmpArray[i];
optMain.options[iIndex].text=GetFullPathOf(tmpArray[i]);
}
if(optMain.options.length==0){
optMain.options.length=1;
optMain.options[0].value=0;
optMain.options[0].text="没找到相关分类，返回顶级分类";
optMain.options[0].style.color="blue";
optMain.onchange=optMain.onclick=function(){
SearchInput.value="";
optMain.style.display="none";
ChangeLocation_1();
};
}else{
optMain.onchange=optMain.onclick=function(){
var selIdx=this.selectedIndex;
if(selIdx==-1){
SelectedClassID.value=0;
}else{
SelectedClassID.value=this.options[selIdx].value;
}
};
}
optMain.style.display="";
refreshZjlist(0);
return true;
}
function InitClasses(){
if(ClassDisplayMode==1){
var aSelect
for(var i=0;i<LevelCount;i++){
aSelect=G("cSelect"+i.toString());
if(aSelect) aSelect.onchange=function(){ChangeLocation_1(this.value,this.id.substring(7,8))};
}
}
}
function GetClassName(cid){
if(cid==0) return "顶级分类";
return getClassInfo_ask('class', cid, 'name');
}
function GetFatherID(cid){
if(cid==0) return "顶级分类";
return getClassInfo_ask('class', cid, 'fatherid');
}
function HaveSubClass(cid){
return getClassInfo_ask('class', cid, 'childrenid').length>0;
}
function hideClass(FromLevel){
var o;
for(var i=FromLevel;i<LevelCount;i++){
o=G('cSelect'+i.toString());
if(o) o.style.display='none';
}
}
function GetFullPathOf(cid){
return trim(getClassInfo_ask('class', cid, 'fullname')).replace(/\,+/g, " >> ");
}
function refreshZjlist(cid){
if(!zjlistSelect) return;
if(zjlistSelect.length==0){
zjlistSelect=$("#zjlist");
if(zjlistSelect.length==0){
zjlistSelect=null;
return;
}
}
if(!cid){cid=0;}
if(zjlistSelect.attr('rel')=='allzj') {cid=0;}
$.ajax({
url:weburl+"js/ajaxServer.asp?lei=4&cid="+cid.toString(),
async:true,
cache:true,
success: function(html){
var obj=zjlistSelect.get(0);
var rel=zjlistSelect.attr("rel");
obj.options.length=0;
obj.selectedIndex=-1;
var arr=html.split(" ");
var iCount=0;
for(var i=0;i<arr.length;i++){
s=arr[i];
if(s){
if(iCount==0){
iCount++;
obj.options.length=1;
obj.options[0].value="";
obj.options[0].text=rel ? rel : "不指定专家";
}
iCount++;
obj.options.length=iCount;
obj.options[iCount-1].value=s;
obj.options[iCount-1].text=s;
}
}
if(iCount==0){
obj.options.length=1;
obj.options[0].value="";
obj.options[0].text=rel ? rel : "暂无专家";
}
if(zjlistSelect.attr('rel')=='allzj') zjlistSelect=null;
}
});
}
var checkGuestLogined=true;
function getAskTitle(frm){
var s=$("#titleInput").val();
if(!s && frm) s=frm.title.value;
if(s && s==$('#titleInput').attr('title')) s='';
return s;
}
function getAskText(frm,aRemoveHtml){
var co="";
try{co=oEditor.getContent('ContentForEdit'); }catch(e){}
if(!co) co=$('#ContentForEdit').val();
if(!co && frm) co=frm.content.value;
if(co && co==$('#ContentForEdit').attr('title')) co='';
if(aRemoveHtml) co=StripHtml(co);
return co;
}
function continueAsk() {
checkGuestLogined=false;
try{closeWindow();}catch(e){}
var btnSend=$('#btnSend');
if(btnSend.length==0) {
btnSend=$('#ftiwen').find('input[name="send"]');
}
if(btnSend.length==0) {
btnSend.click();
}else{
$('#ftiwen').submit();
}
}
function check_askform(frm,reserv1) {
if(submit_by_script) return true;
if(!frm || frm==window){
frm=G("ftiwen");
if(!frm)frm=G("askForm");
}
var title=getAskTitle(frm);
if(title=="" || title.length ==0){
alert("请输入问题标题");
frm.title.focus();
return false;
}
var len=title.length;
if(len<4){
ls_str="问题标题不详细，请重新输入";
alert(ls_str);
frm.title.focus();
return false;
}
if (len>100){
ls_str="问题标题字数限定在100个汉字以内，请缩短提问字数";
frm.title.focus();
return false;
}
var co=getAskText(frm,false);
var content_length=StripHtml(co).length;
if(content_length<5){
ls_str="请填写问题说明，说明越详细，解答就越有针对性";
alert(ls_str);
return false;
}
if ( content_length >4000){
ls_str="问题说明字数限定在4000字以内，请缩短字数";
alert(ls_str);
frm.content.focus();
return false;
}
try{
if(G('notice').checked){
var SenderEmail=G('SenderEmail').value;
if(!IsEmail(SenderEmail)) {
ls_str="请提供正确的邮件地址";
alert(ls_str);
G('SenderEmail').focus();
return false;
}
}
}catch(e){}
var cid=frm.SelectedClassID.value;
if(cid=="" || cid=="0"){
alert("请选择问题分类"); return false;
}
var uid=getUserID();
if(uid==0){
var sName="";
var sPwd="";
try{
var sName=frm.UserName.value;
var sPwd=frm.password.value;
}catch(e){}
if ((sName=="" || sPwd=="") && checkGuestLogined){
var sContinueSendHtml=null;
if(EnableGuestAsk==1){
sContinueSendHtml='<a href="#" onclick="continueAsk();">先不登陆，继续提交问题</a>';
}
ShowLogin('您还没有登陆', '3', sContinueSendHtml);
return false;
}
}
$('#ContentForEdit').val(co);
if(EnableAntiSpam==1){
PrepareAntiSpam(frm,"ASK");
if( NeedVCode(frm,"ask") ) return false;
}
}
var autoKeywordDisabled=false;
var lastTitle='';
var lastContent='';
function afterContentChanged(){setKeywords();}
function setKeywords(){
var title=getAskTitle();
if(G("RelatedQ")){
if(title && lastTitle!=title){
lastTitle=title;
$("#RelatedQ").load("?act=relatedq&QCount=10&q="+escape(title));
}
}
var co=getAskText(null,true);
var sContent=title+' '+ co;
if(lastContent==sContent) {
return false;
}
lastContent=sContent;
if(G('keywordsInput')){
if(EnableFenci==1 && (autoKeywordDisabled==false || $('#keywordsInput').val()=='')){
if(trim(sContent)!=''){
$.post(weburl+"js/ajaxServer.asp", 'lei=5&q='+escape(sContent), function(data){
var iPos=data.indexOf("<div");
$("#keywordsInput").val(iPos==-1 ? data : data.substring(0,iPos));
});
}
}
}
guessClass(sContent);
}
function setKeywordsBy(s){
$("#keywordsInput").val(s);
}
function setKeywordsAuto(f){
if($("#keywordsInput").val() && !confirm("自动提取将会首先清除当前所设置的关键词，继续吗？")) return false;
autoKeywordDisabled=true;
var title=getAskTitle(f);
var co=getAskText(f,true);
G("FenciTitle").value=title;
G("FenciContent").value=co;
G("frmFenci").submit();
}
function disableAutoKeyword(){
autoKeywordDisabled=true;
}
var guessDisabled=false;
function guessClass(aContent){
if(guessDisabled==true || !G('class_select_div') || !G('guess_info')) return false;
var arr;
var guess_class_id=0,guess_brand_id=0,guess_area_id=0;
try{guess_area_id=AreaID;}catch(e){}
var sFullName='';
var bShowGuessInfo=false;
this.doGuess=function(json){
if(json) {
arr=json['class'].sort().reverse();
if(arr.length>0){
guess_class_id=parseInt(arr[0].split('|')[1]);
}
if(EnableBrand==1){
arr=json.brand.sort().reverse();
if(arr.length>0){
guess_brand_id=parseInt(arr[0].split('|')[1]);
}
}
}
if(!guess_class_id){
guess_class_id=parseInt($('#SelectedClassID').val());
try{
if(!guess_class_id || isNaN(guess_class_id)) guess_class_id=defaultCid;
}catch(e){}
if(guess_class_id && getClassInfo_ask('class', guess_class_id, 'exists')==false) guess_class_id = 0;
}
if(guess_class_id){
sFullName=getClassInfo_ask('class', guess_class_id, 'fullname').replace(/\,+/g, " -> ");
$('#guess_info span[rel="class_data"]').text(sFullName);
$('#guess_info span[rel="class"]').show();
bShowGuessInfo=true;
ChangeLocation(guess_class_id);
}
$('#guess_info span[rel="brand"]').hide();
if(EnableBrand==1 && G('SelBrandID')){
if(guess_brand_id){
sFullName=getClassInfo_ask('brand', guess_brand_id, 'fullname').replace(/\,+/g, " -> ");
$('#guess_info span[rel="brand_data"]').text(sFullName);
$('#guess_info span[rel="brand"]').show();
}else{
$('#guess_info span[rel="brand_data"]').text('');
}
$(document).cs_ChangeValue('SelBrandName', guess_brand_id);
}
$('#guess_info span[rel="area"]').hide();
if(EnableArea==1 && G('SelAreaID')){
if(guess_area_id){
sFullName=getClassInfo_ask('area', guess_area_id, 'fullname').replace(/\,+/g, " -> ");
$('#guess_info span[rel="area_data"]').text(sFullName);
$('#guess_info span[rel="area"]').show();
}else{
$('#guess_info span[rel="area_data"]').text('');
}
$(document).cs_ChangeValue('SelAreaName', guess_area_id);
}
if(bShowGuessInfo){
$('#guess_info').show();
$('#class_select_div').hide();
}else{
$('#guess_info').hide();
$('#class_select_div').show();
}
}
if(trim(aContent)=='') {
doGuess(null);
}else{
$.post('?act=guessclass','content='+escape(aContent), function(data){doGuess(data);}, 'json');
}
}
function modifyClass(){
guessDisabled=true;
$('#guess_info').hide();
$('#class_select_div').show();
return false;
}
