// Thrillist javascript/jquery function library
// Created on 9/23/08

// function responsible for binding a form id to
// a submit button image
// usage <a href="javascript:submit_form('form_id');">Do It</a>
function submit_form(formname)
{
  var form = document.getElementById(formname);
  form.submit();
}

/**
 * Function to share content on facebook
 */
function fbs_click()
{
  u=location.href;
  t=document.title;
  window.open("http://www.facebook.com/sharer.php?u="+encodeURIComponent(u)+"&t="+encodeURIComponent(t),"sharer","toolbar=0,status=0,width=626,height=436");
  return false;
}

// close lightbox window
function closeLB()
{
  Lightbox.end('forceClose');
}

function deletecustom(nid)
{
  var host = 'http://www.thrillist.com/';
  //var host = 'http://anthony.thrillist-dev.com/thrillist2.0/';
  
  var answer = confirm('Are you really really sure you want to delete this? Make your decision wisely as any unsaved changes will be lost!');
  if(answer == true)
  {
    window.location = host + 'node/'+nid+'/delete';
  }
}

// custom function to show any hidden data
function toggleDisplay(id)
{
  var display_status = $("#"+id).css("display");
  if(display_status == "none")
  {
    $("#"+id).show();
  }
  else
  {
    $("#"+id).hide();
  }  
}

// custom function to show any hidden data
function toggleVisibility(id)
{
  // wrapper to hide/show
  toggleDisplay(id);
}

// build our ajax objects
// taken from: http://www.w3schools.com/Ajax/ajax_browsers.asp
function buildAjaxObject()
{
  // our xml object
  var xmlHttp;
  
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  // catch any errors that may occur
  catch (e)
  {
    // Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }

  return xmlHttp;
}
