String.prototype.replaceAll=function(strTarget,strSubString){var strText=this;var intIndexOfMatch=strText.indexOf(strTarget);while(intIndexOfMatch!=-1){strText=strText.replace(strTarget,strSubString)
intIndexOfMatch=strText.indexOf(strTarget);}
return(strText);};Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=Base64._utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}
output=output+
this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+
this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4);}
return output;},decode:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}
if(enc4!=64){output=output+String.fromCharCode(chr3);}}
output=Base64._utf8_decode(output);return output;},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}
else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}
else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}
return utftext;},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}
else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}
else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}
return string;}};(function($){$.toJSON=function(o)
{if(typeof(JSON)=='object'&&JSON.stringify)
return JSON.stringify(o);var type=typeof(o);if(o===null)
return"null";if(type=="undefined")
return undefined;if(type=="number"||type=="boolean")
return o+"";if(type=="string")
return $.quoteString(o);if(type=='object')
{if(typeof o.toJSON=="function")
return $.toJSON(o.toJSON());if(o.constructor===Date)
{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';}
if(o.constructor===Array)
{var ret=[];for(var i=0;i<o.length;i++)
ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";}
var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;if(typeof o[k]=="function")
continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);}
return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src)
{if(typeof(JSON)=='object'&&JSON.parse)
return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string)
{if(string.match(_escapeable))
{return'"'+string.replace(_escapeable,function(a)
{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';}
return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);;;mobileAT={currentPage:"",activeAjax:false,cache:{},categories:{},cacheThisPage:function(){mobileAT.cache[mobileAT.currentPage]=$("#mainpagediv").html();},setPageFail:function(){mobileAT.setPageData('There was an error.');},setPageLoading:function(){mobileAT.setPageData('<h2>Loading...</h2><div style="text-align:center; padding-top: 30px"><img src="http://static.apptrackr.org/mobile_en/img/loading.gif" /></div>');},applist:{cat:0,currentPage:1,sort:1,maxPages:0,search:"",appData:[],deviceid:1,populate:function(){var request={p:"browse",getPages:false};if((mobileAT.applist.maxPages==0)||(mobileAT.applist.page==1))
request.getPages=true;if(navigator.userAgent.indexOf("OS 3_2")!=-1)
mobileAT.applist.deviceid=0;request.category=mobileAT.applist.cat;request.page=mobileAT.applist.currentPage;request.sort=mobileAT.applist.sort;request.search=mobileAT.applist.search;request.deviceid=mobileAT.applist.deviceid;if(mobileAT.activeAjax!=false)
mobileAT.activeAjax.abort();mobileAT.activeAjax=$.ajax({type:"POST",url:"/m/",data:request,dataType:"json",success:function(data){if(typeof(data.numpages)!="undefined")
mobileAT.applist.maxPages=data.numpages;mobileAT.applist.appData=data.pagedata;mobileAT.activeAjax=false;mobileAT.applist.constructAppPage();},error:function(){mobileAT.activeAjax=false;mobileAT.setPageFail();}});},constructAppPage:function(){if((typeof(mobileAT.applist.appData)=="undefined")||(mobileAT.applist.appData.length<1)){mobileAT.setPageData('<h2>There are no applications to show.</h2>');return false;}
var appPage='<h2>Applications</h2><ul class="listapp">';for(i in mobileAT.applist.appData){appPage+='<li onmouseover="$(this).css(\'background\', \'#0274EE\');"><a href="#p=viewapp,id='+mobileAT.applist.appData[i].id+',type=normal" onmouseover="$(this).css(\'color\', \'#ffffff\');">';appPage+='<div class="listiconbox"><div class="listicon" style="background: url('+mobileAT.applist.appData[i].icon57+');"></div></div>';appPage+='<div class="listdescbox"><div class="appco">'+mobileAT.applist.appData[i].seller+'</div><div class="appname">'+mobileAT.applist.appData[i].name+'</div><div class="appvers">Version '+mobileAT.applist.appData[i].latest_version+'</div></div>';appPage+='</a></li>';}
if(mobileAT.applist.currentPage<mobileAT.applist.maxPages)
appPage+='<li><a href="#p=browse,search='+mobileAT.encodeReq(mobileAT.applist.search)+',sort='+mobileAT.applist.sort+',cat='+mobileAT.applist.cat+',page='+(mobileAT.applist.currentPage+1)+'"><div class="morelinks">Next Page ...</div></a></li></ul>';else
appPage+='</ul>';mobileAT.setPageData(appPage);}},setCatList:function(sort){var replace='<h2>Categories</h2><ul class="listapp">';replace+='<li onmouseover="$(this).css(\'background\', \'#0274EE\');"><a href="#p=browse,sort='+sort+',cat=0,page=1,search=" onmouseover="$(this).css(\'color\', \'#ffffff\');">';replace+='<div class="listiconbox"><div class="listicon" style="background: url(http://static.apptrackr.org/caticons/all.jpg)"></div></div>';replace+='<div class="listdescbox"><div class="listopt">All Applications</div></div></a></li>';for(var i in mobileAT.categories){replace+='<li onmouseover="$(this).css(\'background\', \'#0274EE\');"><a href="#p=browse,search=,sort='+sort+',cat='+mobileAT.categories[i].id+',page=1" onmouseover="$(this).css(\'color\', \'#ffffff\');">';replace+='<div class="listiconbox"><div class="listicon" style="background: url('+mobileAT.categories[i].iconurl+')"></div></div>';replace+='<div class="listdescbox"><div class="listopt">'+mobileAT.categories[i].name+'</div></div></a></li>';}
replace+='</ul>';mobileAT.setPageData(replace,true);},setCurrentPage:function(){mobileAT.setPageLoading();if(typeof(mobileAT.cache[mobileAT.currentPage])!="undefined"){mobileAT.setPageData(mobileAT.cache[mobileAT.currentPage]);return false;}
var request=mobileAT.parseAnchor(mobileAT.currentPage);if(request.p=="catlist"){return mobileAT.setCatList(request.sort);}else if(request.p=="browse"){mobileAT.applist.currentPage=parseInt(request.page);mobileAT.applist.sort=parseInt(request.sort);mobileAT.applist.cat=parseInt(request.cat);mobileAT.applist.search=mobileAT.decodeReq(request.search);mobileAT.applist.populate();return false;}
if(mobileAT.activeAjax!=false)
mobileAT.activeAjax.abort();mobileAT.activeAjax=$.ajax({type:"POST",url:"/m/",data:request,success:function(data){mobileAT.activeAjax=false;mobileAT.setPageData(data);},error:function(){mobileAT.activeAjax=false;mobileAT.setPageFail();}});return false;},setPageData:function(data,cache){if(typeof(cache)=="undefined")
cache=false;$("#mainpagediv").animate({opacity:0},"fast","swing",function(){$("#mainpagediv").html(data);$("#mainpagediv").animate({opacity:1},"fast","swing");if(cache)
mobileAT.cacheThisPage();});},parseAnchor:function(anchor){anchor=anchor.slice(1);var returnobj={};var groups=anchor.split(",");for(var i in groups){var curgroup=groups[i].split("=");returnobj[curgroup[0]]=curgroup[1];}
return returnobj;},anchorTimer:function(){if(window.location.hash==""){window.location.hash=mobileAT.currentPage="#p=home";mobileAT.setCurrentPage();}else if(mobileAT.currentPage!=window.location.hash){mobileAT.currentPage=window.location.hash;mobileAT.setCurrentPage();}
setTimeout(mobileAT.anchorTimer,100);},encodeReq:function(req){return Base64.encode(req).replaceAll('=',':');},decodeReq:function(req){return Base64.decode(req.replaceAll(':','='));},handleSearchSubmit:function(){$("#searchbar").blur();if($("#searchbar").val()=="")
window.location.hash="#p=home";else
window.location.hash="#p=browse,page=1,cat=0,sort=4,search="+mobileAT.encodeReq($("#searchbar").val());return false;}};
