var shortest_match_char = '';
if(navigator.userAgent.indexOf("MSIE 4")==-1 && navigator.userAgent.indexOf("MSIE 5")==-1){
	shortest_match_char = "121".replace(new RegExp("^.*?1"), "")=="21"?'?':'';
}
var bbcoderegexpre = [[/&([lg]t;)/gi,'&amp;$1'],[/</gi, '&lt;'],[/>/gi, '&gt;']];
var bbcoderegex = [[/\[URL\]\s*((https?|ftp|mms):\/\/[^\[\]\s]+)\s*\[\/URL\]/gi, '<a href="$1" target="_blank">$1</a>'],
[/\[URL\]\s*(www\.[^\[\]\s]+)\s*\[\/URL\]/gi, '<a href="http://$1" target="_blank">$1</a>'],
[new RegExp("\\[URL\\s*=\\s*(['\"]?)((https?|ftp|mms)://[^\\[\\]\\s'\"]+)\\1\\s*\\](.*"+shortest_match_char+")\\[/URL\\]","gi"), '<a href="$2" target="_blank">$4</a>'],
[new RegExp("\\[URL\\s*=\\s*(['\"]?)(www\\.[^\\[\\]\\s'\"]+)\\1\\s*\\]\\s*(.*"+shortest_match_char+")\\s*\\[/URL\\]","gi"), '<a href="http://$2" target="_blank">$3</a>'],
[new RegExp("\\[IMG\\]\\s*(http://([^\\[\\s]|\\[[^/])+)\\s*\\[/IMG\\]", "gi"), '<img src="$1"></img>'],
[new RegExp("\\[([bui])\\](([^[]|\\[[^bBuUiI])*"+shortest_match_char+")\\[/\\1\\]","gi"), '<$1>$2</$1>'],
[new RegExp("\\[color\\s*=\\s*(['\"]?)([^'\"\\]]+)\\1\\s*\\](([^[]|\\[[^cC])*"+shortest_match_char+")\\[/color\\]","gi"), '<font color="$2">$3</font>'],
[new RegExp("\\[font\\s*=\\s*(['\"]?)([^'\"\\]]+)\\1\\s*\\](([^[]|\\[[^fF])*"+shortest_match_char+")\\[/font\\]","gi"), '<font face="$2">$3</font>'],
[new RegExp("\\[size\\s*=\\s*(['\"]?)\\s*(\\d{1,2}p[tx])\\1\\s*\\](([^[]|\\[[^sS])*"+shortest_match_char+")\\[/size\\]","gi"), '<span style="font-size: $2">$3</span>'],
[new RegExp("\\[size\\s*=\\s*(['\"]?)([^'\"\\]]+)\\1\\s*\\](([^[]|\\[[^sS])*"+shortest_match_char+")\\[/size\\]","gi"), '<font size="$2">$3</font>'],
[new RegExp("\\[quote\\](([^[]|\\[[^qQ])*"+shortest_match_char+")\\[/quote\\]","gi"), '<blockquote><font face="宋体,verdana,arial,helvetica" >引用:</font><hr>$1<hr></blockquote>'],
[new RegExp("\\[email\\]\\s*(\\S*"+shortest_match_char+")\\s*\\[/email\\]","gi"), '<a href="mailto:$1">$1</a>'],
[new RegExp("\\[email\\s*=\\s*(['\"]?)([^'\"\\]]+)\\1\\s*\\](([^[]|\\[[^/])*"+shortest_match_char+")\\[/email\\]","gi"), '<a href="mailto:$2">$3</a>']
];

function dobbcode(message) {
  if(message==''){
    return message;
  }
  for(var i in bbcoderegexpre){
    message = message.replace(bbcoderegexpre[i][0], bbcoderegexpre[i][1]);
  }
  var message0;
  do{
    message0=message;
    for(var i in bbcoderegex){
      message = message.replace(bbcoderegex[i][0], bbcoderegex[i][1]);
    }
  }
  while(message!=message0);
  return message;
}

$(function(){
isie=$.browser.msie;

$("#otry em").click(function(){$("#searchstr").val($(this).text());$("form").submit()})

//ie form后面的 button默认不提交
$("#serachit").click(function(){$("form").submit()})

//表单提交
$("form").submit(function(){
if($("#searchstr").val()==""||$("#searchstr").val()=="请输入要查询的关键字"){$("#searchstr").val("请输入要查询的关键字");$("#searchstr").select();return false;}
})

//显示多少条目打印出来
$("#showitem"+itemnum).attr("checked",true).parent().css("color","#c00").css("font-weight","700");

//ui效果
$("#searchstr").hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");}).focus(function(){$(this).addClass("focus");}).blur(function(){$(this).removeClass("focus");});

//如果有关键字
if(stext!=""){

$("#ajax").show();

//////////////////////////////get torrent
$.ajax({
 type: "GET",
        url: "torrent.php?str="+stext+"&ie="+isie,
//        url: "torrent.xml", //本地测试
        dataType: "xml",
        success: function(data) {

	if($(data).find("BTInfo").length==0){$("#btResult").html("没找到关于<em>"+stext+"</em>的种子！").css("background-image","none");
	$("#ajax").fadeOut("fast",function(){$("#btResult").slideDown("fast");});}
	else{
//----------/////////////////
i=0;
ohtml="<ol>";
$(data).find("BTInfo").each(function(){if(i<itemnum){odesc=$(this).find("Desc").text();odesc=dobbcode(odesc).replace(/\n/g,"<br />").replace(/<p[^>]*>/g,"").replace(/<\/p>/g,"");odate=new Date($(this).find("TInfo").attr("UpdateTime")*1000);ohtml+="<li><span title=\"查看内容\" class=\"jianjie\">简介</span><a  title=\"更新日期："+odate.getFullYear()+"-"+(parseInt(odate.getMonth())+1)+"-"+odate.getDate()+" "+odate.getHours()+":"+odate.getMinutes()+" 类别："+$(this).find("Category").text()+"\" href=\"http://nnv.dl1.btchina.net/download.php?s="+$(this).attr("APATH")+"&attachmentid="+$(this).attr("AID")+"\">"+$(this).find("Title").text()+"</a> "+parseInt($(this).attr("FSize")/1024/1024*100)/100+"M "+" <em>"+$(this).find("TInfo").attr("Sources")+"</em>个种子</li><div title=\"双击关闭内容简介\" class=\"desc\">"+odesc+"</div>";i++}})
ohtml+="</ol>";
$("#btResult").html(ohtml);
$("#btResult li span").click(function(){$(this).parent().next().toggle();$(this).parent().toggleClass("nowli")})
$("#btResult li").dblclick(function(){$(this).next().toggle();$(this).toggleClass("nowli")})
$("#btResult div.desc").dblclick(function(){$(this).toggle();$(this).prev().toggleClass("nowli")})

$("#ad2").show();
$("#ad3").show();
$("#ajax").fadeOut("fast",function(){$("#btResult").show("fast");});
//----------/////////////////
	};

        }
})
/////////////////////////////////



//////////////////////////////

ootext = stext;
if($.browser.msie){ootext=encodeURI(stext)}

$("#souyo").load("souyo.php?str="+ootext,function(){
str="<ol>";
$("#souyo").find("a").each(function(){str+="<li><a target=\"souyo\" href=\""+$(this).attr("href")+"\">"+$(this).text()+"</a></li>"})
str+="</ol>";
$("#souyo").html(str);
});


//////////////////////////////

$(".shuoming p").show();

}else{$("#searchstr").focus().select()};

});
