//UBB转html主
function UbbCode2Html(context){
 context=context.replace(/&/g,"&amp;");
 context=context.replace(/</g,"&#60;");
 context=context.replace(/>/g,"&#62;");
 context=AUBB2Html(context,"emo",0);
 context=AUBB2Html(context,"quote",1);
 context=AUBB2Html(context,"reply",1);
 context=AUBB2Html(context,"i",1);
 context=AUBB2Html(context,"b",1);
 context=AUBB2Html(context,"u",1);


 context=context.replace(/\xbd\xbd/g,"");
 context=context.replace(/ /g,"&nbsp;");
 var tempstr;
 while(true){
  if (/(<[a-z]+&nbsp;[^>]*>)/i.test(context)){
   tempstr=RegExp.$1.replace(/&nbsp;/g," ");
   context=context.replace(/(<[a-z]+&nbsp;[^>]*>)/i,tempstr);
  }
  else break;
 }
 context=context.replace(/\n/g,"<br>");
 //context=context.replace(/\"/,"&quot;");
 return context;
}

//UBB转html
function AUBB2Html(context,cmd,mode){
 var len=cmd.length;
 var convtxt=context;
 var lt="["+String.fromCharCode(0XBD,0XBD);
 //var lt="["+String.fromCharCode(0XBD,0XBD);
 while(true){
  var txt=convtxt.toLowerCase();
  var p1=txt.indexOf("["+cmd);
  if (p1==-1) break;
  var p2=txt.indexOf("]",p1);
  if (p2==-1) break;
  var ltext=convtxt.substring(0,p1);
  var rtext=convtxt.substr(p2+1);
  if (mode==0){
   //单目代码解释开始

   var cmdtxt=txt.substring(p1+len+1,p2).replace(/(\s+)$/g,"").replace(/^(\s+)/g,"");
   switch(cmd){
	case "emo":
    convtxt="";
	if (getNumberp(cmdtxt,"t")) convtxt=convtxt+" src="+SystemDomain+"style/emot/Face"+RegExp.$1+".gif"; //style/emot/Face1.gif
		convtxt=ltext.replace(/\r\n$/,"")+"<img"+convtxt+">"+rtext.replace(/^\r\n/,"");
    break;

	}
   //单目代码解释结束
  }else if(mode==1){
   //双目代码解释开始
   p3=txt.lastIndexOf("[/"+cmd+"]");
   if (p3<=p2) break;
   while(true){
    p4=txt.indexOf("[/"+cmd+"]",p2+1);
    if (p4==-1 || p4>=p3) break;
    p5=txt.indexOf("["+cmd,p2+1);
    if (p5>p3 || p5<p4) break;
    p6=txt.indexOf("]");
    if (p6==-1 || p6>p3) break;
    p3=p4;
   }
   //ltext=convtxt.substring(0,p1);
   rtext=convtxt.substr(p3+len+3);
   str1=convtxt.substring(p1+len+1,p2).replace(/(\s+) $/g,"").replace(/^(\s+)/g,"");
   str2=convtxt.substring(p2+1,p3);
   switch(cmd){

    case "quote":
	convtxt=ltext+"<div class=\"UBBPanel\"><div class=\"UBBTitle\"><img src=\"http://www.sikeu.com\/style\/images\/quote.gif\" style=\"margin:0px 2px -3px 0px\" alt=\"引用\"\/>引用<\/div><div class=\"UBBContent\">"+str2+"<br\/><\/div><\/div>"+rtext;
	break; 
    case "i":
    case "b":
    case "u":
    //设置文字斜体、加粗、加下划线效果
    //[I|B|U]显示内容[/I|B|U]
     convtxt=ltext+"<"+cmd.toUpperCase()+">"+str2+"</"+cmd.toUpperCase()+">"+rtext;
     break;
	case "reply":
     if(getUser(str1,"=")){
      convtxt=ltext+"<div class='UBBPanel replayPanel'><div class='UBBTitle'><img src='http://www.sikeu.com\/style\/images\/icon_reply.gif' style='margin:0px 2px -3px 0px'/> "+RegExp.$1+" 回复</div><div class='UBBContent'>"+str2+"</div></div>"+rtext;
	 }
	 else{convtxt=ltext+lt+convtxt.substr(p1+1);}
     break;
	}
  }
 }
 return convtxt;
}
function getNumberp(str,cmd){
 str=" "+str+" ";
 eval("re=/ "+cmd+"(\\d+%?) /i");
 return re.test(str);
}
function getUser(str,cmd){
 str=" "+str+" ";
 eval("re=/ "+cmd+"([^\\f\\n\\r\\t\\v]+) /i");
 return re.test(str);
}
function getStr(str,cmd){
 str=" "+str+" ";
 eval("re=/ "+cmd+" /i");
 return re.test(str);
}

