/* (c) 2009 Blue Indigo, LLC */
var logged_in=false,media_url;var ajx_acct_si_url='/ajx/acct/si/',ajx_acct_so_url='/ajx/acct/so/',ajx_rt_alert_url='/ajx/acct/rta/',ajx_cat_alert_url='/ajx/acct/cata/';var sh_ac_url='/ajx/acct/sh/',rem_pr_url='/ajx/alert/rem/pr/',rem_na_url='/ajx/alert/rem/na/',ajx_al_na_url='/ajx/alert/na/',al_pr_url='/ajx/alert/pr/',ajx_fave_url='/ajx/af/',ajx_owner_url='/ajx/ao/';function $AE(el){return document.getElementById(el);}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"");}
String.prototype.startsWith=function(str){return this.substr(0,str.length)===str}
String.prototype.endsWith=function(str){return this.substr(this.length-str.length)===str}
function escape_entities(html){return html.replace(/&/gmi,'&amp;').replace(/"/gmi,'&quot;').replace(/>/gmi,'&gt;').replace(/</gmi,'&lt;')}
function getXMLHttpReq(){if(window.XMLHttpRequest){return new XMLHttpRequest();}else if(window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}else{return null;}}
function setCookie(name,value,seconds){if(seconds){var date=new Date();date.setTime(date.getTime()+seconds*1000);var expires="; expires="+date.toGMTString();}else{var expires="";}
document.cookie=name+"="+value+expires+"; path=/";}
function getCookie(name){name=name+"=";var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var c=cookies[i].trim();if(c.indexOf(name)==0)return c.substring(name.length,c.length);}
return null;}
function removeCookie(name){setCookie(name,"",-1);}
function init_acct_js(status,media){var ajx_req=getXMLHttpReq();if(ajx_req==null){alert('Your browser does not allow XML HTTP requests, AppExplorer will not work correctly.');}
logged_in=status;media_url=media;}
function show_appurl(short_url){var shmsg=$AE('appurl')
shmsg.innerHTML="";shmsg.style.fontFamily="CourierNew, Courier, monospace";shmsg.style.fontSize="14px";shmsg.innerHTML=short_url;}
function appurl_help(){alert("Tweet and IM short iTunes app links: click on 'Show short iTunes link' and copy and paste\n\n"+"For more information click the About AppExplorer link")}
function post_ajx(ajx_req,url,args,callback){ajx_req.open("POST",url,true);ajx_req.setRequestHeader("Content-type","application/x-www-form-urlencoded");ajx_req.setRequestHeader("Content-length",args.length);ajx_req.setRequestHeader("Connection","close");ajx_req.onreadystatechange=callback;ajx_req.send(args);return ajx_req;}
function sw_full_site(use_full,url){if(use_full){setCookie('expl_fv',1);}else{removeCookie('expl_fv');}
location.href=url;}
var ajx_req_sh;function acct_sh(){ajx_req_sh=getXMLHttpReq();if(ajx_req_sh==null)return;ajx_req_sh.open("POST",sh_ac_url,true);ajx_req_sh.onreadystatechange=proc_acct_sh;ajx_req_sh.send("");}
function proc_acct_sh(){var ndiv;if(ajx_req_sh.readyState==4){if(ajx_req_sh.status==200){resp=ajx_req_sh.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_acct_sh: problem parsing results: "+e);return false;}
var resp=results.Response;if(resp.status!='success'){alert(resp.message);return false;}
$AE('id_acctsh_email').innerHTML=escape(resp.email);$AE('id_rt_alert').checked=resp.rt_alerts;var cat_alert1=resp.cat_alert1,cat_alert2=resp.cat_alert2;var sel1=$AE('id_catalert1');for(opt=0;opt<sel1.options.length;opt++){if(sel1.options[opt].value==cat_alert1)sel1.options[opt].selected=true;}
sel2=$AE('id_catalert2');for(opt=0;opt<sel2.options.length;opt++){if(sel2.options[opt].value==cat_alert2)sel2.options[opt].selected=true;}
var min_stars=resp.min_stars
stars=$AE('id_catalertstars');for(opt=0;opt<stars.options.length;opt++){if(stars.options[opt].value==min_stars)stars.options[opt].selected=true;}
ndiv='';if(resp.price_alerts.length>0){ndiv+='<table width="99%">'+'<tr style="font-style:italic; color:#202040;">'+'<td colspan="2">Send me email:</td><td align="right" >remove</td></tr>\n';for(var pa in resp.price_alerts){pal=resp.price_alerts[pa];ndiv+="<tr><td colspan='2'><a href='/a/"+pal.uid+"/'>"+
pal.name+"</a> ($"+pal.price+") - "+pal.alert+"</td>\n";ndiv+="<td valign='top'>\n";ndiv+="<a style='float:right;' href='javascript:void(rem_pr_al(\""+pal.id+"\"));' onclick='return confirm(\"Remove this alert?\");'>\n";ndiv+="<img src='"+media_url+"pix/xbox10.gif' border='0' title='remove' /></a>\n";ndiv+="</td></tr>\n";}
ndiv+=" </table>\n";$AE('id_acct_pr_al').innerHTML=ndiv;$AE('id_acct_pr_al2').innerHTML="To add another app price alert, find the app in AppExplorer<br />and use the <b>get price alert</b> link<br />"}else{$AE('id_acct_pr_al').innerHTML='';$AE('id_acct_pr_al2').innerHTML="Add price alerts by finding the app in AppExplorer and clicking <b>get price alert</b><br />"}
if(resp.new_app_alerts.length>0){ndiv='<table width="99%">\n';for(var na in resp.new_app_alerts){al=resp.new_app_alerts[na].alert;ndiv+="<tr><td>"+al+"</td>\n";ndiv+="<td valign='top'>\n";ndiv+="<a style='float:right;' href='javascript:void(rem_na_al(\""+resp.new_app_alerts[na].id+"\"));' onclick='return confirm(\"Remove this alert?\");'>\n";ndiv+="<img src='"+media_url+"pix/xbox10.gif' border='0' title='remove' /></a>\n";ndiv+="</td></tr>\n";}
ndiv+=" </table>\n";$AE('id_acct_na_al').innerHTML=ndiv;$AE('id_acct_na_al2').innerHTML="Notify me of new apps like these (no more than once a day):"
$AE('id_acct_na_al3').innerHTML="To watch for other kinds of new apps, try a new search in AppExplorer<br />"+"then click <strong>Notify me of new apps like these</strong>"}else{$AE('id_acct_na_al').innerHTML='';$AE('id_acct_na_al2').innerHTML='';$AE('id_acct_na_al3').innerHTML="To find out when new apps you might like are added to AppExplorer,<br />"+"search for keywords of interest to you, then from the search results page click<br />"+"<strong>Notify me of new apps like these</strong><br />"+"(It works even if your search doesn't find anything right now)"}
if(resp.owned_apps.length>0){var n=0;ndiv='<table width="99%" cellspacing="8"><tr>\n';for(var op in resp.owned_apps){if(n%5==0&&n>0)ndiv+="</tr><tr>";n++;app=resp.owned_apps[op];ndiv+="<td align='center' valign='top' width='100'>";ndiv+="<a href='/a/"+app.uid+"'>";ndiv+="<img src='"+app.img_url+"' border='0' /><br />";ndiv+=app.name+"</a>"+"<a href='javascript:void(rem_owner(\""+app.uid+"\"))'>"+" <img src='"+media_url+"pix/xbox10.gif' alt='' border='0' /></a>"+"</td>\n";}
ndiv+="</tr></table>\n";$AE('id_owned_apps').innerHTML=ndiv;}else{$AE('id_owned_apps').innerHTML="Indicate that you own an app by finding the app in AppExplorer and clicking <b>I own this app</b><br />"+"Doing so may improve AppExplorer app recommendations for you."}
if(resp.favorite_apps.length>0){var n=0;ndiv='<table width="99%" cellspacing="8"><tr>\n';for(var f in resp.favorite_apps){if(n%5==0&&n>0)ndiv+="</tr><tr>";n++;app=resp.favorite_apps[f];ndiv+="<td align='center' valign='top' width='100'>"+"<a href='/a/"+app.uid+"'>"+"<img src='"+app.img_url+"' border='0' /><br />"+
app.name+"</a>"+"<a href='javascript:void(rem_fave(\""+app.uid+"\"))'>"+" <img src='"+media_url+"pix/xbox10.gif' alt='' border='0' /></a>"+"</a></td>\n";}
ndiv+="</tr></table>\n";$AE('id_acct_fave').innerHTML=ndiv;}else{$AE('id_acct_fave').innerHTML="Add to your wish list by finding the app in AppExplorer and clicking <b>Add to wish list</b>"}
show_modal($AE('m_acct_sh'));}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_sh.statusText+"</em><br />";}}
return false;}
var ajx_req_so;function acct_so(){ajx_req_so=getXMLHttpReq();if(ajx_req_so==null)return;ajx_req_so.open("POST",ajx_acct_so_url,true);ajx_req_so.onreadystatechange=proc_acct_so;ajx_req_so.send("");}
function proc_acct_so(){if(ajx_req_so.readyState==4){if(ajx_req_so.status==200){resp=ajx_req_so.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_acct_so: problem parsing results: "+e);}
var resp=results.Response;if(resp.auth){$AE('id_signed_out').style.display="none";$AE('id_signed_in').style.display="inline";logged_in=true;}else{$AE('id_signed_in').style.display="none";$AE('id_signed_out').style.display="inline";logged_in=false;}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_so.statusText+"</em><br />";}}}
function close_siu(){unshow_modal();$AE('id_email').value='';$AE('id_pw').value='';$AE('id_emailsu').value='';$AE('id_pwsu').value='';$AE('id_captcha').value='';return false;}
var ajx_req_si;function acct_si(){unshow_modal();$AE('id_email').value='';$AE('id_pw').value='';show_modal($AE('m_acct_si'));$AE('id_email').focus();}
function sign_in(){var email=$AE('id_email').value;var pw=$AE('id_pw').value;if(!email||!pw){alert('Please enter your email address and password');return false;}
var post_args="email="+encodeURIComponent(email)+"&pw="+encodeURIComponent(pw);ajx_req_si=getXMLHttpReq();if(ajx_req_si==null)return false;post_ajx(ajx_req_si,ajx_acct_si_url,post_args,proc_acct_si);return false;}
function proc_acct_si(){if(ajx_req_si.readyState==4){if(ajx_req_si.status==200){resp=ajx_req_si.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_acct_si: problem parsing results: "+e);}
var resp=results.Response;if(resp.status=='success'){if(resp.auth){$AE('id_signed_out').style.display="none";$AE('id_signed_in').style.display="inline";logged_in=true;}else{$AE('id_signed_in').style.display="none";$AE('id_signed_out').style.display="inline";logged_in=false;}
unshow_modal();}else if(resp.status=='warning'){alert(resp.message);if(resp.auth){$AE('id_signed_out').style.display="none";$AE('id_signed_in').style.display="inline";logged_in=true;}else{$AE('id_signed_in').style.display="none";$AE('id_signed_out').style.display="inline";logged_in=false;}
unshow_modal();}else{alert(resp.message);}}else{if($AE('app_results')){$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_si.statusText+"</em><br />";}else{alert("We're sorry, the sign in service is not currently available,\nplease try again later");}}}}
var cap_url=null,cap_img;function getnewcap(){if(cap_url==null)alert("int err: no cap_url");cap_img=new Image();cap_img.src=cap_url+'?'+(new Date()).getTime();return cap_img;}
function sign_up(c_url){unshow_modal();cap_url=c_url;$AE('id_captcha_img').src=getnewcap().src;$AE('id_nnsu').value=''
$AE('id_emailsu').value=''
$AE('id_pwsu').value=''
$AE('id_captcha').value=''
$AE('id_tos').checked=false;show_modal($AE('m_acct_su'));$AE('id_nnsu').focus();}
function sign_up2(url){var nick=$AE('id_nnsu').value;var email=$AE('id_emailsu').value;var pw=$AE('id_pwsu').value;var pw2=$AE('id_pwsu2').value;var tos=$AE('id_tos').checked;if(!nick){alert('Please enter a name or nickname');return false;}
if(!email){alert('Please enter your email address');return false;}
if(!pw){alert('Please enter a password');return false;}
if(!pw2){alert('Please enter password twice');return false;}
var captcha=$AE('id_captcha').value.trim();if(!captcha){alert('Please enter the test word');return false;}
if(!$AE('id_tos').checked){alert('Please accept the terms of service to sign up');return false;}
var post_args="nick="+encodeURIComponent(nick)+"&email="+encodeURIComponent(email)+"&pw="+encodeURIComponent(pw)+"&pw2="+encodeURIComponent(pw2)+"&captcha="+encodeURIComponent(captcha.trim());if(tos)post_args+="&tos=on";ajx_req_sh=getXMLHttpReq();if(ajx_req_sh==null)return false;post_ajx(ajx_req_sh,url,post_args,proc_acct_su)
return false;}
function proc_acct_su(){if(ajx_req_sh.readyState==4){if(ajx_req_sh.status==200){var resp=ajx_req_sh.responseText;$AE('id_captcha').value='';$AE('id_pwsu').value='';$AE('id_pwsu2').value='';var results;try{results=JSON.parse(resp);}catch(e){alert("proc_acct_su: problem parsing results: "+e);}
var resp=results.Response;if(resp.status=='success'){if(resp.auth){$AE('id_signed_out').style.display="none";$AE('id_signed_in').style.display="inline";logged_in=true;}else{$AE('id_signed_in').style.display="none";$AE('id_signed_out').style.display="inline";logged_in=false;}
alert(resp.message);unshow_modal();}else if(resp.status=='warning'){alert(resp.message);unshow_modal();}else{alert(resp.message);$AE('id_captcha_img').src=getnewcap().src;}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_sh.statusText+"</em><br />";}}
return false;}
var ajx_req_pw,home_url;function pw_reset(url,home){var home_url=home;var email=$AE('id_email').value;if(!email){alert('Please enter your email address');return false;}
var post_args="email="+encodeURIComponent(email);ajx_req_pw=getXMLHttpReq();if(ajx_req_pw==null)return false;post_ajx(ajx_req_pw,url,post_args,proc_pw_reset);return false;}
function proc_pw_reset(){if(ajx_req_pw.readyState==4){if(ajx_req_pw.status==200){var resp=ajx_req_pw.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("problem parsing results: "+e);}
var resp=results.Response;if(resp.status=='success'){alert(resp.message);unshow_modal();}else if(resp.status=='warning'){alert(resp.message);unshow_modal();}else{alert(resp.message);}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_pw.statusText+"</em><br />";}}}
function chg_pw(url,home){home_url=home;pw1=$AE('id_pw1').value;pw2=$AE('id_pw2').value;if(pw1!=pw2){alert('Passwords do not match');return false;}
if(pw1.length<6){alert('Passwords must be at least 6 characters long');return false;}
post_args="pw1="+encodeURIComponent(pw1)+"&pw2="+encodeURIComponent(pw2);ajx_req_pw=getXMLHttpReq();if(ajx_req_pw==null)return false;post_ajx(ajx_req_pw,url,post_args,proc_chg_pw);return false;}
function proc_chg_pw(){if(ajx_req_pw.readyState==4){if(ajx_req_pw.status==200){resp=ajx_req_pw.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_pw_reset: problem parsing results: "+e);}
var resp=results.Response;if(resp.status=='success'){alert(resp.message);$AE('m_pw_reset').style.display='none';location.href=home_url;}else if(resp.status=='warning'){alert(resp.message);$AE('m_pw_reset').style.display='none';}else{alert(resp.message);}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_pw.statusText+"</em><br />";}}}
function show_fb(url){unshow_modal();cap_url=url;$AE('fb_cap').src=getnewcap().src;$AE('id_emailfb').value='';$AE('id_fb').value='';$AE('id_capfb').value='';show_modal($AE('m_fb'));$AE('id_emailfb').focus();return false;}
function close_fb(){$AE('id_fb').innerHTML='';unshow_modal();return false;}
var ajx_req;function send_fb(url){var email=$AE('id_emailfb').value;var msg=$AE('id_fb').value.trim();if(msg==''){alert('Please enter feedback');return false;}
var captcha=$AE('id_capfb').value;if(!captcha){alert('Please enter the test word');return false;}
var params='email='+encodeURIComponent(email)+'&msg='+encodeURIComponent(msg)+'&captcha='+encodeURIComponent(captcha)
ajx_req=getXMLHttpReq();if(ajx_req==null)return false;post_ajx(ajx_req,url,params,proc_fb)
document.body.style.cursor='wait';$AE('id_ssub3').value='Sending...';return false;}
function proc_fb(){if(ajx_req.readyState==4){document.body.style.cursor='default';if(ajx_req.status==200){$AE('id_ssub3').value='Send feedback';var resp=ajx_req.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_fb: problem parsing results: "+e);}
var resp=results.Response;alert(resp.message);if(resp.status=='success'){unshow_modal();}else{$AE('id_capfb').value='';$AE('fb_cap').src=getnewcap(cap_url).src;}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req.statusText+"</em><br />";}}}
function proc_resp(ajx_req){if(ajx_req.readyState==4){if(ajx_req.status==200){var resp=ajx_req.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_resp: problem parsing results: "+e);}
var resp=results.Response;if(resp.message)alert(resp.message);if(resp.status=='success'){unshow_modal();}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req.statusText+"</em><br />";}}}
var ajx_req_pr;function set_pr_al(name,uid,price_t){if(!logged_in){alert('Please sign in first');return false;}
$AE('is_al_pr_nm').innerHTML=name;$AE('is_al_pr_nm2').innerHTML=name;$AE('id_pr_nm').value=uid;$AE('id_curr_pr').innerHTML=price_t;show_modal($AE('m_al_pr'));return false;}
function new_pr_al(){var app=$AE('id_pr_nm').value;var type='';if($AE('id_pr_free').checked)type='free';else if($AE('id_pr_ltc').checked)type='ltc';else if($AE('id_pr_lte').checked)type='lte';else if($AE('id_pr_change').checked)type='change';var price=$AE('id_mprice').value;if(type==''){alert("Please make a selection");$AE('id_nprf').reset();return false;}
var params='app='+encodeURIComponent(app)+'&alert_type='+encodeURIComponent(type)+'&price='+encodeURIComponent(price);ajx_req_pr=getXMLHttpReq();if(ajx_req_pr==null)return false;post_ajx(ajx_req_pr,al_pr_url,params,proc_pr_al)
$AE('id_nprf').reset();return false;}
function proc_pr_al(){proc_resp(ajx_req_pr);}
var ajx_rm_pr;function rem_pr_al(id){var params='id='+encodeURIComponent(id);ajx_rm_pr=getXMLHttpReq();if(ajx_rm_pr==null)return false;post_ajx(ajx_rm_pr,rem_pr_url,params,proc_rm_pr)
return false;}
function proc_rm_pr(){proc_resp(ajx_rm_pr);}
var ajx_req_na;function add_noti(query,cat,cat_name,price,ipad){var params='',amp=false,hasArgs=false;var conf="Do you wish to be notified about new";if(ipad){hasArgs=true;if(amp)params+='&';else amp=true;params+='ip=2';conf+=" iPad";}
conf+=" apps";var q=query.trim();if(q){hasArgs=true;if(amp)params+='&';else amp=true;params+='q='+encodeURIComponent(q);if(q.startsWith('dev:')){conf+=" from developer '"+q.substring(4).trim()+"'";}else{conf+=" matching '"+q+"'";}}
if(cat>0){hasArgs=true;if(amp)params+='&';else amp=true;params+='cat='+cat;conf+=" in category '"+cat_name+"'";}
if(price){hasArgs=true;var price_o=(price+'').trim();if(amp)params+='&';else amp=true;params+='price='+encodeURIComponent(price_o);if(price_o=='0'){conf+=" that are free";}else{conf+=" that are $"+price_o+" or less";}}
if(!hasArgs)conf="Do you want to be notified of all new apps";if(!confirm(conf+'?\n (no more than one email message per day)'))return false;ajx_req_na=getXMLHttpReq();if(ajx_req_na==null)return false;post_ajx(ajx_req_na,ajx_al_na_url,params,proc_na_al);return false;}
function proc_na_al(){proc_resp(ajx_req_na);}
var ajx_rm_na;function rem_na_al(id){var params='id='+encodeURIComponent(id);ajx_rm_na=getXMLHttpReq();if(ajx_rm_na==null)return false;post_ajx(ajx_rm_na,rem_na_url,params,proc_rm_na)
return false;}
function proc_rm_na(){proc_resp(ajx_rm_na);}
var ajx_rta;function rt_alert_changed(){var use_rt=$AE('id_rt_alert').checked;params='rt='+(use_rt?'yes':'no')
ajx_rta=getXMLHttpReq();if(ajx_rta==null)return false;post_ajx(ajx_rta,ajx_rt_alert_url,params,proc_rta)
return false;}
function proc_rta(){if(ajx_rta.readyState==4){if(ajx_rta.status==200){var resp=ajx_rta.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_rta: problem parsing results: "+e);}
var resp=results.Response;if(resp.status!='success'&&resp.message){alert(resp.message);}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_rta.statusText+"</em><br />";}}}
function new_feat(){alert("You can now register to be alerted when any paid app in a particular category becomes free.\r\n\r\n"+"You can also receive price alerts as they are discovered by AppExplorer (rather than only once per day).\r\n\r\n"+"Sign in and view your profile to use these new features.");}
var ajx_cata;function cat_alert_changed(){sel1=$AE('id_catalert1');cat1=sel1.options[sel1.selectedIndex].value;sel2=$AE('id_catalert2');cat2=sel2.options[sel2.selectedIndex].value;selstars=$AE('id_catalertstars');stars=selstars.options[selstars.selectedIndex].value;params='&cat1='+cat1+'&cat2='+cat2+'&stars='+stars;ajx_cata=getXMLHttpReq();if(ajx_cata==null)return false;post_ajx(ajx_cata,ajx_cat_alert_url,params,proc_cata)
return false;}
function proc_cata(){if(ajx_cata.readyState==4){if(ajx_cata.status==200){var resp=ajx_cata.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("proc_cata: problem parsing results: "+e);}
var resp=results.Response;if(resp.status!='success'&&resp.message){alert(resp.message);}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_cata.statusText+"</em><br />";}}}
function hl_rslt(d,c){var clr;if(c){clr=c;}else{clr='#fafafa';}
d.style.background=clr;}
var curr_mdl=new Array();var m_layer=0;function show_modal(m){curr_mdl[m_layer]=m;if(m.style.width&&document.body.scrollWidth){var w=m.style.width;w=w.substr(0,w.length-2);var bw=document.body.scrollWidth;m.style.left=Math.ceil((bw-w)/2)+'px';}
if(m_layer==0){var sh=$AE('mdl_sh');if(navigator.userAgent.toLowerCase().indexOf('msie 6')!=-1){if(document.body.scrollWidth)sh.style.width=document.body.scrollWidth+'px';if(document.body.scrollHeight)sh.style.height=document.body.scrollHeight+'px';}
sh.style.display='block';}
m_layer++;m.style.display='block';}
function unshow_modal(){if(m_layer>0)m_layer--;var m=curr_mdl[m_layer];if(m)m.style.display='none';m=null;if(m_layer==0)$AE('mdl_sh').style.display='none';}
function sh_img2(img2_url){var top=0;var left=0;if(screen&&screen.width&&screen.height){left=(screen.width-510)/2;top=(screen.height-510)/2;}
var nwin=window.open(img2_url,'screenshot','top='+top+'px,left='+left+'px,width=510,height=510');if(nwin.window)nwin.window.focus();}
var ajx_req_rnk,ajx_req_prc;var ajx_rnk_cht_url='/ajx/cht/rnk/',ajx_prc_cht_url='/ajx/cht/prc/';var rnk_msg,prc_msg,rnk_cht_url,prc_cht_url;function fetch_charts(uid){ajx_req_rnk=getXMLHttpReq();if(ajx_req_rnk==null)return false;ajx_req_rnk.open("POST",ajx_rnk_cht_url+uid+'/',true);ajx_req_rnk.onreadystatechange=proc_rnk_resp;ajx_req_rnk.send("");ajx_req_prc=getXMLHttpReq();if(ajx_req_prc==null)return false;ajx_req_prc.open("POST",ajx_prc_cht_url+uid+'/',true);ajx_req_prc.onreadystatechange=proc_prc_resp;ajx_req_prc.send("");return true;}
function proc_rnk_resp(){if(ajx_req_rnk.readyState==4){if(ajx_req_rnk.status==200){resp=ajx_req_rnk.responseText;var results;try{results=JSON.parse(resp);}catch(e){$AE('rnk_chart_msg').innerHTML="Problem parsing ranking chart response: "+e;$AE('id_appsh_charts').style.display="block";return false;}
var resp=results.Response;displ_rnk(resp);}else{$AE('rnk_chart_msg').innerHTML="There was a problem retrieving ranking chart response:<br /><em>"+
ajx_req_rnk.statusText+"</em><br />";$AE('id_appsh_charts').style.display="block";}}
return false;}
function displ_rnk(resp){if(resp.status=='success'){rnk_msg=resp.message;rnk_cht_url=resp.url;if(resp.url!=''){$AE('id_rnk_chart').src=resp.url;$AE('rnk_chart_msg').innerHTML=resp.message;$AE('id_appsh_charts').style.display="block";}else{$AE('td_rnk_chart').style.display="none";}}else{$AE('td_rnk_chart').style.display="none";}}
function proc_prc_resp(){if(ajx_req_prc.readyState==4){if(ajx_req_prc.status==200){resp=ajx_req_prc.responseText;var results;try{results=JSON.parse(resp);}catch(e){$AE('prc_chart_msg').innerHTML="Problem parsing price chart response: "+e;$AE('id_appsh_charts').style.display="block";return false;}
var resp=results.Response;displ_prc(resp);}else{$AE('prc_chart_msg').innerHTML="There was a problem retrieving price chart response:<br /><em>"+ajx_req_prc.statusText+"</em><br />";$AE('id_appsh_charts').style.display="block";}}
return false;}
function displ_prc(resp){if(resp.status=='success'){prc_msg=resp.message;prc_cht_url=resp.url;if(resp.url!=''){$AE('id_prc_chart').src=resp.url;$AE('prc_chart_msg').innerHTML=resp.message;$AE('id_appsh_charts').style.display="block";}else{$AE('id_prc_chart').style.display="none";$AE('td_prc_chart').style.display="inline";}}else{$AE('td_prc_chart').style.display="none";}}
function show_charts(){m_height=240;if(rnk_msg){if(rnk_cht_url){$AE('m_rnk_img').src=rnk_cht_url;$AE('m_rnk_img').style.display="block";}else{$AE('m_rnk_img').style.display="none";}
$AE('m_rnk_cht').style.display="block";$AE('m_rnk_msg').innerHTML=rnk_msg;}else{$AE('m_rnk_cht').style.display="none";$AE('m_rnk_msg').innerHTML='';}
if(prc_msg){if(prc_cht_url){$AE('m_prc_img').src=prc_cht_url;$AE('m_prc_img').style.display="block";}else{$AE('m_prc_img').style.display="none";}
$AE('m_prc_cht').style.display="block";$AE('m_prc_msg').innerHTML=prc_msg;}else{$AE('m_prc_cht').style.display="none";$AE('m_prc_msg').innerHTML='';}
if(rnk_cht_url&&prc_cht_url){$AE('m_charts').style.height='480px';}else{$AE('m_charts').style.height='280px';}
show_modal($AE('m_charts'));}
var ajx_req_af;function add_rem_fave(chk,uid){var params='app='+uid+'&add_fave='+(chk.checked?'on':'off');ajx_req_af=getXMLHttpReq();if(ajx_req_af==null)return false;post_ajx(ajx_req_af,ajx_fave_url,params,proc_fave)
return false;}
function rem_fave(uid){if(!confirm('Remove from wish list?'))return false;var params='app='+uid+'&add_fave=off';ajx_req_af=getXMLHttpReq();if(ajx_req_af==null)return false;post_ajx(ajx_req_af,ajx_fave_url,params,proc_fave);return false;}
function proc_fave(){if(ajx_req_af.readyState==4){if(ajx_req_af.status==200){var resp=ajx_req_af.responseText;var results;try{results=JSON.parse(resp);}catch(e){alert("problem parsing results: "+e);}
var resp=results.Response;alert(resp.message);if(resp.status=='success'){unshow_modal();}else{$AE('id_fave').checked=resp.was_on_list;}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_af.statusText+"</em><br />";}}}
var ajx_req_ao;function add_rem_owned(chk,uid){var params='app='+encodeURIComponent(uid)+'&set_owned='+(chk.checked?'on':'off');ajx_req_ao=getXMLHttpReq();if(ajx_req_ao==null)return false;post_ajx(ajx_req_ao,ajx_owner_url,params,proc_owned);return false;}
function rem_owner(uid){if(!confirm('Remove from list?'))return false;var params='app='+uid+'&set_owned=off'
ajx_req_ao=getXMLHttpReq();if(ajx_req_ao==null)return false;post_ajx(ajx_req_ao,ajx_owner_url,params,proc_owned)
return false;}
function proc_owned(){if(ajx_req_ao.readyState==4){if(ajx_req_ao.status==200){var resp=ajx_req_ao.responseText,results;try{results=JSON.parse(resp);}catch(e){alert("problem parsing results: "+e);}
var resp=results.Response;alert(resp.message);if(resp.status=='success'){unshow_modal();}else{$AE('id_owned').checked=resp.was_on_list;}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_ao.statusText+"</em><br />";}}}
var ajx_req_shar,sh_app_uid;function show_share_app1(uid,url,capurl){sh_app_uid=uid;cap_url=capurl;unshow_modal();ajx_req_shar=getXMLHttpReq();if(ajx_req_shar==null)return false;ajx_req_shar.open("POST",url,true);ajx_req_shar.onreadystatechange=show_share_app2;ajx_req_shar.send("");return false;}
function show_share_app2(){if(ajx_req_shar.readyState==4){if(ajx_req_shar.status==200){var resp=ajx_req_shar.responseText,results;try{results=JSON.parse(resp);}catch(e){alert("problem parsing results: "+e);}
var resp=results.Response;if(resp.status!='success'){alert(resp.message);}else{$AE('shar_cap').src=getnewcap().src;$AE('id_capshar').value='';$AE('id_sh_email').value='';$AE('id_smc').checked=false;$AE('id_sh_msg').value='';$AE('id_sharer').innerHTML=resp.nickname+" ("+resp.email+")";show_modal($AE('m_shar'));$AE('id_sh_email').focus();}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_shar.statusText+"</em><br />";}}
return false;}
function share_app(share_url){var friend=$AE('id_sh_email').value.trim();if(!friend){alert('Please enter email address for your friend');return false;}
var smc;if($AE('id_smc').checked){smc="yes;"}else{smc="no";}
var msg=$AE('id_sh_msg').value.trim().substr(0,200);var captcha=$AE('id_capshar').value.trim();if(!captcha){alert('Please enter the test word');return false;}
var params='app='+encodeURIComponent(sh_app_uid)+'&friend='+encodeURIComponent(friend)+'&smc='+smc+'&msg='+encodeURIComponent(msg)+'&captcha='+encodeURIComponent(captcha)
ajx_req_shar=getXMLHttpReq();if(ajx_req_shar==null)return false;post_ajx(ajx_req_shar,share_url,params,proc_shar)
document.body.style.cursor='wait';$AE('id_ssub5').value='Sharing...';return false;}
function proc_shar(){if(ajx_req_shar.readyState==4){document.body.style.cursor='default';if(ajx_req_shar.status==200){$AE('id_ssub5').value='Share app';var resp=ajx_req_shar.responseText,results;try{results=JSON.parse(resp);}catch(e){alert("problem parsing results: "+e);}
var resp=results.Response;alert(resp.message);if(resp.status=='success'){unshow_modal();}else{$AE('id_capshar').value='';$AE('shar_cap').src=getnewcap(cap_url).src;}}else{$AE('app_results').innerHTML="There was a problem retrieving the result:<br /><em>"+ajx_req_shar.statusText+"</em><br />";}}}
function new_sort(sel,args){location.href='/'+args+'&so='+sel.options[sel.selectedIndex].value;}