

/*
** Places the bookmark button on the asset
** NOT LONGER USED
*/
function initAssetBookmark(asset_id) {
  //new Ajax.Updater('asset-bookmark', "/asset/bookmark/"+asset_id, {asynchronous:true, evalScripts:true});
}



/*
**
**
*/
/*function initUserMenu() {
  new Ajax.Updater("user-menu", "/user/menu", {asynchronous:true, evalScripts:true});  
}*/

/*
**
**
*/
/*function initFlashNotice() {
  new Ajax.Request("/site/flash_notice", {asynchronous:true, evalScripts:true});
}*/

/*
**
**
**
*/
function isUser() {
  if (jimAuld.utils.cookies.get('user_logged_in') == 'yes') {
    return true;
  } else {
    return false;
  }
}

/*
**
**
*/
function actionSignIn(success) {
  if (success) {
    Modalbox.hide();
    location.href = "/";
  } else {
    $('login-form-result').innerHTML = 'Login failed.';
    Modalbox.resizeToContent();
  }
}


/*
**
**
*/
function actionForgotPassword(success) {
  if (success) {
    $('forgot-password-form-result').innerHTML = 'An email has been sent to your address with further instructions.'
    $('forgot-password-form').hide();
    Modalbox.resizeToContent();
  } else {
    $('forgot-password-form-result').innerHTML = 'Sorry, there is no such email here.' 
  }
}


function showMenu() {
  if (isUser()) {
    $('registered-user-menu').show();
    //$('user-menu-name').innerHTML = jimAuld.utils.cookies.get('login');
    $('registered-user-menu').insert({ top: new Element('a', { href: '/home/'+jimAuld.utils.cookies.get('login') }).update(jimAuld.utils.cookies.get('login')) });
    //initUserMenu();
  } else {
    $('anonymous-user-menu').show();
  //var myTemplate = new Template($('login-form-template').innerHTML);
  //$('new-login').innerHTML = myTemplate.evaluate({name : "fucking name"});
  }
}

function setStickyReferer() {
  if (jimAuld.utils.cookies.get('sticky_referer') == null) {
    if (document.referrer != '') {
      jimAuld.utils.cookies.set('sticky_referer', document.referrer);
    }
  }
}


function showLoginDialog() {
  Modalbox.show('/user/login_form', {title: '&nbsp;', overlayOpacity: 0.20, slideUpDuration: 0.25, slideDownDuration: 0.25 , width: 300});    
}
function showSignupDialog() {
  Modalbox.show("/user/signup_form", {title: '&nbsp;', overlayOpacity: 0.20, slideUpDuration: 0.25, slideDownDuration: 0.25 , width: 300});    
}
function showForgotPasswordDialog() {
  Modalbox.show("/user/forgot_password_form", {title: '&nbsp;', overlayOpacity: 0.20, slideUpDuration: 0.25, slideDownDuration: 0.25 , width: 300});    
}
function showVerifyDialog(msg) {
  Modalbox.show(msg, {title: '&nbsp;', overlayOpacity: 0.20, slideUpDuration: 0.25, slideDownDuration: 0.25 , width: 300});
}
function showChangePasswordDialog(msg) {
  Modalbox.show(msg, {title: '&nbsp;', overlayOpacity: 0.20, slideUpDuration: 0.25, slideDownDuration: 0.25 , width: 300});
}


function placeCommentForm(where, h) {
  $(where).update(commentFormTemplate.evaluate(h));
}

function placeReplyCommentForm(asset, comment) {
  var commentHash = { parent_id: comment, asset_id: asset };
  placeCommentForm('reply_button_' + comment, commentHash);
}

function placeMainCommentForm(asset) {
  var commentHash = { parent_id: 0, asset_id: asset };
  placeCommentForm('new_comment_thread', commentHash);
}

function placeReplyButtons(comments, asset) {
  comments.each(function (x) {
    var h = { 'comment_id': x, 'asset_id': asset };
    $("comment_"+x).insert({ bottom:commentReplyButtonTemplate.evaluate(h) });
  });
}

function relativizeDates(d) {
  dates = $$(d);
  dates.each(function (d) {
      var v = d.innerHTML
      d.innerHTML = prettyDate(v);
  });
}

