function basename(path, suffix) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // +   improved by: djmix
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}


function updateVideoViews(video_id) {
  var ajaxRequest = null;

  try {
    ajaxRequest = new XMLHttpRequest();
  } catch(e) {
    try {
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
        alert("Cannot start AJAX server");
        return false;
      }
    }
  }

  ajaxRequest.onreadystatechange = function() {
    if (ajaxRequest.readyState == 3) {
    }
  }

  var queryString = "?v=" + basename(video_id);
  ajaxRequest.open("GET", "/video_count.php" + queryString, true);
  ajaxRequest.send(null);
}

function setVideoTitle(objectid, video_id)
{
  $.ajax({
    type: "GET",
    url: "video_title.php",
    data: "v=" + basename(video_id),
    success: function(html) {
       $(objectid).html(html);
    }
  });
}

function setVideoSize(objectid, video_id)
{
  $.ajax({
    type: "GET",
    url: "video_size.php",
    data: "v=" + basename(video_id),
    success: function(html) {
       $(objectid).css(html);
    }
  });
}

function setVideoLink(objectid, host, type, cat, url)
{
  if (host == "charlesneilwoodworking.")
    host = "charlesneilwoodworking.com";
  else
    host = host + "charlesneilwoodworking.com";

  if (cat == -1)
    player = "/dvdplayer.php?id=" + type;
  else
    player = "/category_player.php?type=" + type +"&amp;cat=" + cat + "&amp;video=" + basename(url);

    html = "<a href=\"http://" + host + player + "\">http://" + host + player + "</a>";
    $(objectid).html(html);
}

function paypal(item_code)
{
  var ar = null;

  try {
    ar = new XMLHttpRequest();
  } catch(e) {
    try {
      ar = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        ar = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        alert("Cannot start AJAX server");
        return false;
      }
    }
  }

  ar.onreadystatechange = function() {
    if (ar.readyState == 3) {
    }
  }

  var queryString = "?code=" + item_code;
  ar.open("GET", "/paypal.php" + queryString, true);
  ar.send(null);

  return false;
}

       