function search()
{this.string;
this.strings=new Object;
this.stringSearch;
this.loaded;
this.sites=new Object;
this.results=new Array;
this.filterTime;
this.filters=new Array;
this.category="";
this.categories=new Object;
this.categories[""]=new Object;
this.categories[""].results=new Array;
this.categoriesIndex=new Array;
this.sortColumn="seeds";
this.sortOrder=1;
this.done=0;this.resultPage;
this.resultMax=50;
this.resultCurrent=0;
this.pagination;
this.cells={health:"health",name:"string",size:"size",seeds:"color",peers:"color",engine:"engine",id:"id"};
this.rows=new Object;this.go=search_go;this.stop=search_stop;this.sort=search_sort;this.display=search_display;this.cat=search_category;this.filter=search_filter;this.sitefilter=search_sitefilter;this.removefilter=search_removefilter;this._get=search_get;this._done=search_done;this._filter=search_pfilter;

function search_go(){this.strings.include="";this.strings.exclude="";this.strings.words=this.string.split(" ");for(var x in this.strings.words){var _2=this.strings.words[x].substr(0,1);if(_2=="+"){this.strings.include+=" "+this.strings.words[x].substr(1)+".*"}else{if(_2=="-"){this.strings.exclude+="|"+this.strings.words[x].substr(1)}}}this.strings.include=this.strings.include.substr(1);this.strings.exclude=this.strings.exclude.substr(1);this.strings.include=this.strings.include?new RegExp(this.strings.include,"gi"):"";this.strings.exclude=this.strings.exclude?new RegExp(this.strings.exclude,"gim"):"";this.stringSearch=this.string.replace(new RegExp("\\+|\\-","g"),"").replace(this.strings.exclude,"");this.strings.highlight=new RegExp("("+this.stringSearch.replace(new RegExp("\\s","g"),"|")+")","gi");document.getElementById("filter").value="Type here to filter...";for(var x in this.sites){this._get(x)}}

function search_stop(){for(var x in this.sites){if(this.sites[x].state==1){this.sites[x].request.abort()}}}

function search_sort(_4,_5){if(!_5){this.sortOrder=this.sortColumn==_4?this.sortOrder==1?-1:1:1}document.getElementById(this.sortColumn).className="";document.getElementById(_4).className="sort_"+(this.sortOrder==1?1:0);this.sortColumn=_4;if(this.filters.length){this.filters.sort(_sort)}else{if(typeof this.categories[this.category]!="undefined"){this.categories[this.category].results.sort(_sort)}}this.display(1)}

function search_filter(){if(this.filterTime){window.clearTimeout(this.filterTime)}this.filterTime=window.setTimeout("search._filter()",500)}

function search_pfilter()
{this.removefilter(1);if(document.getElementById("filter").value){var _6=document.getElementById("filter").value;var _7=this.stringSearch+" "+_6;this.strings.highlight=new RegExp("("+_7.replace(new RegExp("\\s","g"),"|")+")","gi");var _8=new RegExp(_6.replace(new RegExp("\\s","g"),".*"),"gi");var _9=this.categories[this.category].results;for(var x in _9){var _b=_9[x].name.toString();if(_8&&_b.match(_8)){this.filters[this.filters.length]=_9[x]}}}if(this.filters.length||!document.getElementById("filter").value){document.getElementById("filter").className="filter InnerInputBox";document.getElementById("filter_status").innerHTML="<font color=green style=size:12px;>Filter Active!</font>&nbsp;<img src='/i/arrow_right.gif' alt='' border='0' valign='top' />&nbsp; <a href='javascript:search.removefilter();'>Remove filter</a>";this.display(1)}else{if(!this.filters.length){document.getElementById("filter").className="filterNo InnerInputBox";document.getElementById("filter_status").innerHTML="<font color=red>No results found!</font>&nbsp; <a href='javascript:search.removefilter();'>Remove filter</a>"}}
}

function search_sitefilter(_c){if(this.sites[_c].state==2||this.sites[_c].state==4){this.sites[_c].state=2}else{return 1}this.removefilter();var _d=this.categories[this.category].results;for(var x in _d){if(_d[x].engine==_c){this.filters[this.filters.length]=_d[x]}}for(var x in this.sites){if(this.sites[x].state==2&&x!=_c){this.sites[x].state=4}}document.getElementById("remove_filter").style.display="block";if(!this.filters.length){this.display(1,1)}else{this.display(1)}}

function search_removefilter(_f){document.getElementById("filter_status").innerHTML="No filter input...";this.filters=new Array;if(!_f){document.getElementById("filter").value="FILTER RESULTS";this.strings.highlight=new RegExp("("+this.stringSearch.replace(new RegExp("\\s","g"),"|")+")","gi")}for(var x in this.sites){if(this.sites[x].state==4){this.sites[x].state=2}}document.getElementById("remove_filter").style.display="none";this.display(1)}

function search_display(_11,_12){if(_11!=this.resultPage&&typeof window.scroll=="function"){window.scroll(0,0)}else{if(_11!=this.resultPage){window.scrollTo(0,0)}}if(_12){this.results=new Array}else{this.results=this.filters.length?this.filters:typeof this.categories[this.category]!="undefined"?this.categories[this.category].results:new Array}this.resultPage=_11;while(document.getElementById("result").rows.length){document.getElementById("result").deleteRow(document.getElementById("result").rows.length-1)}resultStart=this.resultMax*(this.resultPage-1);resultStop=this.results.length>this.resultMax?this.resultMax*this.resultPage:this.results.length;document.getElementById("counter").innerHTML="Results "+(resultStart+1)+"-"+resultStop+" of "+this.results.length+" for <b>"+this.string+"</b>";if(this.done==count(this.sites)){document.getElementById("status").innerHTML="Search Complete <img src='/i/tick.gif' alt='' />";document.getElementById("status").className="status_state_2";if(!this.results.length){var row=document.getElementById("result").insertRow(0);cell=row.insertCell(0);cell.innerHTML="<center><br /><br />No matching torrent results were found, please redefine your query!<br /><br /></center>";cell.className="search_noResult";cell.colSpan=6}}else{if(!this.results.length){var row=document.getElementById("result").insertRow(0);cell=row.insertCell(0);cell.className="search_wait";cell.colSpan=6}document.getElementById("status").innerHTML="Searching engine "+(this.done+1)+" of "+count(this.sites)}var _14="";this.categoriesIndex.sort(_sort2);for(var x in this.categoriesIndex){var _16=this.categoriesIndex[x];_14+="<li"+(_16==this.category?" class='cat_active'":"")+"><a href=\"javascript:search.cat('"+_16+"')\"><span>"+_16+" ("+this.categories[_16].results.length+")</span></a></li>"}if(_14){document.getElementById("categories").style.display="block";_14="<li"+(!this.category?" class='cat_active'":"")+"><a href=\"javascript:search.cat('')\"><span>All ("+this.categories[""].results.length+")</span></a></li>"+_14}document.getElementById("categories").innerHTML="<ul class='cat_tab'>"+_14+"</ul>";var _17=this.results.slice(resultStart,resultStop);for(var x in _17){var _18=document.getElementById("result").rows.length;var row=document.getElementById("result").insertRow(_18);row.id="results_"+x;if(typeof this.rows[row.id]!="object"){this.rows[row.id]=new Object}this.rows[row.id].even=isEven(x)?1:2;row.className="row_state_"+this.rows[row.id].even;row.onmouseover=function(){this.className="row_state_3"};row.onmouseout=function(){this.className="row_state_"+search.rows[this.id].even};row.onclick=function(){window.open(search.rows[this.id].url+""+search.rows[this.id].id)};var y=0;for(var _16 in this.cells){if(this.cells[_16]!="id"){cell=row.insertCell(y)}switch(this.cells[_16]){case"id":this.rows[row.id].id=_17[x][_16];break;

case"health":cell.innerHTML="<span id='h"+_17[x][_16]+"'><!-- --></span>";break;

//case"date":cell.innerHTML = convert_date(_17[x][_16]);break;

case"string":cell.innerHTML="<div class='name'>"+_17[x][_16].replace(this.strings.highlight,"<b>$1</b>")+"</div>";break;
case"size":cell.innerHTML=convert_size(_17[x][_16]);break;
case"color":cell.innerHTML=_17[x][_16]>0?"<div class='green'>"+_17[x][_16]+"</div>":"<div class='red'>"+_17[x][_16]+"</div>";break;
case"engine":this.rows[row.id].url=this.sites[_17[x][_16]].url;cell.innerHTML=this.sites[_17[x][_16]].name;break;

default:}y++}}var _14="";var y=0;for(var x in this.sites){var _1a=this.sites[x].state?this.sites[x].state:1;if(_1a!=1&&_1a!=3){
	_14+="<tr><td class=\"EngineBoxBottomBorder\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><img src=\"images/spacer.gif\" alt=\"\" width=\"10\" height=\"10\"></td></tr><tr><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"28\" height=\"25\" align=\"center\"><img src=\"images/sites/"+this.sites[x]['name']+".png\" border=\"0\"></td><td><a href=\"#\" class=\"enginrTextlink\">"+this.sites[x]['name']+"</a></td><td align=\"right\"><img src=\"images/TickImg.gif\" alt=\"\" width=\"21\" height=\"15\"></td></tr></table></td></tr></table></td></tr>";
	}else{if(_1a!=3){_14+="<tr><td class=\"EngineBoxBottomBorder\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><img src=\"images/spacer.gif\" alt=\"\" width=\"10\" height=\"10\"></td></tr><tr><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"28\" height=\"25\" align=\"center\"><img src=\"i/loading_small.gif\" alt=\"\" border=\"0\"></td><td><a href=\"#\" class=\"enginrTextlink\">"+this.sites[x]['name']+"</a></td><td align=\"right\">&nbsp;</td></tr></table></td></tr></table></td></tr>"}}y++}document.getElementById("sites").innerHTML="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+_14+"</table>";if(this.pagination){var _11=Math.ceil(this.results.length/this.resultMax);if(_11>1){var _14="<ul>";for(var x=1;x<=_11;x++){_14+="<li"+(x==this.resultPage?" class='page_active'":"")+"><a href='javascript:search.display("+x+")'>"+x+"</a></li>"}for(var id in this.pagination){document.getElementById(this.pagination[id]).innerHTML=_14}_14+="</ul>"}else{for(var id in this.pagination){document.getElementById(this.pagination[id]).innerHTML=""}}}}
function search_category(cat){this.removefilter();this.category=cat;this.sort(this.sortColumn,1)}
function search_get(_1d){var _1e=new Array;_1e.id=_1d;_1e.xml=new XMLHttpRequest;_1e.xml.onreadystatechange=function(){if(_1e.xml.readyState==4&&_1e.xml.status==200){var _1f=new Array;try{eval(_1e.xml.responseText+"_1f=results")}catch(err){search._done(_1e.id,3);return 0}for(var x in _1f){var _21=_1f[x].name.toString();if(search.strings.include){if(!_21.match(search.strings.include)){continue}}if(search.strings.exclude){if(_21.match(search.strings.exclude)){continue}}_1f[x].health=convert_health(_1f[x].seeds,_1f[x].peers);_1f[x].engine=_1e.id;if(!search.categories[_1f[x].category]){search.categories[_1f[x].category]=new Object;search.categories[_1f[x].category].results=new Array;var _22=search.categoriesIndex.length;search.categoriesIndex[_22]=new Object;search.categoriesIndex[_22]=_1f[x].category}search.categories[""].results[search.categories[""].results.length]=_1f[x];search.categories[_1f[x].category].results[search.categories[_1f[x].category].results.length]=_1f[x]}search._done(_1e.id,2)}else{if(_1e.xml.readyState==4&&_1e.xml.status!=200){search._done(_1e.id,3)}}};this.sites[_1d].state=1;this.sites[_1d].request=_1e.xml;_1e.xml.open("POST","get.php?site="+_1d+"&string="+this.string,true);_1e.xml.send("")}

function search_done(_23,_24){this.sites[_23].state=_24;this.done++;this.sort(this.sortColumn,1)}

}
var search=new search;window.onload=function(){if(document.getElementsByTagName){var c=document.getElementsByTagName("a");for(var a=0;a<c.length;a++){var b=c[a];if(b.getAttribute("href")&&b.getAttribute("rel")=="p"){b.onclick=function(){search.stop()}}}}search.display(1);search.go()};window.onunload=function(){search.stop()};function count(b){var c=0;if(b.__count){return b.__count}else{if(b.length){return b.length}else{for(var a in b){c++}return c}}}function isEven(a){return !(a%2)}function convert_health(c,b){if(c>0&&b>0){var a=Math.round((c/b)*10)/10;a=a>=1.1?10:a;a=a==1?10:a;a=a==0.9?9:a;a=a==0.8?8:a;a=a==0.7?9:a;a=a==0.6?7:a;a=a==0.5?6:a;a=a<=0.4?5:a;return a}else{return 1}}function convert_date(input){ 
   if(input == 0) return "-"; var date = new Date(); dif = Math.round(date / 1000) - input; years = Math.floor(dif/31535999); months = Math.floor(dif/2591999); days = Math.floor(dif/86399); hours = Math.floor(dif/3599); if(years < 1) if(months < 1) if(days < 1) if(hours < 1) stime = 'today'; else stime = hours + ' ' + (hours == 1 ? 'hour' : 'hours') + ' ago'; else stime = days + ' ' + (days == 1 ? 'day' : 'days') + ' ago'; else stime = months + ' ' + (months == 1 ? 'month' : 'months') + ' ago'; else stime = years + ' ' + (years == 1 ? 'year' : 'years') + ' ago'; return stime; }function convert_size(b){var a=new Array("MB","GB","TB");for(val in a){if(b>1024){b=b/1024}else{break}}return Math.round(b*100)/100+" "+a[val]}function _sort(e,d){var c=e[search.sortColumn].toString().toLowerCase();var f=d[search.sortColumn].toString().toLowerCase();if(search.cells[search.sortColumn]!="string"){return(f-c)*search.sortOrder}else{return((c<f)?-1:(c>f)?1:0)*search.sortOrder}}function _sort2(e,d){var c=e.toString().toLowerCase();var f=d.toString().toLowerCase();return(c<f)?-1:(c>f)?1:0};
