var nm;
var pm;
var post;
var seeking = 0;
var reprank = 'checked';
var upcode;
var wallatt;
var wallattvalue;
var loggedout;
var ranknames = new Array('(you have to rank her first)','(ugly feet)','(bad feet)','(ok feet)','(nice feet)','(beautiful feet)');
var bctext = new Array();
var actext = new Array();


var RecaptchaOptions = {
   theme : 'blackglass',
   tabindex : 10
};

function ajax(com,url)
{
            if (window.XMLHttpRequest) { // Mozilla, Safari,...
                http_request = new XMLHttpRequest();
            } else if (window.ActiveXObject) { // IE
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            http_request.onreadystatechange = alertContents;
            http_request.open('GET', url, true);
            http_request.send(null);

   function alertContents() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
           eval(com + '(http_request.responseText)');
           //return http_request.responseText;
           }
       }
   }
};

function ajaxpost(com, params)
{
            if (window.XMLHttpRequest) { // Mozilla, Safari,...
                http_request = new XMLHttpRequest();
            } else if (window.ActiveXObject) { // IE
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            }
            http_request.onreadystatechange = alertContents;
            http_request.open('POST', '/perl/helper.pl', true);
            http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            http_request.send(params);

   function alertContents() {
       if (http_request.readyState == 4) {
           if (http_request.status == 200) {
           eval(com + '(http_request.responseText)');
           //return http_request.responseText;
           }
       }
   }
};

function loginPChange(cond)
{
    if (cond)
      {
      document.getElementById('loginpasscont').innerHTML="<INPUT tabindex=2 type=password id=loginpass class=fobj onblur=\"if (this.value=='') {loginPChange(0)}\" onkeydown=\"if (event.keyCode == 13) {loginGO()}\">";
      setTimeout("document.getElementById('loginpass').focus();", 10);
      }
    else
      {
      document.getElementById('loginpasscont').innerHTML="<INPUT tabindex=2 type=text id=loginpass class=lfobj onfocus=\"loginPChange(1)\" value='password'>";
      };
};


function theme(color)
{
    var date = new Date();
		date.setTime(date.getTime()+(360*24*60*60*1000));
    document.cookie='theme=' + color + '; expires=' + date.toGMTString() + '; path=/';
    window.location.reload(1);
};


function nrlclicked()
{
    if (loggedout) {alert('You have to login again...'); return};
    document.getElementById('newreqlabel').style.visibility='hidden';
    document.getElementById('newreqbox').style.display='block';
    document.getElementById('newreqtext').focus();
};

function newreqkeyup(value)
{
    if (value=='') {document.getElementById('newreqbtn').innerHTML='Cancel / Close'}
    else {document.getElementById('newreqbtn').innerHTML='Submit'};
};

function nrbclicked()
{
    if (document.getElementById('newreqtext').value=='')
      {
      document.getElementById('newreqlabel').style.visibility='visible';
      document.getElementById('newreqbox').style.display='none';
      }
    else
      {
      document.getElementById('newreqbtn').disabled = true;
      ajaxpost('nrb_xd', 'request=newrequest&parameter=' + encodeURI( document.getElementById('newreqtext').value ));
      };
};

function nrb_xd(output)
{
    if (output.substring(0,1)=='1')
      {
      if (output.substring(1)=='0') {window.location.reload(1)}
      else {parent.location='/requests/' + output.substring(1)};
      }
    else
      {
      alert(output.substring(1));
      document.getElementById('newreqbtn').disabled = false;
      };
};


function forgotsubmit()
{
if (document.forgot.email.value.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) && document.forgot.pass1.value!='' && document.forgot.pass1.value == document.forgot.pass2.value)
  {return true}
else {forgotfc(2,'1'); return false};
};

function forgotfc(field, value)
{
    if (field==1)
      {
      if (value.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i))
          {
          if (document.forgot.pass1.value!='' && document.forgot.pass1.value == document.forgot.pass2.value)
              {
              document.getElementById('forgotstatus').innerHTML="Valid. <INPUT type=submit name=passreset value='submit'>";
              }
          else
              {
              document.getElementById('forgotstatus').innerHTML="Valid.";
              }
          }
      else
          {
          document.getElementById('forgotstatus').innerHTML=".. Not yet valid..";
          }
      }
    else if (field==2 || field==3)
      {
      if (document.forgot.pass1.value=='' || document.forgot.pass2.value=='')
          {
          document.getElementById('forgotstatus').innerHTML='';
          }
      else
          {
          if (document.forgot.pass1.value==document.forgot.pass2.value)
              {
              if (document.forgot.email.value.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i))
                  {
                  document.getElementById('forgotstatus').innerHTML="Match. <INPUT type=submit name=passreset value='submit'>";
                  }
              else
                  {
                  document.getElementById('forgotstatus').innerHTML="Match. Now fix e-mail address";
                  }
              }
          else
              {
              document.getElementById('forgotstatus').innerHTML=".. Passwords don't match";
              }
          }
      };
    //alert('you wrote ' + value + ' on fileld number ' + field);
};

function picturemenu(thediv)
{
    if (pm) {document.getElementById('pm'+pm).innerHTML=''};
    var reptitle;
    if (document.getElementById('r'+thediv).innerHTML) {reptitle='Unreport picture'} else {reptitle='Report picture as...'};
    if (pm == thediv) {pm=''}
    else if (loggedout) {alert('You have to login again...')}
    else {pm=thediv; document.getElementById('pm'+pm).innerHTML="<table class=picmenu><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"addStuff('pic',"+pm+")\"><td>Comment on this picture</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picinfo("+pm+")\"><td>View extended info</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"pictagmenu()\"><td>Manage picture-tags...</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picrepmenu()\"><td>" + reptitle + "</td></tr></table>"};
};

function picinfo()
{
  document.getElementById('pm'+pm).innerHTML="<table class=picmenu><tr><td><br>Loading picture info...<br><br></td></tr></table>";
  ajax('picinfo_xd', '/perl/helper.pl?request=picinfo&parameter=' + pm + '&random=' + Math.random());
};

function picinfo_xd(output)
{
  document.getElementById('pm'+pm).innerHTML=output;
};

function picrepmenu()
{
if (document.getElementById('r'+pm).innerHTML) {picreport(0); return};
  document.getElementById('pm'+pm).innerHTML="<table class=picmenu><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picreport('F')\"><td>Fake / Wrong person</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picreport('I')\"><td>Illegal / Copyrighted</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picreport('A')\"><td>Adult content</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picreport('P')\"><td>Poor quality - please remove</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picreport('D')\"><td>Duplicate - remove this copy</td></tr><tr style='cursor:pointer' onmouseover=\"this.className='onbrightfix_b'\" onmouseout=\"this.className='onbrightfix'\" onclick=\"picreport('N')\"><td>No feet showing</td></tr></table>";
};

function pictagmenu()
{
  document.getElementById('pm'+pm).innerHTML="<table class=picmenu><tr><td><br>Loading tags...<br><br></td></tr></table>";
  ajax('picinfo_xd', '/perl/helper.pl?request=showtags&parameter=' + pm + '&random=' + Math.random());
};

function picreport(type)
{
    if (pm)
      {
      ajax('picreport_xd', '/perl/helper.pl?request=picreport&parameter=' + pm + '&type=' + type + '&random=' + Math.random());
      }
    else {alert('WTF? something went wrong..')};
    document.getElementById('pm'+pm).innerHTML='';
};

function picreport_xd(output)
{
if (pm=='') {return};

if (output.substring(0,1)=='1')
    {
    if (output.substring(1)=='0')
        {
        document.getElementById('r'+pm).innerHTML='';
        }
    else
        {
        document.getElementById('r'+pm).innerHTML="<IMG SRC='/themes/global/rep_" + output.substring(1) + ".gif' class=reppic>";
        };
    }
else
    {
    alert(output.substring(1));
    };
pm='';
};


function postreport(post)
{
if (loggedout) {alert('You\'ve Logged-out. Please Log-in again to report stuff..'); return};
var sure = confirm('Here at wikiFeet we believe that everyone is entitled to his own opinion.\nHowever, if you believe that this post has offensive content that ruins the browsing experience for other visitors, you are welcome to report it.');
if (sure)
  {
  ajax('postreport_xd', '/perl/helper.pl?request=postreport&parameter=' + post + '&random=' + Math.random());
  };
};

function postreport_xd(output)
{
if (output=='1')
    {
    alert('Post reported.')
    }
else {alert(output.substring(1))};
};

function reqitem(req, type)
{
post = req;
document.getElementById('reqlinks').style.visibility='hidden';
var temp="<table style='border:1px solid #aaa; width:100%; background:#ddd'><tr><td><button id=reqitembtn style='float:right; font-size:8pt' onclick=reqitemsubmit("+ type +")>Close</button>";

if (type=='2') {temp+='Adding a Query'}
else if (type=='3') {temp+='Adding a Comment'}
else if (type=='4') {temp+='Marking as Pending'}
else if (type=='5') {temp+='Marking as Fulfilled'}
else if (type=='6') {temp+='ReOpening request thread'};

temp+="</td><td rowspan=2 style='width:10px; border:1px solid #aaa; height:100%; background:";

if (type=='2') {temp+='#acf'}
else if (type=='3') {temp+='#acf'}
else if (type=='4') {temp+='#ffa'}
else if (type=='5') {temp+='#afa'}
else if (type=='6') {temp+='#acf'};

temp+="'><br></td></tr><tr><td><TEXTAREA id=reqitemtext style='width:99%; height:40px' onkeyup=\"if (this.value=='') {document.getElementById('reqitembtn').innerHTML='Close'} else {document.getElementById('reqitembtn').innerHTML='Submit'}\"></TEXTAREA></td></tr></table>";
document.getElementById('addedcont').innerHTML=temp;
document.getElementById('reqitemtext').focus();
};

function reqitemsubmit(type)
{
if (document.getElementById('reqitembtn').innerHTML=='Submit')
  {
  if (document.getElementById('reqitemtext').value=='') {alert('Text field empty!'); return}
  else
    {
    document.getElementById('reqitembtn').disabled = true;
    ajaxpost('reqitemsubmit_xd', 'request=reqitemsubmit&req=' + post + '&type=' + type + '&comment=' + encodeURIComponent(document.getElementById('reqitemtext').value));
    }
  }
else
  {
  document.getElementById('addedcont').innerHTML='';
  document.getElementById('reqlinks').style.visibility='visible';
  };
};

function reqitemsubmit_xd(output)
{
    if (output.substring(0,1)=='1')
      {
      window.location.reload(1);
      }
    else
      {
      alert(output.substring(1));
      document.getElementById('reqitembtn').disabled = false;
      };
};

function pictag(type, value)
    {
    ajax('pictag_xd', '/perl/helper.pl?request=pictag&parameter=' + pm + '&type=' + type + '&value=' + value + '&random=' + Math.random());
    };
    
function pictag_xd(output)
  {
  if (output.substring(0,1)=='1')
    {
    document.getElementById('t'+pm).innerHTML=output.substring(1);
    }
  else
    {
    alert(output.substring(1));
    };
  };
  
function suggest(value)
{
    ajax('suggest_xd', '/perl/helper.pl?request=suggest&parameter=' + value + '&random=' + Math.random());
};

function suggest_xd(output)
{
    document.getElementById('suggestions').innerHTML=output;
};

function sugclose()
{
    document.getElementById('suggestions').style.visibility='hidden'
};

function loginGO()
{
    var username = document.getElementById('loginuser').value;
    var password = document.getElementById('loginpass').value;
    ajaxpost('loginBACK', 'request=login&username=' + encodeURIComponent(username) + '&password=' + encodeURIComponent(password));
};

function loginBACK(output)
{
    if (output.substring(0,1)=='0')
      {
      document.getElementById('loginmessage').innerHTML=output.substring(1);
      document.getElementById('loginpass').value='';
      document.getElementById('loginpass').focus();
      }
    else
      {
      if (document.getElementById('remember').checked == true)
        {
        var date = new Date();
  		  date.setTime(date.getTime()+(30*24*60*60*1000));
        document.cookie='passkey=' + output.substring(1) + '; expires=' + date.toGMTString() + '; path=/';
        }
      else
        {
        document.cookie='passkey=' + output.substring(1) + '; path=/;';
        };
      window.location.reload(1);
      };
};

function pidcheck(value)
{
    //alert('pid started');
    ajax('pidcheck_xd', '/perl/helper.pl?request=pidcheck&parameter=' + value + '&random=' + Math.random());
};

function silentseek(value)
{
    if (seeking || wallatt!='non') {return};
    var temp = value.match(/[0-9]?[0-9][0-9][0-9][0-9][0-9]+[^0-9]/);
    if (temp)
      {
      seeking = temp.toString().match("^[0-9]+");
      ajaxpost('silentseek_xd', 'request=pidcheck&parameter=' + seeking);
      };
};

function silentseek_xd(output)
{
    var pidtemp = output.split(';');
    nm = document.getElementById('cid').value;
    if (pidtemp[0] == nm)
      {
      wallatt = 'pic';
      wallattvalue = pidtemp[1];
      document.getElementById('w_non').className = 'walltypeoff';
      document.getElementById('w_pic').className = 'walltypeon';
      document.getElementById('w_vid').className = 'walltypeoff';
      document.getElementById('attd').innerHTML = "Picture id: <INPUT id=wi_pic type=text style='width:40px; font-size:7pt' value=" + pidtemp[1] + "><button style='font-size:7pt' onclick=\"addStuff('pic',document.getElementById('wi_pic').value)\">update</button>";
      document.getElementById('attachment').innerHTML="<a href='/pictures/"+pidtemp[1]+".jpg' target='_blank'><image style='border:1px solid black; height:89px' id=thewallimage src='/thumbs/"+pidtemp[1]+".jpg'></a>";
      document.getElementById('attachment').style.width=document.getElementById('thewallimage').width;
      wallattvalue=pidtemp[1];
      }
    else {alert('No go. they say it belongs to ' + pidtemp[1] + ' and not ' + nm)};
      
};

function pidcheck_xd(output)
{
    //alert('pidxd started');
    var pidtemp = output.split(';');
    nm = document.getElementById('cid').value;
    if (pidtemp[0] == nm)
      {
      document.getElementById('attachment').innerHTML="<a href='/pictures/"+pidtemp[1]+".jpg' target='_blank'><image style='border:1px solid black; height:89px' id=thewallimage src='/thumbs/"+pidtemp[1]+".jpg'></a>";
      document.getElementById('attachment').style.width=document.getElementById('thewallimage').width;
      wallattvalue=pidtemp[1];
      }
    else {alert('The specified Picture id does not belong to the current celeb.');};
};

function sendcontact()
{
         ajax('sendcontact_xd', '/perl/helper.pl?request=contact&email=' + encodeURI( document.getElementById('email').value ) + '&message=' + encodeURIComponent( document.getElementById('message').value ) + '&random=' + Math.random());
};

function sendcontact_xd(output)
{
	document.getElementById('contactarea').innerHTML = "<center><font size=6><br>" + output;
}


function checkaddress(value)
{

if (value.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) || value=='')
  {document.getElementById('eae').innerHTML=''}
else {document.getElementById('eae').innerHTML='<< Not a valid email address'};

};


function uploadsuggest(value)
{
         document.getElementById('sign').innerHTML="<image src='/themes/global/xsign.gif'>";
         document.getElementById('uptable').style.display='none';
         if (value=='') {document.getElementById('results').innerHTML=''; return 1}
         document.getElementById('results').innerHTML="Searching for results...";
         
         ajax('uploadsuggest_xd', '/perl/helper.pl?request=upsug&parameter=' + value + '&random=' + Math.random());
};

function uploadsuggest_xd(output)
{
         document.getElementById('results').innerHTML = output;
}



function getimdb(value)
{

  nm = value.match(/nm\d+/);
  if (nm==null) {
    document.getElementById('sign').innerHTML="<image src='/themes/global/xsign.gif'>";
    document.getElementById('uptable').style.display='none';
    document.getElementById('results').innerHTML="Invalid IMDb link entered.";
    }
  else {
    document.getElementById('results').innerHTML="Please Wait.. Fetching Celeb name";
    ajax('getimdb_xd', '/perl/helper.pl?request=imdbfetch&parameter=' + nm + '&random=' + Math.random());
   }
};

function getimdb_xd(output)
{
    if (output.substring(0,1)=='0')
      {
      document.getElementById('uptable').style.display='none';document.getElementById('sign').innerHTML="<image src='/themes/global/xsign.gif'>"; document.getElementById('results').innerHTML="Error: " + output.substring(1); document.upform.thefile.disabled=true;}
      else {upchosen(nm, output.substring(1))};
};





function upchosen(number, name)
{
         nm = number;
                document.getElementById('sign').innerHTML="<image src='/themes/global/vsign.gif'>";
                document.getElementById('results').innerHTML="Celebrity identified as:<br><b>" + name;
                document.getElementById('ucname').innerHTML=name;
                document.getElementById('preview').innerHTML='';
                document.upform.thefile.value='';
                document.getElementById('statusline').innerHTML='Browse to upload (Maximum file size 2.5MB)';
                document.getElementById('uptable').style.display='table';
};


function profilechange()
{
ajax('pr_startup_xd', '/perl/helper.pl?request=prrequest&random=' + Math.random());
};

function pr_startup_xd(output)
{
if (output=='0')
  {
  alert('Error: Check login status');
  document.upform.thefile.value='';
  return;
  };
upcode = output;
document.upform.parameter.value=output;

document.upform.action='/perl/helper.pl';
document.upform.submit();

document.upform.thefile.disabled=true;
timerId = setInterval("prupcheck('" + output + "')", 2000);
};

function startprc()
{
document.upform.submit();
document.upform.thefile.disabled=true;
timerId = setInterval("prupcheck('" + output + "')", 2000);
};

function prupcheck(code)
{
ajax('prupcheck_xd', '/perl/helper.pl?request=prupcheck&parameter=' + code + '&random=' + Math.random());
};

function prupcheck_xd(upresult)
{
var upc = upresult.split(';');
if (upc[0] == 'done')
   {
   document.upform.thefile.disabled=false;
   document.upform.thefile.value='';
   document.getElementById('prpic').src='/profiles/' + upc[1] + '.jpg#' + Math.random();
   clearInterval(timerId);
   alert('New profile pictured uploaded successfully');
   }
else if (upc[0] == 'error')
     {
     alert('Error! ' + upc[1]);
     document.upform.thefile.disabled=false;
     document.upform.thefile.value='';
     clearInterval(timerId);
     }
};


function startup()
{
document.getElementById('statusline').innerHTML='Requesting permission to upload...';
ajax('startup_xd', '/perl/helper.pl?request=uprequest&parameter=' + nm + '&random=' + Math.random());
};


function startup_xd(output)
{
if (output=='0')
  {
  document.getElementById('statusline').innerHTML='Error: Check login status';
  return;
  };
upcode = output;
document.upform.parameter.value=output;
document.upform.action='/perl/helper.pl?upload_id=' + output;
document.upform.submit();
document.upform.thefile.disabled=true;
document.getElementById('statusline').innerHTML='Starting Upload';
timerId = setInterval("upcheck('" + output + "')", 2000);
};

function upcheck(code)
{
ajax('upcheck_xd', '/perl/helper.pl?request=upcheck&parameter=' + code + '&random=' + Math.random());
};

function upcheck_xd(upresult)
{
var upc = upresult.split(';');
if (upc[0] == 'done')
   {
   document.getElementById('statusline').innerHTML='Upload finished successfully';
   document.upform.thefile.disabled=false;
   document.upform.thefile.value='';
   document.getElementById('preview').innerHTML='<image src=/thumbs/' + upc[1] + '.jpg>';
   clearInterval(timerId);
   }
else if (upc[0] == 'error')
     {
     document.getElementById('statusline').innerHTML='Error! ' + upc[1];
     document.upform.thefile.disabled=false;
     document.upform.thefile.value='';
     clearInterval(timerId);
     }
else if (upc[0] == 'requested')
     {
     document.getElementById('statusline').innerHTML='Upload Started...';
     }
else if (upc[0] == 'uploading')
     {
     document.getElementById('statusline').innerHTML="<div class=statdiv><div style='height:15px; width:" + upc[1] + "%; background:white'></DIV></div> " + upc[1] + "% uploaded";
     }
else if (upc[0] == 'duplicate')
     {
     document.getElementById('statusline').innerHTML=upc[1];
     document.upform.thefile.disabled=false;
     document.upform.thefile.value='';
     document.getElementById('preview').innerHTML='<image src=/thumbs/' + upc[2] + '.jpg>';
     clearInterval(timerId);
     }
else
    {
    document.getElementById('statusline').innerHTML='Unknown Error: ' + upc[0];
    document.upform.thefile.disabled=false;
    document.upform.thefile.value='';
    clearInterval(timerId);
    };
	
};


function sucheck()
{
if ((document.suform.sunick.value=='')||(document.suform.suuser.value=='')||(document.suform.supass.value=='')||(document.suform.suconfirm.value=='')||(document.suform.suemail.value==''))
   {
   alert('Please fill in all fields.');
   return false;	
   };
if (document.suform.supass.value!=document.suform.suconfirm.value) {alert('\'Password\' and \'Confirm password\' fields do not match.');return false};
if (!document.suform.suuser.value.match(/^[A-Z0-9]+$/i)) {alert('Illegal username. Please use letters and numbers only.');return false};
if (!document.suform.supass.value.match(/^[A-Z0-9]+$/i)) {alert('Illegal password. Please use letters and numbers only.');return false};
if (!document.suform.suemail.value.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i)) {alert('Invalid e-mail address entered.');return false};
return true;	
};


function maybeRank(ur)
{
for (var i=1; i<6; i++)	
    {
    if (i<=ur) {document.getElementById('urs' + i).src='/themes/global/star_lit.gif'} else {document.getElementById('urs' + i).src='/themes/global/star_off.gif'};
    };
switch (ur)
    {
    case 0: document.getElementById('rankmessage').innerHTML='(click to rate)'; break;
    case 1: document.getElementById('rankmessage').innerHTML='(ugly feet)'; break;
    case 2: document.getElementById('rankmessage').innerHTML='(bad feet)'; break;
    case 3: document.getElementById('rankmessage').innerHTML='(ok feet)'; break;
    case 4: document.getElementById('rankmessage').innerHTML='(nice feet)'; break;
    case 5: document.getElementById('rankmessage').innerHTML='(beautiful feet)'; break;
    }

};

function reply(newpost)
  {
  document.getElementById('newstuff').style.display='none';
  document.getElementById('addstufflabel').style.display='inline';
  if (loggedout) {alert('You\'ve Logged-out. Please Log-in again to add wall stuff..'); return};
  if (post == newpost) {document.getElementById('replytext').focus(); return};
  if (post) {document.getElementById('reply' + post).innerHTML=""};
  post = newpost;
  var disablereprank;
  if (userrank==0) {reprank='disabled'};
  document.getElementById('reply' + post).innerHTML="<table class=replybox><tr><td style='font-size:12pt; font-weight:bold'>Your reply:</td><td align=right><button id=submitreply onclick=wallReplier(" + post + ")>send</button></td></tr><tr><td colspan=2 style='padding-right:5px'><table width=100%><tr><td><TEXTAREA id=replytext style='width:100%; height:45px'></TEXTAREA></td></tr></table></td></tr><tr><td colspan=2><INPUT type=checkbox " + reprank + " id=reprankcheck onclick=\"if (this.checked) {reprank='checked'} else {reprank=''}\"> Show my current rank for " + celebname + "'s feet <span id=rankinreply>" + ranknames[userrank] + "</span></td></tr></table>";
  document.getElementById('replytext').focus();
  };
  
function wallReplier(post)
         {
         //alert(post);
         document.getElementById('submitreply').disabled=true;
         var showrank=0;
         if (document.getElementById('reprankcheck').checked) {showrank=userrank};
         if (document.getElementById('replytext').value=='') {alert('You must write something in the textbox..\nthats what it\'s there for..!'); return};
         ajax('wallReplier_xd', '/perl/helper.pl?request=wallwrite&parameter=' + post + '&rank=' + showrank +'&type=reply&&comment=' + encodeURIComponent( document.getElementById('replytext').value ) + '&random=' + Math.random());
         };

function wallReplier_xd(output)
  {
  if (output.substring(0,1)=='1')
    {
    document.getElementById('thewall').innerHTML=output.substring(1);
    }
  else
    {
    alert(output.substring(1));
    document.getElementById('submitreply').disabled=false;
    };
  };

function yesRank(ur, celeb)
{
if (loggedout) {alert('Rating possible for members only. Please login.')}
else 
     {
     userrank=ur;
     document.getElementById('rankcheck').disabled=false;
     document.getElementById('rankcheck').checked=true;
     reprank='checked';
     if (post)
      {
      document.getElementById('reprankcheck').disabled=false;
      document.getElementById('reprankcheck').checked=true;
      document.getElementById('rankinreply').innerHTML=ranknames[ur];
      };
     document.getElementById('rankinwall').innerHTML=ranknames[ur];
     ajax('yesRank_xd', '/perl/helper.pl?request=rank&parameter=' + celeb + '&rank=' + ur + '&random=' + Math.random())}
};

function yesRank_xd(output)
{
if (output=='1') {document.getElementById('rankmessage').innerHTML='(rank saved)'} else {alert('Error. rank not saved.' + output)};
};

function logout()
         {
         loggedout = true;
         document.cookie='passkey=0; path=/;';
         //if (loginbox !=null) {document.getElementById('loginbox').style.visibility='visible'; alert(1)};
         document.getElementById('userlog').innerHTML='User Logged-Out'
         };

function whatIsImdbLink()
         {
          document.getElementById('results').innerHTML="<br><small>To get the IMDb link of a celebrity, you need to search for her in IMDb (<a href='http://www.imdb.com' style='color:darkblue' target='_blank'>http://www.imdb.com</a>),<br>enter her page and copy the address link.<br><br>The address should be in the form of:<br><i>http://www.imdb.com/name/nm[SomeNumber]/";
         };
         
function addStuff(type,value)
        {
        //alert('adstuff started!');
        if (pm) {document.getElementById('pm'+pm).innerHTML=''};
        if (post) {document.getElementById('reply' + post).innerHTML=""; post=''};
        pm='';
        if (loggedout) {alert('You\'ve Logged-out. Please Log-in again to add wall stuff..'); return};
        document.getElementById('addstufflabel').style.display='none';
        document.getElementById('newstuff').style.display='block';
        //walltop.scrollIntoView();
        if (type==wallatt && value=='') {return} else {wallatt=type};

        // HANDLING ATTACHMENT BUTTON:
        if (type=='non') {document.getElementById('w_non').className = 'walltypeon'} else {document.getElementById('w_non').className = 'walltypeoff'};
        if (type=='pic') {document.getElementById('w_pic').className = 'walltypeon'} else {document.getElementById('w_pic').className = 'walltypeoff'};
        if (type=='vid') {document.getElementById('w_vid').className = 'walltypeon'} else {document.getElementById('w_vid').className = 'walltypeoff'};


        // HANDLING ATTACHMENT INPUT:
        if (type=='non') {document.getElementById('attd').innerHTML = ''}
        else if (type=='pic') {document.getElementById('attd').innerHTML = "Picture id: <INPUT id=wi_pic type=text style='width:40px; font-size:7pt'><button style='font-size:7pt' onclick=\"addStuff('pic',document.getElementById('wi_pic').value)\">update</button>"}
        else if (type=='vid') {document.getElementById('attd').innerHTML = "YouTube link: <INPUT id=wi_vid type=text style='font-size:7pt; width:200px'><button style='font-size:7pt' onclick=\"addStuff('vid',document.getElementById('wi_vid').value)\">update</button>"};
        
        
        // HANDLING ACTUAL ATTACHMENT:
        if (type=='non' || value=='') {wallattvalue=''; document.getElementById('attachment').innerHTML=''}
        else if (type=='pic' && value!='')
          {
          document.getElementById('wi_pic').value=value;
          pidcheck(value);
          document.getElementById('wallta').focus();
          }
        else if (type=='vid' && value!='')
          {
          document.getElementById('wi_vid').value=value;
          var temp=value.match(/(http:\/\/)?(www\.)?youtube\.com\/watch\?v=(.+)&?/);
          if (temp==null) {alert('Bad link format.\n(should be http://www.youtube.com/watch?v=stuff)');return};
          document.getElementById('attachment').innerHTML='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="120" height="90"><param name="movie" value="http://www.youtube.com/v/'+temp[3]+'&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+temp[3]+'&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="120" height="90"></embed></object>';
          wallattvalue=temp[3];
          document.getElementById('wallta').focus();
          };
          
        };
        
function wallWriter(celeb)
         {
         document.getElementById('submitpost').disabled=true;
         var showrank=0;
         if (document.getElementById('rankcheck').checked) {showrank=userrank};
         //alert('celeb=' + celeb + ', rank=' + showrank + ', attachment type=' + wallatt + ', att=' + wallattvalue + ', comment=' + wallta.value);
         if (document.getElementById('wallta').value=='write stuff here' || document.getElementById('wallta').value=='') {alert('You must write something in the textbox..\nthats what it\'s there for..!'); document.getElementById('submitpost').disabled=false; return};
         ajax('wallWriter_xd', '/perl/helper.pl?request=wallwrite&parameter=' + celeb + '&rank=' + showrank +'&type=' + wallatt + '&att=' + wallattvalue + '&comment=' + encodeURIComponent( document.getElementById('wallta').value ) + '&random=' + Math.random());
         };

function wallWriter_xd(output)
  {
  if (output.substring(0,1)=='1')
    {

    addStuff('non','');
    document.getElementById('newstuff').style.display='none';
    document.getElementById('addstufflabel').style.display='inline';
    document.getElementById('wallta').value='write stuff here';
    document.getElementById('thewall').innerHTML=output.substring(1);
    document.getElementById('wallbottom').scrollIntoView();
    }
  else
    {
    //wallstatus.innerHTML=output.substring(1);
    alert(output.substring(1));
    };
  document.getElementById('submitpost').disabled=false;
  };

function unsub(idx)
  {
  if (confirm('Are you sure you want to unsubscribe?'))
    {
    ajax('unsub_xd', '/perl/helper.pl?request=unsubscribe&parameter=' + idx +'&random=' + Math.random());
    };
  };

function unsub_xd(output)
  {
  subout = output.split('|');
  if (subout[0]=='0') {alert(subout[1]);return};
  document.getElementById('subscriptions').innerHTML = subout[1];
  };

function subscribe(celeb,which)
  {
  ajax('subscribe_xd', '/perl/helper.pl?request=subscribe&parameter=' + celeb + '&which=' + which +'&random=' + Math.random());
  };
  
function subscribe_xd(output)
  {
  subout = output.split(';');
  if (subout[0]=='0') {alert(subout[1]);return};
  if (subout[1]=='1') {document.getElementById('sub_' + subout[0]).checked = true}
  else {document.getElementById('sub_' + subout[0]).checked = false};
  };
  
  
window.onscroll = adfollow;
function adfollow()
    {
        var ad = document.getElementById("side_ad");
        var top = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
        if (top>100) {ad.style.top = top-100 + 'px'} else {ad.style.top = '0px'};
        
    }
