function rateEntryUp(e_id)
  {
  new Ajax.Updater('entry_up-'+e_id, 
                   '/idealab/entry/entry_rate_up', 
                   {
                   asynchronous:true, 
                   method:'post', 
                   parameters:{entry_id: e_id}, 
                   onComplete:function()
                                {
                                $('colorentryupdown-up').hide();
                                $('colorentryupdown-down').hide();
                                $('grayentryupdown-up').update('<img src="/idealab/images/arrow3-buy-16x16.png" alt="" />');
                                $('grayentryupdown-up').show();
                                $('grayentryupdown-down').show();
                                }
                   }
                  );
  return false;
  }

function rateEntryDown(e_id)
  {
  new Ajax.Updater('entry_down-'+e_id, 
                   '/idealab/entry/entry_rate_down', 
                   {
                   asynchronous:true, 
                   method:'post', 
                   parameters:{entry_id: e_id}, 
                   onComplete:function()
                                {
                                  $('colorentryupdown-up').hide();
                                  $('colorentryupdown-down').hide();
                                  $('grayentryupdown-up').show();
                                  $('grayentryupdown-down').update('<img src="/idealab/images/arrow3-sell-16x16.png" alt="" />');
                                  $('grayentryupdown-down').show();
                                }
                   }
                  );
  return false;
  }

function rateCommentUp(c_id)
  {
  new Ajax.Updater('strong-'+c_id, 
                   '/idealab/entry/comment_rate_up/', 
                   {
                   asynchronous:true, 
                   method:'post', 
                   parameters:{comment_id: c_id}, 
                   onComplete:function()
                                {
                                $('colorcommentupdown'+c_id).hide();
                                $('graycommentupdown'+c_id).show();
                                }
                   }
                  );
  return false;
  }

function rateCommentDown(c_id)
  {
  new Ajax.Updater('strong-'+c_id, 
                   '/idealab/entry/comment_rate_down/', 
                   {
                   asynchronous:true, 
                   method:'post', 
                   parameters:{comment_id: c_id}, 
                   onComplete:function()
                                 {
                                 $('colorcommentupdown'+c_id).hide();
                                 $('graycommentupdown'+c_id).show();
                                 $('cshowlink'+c_id).show();
                                 new Effect.BlindUp('cbody-inside-'+c_id);
                                 }
                   }
                  );
  return false;
  }

function sC(c_id)
  {
  $('cshowlink'+c_id).hide();
  $('chidelink'+c_id).show();
  new Effect.BlindDown('cbody-inside-'+c_id);
  return false;
  }

function hC(c_id)
  {
  $('chidelink'+c_id).hide();
  $('cshowlink'+c_id).show();
  new Effect.BlindUp('cbody-inside-'+c_id);
  return false;
  }

function editComment(c_id)
  {
  /* Hide the "Click To Edit" and commentstatic divs */
  $('clicktoedit' + c_id).hide();
  $('commentstatic' + c_id).hide();
  /* Show whole edit div */
  $('commentedit' + c_id).show();
  return false;
  }

function updateComment(c_id, new_comment_text)
  {
  /* Send the new text to the server */
  new Ajax.Updater('commentstatic' + c_id, 
                   '/idealab/entry/comment_edit/', 
                   {
                   asynchronous:true, 
                   method:'post', 
                   parameters:{comment_id: c_id, comment_text: new_comment_text}, 
                   onComplete:function()
                                 {
                                 /* Show the "Click To Edit" and commentstatic divs */
                                 $('clicktoedit' + c_id).show();
                                 $('commentstatic' + c_id).show();
                                 /* Hide the div that is the textarea */
                                 $('commentedit' + c_id).hide();
                                 }
                   }
                  );
  return false;
  }

function updateTimezone()
  {
  var state_id = $('location_state').value;
  new Ajax.Request('/idealab/location/convert_state_to_timezone/'+state_id,
                     {
                     onSuccess:function(xh)
                       {
                       var response = xh.responseText;
                       if(!isNaN(parseInt(response)))
                         {
                         $('timezone').value = response;
                         }
                       }
                     }
                    );
  return false;
  }

function setupcomment()
  {
  $('comment').focus();
  return false;
  }

function setupcreply(parentid, parentusername)
  {
  $('creplyformheader').update('Add Your Reply');
  $('submitbutton').value = 'Submit Reply';
  $('cforminfo').update('Replying to comment by '+parentusername+' (<a href="#c'+parentid+'" onclick="return(cancelcreply())">cancel</a>)').show();
  $('cformreplyto').value = parentid;
  $('cformreturn').value = parentid;
  $('comment').focus();
  return false;
  }

function cancelcreply()
  {
  $('cforminfo').hide().update();
  $('cformreplyto').update();
  $('creplyformheader').update('Add Your Comment');
  $('submitbutton').value = 'Submit Comment';
  }

function showCaptcha()
  {
  var target=$('commentcaptcha');
  target.onclick = null;
  target.setStyle('display', 'block');
  if(!(target.empty()))
    {
    $('submitbutton').disable();
    new Ajax.Request('/idealab/get_captcha',
                     {
                     method:'get', 
                     parameters:{keyname: name}, 
                     onSuccess:function(xh)
                       {
                       $('commentcaptcha').update(xh.responseText);
                       $('submitbutton').disabled=false;
                       }
                     }
                    );
    }
  }

function manageStateDropdown()
  {
  if($('location_country').value == '1')
    {
    $('location_state_container').show();
    }
  else
    {
    $('location_state_container').hide();
    }
  }

function manageImName()
  {
  if($('im_client').value != '1')
    {
    $('im_name_container').show();
    $('im_client_name').update($('im_client').options[$('im_client').selectedIndex].text);
    }
  else
    {
    $('im_name_container').hide();
    }
  }

var comment_to_go_to = '';

function sideLogin(comment)
  {
  if(comment != null)
    {
    comment_to_go_to = comment;
    }
  $('firstdiv').scrollTo();
  new Effect.BlindDown('sidelogin', {afterFinish: function(){$('username').focus();}});
  $('sideloginbutton').update('<input type="image" border="0" name="imageField" src="/idealab/images/LogIn2.gif" width="181" height="31" onclick="return ajaxLogin()"><br /><a href="/idealab/user/register"><img src="/idealab/images/Register.gif" width="181" height="28" /></a><br /><img src="http://www.traderinterviews.com/images/leftnav_bottom.gif" width="181" height="12"><br />');
  return false;
  }

function ajaxLogin()
  {
  /* Hide the current message */
  $('ajaxloginmessage').hide();

  /* Send it to the login script */
  new Ajax.Request('/idealab/user/login', 
                   {
                   method: 'post', 
                   postBody: $('sideloginform').serialize(), 
                   onComplete: function(xh)
                                 {
                                 if(xh.responseText == 'Success')
                                   {
                                   if(comment_to_go_to != '')
                                     {
                                     window.location.href = window.location.href+'#c'+comment_to_go_to;
                                     }



                                   if(window.location.href.indexOf("activation_confirm") != -1)
                                     {
                                     window.location.href = 'http://www.traderinterviews.com/idealab/';
                                     /* Something odd here, without the alert, it reloads the activation_confirm screen */
                                     alert("Thanks for logging in");
                                     }
                                   location.reload(true);
                                   comment_to_go_to = '';
                                   }
                                 else
                                   {
                                   $('ajaxloginmessage').update(xh.responseText);
                                   $('ajaxloginmessage').show();
                                   }
                                 }
                   }
                  );
  }

function sideLogout()
  {
  new Ajax.Request('/idealab/user/logout', 
                   {
                   method: 'get', 
                   onComplete: function(xh)
                                 {
                                 if(xh.responseText == 'Success')
                                   {
                                   location.reload(true);
                                   }
                                 else
                                   {
                                   $('ajaxloginmessage').update(xh.responseText);
                                   $('ajaxloginmessage').show();
                                   }
                                 }
                   }
                  );
  return false;
  }

function blockUser(u_id, user_name)
  {
  if(confirm("Are you sure you want to block user " + user_name + '?'))
    {
    new Ajax.Request('/idealab/user/block/', 
                     {
                     asynchronous:true, 
                     method:'post', 
                     parameters:{user_id: u_id}, 
                     onComplete:function(xh)
                                  {
                                  if(xh.responseText == 'Success')
                                    {
                                    var theElements = document.getElementsByClassName('user'+u_id);
                                    theElements.each(function(el){el.hide();});
                                    }
                                  }
                     }
                    );
    }
  return false;
  }

function unblockUser(u_id, user_name)
  {
  if(confirm("Are you sure you want to unblock user " + user_name + '?'))
    {
    new Ajax.Request('/idealab/user/unblock/', 
                     {
                     asynchronous:true, 
                     method:'post', 
                     parameters:{user_id: u_id}, 
                     onComplete:function(xh)
                                  {
                                  if(xh.responseText == 'Success')
                                    {
                                    $('blocked-'+u_id).hide();
                                    }
                                  }
                     }
                    );
    }
  return false;
  }

function makeFriend(u_id, user_name)
  {
  if(confirm("Are you sure you want to make " + user_name + ' a friend?'))
    {
    new Ajax.Request('/idealab/friend/make/', 
                     {
                     asynchronous:true, 
                     method:'post', 
                     parameters:{user_id: u_id}, 
                     onComplete:function(xh)
                                  {
                                  if(xh.responseText == 'Success')
                                    {
                                    $('button-friend-'+u_id).update('<img src="/idealab/images/button-is-friend.gif" alt="'+user_name+' is your Friend"/>');
                                    }
                                  }
                     }
                    );
    }
  return false;
  }

function removeFriend(u_id, user_name)
  {
  if(confirm("Are you sure you want to remove " + user_name + ' as your friend?'))
    {
    new Ajax.Request('/idealab/friend/remove/', 
                     {
                     asynchronous:true, 
                     method:'post', 
                     parameters:{user_id: u_id}, 
                     onComplete:function(xh)
                                  {
                                  if(xh.responseText == 'Success')
                                    {
                                    $('friend-'+u_id).remove();
                                    }
                                  }
                     }
                    );
    }
  return false;
  }

function enablebutton(button, button2, target)
  {
  var string = target.value;
  button2.disabled = false;
  if(string.length > 0)
    {
    button.disabled = false;
    }
  else
    {
    button.disabled=true;
    }
  }

function isValidUsername(form)
  {
  var name = escape(form.username.value);
  if(name.length > 0)
    {
    new Ajax.Request('/idealab/user/check_username',
                     {
                     method:'post', 
                     parameters:{username: name}, 
                     onSuccess:function(xh)
                       {
                       var response = xh.responseText;
                       if(response == 'taken')
                         {
                         $('checkusernamevalue').update('<strong style="background: url(/idealab/images/deny.png) 0 1px no-repeat; padding-left: 16px; font-size: 85%; color: #c00;">Sorry, the username "'+name+'" is taken.</strong>');
                         form.submit.disabled = 'disabled';
                         }
                       else if(response == 'criteria')
                         {
                         $('checkusernamevalue').update('<strong style="background: url(/idealab/images/deny.png) 0 1px no-repeat; padding-left: 16px; font-size: 85%; color: #c00;">Usernames must have 4-15 alphanumeric characters</strong>');
                         form.submit.disabled = 'disabled';
                         }
                       else
                         {
                         $('checkusernamevalue').update('<strong style="background: url(/idealab/images/confirm.png) 0 1px no-repeat; padding-left: 16px; font-size: 85%; color: #090;">Great, the username "'+name+'" is available.</strong>');
                         form.submit.disabled='';
                         }
                       }
                     }
                    );
    }
  else if(name.length == 0)
    {
    $('checkusernamevalue').update();
    }
  return false;
  }

function ShowWhatIs()
  {
	Effect.Appear("WhatIsFull", {duration:0.7});
	$("WhatIs").hide();	
  }

function HideWhatIs()
  {
	$("WhatIsFull").hide();
	Effect.Appear("WhatIs", {duration:0.5});
  }

